-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Wassup789
committed
Jul 30, 2014
1 parent
8a3cb36
commit c861fca
Showing
10 changed files
with
220 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 "*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); | ||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} |