Compare commits

...

3 Commits

Author SHA1 Message Date
mercury 8effb72cdc update version 2026-03-10 10:05:12 +04:00
mercury bec8f5488e reset amnezia keys fix 2026-03-08 01:23:12 +04:00
mercury f97b0f9228 amneziawg2.0 2026-03-08 01:12:09 +04:00
3 changed files with 131 additions and 96 deletions
+127 -94
View File
@@ -461,9 +461,6 @@ class Bot
case preg_match('~^/enterPage$~', $this->input['callback'], $m): case preg_match('~^/enterPage$~', $this->input['callback'], $m):
$this->enterPage(); $this->enterPage();
break; break;
case preg_match('~^/geodb$~', $this->input['callback'], $m):
$this->geodb();
break;
case preg_match('~^/adguardreset$~', $this->input['callback'], $m): case preg_match('~^/adguardreset$~', $this->input['callback'], $m):
$this->adguardreset(); $this->adguardreset();
break; break;
@@ -521,6 +518,9 @@ class Bot
case preg_match('~^/switchAmnezia (-?\d+)$~', $this->input['callback'], $m): case preg_match('~^/switchAmnezia (-?\d+)$~', $this->input['callback'], $m):
$this->switchAmnezia($m[1]); $this->switchAmnezia($m[1]);
break; break;
case preg_match('~^/resetAmnezia (-?\d+)$~', $this->input['callback'], $m):
$this->resetAmnezia($m[1]);
break;
case preg_match('~^/switchExchange (\d+)$~', $this->input['callback'], $m): case preg_match('~^/switchExchange (\d+)$~', $this->input['callback'], $m):
$this->switchExchange($m[1]); $this->switchExchange($m[1]);
break; break;
@@ -2073,63 +2073,65 @@ class Bot
$this->restartWG($this->createConfig($server)); $this->restartWG($this->createConfig($server));
} }
public function switchAmnezia($page = 0) public function resetAmnezia($page = 0) {
$this->switchAmnezia($page, 1);
}
public function switchAmnezia($page = 0, $reset = false)
{ {
$c = $this->getPacConf(); $c = $this->getPacConf();
$amnezia = $c[$this->getInstanceWG(1) . 'amnezia'] = $c[$this->getInstanceWG(1) . 'amnezia'] ? 0 : 1; if (empty($reset)) {
$amnezia = $c[$this->getInstanceWG(1) . 'amnezia'] = $c[$this->getInstanceWG(1) . 'amnezia'] ? 0 : 1;
} else {
$amnezia = 1;
unset($c[$this->getInstanceWG(1) . 'amnezia_keys']);
unset($c[$this->getInstanceWG(1) . 'presharedkey']);
}
$this->setPacConf($c); $this->setPacConf($c);
$pk = $this->presharedKey(); $pk = $this->presharedKey();
$ak = $this->amneziaKeys(); $ak = $this->amneziaKeys();
$clients = $this->readClients(); $clients = $this->readClients();
foreach ($clients as $k => $v) { foreach ($clients as $k => $v) {
unset($clients[$k]['peers'][0]['PresharedKey']);
unset($clients[$k]['interface']['Jc']);
unset($clients[$k]['interface']['Jmin']);
unset($clients[$k]['interface']['Jmax']);
unset($clients[$k]['interface']['S1']);
unset($clients[$k]['interface']['S2']);
unset($clients[$k]['interface']['S3']);
unset($clients[$k]['interface']['S4']);
unset($clients[$k]['interface']['H1']);
unset($clients[$k]['interface']['H2']);
unset($clients[$k]['interface']['H3']);
unset($clients[$k]['interface']['H4']);
unset($clients[$k]['interface']['I1']);
if (!empty($amnezia)) { if (!empty($amnezia)) {
$clients[$k]['peers'][0]['PresharedKey'] = $pk; $clients[$k]['peers'][0]['PresharedKey'] = $pk;
$clients[$k]['interface']['Jc'] = $ak['Jc']; foreach ($ak as $j => $i) {
$clients[$k]['interface']['Jmin'] = $ak['Jmin']; $clients[$k]['interface'][$j] = $i;
$clients[$k]['interface']['Jmax'] = $ak['Jmax']; }
$clients[$k]['interface']['S1'] = $ak['S1'];
$clients[$k]['interface']['S2'] = $ak['S2'];
$clients[$k]['interface']['H1'] = $ak['H1'];
$clients[$k]['interface']['H2'] = $ak['H2'];
$clients[$k]['interface']['H3'] = $ak['H3'];
$clients[$k]['interface']['H4'] = $ak['H4'];
} else {
unset($clients[$k]['peers'][0]['PresharedKey']);
unset($clients[$k]['interface']['Jc']);
unset($clients[$k]['interface']['Jmin']);
unset($clients[$k]['interface']['Jmax']);
unset($clients[$k]['interface']['S1']);
unset($clients[$k]['interface']['S2']);
unset($clients[$k]['interface']['H1']);
unset($clients[$k]['interface']['H2']);
unset($clients[$k]['interface']['H3']);
unset($clients[$k]['interface']['H4']);
} }
} }
$this->saveClients($clients); $this->saveClients($clients);
$wg = $this->readConfig(); $wg = $this->readConfig();
unset($wg['interface']['Jc']);
unset($wg['interface']['Jmin']);
unset($wg['interface']['Jmax']);
unset($wg['interface']['S1']);
unset($wg['interface']['S2']);
unset($wg['interface']['S3']);
unset($wg['interface']['S4']);
unset($wg['interface']['H1']);
unset($wg['interface']['H2']);
unset($wg['interface']['H3']);
unset($wg['interface']['H4']);
unset($wg['interface']['I1']);
if (!empty($amnezia)) { if (!empty($amnezia)) {
$wg['interface']['Jc'] = $ak['Jc']; foreach ($ak as $j => $i) {
$wg['interface']['Jmin'] = $ak['Jmin']; $wg['interface'][$j] = $i;
$wg['interface']['Jmax'] = $ak['Jmax']; }
$wg['interface']['S1'] = $ak['S1'];
$wg['interface']['S2'] = $ak['S2'];
$wg['interface']['H1'] = $ak['H1'];
$wg['interface']['H2'] = $ak['H2'];
$wg['interface']['H3'] = $ak['H3'];
$wg['interface']['H4'] = $ak['H4'];
} else {
unset($wg['interface']['Jc']);
unset($wg['interface']['Jmin']);
unset($wg['interface']['Jmax']);
unset($wg['interface']['S1']);
unset($wg['interface']['S2']);
unset($wg['interface']['H1']);
unset($wg['interface']['H2']);
unset($wg['interface']['H3']);
unset($wg['interface']['H4']);
} }
foreach ($wg['peers'] as $k => $v) { foreach ($wg['peers'] as $k => $v) {
@@ -3359,12 +3361,6 @@ DNS-over-HTTPS with IP:
$am = $c[$this->getInstanceWG(1) . 'amnezia']; $am = $c[$this->getInstanceWG(1) . 'amnezia'];
$end = $c[$this->getInstanceWG(1) . 'endpoint']; $end = $c[$this->getInstanceWG(1) . 'endpoint'];
$data = [ $data = [
[
[
'text' => $this->i18n($am ? 'on' : 'off') . " amnezia",
'callback_data' => "/switchAmnezia $page",
],
],
[ [
[ [
'text' => $this->i18n(!$bt ? 'on' : 'off') . " {$this->i18n('torrent')} ", 'text' => $this->i18n(!$bt ? 'on' : 'off') . " {$this->i18n('torrent')} ",
@@ -3402,6 +3398,20 @@ DNS-over-HTTPS with IP:
], ],
], ],
]; ];
if (!empty($am)) {
array_unshift($data, [
[
'text' => "reset obf-keys",
'callback_data' => "/resetAmnezia $page",
],
]);
}
array_unshift($data, [
[
'text' => $this->i18n($am ? 'on' : 'off') . " amnezia",
'callback_data' => "/switchAmnezia $page",
],
]);
if ($clients) { if ($clients) {
$data = array_merge($data, $clients); $data = array_merge($data, $clients);
} }
@@ -3809,46 +3819,51 @@ DNS-over-HTTPS with IP:
public function getAmneziaShortLink($client) public function getAmneziaShortLink($client)
{ {
$domain = $this->getDomain(); $domain = $this->getDomain();
$dns = explode(',', $client['interface']['DNS']); $pac = $this->getPacConf();
$c = json_encode([ $dnsRaw = $client['interface']['DNS'] ?: $pac[$this->getInstanceWG(1) . 'dns'] ?: $this->dns;
$dns = array_map('trim', explode(',', $dnsRaw));
$wgPort = (int) getenv($this->getInstanceWG() == 'wg1' ? 'WG1PORT' : 'WGPORT');
$c = [
"containers" => [ "containers" => [
[ [
"awg" => [ "awg" => [
"isThirdPartyConfig" => True, "isThirdPartyConfig" => true,
"last_config" => json_encode([ "last_config" => json_encode(array_merge(array_map('strval', $this->amneziaKeys()), [
"H1" => "{$client['interface']['H1']}", "protocol_version" => "2",
"H2" => "{$client['interface']['H2']}", "client_ip" => $client['interface']['Address'],
"H3" => "{$client['interface']['H3']}", "client_priv_key" => $client['interface']['PrivateKey'],
"H4" => "{$client['interface']['H4']}", "client_pub_key" => "0",
"Jc" => "{$client['interface']['Jc']}", "config" => $this->createConfig($client),
"Jmax" => "{$client['interface']['Jmax']}", "hostName" => $domain,
"Jmin" => "{$client['interface']['Jmin']}", "port" => $wgPort,
"S1" => "{$client['interface']['S1']}", "psk_key" => $client['peers'][0]['PresharedKey'],
"S2" => "{$client['interface']['S2']}", "server_pub_key" => $client['peers'][0]['PublicKey'],
"client_ip" => explode('/', $client['interface']['Address'])[0], "allowed_ips" => array_map('trim', explode(',', $client['peers'][0]['AllowedIPs'])),
"client_priv_key" => $client['interface']['PrivateKey'], "persistent_keep_alive" => "25"
"client_pub_key" => "0", ])),
"config" => $this->createConfig($client), "port" => $wgPort,
"hostName" => $domain, "transport_proto" => "udp",
"port" => (int) getenv($this->getInstanceWG() == 'wg1' ? 'WG1PORT' : 'WGPORT'), "protocol_version" => "2"
"psk_key" => $client['peers'][0]['PresharedKey'],
"server_pub_key" => $client['peers'][0]['PublicKey']
]),
"port" => (int) getenv('WG1PORT'),
"transport_proto" => "udp"
], ],
"container" => "amnezia-awg" "container" => "amnezia-awg2"
] ]
], ],
"defaultContainer" => "amnezia-awg", "defaultContainer" => "amnezia-awg2",
"description" => $client['interface']['## name'], "description" => $client['interface']['## name'],
"dns1" => $dns[0], "dns1" => $dns[0] ?? '',
"dns2" => $dns[1] ?: '', "dns2" => $dns[1] ?? '',
"hostName" => $domain "hostName" => $domain,
]); "isThirdPartyConfig" => true
exec("echo '$c' | python amnezia.py", $o); ];
return $o[0]; $json = json_encode($c);
$proc = proc_open('python amnezia.py', [0 => ['pipe', 'r'], 1 => ['pipe', 'w']], $pipes);
fwrite($pipes[0], $json);
fclose($pipes[0]);
$result = trim(stream_get_contents($pipes[1]));
fclose($pipes[1]);
proc_close($proc);
return $result;
} }
public function getClient($client, $page) public function getClient($client, $page)
@@ -3856,7 +3871,7 @@ DNS-over-HTTPS with IP:
$clients = $this->readClients(); $clients = $this->readClients();
if ($clients) { if ($clients) {
$name = $this->getName($clients[$client]['interface']); $name = $this->getName($clients[$client]['interface']);
$conf = $this->createConfig($clients[$client]); $conf = htmlspecialchars($this->createConfig($clients[$client]));
if ($this->getWGType() == 'awg') { if ($this->getWGType() == 'awg') {
$sl = $this->getAmneziaShortLink($clients[$client]); $sl = $this->getAmneziaShortLink($clients[$client]);
} }
@@ -8947,7 +8962,7 @@ DNS-over-HTTPS with IP:
$this->update( $this->update(
$this->input['chat'], $this->input['chat'],
$this->input['message_id'], $this->input['message_id'],
implode("\n", $text ?: ['...']), implode("\n", ['...']),
$data ?: false, $data ?: false,
); );
} }
@@ -9398,16 +9413,34 @@ DNS-over-HTTPS with IP:
{ {
$c = $this->getPacConf(); $c = $this->getPacConf();
if (empty($c[$this->getInstanceWG(1) . 'amnezia_keys'])) { if (empty($c[$this->getInstanceWG(1) . 'amnezia_keys'])) {
// S1 and S2: 064 bytes; constraint: S1 + 56 ≠ S2
$s1 = random_int(15, 64);
do {
$s2 = random_int(15, 64);
} while ($s1 + 56 === $s2);
// H1H4: distinct 32-bit values (must not overlap)
$h = [];
while (count($h) < 4) {
$v = random_int(1, 4_294_967_295);
if (!in_array($v, $h)) {
$h[] = $v;
}
}
$c[$this->getInstanceWG(1) . 'amnezia_keys'] = [ $c[$this->getInstanceWG(1) . 'amnezia_keys'] = [
'Jc' => rand(3, 10), 'Jc' => random_int(3, 10),
'Jmin' => 50, 'Jmin' => 64,
'Jmax' => 1000, 'Jmax' => 1000,
'S1' => rand(15, 150), 'S1' => $s1,
'S2' => rand(15, 150), 'S2' => $s2,
'H1' => rand(1, 2_147_483_647), 'S3' => random_int(0, 64),
'H2' => rand(1, 2_147_483_647), 'S4' => random_int(0, 32),
'H3' => rand(1, 2_147_483_647), 'H1' => $h[0],
'H4' => rand(1, 2_147_483_647), 'H2' => $h[1],
'H3' => $h[2],
'H4' => $h[3],
'I1' => '<b 0xc000000001><r 100>',
]; ];
$this->setPacConf($c); $this->setPacConf($c);
} }
+2 -2
View File
@@ -214,7 +214,7 @@ services:
- dnstt - dnstt
- hy - hy
wg: wg:
image: mercurykd/vpnbot-wg:1.1 image: mercurykd/vpnbot-wg:1.2
build: build:
dockerfile: dockerfile/wireguard.dockerfile dockerfile: dockerfile/wireguard.dockerfile
args: args:
@@ -252,7 +252,7 @@ services:
ipv4_address: 10.10.0.4 ipv4_address: 10.10.0.4
logging: *default-logging logging: *default-logging
wg1: wg1:
image: mercurykd/vpnbot-wg:1.1 image: mercurykd/vpnbot-wg:1.2
build: build:
dockerfile: dockerfile/wireguard.dockerfile dockerfile: dockerfile/wireguard.dockerfile
args: args:
+2
View File
@@ -1,3 +1,5 @@
10.03.2026 v2.29
- amnezia 2.0
16.12.2025 v2.28.1 16.12.2025 v2.28.1
- фикс шаблона mihomo - фикс шаблона mihomo
15.12.2025 v2.28 15.12.2025 v2.28