mirror of
https://github.com/gamaio/lobli.git
synced 2024-12-22 19:52:40 +00:00
Quick and dirty API for the chrome/firefox extension.
Probably buggy, untested.
This commit is contained in:
parent
b40c3206f8
commit
ea1a3a4c10
58
Website/ch/index.php
Normal file
58
Website/ch/index.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require("../Include/PHP/db.php");
|
||||||
|
require("../Include/PHP/functions.php");
|
||||||
|
|
||||||
|
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) { // Get true IP of visiter if going through cloudflare
|
||||||
|
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
|
||||||
|
}
|
||||||
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
$now = time(NULL);
|
||||||
|
$seperator = "ᐖ";
|
||||||
|
|
||||||
|
if(isset($_GET['shorten'])){
|
||||||
|
$short = $_GET['url'];
|
||||||
|
if(strpos($short, "http://") === false && strpos($short, "https://") === false){ $short = "http://$short"; }
|
||||||
|
|
||||||
|
$apip = $redis->get("api:ip:$ip");
|
||||||
|
if(!in_array($ip, $apip)){
|
||||||
|
$redis->set("api:ip:$ip", $ip);
|
||||||
|
$redis->expireAt("api:ip:$ip", $now+5); // Five seconds between requests should be okay
|
||||||
|
}else{
|
||||||
|
die("Too many requests too fast!");
|
||||||
|
}
|
||||||
|
|
||||||
|
$reShort = shorten($redis, $short, 2, $seperator);
|
||||||
|
$reShort = explode($seperator, $reShort);
|
||||||
|
$retCode = $reShort[0];
|
||||||
|
|
||||||
|
switch($retCode){
|
||||||
|
case "0": // Successful link Shorten
|
||||||
|
echo $reShort[1];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "1": // Existing Short Link Found
|
||||||
|
echo $reShort[1];
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "2": // Dead Link
|
||||||
|
echo "dead";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "3": // DB Error
|
||||||
|
echo "db";
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "4": // Sanitize Failure Error
|
||||||
|
echo "sf";
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
echo "Error";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
exit;
|
||||||
|
}elseif(isset($_GET['resolve'])){ die("Not ready"); }
|
||||||
|
else{ die("Improper Call."); }
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in New Issue
Block a user