diff --git a/panel/api/endpoints/proxy.php b/panel/api/endpoints/proxy.php index 138da27..3809a7f 100644 --- a/panel/api/endpoints/proxy.php +++ b/panel/api/endpoints/proxy.php @@ -40,13 +40,19 @@ try { $action === 'control' && $method === 'POST' => (function() use ($body) { $act = $body['action'] ?? ''; if (!in_array($act, ['start','stop','restart','reload'])) Response::error('Invalid action', 400); - $result = match($act) { + $result = match($act) { 'start' => ProxyManager::start(), 'stop' => ProxyManager::stop(), 'restart' => ProxyManager::restart(), 'reload' => ProxyManager::reload(), }; - Response::json(['success' => true, 'data' => ['result' => $result, 'running' => ProxyManager::isRunning()]]); + $running = ProxyManager::isRunning(); + $success = match($act) { + 'start', 'restart' => $running, + 'stop' => !$running, + 'reload' => !str_starts_with($result, 'Config test failed'), + }; + Response::json(['success' => $success, 'data' => ['result' => $result, 'running' => $running]]); })(), // GET hosts list diff --git a/panel/lib/ProxyManager.php b/panel/lib/ProxyManager.php index 5d66de3..c6113c0 100644 --- a/panel/lib/ProxyManager.php +++ b/panel/lib/ProxyManager.php @@ -145,9 +145,9 @@ class ProxyManager { self::remoteExec('systemctl reload nginx'); return 'reloaded'; } - $test = shell_exec('nginx -t 2>&1'); + $test = shell_exec('sudo nginx -t 2>&1'); if (strpos($test ?? '', 'successful') === false) return 'Config test failed: ' . $test; - shell_exec('systemctl reload nginx 2>/dev/null'); + shell_exec('sudo systemctl reload nginx 2>/dev/null'); return 'reloaded'; } @@ -565,7 +565,7 @@ BASH; sleep(1); return self::isRunning() ? 'running' : 'stopped'; } - shell_exec("systemctl {$action} nginx 2>/dev/null"); + shell_exec("sudo systemctl {$action} nginx 2>/dev/null"); sleep(1); return self::isRunning() ? 'running' : 'stopped'; } diff --git a/panel/public/assets/js/admin.js b/panel/public/assets/js/admin.js index f7bd846..7c14315 100644 --- a/panel/public/assets/js/admin.js +++ b/panel/public/assets/js/admin.js @@ -2733,9 +2733,13 @@ window.proxyInstall = async () => { }; window.proxyControl = async (action) => { + Nova.loading(action.charAt(0).toUpperCase() + action.slice(1) + 'ing nginx…'); const r = await Nova.api('proxy', 'control', { method: 'POST', body: { action } }); - Nova.toast(r?.data?.result || r?.message || action + ' done', 'success'); - setTimeout(() => Nova.loadPage('nginx-proxy', window._novaPages), 800); + Nova.loadingDone(); + const ok = r?.success; + const msg = r?.data?.result || r?.message || (ok ? action + ' done' : action + ' failed'); + Nova.toast(msg, ok ? 'success' : 'error'); + Nova.loadPage('nginx-proxy', window._novaPages); }; window.proxySync = async () => {