comparison src/private/tools/backup.html.luan @ 0:dfc36e7ed22c

init
author Vadim Filimonov <fffilimonov@yandex.ru>
date Thu, 12 May 2022 13:51:59 +0400
parents
children 028e74c8889d
comparison
equal deleted inserted replaced
-1:000000000000 0:dfc36e7ed22c
1 local Luan = require "luan:Luan.luan"
2 local error = Luan.error
3 local pairs = Luan.pairs or error()
4 local ipairs = Luan.ipairs or error()
5 local stringify = Luan.stringify or error()
6 local Io = require "luan:Io.luan"
7 local Http = require "luan:http/Http.luan"
8 local Shared = require "site:/lib/Shared.luan"
9 local head = Shared.head or error()
10 local header = Shared.private_header or error()
11 local new_password = Shared.new_password or error()
12 local config = Shared.config or error()
13 local get_raw_config = Shared.get_raw_config or error()
14 local save_raw_config = Shared.save_raw_config or error()
15 local Logging = require "luan:logging/Logging.luan"
16 local logger = Logging.logger "private-users.html"
17
18
19 local function response(content)
20 %>
21 <!doctype html>
22 <html>
23 <head>
24 <% head() %>
25 <title>Mercurial Backup</title>
26 </head>
27 <body>
28 <% header() %>
29 <div content>
30 <h1>Backup</h1>
31 <%=content%>
32 </div>
33 </body>
34 </html>
35 <%
36 end
37
38 local function posted()
39 local raw_config = get_raw_config()
40 local change = Http.request.parameters.change ~= nil
41 local password = config.users.backup
42 if password == nil or change then
43 password = new_password()
44 raw_config.users.backup = password
45 end
46 for repo_name, repo in pairs(raw_config.repos) do
47 local users = {}
48 if Http.request.parameters["repo_"..repo_name] ~= nil then
49 users[#users+1] = "backup"
50 end
51 for _, user in ipairs(repo.users) do
52 if user ~= "backup" then
53 users[#users+1] = user
54 end
55 end
56 repo.users = users
57 end
58 if config.private ~= nil and not config.private.backup then
59 raw_config.private[#raw_config.private+1] = "backup"
60 end
61 save_raw_config(raw_config)
62 return nil
63 end
64
65 return function()
66 Io.stdout = Http.response.text_writer()
67 local error_msg = ""
68 if Http.request.method == "POST" then
69 local error_msg = posted()
70 if error_msg == nil then
71 response([[<p>Backup updated</p>]])
72 else
73 response([[<p error>]]..error_msg..[[</p>]])
74 end
75 return
76 end
77 %>
78 <!doctype html>
79 <html>
80 <head>
81 <% head() %>
82 <title>Mercurial Backup</title>
83 </head>
84 <body>
85 <% header() %>
86 <div content>
87 <h1>Backup</h1>
88 <form method=post>
89 <p>
90 User <b>backup</b> password: <%=config.users.backup%>
91 <label prompt clickable><input type=checkbox name=change> change backup password</label>
92 </p>
93 <p>
94 Repos to backup:
95 </p>
96 <%
97 for _, repo in pairs(config.repos) do
98 local name = repo.name
99 local checked = repo.users.backup and "checked" or ""
100 %>
101 <p>
102 <label clickable><input type=checkbox name="repo_<%=name%>" <%=checked%> > <%=name%></label>
103 - <a href="/repo/<%=name%>/">repo</a>
104 </p>
105 <% end %>
106 <p>
107 <input type=submit value="Update Backup">
108 </p>
109 </form>
110 </div>
111 </body>
112 </html>
113 <%
114 end