-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWEB_control.lua
More file actions
81 lines (77 loc) · 1.78 KB
/
Copy pathWEB_control.lua
File metadata and controls
81 lines (77 loc) · 1.78 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
function load(cmd)
if (cmd == 'disable') then
gpio.wakeup(14, gpio.INTR_LOW)
gpio.write(14, 0)
load_disabled=true
end
if (cmd == 'enable' and low_voltage_disconnect_state == 1) then
gpio.wakeup(14, gpio.INTR_HIGH)
gpio.write(14, 1)
load_disabled=false
end
return not (load_disabled or low_voltage_disconnect_state ~= 1)
end
local items={
ftp='TCP_21_ftp.lua',
telnet='TCP_23_telnet.lua',
web='TCP_80_web.lua',
mpptracker=mppttimer,
load=load
}
local function startstopstatus(cmd,what)
local item=items[what]
if (item == nil) then
return false
end
if (cmd == 'status') then
if (type(item) == 'string') then
return tcp_servers[item]
end
if (type(item) == 'userdata') then
local running,mode=item:state()
return running
end
end
if (cmd == 'disable') then
if (type(item) == 'string') then
server_deactivate(item)
end
if (type(item) == 'userdata') then
tmr:stop()
end
end
if (cmd == 'enable') then
if (type(item) == 'string') then
server_activate(item)
end
if (type(item) == 'userdata') then
tmr:start()
end
end
if (type(item) == 'function') then
return item(cmd)
end
return false
end
return function (info)
if (not authenticated()) then
return
end
local p=info.headers.path
if (p:match('^/control/enable/')) then
startstopstatus('enable',p:sub(17))
end
if (p:match('^/control/disable/')) then
startstopstatus('disable',p:sub(18))
end
send_buffered(info.http_preamble)
for k,v in pairs(items) do
local status='disabled'
local command='enable'
if (startstopstatus('status',k)) then
status='enabled'
command='disable'
end
send_buffered(k..":"..status.."<form method='post' action='/control/"..command..'/'..k.."'><input type='submit' value='"..command.."'/></form></br>\n")
end
end