Initial Commit

This commit is contained in:
mrkmntal 2025-10-25 15:10:38 -04:00
commit 1d85bf6663
7 changed files with 377 additions and 0 deletions

33
admin/auth.php Normal file
View file

@ -0,0 +1,33 @@
<?php
session_start();
require_once __DIR__ . '/config.php';
if (isset($_POST['password'])) {
if (password_verify($_POST['password'], $ADMIN_PASS_HASH)) {
$_SESSION['auth'] = true;
header("Location: upload.php");
exit;
} else {
$error = "Invalid password.";
}
}
if (!isset($_SESSION['auth'])):
?>
<!DOCTYPE html>
<html>
<head><title>Login - MentalNet Funnies Admin</title></head>
<body style="background:#111;color:#eee;font-family:monospace;text-align:center">
<h1>🔒 MentalNet Funnies Admin</h1>
<form method="post">
<input type="password" name="password" placeholder="Password" autofocus>
<button type="submit">Login</button>
</form>
<?php if (!empty($error)) echo "<p style='color:red;'>$error</p>"; ?>
</body>
</html>
<?php
exit;
endif;
?>

22
admin/config.php Normal file
View file

@ -0,0 +1,22 @@
<?php
// --- basic config ---
$db_file = __DIR__ . '/../mentalnet_funnies.db';
// password hash (generate with: php -r "echo password_hash('yourpassword', PASSWORD_DEFAULT);")
$ADMIN_PASS_HASH = 'pwhashgoeshere';
// create db if not exists
if (!file_exists($db_file)) {
$db = new SQLite3($db_file);
$db->exec("CREATE TABLE comics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
filename TEXT NOT NULL,
description TEXT,
date_added DATETIME DEFAULT CURRENT_TIMESTAMP
)");
} else {
$db = new SQLite3($db_file);
}
?>

20
admin/init_db.php Normal file
View file

@ -0,0 +1,20 @@
<?php
$db = new SQLite3(__DIR__ . '/../mentalnet_funnies.db');
// Check if the table already exists
$result = $db->querySingle("SELECT name FROM sqlite_master WHERE type='table' AND name='comics'");
if ($result) {
echo " Table 'comics' already exists.";
} else {
$db->exec("CREATE TABLE comics (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
filename TEXT NOT NULL,
description TEXT,
date_added DATETIME DEFAULT CURRENT_TIMESTAMP
)");
echo "✅ Table 'comics' created.";
}
?>

40
admin/upload.php Normal file
View file

@ -0,0 +1,40 @@
<?php
require_once __DIR__ . '/auth.php'; // ensures login
require_once __DIR__ . '/config.php';
$msg = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['comic'])) {
$title = trim($_POST['title']);
$desc = trim($_POST['description']);
$file = $_FILES['comic'];
if ($file['error'] === UPLOAD_ERR_OK && $title) {
$ext = pathinfo($file['name'], PATHINFO_EXTENSION);
$fname = uniqid('comic_') . '.' . $ext;
move_uploaded_file($file['tmp_name'], __DIR__ . '/../uploads/' . $fname);
$stmt = $db->prepare("INSERT INTO comics (title, filename, description) VALUES (:t,:f,:d)");
$stmt->bindValue(':t',$title,SQLITE3_TEXT);
$stmt->bindValue(':f',$fname,SQLITE3_TEXT);
$stmt->bindValue(':d',$desc,SQLITE3_TEXT);
$stmt->execute();
$msg = "✅ Uploaded '$title'";
} else $msg = "Upload failed.";
}
?>
<!DOCTYPE html>
<html>
<head><title>Upload Comic - MentalNet Funnies</title></head>
<body style="background:#111;color:#eee;font-family:monospace;text-align:center">
<h1>🧠 Upload Comic</h1>
<p><?=htmlspecialchars($msg)?></p>
<form method="post" enctype="multipart/form-data">
<p><input type="text" name="title" placeholder="Title" required></p>
<p><textarea name="description" placeholder="Description"></textarea></p>
<p><input type="file" name="comic" accept="image/*" required></p>
<p><button type="submit">Upload</button></p>
</form>
<p><a href="../index.php" style="color:#0ff;"> View Site</a></p>
</body>
</html>