Compare commits

...

50 Commits

Author SHA1 Message Date
mercury 4082dac97b sslip.io 2024-03-17 17:50:09 +04:00
mercury 7317d418de update version 2024-03-13 22:59:39 +04:00
mercury b7a1f9bbd6 fix override.env in service 2024-03-10 16:57:42 +04:00
mercury fcc165b4be fix override.env 2024-03-10 16:49:19 +04:00
mercury a9d16eadce fix adguard menu 2024-03-10 15:31:40 +04:00
mercury 82b95ccb85 web app for donate 2024-03-10 13:10:35 +04:00
mercury e01ef61b62 protect adguard on backup restore 2024-03-10 13:01:32 +04:00
mercury 367bfc0fbc web panel config 2024-03-10 12:45:42 +04:00
mercury 524c52e326 web panel adguard 2024-03-10 12:39:30 +04:00
mercury 3bbb8290e5 improve settings menu 2024-03-07 19:27:40 +04:00
mercury 1e8ac34370 Merge branch 'master' into dev 2024-03-07 19:13:19 +04:00
Konstantin 2332e5ea71 Merge pull request #9 from 13f66cd22a80/master 2024-03-07 19:09:35 +04:00
mercury 796fa57330 improve status wg error 2024-03-07 19:00:33 +04:00
Jeff Scrum ce91b1152e Update readme.md 2024-03-07 14:44:29 +03:00
mercury 64d44428d0 update version 2024-03-07 14:34:48 +04:00
mercury 860fdc883f fix environment for wg 2024-03-07 14:32:52 +04:00
mercury f2f2066e99 update version 2024-03-07 13:21:46 +04:00
mercury 3e343ce2b7 fix port amnezia 2024-03-07 13:10:09 +04:00
mercury 3c16620a7d update version 2024-03-07 11:58:25 +04:00
mercury b1efd9f400 fix syncports 2024-03-07 11:52:34 +04:00
mercury cbe0ef8a12 check webhook 2024-03-07 10:46:55 +04:00
mercury 24026d3678 optimize images 2024-03-07 10:23:13 +04:00
mercury dea46815c7 override environment 2024-03-07 10:20:43 +04:00
mercury 11e34d8c4e unversary path for vpnbot.service 2024-03-06 15:15:45 +04:00
mercury 3e3684eb34 fix service for systemd 2024-03-06 14:46:02 +04:00
mercury 7ee47db8e2 fix short link type 2024-03-06 11:52:09 +04:00
mercury b390fe7dd8 update version 2024-03-06 04:08:45 +04:00
mercury fe0414cc59 fix export ocserv users 2024-03-06 04:03:30 +04:00
mercury 48a1eba67e fix ocserv 2024-03-06 03:44:52 +04:00
mercury 714cff7d76 fix lib for short link 2024-03-06 02:10:11 +04:00
mercury 0e8bab5c4c fix service script 2024-03-06 01:45:31 +04:00
mercury 387e6e4986 short link for amnezia 2024-03-06 01:35:40 +04:00
mercury 6a7af1c30f fix import wg1 2024-03-05 00:14:36 +04:00
mercury 2a17b4f1f3 update version 2024-03-04 23:30:46 +04:00
mercury d005ccc919 fix start wg1 2024-03-04 23:26:09 +04:00
mercury 5df89e7f89 syncport fix 2024-03-04 16:51:18 +04:00
mercury f6d72800cb white ip 2024-03-04 16:38:37 +04:00
mercury 4ff1929a22 improve makefile 2024-03-03 19:53:52 +04:00
mercury 46d54ffeee fix gitignore 2024-03-03 19:45:57 +04:00
mercury 20cde272dd update self 2024-03-03 19:29:21 +04:00
mercury 4270ee5b23 update version 2024-03-02 15:56:18 +04:00
mercury cdcd6a7931 check webhook 2024-03-02 15:05:21 +04:00
mercury f360091c1a improve makefile 2024-03-02 00:30:12 +04:00
mercury 3e52c3650e two instance wireguard 2024-03-02 00:14:13 +04:00
mercury 757c704d38 update version 2024-03-01 11:50:51 +04:00
mercury 7c9f4d9815 fix iptables wg 2024-03-01 11:27:36 +04:00
mercury 9bfa7bd0c7 fix import 2024-03-01 02:48:24 +04:00
mercury d8620ef4f2 update version 2024-03-01 02:37:22 +04:00
mercury d4b9c4af48 fix long domain set 2024-03-01 02:17:29 +04:00
mercury c115661529 images from hub 2024-02-29 00:10:00 +04:00
32 changed files with 847 additions and 231 deletions
+3
View File
@@ -1,8 +1,11 @@
TZ=Europe/Samara
WGADDRESS=10.0.1.1/24
WGPORT=51820
WG1ADDRESS=10.0.3.1/24
WG1PORT=51821
SSPORT=8388
TGPORT=4443
IMAGE=alpine:3.18.2
IP=
VER=
ENV=/root/.ashrc
+4
View File
@@ -16,3 +16,7 @@
.vscode/
.idea/
mirror/.env
update/*
!update/update.sh
override.env
+14
View File
@@ -0,0 +1,14 @@
import sys
from PyQt5.QtCore import *
def enc(s):
ba = qCompress(QByteArray(s.encode()))
ba = ba.toBase64(QByteArray.Base64Option.Base64UrlEncoding | QByteArray.Base64Option.OmitTrailingEquals)
print('vpn://' + str(ba, 'utf-8'))
s = ''
for line in sys.stdin:
s += line
s = s.strip()
enc(s)
+358 -119
View File
@@ -4,6 +4,8 @@ class Bot
{
public $input;
public $adguard;
public $update;
public $ip;
public function __construct($key, $i18n)
{
@@ -11,6 +13,7 @@ class Bot
$this->api = "https://api.telegram.org/bot$key/";
$this->file = "https://api.telegram.org/file/bot$key/";
$this->clients = '/config/clients.json';
$this->clients1 = '/config/clients1.json';
$this->pac = '/config/pac.json';
$this->ip = getenv('IP');
$this->i18n = $i18n;
@@ -18,6 +21,7 @@ class Bot
$this->dns = '1.1.1.1, 8.8.8.8';
$this->limit = $this->getPacConf()['limitpage'] ?: 5;
$this->adguard = '/config/AdGuardHome.yaml';
$this->update = '/update/json';
}
public function input()
@@ -121,12 +125,21 @@ class Bot
case preg_match('~^/menu (?P<type>subzoneslist|reverselist|includelist|excludelist) (?P<arg>(?:-)?\d+)$~', $this->input['callback'], $m):
$this->menu(type: $m['type'] ?? false, arg: $m['arg'] ?? false);
break;
case preg_match('~^/changeWG (\d+)$~', $this->input['callback'], $m):
$this->changeWG($m[1]);
break;
case preg_match('~^/id$~', $this->input['message'], $m):
$this->send($this->input['chat'], $this->input['from'], $this->input['message_id']);
break;
case preg_match('~^/adguardChBr$~', $this->input['callback'], $m):
$this->adguardChBr();
break;
case preg_match('~^/mtproto$~', $this->input['callback'], $m):
$this->mtproto();
break;
case preg_match('~^/updatebot$~', $this->input['callback'], $m):
$this->updatebot();
break;
case preg_match('~^/getMirror$~', $this->input['callback'], $m):
$this->getMirror();
break;
@@ -933,12 +946,15 @@ class Bot
public function shutdownClient()
{
try {
$clients = $this->readClients();
if ($clients) {
foreach ($clients as $k => $v) {
if (!empty($v['interface']['## time'])) {
if (strtotime($v['interface']['## time']) < time()) {
$this->switchClient($k);
for ($i=0; $i < 2; $i++) {
$this->wg = $i;
$clients = $this->readClients();
if ($clients) {
foreach ($clients as $k => $v) {
if (!empty($v['interface']['## time'])) {
if (strtotime($v['interface']['## time']) < time()) {
$this->switchClient($k);
}
}
}
}
@@ -964,16 +980,24 @@ class Bot
public function readClients(): array
{
return json_decode(file_get_contents($this->clients), true) ?: [];
return json_decode(file_get_contents($this->getInstanceWG(1) ? $this->clients1 : $this->clients), true) ?: [];
}
public function export()
{
$this->wg = 0;
$wg = [
'server' => $this->readConfig(),
'clients' => json_decode(file_get_contents($this->clients), true) ?: [],
];
$this->wg = 1;
$wg1 = [
'server' => $this->readConfig(),
'clients' => json_decode(file_get_contents($this->clients1), true) ?: [],
];
$conf = [
'wg' => [
'server' => $this->readConfig(),
'clients' => json_decode(file_get_contents($this->clients), true) ?: [],
],
'wg' => $wg,
'wg1' => $wg1,
'ss' => $this->getSSConfig(),
'sl' => $this->getSSLocalConfig(),
'ad' => yaml_parse_file($this->adguard),
@@ -985,15 +1009,20 @@ class Bot
'mtproto' => file_get_contents('/config/mtprotosecret'),
'xray' => json_decode(file_get_contents('/config/xray.json'), true),
'oc' => file_get_contents('/config/ocserv.conf'),
'ocu' => file_get_contents('/config/ocserv.passwd'),
];
return json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
}
public function exportManual()
public function exportManual($file = false)
{
$json = $this->export();
if (!empty($file)) {
file_put_contents($file, $json);
}
$bot = $this->request('getMyName', [])['result']['name'];
return $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $this->export());
return $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $json);
}
public function import()
@@ -1012,10 +1041,14 @@ class Bot
];
}
public function importFile()
public function importFile($file = false)
{
$r = $this->request('getFile', ['file_id' => $this->input['file_id']]);
$json = json_decode(file_get_contents($this->file . $r['result']['file_path']), true);
if (!empty($file)) {
$json = json_decode(file_get_contents($file), true);
} else {
$r = $this->request('getFile', ['file_id' => $this->input['file_id']]);
$json = json_decode(file_get_contents($this->file . $r['result']['file_path']), true);
}
if (empty($json) || !is_array($json)) {
$this->answer($this->input['callback_id'], 'error', true);
} else {
@@ -1033,6 +1066,9 @@ class Bot
if ($this->getPacConf()['amnezia'] != $json['pac']['amnezia']) {
$switch_amnezia = 1;
}
if ($this->getPacConf()['wg1_amnezia'] != $json['pac']['wg1_amnezia']) {
$switch_wg1amnezia = 1;
}
$this->setPacConf($json['pac']);
$out[] = 'update naiveproxy';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
@@ -1043,8 +1079,19 @@ class Bot
if (!empty($json['wg'])) {
$out[] = 'update wireguard';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->wg = 0;
$this->saveClients($json['wg']['clients']);
$this->restartWG($this->createConfig($json['wg']['server']), $switch_amnezia);
$this->iptablesWG();
}
// wg1
if (!empty($json['wg1'])) {
$out[] = 'update wireguard 1';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->wg = 1;
$this->saveClients($json['wg1']['clients']);
$this->restartWG($this->createConfig($json['wg1']['server']), $switch_wg1amnezia);
$this->iptablesWG();
}
// ad
if (!empty($json['ad'])) {
@@ -1087,6 +1134,7 @@ class Bot
if (!empty($json['oc'])) {
$out[] = 'update ocserv';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
file_put_contents('/config/ocserv.passwd', $json['ocu']);
$this->restartOcserv($json['oc']);
}
if (!empty($json['pac']['domain'])) {
@@ -1099,7 +1147,7 @@ class Bot
$t = file_get_contents('/config/nginx_default.conf');
if (!empty($json['pac']['domain'])) {
$t = preg_replace('/server_name([^\n]+)?/', "server_name {$json['pac']['domain']};", $t);
$t = preg_replace('/server_name ([^\n]+)?/', "server_name {$json['pac']['domain']};", $t);
preg_match_all('~#-domain.+?#-domain~s', $t, $m);
foreach ($m[0] as $k => $v) {
$t = preg_replace('~#-domain.+?#-domain~s', $this->uncomment($v, 'domain'), $t, 1);
@@ -1114,13 +1162,18 @@ class Bot
}
}
file_put_contents('/config/nginx.conf', $t);
$this->adguardProtect();
$out[] = $this->ssh("nginx -s reload 2>&1", 'ng');
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$out[] = "end import";
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$this->language = $this->getPacConf()['language'] ?: 'en';
$this->limit = $this->getPacConf()['limitpage'] ?: 5;
sleep(3);
$this->menu();
if (empty($file)) {
$this->menu();
}
}
}
@@ -1168,14 +1221,14 @@ class Bot
public function switchAmnezia($page = 0)
{
$c = $this->getPacConf();
$c['amnezia'] = $c['amnezia'] ? 0 : 1;
$amnezia = $c[$this->getInstanceWG(1) . 'amnezia'] = $c[$this->getInstanceWG(1) . 'amnezia'] ? 0 : 1;
$this->setPacConf($c);
$pk = $this->presharedKey();
$ak = $this->amneziaKeys();
$clients = $this->readClients();
foreach ($clients as $k => $v) {
if (!empty($c['amnezia'])) {
if (!empty($amnezia)) {
$clients[$k]['peers'][0]['PresharedKey'] = $pk;
$clients[$k]['interface']['Jc'] = $ak['Jc'];
$clients[$k]['interface']['Jmin'] = $ak['Jmin'];
@@ -1202,7 +1255,7 @@ class Bot
$this->saveClients($clients);
$wg = $this->readConfig();
if (!empty($c['amnezia'])) {
if (!empty($amnezia)) {
$wg['interface']['Jc'] = $ak['Jc'];
$wg['interface']['Jmin'] = $ak['Jmin'];
$wg['interface']['Jmax'] = $ak['Jmax'];
@@ -1225,7 +1278,7 @@ class Bot
}
foreach ($wg['peers'] as $k => $v) {
if (!empty($c['amnezia'])) {
if (!empty($amnezia)) {
$wg['peers'][$k]['PresharedKey'] = $pk;
} else {
unset($wg['peers'][$k]['PresharedKey']);
@@ -1235,30 +1288,34 @@ class Bot
$this->menu('wg', $page);
}
public function switchTorrent($page)
public function switchTorrent($page = 0, $restart = false)
{
$c = $this->getPacConf();
$c['blocktorrent'] = $c['blocktorrent'] ? 0 : 1;
$c[$this->getInstanceWG(1) . 'blocktorrent'] = $c[$this->getInstanceWG(1) . 'blocktorrent'] ? 0 : 1;
$this->setPacConf($c);
if ($c['blocktorrent']) {
$this->ssh('bash /block_torrent.sh');
} else {
$this->ssh('bash /unblock_torrent.sh');
}
$this->answer($this->input['callback_id'], 'доступ к торрентам ' . ($c['blocktorrent'] ? 'заблокирован' : 'разблокирован'), true);
$this->iptablesWG();
$this->answer($this->input['callback_id'], 'доступ к торрентам ' . ($c[$this->getInstanceWG(1) . 'blocktorrent'] ? 'заблокирован' : 'разблокирован'), true);
$this->menu('wg', $page);
}
public function iptablesWG()
{
$c = $this->getPacConf();
$this->ssh('iptables -F', $this->getInstanceWG());
if ($c['exchange']) {
$this->ssh('bash /block_exchange.sh', $this->getInstanceWG());
}
if ($c['blocktorrent']) {
$this->ssh('bash /block_torrent.sh', $this->getInstanceWG());
}
}
public function switchExchange($page)
{
$c = $this->getPacConf();
$c['exchange'] = $c['exchange'] ? 0 : 1;
$c[$this->getInstanceWG(1) . 'exchange'] = $c[$this->getInstanceWG(1) . 'exchange'] ? 0 : 1;
$this->setPacConf($c);
if ($c['exchange']) {
$this->ssh('bash /block_exchange.sh');
} else {
$this->ssh('bash /unblock_exchange.sh');
}
$this->answer($this->input['callback_id'], 'обмен между пользователями ' . ($c['exchange'] ? 'заблокирован' : 'разблокирован'), true);
$this->iptablesWG();
$this->answer($this->input['callback_id'], 'обмен между пользователями ' . ($c[$this->getInstanceWG(1) . 'exchange'] ? 'заблокирован' : 'разблокирован'), true);
$this->menu('wg', $page);
}
@@ -1395,14 +1452,14 @@ class Bot
}
}
public function addDomain($domain)
public function addDomain($domain, $nomenu = false)
{
$domain = trim($domain);
if (!empty($domain)) {
$conf = $this->getPacConf();
$conf['domain'] = idn_to_ascii($domain);
$nginx = file_get_contents('/config/nginx.conf');
$t = preg_replace('/server_name([^\n]+)?/', "server_name {$conf['domain']};", $nginx);
$t = preg_replace('/server_name ([^\n]+)?/', "server_name {$conf['domain']};", $nginx);
preg_match_all('~#-domain.+?#-domain~s', $t, $m);
foreach ($m[0] as $k => $v) {
$t = preg_replace('~#-domain.+?#-domain~s', $this->uncomment($v, 'domain'), $t, 1);
@@ -1422,8 +1479,21 @@ class Bot
file_put_contents('/config/nginx.conf', $nginx);
}
}
sleep(3);
$this->menu('config');
if (empty($nomenu)) {
sleep(3);
$this->menu('config');
}
}
public function sslip()
{
$c = $this->getPacConf();
if (empty($c['domain'])) {
$this->addDomain(str_replace('.', '-', $this->ip) . '.sslip.io', 1);
$this->setSSL('letsencrypt');
} else {
$this->menu();
}
}
public function comment($text, $tag)
@@ -2118,15 +2188,33 @@ DNS-over-HTTPS with IP:
return $text;
}
public function getTitleWG()
{
$c = $this->getPacConf();
return $this->i18n($c[$this->getInstanceWG(1) . 'amnezia'] ? 'amnezia' : 'wg_title') . ' ' . $c['wg_instance'];
}
public function statusWg(int $page = 0)
{
$c = $this->getPacConf();
$conf = $this->readConfig();
$status = $this->readStatus();
if (empty($status)) {
return [
'text' => "Menu -> " . $this->getTitleWG() . "\n\nerror status",
'data' => [[
[
'text' => $this->i18n('back'),
'callback_data' => "/menu",
],
]],
];
}
$clients = $this->getClients($page);
$bt = $this->getPacConf()['blocktorrent'];
$ex = $this->getPacConf()['exchange'];
$dns = $this->getPacConf()['dns'];
$am = $this->getPacConf()['amnezia'];
$bt = $c[$this->getInstanceWG(1) . 'blocktorrent'];
$ex = $c[$this->getInstanceWG(1) . 'exchange'];
$dns = $c[$this->getInstanceWG(1) . 'dns'];
$am = $c[$this->getInstanceWG(1) . 'amnezia'];
$data = [
[
[
@@ -2173,7 +2261,7 @@ DNS-over-HTTPS with IP:
if (!empty($v['# PublicKey'])) {
$conf['peers'][$k]['online'] = 'off';
} else {
$conf['peers'][$k]['status'] = $this->getStatusPeer($v['PublicKey'], $status['peers']);
$conf['peers'][$k]['status'] = $status ? $this->getStatusPeer($v['PublicKey'], $status['peers']) : 'error';
$conf['peers'][$k]['online'] = preg_match('~^(\d+ seconds|[12] minute)~', $conf['peers'][$k]['status']['latest handshake']) ? 'online' : '';
}
}
@@ -2207,7 +2295,7 @@ DNS-over-HTTPS with IP:
]);
}
}
$text = "Menu -> Wireguard\n\n<code>" . implode(PHP_EOL, $text ?: []) . '</code>';
$text = "Menu -> " . $this->getTitleWG() . "\n\n<code>" . implode(PHP_EOL, $text ?: []) . '</code>';
$data[] = [
[
'text' => $this->i18n('update status'),
@@ -2244,9 +2332,9 @@ DNS-over-HTTPS with IP:
{
$c = $this->getPacConf();
if ($text) {
$c['dns'] = $text;
$c[$this->getInstanceWG(1) . 'dns'] = $text;
} else {
unset($c['dns']);
unset($c[$this->getInstanceWG(1) . 'dns']);
}
$this->setPacConf($c);
$this->menu('wg', $page);
@@ -2479,14 +2567,60 @@ DNS-over-HTTPS with IP:
$this->menu('client', "{$k}_$page");
}
public function getAmneziaShortLink($client)
{
$dns = explode(',', $client['interface']['DNS']);
$c = json_encode([
"containers" => [
[
"awg" => [
"isThirdPartyConfig" => True,
"last_config" => json_encode([
"H1" => "{$client['interface']['H1']}",
"H2" => "{$client['interface']['H2']}",
"H3" => "{$client['interface']['H3']}",
"H4" => "{$client['interface']['H4']}",
"Jc" => "{$client['interface']['Jc']}",
"Jmax" => "{$client['interface']['Jmax']}",
"Jmin" => "{$client['interface']['Jmin']}",
"S1" => "{$client['interface']['S1']}",
"S2" => "{$client['interface']['S2']}",
"client_ip" => explode('/', $client['interface']['Address'])[0],
"client_priv_key" => $client['interface']['PrivateKey'],
"client_pub_key" => "0",
"config" => $this->createConfig($client),
"hostName" => $this->ip,
"port" => (int) getenv('WG1PORT'),
"psk_key" => $client['peers'][0]['PresharedKey'],
"server_pub_key" => $client['peers'][0]['PublicKey']
]),
"port" => (int) getenv('WG1PORT'),
"transport_proto" => "udp"
],
"container" => "amnezia-awg"
]
],
"defaultContainer" => "amnezia-awg",
"description" => $client['interface']['## name'],
"dns1" => $dns[0],
"dns2" => $dns[1] ?: '',
"hostName" => $this->ip
]);
exec("echo '$c' | python amnezia.py", $o);
return $o[0];
}
public function getClient($client, $page)
{
$clients = $this->readClients();
if ($clients) {
$name = $this->getName($clients[$client]['interface']);
$conf = $this->createConfig($clients[$client]);
if ($this->getWGType() == 'awg') {
$sl = $this->getAmneziaShortLink($clients[$client]);
}
return [
'text' => "<code>$conf</code>\n\n<b>$name</b>",
'text' => "<pre>$conf</pre>\n\n<code>$sl</code>\n\n<b>$name</b> ({$this->getTitleWG()})",
'data' => [
[
[
@@ -2893,30 +3027,28 @@ DNS-over-HTTPS with IP:
return $this->i18n[$menu][$this->language] ?: $menu;
}
public function changeWG($i)
{
$c = $this->getPacConf();
$c['wg_instance'] = $i;
$this->setPacConf($c);
$this->menu('wg', 0);
}
public function menu($type = false, $arg = false, $return = false)
{
$menu = [
'main' => [
'text' => $this->i18n('menu'),
'text' => 'v' . getenv('VER'),
'data' => [
[
[
'text' => $this->i18n($this->getPacConf()['amnezia'] ? 'amnezia' : 'wg_title'),
'callback_data' => "/menu wg 0",
'callback_data' => "/changeWG 0",
],
[
'text' => $this->i18n('ad_title'),
'callback_data' => "/menu adguard",
],
],
[
[
'text' => $this->i18n('sh_title'),
'callback_data' => "/menu ss",
],
[
'text' => $this->i18n('ocserv'),
'callback_data' => "/menu oc",
'text' => $this->i18n($this->getPacConf()['wg1_amnezia'] ? 'amnezia' : 'wg_title'),
'callback_data' => "/changeWG 1",
],
],
[
@@ -2924,6 +3056,16 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('xray'),
'callback_data' => "/xray",
],
[
'text' => $this->i18n('naive'),
'callback_data' => "/menu naive",
],
],
[
[
'text' => $this->i18n('ocserv'),
'callback_data' => "/menu oc",
],
[
'text' => $this->i18n('mtproto'),
'callback_data' => "/mtproto",
@@ -2931,18 +3073,22 @@ DNS-over-HTTPS with IP:
],
[
[
'text' => $this->i18n('naive'),
'callback_data' => "/menu naive",
'text' => $this->i18n('sh_title'),
'callback_data' => "/menu ss",
],
[
'text' => $this->i18n('pac'),
'callback_data' => "/menu pac",
'text' => $this->i18n('mirror'),
'callback_data' => "/menu mirror",
],
],
[
[
'text' => $this->i18n('mirror'),
'callback_data' => "/menu mirror",
'text' => $this->i18n('ad_title'),
'callback_data' => "/menu adguard",
],
[
'text' => $this->i18n('pac'),
'callback_data' => "/menu pac",
],
],
[
@@ -2958,9 +3104,11 @@ DNS-over-HTTPS with IP:
],
[
'text' => $this->i18n('donate'),
'url' => "https://yoomoney.ru/to/410011827900450",
'web_app' => [
'url' => "https://www.donationalerts.com/r/mercurykd",
]
],
]
],
],
],
'wg' => $type == 'wg' ? $this->statusWg($arg) : false,
@@ -2977,7 +3125,7 @@ DNS-over-HTTPS with IP:
'lang' => $type == 'lang' ? $this->menuLang() : false,
'oc' => $type == 'oc' ? $this->ocMenu() : false,
'naive' => $type == 'naive' ? $this->naiveMenu() : false,
'mirror' => $type == 'mirror' ? $this->mirrorMenu() : false,
'mirror' => $type == 'mirror' ? $this->mirrorMenu() : false,
];
$text = $menu[$type ?: 'main' ]['text'];
@@ -3288,7 +3436,7 @@ DNS-over-HTTPS with IP:
public function addWg($page)
{
$text = "Menu -> Wireguard -> Add peer\n\n";
$text = "Menu -> {$this->getTitleWG()} -> Add peer\n\n";
$data[] = [
[
'text' => $this->i18n('all traffic'),
@@ -3327,37 +3475,95 @@ DNS-over-HTTPS with IP:
];
}
public function adguardProtect()
{
$h = substr(hash('sha256', $this->key), 0, 8);
$s = empty($this->getPacConf()['adgbrowser']) ? '' : '#';
$a = $this->adguardBasicAuth();
$r = <<<CONF
location /adguard/ {
access_log /logs/nginx_adguard_access;
if (\$cookie_c != "$h") {
$s rewrite .* /webapp redirect;
}
proxy_pass http://ad:80/;
proxy_redirect / /adguard/;
proxy_cookie_path / /adguard/;
proxy_set_header Authorization "Basic \$cookie_a";
}
location
CONF;
$f = '/config/nginx.conf';
$c = file_get_contents($f);
$t = preg_replace('~(location /adguard.+?})\s*location~s', $r, $c);
file_put_contents($f, $t);
}
public function adguardBasicAuth()
{
return base64_encode('admin:' . $this->getPacConf()['adpswd']);
}
public function adguardChBr()
{
$c = $this->getPacConf();
$c['adgbrowser'] = $c['adgbrowser'] ? 0 : 1;
$this->setPacConf($c);
$this->adguardProtect();
$this->ssh('nginx -s reload', 'ng');
$this->answer($this->input['callback_id'], $this->i18n($c['adgbrowser'] ? 'browser_notify_on' : 'browser_notify_off'), true);
$this->menu('adguard');
}
public function adguardMenu()
{
$conf = $this->getPacConf();
$ip = $this->ip;
$domain = $conf['domain'] ?: $ip;
$scheme = empty($ssl = $this->nginxGetTypeCert()) ? 'http' : 'https';
$text = "$scheme://$domain/adguard\nLogin: admin\nPass: <span class='tg-spoiler'>{$conf['adpswd']}</span>\n\n";
$text = "$scheme://$domain/adguard\nLogin: admin\nPass: <span class='tg-spoiler'>{$conf['adpswd']}</span>\n\n";
if ($ssl) {
$text .= "DNS over HTTPS:\n<code>$ip</code>\n<code>$scheme://$domain/dns-query" . ($conf['adguardkey'] ? "/{$conf['adguardkey']}" : '') . "</code>\n\n";
$text .= "DNS over TLS:\n<code>tls://" . ($conf['adguardkey'] ? "{$conf['adguardkey']}." : '') . "$domain</code>";
}
$data = [
[
[
'text' => 'web panel',
'web_app' => [
"url" => "https://$domain/adguard"
],
],
[
'text' => $this->i18n('third party browser') . ': ' . $this->i18n($conf['adgbrowser'] ? 'on' : 'off'),
'callback_data' => '/adguardChBr'
],
],
[
[
'text' => $this->i18n('change password'),
'callback_data' => "/adguardpsswd",
],
[
'text' => $this->i18n('reset settings'),
'callback_data' => "/adguardreset",
'text' => 'ClientID' . ($conf['adguardkey'] ? ": {$conf['adguardkey']}" : ''),
'callback_data' => "/setAdguardKey",
],
],
];
$data[] = [
[
'text' => $this->i18n('reset settings'),
'callback_data' => "/adguardreset",
],
];
$data[] = [
[
'text' => $this->i18n('add upstream'),
'callback_data' => "/addupstream",
],
[
'text' => $this->i18n('setSecret') . ($conf['adguardkey'] ? ": {$conf['adguardkey']}" : ''),
'callback_data' => "/setAdguardKey",
'text' => $this->i18n('check DNS'),
'callback_data' => "/checkdns",
],
];
$upstreams = yaml_parse_file($this->adguard)['dns']['upstream_dns'];
@@ -3375,12 +3581,6 @@ DNS-over-HTTPS with IP:
];
}
}
$data[] = [
[
'text' => $this->i18n('check DNS'),
'callback_data' => "/checkdns",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -3429,10 +3629,22 @@ DNS-over-HTTPS with IP:
return openssl_x509_parse($c)["validTo_time_t"] ?: false;
}
public function updatebot()
{
$this->exportManual($this->update);
$r = $this->send($this->input['from'], 'update...');
file_put_contents('/update/reload_message', "{$this->input['from']}:{$r['result']['message_id']}");
file_put_contents('/update/pipe', '1');
$this->delete($this->input['from'], $this->input['message_id']);
}
public function configMenu()
{
$conf = $this->getPacConf();
$text = $this->i18n('domain explain');
$conf = $this->getPacConf();
$text[] = $conf['domain'] ? "Domains:\n{$conf['domain']}\nnp.{$conf['domain']}\noc.{$conf['domain']}" . ($conf['adguardkey'] ? "\n{$conf['adguardkey']}.{$conf['domain']}" : '') : $this->i18n('domain explain');
$ssl = $this->expireCert();
$text[] = $conf['domain'] ? "\nSSL: " . ($ssl ? date('Y-m-d H:i:s', $this->expireCert()) : 'none') : '';
$data = [
[
[
@@ -3447,7 +3659,7 @@ DNS-over-HTTPS with IP:
case 'letsencrypt':
$data[] = [
[
'text' => $this->i18n('renew SSL') . ': ' . date('Y-m-d H:i:s', $this->expireCert()),
'text' => $this->i18n('renew SSL'),
'callback_data' => "/setSSL letsencrypt",
],
[
@@ -3539,6 +3751,12 @@ DNS-over-HTTPS with IP:
'callback_data' => "/debug",
],
];
$data[] = [
[
'text' => $this->i18n('update bot'),
'callback_data' => "/updatebot",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -3546,7 +3764,7 @@ DNS-over-HTTPS with IP:
],
];
return [
'text' => $text,
'text' => implode("\n", $text),
'data' => $data,
];
}
@@ -3700,9 +3918,17 @@ DNS-over-HTTPS with IP:
}
}
public function getInstanceWG($k = false)
{
if (!empty($k)) {
return ($this->wg ?? $this->getPacConf()['wg_instance']) ? 'wg1_' : '';
}
return ($this->wg ?? $this->getPacConf()['wg_instance']) ? 'wg1' : 'wg';
}
public function readConfig()
{
$r = $this->ssh('cat /etc/wireguard/wg0.conf');
$r = $this->ssh('cat /etc/wireguard/wg0.conf', $this->getInstanceWG());
$r = explode(PHP_EOL, $r);
$r = array_filter($r);
$i = 0;
@@ -3740,7 +3966,7 @@ DNS-over-HTTPS with IP:
public function readStatus()
{
$r = $this->ssh($this->getWGType());
$r = $this->ssh($this->getWGType(), $this->getInstanceWG());
$r = explode(PHP_EOL, $r);
$r = array_filter($r);
$i = 0;
@@ -3785,7 +4011,7 @@ DNS-over-HTTPS with IP:
$conf[] = "[Interface]";
if (empty($data['interface']['ListenPort'])) {
if (empty($data['interface']['DNS'])) {
$data['interface']['DNS'] = $this->getPacConf()['dns'] ?: $this->dns;
$data['interface']['DNS'] = $this->getPacConf()[$this->getInstanceWG(1) . 'dns'] ?: $this->dns;
}
}
foreach ($data['interface'] as $k => $v) {
@@ -3797,7 +4023,7 @@ DNS-over-HTTPS with IP:
$conf[] = '';
$conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]';
if (!empty($peer['Endpoint'])) {
$peer['Endpoint'] = ($pac['domain'] && !$pac['amnezia'] ? $pac['domain'] : $this->ip) . ":" . getenv('WGPORT');
$peer['Endpoint'] = ($pac['domain'] && !$pac[$this->getInstanceWG(1) . 'amnezia'] ? $pac['domain'] : $this->ip) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT');
}
foreach ($peer as $k => $v) {
$conf[] = "$k = $v";
@@ -3810,18 +4036,18 @@ DNS-over-HTTPS with IP:
public function presharedKey()
{
$c = $this->getPacConf();
if (empty($c['presharedkey'])) {
$c['presharedkey'] = trim($this->ssh("{$this->getWGType()} genpsk"));
if (empty($c[$this->getInstanceWG(1) . 'presharedkey'])) {
$c[$this->getInstanceWG(1) . 'presharedkey'] = trim($this->ssh("{$this->getWGType()} genpsk", $this->getInstanceWG()));
$this->setPacConf($c);
}
return $c['presharedkey'];
return $c[$this->getInstanceWG(1) . 'presharedkey'];
}
public function amneziaKeys()
{
$c = $this->getPacConf();
if (empty($c['amnezia_keys'])) {
$c['amnezia_keys'] = [
if (empty($c[$this->getInstanceWG(1) . 'amnezia_keys'])) {
$c[$this->getInstanceWG(1) . 'amnezia_keys'] = [
'Jc' => rand(3, 10),
'Jmin' => 50,
'Jmax' => 1000,
@@ -3834,7 +4060,7 @@ DNS-over-HTTPS with IP:
];
$this->setPacConf($c);
}
return $c['amnezia_keys'];
return $c[$this->getInstanceWG(1) . 'amnezia_keys'];
}
public function createPeer($ips_user = false, $name = false)
@@ -3857,9 +4083,9 @@ DNS-over-HTTPS with IP:
break;
}
}
$public_server_key = trim($this->ssh("echo {$conf['interface']['PrivateKey']} | {$this->getWGType()} pubkey"));
$private_peer_key = trim($this->ssh("{$this->getWGType()} genkey"));
$public_peer_key = trim($this->ssh("echo $private_peer_key | {$this->getWGType()} pubkey"));
$public_server_key = trim($this->ssh("echo {$conf['interface']['PrivateKey']} | {$this->getWGType()} pubkey", $this->getInstanceWG()));
$private_peer_key = trim($this->ssh("{$this->getWGType()} genkey", $this->getInstanceWG()));
$public_peer_key = trim($this->ssh("echo $private_peer_key | {$this->getWGType()} pubkey", $this->getInstanceWG()));
$name = ($name ? "$name" : '') . time();
@@ -3868,7 +4094,7 @@ DNS-over-HTTPS with IP:
'PublicKey' => $public_peer_key,
'AllowedIPs' => "$client_ip/32",
],
$this->getPacConf()['amnezia'] ? ['PresharedKey' => $this->presharedKey()] : []
$this->getPacConf()[$this->getInstanceWG(1) . 'amnezia'] ? ['PresharedKey' => $this->presharedKey()] : []
);
$client_conf = [
'interface' => array_merge(
@@ -3878,7 +4104,7 @@ DNS-over-HTTPS with IP:
'Address' => "$client_ip/32",
'MTU' => 1350,
],
$this->getPacConf()['amnezia'] ? $this->amneziaKeys() : []
$this->getPacConf()[$this->getInstanceWG(1) . 'amnezia'] ? $this->amneziaKeys() : []
),
'peers' => [
array_merge(
@@ -3887,7 +4113,7 @@ DNS-over-HTTPS with IP:
'AllowedIPs' => $ips_user ?: "0.0.0.0/0",
'PersistentKeepalive' => 20,
],
$this->getPacConf()['amnezia'] ? ['PresharedKey' => $this->presharedKey()] : []
$this->getPacConf()[$this->getInstanceWG(1) . 'amnezia'] ? ['PresharedKey' => $this->presharedKey()] : []
),
],
];
@@ -3912,39 +4138,47 @@ DNS-over-HTTPS with IP:
public function syncPortClients()
{
$endpoint = $this->ip . ':' . getenv('WGPORT');
$clients = $this->readClients();
foreach ($clients as $k => $v) {
foreach ($v['peers'] as $i => $j) {
$clients[$k]['peers'][$i]['Endpoint'] = $endpoint;
$endpoint = [
$this->ip . ':' . getenv('WGPORT'),
$this->ip . ':' . getenv('WG1PORT'),
];
for ($i=0; $i < 2; $i++) {
$this->wg = $i;
$clients = $this->readClients();
foreach ($clients as $k => $v) {
foreach ($v['peers'] as $n => $j) {
$clients[$k]['peers'][$n]['Endpoint'] = $endpoint[$i];
}
}
$this->saveClients($clients);
}
$this->saveClients($clients);
unset($this->wg);
}
public function saveClients(array $clients)
{
$domain = ($this->getPacConf()['domain'] ?: $this->ip) . ":" . getenv('WGPORT');
$c = $this->getPacConf();
$domain = ($c['domain'] ?: $this->ip) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT');
foreach ($clients as $k => $v) {
$clients[$k]['peers'][0]['Endpoint'] = $domain;
}
file_put_contents($this->clients, json_encode($clients, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
file_put_contents($this->getInstanceWG(1) ? $this->clients1 : $this->clients, json_encode($clients, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
}
public function getWGType($revert = 0)
{
$wg = $this->getPacConf()['amnezia'];
$wg = $this->getPacConf()[$this->getInstanceWG(1) . 'amnezia'];
return ($revert ? !$wg : $wg) ? 'awg' : 'wg';
}
public function restartWG($conf_str, $switch = false)
{
$this->ssh("echo '$conf_str' > /etc/wireguard/wg0.conf");
$this->ssh("echo '$conf_str' > /etc/wireguard/wg0.conf", $this->getInstanceWG());
if (!empty($switch)) {
$this->ssh("{$this->getWGType(1)}-quick down wg0");
$this->ssh("{$this->getWGType()}-quick up wg0");
$this->ssh("{$this->getWGType(1)}-quick down wg0", $this->getInstanceWG());
$this->ssh("{$this->getWGType()}-quick up wg0", $this->getInstanceWG());
} else {
$this->ssh("{$this->getWGType()} syncconf wg0 <({$this->getWGType()}-quick strip wg0)");
$this->ssh("{$this->getWGType()} syncconf wg0 <({$this->getWGType()}-quick strip wg0)", $this->getInstanceWG());
}
return true;
}
@@ -4006,10 +4240,15 @@ DNS-over-HTTPS with IP:
die('нет айпи');
}
echo "$ip\n";
var_dump($this->request('setWebhook', [
var_dump($r = $this->request('setWebhook', [
'url' => "https://$ip/tlgrm?k={$this->key}",
'certificate' => curl_file_create('/certs/self_public'),
]));
if (!empty($r['result']) && $r['result'] == true) {
file_put_contents('/start', 1);
} else {
die("set webhook fail\n");
}
}
public function setcommands()
+11
View File
@@ -0,0 +1,11 @@
<?php
require './config.php';
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://api.telegram.org/bot{$c['key']}/getWebhookInfo",
CURLOPT_RETURNTRANSFER => true,
]);
$res = curl_exec($ch);
die(var_dump($res));
+17 -1
View File
@@ -243,7 +243,7 @@ $i = [
],
'backup' => [
'en' => 'auto backup',
'ru' => 'бэкап',
'ru' => 'автобэкап',
],
'logs' => [
'en' => 'logs',
@@ -301,4 +301,20 @@ $i = [
'en' => 'download',
'ru' => 'скачать',
],
'update bot' => [
'en' => 'update bot',
'ru' => 'обновить бота',
],
'third party browser' => [
'en' => 'third party browser',
'ru' => 'сторонний браузер',
],
'browser_notify_on' => [
'en' => 'the web panel can now be opened in any browser',
'ru' => 'веб панель теперь может быть открыта в любом браузере',
],
'browser_notify_off' => [
'en' => 'the web panel can no longer be opened in any browser',
'ru' => 'веб панель теперь не может быть открыта в любом браузере',
],
];
+18
View File
@@ -42,6 +42,24 @@ if ($hash == substr(md5($c['key']), 0, 8)) {
}
}
}
if (!empty($_GET['hash'])) {
$t = $_GET;
unset($t['hash']);
ksort($t);
foreach ($t as $k => $v) {
$s[] = "$k=$v";
}
$s = implode("\n", $s);
$sk = hash_hmac('sha256', $c['key'], "WebAppData", true);
if (hash_hmac('sha256', $s, $sk) == $_GET['hash']) {
require __DIR__ . '/bot.php';
require __DIR__ . '/i18n.php';
$bot = new Bot($c['key'], $i);
setcookie('c', substr(hash('sha256', $c['key']), 0, 8), 0, '/');
setcookie('a', $bot->adguardBasicAuth(), 0, '/');
die('ok');
}
}
header('500', true, 500);
exit;
+2 -7
View File
@@ -8,12 +8,7 @@ require __DIR__ . '/config.php';
require __DIR__ . '/i18n.php';
$bot = new Bot($c['key'], $i);
$bot->setwebhook();
$bot->adguardProtect();
$bot->setcommands();
$bot->syncPortClients();
if (!empty($c['admin'])) {
$ip = getenv('IP');
foreach ($c['admin'] as $k => $v) {
$bot->send($v, "start $ip");
}
}
$bot->setwebhook();
+38
View File
@@ -0,0 +1,38 @@
<?php
require __DIR__ . '/timezone.php';
// require __DIR__ . '/debug.php';
require __DIR__ . '/bot.php';
require __DIR__ . '/config.php';
require __DIR__ . '/i18n.php';
$bot = new Bot($c['key'], $i);
if (!empty($c['admin'])) {
$ip = getenv('IP');
$rm = explode(':', trim(file_get_contents('/update/reload_message')));
$m = file_get_contents('/update/message');
foreach ($c['admin'] as $k => $v) {
$r = $bot->send($v, "start $ip");
$bot->input['chat'] = $v;
$bot->input['message_id'] = $r['result']['message_id'];
if (file_exists($bot->update)) {
if (!empty($m)) {
$bot->send($v, "<pre>$m</pre>", $v == $rm[0] ? $rm[1] : 0);
}
$r = $bot->send($v, "import settings");
$bot->input['chat'] = $v;
$bot->input['message_id'] = $r['result']['message_id'];
$bot->input['callback_id'] = $r['result']['message_id'];
if (empty($flag)) {
$bot->importFile($bot->update);
unlink($bot->update);
$flag = true;
}
}
}
}
file_put_contents('/update/message', '');
file_put_contents('/update/reload_message', '');
$bot->sslip();
+24
View File
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://telegram.org/js/telegram-web-app.js"></script>
<script src="jquery-3.7.1.min.js"></script>
<title>Document</title>
</head>
<body>
<script>
var tg = window.Telegram.WebApp;
jQuery(function($) {
$.ajax({
'url': 'check?' + tg.initData,
}).done(function (r) {
location.replace('/adguard/');
}).fail(function (r) {
location.replace('/');
});
});
</script>
</body>
</html>
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
[]
+13
View File
@@ -9,6 +9,7 @@ events {
}
http {
server_names_hash_bucket_size 64;
include include.conf;
include /etc/nginx/mime.types;
default_type application/octet-stream;
@@ -37,6 +38,12 @@ http {
proxy_redirect / /adguard/;
proxy_cookie_path / /adguard/;
}
location /webapp {
access_log /logs/nginx_webapp_access;
alias /app;
index index.html;
try_files $uri $uri/ /pac?$query_string;
}
location /pac {
access_log /logs/nginx_pac_access;
proxy_pass http://php;
@@ -87,6 +94,12 @@ http {
# proxy_redirect / /adguard/;
# proxy_cookie_path / /adguard/;
# }
# location /webapp {
# access_log /logs/nginx_webapp_access;
# alias /app;
# index index.html;
# try_files $uri $uri/ /pac?$query_string;
# }
# location /pac {
# access_log /logs/nginx_pac_access;
# proxy_pass http://php;
+13
View File
@@ -9,6 +9,7 @@ events {
}
http {
server_names_hash_bucket_size 64;
include include.conf;
include /etc/nginx/mime.types;
default_type application/octet-stream;
@@ -37,6 +38,12 @@ http {
proxy_redirect / /adguard/;
proxy_cookie_path / /adguard/;
}
location /webapp {
access_log /logs/nginx_webapp_access;
alias /app;
index index.html;
try_files $uri $uri/ /pac?$query_string;
}
location /pac {
access_log /logs/nginx_pac_access;
proxy_pass http://php;
@@ -87,6 +94,12 @@ http {
# proxy_redirect / /adguard/;
# proxy_cookie_path / /adguard/;
# }
# location /webapp {
# access_log /logs/nginx_webapp_access;
# alias /app;
# index index.html;
# try_files $uri $uri/ /pac?$query_string;
# }
# location /pac {
# access_log /logs/nginx_pac_access;
# proxy_pass http://php;
View File
+158 -30
View File
@@ -17,6 +17,7 @@ volumes:
services:
up:
image: mercurykd/vpnbot-up:1.1
build:
context: dockerfile
dockerfile: nginx.dockerfile
@@ -40,8 +41,11 @@ services:
condition: service_started
ss:
condition: service_started
environment:
TZ: ${TZ}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_upstream.sh"]
networks:
@@ -49,6 +53,7 @@ services:
ipv4_address: 10.10.0.10
logging: *default-logging
ng:
image: mercurykd/vpnbot-ng:1.1
build:
context: dockerfile
dockerfile: nginx.dockerfile
@@ -64,6 +69,7 @@ services:
- ./ssh:/ssh
- ./config/sshd_config:/etc/ssh/sshd_config
- ./logs/:/logs/
- ./app/webapp:/app
ports:
- 80:80
hostname: nginx
@@ -71,9 +77,11 @@ services:
depends_on:
up:
condition: service_started
environment:
TZ: ${TZ}
SSPORT: ${SSPORT}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_ng.sh"]
networks:
@@ -81,10 +89,13 @@ services:
ipv4_address: 10.10.0.2
logging: *default-logging
php:
image: mercurykd/vpnbot-php:1.2
build:
dockerfile: dockerfile/php.dockerfile
args:
image: ${IMAGE}
ports:
- 127.0.0.1:8081:8080
volumes:
- ./config/.profile:/root/.ashrc:ro
- ./config/php.ini:/etc/php81/php.ini
@@ -98,13 +109,15 @@ services:
- ./version:/version
- ./mirror:/mirror
- ./.env:/mirror/.env
- ./update:/update
environment:
TZ: ${TZ}
IP: ${IP}
ADDRESS: ${WGADDRESS}
WGPORT: ${WGPORT}
SSPORT: ${SSPORT}
TGPORT: ${TGPORT}
VER: ${VER}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
hostname: php
container_name: php-${VER}
restart: unless-stopped
@@ -122,7 +135,55 @@ services:
interval: 5s
timeout: 5s
retries: 5
service:
image: mercurykd/vpnbot-php:1.2
build:
dockerfile: dockerfile/php.dockerfile
args:
image: ${IMAGE}
volumes:
- ./config/.profile:/root/.ashrc:ro
- ./config/php.ini:/etc/php81/php.ini
- ./config/:/config/
- ./certs/:/certs/
- ./ssh:/ssh
- ./app:/app
- ./logs/:/logs/
- ./update:/update
- ./scripts/start_service.sh:/start_service.sh
environment:
IP: ${IP}
VER: ${VER}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
hostname: service
container_name: service-${VER}
# restart: unless-stopped
stop_grace_period: 1s
command: ["/bin/sh", "/start_service.sh"]
working_dir: /app
networks:
default:
ipv4_address: 10.10.0.15
logging: *default-logging
depends_on:
- up
- ng
- php
- proxy
- wg
- wg1
- ad
- ss
- tg
- xr
- oc
- np
proxy:
image: mercurykd/vpnbot-ss:1.1
build:
dockerfile: dockerfile/shadowsocks.dockerfile
args:
@@ -143,11 +204,16 @@ services:
ipv4_address: 10.10.0.3
environment:
TZ: ${TZ}
SSPORT: ${SSPORT}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_proxy.sh"]
logging: *default-logging
wg:
image: mercurykd/vpnbot-wg:1.1
build:
dockerfile: dockerfile/wireguard.dockerfile
args:
@@ -159,9 +225,7 @@ services:
- ./scripts/start_wg.sh:/start_wg.sh
- ./scripts/reset_wg.sh:/reset_wg.sh
- ./scripts/block_torrent.sh:/block_torrent.sh
- ./scripts/unblock_torrent.sh:/unblock_torrent.sh
- ./scripts/block_exchange.sh:/block_exchange.sh
- ./scripts/unblock_exchange.sh:/unblock_exchange.sh
- ./ssh:/ssh
- ./config/sshd_config:/etc/ssh/sshd_config
hostname: wireguard
@@ -171,9 +235,12 @@ services:
condition: service_healthy
ports:
- ${WGPORT}:${WGPORT}/udp
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
environment:
TZ: ${TZ}
WGPORT: ${WGPORT}
ADDRESS: ${WGADDRESS}
cap_add:
- NET_ADMIN
@@ -185,7 +252,48 @@ services:
default:
ipv4_address: 10.10.0.4
logging: *default-logging
wg1:
image: mercurykd/vpnbot-wg:1.1
build:
dockerfile: dockerfile/wireguard.dockerfile
args:
image: ${IMAGE}
volumes:
- ./config/.profile:/root/.ashrc:ro
- ./config/wg1.conf:/etc/wireguard/wg0.conf
- ./config/pac.json:/pac.json
- ./scripts/start_wg.sh:/start_wg.sh
- ./scripts/reset_wg.sh:/reset_wg.sh
- ./scripts/block_torrent.sh:/block_torrent.sh
- ./scripts/block_exchange.sh:/block_exchange.sh
- ./ssh:/ssh
- ./config/sshd_config:/etc/ssh/sshd_config
hostname: wireguard1
container_name: wireguard1-${VER}
depends_on:
php:
condition: service_healthy
ports:
- ${WG1PORT}:${WG1PORT}/udp
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
environment:
ADDRESS: ${WG1ADDRESS}
cap_add:
- NET_ADMIN
devices:
- /dev/net/tun:/dev/net/tun
stop_grace_period: 1s
command: ["/bin/sh", "/start_wg.sh"]
networks:
default:
ipv4_address: 10.10.0.14
logging: *default-logging
ad:
image: mercurykd/vpnbot-ad:1.1
build:
dockerfile: dockerfile/adguard.dockerfile
args:
@@ -208,8 +316,11 @@ services:
depends_on:
php:
condition: service_healthy
environment:
TZ: ${TZ}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
networks:
default:
@@ -219,6 +330,7 @@ services:
entrypoint: ["/bin/sh", "/start_ad.sh"]
logging: *default-logging
ss:
image: mercurykd/vpnbot-ss:1.1
build:
dockerfile: dockerfile/shadowsocks.dockerfile
args:
@@ -237,9 +349,11 @@ services:
ports:
- ${SSPORT}:${SSPORT}/tcp
- ${SSPORT}:${SSPORT}/udp
environment:
TZ: ${TZ}
SSPORT: ${SSPORT}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_ss.sh"]
networks:
@@ -247,6 +361,7 @@ services:
ipv4_address: 10.10.0.6
logging: *default-logging
tg:
image: mercurykd/vpnbot-tg:1.1
build:
dockerfile: dockerfile/telegram.dockerfile
volumes:
@@ -263,9 +378,12 @@ services:
ports:
- ${TGPORT}:${TGPORT}
environment:
TZ: ${TZ}
IP: ${IP}
TGPORT: ${TGPORT}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_tg.sh"]
networks:
@@ -273,6 +391,7 @@ services:
ipv4_address: 10.10.0.8
logging: *default-logging
xr:
image: mercurykd/vpnbot-xr:1.1
build:
dockerfile: dockerfile/xray.dockerfile
args:
@@ -288,8 +407,11 @@ services:
depends_on:
php:
condition: service_healthy
environment:
TZ: ${TZ}
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_xray.sh"]
networks:
@@ -297,6 +419,7 @@ services:
ipv4_address: 10.10.0.9
logging: *default-logging
oc:
image: mercurykd/vpnbot-oc:1.2
build:
dockerfile: dockerfile/ocserv.dockerfile
args:
@@ -313,9 +436,11 @@ services:
depends_on:
php:
condition: service_healthy
environment:
TZ: ${TZ}
ENV: /root/.ashrc
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_oc.sh"]
cap_add:
@@ -327,6 +452,7 @@ services:
ipv4_address: 10.10.0.11
logging: *default-logging
np:
image: mercurykd/vpnbot-np:1.1
build:
dockerfile: dockerfile/naive.dockerfile
args:
@@ -343,9 +469,11 @@ services:
depends_on:
php:
condition: service_healthy
environment:
TZ: ${TZ}
ENV: /root/.ashrc
env_file:
- path: ./.env
required: true # default
- path: ./override.env
required: false
stop_grace_period: 1s
command: ["/bin/sh", "/start_np.sh"]
cap_add:
+10 -9
View File
@@ -1,21 +1,22 @@
ARG image
FROM $image
RUN apk add --update openssh iptables \
&& apk add --no-cache --virtual .build-deps \
curl \
g++ \
RUN apk add --update openssh \
iptables \
gnutls-dev \
gpgme \
libev-dev \
libnl3-dev \
libseccomp-dev \
linux-headers \
linux-pam-dev \
lz4-dev \
libseccomp-dev \
&& apk add --no-cache --virtual .build-deps \
xz \
linux-headers \
libnl3-dev \
g++ \
gpgme \
curl \
make \
readline-dev \
tar \
xz \
autoconf \
automake \
gperf \
+1
View File
@@ -19,6 +19,7 @@ RUN apk add --no-cache --update php81 \
openssh \
openssl \
curl \
py3-qt5 \
&& wget https://github.com/ameshkov/dnslookup/releases/download/v1.9.1/dnslookup-linux-amd64-v1.9.1.tar.gz \
&& tar -xf dnslookup-linux-amd64-v1.9.1.tar.gz \
&& mv linux-amd64/dnslookup /usr/bin \
+23 -13
View File
@@ -1,12 +1,15 @@
b:
docker compose build
u: # запуск контейнеров
IP=$(shell ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$$|\1|p' | awk '{print $1}' | head -1) VER=$(shell git describe --tags) docker compose up -d --build --force-recreate
bash ./update/update.sh &
touch ./override.env
IP=$(shell curl https://ipinfo.io/ip) VER=$(shell git describe --tags) docker compose --env-file ./.env --env-file ./override.env up -d --force-recreate
d: # остановка контейнеров
docker compose down
-kill -9 $(shell cat ./update/update_pid) > /dev/null
docker compose down --remove-orphans
dv: # остановка контейнеров
docker compose down -v
r: cleanf d u cleanf
r: d cleanf u cleanf
ps: # список контейнеров
docker compose ps
l: # логи из контейнеров
@@ -15,6 +18,8 @@ php: # консоль сервиса
docker compose exec php /bin/sh
wg: # консоль сервиса
docker compose exec wg /bin/sh
wg1: # консоль сервиса
docker compose exec wg1 /bin/sh
ss: # консоль сервиса
docker compose exec ss /bin/sh
ng: # консоль сервиса
@@ -25,12 +30,14 @@ up: # консоль сервиса
docker compose exec up /bin/sh
ad: # консоль сервиса
docker compose exec ad /bin/sh
wp: # консоль сервиса
docker compose exec wp bash
proxy: # консоль сервиса
docker compose exec proxy /bin/sh
tg: # консоль сервиса
docker compose exec tg /bin/sh
xr: # консоль сервиса
docker compose exec xr /bin/shec tg /bin/sh
docker compose exec xr /bin/sh
oc: # консоль сервиса
docker compose exec oc /bin/sh
clean:
@@ -40,12 +47,15 @@ cleanf:
docker image prune -f > /dev/null
docker builder prune -f > /dev/null
cleanall:
docker image prune -a
docker builder prune -a
p:
git stash
git pull
git stash pop stash@{0}
update: p r
cn:
docker compose exec ng nginx -t
docker image prune -a -f
docker builder prune -a -f
push:
docker compose push
s:
git status -su
c:
git add config/
git checkout .
git reset
webhook:
docker compose exec php php checkwebhook.php
+8 -10
View File
@@ -62,19 +62,17 @@ telegram bot to manage servers (inside the bot)
<img src="https://github.com/mercurykd/vpnbot/assets/30900414/431ec09d-9c14-4c74-b8f6-e49c142132e8" width="200">
---
environment: ubuntu 18.04/20.04/22.04, debian 11
environment: ubuntu 18.04/20.04/22.04, debian 11/12
install:
`wget -O- https://raw.githubusercontent.com/mercurykd/vpnbot/master/scripts/init.sh | sh -s YOUR_TELEGRAM_BOT_KEY`
---
additional options:
install as service(autoload on start):
### Install:
```shell
wget -O- https://raw.githubusercontent.com/mercurykd/vpnbot/master/scripts/init.sh | sh -s YOUR_TELEGRAM_BOT_KEY
```
### Install as service (autoload on start):
```shell
cd /root/vpnbot
bash scripts/install_as_service.sh
```
+1 -1
View File
@@ -1,4 +1,4 @@
if [[ -f "/ssh/key.pub" && -s "/ssh/key.pub" ]]; then
if [[ -f "/start" && -f "/ssh/key.pub" && -s "/ssh/key.pub" ]]; then
exit 0;
else
exit 1;
+2 -1
View File
@@ -1,3 +1,4 @@
cp scripts/vpnbot.service /etc/systemd/system/vpnbot.service
path=`pwd`
sed "s|path|$path|g" "$path/scripts/vpnbot.service" > /etc/systemd/system/vpnbot.service
systemctl daemon-reload
systemctl enable vpnbot
+1
View File
@@ -1,4 +1,5 @@
route add -net 10.0.1.0 netmask 255.255.255.0 gw wg
route add -net 10.0.3.0 netmask 255.255.255.0 gw wg1
route add -net 10.0.2.0 netmask 255.255.255.0 gw oc
cat /ssh/key.pub > /root/.ssh/authorized_keys
ssh-keygen -A
+1 -1
View File
@@ -6,4 +6,4 @@ php cron.php &
unitd --log /logs/unit_error
curl -X PUT --data-binary @/config/unit.json --unix-socket /var/run/control.unit.sock http://localhost/config
pkill unitd
unitd --no-daemon --log /logs/unit_error
unitd --no-daemon --control 0.0.0.0:8080 --log /logs/unit_error
+1
View File
@@ -0,0 +1 @@
php service.php
+56 -22
View File
@@ -1,33 +1,67 @@
cat /ssh/key.pub > /root/.ssh/authorized_keys
ssh-keygen -A
exec /usr/sbin/sshd -D -e "$@" &
INTERFACE=$(route | grep '^default' | grep -o '[^ ]*$')
if [ $(cat /etc/wireguard/wg0.conf | wc -c) -eq 0 ]
if [ "$HOSTNAME" = "wireguard1" ]
then
PRIVATEKEY=$(wg genkey | tee /etc/wireguard/privatekey)
echo "[Interface]" > /etc/wireguard/wg0.conf
echo "PrivateKey = $PRIVATEKEY" >> /etc/wireguard/wg0.conf
echo "Address = $ADDRESS" >> /etc/wireguard/wg0.conf
echo "ListenPort = $WGPORT" >> /etc/wireguard/wg0.conf
if [ $(cat /etc/wireguard/wg0.conf | wc -c) -eq 0 ]
then
PRIVATEKEY=$(wg genkey | tee /etc/wireguard/privatekey)
echo "[Interface]" > /etc/wireguard/wg0.conf
echo "PrivateKey = $PRIVATEKEY" >> /etc/wireguard/wg0.conf
echo "Address = $ADDRESS" >> /etc/wireguard/wg0.conf
echo "ListenPort = $WG1PORT" >> /etc/wireguard/wg0.conf
else
sed "s/ListenPort = [0-9]\+/ListenPort = $WG1PORT/" /etc/wireguard/wg0.conf > change_port
cat change_port > /etc/wireguard/wg0.conf
fi
else
sed "s/ListenPort = [0-9]\+/ListenPort = $WGPORT/" /etc/wireguard/wg0.conf > change_port
cat change_port > /etc/wireguard/wg0.conf
if [ $(cat /etc/wireguard/wg0.conf | wc -c) -eq 0 ]
then
PRIVATEKEY=$(wg genkey | tee /etc/wireguard/privatekey)
echo "[Interface]" > /etc/wireguard/wg0.conf
echo "PrivateKey = $PRIVATEKEY" >> /etc/wireguard/wg0.conf
echo "Address = $ADDRESS" >> /etc/wireguard/wg0.conf
echo "ListenPort = $WGPORT" >> /etc/wireguard/wg0.conf
else
sed "s/ListenPort = [0-9]\+/ListenPort = $WGPORT/" /etc/wireguard/wg0.conf > change_port
cat change_port > /etc/wireguard/wg0.conf
fi
fi
iptables -t nat -A POSTROUTING --destination 10.10.0.5 -j ACCEPT
iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE
ln -s /etc/wireguard/wg0.conf /etc/amnezia/amneziawg/wg0.conf
if [ $(cat /pac.json | jq .amnezia) -eq 1 ]
if [ "$HOSTNAME" = "wireguard1" ]
then
awg-quick up wg0
if [ $(cat /pac.json | jq .wg1_amnezia) -eq 1 ]
then
awg-quick up wg0
else
wg-quick up wg0
fi
if [ $(cat /pac.json | jq .wg1_blocktorrent) -eq 1 ]
then
sh /block_torrent.sh
fi
if [ $(cat /pac.json | jq .wg1_exchange) -eq 1 ]
then
sh /block_exchange.sh
fi
else
wg-quick up wg0
fi
cat /ssh/key.pub > /root/.ssh/authorized_keys
ssh-keygen -A
exec /usr/sbin/sshd -D -e "$@" &
if [ $(cat /pac.json | jq .blocktorrent) -eq 1 ]
then
sh /block_torrent.sh
fi
if [ $(cat /pac.json | jq .exchange) -eq 1 ]
then
sh /block_exchange.sh
if [ $(cat /pac.json | jq .amnezia) -eq 1 ]
then
awg-quick up wg0
else
wg-quick up wg0
fi
if [ $(cat /pac.json | jq .blocktorrent) -eq 1 ]
then
sh /block_torrent.sh
fi
if [ $(cat /pac.json | jq .exchange) -eq 1 ]
then
sh /block_exchange.sh
fi
fi
tail -f /dev/null
-1
View File
@@ -1 +0,0 @@
iptables -D FORWARD -i wg0 -o wg0 -j REJECT
-12
View File
@@ -1,12 +0,0 @@
iptables -D FORWARD -p tcp -m ipp2p --bit -j DROP
iptables -D FORWARD -p udp -m ipp2p --bit -j DROP
iptables -D FORWARD -m string --algo bm --string "BitTorrent" -j DROP
iptables -D FORWARD -m string --algo bm --string "BitTorrent protocol" -j DROP
iptables -D FORWARD -m string --algo bm --string "peer_id=" -j DROP
iptables -D FORWARD -m string --algo bm --string ".torrent" -j DROP
iptables -D FORWARD -m string --algo bm --string "announce.php?passkey=" -j DROP
iptables -D FORWARD -m string --algo bm --string "torrent" -j DROP
iptables -D FORWARD -m string --algo bm --string "announce" -j DROP
iptables -D FORWARD -m string --algo bm --string "info_hash" -j DROP
iptables -D OUTPUT -p tcp -m ipp2p --bit -j DROP
iptables -D OUTPUT -p udp -m ipp2p --bit -j DROP
+8 -4
View File
@@ -3,10 +3,14 @@ Description=VPN: Docker Compose Application Service
Requires=docker.service
After=docker.service
[Service]
WorkingDirectory=/root/vpnbot
ExecStart=/bin/sh -c "IP=$(ip -4 addr | sed -ne 's|^.* inet \([^/]*\)/.* scope global.*$|\1|p' | awk '{print $1}' | head -1) docker compose up --build --force-recreate"
ExecStop=/usr/bin/docker compose down
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=path
ExecStartPre=/bin/sh -c "touch ./override.env"
ExecStart=/bin/sh -c "IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose --env-file ./.env --env-file ./override.env up -d --force-recreate"
ExecStartPost=/bin/sh -c "bash ./update/update.sh &"
ExecStop=/bin/sh -c "docker compose down --remove-orphans"
ExecStopPost=/bin/sh -c "kill -9 $(cat ./update/update_pid) > /dev/null"
TimeoutStartSec=0
Restart=on-failure
[Install]
WantedBy=multi-user.target
+6
View File
@@ -0,0 +1,6 @@
@url = http://127.0.0.1:8081
###
GET {{url}}/status
###
GET {{url}}/config
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
pwd=`pwd`
> $pwd/update/pipe
echo "$$" > $pwd/update/update_pid
while true
do
cmd=$(cat $pwd/update/pipe)
if [[ -n "$cmd" ]]
then
docker compose down --remove-orphans
git reset --hard
git pull > ./update/message
IP=$(curl https://ipinfo.io/ip) VER=$(git describe --tags) docker compose up -d --force-recreate
bash $pwd/update/update.sh &
exit 0
fi
sleep 1
done
+34
View File
@@ -1,3 +1,37 @@
17.03.2024 v1.9
- автоматический технический домен sslip
13.03.2024 v1.8.10
- фикс override.env
10.03.2024 v1.8.9
- веб морда адгварда "встроена" в телеграм
- мелкие улучшения меню
07.03.2024 v1.8.8
- фикс не работающего wireguard
07.03.2024 v1.8.7
- фикс порта амнезии
- у кого ошибка запуска обновите докер и докер композ
07.03.2024 v1.8.6
- фикс синхронизации клиентов амнезии, бот падал после рестарта, клиенты пропадали
- возможность переназначить порты в override.env, файл не отслеживаемый, обновление не будет его сбрасывать
- убрал дублирование образа php
06.03.2024
- короткие ссылки для амнезии
- фикс работы openconnect
- фикс экспорта пользователей openconnect
- фикс скрипта установки бота как сервиса
04.03.2024
- решение "серого айпи" при запуске
- фикс стартового скрипта второго контейнера wireguard
03.03.2024 возможность обновления бота по кнопке из самого бота
- <code>git pull && make r</code>
02.03.2024 2 сервера wireguard, для возможности один запускать как wireguard а второй как amnezia
- <code>git pull && make r</code>
01.03.2024 фикс блокировок торрентов и обмена между пользователями
- <code>git pull && make r</code>
01.03.2024 фикс установки домена с длинным названием
- <code>make update</code>
29.02.2024 образы теперь будут скачиваться с docker hub
- <code>git pull && make d cleanall u</code>
28.02.2024 v1.1 добавлен раздел "зеркало"
- <code>git pull && make r</code>
27.02.2024 оптимизация размеров образов, сборка naive из исходников