devshort

private self-hosted shortlink service
git clone https://git.clttr.info/devshort.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit 7048c8ed1b38ea7eac5194f2211d9a6711a1dcc3
parent 68222d91077a5720f06eccdc6da32b684bc66dee
Author: René Wagner <rwagner@rw-net.de>
Date:   Thu, 14 May 2020 20:29:37 +0200

Revert "fix broken links in admin page"

This reverts commit 68222d91077a5720f06eccdc6da32b684bc66dee.

Diffstat:
Madmin.php | 34++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)

diff --git a/admin.php b/admin.php @@ -8,6 +8,19 @@ $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); +// convert the old timestamp format in the stats file to the now used date-format +my $converted = 0; +foreach ( $stats_content as &$stats_entry ) { + foreach ($stats_entry as $key => $value) { + if ( is_numeric($key) ) { + $converted = 1; + unset($sub_stats[$key]); + $sub_stats[date("Y-m-d", $key)] = $value; + } + } +} +if ( $converted ) { file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT)); } + // Check if authentication is valid session_start(); if (!isset($_SESSION["user_authenticated"])) { @@ -18,9 +31,8 @@ if (!isset($_SESSION["user_authenticated"])) { // Deliver stats.json content for the program (make AJAX calls and charts reloading possible) if (isset($_GET["get_data"])) { header("Content-Type: application/json"); - $content = array("shortlinks" => $config_content["shortlinks"], "stats" => $stats_content); - echo json_encode($content); + echo json_encode($content); exit; } @@ -31,16 +43,15 @@ if (isset($_GET["delete"]) || isset($_GET["add"])) { unset($config_content["shortlinks"][$data["name"]]); unset($stats_content[$data["name"]]); } else if (isset($_GET["add"])) { - $filtered = array("name" => filter_var($data["name"], FILTER_SANITIZE_STRING), + $filtered = array("name" => strtolower(filter_var($data["name"], FILTER_SANITIZE_STRING)), "url" => filter_var($data["url"], FILTER_SANITIZE_URL)); if (!filter_var($filtered["url"], FILTER_VALIDATE_URL)) { echo "{\"status\": \"unvalid-url\"}"; exit; } - if (array_key_exists($filtered["name"], $config_content["shortlinks"])) - { - echo "{\"status\": \"url-already-exists\"}"; - exit; + if (array_key_exists($filtered["name"], $config_content["shortlinks"])) { + echo "{\"status\": \"url-already-exists\"}"; + exit; } $config_content["shortlinks"][$filtered["name"]] = $filtered["url"]; $stats_content[$filtered["name"]] = array(); @@ -74,7 +85,6 @@ if ($config_content["settings"]["custom_links"]) { <link href="<?php echo $config_content["settings"]["favicon"]; ?>" rel="icon"> <title>Admin panel | <?php echo $config_content["settings"]["name"]; ?></title> <link href="assets/vendor/bootstrap/bootstrap.min.css" rel="stylesheet"> - <link href="assets/main.css" rel="stylesheet"> </head> <body class="d-flex flex-column h-100"> @@ -119,7 +129,7 @@ if ($config_content["settings"]["custom_links"]) { </div> <div class="card d-none d-md-block mb-3"> <div class="card-body"> - <p class="mb-0" id="version-1">powered by <a href="https://sr.ht/~rwa/devShort/" target="_blank">devShort</a></p> + <p class="mb-0" id="version-1">powered by <a href="https://github.com/flokX/devShort">devShort</a></p> </div> </div> <div class="card d-md-none mb-3"> @@ -138,14 +148,14 @@ if ($config_content["settings"]["custom_links"]) { <chart v-for="(stats, name) in dataObject.stats" v-bind:key="name" :style="displayStyle(name)" v-bind:name="name" v-bind:stats="stats" v-else></chart> </div> </div> - <p class="text-center d-md-none mt-1 mb-5" id="version-2">powered by <a href="https://sr.ht/~rwa/devShort/" target="_blank">devShort</a></p> + <p class="text-center d-md-none mt-1 mb-5" id="version-2">powered by <a href="https://github.com/flokX/devShort">devShort</a></p> </div> </main> <footer class="footer mt-auto py-3 bg-light"> <div class="container"> <div class="d-flex justify-content-between align-items-center"> - <span class="text-muted">&copy; <?php echo date("Y") . " " . $config_content["settings"]["author"]; ?> and <a href="https://github.com/flokX/devShort">devShort</a></span> + <span class="text-muted">&copy; 2020 <?php $config_content["settings"]["author"]; ?> and <a href="https://github.com/flokX/devShort">devShort</a></span> <?php if ($links_string) { echo "<span class=\"text-muted\">$links_string</span>"; } ?> </div> </div> @@ -165,7 +175,7 @@ if ($config_content["settings"]["custom_links"]) { <hr> <div class="overflow-auto" :id="chartId"></div> <hr> - <p class="text-center text-muted mb-0" v-if="this.name === 'Index'">Index is an internal entry. It counts the number of front page accesses.</p> + <p class="text-center text-muted mb-0" v-if="this.name === 'index'">Index is an internal entry. It counts the number of front page accesses.</p> <p class="text-center text-muted mb-0" v-else-if="this.name === '404-request'">404-request is an internal entry. It counts the number of accesses to non-existent shortlinks.</p> <div class="row" v-else> <div class="col-lg-9">