Compare commits

..

10 Commits

Author SHA1 Message Date
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
18 changed files with 354 additions and 125 deletions
+2
View File
@@ -1,6 +1,8 @@
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
+1
View File
@@ -16,3 +16,4 @@
.vscode/
.idea/
mirror/.env
update/
+189 -93
View File
@@ -4,6 +4,7 @@ class Bot
{
public $input;
public $adguard;
public $update;
public function __construct($key, $i18n)
{
@@ -11,6 +12,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 +20,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 +124,18 @@ 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('~^/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 +942,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 +976,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),
@@ -990,10 +1010,14 @@ class Bot
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 +1036,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 {
@@ -1043,8 +1071,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_amnezia);
$this->iptablesWG();
}
// ad
if (!empty($json['ad'])) {
@@ -1099,7 +1138,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);
@@ -1119,8 +1158,12 @@ class Bot
$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 +1211,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 +1245,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 +1268,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 +1278,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);
}
@@ -1402,7 +1449,7 @@ class Bot
$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);
@@ -2118,15 +2165,22 @@ 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();
$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 = [
[
[
@@ -2207,7 +2261,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 +2298,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);
@@ -2486,7 +2540,7 @@ DNS-over-HTTPS with IP:
$name = $this->getName($clients[$client]['interface']);
$conf = $this->createConfig($clients[$client]);
return [
'text' => "<code>$conf</code>\n\n<b>$name</b>",
'text' => "<code>$conf</code>\n\n<b>$name</b> ({$this->getTitleWG()})",
'data' => [
[
[
@@ -2893,30 +2947,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 +2976,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 +2993,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",
],
],
[
@@ -2960,7 +3026,7 @@ DNS-over-HTTPS with IP:
'text' => $this->i18n('donate'),
'url' => "https://yoomoney.ru/to/410011827900450",
],
]
],
],
],
'wg' => $type == 'wg' ? $this->statusWg($arg) : false,
@@ -2977,7 +3043,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 +3354,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'),
@@ -3429,6 +3495,15 @@ 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();
@@ -3539,6 +3614,12 @@ DNS-over-HTTPS with IP:
'callback_data' => "/debug",
],
];
$data[] = [
[
'text' => $this->i18n('update bot'),
'callback_data' => "/updatebot",
],
];
$data[] = [
[
'text' => $this->i18n('back'),
@@ -3700,9 +3781,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 +3829,8 @@ DNS-over-HTTPS with IP:
public function readStatus()
{
$r = $this->ssh($this->getWGType());
// $this->sd([$this->getWGType(), $this->getInstanceWG()]);
$r = $this->ssh($this->getWGType(), $this->getInstanceWG());
$r = explode(PHP_EOL, $r);
$r = array_filter($r);
$i = 0;
@@ -3785,7 +3875,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 +3887,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 +3900,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 +3924,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 +3947,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 +3958,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 +3968,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 +3977,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()] : []
),
],
];
@@ -3924,27 +4014,28 @@ DNS-over-HTTPS with IP:
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 +4097,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()
+4
View File
@@ -301,4 +301,8 @@ $i = [
'en' => 'download',
'ru' => 'скачать',
],
'update bot' => [
'en' => 'update bot',
'ru' => 'обновить бота',
],
];
-6
View File
@@ -11,9 +11,3 @@ $bot = new Bot($c['key'], $i);
$bot->setwebhook();
$bot->setcommands();
$bot->syncPortClients();
if (!empty($c['admin'])) {
$ip = getenv('IP');
foreach ($c['admin'] as $k => $v) {
$bot->send($v, "start $ip");
}
}
+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->menu();
+1
View File
@@ -0,0 +1 @@
[]
+1
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;
+1
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;
View File
+92 -2
View File
@@ -101,13 +101,17 @@ services:
- ./version:/version
- ./mirror:/mirror
- ./.env:/mirror/.env
- ./update:/update
environment:
TZ: ${TZ}
IP: ${IP}
ADDRESS: ${WGADDRESS}
WGPORT: ${WGPORT}
WG1ADDRESS: ${WG1ADDRESS}
WG1PORT: ${WG1PORT}
SSPORT: ${SSPORT}
TGPORT: ${TGPORT}
VER: ${VER}
hostname: php
container_name: php-${VER}
restart: unless-stopped
@@ -125,6 +129,55 @@ services:
interval: 5s
timeout: 5s
retries: 5
service:
image: mercurykd/vpnbot-php:1.1
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:
TZ: ${TZ}
IP: ${IP}
ADDRESS: ${WGADDRESS}
WGPORT: ${WGPORT}
WG1ADDRESS: ${WG1ADDRESS}
WG1PORT: ${WG1PORT}
SSPORT: ${SSPORT}
TGPORT: ${TGPORT}
VER: ${VER}
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:
@@ -164,9 +217,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
@@ -180,6 +231,7 @@ services:
TZ: ${TZ}
WGPORT: ${WGPORT}
ADDRESS: ${WGADDRESS}
ENV: /root/.ashrc
cap_add:
- NET_ADMIN
devices:
@@ -190,6 +242,44 @@ 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
environment:
TZ: ${TZ}
WGPORT: ${WG1PORT}
ADDRESS: ${WG1ADDRESS}
ENV: /root/.ashrc
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:
+14 -10
View File
@@ -1,12 +1,14 @@
b:
docker compose build
u: # запуск контейнеров
bash ./update/update.sh &
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 --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 +17,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 +29,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:
@@ -42,12 +48,10 @@ cleanf:
cleanall:
docker image prune -a -f
docker builder prune -a -f
p:
git stash
git pull
git stash pop stash@{0}
update: p r
cn:
docker compose exec ng nginx -t
push:
docker compose push
s:
git status -su
c:
git add config/
git checkout .
+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;
+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
View File
@@ -0,0 +1 @@
php service.php
-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
View File
@@ -1,3 +1,11 @@
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 добавлен раздел "зеркало"