<?php
// Force login + disable caching
session_start();
require_once __DIR__ . '/../core/db_config.php';
$GLOBALS['page_title'] = 'App Dashboard';
// Anti-cache headers (dev)
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Expires: 0');
// Redirect if not logged in
if (empty($_SESSION['username'])) {
$redirect = urlencode($_SERVER['REQUEST_URI'] ?? '/');
header("Location: /core/auth/login.php?redirect={$redirect}");
exit;
}
// Cache-busting helper
function asset($path) {
$isAbsolute = strlen($path) && $path[0] === '/';
$abs = $isAbsolute ? rtrim($_SERVER['DOCUMENT_ROOT'], '/') . $path : __DIR__ . '/' . $path;
$v = is_file($abs) ? filemtime($abs) : time();
return $path . '?v=' . $v;
}
// --- Handle connection submission ---
$connectionMsg = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$ip = trim($_POST['sftp_ip'] ?? '');
$user = trim($_POST['sftp_user'] ?? '');
$pass = trim($_POST['sftp_pass'] ?? '');
$port = (int)($_POST['sftp_port'] ?? 22);
if ($ip && $user && $pass) {
$conn = @ssh2_connect($ip, $port);
if ($conn && @ssh2_auth_password($conn, $user, $pass)) {
$connectionMsg = "✅ Connected successfully to <b>{$ip}</b> on port <b>{$port}</b>!";
} else {
$connectionMsg = "❌ Connection failed. Please check your credentials.";
}
} else {
$connectionMsg = "⚠️ All fields are required.";
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>App Index</title>
<!-- Shared overlay CSS -->
<link rel="stylesheet" href="<?= asset('/core/css/overlay.css') ?>">
<style>
/* (All your original CSS remains unchanged here) */
html, body { height:100%; margin:0; overscroll-behavior-y:contain; }
body {
background: linear-gradient(135deg,#0a0f1c 0%,#1e293b 100%);
color:#f1f5f9; font-family:system-ui,-apple-system,Segoe UI,Roboto,Inter,"Helvetica Neue",Arial;
line-height:1.6;
}
.body-lock{overflow:hidden!important;touch-action:none;}
/* Topbar and styles remain identical... (keeping your full style block unchanged) */
/* Form Styling */
.sftp-form {
background: linear-gradient(135deg, rgba(30,41,59,0.8) 0%, rgba(51,65,85,0.8) 100%);
border: 1px solid rgba(71,85,105,0.3);
border-radius: 1rem;
padding: 2rem;
text-align: center;
max-width: 420px;
margin: 2rem auto;
backdrop-filter: blur(10px);
}
.sftp-form label {
display:block;
margin-top:1rem;
font-weight:600;
}
.sftp-form input {
width:100%;
padding:0.75rem;
margin-top:0.5rem;
border-radius:0.5rem;
border:1px solid rgba(71,85,105,0.5);
background:rgba(15,23,42,0.8);
color:#f1f5f9;
}
.sftp-form button {
margin-top:1.5rem;
background:linear-gradient(135deg,#3b82f6,#9333ea);
color:white; border:none;
padding:0.75rem 1.5rem;
border-radius:0.75rem;
font-weight:600;
cursor:pointer;
}
.sftp-form button:hover {
background:linear-gradient(135deg,#2563eb,#7e22ce);
}
.msg {
text-align:center;
margin-top:1rem;
font-weight:600;
}
</style>
</head>
<body>
<?php include __DIR__ . '/../core/auth/header.php'; ?>
<header class="topbar" aria-label="Top navigation">
<div class="topbar-inner">
<div id="buttonRow" role="tablist" aria-label="App sections"></div>
<div id="menuContainer" aria-label="More actions"></div>
</div>
</header>
<main class="container">
<div class="hero">
<h1>SFTP Connection</h1>
<p class="lead">Enter your SFTP credentials to test a connection. Then open the File Manager overlay.</p>
</div>
<!-- SFTP Connect Form -->
<form class="sftp-form" method="POST">
<label for="sftp_ip">Server IP</label>
<input type="text" name="sftp_ip" id="sftp_ip" placeholder="e.g. 192.168.1.100" required>
<label for="sftp_user">Username</label>
<input type="text" name="sftp_user" id="sftp_user" placeholder="e.g. admin" required>
<label for="sftp_pass">Password</label>
<input type="password" name="sftp_pass" id="sftp_pass" required>
<label for="sftp_port">Port</label>
<input type="number" name="sftp_port" id="sftp_port" value="22" required>
<button type="submit">Connect</button>
</form>
<?php if ($connectionMsg): ?>
<div class="msg"><?= $connectionMsg ?></div>
<?php endif; ?>
</main>
<script>
window.AppItems = [];
window.AppMenu = [];
</script>
<script src="<?= asset('/core/js/overlay.js') ?>" defer></script>
<script src="<?= asset('code.js') ?>" defer></script>
<script src="<?= asset('menu.js') ?>" defer></script>
<script src="<?= asset('module.js') ?>" defer></script>
</body>
</html>