annotate src/private/tools/backup.html.luan @ 18:64eee582fec1

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