refactor: оптимизация хелперов бэкенда и очистка фронтенд-зависимостей

Проведен рефакторинг кодовой базы для устранения дублирования кода и оптимизации скриптов сборки:

- Бэкенд (ucode):
  - Перенесена функция экранирования шелл-аргументов `shell_quote` в общий модуль `core.common`.
  - Удалены дублирующиеся инлайновые объявления функций `as_string`, `shell_quote` и `read_json_file` из всех 23 файлов бэкенда. Вместо них настроен импорт из общего модуля `core.common`.
  - Валидация IP-адресов и CIDR в файле `core/helpers.uc` переведена на использование методов из модуля `core.ip` (`core_ip.valid_ipv4` и `core_ip.valid_ipv4_cidr`).
  - Проверка исполняемости файла (`test -x`) в скрипте `install.sh` заменена на нативную побитовую проверку прав через `fs.stat`.

- Локализация и сборка перевода:
  - Создан общий модуль `fe-app-forkop/locales-utils.js` для получения информации о пользователе Git (`getGitUser`) в скриптах перевода.
  - Из скриптов `generate-po.js` и `generate-pot.js` удалены локальные копии `getGitUser()`, они импортируют общую функцию.

- Зависимости Node.js фронтенда:
  - В скрипте `fe-app-forkop/watch-upload.js` стандартная библиотека `glob` заменена на `fast-glob`.
  - Устаревший пакет `glob` удален из `devDependencies` в `fe-app-forkop/package.json`.
This commit is contained in:
Dushnilin
2026-07-13 10:57:21 +03:00
parent 8b476cd145
commit e5c022c2c6
32 changed files with 396 additions and 903 deletions
+2 -10
View File
@@ -1,5 +1,5 @@
import fs from 'fs/promises';
import { execSync } from 'child_process';
import { getGitUser } from './locales-utils.js';
const lang = process.argv[2];
if (!lang) {
@@ -10,14 +10,6 @@ if (!lang) {
const callsPath = 'locales/calls.json';
const poPath = `locales/forkop.${lang}.po`;
function getGitUser() {
try {
return execSync('git config user.name').toString().trim();
} catch {
return 'Automatically generated';
}
}
function getHeader(lang) {
const now = new Date();
const date = now.toISOString().split('T')[0];
@@ -30,7 +22,7 @@ function getHeader(lang) {
return `${sign}${hours}${minutes}`;
})();
const translator = getGitUser();
const translator = getGitUser('Automatically generated').name;
const pluralForms = lang === 'ru'
? 'nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);'
: 'nplurals=2; plural=(n != 1);';
+1 -19
View File
@@ -1,28 +1,10 @@
import fs from 'fs/promises';
import { execSync } from 'child_process';
import { getGitUser } from './locales-utils.js';
const inputFile = 'locales/calls.json';
const outputFile = 'locales/forkop.pot';
const projectId = 'FORKOP';
function getGitUser() {
try {
const name = execSync('git config user.name', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
const email = execSync('git config user.email', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
if (name && email) {
return { name, email };
}
} catch (error) {
// Fall through to deterministic defaults when git identity is not configured.
}
return {
name: 'Forkop',
email: 'ushan0v@users.noreply.github.com',
};
}
function getPotHeader({ name, email }) {
const now = new Date();
const date = now.toISOString().replace('T', ' ').slice(0, 16);
+19
View File
@@ -0,0 +1,19 @@
import { execSync } from 'child_process';
export function getGitUser(defaultName = 'Forkop', defaultEmail = 'ushan0v@users.noreply.github.com') {
try {
const name = execSync('git config user.name', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
const email = execSync('git config user.email', { stdio: ['ignore', 'pipe', 'ignore'] }).toString().trim();
if (name) {
return { name, email: email || defaultEmail };
}
} catch (error) {
// Fall through
}
return {
name: defaultName,
email: defaultEmail,
};
}
-1
View File
@@ -29,7 +29,6 @@
"eslint": "9.36.0",
"eslint-config-prettier": "10.1.8",
"fast-glob": "3.3.3",
"glob": "11.0.3",
"prettier": "3.6.2",
"ssh2-sftp-client": "12.0.1",
"tsup": "8.5.0",
+2 -2
View File
@@ -3,7 +3,7 @@ import chokidar from 'chokidar';
import SFTPClient from 'ssh2-sftp-client';
import path from 'path';
import fs from 'fs';
import { glob } from 'glob';
import glob from 'fast-glob';
const sftp = new SFTPClient();
@@ -64,7 +64,7 @@ async function deleteFile(filePath, baseDir, remoteBase) {
async function uploadAllFiles() {
for (const { local, remote } of syncDirs) {
console.log(`📂 Uploading all from ${local}`);
const files = await glob(`${local}/**/*`, { nodir: true });
const files = await glob(`${local}/**/*`, { onlyFiles: true });
for (const file of files) {
await uploadFile(file, local, remote);
}
+282 -576
View File
File diff suppressed because it is too large Load Diff
+3 -7
View File
@@ -23,19 +23,15 @@ let lock_held = false;
let forkop_was_running = false;
let forkop_stopped_for_sing_box_change = false;
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function arg_bool(value) {
value = lc(as_string(value));
return value == "1" || value == "true" || value == "yes" || value == "on";
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
for (let arg in args)
+5 -23
View File
@@ -82,18 +82,11 @@ function singbox_rulesets_module() {
return singbox_rulesets_module_value;
}
function as_string(value) {
return value == null ? "" : "" + value;
}
function read_stdin() {
let data = fs.readfile("/dev/stdin");
return data == null ? "" : data;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
let read_stdin = common.read_stdin;
function command_from_args(args) {
let parts = [];
@@ -165,18 +158,7 @@ function log_message(message, level) {
command_success_from_args([ "logger", "-t", "forkop", "[" + level + "] " + as_string(message) ]);
}
function read_json_file(path) {
let data = fs.readfile(path);
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function write_json(value) {
print(sprintf("%J", value), "\n");
+2 -3
View File
@@ -11,6 +11,7 @@ let singbox_constants_module = require("singbox.constants");
let domain_config = require("config.domain");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
let write_json = common.write_json;
let option = common.option;
@@ -40,9 +41,7 @@ const CHILD_ITEM_TYPES = [
"urltest"
];
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_output(command) {
let pipe = fs.popen(command, "r");
+5 -17
View File
@@ -16,9 +16,10 @@ let connections = require("config.connections");
const CONFIG_NAME = getenv("FORKOP_CONFIG_NAME") || "forkop";
const DEFAULT_LATENCY_TEST_URL = "https://www.gstatic.com/generate_204";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function read_stdin() {
let input = fs.open("/dev/stdin", "r");
@@ -39,18 +40,7 @@ function read_stdin_json() {
}
}
function read_json_file(path) {
let data = fs.readfile(as_string(path));
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function string_starts_with(value, prefix) {
value = as_string(value);
@@ -154,9 +144,7 @@ function file_nonempty(path) {
return stat != null && stat.size != null && stat.size > 0;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
+5
View File
@@ -6,6 +6,10 @@ function as_string(value) {
return value == null ? "" : "" + value;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function read_json_file(path) {
let data = fs.readfile(path);
if (data == null)
@@ -130,6 +134,7 @@ function int_option(section, key, fallback) {
return {
as_string,
shell_quote,
read_json_file,
read_stdin,
read_stdin_json,
+3 -7
View File
@@ -1,18 +1,14 @@
#!/usr/bin/env ucode
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function env(name, fallback) {
let value = getenv(name);
return value == null ? as_string(fallback) : as_string(value);
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function constants_map() {
let c = {};
+5 -41
View File
@@ -15,9 +15,9 @@ const SB_SERVICE_MIXED_INBOUND_TAG = getenv("SB_SERVICE_MIXED_INBOUND_TAG") || "
const SB_DIRECT_OUTBOUND_TAG = getenv("SB_DIRECT_OUTBOUND_TAG") || "direct-out";
const SB_BYPASS_OUTBOUND_TAG = getenv("SB_BYPASS_OUTBOUND_TAG") || "bypass-out";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let core_ip = require("core.ip");
let as_string = common.as_string;
function ascii_lower(value) {
let upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -100,48 +100,12 @@ function write_compact_string_array(values) {
print("]\n");
}
function valid_ipv4_octet(value) {
value = as_string(value);
return match(value, /^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]?|0)$/) != null;
}
function valid_ipv4(value) {
value = as_string(value);
let trailing_dot = length(value) > 0 && substr(value, length(value) - 1) == ".";
if (trailing_dot)
value = substr(value, 0, length(value) - 1);
let parts = split(value, ".");
if (length(parts) != 4)
return false;
for (let part in parts)
if (!valid_ipv4_octet(part))
return false;
return true;
return core_ip.valid_ipv4(value, true, true);
}
function valid_ipv4_cidr(value) {
value = as_string(value);
let slash = index(value, "/");
if (slash < 0)
return false;
let ip = substr(value, 0, slash);
let mask = substr(value, slash + 1);
if (length(ip) > 0 && substr(ip, length(ip) - 1) == ".")
return false;
if (index(mask, "/") >= 0 || !valid_ipv4(ip))
return false;
if (mask == "" || match(mask, /[^0-9]/) != null)
return false;
let bits = int(mask);
return bits >= 0 && bits <= 32;
return core_ip.valid_ipv4_cidr(value, true);
}
function valid_domain(value) {
+3 -7
View File
@@ -2,13 +2,9 @@
let fs = require("fs");
function as_string(value) {
return value == null ? "" : "" + value;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function command_from_args(args) {
let parts = [];
+5 -18
View File
@@ -59,9 +59,10 @@ const BYEDPI_RUNTIME_UC = LIB_DIR + "/providers/byedpi/runtime.uc";
const ZAPRET_VALIDATOR_UC = LIB_DIR + "/providers/zapret/validator.uc";
const ZAPRET2_VALIDATOR_UC = LIB_DIR + "/providers/zapret2/validator.uc";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function arg_number(value) {
value = as_string(value);
@@ -73,10 +74,6 @@ function arg_bool(value) {
return value == "1" || value == "true" || value == "yes" || value == "on";
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
for (let arg in args)
@@ -199,17 +196,7 @@ function read_stdin() {
return data == null ? "" : as_string(data);
}
function read_json_file(path) {
let data = fs.readfile(as_string(path));
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function parse_json_or_null(value) {
try {
+3 -7
View File
@@ -7,13 +7,9 @@ const CONFIG_NAME = getenv("FORKOP_CONFIG_NAME") || "forkop";
const SB_DNS_INBOUND_ADDRESS = getenv("SB_DNS_INBOUND_ADDRESS") || "127.0.0.42";
const DNSMASQ_INIT = getenv("DNSMASQ_INIT") || "/etc/init.d/dnsmasq";
function as_string(value) {
return value == null ? "" : "" + value;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function run(command) {
return system(command) == 0;
+2 -7
View File
@@ -13,10 +13,7 @@ const CONFIG_NAME = getenv("FORKOP_CONFIG_NAME") || "forkop";
let common_read_json_file = common.read_json_file;
let list_option = common.list_option;
let bool_option = common.bool_option;
function as_string(value) {
return value == null ? "" : "" + value;
}
let as_string = common.as_string;
function arg_bool(value) {
value = lc(as_string(value));
@@ -99,9 +96,7 @@ function unlink_file(path) {
}
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let shell_quote = common.shell_quote;
function command_from_args(args) {
let parts = [];
@@ -20,9 +20,10 @@ const BYEDPI_OPEN_FILES_LIMIT = getenv("BYEDPI_OPEN_FILES_LIMIT") || "4096";
const BYEDPI_DEFAULT_CMD_OPTS = getenv("BYEDPI_DEFAULT_CMD_OPTS") || "-o 2 --auto=t,r,a,s -d 2";
const SB_TPROXY_INBOUND_TAG = getenv("SB_TPROXY_INBOUND_TAG") || "tproxy-in";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function bool_value(value) {
value = lc(as_string(value));
@@ -33,10 +34,6 @@ function write_json(value) {
print(sprintf("%J", value), "\n");
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
for (let arg in args)
@@ -432,17 +429,7 @@ function runtime_tag(base, postfix) {
return runtime_constants.tag(base, postfix);
}
function read_json_file(path) {
let data = fs.readfile(path);
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function value_contains(value, needle) {
if (type(value) == "array") {
@@ -10,9 +10,10 @@ const LIB_DIR = getenv("FORKOP_LIB") || "/usr/lib/forkop";
const SB_TPROXY_INBOUND_TAG = getenv("SB_TPROXY_INBOUND_TAG") || constants.SB_TPROXY_INBOUND_TAG || "tproxy-in";
const NFT_TABLE_NAME = getenv("NFT_TABLE_NAME") || constants.NFT_TABLE_NAME || "ForkopTable";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function bool_value(value) {
value = lc(as_string(value));
@@ -23,10 +24,6 @@ function write_json(value) {
print(sprintf("%J", value), "\n");
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
for (let arg in args)
@@ -495,17 +492,7 @@ function runtime_tag(base, postfix) {
return runtime_constants.tag(base, postfix);
}
function read_json_file(path) {
let data = fs.readfile(as_string(path));
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function value_contains(value, needle) {
if (type(value) == "array") {
+4 -18
View File
@@ -7,9 +7,10 @@ let uci = require("core.uci");
const CONFIG_NAME = getenv("FORKOP_CONFIG_NAME") || "forkop";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function ascii_lower(value) {
let upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -23,10 +24,6 @@ function write_json(value) {
print(sprintf("%J", value), "\n");
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function run(command) {
return system(command) == 0;
}
@@ -106,18 +103,7 @@ function server_set_option(section, option, value) {
SERVER_DEFAULTS_CHANGED = true;
}
function read_json_file(path) {
let data = fs.readfile(path);
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function read_stdin() {
let input = fs.open("/dev/stdin", "r");
+4 -6
View File
@@ -4,9 +4,9 @@ let fs = require("fs");
let constants = require("core.constants");
let uci_core = require("core.uci");
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function constant_value(name, fallback) {
let value = constants[name];
@@ -32,9 +32,7 @@ const CONFIG_CHANGE_REASON = getenv("FORKOP_CONFIG_CHANGE_REASON") || "on_config
const DNS_APPLY_UC = LIB_DIR + "/dns/apply.uc";
const UI_UC = LIB_DIR + "/service/ui.uc";
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function shell_assignment(name, value) {
print(as_string(name), "=", shell_quote(value), "\n");
+5 -17
View File
@@ -4,9 +4,10 @@ let fs = require("fs");
let constants = require("core.constants");
let uci_core = require("core.uci");
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function constant_value(name, fallback) {
let value = constants[name];
@@ -119,9 +120,7 @@ let nft_populate_enabled = NFT_POPULATE_ENABLED_DEFAULT;
let rule_condition_cache_enabled = 0;
let startup_config_fingerprint = "";
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
@@ -154,18 +153,7 @@ function command_output(command) {
return result.status == 0 ? result.output : "";
}
function read_json_file(path) {
let data = fs.readfile(as_string(path));
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function write_json(value) {
print(sprintf("%J", value), "\n");
+3 -7
View File
@@ -3,9 +3,9 @@
let fs = require("fs");
let uci_core = require("core.uci");
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function env(name, fallback) {
let value = getenv(name);
@@ -23,10 +23,6 @@ const SING_BOX_CRONET = env("FORKOP_SING_BOX_CRONET", "/usr/lib/libcronet.so");
const SING_BOX_MANAGED_MARKER = env("SB_MANAGED_SERVICE_MARKER", "Forkop managed sing-box service for binary variants");
const PACKAGE_TEST_MODE = env("FORKOP_PACKAGE_TEST_MODE", "") != "";
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
for (let arg in args)
+4 -20
View File
@@ -15,9 +15,10 @@ const ZAPRET_DEFAULT_NFQWS_OPT = getenv("ZAPRET_DEFAULT_NFQWS_OPT") || "";
const ZAPRET2_DEFAULT_NFQWS2_OPT = getenv("ZAPRET2_DEFAULT_NFQWS2_OPT") || "";
const BYEDPI_DEFAULT_CMD_OPTS = getenv("BYEDPI_DEFAULT_CMD_OPTS") || "";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function read_stdin() {
let input = fs.open("/dev/stdin", "r");
@@ -38,19 +39,6 @@ function read_stdin_json() {
}
}
function read_json_file(path) {
let data = fs.readfile(path);
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function write_text_file(path, text) {
let result = fs.writefile(path, as_string(text));
if (result == null)
@@ -68,10 +56,6 @@ function unlink_file(path) {
}
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
+4 -20
View File
@@ -34,9 +34,10 @@ const ZAPRET_PROVIDER_NFQWS_BIN = getenv("ZAPRET_PROVIDER_NFQWS_BIN") || "/opt/z
const ZAPRET2_PROVIDER_NFQWS2_BIN = getenv("ZAPRET2_PROVIDER_NFQWS2_BIN") || "/opt/zapret2/nfq2/nfqws2";
const BYEDPI_BIN = getenv("BYEDPI_BIN") || "/usr/bin/ciadpi";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
let read_json_file = common.read_json_file;
function read_stdin() {
let input = fs.open("/dev/stdin", "r");
@@ -47,19 +48,6 @@ function read_stdin() {
return data == null ? "" : data;
}
function read_json_file(path) {
let data = fs.readfile(path);
if (data == null)
return null;
try {
return json(data);
}
catch (e) {
return null;
}
}
function parse_json_or_null(value) {
try {
return json(as_string(value));
@@ -77,10 +65,6 @@ function json_text(value) {
return sprintf("%J", value) + "\n";
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
+1 -3
View File
@@ -10,9 +10,7 @@ let object_or_empty = common.object_or_empty;
const COUNTRY_IS_URL = getenv("FORKOP_COUNTRY_IS_URL") || "https://api.country.is/";
const COUNTRY_IS_BATCH_SIZE = 100;
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let shell_quote = common.shell_quote;
function command_from_args(args) {
let parts = [];
+2 -7
View File
@@ -15,13 +15,8 @@ const DNS_FAILOVER_UC = getenv("FORKOP_DNS_FAILOVER_UC") || LIB_DIR + "/singbox/
const SERVICE_BIN = getenv("FORKOP_BIN") || "/usr/bin/forkop";
const CHECK_DOMAIN = "example.com";
function as_string(value) {
return value == null ? "" : "" + value;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function command_from_args(args) {
let result = [];
+1 -3
View File
@@ -16,9 +16,7 @@ const PRIORITY_PID_FILE = getenv("FORKOP_PRIORITY_PID_FILE") || RUNTIME_STATE_DI
const PRIORITY_UC = getenv("FORKOP_PRIORITY_UC") || LIB_DIR + "/singbox/priority.uc";
const DIAGNOSTICS_UC = getenv("FORKOP_DIAGNOSTICS_UC") || LIB_DIR + "/diagnostics/runtime.uc";
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let shell_quote = common.shell_quote;
function command_from_args(args) {
let parts = [];
+2 -7
View File
@@ -38,13 +38,8 @@ const SB_VARIANT_STATE_FILE = getenv("SB_VARIANT_STATE_FILE") || "/etc/forkop/si
const SB_VERSION_STATE_FILE = getenv("SB_VERSION_STATE_FILE") || "/etc/forkop/sing-box-version";
const SB_MANAGED_SERVICE_MARKER = getenv("SB_MANAGED_SERVICE_MARKER") || "Forkop managed sing-box service for binary variants";
function as_string(value) {
return value == null ? "" : "" + value;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function command_from_args(args) {
let parts = [];
+4 -6
View File
@@ -31,9 +31,9 @@ const ZAPRET_PROVIDER_NFQWS_BIN = getenv("ZAPRET_PROVIDER_NFQWS_BIN") || "/opt/z
const ZAPRET2_PROVIDER_NFQWS2_BIN = getenv("ZAPRET2_PROVIDER_NFQWS2_BIN") || "/opt/zapret2/nfq2/nfqws2";
const BYEDPI_BIN = getenv("BYEDPI_BIN") || "/usr/bin/ciadpi";
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function read_stdin() {
let data = fs.readfile("/dev/stdin");
@@ -531,9 +531,7 @@ function files_equal(left, right) {
return left_data != null && right_data != null && left_data == right_data;
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function command_from_args(args) {
let parts = [];
+3 -7
View File
@@ -2,9 +2,9 @@
let fs = require("fs");
function as_string(value) {
return value == null ? "" : "" + value;
}
let common = require("core.common");
let as_string = common.as_string;
let shell_quote = common.shell_quote;
function trim(value) {
value = as_string(value);
@@ -2752,10 +2752,6 @@ function temp_path(prefix) {
return sprintf("/tmp/%s.%d.%d", prefix, stamp[0], stamp[1]);
}
function shell_quote(value) {
return "'" + replace(as_string(value), /'/g, "'\\''") + "'";
}
function gzip_decode_file(input_file, output_file) {
if (as_string(input_file) == "" || as_string(output_file) == "" || !fs.stat(input_file))
return false;
+2 -1
View File
@@ -489,7 +489,8 @@ function path_exists(path) {
}
function path_executable(path) {
return run_args([ "test", "-x", path ]);
let stat = fs.stat(as_string(path));
return stat != null && stat.mode != null && (int(stat.mode) & 73) != 0;
}
function remove_path(path) {