fix: update logic for waiting
This commit is contained in:
@ -29,9 +29,13 @@ class LoginController
|
||||
$configPath = __DIR__ . '/../../config.json';
|
||||
$config = file_exists($configPath) ? json_decode(file_get_contents($configPath), true) : [];
|
||||
$name = $config[$domain] ?? null;
|
||||
|
||||
$params = (array)$request->getParsedBody();
|
||||
|
||||
if(!$name){
|
||||
return $this->json($response, [
|
||||
'status' => 'not_found',
|
||||
'message' => 'Container not found',
|
||||
], 404);
|
||||
}
|
||||
$captcha = new PCaptcha();
|
||||
|
||||
if (!$captcha->validate_captcha($params['panswer'])) {
|
||||
|
||||
@ -30,13 +30,13 @@ const checkStatus = async () => {
|
||||
try {
|
||||
const res = await $fetch(`${window.location.origin}/api/status?name=${name}`);
|
||||
status.value = res.status;
|
||||
|
||||
if (interval.value) {
|
||||
clearInterval(interval.value);
|
||||
}
|
||||
if (res.status === 'ready') {
|
||||
ip.value = res.ip;
|
||||
clearInterval(interval.value);
|
||||
loading.value = false;
|
||||
// Redirect or show login link
|
||||
window.location.href= redirect ?? `http://${res.ip}`;
|
||||
window.location.href= 'http://'+ window.location.host;
|
||||
}
|
||||
} catch (error) {
|
||||
loading.value = false;
|
||||
@ -44,8 +44,8 @@ const checkStatus = async () => {
|
||||
errorMessage.value = error?.data?.message || 'Internal server error!';
|
||||
clearInterval(interval.value);
|
||||
setTimeout( () => {
|
||||
router.replace(`/?auth=ok&redirect=${redirect}`);
|
||||
}, 3000);
|
||||
router.replace(`/app/?auth=ok&redirect=${redirect}`);
|
||||
}, 5000);
|
||||
|
||||
}
|
||||
};
|
||||
@ -56,7 +56,9 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
clearInterval(interval.value);
|
||||
if (interval.value) {
|
||||
clearInterval(interval.value);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style scoped>
|
||||
|
||||
20
index.php
20
index.php
@ -11,9 +11,12 @@ if (str_starts_with($requestUri, '/api/')) {
|
||||
require __DIR__ . "/api/vendor/autoload.php";
|
||||
require __DIR__ . "/api/src/Services/LxdService.php";
|
||||
|
||||
use Dotenv\Dotenv;
|
||||
use Zounar\PHPProxy\Proxy;
|
||||
use App\Services\LxdService;
|
||||
|
||||
// 🔹 Load .env config
|
||||
$dotenv = Dotenv::createImmutable(__DIR__ . '/api/');
|
||||
$dotenv->load();
|
||||
|
||||
$host = $_SERVER['HTTP_HOST'] ?? '';
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
@ -25,8 +28,7 @@ $lxd = new LxdService();
|
||||
|
||||
// === Helper URLs ===
|
||||
$redirectBase = parseUrl("$host/app?auth=ok&redirect=" . urlencode(getFullUrl()));
|
||||
$waitingPage = parseUrl("$host/app/waiting?name=$container&redirect=" . urlencode($requestUri));
|
||||
|
||||
$waitingPage = parseUrl("$host/app/waiting?name=$container&redirect=" . urlencode(getFullUrl()));
|
||||
// === If container is missing or invalid ===
|
||||
if (!$container || !$lxd->containerExists($container)) {
|
||||
redirect($redirectBase);
|
||||
@ -39,9 +41,19 @@ if ($state !== 'Running') {
|
||||
redirect($redirectBase);
|
||||
}
|
||||
|
||||
// === Check container status ===
|
||||
$state = $lxd->getContainerState($container)['metadata']['status'] ?? 'Stopped';
|
||||
|
||||
if ($state !== 'Running') {
|
||||
redirect($redirectBase);
|
||||
}
|
||||
|
||||
// === Get container IP ===
|
||||
$ip = $lxd->getContainerIP($container);
|
||||
if (!$ip) {
|
||||
$nginx = $lxd->isServiceRunning($container, 'nginx');
|
||||
$mysql = $lxd->isServiceRunning($container, 'mysql');
|
||||
|
||||
if (!$ip || $nginx !== 'active' || $mysql !== 'active') {
|
||||
redirect($waitingPage);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user