Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4998893234 | |||
| 95f92791b1 | |||
| cedfb66ca0 |
+31
-20
@@ -1076,23 +1076,27 @@ class Bot
|
||||
public function checkBackup()
|
||||
{
|
||||
$c = $this->getPacConf();
|
||||
$now = strtotime(date('Y-m-d H:i'));
|
||||
if (!empty($c['backup'])) {
|
||||
$now = strtotime(date('Y-m-d H:i:s'));
|
||||
[$start, $period] = explode('/', $c['backup']);
|
||||
$start = strtotime($start);
|
||||
$period = strtotime($period, 0);
|
||||
if (!empty($start) && !empty($period)) {
|
||||
if ($now - $start >= $period && ($now - $start) % $period == 0) {
|
||||
if (!empty($c['pinbackup'])) {
|
||||
$this->pinAdmin($c['pinbackup'], 1);
|
||||
}
|
||||
$this->pinBackup();
|
||||
$start = strtotime(trim($start));
|
||||
$period = strtotime(trim($period), 0);
|
||||
if (
|
||||
!empty($start)
|
||||
&& !empty($period)
|
||||
&& empty($this->backup)
|
||||
&& $now - $start >= $period
|
||||
&& ($now - $start) % $period < 10
|
||||
) {
|
||||
if (!empty($c['pinbackup'])) {
|
||||
$this->pinAdmin($c['pinbackup'], 1);
|
||||
}
|
||||
$this->pinBackup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function cleanQueue()
|
||||
public function cleanQueue(): void
|
||||
{
|
||||
$r = $this->request('deleteWebhook', []);
|
||||
$r = $this->request('getUpdates', ['offset' => -1]);
|
||||
@@ -1112,9 +1116,8 @@ class Bot
|
||||
{
|
||||
require __DIR__ . '/config.php';
|
||||
$conf = $this->getPacConf();
|
||||
$bot = $this->request('getMyName', [])['result']['name'];
|
||||
$bot = preg_replace('~[\W]~iu', '_', $this->request('getMyName', [])['result']['name']);
|
||||
$conf['pinbackup'] = $this->upload("{$bot}_export_" . date('d_m_Y_H_i') . '.json', $this->export(), $c['admin'][0])['result']['message_id'];
|
||||
$conf['backup'] = implode(' / ', [date('Y-m-d H:i'), trim(explode('/', $conf['backup'])[1])]);
|
||||
$this->setPacConf($conf);
|
||||
$this->pinAdmin($conf['pinbackup']);
|
||||
}
|
||||
@@ -1324,7 +1327,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 +1367,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 +1380,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
|
||||
@@ -5755,7 +5766,7 @@ DNS-over-HTTPS with IP:
|
||||
$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);
|
||||
$this->importFile($this->update, 1);
|
||||
unlink($this->update);
|
||||
}
|
||||
file_put_contents('/update/message', '');
|
||||
@@ -6016,25 +6027,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";
|
||||
|
||||
Reference in New Issue
Block a user