devshort

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/devshort.git
Log | Files | Refs | README | LICENSE

commit 5c4a6a442495c47781af0d7b50228b3cc105c709
parent 42d2cdea8790b31663aec2205acccc447cc5cea1
Author: Florian Kaldowski <flokX@users.noreply.github.com>
Date:   Thu, 11 Apr 2019 10:28:05 +0200

Validation updates (see #6)
Diffstat:
Madmin/index.php | 32++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)

diff --git a/admin/index.php b/admin/index.php @@ -24,7 +24,7 @@ if (isset($_GET["delete"]) || isset($_GET["add"])) { } else if (isset($_GET["add"])) { $filtered = array("name" => filter_name($data["name"]), "url" => filter_var($data["url"], FILTER_SANITIZE_URL)); - if (!filter_var($filtered["url"], FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED)) { + if (!filter_var($filtered["url"], FILTER_VALIDATE_URL)) { echo "{\"status\": \"unvalid-url\"}"; exit; } @@ -37,25 +37,6 @@ if (isset($_GET["delete"]) || isset($_GET["add"])) { exit; } -// Check if there are links which are only in the config.json or only in the stats.json -$changed = false; -foreach ($config_content["shortlinks"] as $name => $url) { - if (!isset($stats_content[$name])) { - $stats_content[$name] = array(); - $changed = true; - } -} -foreach ($stats_content as $name => $stats) { - if (!isset($config_content["shortlinks"][$name]) && $name !== "404-request" && $name !== "Index") { - unset($stats_content[$name]); - $changed = true; - } -} -if ($changed) { - file_put_contents($config_path, json_encode($config_content, JSON_PRETTY_PRINT)); - file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT)); -} - // Generator for page customization $links_string = ""; if ($config_content["settings"]["custom_links"]) { @@ -85,18 +66,17 @@ if ($config_content["settings"]["custom_links"]) { <main role="main" class="flex-shrink-0"> <div class="container"> - <h1 class="mt-5 text-center"><?php echo $config_content["settings"]["name"]; ?> - </h1> + <h1 class="mt-5 text-center"><?php echo $config_content["settings"]["name"]; ?></h1> <h4 class="mb-4 text-center">admin panel</h4> <div class="card mb-3"> <div class="card-body"> <h5 class="card-title">Add shortlink <small><a id="refresh" href="#refresh" class="card-link">Refresh charts</a></small></h5> - <form class="form-inline"> + <form class="form-inline" id="add-form"> <label class="sr-only" for="name">Name</label> - <input type="text" class="form-control mb-2 mr-sm-2" id="name" placeholder="Link1" aria-describedby="name-help"> + <input type="text" class="form-control mb-2 mr-sm-2" id="name" placeholder="Link1" required> <label class="sr-only" for="url">URL (destination)</label> - <input type="text" class="form-control mb-2 mr-sm-2" id="url" placeholder="https://example.com"> - <button type="submit" id="add-shortlink" class="btn btn-primary mb-2">Add</button> + <input type="url" class="form-control mb-2 mr-sm-2" id="url" placeholder="https://example.com" value="https://" required> + <button type="submit" class="btn btn-primary mb-2">Add</button> <div id="status"></div> </form> </div>