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