annotate src/admin/add.html.luan @ 19:a90e510ccc4f

fix restart/move logs
author Vadim Filimonov <fffilimonov@yandex.ru>
date Mon, 05 Aug 2024 11:29:06 +0300
parents a7187a447835
children b14073ab9d07
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
5
a09d8bcdc0f9 lower case repos
Franklin Schmidt <fschmidt@gmail.com>
parents: 0
diff changeset
3 local String = require "luan:String.luan"
10
a7187a447835 restrict repo names
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
4 local matches = String.matches or error()
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
5 local Io = require "luan:Io.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
6 local Http = require "luan:http/Http.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
7 local Shared = require "site:/lib/Shared.luan"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
8 local head = Shared.head or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
9 local header = Shared.admin_header or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
10 local get_user = Shared.get_user or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
11 local get_raw_config = Shared.get_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
12 local save_raw_config = Shared.save_raw_config or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
13 local admin_return = Shared.admin_return or error()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
14
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
15
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
16 local function handle()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
17 local user = get_user()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
18 local repo_name = Http.request.parameters.repo or error()
10
a7187a447835 restrict repo names
Franklin Schmidt <fschmidt@gmail.com>
parents: 5
diff changeset
19 matches( repo_name, "^[a-z0-9_][a-z0-9_-]*$" ) or error "invalid regex name"
0
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
20 if repo_name=="_all" or repo_name=="_private" then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
21 return [[<p error>Invalid rep name</p>]]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
22 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
23 local raw_config = get_raw_config()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
24 if raw_config.repos[repo_name] ~= nil then
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
25 return [[<p error>A repo named <b>]]..repo_name..[[</b> already exists</p>]]
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
26 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
27 raw_config.repos[repo_name] = {
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
28 mode = "public"
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
29 users = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
30 admins = {user}
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
31 }
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
32 save_raw_config(raw_config)
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
33 return [[<p>Repo <b>]]..repo_name..[[</b> created</p>]]..admin_return
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
34 end
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
35
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
36 return function()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
37 Io.stdout = Http.response.text_writer()
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
38 %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
39 <!doctype html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
40 <html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
41 <head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
42 <% head() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
43 <title>Add Mercurial Repository</title>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
44 </head>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
45 <body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
46 <% header() %>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
47 <div content>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
48 <h1>Add Repository</h1>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
49 <%=handle()%>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
50 </div>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
51 </body>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
52 </html>
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
53 <%
Vadim Filimonov <fffilimonov@yandex.ru>
parents:
diff changeset
54 end