diff options
Diffstat (limited to 'linkshorter')
| -rw-r--r-- | linkshorter/class/db.php | 73 | ||||
| -rw-r--r-- | linkshorter/config.php | 3 | ||||
| -rw-r--r-- | linkshorter/css/style.css | 68 | ||||
| -rw-r--r-- | linkshorter/goto.php | 2 | ||||
| -rw-r--r-- | linkshorter/index.php | 10 | ||||
| -rw-r--r-- | linkshorter/view/templ-head.php | 5 | ||||
| -rw-r--r-- | linkshorter/view/templ-index.php | 17 | ||||
| -rw-r--r-- | linkshorter/view/templ-notfound.php | 14 |
8 files changed, 38 insertions, 154 deletions
diff --git a/linkshorter/class/db.php b/linkshorter/class/db.php deleted file mode 100644 index 7713487..0000000 --- a/linkshorter/class/db.php +++ /dev/null @@ -1,73 +0,0 @@ -<?php - -class Database { - - private $db; - public $error; - - public function __construct($connect = false, $db = false){ - $this->db = new Redis(); - - if ( ! $connect || ! $db ) - return; - - $this->connect($connect, $db); - } - - public function connect($connect, $db){ - try { - $this->db->connect($connect); - } catch (Exception $e){ - $this->error = $e; - return false; - } - - try { - $this->db->select($db); - } catch (Exception $e){ - $this->error = $e; - return false; - } - - try { - $this->db->ping(); - } catch (Exception $e){ - $this->error = $e; - return false; - } - - return true; - } - - public function expire($key, $ttl){ - try { - $this->db->setTimeout($key, $ttl); - } catch (Exception $e){ - $this->error = $e; - return false; - } - } - - public function set($key, $value, $ttl = null){ - if ( is_null($ttl) ) - return $this->db->set($key, $value); - else - return $this->db->set($key, $value, (int)$ttl); - } - - public function get($key){ - return $this->db->get($key); - } - - public function exists($key){ - return $this->db->exists($key); - } - - public function __destruct(){ - try { - $this->db->close(); - } catch (Exception $e){ - return false; - } - } -} diff --git a/linkshorter/config.php b/linkshorter/config.php index 4b38311..298d9f0 100644 --- a/linkshorter/config.php +++ b/linkshorter/config.php @@ -1,7 +1,8 @@ <?php -define("REDIS_CONNECT", "/var/run/redis/redis.sock"); define("REDIS_SELECT", 10); define("SHORTDOMAIN", "http://s.moehm.org/"); define("ADMINDOMAIN", SHORTDOMAIN); define("PEPPER", "secretstring"); + +require '../tools/config.php'; diff --git a/linkshorter/css/style.css b/linkshorter/css/style.css deleted file mode 100644 index b5aa321..0000000 --- a/linkshorter/css/style.css +++ /dev/null @@ -1,68 +0,0 @@ -html { - position: relative; - min-height: 100%; -} - -body { - margin-bottom: 60px; -} - -a { - color: #3083D6; -} - -/* navbar */ - -.navbar-default { - background-color: #3083D6 ; - border-color: #3083D6 ; - background: #3083D6 ; -} - -.navbar-default .navbar-brand { - color: white; -} - -.navbar-default .navbar-brand:hover, -.navbar-default .navbar-brand:focus { -} - -.navbar-default .navbar-nav > li > a { - color: white; -} - -.noscript { - background-color: #dd5148; - color: white; -} - -/* footer */ - -.footer { - background-color: #3083D6 ; - border-color: #3083D6 ; - background: #3083D6 ; - color: white ; - position: absolute; - bottom: 0; - width: 100%; -} - -.footer-a { - color: white; -} - -.footer-a:hover { - color: white; - text-decoration: underline; -} - -.underline { - text-decoration: underline; -} - -.actives { - color: white !important; - text-decoration: underline; - font-weight: bold; -} diff --git a/linkshorter/goto.php b/linkshorter/goto.php index f42705f..f459dc6 100644 --- a/linkshorter/goto.php +++ b/linkshorter/goto.php @@ -1,6 +1,6 @@ <?php -require 'class/db.php'; +require '../tools/class/redis.php'; require 'config.php'; require 'functions.php'; diff --git a/linkshorter/index.php b/linkshorter/index.php index cca4f20..8d05977 100644 --- a/linkshorter/index.php +++ b/linkshorter/index.php @@ -1,18 +1,18 @@ <?php require 'functions.php'; require 'config.php'; -require 'class/db.php'; +require '../tools/class/redis.php'; if ( ! isset($_REQUEST['url']) || $_REQUEST['url'] == "" ){ -if ( ! isset($_REQUEST['checkpassword']) || $_REQUEST['checkpassword'] != 1 ) + if ( ! isset($_REQUEST['checkpassword']) || $_REQUEST['checkpassword'] != 1 ) require 'view/templ-index.php'; else { if ( ! isset($_REQUEST["short"]) || $_REQUEST["short"] == "" ){ - header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); - _do_output("Failure!", "Requested ID not found."); + require 'view/templ-notfound.php'; + exit; } $db = new Database(REDIS_CONNECT, REDIS_SELECT); @@ -73,5 +73,5 @@ if ( ! isset($_REQUEST['checkpassword']) || $_REQUEST['checkpassword'] != 1 ) } } - _do_output("Success!", "Your short link is " . SHORTDOMAIN . htmlentities($options["short"]) . "."); + _do_output("Success!", "Your short link is <a href=\"" . SHORTDOMAIN . htmlentities($options["short"]) . "\" title=\"".htmlentities($options["url"])."\">". SHORTDOMAIN . htmlentities($options["short"]) ."</a>"); } diff --git a/linkshorter/view/templ-head.php b/linkshorter/view/templ-head.php index 2eee43c..4dd76d5 100644 --- a/linkshorter/view/templ-head.php +++ b/linkshorter/view/templ-head.php @@ -1,3 +1,6 @@ +<?php + require '../tools/config.php'; +?> <!doctype html> <html> <head> @@ -9,7 +12,7 @@ <?php echo file_get_contents("../tools/style.css"); ?> .grey { color: #737373;} </style> - <link rel='shortcut icon' href='../tools/favicon.ico' type='image/x-icon'> + <link rel='shortcut icon' href='<?php echo __domain_; ?>/tools/favicon.ico' type='image/x-icon'> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <?php require("../tools/navbar.php"); ?> diff --git a/linkshorter/view/templ-index.php b/linkshorter/view/templ-index.php index 17b042e..46ff6a8 100644 --- a/linkshorter/view/templ-index.php +++ b/linkshorter/view/templ-index.php @@ -1,6 +1,9 @@ <?php $title= "Link Shorter"; require 'view/templ-head.php'; + + if ( $_scheme . $_SERVER["HTTP_HOST"] != __domain_ ) + redirect(__domain_ . "/linkshorter/"); ?> <div class="container"> <div class="text-center"> @@ -13,27 +16,31 @@ <div class="form-group"> <label class="col-md-4 control-label" for="url">Link:</label> <div class="col-md-5"> - <input id="url" name="url" placeholder="http://www.moehm.org/" class="form-control input-md" required="" type="text"> + <input id="url" name="url" placeholder="Enter a URL to shorten..." class="form-control input-md" required="" type="text"> </div> </div> <div class="form-group"> - <label class="col-md-4 control-label grey" for="short">(optional)</label> + <h4>Options:</h4> + </div> + + <div class="form-group"> + <label class="col-md-4 control-label grey" for="short">Query String</label> <div class="col-md-4"> - <input id="short" name="short" placeholder="Your own query string here." class="form-control input-md" type="text"> + <input id="short" name="short" placeholder="Your own query string here. (optional)" class="form-control input-md" type="text"> </div> </div> <!-- Password input--> <div class="form-group"> - <label class="col-md-4 control-label grey" for="password">(optional)</label> + <label class="col-md-4 control-label grey" for="password">Password</label> <div class="col-md-4"> <input id="password" name="password" placeholder="Protect your link with a password." class="form-control input-md" type="password"> </div> </div> <div class="form-group"> - <label class="col-md-4 control-label grey" for="ttl">(optional)</label> + <label class="col-md-4 control-label grey" for="ttl">Expires</label> <div class="col-md-4"> <input id="ttl" name="ttl" class="form-control input-md" type="number" min="0"> <span class="help-block text-left">Choose how long the shortlink should be valid. (In seconds)</span> diff --git a/linkshorter/view/templ-notfound.php b/linkshorter/view/templ-notfound.php new file mode 100644 index 0000000..66d654b --- /dev/null +++ b/linkshorter/view/templ-notfound.php @@ -0,0 +1,14 @@ +<?php + header($_SERVER["SERVER_PROTOCOL"] . " 404 Not Found"); + header("X-Request-Id: " . $_REQUEST["short"]); + $title= "404 Not Found"; + require 'view/templ-head.php'; +?> +<div class="container text-center pagination-centered"> + <div class="row"> + <h1>Failure - Not Found</h1> + <hr> + <h4>The requested URL ('<?php echo htmlentities($_SERVER["REQUEST_URI"]); ?>') wasn't found on this server.</h4> + </div> +</div> + <?php require("../tools/footer.php"); ?> |
