get($_REQUEST["short"]), true ); if ( password_verify( $_REQUEST["password"] . PEPPER, $options["password"] ) ) redirect($options["url"]); else _do_output("Failure!", "Wrong password supplied"); } } else { $url = trim($_REQUEST['url']); if( ! preg_match("/^https?:\/\//", $url) ){ $heading = "Failure!"; $reason = "This doesn't look like a valid URL."; _do_output($heading, $reason); } $options = array("url" => $url); if ( ! isset($_REQUEST["short"]) || $_REQUEST["short"] == "" ) $options["short"] = ""; else $options["short"] = $_REQUEST["short"]; if ( ! isset($_REQUEST["ttl"]) || $_REQUEST["ttl"] == "" ) $options["ttl"] = ""; else { if ( ! preg_match( "/^[0-9]+$/", trim($_REQUEST["ttl"]) ) ){ _do_output("Failure!", "Your Lifetime doesn't look like a valid number."); } $options["ttl"] = $_REQUEST["ttl"]; } if ( ! isset($_REQUEST["password"]) || $_REQUEST["password"] == "" ) $options["password"] = ""; else $options["password"] = password_hash($_REQUEST["password"] . PEPPER, PASSWORD_DEFAULT); $db = new Database(REDIS_CONNECT, REDIS_SELECT); if ( $options["short"] != "" && $db->exists($options["short"]) ) _do_output("Failure!", "Query string '".htmlentities($options["short"])."' already taken. Please choose a different one."); if ( $options["short"] == "" ) $options["short"] = getToken(); if ( $options["ttl"] != "" ){ if ( ! $db->set($options["short"], json_encode($options), $options["ttl"]) ){ _do_output("Failure!", "Database went away. :("); } } else { if ( ! $db->set($options["short"], json_encode($options)) ){ _do_output("Failure!", "Database went away. :("); } } _do_output("Success!", "Your short link is ". SHORTDOMAIN . htmlentities($options["short"]) .""); }