119 lines
3.7 KiB
PHP
119 lines
3.7 KiB
PHP
<?php
|
|
/**
|
|
* Pencil Automator - Main Entry Point
|
|
* Requires authentication via SSO (or mock user if SSO disabled)
|
|
*/
|
|
|
|
// Require authentication
|
|
$user = ['name' => 'User', 'preferred_username' => 'user@localhost'];
|
|
$ssoEnabled = false;
|
|
|
|
try {
|
|
if (file_exists(__DIR__ . '/AuthMiddleware.php')) {
|
|
require_once 'AuthMiddleware.php';
|
|
$auth = new AuthMiddleware();
|
|
$user = $auth->requireAuth(); // Blocks if not authenticated
|
|
$ssoEnabled = $auth->isSSOEnabled();
|
|
}
|
|
} catch (Exception $e) {
|
|
// Log error but don't block app
|
|
error_log("Auth error (app will continue without auth): " . $e->getMessage());
|
|
}
|
|
|
|
// Read and serve the UI HTML
|
|
$uiContent = file_get_contents(__DIR__ . '/ui.html');
|
|
|
|
// Extract the body content from ui.html
|
|
preg_match('/<body>(.*?)<\/body>/s', $uiContent, $bodyMatches);
|
|
$bodyContent = $bodyMatches[1] ?? '';
|
|
|
|
// Extract the style content from ui.html
|
|
preg_match('/<style>(.*?)<\/style>/s', $uiContent, $styleMatches);
|
|
$styleContent = $styleMatches[1] ?? '';
|
|
|
|
// Extract the script content from ui.html
|
|
preg_match_all('/<script[^>]*>(.*?)<\/script>/s', $uiContent, $scriptMatches);
|
|
$scriptContent = implode("\n", $scriptMatches[1] ?? []);
|
|
|
|
// Extract external script sources
|
|
preg_match_all('/<script[^>]*src="([^"]*)"[^>]*><\/script>/s', $uiContent, $externalScripts);
|
|
$externalScriptSources = $externalScripts[1] ?? [];
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Pencil Automator</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
/* Auth header styles */
|
|
.auth-header {
|
|
background: #2c2c2c;
|
|
padding: 12px 20px;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
border-bottom: 1px solid #444;
|
|
}
|
|
.auth-user-info {
|
|
color: #aaa;
|
|
font-size: 12px;
|
|
}
|
|
.auth-user-name {
|
|
color: #18A0FB;
|
|
font-weight: 600;
|
|
}
|
|
.btn-logout {
|
|
background-color: #444;
|
|
color: white;
|
|
border: none;
|
|
padding: 6px 16px;
|
|
border-radius: 4px;
|
|
font-weight: 500;
|
|
cursor: pointer;
|
|
font-size: 11px;
|
|
}
|
|
.btn-logout:hover {
|
|
background-color: #555;
|
|
}
|
|
|
|
/* Original UI styles */
|
|
<?php echo $styleContent; ?>
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<?php if ($ssoEnabled): ?>
|
|
<div class="auth-header">
|
|
<div class="auth-user-info">
|
|
Logged in as <span class="auth-user-name"><?php echo htmlspecialchars($user['name'] ?? $user['preferred_username'] ?? 'User'); ?></span>
|
|
</div>
|
|
<button onclick="signOut()" class="btn-logout">🔒 Log Out</button>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php echo $bodyContent; ?>
|
|
|
|
<?php foreach ($externalScriptSources as $src): ?>
|
|
<script src="<?php echo htmlspecialchars($src); ?>"></script>
|
|
<?php endforeach; ?>
|
|
|
|
<script>
|
|
<?php if ($ssoEnabled): ?>
|
|
function signOut() {
|
|
fetch('auth.php', {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ action: 'logout' })
|
|
})
|
|
.then(() => window.location.reload())
|
|
.catch(err => console.error('Logout error:', err));
|
|
}
|
|
<?php endif; ?>
|
|
|
|
<?php echo $scriptContent; ?>
|
|
</script>
|
|
</body>
|
|
</html>
|