nginx reset button for post-import migration

This commit is contained in:
mercury
2023-02-10 23:25:23 +04:00
parent 1a1ed3a9f7
commit f3cf7ec58e
3 changed files with 213 additions and 0 deletions
+30
View File
@@ -122,6 +122,9 @@ class Bot
case preg_match('~^/checkdns$~', $this->input['callback'], $m):
$this->checkdns();
break;
case preg_match('~^/resetnginx$~', $this->input['callback'], $m):
$this->resetnginx();
break;
case preg_match('~^/adguardpsswd$~', $this->input['callback'], $m):
$this->adguardpsswd();
break;
@@ -719,6 +722,27 @@ class Bot
];
}
public function resetnginx()
{
$nginx = file_get_contents('/config/nginx.conf');
$default = file_get_contents('/config/nginx_default.conf');
file_put_contents('/config/nginx.conf', $default);
$u = $this->ssh("nginx -t 2>&1", 'ng');
$out[] = $u;
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
if (preg_match('~test is successful~', $u)) {
$out[] = $this->ssh("nginx -s reload 2>&1", 'ng');
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$conf = $this->getPacConf();
unset($conf['domain']);
$this->setPacConf($conf);
} else {
file_put_contents('/config/nginx.conf', $nginx);
}
sleep(5);
$this->menu('config');
}
public function adguardpsswd()
{
$r = $this->send(
@@ -1687,6 +1711,12 @@ DNS-over-HTTPS with IP:
];
}
}
$data[] = [
[
'text' => 'reset nginx',
'callback_data' => "/resetnginx",
],
];
$data[] = [
[
'text' => 'import',