diff --git a/app/bot.php b/app/bot.php index e5d36d9..2d19336 100644 --- a/app/bot.php +++ b/app/bot.php @@ -281,6 +281,9 @@ class Bot case preg_match('~^/timerXr (\d+)$~', $this->input['callback'], $m): $this->timerXr($m[1]); break; + case preg_match('~^/switchXr (\d+)$~', $this->input['callback'], $m): + $this->switchXr($m[1]); + break; case preg_match('~^/delxr (\d+)$~', $this->input['callback'], $m): $this->delxr($m[1]); break; @@ -1046,16 +1049,11 @@ class Bot { try { $c = $this->getXray(); - $f = 0; foreach ($c['inbounds'][0]['settings']['clients'] as $k => $v) { - if (!empty($v['time']) && $v['time'] < time()) { - unset($c['inbounds'][0]['settings']['clients'][$k]); - $f = 1; + if (!empty($v['time']) && ($v['time'] < time())) { + $this->switchXr($k, 1); } } - if (!empty($f)) { - $this->restartXray($c); - } } catch (Exception $e) { } } @@ -3506,16 +3504,42 @@ DNS-over-HTTPS with IP: public function setTimerXr($time, $i) { + $time = strtotime($time); + if ($time === false) { + $this->send($this->input['chat'], 'wrong format'); + return; + } $c = $this->getXray(); if (empty($time)) { unset($c['inbounds'][0]['settings']['clients'][$i]['time']); } else { - $c['inbounds'][0]['settings']['clients'][$i]['time'] = strtotime($time); + if (!empty($c['inbounds'][0]['settings']['clients'][$i]['off'])) { + $this->switchXr($i, 1); + $c = $this->getXray(); + } + $c['inbounds'][0]['settings']['clients'][$i]['time'] = $time; } file_put_contents('/config/xray.json', json_encode($c, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); $this->userXr($i); } + public function switchXr($i, $nm = 0) + { + $c = $this->getXray(); + unset($c['inbounds'][0]['settings']['clients'][$i]['time']); + if (empty($c['inbounds'][0]['settings']['clients'][$i]['off'])) { + $c['inbounds'][0]['settings']['clients'][$i]['off'] = $c['inbounds'][0]['settings']['clients'][$i]['id']; + $c['inbounds'][0]['settings']['clients'][$i]['id'] = trim($this->ssh('xray uuid', 'xr')); + } else { + $c['inbounds'][0]['settings']['clients'][$i]['id'] = $c['inbounds'][0]['settings']['clients'][$i]['off']; + unset($c['inbounds'][0]['settings']['clients'][$i]['off']); + } + $this->restartXray($c); + if (empty($nm)) { + $this->userXr($i); + } + } + public function renXrUs($name, $i) { $c = $this->getXray(); @@ -3552,7 +3576,7 @@ DNS-over-HTTPS with IP: $time = $v['time'] ? $this->getTime($v['time']) : ''; $data[] = [ [ - 'text' => "{$v['email']}" . ($time ? ": $time" : ''), + 'text' => $this->i18n($v['off'] ? 'off' : 'on') . " {$v['email']}" . ($time ? ": $time" : ''), 'callback_data' => "/userXr $k", ], ]; @@ -3593,15 +3617,15 @@ DNS-over-HTTPS with IP: $text[] = "v2ray: $v2ray\n"; $text[] = "sing-box: $sing"; - if ($time = $c['inbounds'][0]['settings']['clients'][$i]['time']) { - $text[] = "\ntimer: " . $this->getTime($time); - } - $data[] = [ [ - 'text' => $this->i18n('timer'), + 'text' => $c['inbounds'][0]['settings']['clients'][$i]['time'] ? "timer: " . $this->getTime($c['inbounds'][0]['settings']['clients'][$i]['time']) : $this->i18n('timer'), 'callback_data' => "/timerXr $i", ], + [ + 'text' => $this->i18n($c['inbounds'][0]['settings']['clients'][$i]['off'] ? 'off' : 'on'), + 'callback_data' => "/switchXr $i", + ], ]; $data[] = [ [ @@ -3647,7 +3671,9 @@ DNS-over-HTTPS with IP: if (!empty($fs)) { return $this->userXr($k, 0, 1); } - $flag = false; + if (empty($v['off'])) { + $flag = false; + } break; } } @@ -3684,7 +3710,10 @@ DNS-over-HTTPS with IP: if (!empty($fs)) { return $this->userXr($k, 1); } - $flag = false; + if (empty($v['off'])) { + $flag = false; + } + break; } } @@ -3692,8 +3721,6 @@ DNS-over-HTTPS with IP: return false; } - - $c = json_decode(file_get_contents('/config/sing.json'), true); if ($c['dns']['servers'][0]['address'] == '~dns~') {