| 
0
 | 
     1 local Luan = require "luan:Luan.luan"
 | 
| 
 | 
     2 local error = Luan.error
 | 
| 
5
 | 
     3 local String = require "luan:String.luan"
 | 
| 
0
 | 
     4 local Io = require "luan:Io.luan"
 | 
| 
 | 
     5 local Http = require "luan:http/Http.luan"
 | 
| 
 | 
     6 local Shared = require "site:/lib/Shared.luan"
 | 
| 
 | 
     7 local head = Shared.head or error()
 | 
| 
 | 
     8 local header = Shared.admin_header or error()
 | 
| 
 | 
     9 local get_user = Shared.get_user or error()
 | 
| 
 | 
    10 local get_raw_config = Shared.get_raw_config or error()
 | 
| 
 | 
    11 local save_raw_config = Shared.save_raw_config or error()
 | 
| 
 | 
    12 local admin_return = Shared.admin_return or error()
 | 
| 
 | 
    13 
 | 
| 
21
 | 
    14 local name_regex = String.regex("^[a-z0-9_][a-z0-9_-]*$")
 | 
| 
0
 | 
    15 
 | 
| 
 | 
    16 local function handle()
 | 
| 
 | 
    17 	local user = get_user()
 | 
| 
 | 
    18 	local repo_name = Http.request.parameters.repo or error()
 | 
| 
23
 | 
    19 	name_regex.matches( repo_name ) or error "invalid repo name"
 | 
| 
0
 | 
    20 	if repo_name=="_all" or repo_name=="_private" then
 | 
| 
 | 
    21 		return [[<p error>Invalid rep name</p>]]
 | 
| 
 | 
    22 	end
 | 
| 
 | 
    23 	local raw_config = get_raw_config()
 | 
| 
 | 
    24 	if raw_config.repos[repo_name] ~= nil then
 | 
| 
 | 
    25 		return [[<p error>A repo named <b>]]..repo_name..[[</b> already exists</p>]]
 | 
| 
 | 
    26 	end
 | 
| 
 | 
    27 	raw_config.repos[repo_name] = {
 | 
| 
 | 
    28 		mode = "public"
 | 
| 
 | 
    29 		users = {user}
 | 
| 
 | 
    30 		admins = {user}
 | 
| 
 | 
    31 	}
 | 
| 
 | 
    32 	save_raw_config(raw_config)
 | 
| 
 | 
    33 	return [[<p>Repo <b>]]..repo_name..[[</b> created</p>]]..admin_return
 | 
| 
 | 
    34 end
 | 
| 
 | 
    35 
 | 
| 
 | 
    36 return function()
 | 
| 
 | 
    37 	Io.stdout = Http.response.text_writer()
 | 
| 
 | 
    38 %>
 | 
| 
 | 
    39 <!doctype html>
 | 
| 
24
 | 
    40 <html lang="en">
 | 
| 
0
 | 
    41 	<head>
 | 
| 
 | 
    42 <%		head() %>
 | 
| 
 | 
    43 		<title>Add Mercurial Repository</title>
 | 
| 
 | 
    44 	</head>
 | 
| 
 | 
    45 	<body>
 | 
| 
 | 
    46 <%		header() %>
 | 
| 
 | 
    47 		<div content>
 | 
| 
 | 
    48 			<h1>Add Repository</h1>
 | 
| 
 | 
    49 			<%=handle()%>
 | 
| 
 | 
    50 		</div>
 | 
| 
 | 
    51 	</body>
 | 
| 
 | 
    52 </html>
 | 
| 
 | 
    53 <%
 | 
| 
 | 
    54 end
 |