|
|
|
@@ -1324,7 +1324,7 @@ class Bot
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function importFile($file = false)
|
|
|
|
|
public function importFile($file = false, $autoupdate = false)
|
|
|
|
|
{
|
|
|
|
|
if (!empty($file)) {
|
|
|
|
|
$json = json_decode(file_get_contents($file), true);
|
|
|
|
@@ -1364,7 +1364,11 @@ class Bot
|
|
|
|
|
$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);
|
|
|
|
|
if (empty($autoupdate)) {
|
|
|
|
|
$this->restartWG($this->createConfig($json['wg']['server']), $switch_amnezia);
|
|
|
|
|
} else {
|
|
|
|
|
file_put_contents('/config/wg0.conf', $this->createConfig($json['wg']['server']));
|
|
|
|
|
}
|
|
|
|
|
$this->iptablesWG();
|
|
|
|
|
}
|
|
|
|
|
// wg1
|
|
|
|
@@ -1373,7 +1377,11 @@ class Bot
|
|
|
|
|
$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);
|
|
|
|
|
if (empty($autoupdate)) {
|
|
|
|
|
$this->restartWG($this->createConfig($json['wg1']['server']), $switch_wg1amnezia);
|
|
|
|
|
} else {
|
|
|
|
|
file_put_contents('/config/wg1.conf', $this->createConfig($json['wg1']['server']));
|
|
|
|
|
}
|
|
|
|
|
$this->iptablesWG();
|
|
|
|
|
}
|
|
|
|
|
// ad
|
|
|
|
@@ -1456,8 +1464,10 @@ class Bot
|
|
|
|
|
$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)) {
|
|
|
|
|
sleep(3);
|
|
|
|
|
$this->menu();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1804,7 +1814,7 @@ class Bot
|
|
|
|
|
$this->addDomain(str_replace('.', '-', $this->ip) . '.nip.io', 1);
|
|
|
|
|
$this->setSSL('letsencrypt');
|
|
|
|
|
}
|
|
|
|
|
$this->menu(dontshowcron: 1);
|
|
|
|
|
$this->menu();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function comment($text, $tag)
|
|
|
|
@@ -3855,13 +3865,13 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
$this->menu('wg', 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function menu($type = false, $arg = false, $return = false, $dontshowcron = false)
|
|
|
|
|
public function menu($type = false, $arg = false, $return = false)
|
|
|
|
|
{
|
|
|
|
|
$domain = $this->getPacConf()['domain'] ?: $this->ip;
|
|
|
|
|
$cron = exec('pgrep -f cron.php');
|
|
|
|
|
$menu = [
|
|
|
|
|
'main' => [
|
|
|
|
|
'text' => 'v' . getenv('VER') . ($dontshowcron ? '' : "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show <code>logs/php_error</code>')),
|
|
|
|
|
'text' => 'v' . getenv('VER') . ($this->dontshowcron ? '' : "\ncron: " . $this->i18n($cron ? 'on' : 'off') . ($cron ? '' : ' show <code>logs/php_error</code>')),
|
|
|
|
|
'data' => [
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
@@ -5041,6 +5051,14 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
}
|
|
|
|
|
$json['routing']['rules'] = array_values($json['routing']['rules']);
|
|
|
|
|
}
|
|
|
|
|
if (!empty($json['route']['rules'])) {
|
|
|
|
|
foreach ($json['route']['rules'] as $k => $v) {
|
|
|
|
|
if (count($v) < 2) {
|
|
|
|
|
unset($json['route']['rules'][$k]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$json['route']['rules'] = array_values($json['route']['rules']);
|
|
|
|
|
}
|
|
|
|
|
return json_encode($json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -5732,28 +5750,21 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
|
|
|
|
|
public function selfUpdate()
|
|
|
|
|
{
|
|
|
|
|
require __DIR__ . '/config.php';
|
|
|
|
|
if (!empty($c['admin'])) {
|
|
|
|
|
$ip = getenv('IP');
|
|
|
|
|
$rm = explode(':', trim(file_get_contents('/update/reload_message')));
|
|
|
|
|
$m = file_get_contents('/update/message');
|
|
|
|
|
if (file_exists($this->update)) {
|
|
|
|
|
$r = $this->send($c['admin'][0], "start update");
|
|
|
|
|
$this->input['chat'] = $c['admin'][0];
|
|
|
|
|
$this->input['message_id'] = $r['result']['message_id'];
|
|
|
|
|
if (!empty($m)) {
|
|
|
|
|
$this->send($c['admin'][0], "<pre>$m</pre>", $rm[1]);
|
|
|
|
|
}
|
|
|
|
|
$r = $this->send($c['admin'][0], "import settings");
|
|
|
|
|
$this->input['chat'] = $c['admin'][0];
|
|
|
|
|
$this->input['message_id'] = $r['result']['message_id'];
|
|
|
|
|
$this->input['callback_id'] = $r['result']['message_id'];
|
|
|
|
|
if (empty($flag)) {
|
|
|
|
|
$this->importFile($this->update);
|
|
|
|
|
unlink($this->update);
|
|
|
|
|
$flag = true;
|
|
|
|
|
}
|
|
|
|
|
$ip = getenv('IP');
|
|
|
|
|
$rm = explode(':', trim(file_get_contents('/update/reload_message')));
|
|
|
|
|
$m = file_get_contents('/update/message');
|
|
|
|
|
$this->input['chat'] = $rm[0];
|
|
|
|
|
$this->input['message_id'] = $rm[1];
|
|
|
|
|
$this->input['callback_id'] = $rm[1];
|
|
|
|
|
if (file_exists($this->update)) {
|
|
|
|
|
if (!empty($m)) {
|
|
|
|
|
$this->send($this->input['chat'], "<pre>$m</pre>", $rm[1]);
|
|
|
|
|
}
|
|
|
|
|
$r = $this->send($this->input['chat'], "import settings");
|
|
|
|
|
$this->input['message_id'] = $r['result']['message_id'];
|
|
|
|
|
$this->input['callback_id'] = $r['result']['message_id'];
|
|
|
|
|
$this->importFile($this->update, 1);
|
|
|
|
|
unlink($this->update);
|
|
|
|
|
}
|
|
|
|
|
file_put_contents('/update/message', '');
|
|
|
|
|
file_put_contents('/update/reload_message', '');
|
|
|
|
@@ -6013,25 +6024,25 @@ DNS-over-HTTPS with IP:
|
|
|
|
|
|
|
|
|
|
public function createConfig($data)
|
|
|
|
|
{
|
|
|
|
|
$pac = $this->getPacConf();
|
|
|
|
|
$conf[] = "[Interface]";
|
|
|
|
|
if (empty($data['interface']['ListenPort'])) {
|
|
|
|
|
if (empty($data['interface']['DNS'])) {
|
|
|
|
|
$data['interface']['DNS'] = $this->getPacConf()[$this->getInstanceWG(1) . 'dns'] ?: $this->dns;
|
|
|
|
|
$data['interface']['DNS'] = $pac[$this->getInstanceWG(1) . 'dns'] ?: $this->dns;
|
|
|
|
|
}
|
|
|
|
|
if (empty($data['interface']['MTU'])) {
|
|
|
|
|
$data['interface']['MTU'] = $this->getPacConf()[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu;
|
|
|
|
|
$data['interface']['MTU'] = $pac[$this->getInstanceWG(1) . 'mtu'] ?: $this->mtu;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
foreach ($data['interface'] as $k => $v) {
|
|
|
|
|
$conf[] = "$k = $v";
|
|
|
|
|
}
|
|
|
|
|
$pac = $this->getPacConf();
|
|
|
|
|
if (!empty($data['peers'])) {
|
|
|
|
|
foreach ($data['peers'] as $peer) {
|
|
|
|
|
$conf[] = '';
|
|
|
|
|
$conf[] = $peer['# PublicKey'] ? '# [Peer]' : '[Peer]';
|
|
|
|
|
if (!empty($peer['Endpoint'])) {
|
|
|
|
|
$peer['Endpoint'] = ($this->getPacConf()[$this->getInstanceWG(1) . 'endpoint'] ? $this->ip : $this->getDomain()) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT');
|
|
|
|
|
$peer['Endpoint'] = ($pac[$this->getInstanceWG(1) . 'endpoint'] ? $this->ip : $this->getDomain()) . ":" . getenv($this->getInstanceWG(1) ? 'WG1PORT' : 'WGPORT');
|
|
|
|
|
}
|
|
|
|
|
foreach ($peer as $k => $v) {
|
|
|
|
|
$conf[] = "$k = $v";
|
|
|
|
|