mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 16:44:23 +08:00
🤞 Sync 2026-09-27 22:16:29
This commit is contained in:
1 parent
8ede4a8320
commit
618f51e9dc
459 files changed
+44817
-2191
No files matched your search
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"admin/services/wolplus": {
|
||||
"title": "Wake on LAN +",
|
||||
"order": 95,
|
||||
"action": {
|
||||
"type": "view",
|
||||
"path": "wolplus"
|
||||
},
|
||||
"depends": {
|
||||
"acl": [ "luci-app-wolplus" ],
|
||||
"fs": { "/etc/config/wolplus": "file" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,16 @@
|
||||
"luci-app-wolplus": {
|
||||
"description": "Grant UCI access for luci-app-wolplus",
|
||||
"read": {
|
||||
"ubus": {
|
||||
"luci.wolplus": [ "awake" ],
|
||||
"luci-rpc": [ "getHostHints", "getNetworkDevices" ]
|
||||
},
|
||||
"uci": [ "wolplus" ]
|
||||
},
|
||||
"write": {
|
||||
"ubus": {
|
||||
"luci.wolplus": [ "awake" ]
|
||||
},
|
||||
"uci": [ "wolplus" ]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/ucode
|
||||
|
||||
'use strict';
|
||||
|
||||
import { popen } from 'fs';
|
||||
import { cursor } from 'uci';
|
||||
|
||||
const etherwake = '/usr/bin/etherwake';
|
||||
|
||||
function shellquote(s) {
|
||||
return "'" + replace(s, "'", "'\\''") + "'";
|
||||
}
|
||||
|
||||
const methods = {
|
||||
awake: {
|
||||
args: { section: 'string' },
|
||||
call: function(request) {
|
||||
const section = request.args.section;
|
||||
if (!section || match(section, /[^A-Za-z0-9_]/))
|
||||
return { data: 'invalid section' };
|
||||
|
||||
let ctx = cursor();
|
||||
let lan = ctx.get('wolplus', section, 'maceth') || '';
|
||||
let mac = ctx.get('wolplus', section, 'macaddr') || '';
|
||||
|
||||
if (!mac)
|
||||
return { data: 'missing MAC address' };
|
||||
|
||||
let cmd = etherwake + ' -D' +
|
||||
(lan ? ' -i ' + shellquote(lan) : '') +
|
||||
' -b ' + shellquote(mac) + ' 2>&1';
|
||||
|
||||
const fd = popen(cmd);
|
||||
let out = fd.read('all') || '';
|
||||
fd.close();
|
||||
|
||||
if (length(out) > 500)
|
||||
out = substr(out, 0, 500) + '...';
|
||||
|
||||
return { data: out };
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return { 'luci.wolplus': methods };
|
||||
Reference in new issue
Block a user