76 lines
2.0 KiB
Plaintext
76 lines
2.0 KiB
Plaintext
#!/usr/bin/ucode
|
|
|
|
'use strict';
|
|
|
|
import { access, popen } from 'fs';
|
|
import { get_users, get_groups, get_cgroups } from '/etc/nikki/ucode/include.uc';
|
|
|
|
const methods = {
|
|
version: {
|
|
call: function() {
|
|
let process;
|
|
let app = '';
|
|
if (system('command -v opkg') == 0) {
|
|
process = popen('opkg list-installed luci-app-nikki | cut -d " " -f 3');
|
|
if (process != null) {
|
|
app = trim(process.read('all'));
|
|
process.close();
|
|
}
|
|
} else if (system('command -v apk') == 0) {
|
|
process = popen('apk list -I luci-app-nikki | cut -d " " -f 1 | cut -d "-" -f 4');
|
|
if (process != null) {
|
|
app = trim(process.read('all'));
|
|
process.close();
|
|
}
|
|
}
|
|
let core = '';
|
|
process = popen('mihomo -v | grep Mihomo | cut -d " " -f 3');
|
|
if (process != null) {
|
|
core = trim(process.read('all'));
|
|
process.close();
|
|
}
|
|
return { app: app, core: core };
|
|
}
|
|
},
|
|
profile: {
|
|
call: function() {
|
|
let profile = {};
|
|
const filepath = '/etc/nikki/run/config.yaml';
|
|
if (access(filepath, 'r')) {
|
|
const process = popen(`yq -p yaml -o json < ${filepath}`);
|
|
if (process != null) {
|
|
profile = json(process.read('all'));
|
|
process.close();
|
|
}
|
|
}
|
|
return profile;
|
|
}
|
|
},
|
|
update_subscription: {
|
|
args: { section_id: 'section_id' },
|
|
call: function(req) {
|
|
let success = false;
|
|
const section_id = req.args?.section_id;
|
|
if (section_id) {
|
|
success = system(['service', 'nikki', 'update_subscription', section_id]) == 0;
|
|
}
|
|
return { success: success };
|
|
}
|
|
},
|
|
get_identifiers: {
|
|
call: function() {
|
|
const users = filter(get_users(), (x) => x != '' && x != 'root');
|
|
const groups = filter(get_groups(), (x) => x != '' && x != 'root');
|
|
const cgroups = filter(get_cgroups(), (x) => x != '' && x != 'nikki');
|
|
return { users: users, groups: groups, cgroups: cgroups };
|
|
}
|
|
},
|
|
debug: {
|
|
call: function() {
|
|
const success = system('/etc/nikki/scripts/debug.sh > /var/run/nikki/debug.md') == 0;
|
|
return { success: success };
|
|
}
|
|
}
|
|
};
|
|
|
|
return { 'luci.nikki': methods }; |