From 14d0fdaaeb1b1f9594a8c55d738a63cdb3956b99 Mon Sep 17 00:00:00 2001 From: Luke Ogburn Date: Sun, 31 Mar 2019 11:41:33 -0400 Subject: [PATCH] initial commit --- .gitignore | 2 + .htaccess | 1 + .../5ED0DD863F7316D52DCB0CFF13F0066A.txt | 1 + 404.php | 18 ++++ done.php | 20 ++++ function.php | 63 ++++++++++++ index.php | 38 ++++++++ style.css | 96 +++++++++++++++++++ 8 files changed, 239 insertions(+) create mode 100644 .gitignore create mode 100644 .htaccess create mode 100644 .well-known/pki-validation/5ED0DD863F7316D52DCB0CFF13F0066A.txt create mode 100644 404.php create mode 100644 done.php create mode 100644 function.php create mode 100644 index.php create mode 100644 style.css diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d8be26a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +tempStorage/ +conn.php diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..850a961 --- /dev/null +++ b/.htaccess @@ -0,0 +1 @@ +ErrorDocument 404 /404.php \ No newline at end of file diff --git a/.well-known/pki-validation/5ED0DD863F7316D52DCB0CFF13F0066A.txt b/.well-known/pki-validation/5ED0DD863F7316D52DCB0CFF13F0066A.txt new file mode 100644 index 0000000..25e2060 --- /dev/null +++ b/.well-known/pki-validation/5ED0DD863F7316D52DCB0CFF13F0066A.txt @@ -0,0 +1 @@ +5E9022E82668985A0143C2969A359F58FEFE2F4E70C30BF1FA753016FDB6FB61 comodoca.com 5c2cdb2ce8a20 \ No newline at end of file diff --git a/404.php b/404.php new file mode 100644 index 0000000..3319bf7 --- /dev/null +++ b/404.php @@ -0,0 +1,18 @@ +prepare("SELECT * FROM directories WHERE fromsite = :site"); + $stmt->bindParam(":site", $url); + $stmt->execute(); + $return = $stmt->fetch(PDO::FETCH_OBJ); + $return = $return->tosite; + + if(substr($return, 0, 5)!="http:" && substr($return, 0, 6)!="https:"){ + $return = "http://".$return; + } + + header("Location: $return"); +?> \ No newline at end of file diff --git a/done.php b/done.php new file mode 100644 index 0000000..2279aa9 --- /dev/null +++ b/done.php @@ -0,0 +1,20 @@ + + + + + URL Shortener  -  lukeo.link + + + + +
+

Check out my main site!

+
+
+

HERE'S YOUR SHORT URL

+

lukeo.link/

+
+

Want to make another?

+
+ + \ No newline at end of file diff --git a/function.php b/function.php new file mode 100644 index 0000000..02b2e12 --- /dev/null +++ b/function.php @@ -0,0 +1,63 @@ +prepare("SELECT * FROM directories WHERE fromsite = :pid"); + $stmt->bindParam(":pid", $pid); + $stmt->execute(); + $return = $stmt->fetch(PDO::FETCH_OBJ)->fromsite; + return ($return!=NULL)?false:true; + } + + function randID($length = 6) { + do{ + if(function_exists("random_bytes")){ + $bytes = random_bytes(ceil($length/2)); + }elseif(function_exists("openssl_random_pseudo_bytes")){ + $bytes = openssl_random_pseudo_bytes(ceil($length/2)); + }else{ + throw new Exception("No cryptographically secure random function available."); + } + $x = substr(bin2hex($bytes), 0, $length); + $id = gmp_strval(gmp_init($x, 36), 62); + } while(!verifyID($id)); + return $id; + } + + function hyperSearch($text){ + preg_match_all("#((((-|_){0,}\w)+\.([a-zA-Z]+){2,})|((((http)|(https)):\/\/){1}((-|_){0,}\w)+\.([a-zA-Z]+){2,}))((\w+|-|_|\/|\.)+){0,}#", $text, $match); + if($match[0]==NULL){ + return false; + }else{ + return true; + } + } + + if(hyperSearch($_POST["url"]) == false){ + header("Location: /?error=hps"); + exit(); + } + + $stmt = $conn->prepare("SELECT * FROM directories WHERE tosite = :site"); + $stmt->bindParam(":site", $_POST["url"]); + $stmt->execute(); + $return = $stmt->fetch(PDO::FETCH_OBJ)->fromsite; + $siteExists = ($return==NULL)?false:$return; + + if($siteExists == false){ + $fromurl = randID(); + $tourl = $_POST["url"]; + $stmt = $conn->prepare("INSERT INTO directories (fromsite, tosite) VALUES (:f, :t)"); + $stmt->bindParam(":f", $fromurl); + $stmt->bindParam(":t", $tourl); + $stmt->execute(); + if(!$stmt){ + header("Location: /?error=stmt"); + }else{ + header("Location: /done.php?code=$fromurl"); + } + }else{ + header("Location: /done.php?code=$siteExists"); + } +?> \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..b373a38 --- /dev/null +++ b/index.php @@ -0,0 +1,38 @@ + + + + + URL Shortener  -  lukeo.link + + + + +
+

Looking for lukeogburn.com?

+
+
+

URL SHORTENER

+
+ + +
+ Error creating short URL

"; + break; + case "hps": + echo "

Please enter a valid URL

"; + break; + case "unr": + echo "

That URL wasn't recognized

"; + break; + } + } + ?> +
+ + + + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..12aa4dd --- /dev/null +++ b/style.css @@ -0,0 +1,96 @@ +body{ + font-family: sans-serif; + width: 60%; + margin: 0 auto; +} + +.center{ + text-align: center; +} +a{ + text-decoration: none; + color: #35c97b; +} +a:hover{ + text-decoration: underline; +} + +/*Cookie notif*/ +#boo{ + display: none; +} +#boo:checked+div{ + display: none; +} +#cookie{ + position: absolute; + bottom: 0; + width: 60%; + text-align: center; + font-size: 0.8em; + color: #252525; +} +label:hover{ + cursor: pointer; +} + +#top{ + display: block; + width: 100%; + border-bottom: 1px solid #ccc; + font-weight: 400; +} +#top>p{ + margin: 1em 0 0.7em 0; +} + +#main{ + margin-top: 5vh; +} +#main>h2{ + font-weight: 400; + letter-spacing: 2px; +} +.error{ + color: #ff3939; +} + +form{ + width: 75%; + margin: 0 auto; + display: grid; + grid-template-columns: 5fr 1fr; +} +form>input, form>button{ + border: 1px solid #aaa; + padding: 0.5em 0.8em; +} +input{ + width: calc(100% - 1.6em); + border-radius: 0.2em 0 0 0.2em; + font-size: 1em; +} +button{ + width: 100%; + border-radius: 0 0.2em 0.2em 0; + background-color: #eee; + font-size: 0.85em; +} +button:hover{ + cursor: pointer; + background-color: #eee; +} + +@media (max-width: 1000px){ + body, #cookie{ + width: 70%; + } + form{ + width: 90%; + } +} +@media (max-width: 600px){ + body, #cookie{ + width: 100%; + } +} \ No newline at end of file