🐶 Sync 2025-11-02 14:26:26

This commit is contained in:
actions-user
2025-11-02 14:26:26 +08:00
parent 64bcc56c2a
commit ac011db799
1557 changed files with 746465 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
{
"admin/services/nikki": {
"title": "Nikki",
"action": {
"type": "firstchild"
},
"depends": {
"acl": [ "luci-app-nikki" ],
"uci": { "nikki": true }
}
},
"admin/services/nikki/config": {
"title": "App Config",
"order": 10,
"action": {
"type": "view",
"path": "nikki/app"
}
},
"admin/services/nikki/profile": {
"title": "Profile",
"order": 20,
"action": {
"type": "view",
"path": "nikki/profile"
}
},
"admin/services/nikki/mixin": {
"title": "Mixin Config",
"order": 30,
"action": {
"type": "view",
"path": "nikki/mixin"
}
},
"admin/services/nikki/proxy": {
"title": "Proxy Config",
"order": 40,
"action": {
"type": "view",
"path": "nikki/proxy"
}
},
"admin/services/nikki/editor": {
"title": "Editor",
"order": 50,
"action": {
"type": "view",
"path": "nikki/editor"
}
},
"admin/services/nikki/log": {
"title": "Log",
"order": 60,
"action": {
"type": "view",
"path": "nikki/log"
}
}
}

View File

@@ -0,0 +1,37 @@
{
"luci-app-nikki": {
"description": "Grant access to nikki procedures",
"read": {
"uci": [ "nikki" ],
"ubus": {
"rc": [ "*" ],
"luci.nikki": [ "*" ]
},
"file": {
"/etc/nikki/profiles/*.yaml": ["read"],
"/etc/nikki/profiles/*.yml": ["read"],
"/etc/nikki/subscriptions/*.yaml": ["read"],
"/etc/nikki/subscriptions/*.yml": ["read"],
"/etc/nikki/mixin.yaml": ["read"],
"/etc/nikki/run/config.yaml": ["read"],
"/etc/nikki/run/providers/rule/*": ["read"],
"/etc/nikki/run/providers/proxy/*": ["read"],
"/var/log/nikki/*.log": ["read"]
}
},
"write": {
"uci": [ "nikki" ],
"file": {
"/etc/nikki/profiles/*.yaml": ["write"],
"/etc/nikki/profiles/*.yml": ["write"],
"/etc/nikki/subscriptions/*.yaml": ["write"],
"/etc/nikki/subscriptions/*.yml": ["write"],
"/etc/nikki/mixin.yaml": ["write"],
"/etc/nikki/run/config.yaml": ["write"],
"/etc/nikki/run/providers/rule/*": ["write"],
"/etc/nikki/run/providers/proxy/*": ["write"],
"/var/log/nikki/*.log": ["write"]
}
}
}
}

View File

@@ -0,0 +1,110 @@
#!/usr/bin/ucode
'use strict';
import { access, popen, writefile } from 'fs';
import { get_users, get_groups, get_cgroups, load_profile } 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) {
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) {
app = trim(process.read('all'));
process.close();
}
}
let core = '';
process = popen('mihomo -v | grep Mihomo | cut -d " " -f 3');
if (process) {
core = trim(process.read('all'));
process.close();
}
return { app: app, core: core };
}
},
profile: {
args: { defaults: {} },
call: function(req) {
let profile = {};
const defaults = req.args?.defaults ?? {};
const filepath = '/etc/nikki/run/config.yaml';
const tmpFilepath = '/var/run/nikki/profile.json';
if (access(filepath, 'r')) {
writefile(tmpFilepath, defaults);
const command = `yq -p yaml -o json eval-all 'select(fi == 0) *? select(fi == 1)' ${tmpFilepath} ${filepath}`;
const process = popen(command);
if (process) {
profile = json(process);
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 };
}
},
api: {
args: { method: 'method', path: 'path', query: 'query', body: 'body' },
call: function(req) {
let result = {};
const method = req.args?.method;
const path = req.args?.path;
const query = req.args?.query;
const body = req.args?.body;
const profile = load_profile();
const api_listen = profile['external-controller'];
const api_secret = profile['secret'];
if (!api_listen) {
return result;
}
const url = api_listen + path;
const process = popen(`curl --request '${method}' --oauth2-bearer '${api_secret}' --url-query '${query}' --data '${body}' '${url}'`);
if (process) {
result = json(process);
process.close();
}
return result;
}
},
get_identifiers: {
call: function() {
const users = filter(get_users(), (x) => x != '');
const groups = filter(get_groups(), (x) => x != '');
const cgroups = filter(get_cgroups(), (x) => x != '' && index(x, 'services/nikki') < 0);
return { users: users, groups: groups, cgroups: cgroups };
}
},
debug: {
call: function() {
const success = system('/etc/nikki/scripts/debug.sh > /var/log/nikki/debug.log') == 0;
return { success: success };
}
}
};
return { 'luci.nikki': methods };