/
system.modgui.map
441 lines (402 loc) · 9.74 KB
/
system.modgui.map
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
local modgui = require("modgui")
local logger = modgui.getRightLoggerModule()
local commitapply = commitapply
--- Returns HEX representation of num
local function num2hex(num)
local hexstr = '0123456789abcdef'
local s = ''
while num > 0 do
local mod = math.fmod(num, 16)
s = string.sub(hexstr, mod+1, mod+1) .. s
num = math.floor(num / 16)
end
if s == '' then s = '0' end
return s
end
local function str2hex(str)
local hex = ''
while #str > 0 do
local hb = num2hex(string.byte(str, 1, 1))
if #hb < 2 then hb = '0' .. hb end
hex = hex .. hb
str = string.sub(str, 2)
end
return hex
end
local function enumFileToCount()
local rootdevicefile = "/etc/init.d/rootdevice"
local additional_script = "/etc/modgui_scripts/"
local ret = { rootdevicefile }
local p = io.popen('find "'..additional_script..'" -type f')
for file in p:lines() do
ret[ #ret + 1 ] = file
end
return ret
end
--idiot function to count how much log output we have in rootdevice
local function countStepInRootdevice()
local start_count = false
local log_num = 0
for _, file in ipairs(enumFileToCount()) do
for line in io.lines(file) do
if ( start_count == true ) or not ( file:match("rootdevice") ) then
if line:match("logger_command \"") and not line:match("\" ConsoleOnly") then
log_num = log_num+1
end
end
if line:match("check_bank%(%) {") and file:match("rootdevice") then
io.close()
break
end
if line == "root() {" and file:match("rootdevice") then
start_count = true
end
end
if not ( file:match("rootdevice") ) then
io.close()
end
end
return tostring(log_num)
end
local SYSTEM_MODGUI_ = {
objectType = {
name = 'rpc.system.modgui.',
access = 'readOnly',
minEntries = 1,
maxEntries = 1,
parameters = {}
}
}
register(SYSTEM_MODGUI_)
local SYSTEM_MODGUI_UPGRADEGUI_ = {
objectType = {
name = 'rpc.system.modgui.upgradegui.',
access = 'readOnly',
minEntries = 1,
maxEntries = 1,
parameters = {
state = {
access = "readWrite",
type = "string",
enumeration = {
"Not started",
"Downloading",
"Clearing",
"Extracting",
"Requested",
"In Progress",
"Finished",
},
},
start = {
access = "readWrite",
type = "boolean",
},
log = {
access = "readWrite",
type = "string",
},
log_step = {
access = "readOnly",
type = "int",
},
log_prog = {
access = "readWrite",
type = "int",
},
extract_prog = {
access = "readWrite",
type = "int",
}
}
}
}
local upgradegui = {}
upgradegui.log_step = countStepInRootdevice()
SYSTEM_MODGUI_UPGRADEGUI_.get = {
start = "0",
state = function(mapping, param)
if ( upgradegui.resetOnNextRequest == 1 ) then
upgradegui.resetOnNextRequest = 0
upgradegui.state = nil
end
local progress_status = io.open("/root/.check_process","r")
if progress_status then
progress_status:close()
upgradegui.state = nil --reset state as we are in root progress...
return "In Progress"
elseif upgradegui.state then
if ( upgradegui.state == "Complete" ) then
upgradegui.resetOnNextRequest = 1
end
return upgradegui.state
end
return "Not started"
end,
log = function(mapping, param)
return upgradegui.log or ""
end,
log_step = function(mapping, param)
if upgradegui.logstep then
return upgradegui.logstep
else
return countStepInRootdevice()
end
end,
log_prog = function(mapping, param)
return upgradegui.log_prog or "0"
end,
extract_prog = function(mapping, param)
return upgradegui.extract_prog or "Not Extracting"
end,
}
SYSTEM_MODGUI_UPGRADEGUI_.set = {
state = function(mapping, paramName, paramValue)
if paramValue == "Finished" or
paramValue == "Clearing" or
paramValue == "Extracting" or
paramValue == "Requested" or
paramValue == "Downloading" then
upgradegui.state = paramValue
end
if paramValue == "Finished" then
upgradegui.log = ""
end
end,
start = function(mapping, paramName, paramValue)
if paramValue == "1" then
commitapply:newset("rpc.system.modgui.upgradegui." .. paramName)
end
end,
log = function(mapping, paramName, paramValue)
upgradegui.log = paramValue
end,
log_prog = function(mapping, paramName, paramValue)
upgradegui.log_prog = paramValue
end,
extract_prog = function(mapping, paramName, paramValue)
upgradegui.extract_prog = paramValue
end,
}
register(SYSTEM_MODGUI_UPGRADEGUI_)
local SYSTEM_MODGUI_UTILITY_ = {
objectType = {
name = 'rpc.system.modgui.utility.',
access = 'readOnly',
minEntries = 1,
maxEntries = 1,
parameters = {
resetgui = {
access = "readWrite",
type = "boolean",
},
upgradegui = {
access = "readWrite",
type = "boolean",
},
checkver = {
access = "readWrite",
type = "boolean",
},
removeroot = {
access = "readWrite",
type = "boolean",
},
resetconfig = {
access = "readWrite",
type = "boolean",
},
refreshdriver = {
access = "readWrite",
type = "boolean",
},
transfer_bank1 = {
access = "readWrite",
type = "boolean",
},
copy_bank = {
access = "readWrite",
type = "boolean",
},
rip_key_B = {
access = "readOnly",
type = "string",
},
}
},
get = {
resetgui = "0",
upgradegui = "0",
checkver = "0",
removeroot = "0",
transfer_bank1 = "0",
refreshdriver = "0",
copy_bank = "0",
resetconfig = "0",
rip_key_B = function()
local content = io.open("/proc/rip/0108")
local result = content:read("*all")
content:close()
return str2hex(result:sub(1,64))
end,
},
set = function(mapping, paramName, paramValue)
if paramValue == "1" then
commitapply:newset("rpc.system.modgui.utility." .. paramName)
end
end
}
register(SYSTEM_MODGUI_UTILITY_)
local SYSTEM_MODGUI_DEBUGLOG_ = {
objectType = {
name = 'rpc.system.modgui.debuglog.',
access = 'readOnly',
minEntries = 1,
maxEntries = 1,
parameters = {
state = {
access = "readOnly",
type = "string",
enumeration = {
"None",
"Requested",
"Complete",
},
},
filename = {
access = "readOnly",
type = "string",
max = "256",
},
start = {
access = "readWrite",
type = "boolean",
}
}
}
}
SYSTEM_MODGUI_DEBUGLOG_.get = {
filename = function(mapping, param)
local handle = io.popen('find /tmp -type f -name "DebugHelper*"')
local filename = handle:read("*a")
filename = string.gsub(filename, '^%s+', '')
filename = string.gsub(filename, '%s+$', '')
filename = string.gsub(filename, '[\n\r]+', ' ')
handle:close()
return filename
end,
state = function(mapping, param)
local handle = io.popen('find /tmp -type f -name "DebugHelper*"')
local filename = handle:read("*a")
filename = string.gsub(filename, '^%s+', '')
filename = string.gsub(filename, '%s+$', '')
filename = string.gsub(filename, '[\n\r]+', ' ')
handle:close()
if filename ~= "" then
return "Complete"
end
handle = io.popen('find /tmp -type d -name "DebugHelper*"')
local filedir = handle:read("*a")
filename = string.gsub(filename, '^%s+', '')
filename = string.gsub(filename, '%s+$', '')
filedir = string.gsub(filedir, '[\n\r]+', ' ')
handle:close()
if filedir ~= "" then
return "Requested"
end
return "None"
end,
start = "0",
}
SYSTEM_MODGUI_DEBUGLOG_.set = {
start = function(mapping, paramName, paramValue)
if paramValue == "1" then
commitapply:newset("rpc.system.modgui.debuglog." .. paramName)
end
end,
}
register(SYSTEM_MODGUI_DEBUGLOG_)
local SYSTEM_MODGUI_SCRIPTREQUEST_ = {
objectType = {
name = 'rpc.system.modgui.scriptRequest.',
access = 'readOnly',
minEntries = 1,
maxEntries = 1,
parameters = {
state = {
access = "readWrite",
type = "string",
enumeration = {
"Not Requested",
"Requested",
"Complete",
},
}
}
}
}
upgradegui.scriptRequest = {}
SYSTEM_MODGUI_SCRIPTREQUEST_.get = {
state = function(mapping, param)
local result = upgradegui.scriptRequest.state
if ( upgradegui.scriptRequest.resetOnNextRequest == 1 ) then
upgradegui.scriptRequest.state = nil
end
return result or "Not Requested"
end
}
SYSTEM_MODGUI_SCRIPTREQUEST_.set = {
state = function(mapping, paramName, paramValue)
if ( paramValue == "Requested" ) then
upgradegui.scriptRequest.resetOnNextRequest = 0
upgradegui.scriptRequest.state = paramValue
elseif ( paramValue == "Complete" ) then
upgradegui.scriptRequest.resetOnNextRequest = 1
upgradegui.scriptRequest.state = paramValue
end
end,
}
register(SYSTEM_MODGUI_SCRIPTREQUEST_)
local SYSTEM_MODGUI_APP_ = {
objectType = {
name = 'rpc.system.modgui.app.',
access = 'readOnly',
minEntries = 1,
maxEntries = 1,
parameters = {
install_emptyblacklist = {
access = "readWrite",
type = "boolean",
}
}
}
}
SYSTEM_MODGUI_APP_.get = {
install_emptyblacklist = "0"
}
local app_list = {
"luci",
"aria2",
"transmission",
"blacklist",
"xupnp",
"telstra",
"amule",
"specific_app",
}
for _, app in ipairs(app_list) do
for _, action in ipairs({"install","remove","start","stop"}) do
SYSTEM_MODGUI_APP_.objectType.parameters[action.."_"..app] =
{
access = "readWrite",
type = "boolean",
}
SYSTEM_MODGUI_APP_.get[action.."_"..app] = "0"
end
end
SYSTEM_MODGUI_APP_.set = function(mapping, paramName, paramValue)
if paramValue == "1" then
commitapply:newset("rpc.system.modgui.app." .. paramName)
end
end
register(SYSTEM_MODGUI_APP_)