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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
module(..., package.seeall)
require("fs")
require("procps")
require("getopts")
require("format")
require("daemoncontrol")
require("validator")
local configfile = "/etc/quagga/bgpd.conf"
local processname = "bgpd"
local baseurl = "/etc/quagga/"
local descr = {
Type = {
['incomplete']="The protocol address is being resolved",
['negative']="This protocol address is not available",
['cached']="Protocol address was resolved successfully",
['route']="This is a dynamic shortcut",
['dynamic']="This entry is from a node that connected to us",
['local']="Local interface address",
['static']="Static mapping from configuration file (e.g. address of core)",
},
Flags= {
-- ['up']="Connection is fully usable",
['lower-up']="ipsec connections is up, but registration is not yet done",
},
}
local function get_version()
local cmd_output_result, cmd_output_error
local cmd = "/sbin/apk_version -vs " .. processname .." 2>/dev/null"
local f = io.popen( cmd )
local cmdresult = f:read("*l")
if (cmdresult) and (#cmdresult > 0) then
cmd_output_result = string.match(cmdresult,"^%S*") or "Unknown"
else
cmd_output_error = "Program not installed"
end
f:close()
return cmd_output_result,cmd_output_error
end
local function autostarts()
local cmd_output_result, cmd_output_error
local cmd = "/sbin/rc_status | egrep '^S' | egrep '" .. processname .."' 2>/dev/null"
local f = io.popen( cmd )
local cmdresult = f:read("*a")
if (cmdresult) and (#cmdresult > 0) then
cmd_output_result = "Process will autostart at next boot (at sequence '" .. string.match(cmdresult,"^%a+(%d%d)") .. "')"
else
cmd_output_error = "Not programmed to autostart"
end
f:close()
return cmd_output_result,cmd_output_error
end
local function opennhrpctl_show()
local cmd_output_result={}
local cmd_output_result_table={}
local cmd_output_error, opennhrpstatus
local cmd = "/usr/sbin/opennhrpctl show 2>/dev/null"
local f = io.popen( cmd )
for line in f:lines() do
if string.find(line, "^Status:") then
opennhrpstatus=line
else
table.insert(cmd_output_result, line)
end
end
f:close()
local cnt = 0
for k,v in pairs(cmd_output_result) do
if string.find(v,"^Interface") then
cnt = cnt + 1
cmd_output_result_table[cnt] = {}
end
if ( cnt > 0 ) and (v ~= "") then
local k = string.match(v,"^(.-):%s?.*")
cmd_output_result_table[cnt][k]=cfe({value=string.match(v,"^.-:%s?(.*)")})
local statusdescription = string.lower(string.match(v,"^.-:%s?(.*)"))
if (type(descr[k]) == "table") then
cmd_output_result_table[cnt][k]['descr']=descr[k][statusdescription]
end
end
end
local peers_list = {}
for k,v in pairs(cmd_output_result_table) do
if (v.Interface.value) and not (peers_list[v.Interface.value]) then
peers_list[v.Interface.value] = {}
end
table.insert(peers_list[v.Interface.value], v)
end
return peers_list,opennhrpstatus,cmd_output_error
end
function process_status_text(procname)
local t = procps.pidof(procname)
if (t) and (#t > 0) then
return "Enabled"
else
return "Disabled"
end
end
-- ################################################################################
-- PUBLIC FUNCTIONS
function startstop_service ( self, action )
local cmd = action.value
local cmdresult,cmdmessage,cmderror,cmdaction = daemoncontrol.daemoncontrol(processname, cmd)
action.descr=cmdmessage
action.errtxt=cmderror
-- Reporting back (true|false, the original acition)
return cmdresult,action
end
function getstatus()
local status = {}
local value, errtxt = get_version()
status.version = cfe({ name = "version",
label="Program version",
value=value,
errtxt=errtxt,
})
status.status = cfe({ name="status",
label="Program status",
value=process_status_text(processname),
})
local autostart_sequense, autostart_errtxt = autostarts()
status.autostart = cfe({ name="autostart",
label="Autostart sequence",
value=autostart_sequense,
errtxt=autostart_errtxt,
})
local opennhrpctl_show, opennhrpctl_status = opennhrpctl_show()
status.stats = cfe({ name="stats",
label="Programstatus reports",
value=opennhrpctl_status,
})
status.show = cfe({ name="show",
label="Peers",
option=opennhrpctl_show,
})
return status
end
function get_filedetails()
local path = configfile
local filedetails = fs.stat(path)
local file = {}
file["filename"] = cfe({
name="filename",
label="File name",
value=path,
})
file["filesize"] = cfe({
name="filesize",
label="File size",
value=filedetails.size or 0,
})
file["mtime"] = cfe({
name="mtime",
label="File date",
value=filedetails.mtime or "---",
})
file["filecontent"] = cfe({
type="longtext",
name="filecontent",
label="File content",
value=fs.read_file(path),
})
return file
end
function update_filecontent (self, modifications)
local path = configfile
local file_result,err = fs.write_file(path, format.dostounix(modifications))
return file_result
end
|