-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWEB_config.lua
63 lines (62 loc) · 1.6 KB
/
WEB_config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
local function gen_page(data)
local s=data.param
if (data.key) then
local c=data.type
if (c == 'boolean') then c='option true;false' end
if (c:sub(1,7) == 'option ') then
send_buffered("<select name='"..k.."'>")
for str in string.gmatch(c:sub(8), "([^;]+)") do
send_buffered("<option value='"..str.."'"..(v == str and " selected='selected'" or "")..">"..str..'</option>')
end
send_buffered("</select></br>")
else
send_buffered("<input type='"..(c == 'password' and c or 'text').."' name='"..k.."' value='"..v.."' /><br/>")
end
s.sep='<hr/>'
else
if (s.output) then
if (s.sep ~= '') then
send_buffered(s.sep)
s.sep=''
end
local text
local prefix=''
local postfix='<br/>'
if (data.line:sub(1,6) == '------') then
prefix='<h1>'
text=data.line:sub(7)
postfix='</h1>'
elseif (data.line:sub(1,4) == '----') then
prefix='<h2>'
text=data.line:sub(5)
postfix='</h2>'
else
text=data.line:sub(4)
end
send_buffered(prefix..text..postfix)
end
if (data.line == '-- BEGIN') then
s.output=true
end
end
return true
end
return function (info)
if (not authenticated()) then
return
end
send_buffered(info.http_preamble)
if (info.headers.method == 'POST') then
if (config.update(info.postdata)) then
send_buffered("Success, <a href='/'>back to main page</a>",nil)
return
else
send_buffered('An error occured</br>')
end
end
send_buffered("<form method='post'>")
state={output=false,sep=''}
config.parse('config.lua',gen_page,state)
send_buffered("</hr><input type='submit' value='Submit'/>")
send_buffered("</form>")
end