the ability to set the port for wireguard and shadowsocks at startup
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
TZ=Europe/Samara
|
||||
WGPORT=51820
|
||||
WGADDRESS=10.0.1.1/24
|
||||
WGPORT=51820
|
||||
SSPORT=8388
|
||||
|
||||
+19
-6
@@ -311,12 +311,14 @@ class Bot
|
||||
unset($l['plugin']);
|
||||
unset($l['plugin_opts']);
|
||||
$l['server'] = 'ss';
|
||||
$l['server_port'] = 8388;
|
||||
$l['server_port'] = (int) getenv('SSPORT');
|
||||
$c['server_port'] = (int) getenv('SSPORT');
|
||||
} else {
|
||||
$c['plugin'] = 'v2ray-plugin';
|
||||
$c['plugin_opts'] = 'server;loglevel=none';
|
||||
$l['server'] = 'ng';
|
||||
$l['server_port'] = 443;
|
||||
$c['server_port'] = 443;
|
||||
$l['plugin'] = 'v2ray-plugin';
|
||||
$l['plugin_opts'] = "tls;fast-open;path=/v2ray;host=$domain";
|
||||
}
|
||||
@@ -512,7 +514,7 @@ class Bot
|
||||
$domain = $conf['domain'] ?: $ip;
|
||||
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
|
||||
$ss = $this->getSSConfig();
|
||||
$port = !empty($ssl) && !empty($ss['plugin']) ? 443 : 8388;
|
||||
$port = !empty($ssl) && !empty($ss['plugin']) ? 443 : getenv('SSPORT');
|
||||
$ss_link = 'ss://' . base64_encode("{$ss['method']}:{$ss['password']}@$domain:$port");
|
||||
$qr_file = __DIR__ . "/qr/shadowsocks.png";
|
||||
exec("qrencode -t png -o $qr_file '$ss_link'");
|
||||
@@ -884,7 +886,6 @@ class Bot
|
||||
$out[] = $this->ssh("/AdGuardHome/AdGuardHome -s stop 2>&1", 'ad');
|
||||
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
|
||||
$c = yaml_parse_file('/config/AdGuardHome.yaml');
|
||||
$this->sd($c);
|
||||
yaml_emit_file('/config/adguard/AdGuardHome.yaml', $c);
|
||||
$out[] = $this->ssh("/AdGuardHome/AdGuardHome -s start 2>&1", 'ad');
|
||||
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
|
||||
@@ -1132,7 +1133,7 @@ DNS-over-HTTPS with IP:
|
||||
{
|
||||
$conf = $this->readConfig();
|
||||
$address = getenv('ADDRESS');
|
||||
$port = getenv('PORT_WG');
|
||||
$port = getenv('WGPORT');
|
||||
$r = $this->ssh("/bin/sh /reset_wg.sh $address $port");
|
||||
file_put_contents($this->clients, '');
|
||||
$this->menu();
|
||||
@@ -1568,7 +1569,7 @@ DNS-over-HTTPS with IP:
|
||||
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
|
||||
$ss = $this->getSSConfig();
|
||||
$v2ray = !empty($ss['plugin']) ? 'ON' : 'OFF';
|
||||
$port = !empty($ssl) && !empty($ss['plugin']) ? 443 : 8388;
|
||||
$port = !empty($ssl) && !empty($ss['plugin']) ? 443 : getenv('SSPORT');
|
||||
$options = !empty($ssl) && !empty($ss['plugin']) ? "tls;fast-open;path=/v2ray;host=$domain" : "path=/v2ray;host=$domain";
|
||||
|
||||
$text = "Menu -> ShadowSocks";
|
||||
@@ -2016,7 +2017,7 @@ DNS-over-HTTPS with IP:
|
||||
'peers' => [
|
||||
[
|
||||
'PublicKey' => $public_server_key,
|
||||
'Endpoint' => file_get_contents('https://ipinfo.io/ip') . ":" . getenv('PORT_WG'),
|
||||
'Endpoint' => file_get_contents('https://ipinfo.io/ip') . ":" . getenv('WGPORT'),
|
||||
'AllowedIPs' => $ips_user ?: "0.0.0.0/0",
|
||||
'PersistentKeepalive' => 20,
|
||||
]
|
||||
@@ -2041,6 +2042,18 @@ DNS-over-HTTPS with IP:
|
||||
return count($r) - 1;
|
||||
}
|
||||
|
||||
public function syncPortClients()
|
||||
{
|
||||
$endpoint = file_get_contents('https://ipinfo.io/ip') . ':' . getenv('WGPORT');
|
||||
$clients = $this->readClients();
|
||||
foreach ($clients as $k => $v) {
|
||||
foreach ($v['peers'] as $i => $j) {
|
||||
$clients[$k]['peers'][$i]['Endpoint'] = $endpoint;
|
||||
}
|
||||
}
|
||||
$this->saveClients($clients);
|
||||
}
|
||||
|
||||
public function saveClients(array $clients)
|
||||
{
|
||||
file_put_contents($this->clients, json_encode($clients, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
|
||||
|
||||
@@ -7,3 +7,4 @@ require __DIR__ . '/config.php';
|
||||
$bot = new Bot($c['key']);
|
||||
$bot->setwebhook($c['key']);
|
||||
$bot->setcommands();
|
||||
$bot->syncPortClients();
|
||||
|
||||
@@ -27,7 +27,7 @@ dns:
|
||||
blocked_response_ttl: 10
|
||||
parental_block_host: family-block.dns.adguard.com
|
||||
safebrowsing_block_host: standard-block.dns.adguard.com
|
||||
ratelimit: 20
|
||||
ratelimit: 200
|
||||
ratelimit_whitelist: []
|
||||
refuse_any: true
|
||||
upstream_dns:
|
||||
|
||||
+9
-6
@@ -38,8 +38,6 @@ services:
|
||||
unit:
|
||||
build:
|
||||
dockerfile: dockerfile/php.dockerfile
|
||||
args:
|
||||
IP: ${IP}
|
||||
volumes:
|
||||
- ./config/.profile:/root/.bashrc:ro
|
||||
- ./config/php.ini:/usr/local/etc/php/php.ini
|
||||
@@ -62,7 +60,8 @@ services:
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
ADDRESS: ${WGADDRESS}
|
||||
PORT_WG: ${WGPORT}
|
||||
WGPORT: ${WGPORT}
|
||||
SSPORT: ${SSPORT}
|
||||
hostname: unit
|
||||
restart: unless-stopped
|
||||
stop_grace_period: 1s
|
||||
@@ -71,6 +70,8 @@ services:
|
||||
networks:
|
||||
default:
|
||||
ipv4_address: 10.10.0.7
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
proxy:
|
||||
build:
|
||||
dockerfile: dockerfile/shadowsocks.dockerfile
|
||||
@@ -87,6 +88,7 @@ services:
|
||||
ipv4_address: 10.10.0.3
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
SSPORT: ${SSPORT}
|
||||
stop_grace_period: 1s
|
||||
command: ["/bin/sh", "/start_proxy.sh"]
|
||||
wg:
|
||||
@@ -105,7 +107,7 @@ services:
|
||||
- ${WGPORT}:${WGPORT}/udp
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
PORT_WG: ${WGPORT}
|
||||
WGPORT: ${WGPORT}
|
||||
ADDRESS: ${WGADDRESS}
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
@@ -147,10 +149,11 @@ services:
|
||||
depends_on:
|
||||
- unit
|
||||
ports:
|
||||
- 8388:8388/udp
|
||||
- 8388:8388/tcp
|
||||
- ${SSPORT}:${SSPORT}/tcp
|
||||
- ${SSPORT}:${SSPORT}/udp
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
SSPORT: ${SSPORT}
|
||||
stop_grace_period: 1s
|
||||
command: ["/bin/sh", "/start_ss.sh"]
|
||||
networks:
|
||||
|
||||
@@ -40,8 +40,6 @@ services:
|
||||
unit:
|
||||
build:
|
||||
dockerfile: dockerfile/php.dockerfile
|
||||
args:
|
||||
IP: ${IP}
|
||||
volumes:
|
||||
- ./config/.profile:/root/.bashrc:ro
|
||||
- ./config/php.ini:/usr/local/etc/php/php.ini
|
||||
@@ -64,7 +62,8 @@ services:
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
ADDRESS: ${WGADDRESS}
|
||||
PORT_WG: ${WGPORT}
|
||||
WGPORT: ${WGPORT}
|
||||
SSPORT: ${SSPORT}
|
||||
hostname: unit
|
||||
restart: unless-stopped
|
||||
stop_grace_period: 1s
|
||||
@@ -73,6 +72,8 @@ services:
|
||||
networks:
|
||||
default:
|
||||
ipv4_address: 10.10.0.7
|
||||
extra_hosts:
|
||||
- "host.docker.internal:host-gateway"
|
||||
proxy:
|
||||
build:
|
||||
dockerfile: dockerfile/shadowsocks.dockerfile
|
||||
@@ -89,6 +90,7 @@ services:
|
||||
ipv4_address: 10.10.0.3
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
SSPORT: ${SSPORT}
|
||||
stop_grace_period: 1s
|
||||
command: ["/bin/sh", "/start_proxy.sh"]
|
||||
wg:
|
||||
@@ -107,7 +109,7 @@ services:
|
||||
- ${WGPORT}:${WGPORT}/udp
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
PORT_WG: ${WGPORT}
|
||||
WGPORT: ${WGPORT}
|
||||
ADDRESS: ${WGADDRESS}
|
||||
cap_add:
|
||||
- NET_ADMIN
|
||||
@@ -149,10 +151,11 @@ services:
|
||||
depends_on:
|
||||
- unit
|
||||
ports:
|
||||
- 8388:8388/udp
|
||||
- 8388:8388/tcp
|
||||
- ${SSPORT}:${SSPORT}/tcp
|
||||
- ${SSPORT}:${SSPORT}/udp
|
||||
environment:
|
||||
TZ: ${TZ}
|
||||
SSPORT: ${SSPORT}
|
||||
stop_grace_period: 1s
|
||||
command: ["/bin/sh", "/start_ss.sh"]
|
||||
networks:
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
from nginx/unit:1.29.0-php8.1
|
||||
arg IP
|
||||
run apt update && apt install -y qrencode wget libssh2-1-dev ssh libicu-dev libyaml-dev certbot && \
|
||||
pecl install https://pecl.php.net/get/ssh2-1.3.1.tgz && \
|
||||
pecl install https://pecl.php.net/get/yaml-2.2.2.tgz && \
|
||||
|
||||
@@ -5,7 +5,7 @@ hosts: unhosts # маппинг доменов на локалку
|
||||
unhosts:
|
||||
sed -i '/test.ru/d' /mnt/c/Windows/System32/drivers/etc/hosts
|
||||
u: # запуск контейнеров
|
||||
IP=$(shell curl https://ipinfo.io/ip) docker compose up -d --build --force-recreate
|
||||
docker compose up -d --build --force-recreate
|
||||
# sleep 1
|
||||
# docker compose logs unit wg ss proxy
|
||||
d: # остановка контейнеров
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
cat /ssh/key.pub > /root/.ssh/authorized_keys
|
||||
service ssh start
|
||||
sed -n "s/\"server_port\": \([0-9]\+\),/\1/p" /config.json > current_port
|
||||
CURRENT_PORT=$(cat current_port | tr -d " ")
|
||||
if [ "$CURRENT_PORT" -ne "443" ]
|
||||
then
|
||||
sed "s/\"server_port\": [0-9]\+/\"server_port\": $SSPORT/" /config.json > change_port
|
||||
cat change_port > /config.json
|
||||
fi
|
||||
/sslocal -v -d -c /config.json
|
||||
tail -f /dev/null
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
cat /ssh/key.pub > /root/.ssh/authorized_keys
|
||||
service ssh start
|
||||
sed -n "s/\"server_port\": \([0-9]\+\),/\1/p" /config.json > current_port
|
||||
CURRENT_PORT=$(cat current_port | tr -d " ")
|
||||
if [ "$CURRENT_PORT" -ne "443" ]
|
||||
then
|
||||
sed "s/\"server_port\": [0-9]\+/\"server_port\": $SSPORT/" /config.json > change_port
|
||||
cat change_port > /config.json
|
||||
fi
|
||||
/ssserver -v -d -c /config.json
|
||||
tail -f /dev/null
|
||||
|
||||
+3
-1
@@ -5,10 +5,12 @@ then
|
||||
echo "[Interface]" > /etc/wireguard/wg0.conf
|
||||
echo "PrivateKey = $PRIVATEKEY" >> /etc/wireguard/wg0.conf
|
||||
echo "Address = $ADDRESS" >> /etc/wireguard/wg0.conf
|
||||
echo "ListenPort = $PORT_WG" >> /etc/wireguard/wg0.conf
|
||||
echo "ListenPort = $WGPORT" >> /etc/wireguard/wg0.conf
|
||||
echo "PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE" >> /etc/wireguard/wg0.conf
|
||||
echo "PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o $INTERFACE -j MASQUERADE" >> /etc/wireguard/wg0.conf
|
||||
fi
|
||||
sed "s/ListenPort = [0-9]\+/ListenPort = $WGPORT/" /etc/wireguard/wg0.conf > change_port
|
||||
cat change_port > /etc/wireguard/wg0.conf
|
||||
wg-quick up wg0
|
||||
cat /ssh/key.pub > /root/.ssh/authorized_keys
|
||||
service ssh start
|
||||
|
||||
Reference in New Issue
Block a user