Sync 2024-09-24 22:25:11

This commit is contained in:
github-actions[bot] 2024-09-24 22:25:11 +08:00
parent 60286d4c17
commit 253317ffd7
4 changed files with 146 additions and 20 deletions

View File

@ -61,58 +61,62 @@ return view.extend({
o = s.taboption('basic', form.Flag, 'enabled', _('Enable'), _('Enable apfree-wifidog service.'));
o.rmempty = false;
o = s.taboption('basic', form.Flag, 'no_auth_server', _('No Auth Server'), _('Do not use authentication server.'));
o.rmempty = false;
o = s.taboption('basic', form.ListValue, 'auth_server_mode', _('Auth Server Mode'),
_('The mode of the authentication server.'));
o.value('cloud', _('Cloud Auth'));
o.value('local', _('Local Auth'));
o.defaulValue = 'cloud';
o.optional = false;
o = s.taboption('basic', form.Value, 'device_id', _('Device ID'), _('The ID of the device.'));
o.depends('no_auth_server', '0');
o.rmempty = false;
o.datatype = 'string';
o.optional = false;
o.depends('auth_server_mode', 'cloud');
o = s.taboption('basic', form.Value, 'auth_server_hostname', _('Auth Server Hostname'),
_('The domain or IP address of the authentication server.'));
o.depends('no_auth_server', '0');
o.rmempty = false;
o.datatype = 'or(host,ip4addr)';
o.optional = false;
o.depends('auth_server_mode', 'cloud');
o = s.taboption('basic', form.Value, 'auth_server_port', _('Auth Server Port'),
_('The port of the authentication server.'));
o.depends('no_auth_server', '0');
o.rmempty = false;
o.datatype = 'port';
o.optional = false;
o.depends('auth_server_mode', 'cloud');
o = s.taboption('basic', form.Value, 'auth_server_path', _('Auth Server URI path'),
_('The URI path of the authentication server.'));
o.depends('no_auth_server', '0');
o.rmempty = false;
o.datatype = 'string';
o.optional = false;
o.depends('auth_server_mode', 'cloud');
o = s.taboption('basic', form.FileUpload, 'auth_server_offline_page', _('Upload offline Page'),
_('The offline page of the authentication server.'));
o.depends('no_auth_server', '1');
o.rmempty = false;
o.optional = true
o.datatype = 'file';
o.root_directory = '/etc/wifidogx';
o.depends('auth_server_mode', 'local');
o = s.taboption('basic', form.Value, 'auth_server_offline_file', _('Offline Page Full Path'),
_('The full path of the uploaded offline page.'));
o.depends('no_auth_server', '1');
o.rmempty = false;
o.datatype = 'string';
o.optional = true;
o.placeholder = '/etc/wifidogx/';
o.depends('auth_server_mode', 'local');
o = s.taboption('basic', form.Value, 'local_portal', _('Local Portal'),
_('The local portal url.'));
o.depends('no_auth_server', '1');
o.rmempty = false;
o.datatype = 'string';
o.optional = true;
o.depends('auth_server_mode', 'local');
o = s.taboption('basic', form.ListValue, 'log_level', _('Log Level'),
_('The log level of the apfree-wifidog.'));
@ -157,31 +161,68 @@ return view.extend({
// advanced settings
o = s.taboption('advanced', form.Flag, 'enable_websocket', _('Enable WebSocket'),
_('Enable websocket support.'));
o = s.taboption('advanced', form.ListValue, 'long_conn_mode', _('Persistent Connection Mode'),
_('The persistent connection mode of the device to auth server.'));
o.value('ws', _('WebSocket Connection Mode'));
o.value('wss', _('WebSocket Secure Connection Mode'));
o.value('mqtt', _('MQTT Connection Mode'));
o.value('none', _('None'));
o.rmempty = false;
o.defaulValue = true;
o.defaulValue = 'ws';
o.optional = false;
o = s.taboption('advanced', form.Value, 'ws_server_hostname', _('WebSocket Hostname'),
_('The hostname of the websocket, if the field is left empty, automatically use the same hostname as the auth server.'));
o.datatype = 'or(host,ip4addr)';
o.rmempty = true;
o.optional = true;
o.depends('enable_websocket', '1');
o.depends('long_conn_mode', 'ws');
o.depends('long_conn_mode', 'wss');
o = s.taboption('advanced', form.Value, 'ws_server_port', _('WebSocket Port'),
_('The port of the websocket, if the field is left empty, automatically use the same port as the auth server.'));
o.datatype = 'port';
o.rmempty = true;
o.depends('enable_websocket', '1');
o.optional = true;
o.depends('long_conn_mode', 'ws');
o.depends('long_conn_mode', 'wss');
o = s.taboption('advanced', form.Value, 'ws_server_path', _('WebSocket URI path'),
_('The URI path of the websocket.'));
o.datatype = 'string';
o.rmempty = true;
o.depends('enable_websocket', '1');
o.optional = true;
o.depends('long_conn_mode', 'ws');
o.depends('long_conn_mode', 'wss');
o = s.taboption('advanced', form.Value, 'mqtt_server_hostname', _('MQTT Hostname'),
_('The hostname of the mqtt.'));
o.datatype = 'or(host,ip4addr)';
o.rmempty = true;
o.optional = true;
o.depends('long_conn_mode', 'mqtt');
o = s.taboption('advanced', form.Value, 'mqtt_server_port', _('MQTT Port'),
_('The port of the mqtt.'));
o.datatype = 'port';
o.rmempty = false;
o.optional = false;
o.depends('long_conn_mode', 'mqtt');
o.defaulValue = 1883;
o = s.taboption('advanced', form.Value, 'mqtt_username', _('MQTT Username'),
_('The username of the mqtt.'));
o.datatype = 'string';
o.rmempty = true;
o.optional = true;
o.depends('long_conn_mode', 'mqtt');
o = s.taboption('advanced', form.Value, 'mqtt_password', _('MQTT Password'),
_('The password of the mqtt.'));
o.datatype = 'string';
o.rmempty = true;
o.optional = true;
o.depends('long_conn_mode', 'mqtt');
o = s.taboption('advanced', form.Flag, 'enable_dns_forward', _('Enable Wildcard Domain'),
_('Enable wildcard domain support.'));

View File

@ -262,4 +262,57 @@ msgid "WebSocket URI path"
msgstr "Websocket URI 路径"
msgid "The URI path of the websocket."
msgstr "Websocket 的 URI 路径"
msgstr "Websocket 的 URI 路径"
msgid "Auth Server Mode"
msgstr "认证服务器模式"
msgid "The mode of the authentication server."
msgstr "认证服务器是云认证还是本地认证"
msgid "Cloud Auth"
msgstr "云认证"
msgid "Local Auth"
msgstr "本地认证"
msgid "Persistent Connection Mode"
msgstr "持久连接模式"
msgid "The persistent connection mode of the device to auth server."
msgstr "设备到认证服务器的持久连接模式"
msgid "WebSocket Connection Mode"
msgstr "Websocket 连接模式"
msgid "WebSocket Secure Connection Mode"
msgstr "Websocket 安全连接模式"
msgid "MQTT Connection Mode"
msgstr "MQTT 连接模式"
msgid "MQTT Hostname"
msgstr "MQTT 主机名"
msgid "The hostname of the mqtt."
msgstr "mqtt 的主机名"
msgid "MQTT Port"
msgstr "MQTT 端口"
msgid "The port of the mqtt."
msgstr "mqtt 的端口"
msgid "MQTT Username"
msgstr "MQTT 用户名"
msgid "The username of the mqtt."
msgstr "mqtt 的用户名"
msgid "MQTT Password"
msgstr "MQTT 密码"
msgid "The password of the mqtt."
msgstr "mqtt 的密码"

View File

@ -7,7 +7,7 @@ include $(TOPDIR)/rules.mk
PKG_MAINTAINER:=Thaolga <https://github.com/Thaolga/luci-app-nekoclash>
PKG_NAME:=luci-app-nekoclash
PKG_VERSION:=1.3.5
PKG_RELEASE:=47
PKG_RELEASE:=48
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)

View File

@ -313,6 +313,7 @@ $lang = $_GET['lang'] ?? 'en';
<tbody>
<tr>
<?php
date_default_timezone_set('Asia/Shanghai');
$singbox_status = 0;
$logDir = '/etc/neko/tmp/';
@ -459,6 +460,35 @@ function createStartScript($configFile) {
chmod('/etc/neko/core/start.sh', 0755);
}
function createRestartFirewallScript() {
$scriptPath = '/etc/neko/core/restart_firewall.sh';
$scriptContent = <<<EOF
#!/bin/bash
service firewall restart
if [ \$? -eq 0 ]; then
echo "[\$(date '+%H:%M:%S')] Restarting Firewall." >> /etc/neko/tmp/log.txt
else
echo "[\$(date '+%H:%M:%S')] Firewall restart failed." >> /etc/neko/tmp/log.txt
fi
EOF;
$result = file_put_contents($scriptPath, $scriptContent);
if ($result === false) {
error_log("Failed to create script at $scriptPath");
} else {
chmod($scriptPath, 0755);
}
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['singbox'])) {
if ($_POST['singbox'] === 'start') {
createRestartFirewallScript();
}
}
}
function rotateLogFile($filePath) {
$backupPath = $filePath . '-' . date('Y-m-d-H-i-s') . '.bak';
rename($filePath, $backupPath);
@ -558,19 +588,20 @@ function stopSingbox() {
if ($returnVar !== 0) {
exec("kill -9 $pid", $output, $returnVar);
}
exec("service firewall restart", $output, $returnVar);
exec('/etc/neko/core/restart_firewall.sh', $output, $returnVar);
if ($returnVar === 0) {
logToFile('/etc/neko/tmp/log.txt', "防火墙重启成功。");
logToFile('/etc/neko/tmp/log.txt', "Restarting Firewall.");
return true;
} else {
logToFile('/etc/neko/tmp/log.txt', "防火墙重启失败。");
logToFile('/etc/neko/tmp/log.txt', "Firewall restart failed.");
error_log("Failed to stop Sing-box with PID $pid");
}
}
return false;
}
function logToFile($filePath, $message) {
$timestamp = date('H:i:s');
file_put_contents($filePath, "[$timestamp] $message\n", FILE_APPEND);
@ -619,6 +650,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
applyFirewallRules();
createStartScript($configFile);
exec("/etc/neko/core/start.sh > $singBoxLogFile 2>&1 &", $output, $returnVar);
exec('/etc/neko/core/restart_firewall.sh', $output, $returnVar);
$version = getSingboxVersion();
$pid = getSingboxPID();
$logMessage = $returnVar === 0