singbox for windows as service

This commit is contained in:
mercury
2024-04-13 19:19:30 +04:00
parent 95fea3bb7b
commit e1902827ce
13 changed files with 64 additions and 7 deletions
+10 -3
View File
@@ -3764,7 +3764,7 @@ DNS-over-HTTPS with IP:
);
}
public function userXr($i, $fs = 0, $fv = 0)
public function userXr($i, $fs = 0, $fv = 0, $a = 0)
{
$c = $this->getXray();
$pac = $this->getPacConf() ?: $this->ip;
@@ -3781,12 +3781,16 @@ DNS-over-HTTPS with IP:
if (!empty($fv)) {
return $fullv2ray;
}
if (!empty($a)) {
return "$scheme://{$domain}/pac?h=$hash&t=si&s={$c['inbounds'][0]['settings']['clients'][$i]['id']}";
}
$text[] = "Menu -> " . $this->i18n('xray') . " -> {$c['inbounds'][0]['settings']['clients'][$i]['email']}\n";
$text[] = "<code>{$this->linkXray($i)}</code>\n";
$text[] = "v2ray import: <a href='$v2ray'>v2rayng://install-config</a>";
$text[] = "v2ray config: <code>$scheme://{$domain}/pac?h=$hash&t=s&s={$c['inbounds'][0]['settings']['clients'][$i]['id']}</code>\n";
$text[] = "sing-box import: <a href='$sing'>sing-box://import-remote-profile</a>";
$text[] = "sing-box import (Android, IOS): <a href='$sing'>sing-box://import-remote-profile</a>";
$text[] = "sing-box windows: <a href='$scheme://{$domain}/pac?h=$hash&t=si&b=2&s={$c['inbounds'][0]['settings']['clients'][$i]['id']}'>windows service</a>";
$text[] = "sing-box config: <code>$scheme://{$domain}/pac?h=$hash&t=si&s={$c['inbounds'][0]['settings']['clients'][$i]['id']}</code>";
$data[] = [
@@ -3885,7 +3889,7 @@ DNS-over-HTTPS with IP:
echo json_encode($c);
}
public function singboxSubscription($key, $fs = 0)
public function singboxSubscription($key, $fs = 0, $a = 0)
{
$pac = $this->getPacConf();
$domain = $pac['domain'] ?: $this->ip;
@@ -3897,6 +3901,9 @@ DNS-over-HTTPS with IP:
if (!empty($fs)) {
return $this->userXr($k, 1);
}
if (!empty($a)) {
return $this->userXr($k, a: 1);
}
if (empty($v['off'])) {
$flag = false;
}
+22 -3
View File
@@ -49,9 +49,28 @@ if ($hash == substr(md5($c['key']), 0, 8)) {
require __DIR__ . '/i18n.php';
$bot = new Bot($c['key'], $i);
if (!empty($_GET['b'])) {
$fs = $bot->singboxSubscription($_GET['s'], 1);
header("Location: $fs");
exit;
switch ($_GET['b']) {
case '1':
$fs = $bot->singboxSubscription($_GET['s'], 1);
header("Location: $fs");
exit;
case '2':
$link = htmlspecialchars($bot->singboxSubscription($_GET['s'], a: 1), ENT_XML1, 'UTF-8');
file_put_contents('/singbox/winsw.xml', preg_replace('#~url~#', $link, file_get_contents('/singbox/winsw.xml')));
$zip = new ZipArchive();
$n = "singbox_$v.zip";
$zip->open($n, ZipArchive::CREATE | ZipArchive::OVERWRITE);
foreach (scandir('/singbox') as $k => $v) {
if (!empty(!in_array($v, ['.', '..']))) {
$zip->addFile("/singbox/$v", $v);
}
}
$zip->close();
header('Content-Disposition: attachment; filename="singbox.zip"');
echo file_get_contents('singbox.zip');
unlink($n);
break;
}
} else {
header('Content-Type: application/json');
echo $bot->singboxSubscription($_GET['s']);
+2 -1
View File
@@ -93,7 +93,7 @@ services:
ipv4_address: 10.10.1.2
logging: *default-logging
php:
image: mercurykd/vpnbot-php:1.3
image: mercurykd/vpnbot-php:1.4
build:
dockerfile: dockerfile/php.dockerfile
args:
@@ -115,6 +115,7 @@ services:
- ./.env:/mirror/.env
- ./update:/update
- ./.git:/.git
- ./singbox_windows:/singbox
environment:
IP: ${IP}
VER: ${VER}
+1
View File
@@ -4,6 +4,7 @@ RUN apk add --no-cache --update php81 \
php81-mbstring \
php81-session \
php81-phar \
php81-zip \
php81-curl \
php81-opcache \
php81-openssl \
+2
View File
@@ -0,0 +1,2 @@
winsw.exe install
pause
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
winsw.exe start
+2
View File
@@ -0,0 +1,2 @@
winsw.exe status
pause
+1
View File
@@ -0,0 +1 @@
winsw.exe stop
+2
View File
@@ -0,0 +1,2 @@
winsw.exe uninstall
pause
Binary file not shown.
+19
View File
@@ -0,0 +1,19 @@
<service>
<id>singbox</id>
<name>singbox</name>
<description>singbox</description>
<executable>%BASE%\sing-box.exe</executable>
<arguments>run -c %BASE%\config.json</arguments>
<logmode>rotate</logmode>
<onfailure action="restart" delay="10 sec" />
<onfailure action="restart" delay="20 sec" />
<onfailure action="restart" delay="30 sec" />
<onfailure action="none" />
<onexit action="restart" />
<onexit action="restart" />
<onexit action="restart" />
<onexit action="none" />
<configuration>
<download from="~url~" to="%BASE%\config.json" interval="1 minute" />
</configuration>
</service>
+2
View File
@@ -1,3 +1,5 @@
13.04.2024 v1.27
- архив сингбокса для windows, работает как служба
12.04.2024 v1.26
- имя клиента xtls подтягивается по подписке из бота
11.04.2024 v1.25