2
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local Html = require "luan:Html.luan"
|
|
4 local html_encode = Html.encode or error()
|
|
5 local Parsers = require "luan:Parsers.luan"
|
|
6 local json_string = Parsers.json_string or error()
|
|
7 local Io = require "luan:Io.luan"
|
|
8 local Http = require "luan:http/Http.luan"
|
|
9 local reset_luan = Http.reset_luan or error()
|
|
10 local test_as_init = Http.test_as_init or error()
|
|
11 local Run = require "luan:http/tools/Run.luan"
|
|
12 local Config = require "site:/lib/Config.luan"
|
4
|
13 local Shared = require "site:/lib/Shared.luan"
|
|
14 local head = Shared.head or error()
|
|
15 local header = Shared.admin_header or error()
|
2
|
16 local Logging = require "luan:logging/Logging.luan"
|
4
|
17 local logger = Logging.logger "admin/config.html"
|
2
|
18
|
|
19
|
|
20 return function()
|
|
21 Io.stdout = Http.response.text_writer()
|
4
|
22 local updated = false
|
2
|
23 if Http.request.method == "POST" then
|
|
24 local config = Http.request.parameters.config or error()
|
|
25 try
|
|
26 test_as_init(config,"config")
|
|
27 catch e
|
|
28 Run.print_error(e,config)
|
|
29 return
|
|
30 end
|
|
31 Config.set(config)
|
|
32 reset_luan()
|
4
|
33 updated = true
|
2
|
34 end
|
|
35 %>
|
|
36 <!doctype html>
|
|
37 <html>
|
|
38 <head>
|
4
|
39 <% head() %>
|
2
|
40 <title>FreedIt - Configure Forum</title>
|
|
41 <style>
|
|
42 textarea {
|
|
43 width: 90%;
|
|
44 height: 20em;
|
|
45 }
|
|
46 </style>
|
|
47 <script>
|
|
48 function restoreDefault() {
|
|
49 document.querySelector('textarea').value = <%=json_string(Config.default_text,{compressed=true})%>;
|
|
50 }
|
|
51 </script>
|
|
52 </head>
|
|
53 <body>
|
4
|
54 <% header() %>
|
|
55 <div content>
|
|
56 <h1>Configure Forum</h1>
|
|
57 <% if updated then %>
|
|
58 <p>Updated</p>
|
|
59 <% else %>
|
|
60 <form method=post>
|
|
61 <p>
|
|
62 Configuration in <a href="http://www.luan.software/">Luan</a>
|
|
63 - <a href="javascript:restoreDefault()">restore default</a>
|
|
64 </p>
|
|
65 <p><textarea name=config autofocus><%= html_encode(Config.text) %></textarea></p>
|
|
66 <p><input type=submit><p>
|
|
67 </form>
|
|
68 <% end %>
|
|
69 </div>
|
2
|
70 </body>
|
|
71 </html>
|
|
72 <%
|
|
73 end
|