fix export/import config bot

This commit is contained in:
mercury
2023-02-12 02:52:57 +04:00
parent bd4b1d3b7d
commit 2f9a8f7b8f
2 changed files with 31 additions and 15 deletions
+23 -7
View File
@@ -363,7 +363,6 @@ class Bot
'private' => file_exists('/certs/cert_private') ? file_get_contents('/certs/cert_private') : false,
'public' => file_exists('/certs/cert_public') ? file_get_contents('/certs/cert_public') : false,
],
'nginx' => file_get_contents('/config/nginx.conf')
];
$this->upload(date('d_m_Y_H_i') . '.json', json_encode($conf, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
@@ -437,13 +436,30 @@ class Bot
file_put_contents('/certs/cert_public', $json['ssl']['public']);
}
// nginx
if (!empty($json['nginx'])) {
$out[] = 'reload nginx';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
file_put_contents('/config/nginx.conf', $json['nginx']);
$this->ssh("nginx -s reload 2>&1", 'ng');
$out[] = 'reset nginx';
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$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);
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);
}
}
$out[] = 'end import';
if (!empty($json['ssl'])) {
$name = $json['pac']['letsencrypt'] ? 'letsencrypt' : 'self';
$t = preg_replace('/#~([^\n]+)?/', "#~$name", $t);
preg_match_all('~#-ssl.+?#-ssl~s', $t, $m);
foreach ($m[0] as $k => $v) {
$t = preg_replace('~#-ssl.+?#-ssl~s', $this->uncomment($v, 'ssl'), $t, 1);
}
}
file_put_contents('/config/nginx.conf', $t);
$out[] = $this->ssh("nginx -s reload 2>&1", 'ng');
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
$out[] = "end import";
$this->update($this->input['chat'], $this->input['message_id'], implode("\n", $out));
sleep(3);
$this->menu();
+8 -8
View File
@@ -61,18 +61,18 @@ http {
#~
#~domain
#-domain
# server {
# listen 80;
# server_name ;
#~domain
#~ssl
#-domain
#-ssl
# listen 443 ssl http2;
# ssl_certificate /certs/cert_public;
# ssl_certificate_key /certs/cert_private;
#~ssl
#-ssl
#~domain
#-domain
# access_log /logs/nginx_domain_access;
# location / {
@@ -119,7 +119,7 @@ http {
# proxy_pass http://dohloop;
# }
# }
#~domain
#-domain
# This upstream connects to a local Stream service which converts HTTP -> DNS
upstream dohloop {
@@ -154,11 +154,11 @@ stream {
# Terminate DoT and DNS TCP, and proxy onto standard DNS
server {
listen 53;
#~ssl
#-ssl
# listen 853 ssl;
# ssl_certificate /certs/cert_public;
# ssl_certificate_key /certs/cert_private;
#~ssl
#-ssl
js_preread dns.preread_dns_request;
proxy_pass dns;
}