🎉 Sync 2026-09-27 21:03:26

This commit is contained in:
github-actions[bot] committed 2026-09-27 21:03:26 +08:00
1 parent f4559bbed1
commit 065763f7fd
673 files changed
+261285 -34160

No files matched your search

@@ -0,0 +1,78 @@
'use strict';
let values = {
enabled: '0',
debug: '0',
download_retry: '3',
statistics_enabled: '1',
license_key: 'abcd1234wxyz',
device_vendor: 'Junatum',
device_model: 'Test Router',
device_arch: 'aarch64',
device_memory_mb: '256'
};
const CONFIG_SPEC = {
debug: { kind: 'bool', def: false },
download_retry: { kind: 'int', def: 3, min: 1, max: 100 },
statistics_enabled: { kind: 'bool', def: true }
};
function to_bool(v, def) {
if (v == null) return def;
let s = sprintf('%s', v);
if (s == '1' || s == 'true' || s == 'yes' || s == 'on') return true;
if (s == '0' || s == 'false' || s == 'no' || s == 'off') return false;
return def;
}
function to_int(v, def) {
if (v == null || v == '') return def;
let n = int(v);
return type(n) == 'int' ? n : def;
}
function mask_secret(v) {
let s = sprintf('%s', v || '');
if (!length(s)) return '';
if (length(s) <= 8) return '********';
return sprintf('%s...%s', substr(s, 0, 4), substr(s, length(s) - 4));
}
function api_error(code, message, field) {
let error = { code: code, message: message };
if (field) error.field = field;
return { ok: false, error: error };
}
let uci = {
set: function(pkg, section, name, value) {
values[name] = value;
return true;
},
commit: function() { return true; },
revert: function() { return true; }
};
function uci_commit_option(name, value) {
values[name] = sprintf('%s', value);
return true;
}
return {
uci: uci,
PKG_NAME: 'safeshield',
CONFIG_SCHEMA_NAME: 'safeshield.config',
CONFIG_SCHEMA_VERSION: 1,
CONFIG_SPEC: CONFIG_SPEC,
values: values,
reload_uci: function() { return true; },
cfg: function(name, def) { return values[name] == null ? def : values[name]; },
to_bool: to_bool,
to_int: to_int,
mask_secret: mask_secret,
api_error: api_error,
uci_commit_option: uci_commit_option,
bool_uci: function(v) { return v ? '1' : '0'; }
};
@@ -0,0 +1,22 @@
'use strict';
let state = {
last_action: '',
refresh_count: 0,
service_ok: true,
service_rc: 0,
refresh_accepted: true,
refresh_reason: ''
};
return {
state: state,
run_service_action: function(action) {
state.last_action = action;
return { ok: state.service_ok, rc: state.service_rc };
},
start_refresh_async: function() {
state.refresh_count++;
return { accepted: state.refresh_accepted, reason: state.refresh_reason };
}
};
+16
View File
@@ -0,0 +1,16 @@
'use strict';
function cursor() {
return {
load: function() { return true; },
get: function() { return null; },
set: function() { return true; },
delete: function() { return true; },
commit: function() { return true; },
revert: function() { return true; }
};
}
return {
cursor: cursor
};
@@ -0,0 +1,43 @@
'use strict';
let state = {
license_key: 'existing-license-key',
commits: 0,
deletes: 0
};
function trim(s) {
return replace(s, /^[\r\n\t ]+|[\r\n\t ]+$/g, '');
}
function mask_secret(v) {
let s = sprintf('%s', v || '');
if (!length(s)) return '';
if (length(s) <= 8) return '********';
return sprintf('%s...%s', substr(s, 0, 4), substr(s, length(s) - 4));
}
function api_error(code, message, field) {
let error = { code: code, message: message };
if (field) error.field = field;
return { ok: false, error: error };
}
return {
state: state,
reload_uci: function() { return true; },
cfg: function(name, def) { return name == 'license_key' ? state.license_key : def; },
trim: trim,
mask_secret: mask_secret,
api_error: api_error,
uci_commit_option: function(name, value) {
state.license_key = value;
state.commits++;
return true;
},
uci_delete_option: function(name) {
state.license_key = '';
state.deletes++;
return true;
}
};
@@ -0,0 +1,14 @@
'use strict';
let state = { refresh_count: 0, statistics_reset_count: 0, accepted: true, reason: '' };
return {
state: state,
reset_statistics_upload_state: function() {
state.statistics_reset_count++;
},
start_refresh_async: function() {
state.refresh_count++;
return { accepted: state.accepted, reason: state.reason };
}
};
@@ -0,0 +1,10 @@
'use strict';
let state = { accepted: true, reason: '' };
return {
state: state,
start_refresh_async: function() {
return { accepted: state.accepted, reason: state.reason };
}
};
@@ -0,0 +1,8 @@
'use strict';
let state = { value: 'test-status' };
return {
state: state,
build: function() { return { marker: state.value }; }
};
@@ -0,0 +1,32 @@
'use strict';
function trim(s) {
return replace(s, /^[\r\n\t ]+|[\r\n\t ]+$/g, '');
}
function to_bool(v, def) {
if (v == null) return def;
let s = sprintf('%s', v);
if (s == '1' || s == 'true' || s == 'yes' || s == 'on') return true;
if (s == '0' || s == 'false' || s == 'no' || s == 'off') return false;
return def;
}
function api_error(code, message, field) {
let error = { code: code, message: message };
if (field) error.field = field;
return { ok: false, error: error };
}
return {
LOCAL_ALLOWLIST_FILE: sprintf('%s/allowlist', TEST_TMP),
LOCAL_BLOCKLIST_FILE: sprintf('%s/blocklist', TEST_TMP),
RULES_SCHEMA_NAME: 'safeshield.rules',
RULES_SCHEMA_VERSION: 1,
RULES_DIR: TEST_TMP,
trim: trim,
reload_uci: function() { return true; },
cfg: function(name, def) { return name == 'apply_local_overrides' ? '1' : def; },
to_bool: to_bool,
api_error: api_error
};
@@ -0,0 +1,11 @@
'use strict';
let state = { apply_count: 0, accepted: true, reason: '' };
return {
state: state,
start_local_apply_async: function() {
state.apply_count++;
return { accepted: state.accepted, reason: state.reason };
}
};
@@ -0,0 +1,31 @@
'use strict';
let values = {
enabled: '1',
apply_local_overrides: '1'
};
let state = {
status: { data: { status: 'idle' } },
reloads: 0
};
function to_bool(v, def) {
if (v == null) return def;
let s = sprintf('%s', v);
if (s == '1' || s == 'true' || s == 'yes' || s == 'on') return true;
if (s == '0' || s == 'false' || s == 'no' || s == 'off') return false;
return def;
}
return {
PKG_NAME: 'safeshield',
STATUS_FILE: sprintf('%s/status.json', TEST_TMP),
SERVICE_INIT: '/bin/true',
values: values,
state: state,
read_json_file: function() { return state.status; },
to_bool: to_bool,
reload_uci: function() { state.reloads++; return true; },
cfg: function(name, def) { return values[name] == null ? def : values[name]; }
};
@@ -0,0 +1,27 @@
'use strict';
let state = {
services: {}
};
function connect() {
return {
call: function(object, method, args) {
if (object != 'service' || method != 'list' || !args || !args.name) {
return null;
}
let result = {};
let service = state.services[args.name];
if (service != null) {
result[args.name] = service;
}
return result;
}
};
}
return {
state: state,
connect: connect
};
@@ -0,0 +1,80 @@
'use strict';
let config = {
statistics_enabled: '1',
statistics_retention_hours: '24',
statistics_snapshot_interval_s: '30'
};
let data = {
schema: { name: 'collector' },
generation_id: 'generation-test',
snapshot_seq: '42',
volatile: '0',
storage: 'tmpfs+flash',
persistent: '1',
persistence_enabled: '1',
persistence_healthy: '1',
persistence_mode: 'journal',
persistent_error_count: '2',
persistent_last_error_at: '190',
persistent_updated_at: '195',
persistent_checkpoint_interval_s: '3600',
persistent_compacted_at: '180',
persistent_compact_interval_s: '604800',
started_at: '100',
session_started_at: '150',
updated_at: '200',
totals: { queries: '120', blocked: '12' },
source: {
backend: 'dnsmasq_ubus',
available: '1',
instance_id: 'epoch-test',
transport_scope: 'udp',
client_capacity: '128',
tracked_clients: '2',
untracked_queries: '3',
untracked_blocked: '2',
poll_error_count: '4',
last_error_at: '199'
},
hourly: [
{ bucket_start: '10', queries: '20', blocked: '2' },
'invalid',
{ bucket_start: 20, queries: 30, blocked: 3 }
],
device_limit: '128',
devices_truncated: '1',
devices: [
{ id: 'aa:bb', mac: 'AA:BB', ip: '192.0.2.10', hostname: 'phone', identified: '1', queries: '50', blocked: '5' },
{ id: '', ip: '192.0.2.11', queries: 10 },
'invalid'
]
};
function to_bool(v, def) {
if (v == null) return def;
let s = sprintf('%s', v);
if (s == '1' || s == 'true' || s == 'yes' || s == 'on') return true;
if (s == '0' || s == 'false' || s == 'no' || s == 'off') return false;
return def;
}
function to_int(v, def) {
if (v == null || v == '') return def;
let n = int(v);
return type(n) == 'int' ? n : def;
}
return {
PKG_NAME: 'safeshield',
STATISTICS_SCHEMA_NAME: 'safeshield.statistics',
STATISTICS_SCHEMA_VERSION: 3,
STATISTICS_FILE: '/tmp/statistics.json',
data: data,
reload_uci: function() { return true; },
cfg: function(name, def) { return config[name] == null ? def : config[name]; },
read_json_file: function() { return data; },
to_bool: to_bool,
to_int: to_int
};
@@ -0,0 +1,7 @@
'use strict';
return {
service_instance_running: function(name, instance) {
return name == 'safeshield' && instance == 'statistics';
}
};
@@ -0,0 +1,98 @@
'use strict';
let config = {
enabled: '1',
refresh_on_boot: '1',
require_wan: '1',
refresh_interval_s: '28800',
boot_start_delay_s: '30',
license_key: 'abcd1234wxyz',
apply_local_overrides: '1',
device_vendor: 'Junatum',
device_model: 'Test Router',
device_arch: 'aarch64',
device_memory_mb: '256'
};
let identity = {
physical_fingerprint: 'fingerprint',
fingerprint_version: '1',
identity_provider: 'factory-mac',
identity_source: 'eth0',
identity_strength: 'strong',
identity_profile: 'test-profile',
device_code: 'xiaomi-ax3000t',
device_code_source: 'smartsafehub_firmware',
installation_id: 'install-id'
};
let state = {
data: {
status: 'ready',
valid_line_count: '42000',
artifact_tier: 'pro',
artifact_version: '20260830T000000Z',
artifact_unique_domains: '41000',
artifact_source_count: '2',
artifact_block_source_count: '1',
artifact_allow_source_count: '1',
health_api_resolve: '1',
health_artifact_download: '1',
health_dns_runtime: '1',
blocklist_installed: '1',
blocklist_file_size_kb: '2048',
license_plan: 'pro',
license_status: 'active'
},
warnings: [],
errors: []
};
function to_bool(v, def) {
if (v == null) return def;
let s = sprintf('%s', v);
if (s == '1' || s == 'true' || s == 'yes' || s == 'on') return true;
if (s == '0' || s == 'false' || s == 'no' || s == 'off') return false;
return def;
}
function to_optional_bool(v) {
if (v == null || v == '') return null;
return to_bool(v, null);
}
function to_int(v, def) {
if (v == null || v == '') return def;
let n = int(v);
return type(n) == 'int' ? n : def;
}
function mask_secret(v) {
let s = sprintf('%s', v || '');
if (!length(s)) return '';
if (length(s) <= 8) return '********';
return sprintf('%s...%s', substr(s, 0, 4), substr(s, length(s) - 4));
}
return {
PKG_NAME: 'safeshield',
PKG_VERSION: '0.3.16-r4',
STATUS_FILE: '/tmp/status.json',
BLOCKLIST_FILE: '/tmp/blocklist',
LOCAL_ALLOWLIST_FILE: '/etc/safeshield/allowlist',
LOCAL_BLOCKLIST_FILE: '/etc/safeshield/blocklist',
SCHEMA_NAME: 'safeshield.status',
SCHEMA_VERSION: 1,
state: state,
config: config,
reload_uci: function() { return true; },
cfg: function(name, def) { return config[name] == null ? def : config[name]; },
identity_cfg: function(name, def) { return identity[name] == null ? def : identity[name]; },
read_json_file: function() { return state; },
file_exists: function() { return false; },
file_size_kb: function() { return 0; },
to_bool: to_bool,
to_optional_bool: to_optional_bool,
to_int: to_int,
mask_secret: mask_secret
};
@@ -0,0 +1,9 @@
'use strict';
let state = { service_running: true, dnsmasq_running: true };
return {
state: state,
service_running: function() { return state.service_running; },
dnsmasq_running: function() { return state.dnsmasq_running; }
};