Skip to content

Commit

Permalink
Updated to v1.0.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Wassup789 committed Jul 30, 2014
1 parent 8a3cb36 commit c861fca
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
=====
## v1.0.2.0
* Swapped domains
* Added data source

## v1.0.1.0
* Added connection error fallback
* Added domain choices
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ This code is licensed under the MIT License

**Latest Stable Release:**

- **Version 1.0.1.0** - 07-17-2014 22:28 PDT
- **Version 1.0.2.0** - 07-30-2014 15:47 PDT
- [Download Here via Google Drive][Dld_Latest_GD]
- [Direct Link via Dropbox][Dld_Latest_DB]

Expand All @@ -37,9 +37,9 @@ This code is licensed under the MIT License
## Changelog
[See CHANGELOG.md][CLog.md]

[Dld_Latest_GD]: https://drive.google.com/file/d/0B_WfQfUn7IraVWNOVmVueG9OS2s/edit?usp=sharing
[Dld_Latest_GD]: https://drive.google.com/file/d/0B_WfQfUn7IraeHJ3ZFNFTG1wYU0/edit?usp=sharing

[Dld_Latest_DB]: https://dl.dropboxusercontent.com/u/14210090/URL%20Shortener/URL_Shortener_v1.0.1.0.crx
[Dld_Latest_DB]: https://dl.dropboxusercontent.com/u/14210090/URL%20Shortener/URL_Shortener_v1.0.2.0.crx
[Dld_Archive]: https://drive.google.com/folderview?id=0B_WfQfUn7IraLVNBQmJOWFFpSmc&usp=sharing

[CLog.md]: https://github.com/Wassup789/URL-Shortener/blob/master/CHANGELOG.md
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"name": "URL Shortener (beta)",
"name": "URL Shortener",
"description": "Shorten your URL with goo.gl, bit.ly or tinyurl.com with a click of a button.",
"version": "1.0.2.0",
"permissions": [ "tabs" ],
Expand Down
2 changes: 1 addition & 1 deletion settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ $(document).ready(function(){

var manifest = chrome.runtime.getManifest();

var beta = true;
var beta = false;
if(beta)
$(".version").html("Version " + manifest.version + " beta<br/>by Wassup789");
else
Expand Down
4 changes: 4 additions & 0 deletions www/.htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
Header set Access-Control-Allow-Origin "*"
56 changes: 56 additions & 0 deletions www/bitly.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
include("connection.php");
if(!isset($_GET["url"])){
header("HTTP/1.1 400 Bad Request");
exit();
}
$longUrl = $_GET["url"];

$origin = $_SERVER["HTTP_ORIGIN"];

if($origin != "chrome-extension://nmmlgajflaadkcfcdiblldhdhpnbmhii" && $origin != "chrome-extension://inkbdhkochhhjjbckkejpganmobahlpj")
exit();

$loginName = "BITLYLOGINNAMEHERE";
$apiKey = "BITLYAPIKEY";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://api.bit.ly/v3/shorten?apiKey={$apiKey}&login={$loginName}&longUrl={$longUrl}&format=json");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type:application/json'));

$shortUrl = json_decode(curl_exec($ch)) -> data -> url;

curl_close($ch);

$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');

$num = 0;
$navcmd = "SELECT * FROM bitly WHERE ip=\"$ip\" AND timestamp > " . (time() - 10);
$navquery = mysqli_query($mysql_link, $navcmd) or die (mysql_error());
while ($row = mysqli_fetch_array($navquery)) {
$num++;
}

if($num >= 5)
echo "Too many requests";
else{
echo $shortUrl;
$query = 'INSERT INTO bitly (ip, timestamp, link) VALUES ("'.$ip.'", "'.time().'", "'.$shortUrl.'")';
mysqli_query($mysql_link, $query) OR die (mysql_error());
}

$navcmd = "SELECT * FROM bitly WHERE timestamp < " . (time() - 20);
$navquery = mysqli_query($mysql_link, $navcmd) or die (mysql_error());
while ($row = mysqli_fetch_array($navquery)) {
$query = 'DELETE FROM bitly WHERE id="'.$row["id"].'"';
mysqli_query($mysql_link, $query) OR die (mysql_error());
}
13 changes: 13 additions & 0 deletions www/connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
//-----------Database Details------------------------------------

$server["host"] = "HOSTNAME";//Host
$server["username"] = "USERNAME";//Database Username
$server["password"] = "PASSWORD";//Database Password
$server["db"] = "DATABASENAME";// Database

//-----------Dont Touch This-------------------------------------

$mysql_link = mysqli_connect($server["host"], $server["username"], $server["password"]) OR die ('Cant connect to the database');
mysqli_select_db($mysql_link, $server["db"]);
?>
26 changes: 26 additions & 0 deletions www/executethis.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
DROP TABLE IF EXISTS `bitly`;
CREATE TABLE `bitly` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(45) NOT NULL,
`timestamp` varchar(10) NOT NULL,
`link` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `google`;
CREATE TABLE `google` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(45) NOT NULL,
`timestamp` varchar(10) NOT NULL,
`link` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=55 DEFAULT CHARSET=latin1;

DROP TABLE IF EXISTS `tinyurl`;
CREATE TABLE `tinyurl` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(45) NOT NULL,
`timestamp` varchar(10) NOT NULL,
`link` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=133 DEFAULT CHARSET=latin1;
59 changes: 59 additions & 0 deletions www/google.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
include("connection.php");
if(!isset($_GET["url"])){
header("HTTP/1.1 400 Bad Request");
exit();
}
$longUrl = $_GET["url"];

$origin = $_SERVER["HTTP_ORIGIN"];

if($origin != "chrome-extension://nmmlgajflaadkcfcdiblldhdhpnbmhii" && $origin != "chrome-extension://inkbdhkochhhjjbckkejpganmobahlpj")
exit();

$apiKey = "GOOGLAPIKEYHERE";
$data = array("longUrl" => $longUrl, "key" => $apiKey);
$data_json = json_encode($data);

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "https://www.googleapis.com/urlshortener/v1/url");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type:application/json"));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);

$shortUrl = json_decode(curl_exec($ch)) -> id;

curl_close($ch);

$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');

$num = 0;
$navcmd = "SELECT * FROM google WHERE ip=\"$ip\" AND timestamp > " . (time() - 10);
$navquery = mysqli_query($mysql_link, $navcmd) or die (mysql_error());
while ($row = mysqli_fetch_array($navquery)) {
$num++;
}

if($num >= 5)
echo "Too many requests";
else{
echo $shortUrl;
$query = 'INSERT INTO google (ip, timestamp, link) VALUES ("'.$ip.'", "'.time().'", "'.$shortUrl.'")';
mysqli_query($mysql_link, $query) OR die (mysql_error());
}

$navcmd = "SELECT * FROM google WHERE timestamp < " . (time() - 20);
$navquery = mysqli_query($mysql_link, $navcmd) or die (mysql_error());
while ($row = mysqli_fetch_array($navquery)) {
$query = 'DELETE FROM google WHERE id="'.$row["id"].'"';
mysqli_query($mysql_link, $query) OR die (mysql_error());
}
53 changes: 53 additions & 0 deletions www/tinyurl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
include("connection.php");
if(!isset($_GET["url"])){
header("HTTP/1.1 400 Bad Request");
exit();
}
$longUrl = $_GET["url"];

$origin = $_SERVER["HTTP_ORIGIN"];

if($origin != "chrome-extension://nmmlgajflaadkcfcdiblldhdhpnbmhii" && $origin != "chrome-extension://inkbdhkochhhjjbckkejpganmobahlpj")
exit();

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, "http://tinyurl.com/api-create.php?url={$longUrl}");
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.3 Safari/537.36");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$shortUrl = curl_exec($ch);

curl_close($ch);

$ip = getenv('HTTP_CLIENT_IP')?:
getenv('HTTP_X_FORWARDED_FOR')?:
getenv('HTTP_X_FORWARDED')?:
getenv('HTTP_FORWARDED_FOR')?:
getenv('HTTP_FORWARDED')?:
getenv('REMOTE_ADDR');

$num = 0;
$navcmd = "SELECT * FROM tinyurl WHERE ip=\"$ip\" AND timestamp > " . (time() - 10);
$navquery = mysqli_query($mysql_link, $navcmd) or die (mysql_error());
while ($row = mysqli_fetch_array($navquery)) {
$num++;
}

if($num >= 5)
echo "Too many requests";
else{
echo $shortUrl;
$query = 'INSERT INTO tinyurl (ip, timestamp, link) VALUES ("'.$ip.'", "'.time().'", "'.$shortUrl.'")';
mysqli_query($mysql_link, $query) OR die (mysql_error());
}

$navcmd = "SELECT * FROM tinyurl WHERE timestamp < " . (time() - 20);
$navquery = mysqli_query($mysql_link, $navcmd) or die (mysql_error());
while ($row = mysqli_fetch_array($navquery)) {
$query = 'DELETE FROM tinyurl WHERE id="'.$row["id"].'"';
mysqli_query($mysql_link, $query) OR die (mysql_error());
}

0 comments on commit c861fca

Please sign in to comment.