From 4168f7aff52f6e7cf7320e42252227dac5169c4a Mon Sep 17 00:00:00 2001 From: Horus3 Date: Sun, 16 Nov 2014 21:20:41 +0100 Subject: Initial commit. --- header/index.php | 200 ++++++++++++++++++++++++++++++++++++++++++++++ index.php | 30 +++++++ linkshorter/.gitignore | 4 + linkshorter/db.php | 16 ++++ linkshorter/error.php | 13 +++ linkshorter/functions.php | 58 ++++++++++++++ linkshorter/goto.php | 13 +++ linkshorter/header.php | 18 +++++ linkshorter/index.html | 50 ++++++++++++ linkshorter/index.php | 108 +++++++++++++++++++++++++ linkshorter/insert.php | 36 +++++++++ linkshorter/style.css | 21 +++++ robots.txt | 2 + tools/favicon.ico | Bin 0 -> 5242 bytes tools/footer.php | 9 +++ tools/navbar.php | 27 +++++++ tools/style.css | 54 +++++++++++++ 17 files changed, 659 insertions(+) create mode 100644 header/index.php create mode 100644 index.php create mode 100644 linkshorter/.gitignore create mode 100644 linkshorter/db.php create mode 100644 linkshorter/error.php create mode 100644 linkshorter/functions.php create mode 100644 linkshorter/goto.php create mode 100644 linkshorter/header.php create mode 100644 linkshorter/index.html create mode 100644 linkshorter/index.php create mode 100644 linkshorter/insert.php create mode 100644 linkshorter/style.css create mode 100644 robots.txt create mode 100644 tools/favicon.ico create mode 100644 tools/footer.php create mode 100644 tools/navbar.php create mode 100644 tools/style.css diff --git a/header/index.php b/header/index.php new file mode 100644 index 0000000..1a027ab --- /dev/null +++ b/header/index.php @@ -0,0 +1,200 @@ + + + + + + + + + + + Check HTTP Headers online! + Header: ' . htmlentities($_REQUEST['url']) .''; + } + ?> + + + + + +
+
+
+connect("/var/run/redis/redis.sock"); + $redis->ping(); + $redis->select(9); + + $key = md5( $url . serialize($customHeader) ); + + if( $redis->exists( $key ) ){ + return unserialize( $redis->get( $key ) ); + } + + $agent = "Retrieve HTTP headers online. v0.1"; + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($ch, CURLOPT_HEADER, 1); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); + curl_setopt($ch, CURLOPT_USERAGENT, $agent); + curl_setopt($ch, CURLINFO_HEADER_OUT, 1); + + switch($method){ + case("head"): + curl_setopt($ch, CURLOPT_NOBODY, true); + break; + case("post"): + curl_setopt($ch, CURLOPT_POST, true); + default: + break; + } + + if ( ! empty($customHeader) ){ + curl_setopt($ch, CURLOPT_HTTPHEADER, $customHeader); + } + + $response = curl_exec($ch); + if ( ! $response ) + return false; + $request = curl_getinfo($ch, CURLINFO_HEADER_OUT); + $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); + $header = substr($response, 0, $header_size); + $host = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); + + $result = array($request, $header, $host); + + # redis. remove this line if no redis + $redis->set( $key, serialize($result), 60 ); + + return $result; + } + if ( ! isset($_REQUEST['method']) || $_REQUEST['method'] != "" ){ + $_REQUEST['method'] = 'get'; + } else { + $_REQUEST['method'] = strtolower($_REQUEST['method']); + } + $header_info = getInfo($_REQUEST['url'], $_REQUEST['method'], $_REQUEST['header']); + if ( ! $header_info ){ + echo "

Failure!

Requested URL: \"".htmlentities($_REQUEST['url'])."\"


Couldn't retrieve URL. Please check whether the website is available and try again.
"; + } else { + ?> +

Success!

+
+

Requested URL: ""
+Host: ""

+
+ +

Request Header:

+ ".htmlentities($header_info[0]).""; + ?> +

Response Header:

+ "; + echo htmlentities($header_info[1]); + echo ""; + } + ?> +

Entries are cached for 60 seconds.

+ +

Retrieve HTTP Headers Online!

+

Check the response headers for websites.
Enter a URL and hit the submit button.

+
+
+
+ + + + + + +
+ +
+ +
+
+ + +
+ +
+ + + +
+
+ +
+ + +
+ +
+
+ + + + + +
+ Add any header, which are sent to the server. +
+
+ + + + +
+ +
+ +
+
+ +
+
+ + +
+
+
+ + + diff --git a/index.php b/index.php new file mode 100644 index 0000000..99a8458 --- /dev/null +++ b/index.php @@ -0,0 +1,30 @@ + + + + + + + + + + Check HTTP Headers online! + Header: ' . htmlentities($_REQUEST['url']) .''; + } + ?> + + + + + +
+
+
+ +
+
+
+ + diff --git a/linkshorter/.gitignore b/linkshorter/.gitignore new file mode 100644 index 0000000..f7f0c78 --- /dev/null +++ b/linkshorter/.gitignore @@ -0,0 +1,4 @@ +*.swp +*~ +*.tmp +*notmin* diff --git a/linkshorter/db.php b/linkshorter/db.php new file mode 100644 index 0000000..4dcf58a --- /dev/null +++ b/linkshorter/db.php @@ -0,0 +1,16 @@ +connect('/var/run/redis/redis.sock'); + +try { + $db->ping(); +} catch (Exception $e){ + do_output("

No connection to the database established.

", "500 Server Failure", false, "

Redis went away

"); +} + +try { + $db->select(1); +} catch (Exception $e){ + do_output("

No connection to the database established.

", "500 Server Failure", false, "

Redis went away

"); +} diff --git a/linkshorter/error.php b/linkshorter/error.php new file mode 100644 index 0000000..92ba713 --- /dev/null +++ b/linkshorter/error.php @@ -0,0 +1,13 @@ +The requested url ( ".htmlentities($_SERVER['REQUEST_URI'])." ) wasn't found on this server.

", "404 Not Found", false, "

400 - Not Found

"); + break; + + default: + do_output("

There was a failure and your request can't be proceeded.

", "500 Error", false, "

Error!

"); +} diff --git a/linkshorter/functions.php b/linkshorter/functions.php new file mode 100644 index 0000000..f6f021a --- /dev/null +++ b/linkshorter/functions.php @@ -0,0 +1,58 @@ + + + + + + Link Shorter + + + + + + + +
+
+ +
+
+
+ +
+
+ + +[^\S ]+/s', // strip whitespaces after tags, except space + '/[^\S ]+\', + '<', + '\\1' + ); + + $buffer = preg_replace($search, $replace, $buffer); + + return $buffer; +} diff --git a/linkshorter/goto.php b/linkshorter/goto.php new file mode 100644 index 0000000..d77e1e2 --- /dev/null +++ b/linkshorter/goto.php @@ -0,0 +1,13 @@ +get($_GET["goto"]); +if( ! $url || $url == "" ){ + do_output("

This url wasn't found on this server.

", "404 Not Found", false, "

404 - Not found

"); +} + +header($_SERVER['SERVER_PROTOCOL'] . " 301 Moved Permanently"); +header("Location: ".$url); +exit; diff --git a/linkshorter/header.php b/linkshorter/header.php new file mode 100644 index 0000000..c207321 --- /dev/null +++ b/linkshorter/header.php @@ -0,0 +1,18 @@ + diff --git a/linkshorter/index.html b/linkshorter/index.html new file mode 100644 index 0000000..62ff295 --- /dev/null +++ b/linkshorter/index.html @@ -0,0 +1,50 @@ + + + + +Link Shorter + + + + + + +
+
+
+
+
+

Amazing Linkshorter

+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+
+
+ + diff --git a/linkshorter/index.php b/linkshorter/index.php new file mode 100644 index 0000000..75ac9aa --- /dev/null +++ b/linkshorter/index.php @@ -0,0 +1,108 @@ +exists($key) ) { + header("X-Cache: Hit"); + echo $db->get($key); + ob_end_flush(); + exit; + } + +?> + + + + + Link Shorter + + + + + + + +
+
+
+
+
+ +

Amazing Linkshorter

+ +
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+ +
+ +
+
+ +
+
+
+
+
+ + +set($key, $html, 3600); + ob_end_flush(); + +} else { + + if ( empty($_POST["url"]) || $_POST["url"] == "" ){ + do_output("

We need a link to be shortened.

", "400 Client Failed", false, "

Missing URL

"); + } + + if ( ! preg_match("/^[a-z]+:\/\/[a-z0-9_]+/i", $_POST["url"]) ){ + do_output("

Only schemas like http:// or ftp:// are supported.

", "400 Client Failed", false, "

This does not look like an url

"); + } + + + $hash = md5($_POST["url"]); + if( ! empty($_POST["short"]) && $_POST["short"] != "" ) { + $short = $_POST["short"]; + if ( $db->exists($short) == 1 && $_POST["url"] != $db->get($short) ) + do_output("

Someone else has already a registered entry under '".htmlentities($short)."'.

", "422 Unprocessable Entity", false, "

Query string already exists.

"); + } else { + if( ! $short = $db->get($hash) ){ + $arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); + + do { + $short=""; + for ($i=0;$i<5;$i++){ + $r = mt_rand(0, count($arr)-1); + $short.=$arr[$r]; + } + } while ( $db->exists($short) ); + $db->set($hash, $short); + } + } + $db->set($short, $_POST["url"]); + + do_output("

Your short link for ".htmlentities($_POST["url"])." is
http://".$_SERVER["HTTP_HOST"]."/".$short."

", "200 OK", false, "

Success

"); +} diff --git a/linkshorter/insert.php b/linkshorter/insert.php new file mode 100644 index 0000000..94d01a3 --- /dev/null +++ b/linkshorter/insert.php @@ -0,0 +1,36 @@ +We need a link to be shortened.

", false, "400 Client Failed", "

Missing URL

"); +} + +if ( ! preg_match("/^[a-z]+:\/\/[a-z0-9_]+/i", $_POST["url"]) ){ + failure("

Only schemas like http:// or ftp:// are supported.

", false, "400 Client Failed", "

This does not look like an url

"); +} + +require 'db.php'; + +$hash = md5($_POST["url"]); +if( ! $short = $db->get($hash)){ + + $arr = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"); + + $short=""; + for ($i=0;$i<5;$i++){ + $r = mt_rand(0, count($arr)-1); + $short.=$arr[$r]; + } + + $db->set($short, $_POST["url"]); + $db->set($hash, $short);; +} + +failure("

Your short link for ".htmlentities($_POST["url"])." is
http://".$_SERVER["HTTP_HOST"]."/-".$short."

", false, "200 OK", "

Success

"); diff --git a/linkshorter/style.css b/linkshorter/style.css new file mode 100644 index 0000000..c762039 --- /dev/null +++ b/linkshorter/style.css @@ -0,0 +1,21 @@ +html { + position: relative; + min-height: 100%; +} + +body { + margin-bottom: 60px; +} + +/* footer */ + +.footer { + position: absolute; + bottom: 0; + width: 100%; +} + +#copyright-text { + text-decoration: underline; + color: #333; +} diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/tools/favicon.ico b/tools/favicon.ico new file mode 100644 index 0000000..41f6475 Binary files /dev/null and b/tools/favicon.ico differ diff --git a/tools/footer.php b/tools/footer.php new file mode 100644 index 0000000..9bc6c55 --- /dev/null +++ b/tools/footer.php @@ -0,0 +1,9 @@ + diff --git a/tools/navbar.php b/tools/navbar.php new file mode 100644 index 0000000..b676fa2 --- /dev/null +++ b/tools/navbar.php @@ -0,0 +1,27 @@ + + diff --git a/tools/style.css b/tools/style.css new file mode 100644 index 0000000..c42a75b --- /dev/null +++ b/tools/style.css @@ -0,0 +1,54 @@ +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; +} + + +/* 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; +} -- cgit v1.2.3