commit 86c32aa965348b816f0c62092612cb8787033cb5
parent 70b56eb6800bd3a35b67fe719db450ed186f57fd
Author: Florian <flokX@users.noreply.github.com>
Date: Thu, 26 Dec 2019 17:57:40 +0100
Fixes and enhancements
Diffstat:
6 files changed, 38 insertions(+), 36 deletions(-)
diff --git a/LICENSE b/LICENSE
@@ -1,6 +1,6 @@
MIT License
-Copyright (c) 2019 flokX
+Copyright (c) 2019-2020 flokX
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/admin-auth.php b/admin-auth.php
@@ -34,7 +34,7 @@ if (isset($_GET["logout"])) {
}
// Login user in session if mode is login and post data is available
-if (isset($_GET["login"])) {
+if (isset($_GET["login"]) && isset($_POST["input_password"])) {
if (password_verify($_POST["input_password"], $config_content["admin_password"])) {
$_SESSION["user_authenticated"] = true;
header("Location: admin.php");
@@ -44,7 +44,7 @@ if (isset($_GET["login"])) {
}
}
-// Generator for page customization
+// Generate custom buttons for the footer
$links_string = "";
if ($config_content["settings"]["custom_links"]) {
foreach ($config_content["settings"]["custom_links"] as $name => $url) {
@@ -83,12 +83,12 @@ if ($config_content["settings"]["custom_links"]) {
<h1 class="mt-5">Login</h1>
<p class="lead">Please sign in to access the admin panel. If you need help, visit <a href="https://github.com/flokX/devShort/wiki">the devShort wiki</a>.</p>
<form action="admin-auth.php?login" method="POST">
- <div class="alert alert-danger" role="alert" <?php if (!$incorrect_password) { echo "style=\"display: none;\"" } ?>>
+ <div class="alert alert-danger" role="alert" <?php if (!$incorrect_password) { echo "style=\"display: none;\""; } ?>>
The given password was incorrect, please try again!
</div>
<div class="form-group">
<label for="inputPassword">Password</label>
- <input class="form-control" id="inputPassword" name="input_password" type="password">
+ <input class="form-control" id="inputPassword" name="input_password" type="password" autofocus required>
</div>
<button class="btn btn-primary" type="submit">Login</button>
</form>
diff --git a/admin.php b/admin.php
@@ -39,13 +39,13 @@ if (isset($_GET["delete"]) || isset($_GET["add"])) {
$stats_content[$filtered["name"]] = array();
}
file_put_contents($config_path, json_encode($config_content, JSON_PRETTY_PRINT));
- file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT));
+ file_put_contents($stats_path, json_encode($stats_content));
header("Content-Type: application/json");
echo "{\"status\": \"successful\"}";
exit;
}
-// Generator for page customization
+// Generate custom buttons for the footer
$links_string = "";
if ($config_content["settings"]["custom_links"]) {
foreach ($config_content["settings"]["custom_links"] as $name => $url) {
@@ -81,7 +81,7 @@ if ($config_content["settings"]["custom_links"]) {
<div class="card d-none d-md-block mb-3">
<div class="card-body">
<h5 class="card-title">Tools</h5>
- <a class="card-link" id="refresh" href="#refresh">Refresh charts</a>
+ <a class="card-link" id="refresh-1" href="#refresh">Refresh charts</a>
<a class="card-link" href="admin-auth.php?logout">Logout</a>
</div>
</div>
@@ -112,12 +112,12 @@ if ($config_content["settings"]["custom_links"]) {
</div>
<div class="card d-none d-md-block">
<div class="card-body">
- <p class="mb-0">powered by <a href="https://github.com/flokX/devShort">devShort</a> v2.4.0</p>
+ <p class="mb-0">powered by <a href="https://github.com/flokX/devShort">devShort</a> v3.0.0</p>
</div>
</div>
<div class="card d-md-none mb-3">
<div class="card-body text-center">
- <a class="card-link" id="refresh" href="#refresh">Refresh charts</a>
+ <a class="card-link" id="refresh-2" href="#refresh">Refresh charts</a>
<a class="card-link" href="admin-auth.php?logout">Logout</a>
</div>
</div>
@@ -131,7 +131,7 @@ if ($config_content["settings"]["custom_links"]) {
<div id="charts"></div>
</div>
</div>
- <p class="text-center d-md-none mt-1 mb-5">powered by <a href="https://github.com/flokX/devShort">devShort</a> v2.4.0</p>
+ <p class="text-center d-md-none mt-1 mb-5">powered by <a href="https://github.com/flokX/devShort">devShort</a> v3.0.0</p>
</div>
</main>
diff --git a/assets/main.js b/assets/main.js
@@ -25,7 +25,7 @@ document.getElementById('add-form').addEventListener('submit', function (event)
'use strict';
event.preventDefault();
spinner.style.display = '';
- post('index.php?add', {
+ post('admin.php?add', {
name: document.getElementById('name').value,
url: document.getElementById('url').value
}).then(function (data) {
@@ -59,12 +59,14 @@ searchBox.addEventListener('input', function (event) {
}
});
-/* Reload charts */
-document.getElementById('refresh').addEventListener('click', function (event) {
+/* Refresh charts */
+function refreshCharts(event) {
'use strict';
event.preventDefault();
getCharts();
-});
+}
+document.getElementById('refresh-1').addEventListener('click', refreshCharts);
+document.getElementById('refresh-2').addEventListener('click', refreshCharts);
/* Get charts and date (remove old when necessary) */
function getCharts() {
@@ -106,7 +108,7 @@ function getCharts() {
});
document.getElementById('delete-' + name).addEventListener('click', function (event) {
event.preventDefault();
- post('index.php?delete', {
+ post('admin.php?delete', {
name: name
}).then(function () {
document.getElementById('card-' + name).remove();
diff --git a/index.php b/index.php
@@ -2,16 +2,16 @@
// All relevant changes can be made in the data file. Please read the docs: https://github.com/flokX/devShort/wiki
-$base_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data"));
-$config_content = json_decode(file_get_contents($base_path . DIRECTORY_SEPARATOR . "config.json"), true);
+$config_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "config.json"));
+$config_content = json_decode(file_get_contents($config_path), true);
+$stats_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "stats.json"));
+$stats_content = json_decode(file_get_contents($stats_path), true);
-// Counts the access
-$filename = $base_path . DIRECTORY_SEPARATOR . "stats.json";
-$stats = json_decode(file_get_contents($filename), true);
-$stats["Index"][mktime(0, 0, 0)] += 1;
-file_put_contents($filename, json_encode($stats, JSON_PRETTY_PRINT));
+// Count the access
+$stats_content["Index"][mktime(0, 0, 0)] += 1;
+file_put_contents($stats_path, json_encode($stats_content));
-// Generator for page customization
+// Generate custom buttons for the footer
$links_string = "";
if ($config_content["settings"]["custom_links"]) {
foreach ($config_content["settings"]["custom_links"] as $name => $url) {
@@ -41,9 +41,9 @@ if ($config_content["settings"]["custom_links"]) {
<main class="flex-shrink-0">
<div class="container">
<nav class="mt-3" aria-label="breadcrumb">
- <ol class="breadcrumb">
+ <ol class="breadcrumb shadow-sm">
<li class="breadcrumb-item"><a href="<?php echo $config_content["settings"]["home_link"]; ?>">Home</a></li>
- <li class="breadcrumb-item" aria-current="page"><?php echo $config_content["settings"]["name"]; ?></li>
+ <li class="breadcrumb-item active" aria-current="page"><?php echo $config_content["settings"]["name"]; ?></li>
</ol>
</nav>
<h1 class="mt-5"><?php echo $config_content["settings"]["name"]; ?></h1>
diff --git a/redirect.php b/redirect.php
@@ -10,17 +10,17 @@ if (in_array($short, $return_404)) {
exit;
}
-// Counts the access to the given $name
+$config_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "config.json"));
+$config_content = json_decode(file_get_contents($config_path), true);
+$stats_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "stats.json"));
+$stats_content = json_decode(file_get_contents($stats_path), true);
+
+// Count the access to the given $name
function count_access($base_path, $name) {
- $filename = $base_path . DIRECTORY_SEPARATOR . "stats.json";
- $stats = json_decode(file_get_contents($filename), true);
- $stats[$name][mktime(0, 0, 0)] += 1;
- file_put_contents($filename, json_encode($stats, JSON_PRETTY_PRINT));
+ $stats_content[$name][mktime(0, 0, 0)] += 1;
+ file_put_contents($stats_path, json_encode($stats_content));
}
-$base_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data"));
-$config_content = json_decode(file_get_contents($base_path . DIRECTORY_SEPARATOR . "config.json"), true);
-
if (array_key_exists($short, $config_content["shortlinks"])) {
header("Location: " . $config_content["shortlinks"][$short], $http_response_code=303);
count_access($base_path, $short);
@@ -32,7 +32,7 @@ if (array_key_exists($short, $config_content["shortlinks"])) {
header("HTTP/1.1 404 Not Found");
count_access($base_path, "404-request");
- // Generator for page customization
+ // Generate custom buttons for the footer
$links_string = "";
if ($config_content["settings"]["custom_links"]) {
foreach ($config_content["settings"]["custom_links"] as $name => $url) {
@@ -63,7 +63,7 @@ if (array_key_exists($short, $config_content["shortlinks"])) {
<main class="flex-shrink-0">
<div class="container">
<nav class="mt-3" aria-label="breadcrumb">
- <ol class="breadcrumb">
+ <ol class="breadcrumb shadow-sm">
<li class="breadcrumb-item"><a href="<?php echo $config_content["settings"]["home_link"]; ?>">Home</a></li>
<li class="breadcrumb-item"><?php echo $config_content["settings"]["name"]; ?></li>
<li class="breadcrumb-item active" aria-current="page">404</li>