Last version, good buy
This commit is contained in:
parent
cffcd77bc0
commit
fe79434001
|
@ -1,6 +1,6 @@
|
|||
Parsedown.php
|
||||
credentials.csv
|
||||
pages/*
|
||||
users/*
|
||||
public/font/*
|
||||
public/img/*
|
||||
!.gitkeep
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
// This page is the
|
||||
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
|
||||
echo $_GET['p'];
|
||||
|
||||
$path = $_SERVER["DOCUMENT_ROOT"] . "/public" . $_GET['p'];
|
||||
|
||||
?>
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
function unixToDate($unixTime) {
|
||||
return date('Y-m-d', $unixTime);
|
||||
}
|
||||
|
||||
function sluggify($string) {
|
||||
$string = strtolower($string);
|
||||
$string = str_replace(' ', '-', $string);
|
||||
|
||||
$string = str_split($string);
|
||||
$result = "";
|
||||
$slugAcceptable = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
||||
foreach ($string as $c) {
|
||||
if (stripos($slugAcceptable, $c) !== false) $result .= $c;
|
||||
}
|
||||
$result = trim($result, "-");
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/users.php");
|
||||
|
||||
function verifyKey($username, $password) {
|
||||
$user = new User($username);
|
||||
return password_verify($password, $user->hash);
|
||||
}
|
||||
|
||||
function generateHash($password) {
|
||||
return password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
function verifyKeyOld($username, $password) {
|
||||
$csv = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/../credentials.csv');
|
||||
$hashes = explode(PHP_EOL, $csv);
|
||||
foreach ($hashes as $hash) {
|
||||
$hash = explode(';', $hash);
|
||||
if ($hash[0] == $username) {
|
||||
$hash = substr($hash[2], 0, -1);
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
|
@ -0,0 +1,82 @@
|
|||
<?php
|
||||
|
||||
|
||||
$pagesFolder = $_SERVER["DOCUMENT_ROOT"] . '/../pages/';
|
||||
|
||||
class Page {
|
||||
public $title;
|
||||
public $slug;
|
||||
public $author;
|
||||
public $cDate;
|
||||
public $mDate;
|
||||
public $content;
|
||||
|
||||
function __construct($pageSlug = '') {
|
||||
if (existPage($pageSlug)) {
|
||||
$pageJSON = json_decode(file_get_contents(getPageJSONPath($pageSlug)));
|
||||
foreach ($pageJSON as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
$this->slug = $pageSlug;
|
||||
}
|
||||
}
|
||||
|
||||
function write() {
|
||||
$filePath = getPageJSONPath($this->slug);
|
||||
|
||||
// Remove attributes that should be serialized
|
||||
$slug = $this->slug;
|
||||
unset($this->slug);
|
||||
|
||||
$file = fopen($filePath, 'w');
|
||||
fwrite($file, json_encode($this));
|
||||
fclose($file);
|
||||
|
||||
// Add them back
|
||||
$this->slug = $slug;
|
||||
}
|
||||
|
||||
function delete() {
|
||||
$filePath = getPageJSONPath($this->slug);
|
||||
if (file_exists($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
|
||||
function rename($newSlug) {
|
||||
rename(getPageJSONPath($this->slug), getPageJSONPath($newSlug));
|
||||
$this->slug = $newSlug;
|
||||
}
|
||||
|
||||
function parse() {
|
||||
require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/Parsedown.php");
|
||||
$parsedown = new Parsedown();
|
||||
$parsedown->setSafeMode(true);
|
||||
return $parsedown->text($this->content);
|
||||
}
|
||||
}
|
||||
|
||||
function getListSlugPages() {
|
||||
global $pagesFolder;
|
||||
$pages = scandir($pagesFolder);
|
||||
$pages = array_slice($pages, 2);
|
||||
$result = array();
|
||||
foreach ($pages as $page) {
|
||||
if (substr($page, -5, 5) == '.json') {
|
||||
array_push($result, substr($page, 0, -5));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function existPage($pageSlug) {
|
||||
return file_exists(getPageJSONPath($pageSlug));
|
||||
}
|
||||
|
||||
function getPageJSONPath($pageSlug) {
|
||||
global $pagesFolder;
|
||||
return $pagesFolder . $pageSlug . '.json';
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -0,0 +1,83 @@
|
|||
<?php
|
||||
|
||||
|
||||
$rootFolder = $_SERVER["DOCUMENT_ROOT"] . '/../users/';
|
||||
|
||||
class User {
|
||||
public $name;
|
||||
public $slug;
|
||||
public $role;
|
||||
public $hash;
|
||||
public $content;
|
||||
|
||||
function __construct($slug = '') {
|
||||
if (exist($slug)) {
|
||||
$json = json_decode(file_get_contents(getPathJSON($slug)));
|
||||
foreach ($json as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
$this->slug = $slug;
|
||||
}
|
||||
}
|
||||
|
||||
function write() {
|
||||
$filePath = getPathJSON($this->slug);
|
||||
|
||||
// Remove attributes that should be serialized
|
||||
$slug = $this->slug;
|
||||
unset($this->slug);
|
||||
|
||||
$file = fopen($filePath, 'w');
|
||||
fwrite($file, json_encode($this));
|
||||
fclose($file);
|
||||
|
||||
// Add them back
|
||||
$this->slug = $slug;
|
||||
}
|
||||
|
||||
function delete() {
|
||||
if (exist($this->slug)) {
|
||||
unlink(getPathJSON($this->slug));
|
||||
}
|
||||
}
|
||||
|
||||
function rename($newSlug) {
|
||||
rename(getPageJSONPath($this->slug), getPageJSONPath($newSlug));
|
||||
$this->slug = $newSlug;
|
||||
}
|
||||
|
||||
function parse() {
|
||||
require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/Parsedown.php");
|
||||
$parsedown = new Parsedown();
|
||||
$parsedown->setSafeMode(true);
|
||||
return $parsedown->text($this->content);
|
||||
}
|
||||
}
|
||||
|
||||
function getListSlug() {
|
||||
global $rootFolder;
|
||||
$items = scandir($rootFolder);
|
||||
$result = array();
|
||||
foreach ($items as $item) {
|
||||
if (substr($item, -5, 5) == '.json') {
|
||||
array_push($result, substr($item, 0, -5));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function exist($slug) {
|
||||
return file_exists(getPathJSON($slug));
|
||||
}
|
||||
|
||||
function getPathJSON($slug) {
|
||||
global $rootFolder;
|
||||
return $rootFolder . $slug . '.json';
|
||||
}
|
||||
|
||||
function getCurrentUser() {
|
||||
return new User($_SESSION['loginUsername']);
|
||||
}
|
||||
|
||||
|
||||
?>
|
|
@ -1,11 +0,0 @@
|
|||
<div id="admin-bar">
|
||||
<h1>Accord's CMS</h1>
|
||||
<?php
|
||||
if (session_status() == PHP_SESSION_NONE) session_start();
|
||||
if (isset($_SESSION['loginUsername'])) {
|
||||
echo '<div id="logout">Welcome ' . $_SESSION['loginUsername'] . '<a class="button" href="/admin/logout.php">Logout</a></div>';
|
||||
} else {
|
||||
header('Location: /');
|
||||
}
|
||||
?>
|
||||
</div>
|
|
@ -1,37 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/admin-bar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/tools.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<?php
|
||||
|
||||
if (isset($_GET['page'])) {
|
||||
$page = new Page($_GET['page']);
|
||||
|
||||
if (isset($_GET['confirm'])) {
|
||||
$page->delete();
|
||||
header('Location: /admin');
|
||||
exit();
|
||||
}
|
||||
|
||||
echo "<h2>Deletion of $page->title</h2>";
|
||||
echo "<p>Are you sure you want to delete this page?</p>";
|
||||
echo "<a class='button' href='/admin'>Cancel<a>";
|
||||
echo "<a class='button' href='/admin/delete.php?page=$page->slug&confirm=true'>Confirm<a>";
|
||||
}
|
||||
|
||||
?>
|
||||
</body>
|
||||
</html>
|
|
@ -1,55 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Accord's CMS</title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/admin-bar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/tools.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="title">
|
||||
<h2>Pages</h2>
|
||||
<a class='button' href='/admin/edit.php?page='>Create a new page</a>
|
||||
</div>
|
||||
|
||||
<div class="page-list">
|
||||
|
||||
<p>Title</p>
|
||||
<p>Author</p>
|
||||
<p>Last edit</p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
|
||||
<?php
|
||||
|
||||
// Get all MD files
|
||||
foreach (getListSlugPages() as $pageSlug) {
|
||||
|
||||
$page = new Page($pageSlug);
|
||||
|
||||
echo "<p> - " . $page->title . "</p>";
|
||||
echo "<p>" . $page->author . "</p>";
|
||||
echo "<p>" . unixToDate($page->mDate) . "</p>";
|
||||
echo "<a class='button' href='/$page->slug'>View</a>";
|
||||
echo "<a class='button' href='/admin/edit.php?page=$page->slug'>Edit</a>";
|
||||
echo "<a class='button' href='/admin/delete.php?page=$page->slug'>Delete</a>";
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,42 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/pages/delete.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/pages.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/admin.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<?php
|
||||
|
||||
if (isset($_GET['slug'])) {
|
||||
$page = new Page($_GET['slug']);
|
||||
|
||||
if (isset($_GET['confirm'])) {
|
||||
$page->delete();
|
||||
header('Location: /admin/pages');
|
||||
exit();
|
||||
}
|
||||
|
||||
echo "<h2>Deletion of $page->title</h2>";
|
||||
echo "<p>Are you sure you want to delete this page?</p>";
|
||||
echo "<a class='button outline' href='/admin'>Cancel<a>";
|
||||
echo "<a class='button outline' href='/admin/pages/delete.php?page=$page->slug&confirm=true'>Confirm<a>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -4,15 +4,16 @@
|
|||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin.css">
|
||||
<link rel="stylesheet" href="/css/edit.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/pages/edit.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/admin-bar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/tools.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/pages.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/admin.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
|
@ -50,12 +51,12 @@
|
|||
|
||||
$page->write();
|
||||
|
||||
header('Location: /admin');
|
||||
header('Location: /admin/pages');
|
||||
exit();
|
||||
|
||||
} else if (isset($_GET['page'])) {
|
||||
} else if (isset($_GET['slug'])) {
|
||||
|
||||
$page = new Page($_GET['page']);
|
||||
$page = new Page($_GET['slug']);
|
||||
|
||||
if ($page->slug) {
|
||||
echo "<h2>Editing $page->title</h2>";
|
||||
|
@ -68,8 +69,8 @@
|
|||
https://new.accords-library.com/<input type='text' name='slug' placeholder='' value='$page->slug' required><br>
|
||||
Title: <input type='text' name='title' placeholder='A great title...' value='$page->title' required><br>
|
||||
<textarea name='content' placeholder='Some awesome content...'>$page->content</textarea><br>
|
||||
<input type='hidden' name='originalSlug' value='" . $_GET['page'] . "'>
|
||||
<input class='button' type='submit'>
|
||||
<input type='hidden' name='originalSlug' value='" . $_GET['slug'] . "'>
|
||||
<input class='button outline' type='submit'>
|
||||
</form>
|
||||
";
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Accord's CMS</title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/pages/pages.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/pages.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/admin.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="title">
|
||||
<h2>Pages</h2>
|
||||
<a class='button outline' href='/admin/pages/edit.php?slug='><i class="fa-solid fa-plus"></i></a>
|
||||
</div>
|
||||
|
||||
<div class="page-list">
|
||||
|
||||
<p>Title</p>
|
||||
<p>Author</p>
|
||||
<p>Last edit</p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
|
||||
<?php
|
||||
|
||||
// Get all MD files
|
||||
foreach (getListSlugPages() as $pageSlug) {
|
||||
|
||||
$page = new Page($pageSlug);
|
||||
|
||||
echo "<p> - " . $page->title . "</p>";
|
||||
echo "<p>" . $page->author . "</p>";
|
||||
echo "<p>" . unixToDate($page->mDate) . "</p>";
|
||||
echo "<a class='button' href='/news/$page->slug'><i class='fa-solid fa-eye'></i></a>";
|
||||
echo "<a class='button' href='/admin/pages/edit.php?slug=$page->slug'><i class='fa-solid fa-pen-to-square'></i></a>";
|
||||
echo "<a class='button' href='/admin/pages/delete.php?slug=$page->slug'><i class='fa-solid fa-trash-can'></i></a>";
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,112 +0,0 @@
|
|||
<?php
|
||||
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
|
||||
|
||||
{
|
||||
|
||||
$pagesFolder = $_SERVER["DOCUMENT_ROOT"] . '/../pages/';
|
||||
|
||||
class Page {
|
||||
public $title;
|
||||
public $slug;
|
||||
public $author;
|
||||
public $cDate;
|
||||
public $mDate;
|
||||
public $content;
|
||||
|
||||
function __construct($pageSlug = '') {
|
||||
if (existPage($pageSlug)) {
|
||||
$pageJSON = json_decode(file_get_contents(getPageJSONPath($pageSlug)));
|
||||
foreach ($pageJSON as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
$this->slug = $pageSlug;
|
||||
}
|
||||
}
|
||||
|
||||
function write() {
|
||||
$filePath = getPageJSONPath($this->slug);
|
||||
|
||||
// Remove attributes that should be serialized
|
||||
$slug = $this->slug;
|
||||
unset($this->slug);
|
||||
|
||||
$file = fopen($filePath, 'w');
|
||||
fwrite($file, json_encode($this));
|
||||
fclose($file);
|
||||
|
||||
// Add them back
|
||||
$this->slug = $slug;
|
||||
}
|
||||
|
||||
function delete() {
|
||||
$filePath = getPageJSONPath($this->slug);
|
||||
if (file_exists($filePath)) {
|
||||
unlink($filePath);
|
||||
}
|
||||
}
|
||||
|
||||
function rename($newSlug) {
|
||||
rename(getPageJSONPath($this->slug), getPageJSONPath($newSlug));
|
||||
$this->slug = $newSlug;
|
||||
}
|
||||
|
||||
function parse() {
|
||||
require_once($_SERVER["DOCUMENT_ROOT"] . "/../Parsedown.php");
|
||||
$parsedown = new Parsedown();
|
||||
$parsedown->setSafeMode(true);
|
||||
return $parsedown->text($this->content);
|
||||
}
|
||||
}
|
||||
|
||||
function getListSlugPages() {
|
||||
global $pagesFolder;
|
||||
$pages = scandir($pagesFolder);
|
||||
$pages = array_slice($pages, 2);
|
||||
$result = array();
|
||||
foreach ($pages as $page) {
|
||||
if (substr($page, -5, 5) == '.json') {
|
||||
array_push($result, substr($page, 0, -5));
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
function existPage($pageSlug) {
|
||||
return file_exists(getPageJSONPath($pageSlug));
|
||||
}
|
||||
|
||||
function getPageJSONPath($pageSlug) {
|
||||
global $pagesFolder;
|
||||
return $pagesFolder . $pageSlug . '.json';
|
||||
}
|
||||
|
||||
function unixToDate($unixTime) {
|
||||
return date('Y-m-d', $unixTime);
|
||||
}
|
||||
|
||||
function sluggify($string) {
|
||||
$string = strtolower($string);
|
||||
$string = str_replace(' ', '-', $string);
|
||||
|
||||
$string = str_split($string);
|
||||
$result = "";
|
||||
$slugAcceptable = "abcdefghijklmnopqrstuvwxyz0123456789-";
|
||||
foreach ($string as $c) {
|
||||
if (stripos($slugAcceptable, $c) !== false) $result .= $c;
|
||||
}
|
||||
$result = trim($result, "-");
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
?>
|
|
@ -0,0 +1,63 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/users/edit.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/users.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/admin.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/crypto.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<?php
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
$user = new User();
|
||||
$user->name = $_POST['name'];
|
||||
$user->slug = sluggify($_POST['slug']);
|
||||
$user->role = $_POST['role'];
|
||||
$user->hash = generateHash($_POST['password']);
|
||||
$user->content = $_POST['content'];
|
||||
|
||||
$user->write();
|
||||
|
||||
header('Location: /admin/users');
|
||||
exit();
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
$user = new User();
|
||||
|
||||
echo "
|
||||
<h2>Creating a new user</h2>
|
||||
<form action='/admin/users/add.php' method='post'>
|
||||
<input type='text' name='slug' placeholder='Username...' value='$user->slug' required><br>
|
||||
<input type='text' name='name' placeholder='Displayed name...' value='$user->slug' required><br>
|
||||
<select name='role'>
|
||||
<option value='contributor'>Contributor</option>
|
||||
<option value='author'>Author</option>
|
||||
<option value='editor'>Editor</option>
|
||||
<option value='admin'>Admin</option>
|
||||
</select>
|
||||
<br>
|
||||
<input type='password' name='password' placeholder='Password...' required><br>
|
||||
<textarea name='content' placeholder='Description...'>$user->content</textarea><br>
|
||||
<input class='button outline' type='submit'>
|
||||
</form>
|
||||
";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,47 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/pages/delete.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/users.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/admin.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<?php
|
||||
|
||||
if (getCurrentUser()->role !== 'admin') {
|
||||
header('Location: /admin/users');
|
||||
exit();
|
||||
}
|
||||
|
||||
if (isset($_GET['slug'])) {
|
||||
$user = new User($_GET['slug']);
|
||||
|
||||
if (isset($_GET['confirm'])) {
|
||||
$user->delete();
|
||||
header('Location: /admin/users');
|
||||
exit();
|
||||
}
|
||||
|
||||
echo "<h2>Deletion of $user->name</h2>";
|
||||
echo "<p>Are you sure you want to delete this page?</p>";
|
||||
echo "<a class='button outline' href='/admin'>Cancel<a>";
|
||||
echo "<a class='button outline' href='/admin/users/delete.php?slug=$user->slug&confirm=true'>Confirm<a>";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,91 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title></title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/users/edit.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/users.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/admin.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<?php
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
||||
|
||||
$originalSlug = $_POST['originalSlug'];
|
||||
$newSlug = sluggify($_POST['slug']);
|
||||
|
||||
|
||||
|
||||
if (!$originalSlug) {
|
||||
// This is the creation of a new page
|
||||
$page = new User();
|
||||
$page->name = $_POST['name'];
|
||||
$page->slug = $newSlug;
|
||||
$page->role = $_POST['role'];
|
||||
$page->password = $_POST['password'];
|
||||
$page->content = $_POST['content'];
|
||||
|
||||
} else {
|
||||
// This is modification of an existing page
|
||||
$page = new Page($originalSlug);
|
||||
$page->title = $_POST['title'];
|
||||
$page->mDate = time();
|
||||
$page->content = $_POST['content'];
|
||||
if ($originalSlug !== $newSlug) {
|
||||
// The page needs to be moved
|
||||
$page->slug = $originalSlug;
|
||||
$page->rename($newSlug);
|
||||
}
|
||||
}
|
||||
|
||||
$page->write();
|
||||
|
||||
header('Location: /admin/pages');
|
||||
exit();
|
||||
|
||||
} else if (isset($_GET['slug'])) {
|
||||
|
||||
$user = new User($_GET['slug']);
|
||||
|
||||
if ($user->slug) {
|
||||
echo "<h2>Editing $user->slug</h2>";
|
||||
} else {
|
||||
echo "<h2>Creating a new user</h2>";
|
||||
}
|
||||
|
||||
echo "
|
||||
<form action='edit.php' method='post'>
|
||||
<input type='text' name='slug' placeholder='Username...' value='$user->slug' required><br>
|
||||
<input type='text' name='name' placeholder='Displayed name...' value='$user->slug' required><br>
|
||||
<select name='role'>
|
||||
<option value='contributor'>Contributor</option>
|
||||
<option value='author'>Author</option>
|
||||
<option value='editor'>Editor</option>
|
||||
<option value='admin'>Admin</option>
|
||||
</select>
|
||||
<br>
|
||||
<input type='password' name='password' placeholder='Password...' required><br>
|
||||
<textarea name='content' placeholder='Description...'>$user->content</textarea><br>
|
||||
<input type='hidden' name='originalSlug' value='" . $_GET['slug'] . "'>
|
||||
<input class='button outline' type='submit'>
|
||||
</form>
|
||||
";
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,63 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Accord's CMS</title>
|
||||
<link rel="stylesheet" href="/css/master.css">
|
||||
<link rel="stylesheet" href="/css/admin/admin.css">
|
||||
<link rel="stylesheet" href="/css/admin/users/users.css">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../templates/admin/adminbar.php") ?>
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/users.php") ?>
|
||||
|
||||
<div class="content">
|
||||
|
||||
<div class="title">
|
||||
<h2>Users</h2>
|
||||
<a class='button outline' href='/admin/users/add.php'><i class="fa-solid fa-plus"></i></a>
|
||||
</div>
|
||||
|
||||
<div class="user-list">
|
||||
|
||||
<p>Name</p>
|
||||
<p>Role</p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
<p></p>
|
||||
|
||||
<?php
|
||||
|
||||
// Get all MD files
|
||||
foreach (getListSlug() as $slug) {
|
||||
|
||||
$user = new User($slug);
|
||||
|
||||
echo "<p> - " . $user->name . "</p>";
|
||||
echo "<p>" . $user->role . "</p>";
|
||||
echo "<a class='button' href='/$user->slug'><i class='fa-solid fa-eye'></i></a>";
|
||||
if (getCurrentUser()->role === 'admin') {
|
||||
echo "<a class='button' href='/admin/users/edit.php?slug=$user->slug'><i class='fa-solid fa-pen-to-square'></i></a>";
|
||||
echo "<a class='button' href='/admin/users/delete.php?slug=$user->slug'><i class='fa-solid fa-trash-can'></i></a>";
|
||||
} else {
|
||||
echo "<a class='button disabled'><i class='fa-solid fa-pen-to-square'></i></a>";
|
||||
echo "<a class='button disabled'><i class='fa-solid fa-trash-can'></i></a>";
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
|
||||
?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,88 +0,0 @@
|
|||
@font-face {
|
||||
font-family: customFont;
|
||||
src: url("/font/Quicksand-VariableFont_wght.ttf");
|
||||
}
|
||||
|
||||
:root {
|
||||
--break-point: 60em;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr var(--break-point) 1fr;
|
||||
place-content: center;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
body > .container {
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
border: var(--default-border);
|
||||
box-shadow: var(--default-box-shadow);
|
||||
grid-column: 2;
|
||||
transition: 1s margin-top;
|
||||
}
|
||||
|
||||
body > .container > .content {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
#admin-bar {
|
||||
max-width: var(--break-point);
|
||||
display: grid;
|
||||
grid-template-columns: 1fr;
|
||||
grid-auto-flow: column;
|
||||
align-items: center;
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
box-sizing: border-box;
|
||||
background-color: var(--color-main-dark);
|
||||
color: var(--color-main-light);
|
||||
}
|
||||
|
||||
#admin-bar > #logout > .button {
|
||||
margin-left: 1rem;
|
||||
}
|
||||
|
||||
.content > .title {
|
||||
display: grid;
|
||||
grid-gap: 1rem;
|
||||
grid-auto-flow: column;
|
||||
place-content: start;
|
||||
place-items: center start;
|
||||
}
|
||||
|
||||
.page-list {
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 1fr 1fr auto auto auto;
|
||||
grid-row-gap: 0.5rem;
|
||||
}
|
||||
|
||||
.page-list > * {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.page-list > .button {
|
||||
place-self: center;
|
||||
}
|
||||
|
||||
.page-list p {
|
||||
margin-top: .5em;
|
||||
margin-bottom: .5em;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
|
||||
@media only screen and (max-width: 60em) {
|
||||
body {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
body > .container {
|
||||
grid-column: 1;
|
||||
margin-top: 0;
|
||||
border: unset;
|
||||
box-shadow: unset;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
:root {
|
||||
--break-point: 60em;
|
||||
}
|
||||
|
||||
body {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
grid-template-columns: 1fr var(--break-point) 1fr;
|
||||
place-content: center;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
body > .container {
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
border: var(--default-border);
|
||||
box-shadow: var(--default-box-shadow);
|
||||
grid-column: 2;
|
||||
transition: 1s margin-top;
|
||||
}
|
||||
|
||||
body > .container > .content {
|
||||
padding: 2rem;
|
||||
}
|
||||
|
||||
.content > .title {
|
||||
display: grid;
|
||||
grid-gap: 1rem;
|
||||
grid-auto-flow: column;
|
||||
place-content: start;
|
||||
place-items: center start;
|
||||
}
|
||||
|
||||
@media only screen and (max-width: 60em) {
|
||||
body {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
body > .container {
|
||||
grid-column: 1;
|
||||
margin-top: 0;
|
||||
border: unset;
|
||||
box-shadow: unset;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
#admin-bar {
|
||||
max-width: var(--break-point);
|
||||
display: grid;
|
||||
grid-auto-flow: column;
|
||||
place-items: center;
|
||||
padding-left: 2rem;
|
||||
padding-right: 2rem;
|
||||
box-sizing: border-box;
|
||||
background-color: var(--color-main-dark);
|
||||
color: var(--color-main-light);
|
||||
}
|
||||
|
||||
#admin-bar > #logout {
|
||||
display: grid;
|
||||
grid-auto-flow: column;
|
||||
place-items: center end;
|
||||
grid-gap: .5em;
|
||||
}
|
||||
|
||||
#admin-bar > a {
|
||||
font-size: 1.5em;
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
.content > .button {
|
||||
display: inline;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
.page-list {
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 1fr 1fr auto auto auto;
|
||||
grid-row-gap: 0.5rem;
|
||||
}
|
||||
|
||||
.page-list > * {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.page-list > .button {
|
||||
place-self: center;
|
||||
}
|
||||
|
||||
.page-list p {
|
||||
margin-top: .5em;
|
||||
margin-bottom: .5em;
|
||||
font-weight: bold;
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
.user-list {
|
||||
display: grid;
|
||||
grid-template-columns: 2fr 1fr auto auto auto;
|
||||
grid-row-gap: 0.5rem;
|
||||
}
|
||||
|
||||
.user-list > * {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
.user-list > .button {
|
||||
place-self: center;
|
||||
}
|
||||
|
||||
.user-list p {
|
||||
margin-top: .5em;
|
||||
margin-bottom: .5em;
|
||||
font-weight: bold;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -5,7 +5,7 @@
|
|||
|
||||
:root {
|
||||
--color-main-light: #FFF8E7;
|
||||
--color-main-base: #ffEBCD;
|
||||
--color-main-base: #FFEBCD;
|
||||
--color-main-dark: #954535;
|
||||
--color-main-black: #1B1811;
|
||||
--default-border: solid 1px var(--color-main-dark);
|
||||
|
@ -21,19 +21,61 @@ body {
|
|||
}
|
||||
|
||||
.button {
|
||||
background: var(--color-main-light);
|
||||
background-color: var(--color-main-light);
|
||||
padding: 0.3em 1.1em;
|
||||
color: var(--color-main-dark);
|
||||
transition: .1s background-color, .1s color, .1s border;
|
||||
border: solid 2px var(--color-main-dark);
|
||||
border-radius: 9999px;
|
||||
border-radius: 100vmax;
|
||||
text-decoration-line: none;
|
||||
margin-left: 0.3em;
|
||||
margin-right: 0.3em;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
border: unset;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.button:hover {
|
||||
background: var(--color-main-dark);
|
||||
color: var(--color-main-light);
|
||||
border: solid 2px var(--color-main-dark);
|
||||
border-color: var(--color-main-dark);
|
||||
}
|
||||
|
||||
.button.icon {
|
||||
width: 2em;
|
||||
height: 1.6em;
|
||||
padding: 0em;
|
||||
}
|
||||
|
||||
.button.outline {
|
||||
border: solid 0.1em var(--color-main-dark);
|
||||
}
|
||||
|
||||
.button.invert {
|
||||
border-color: var(--color-main-light);
|
||||
}
|
||||
|
||||
.button.invert {
|
||||
color: var(--color-main-light);
|
||||
background-color: var(--color-main-dark);
|
||||
}
|
||||
|
||||
.button.invert:hover {
|
||||
color: var(--color-main-dark);
|
||||
background-color: var(--color-main-light);
|
||||
}
|
||||
|
||||
.button.invert.active {
|
||||
color: var(--color-main-dark);
|
||||
background-color: var(--color-main-light);
|
||||
}
|
||||
|
||||
.button.disabled {
|
||||
cursor: no-drop;
|
||||
opacity: 0.4;
|
||||
}
|
||||
|
||||
.button.disabled:hover {
|
||||
color: var(--color-main-dark);
|
||||
background-color: inherit;
|
||||
}
|
||||
|
|
|
@ -19,39 +19,26 @@
|
|||
|
||||
<?php
|
||||
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
function verifyKey($username, $password) {
|
||||
$csv = file_get_contents($_SERVER["DOCUMENT_ROOT"] . '/../credentials.csv');
|
||||
$hashes = explode(PHP_EOL, $csv);
|
||||
foreach ($hashes as $hash) {
|
||||
$hash = explode(';', $hash);
|
||||
if ($hash[0] == $username) {
|
||||
$hash = substr($hash[2], 0, -1);
|
||||
return password_verify($password, $hash);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($_POST['submitButton'] == "Submit") {
|
||||
|
||||
$username = filter_var($_POST["username"], FILTER_SANITIZE_STRING);
|
||||
$password = filter_var($_POST["password"], FILTER_SANITIZE_STRING);
|
||||
|
||||
require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/crypto.php");
|
||||
|
||||
if (session_status() == PHP_SESSION_NONE) {
|
||||
session_start();
|
||||
}
|
||||
|
||||
if (verifyKey($username, $password)) {
|
||||
$_SESSION['loginUsername'] = $username;
|
||||
header('Location: /admin');
|
||||
header('Location: /admin/pages');
|
||||
} else {
|
||||
unset($_SESSION['loginUsername']);
|
||||
echo '<p id="answer">The account name or password that you have entered is incorrect.</p>';
|
||||
echo '<style>body{animation: bw 1s;animation-fill-mode: forwards;}#container{animation: shake 0.2s;animation-iteration-count: 2;}</style>';
|
||||
}
|
||||
|
||||
//echo '<p>' . $username . ';' . password_hash($password, PASSWORD_DEFAULT) . '</p>';
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -6,12 +6,14 @@
|
|||
</head>
|
||||
<body>
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/admin/tools.php") ?>
|
||||
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/pages.php") ?>
|
||||
|
||||
<?php
|
||||
|
||||
if (isset($_GET['p'])) {
|
||||
$page = new Page($_GET['p']);
|
||||
if (isset($_GET['slug'])) {
|
||||
$slug = substr($_GET['slug'], 6);
|
||||
$page = new Page($slug);
|
||||
echo $page->parse();
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
chown www-data:www-data -R * # Set Apache's www-data user as the owner
|
||||
find . -type d -exec chmod 775 {} \; # Change folder permissions to rwxrwxr-x
|
||||
find . -type f -exec chmod 664 {} \; # Change file permissions to rw-rw--r--
|
||||
chmod +x resetFilePermissions.sh
|
|
@ -0,0 +1,33 @@
|
|||
<link rel="stylesheet" href="/css/admin/adminbar.css">
|
||||
<link rel="stylesheet" href="/css/fontawesome.css">
|
||||
|
||||
<?php require_once($_SERVER["DOCUMENT_ROOT"] . "/../php/tools/users.php") ?>
|
||||
|
||||
<?php
|
||||
// Authentification check
|
||||
if (session_status() == PHP_SESSION_NONE) session_start();
|
||||
if (!isset($_SESSION['loginUsername'])) {
|
||||
header('Location: /');
|
||||
}
|
||||
?>
|
||||
|
||||
<?php
|
||||
|
||||
function isActive($url) {
|
||||
return $url === dirname($_SERVER["PHP_SELF"]);
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div id="admin-bar">
|
||||
<h1>Accord's CMS</h1>
|
||||
<a class="button icon invert <?php if (isActive('/admin/pages')) echo 'active'; ?>" href="/admin/pages"><i class="fa-solid fa-file-lines"></i></a>
|
||||
<a class="button icon invert <?php if (isActive('/admin/users')) echo 'active'; ?>" href="/admin/users"><i class="fa-solid fa-user"></i></a>
|
||||
<a class="button icon invert <?php if (isActive('/admin/comments')) echo 'active'; ?>" href="/admin/comments"><i class="fa-solid fa-comment"></i></a>
|
||||
<a class="button icon invert <?php if (isActive('/admin/scripts')) echo 'active'; ?>" href="/admin/scripts"><i class="fa-solid fa-code"></i></a>
|
||||
<a class="button icon invert <?php if (isActive('/admin/settings')) echo 'active'; ?>" href="/admin/settings"><i class="fa-solid fa-gear"></i></a>
|
||||
<div id="logout">
|
||||
<p>Welcome <?php echo getCurrentUser()->name; ?></p>
|
||||
<a class="button invert outline" href="/admin/logout.php">Logout</a>
|
||||
</div>
|
||||
</div>
|
Loading…
Reference in New Issue