mirror of
https://github.com/gamaio/unps.us-Shortener.git
synced 2025-07-30 13:50:17 +00:00
Broke the shortener
I broke everything.
This commit is contained in:
@@ -37,8 +37,10 @@ function checkRemoteFile($ip=null){
|
||||
}
|
||||
|
||||
class api{
|
||||
require_once('dbsettings.php');
|
||||
|
||||
// Begin Short
|
||||
function shorten($apidb, $apikey, $sdb, $link, $dpass=null){
|
||||
function shorten($link, $dpass=null){
|
||||
$apisql = "SELECT * FROM `users` WHERE `key` = '$apikey' LIMIT 1";
|
||||
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
||||
if($row = $result->fetch_assoc()){
|
||||
@@ -126,6 +128,39 @@ class api{
|
||||
return "<div id=\"success\">Reported $link. Please check back in a day or two</div>";
|
||||
}
|
||||
|
||||
function trackLink($apidb, $apikey, $sdb, $linkid){
|
||||
$apisql = "SELECT * FROM `users` WHERE `key` = '$apikey' LIMIT 1;";
|
||||
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
||||
if($row = $result->fetch_assoc()){
|
||||
$canshort = $row['short'];
|
||||
$name = $row['name'];
|
||||
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
|
||||
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Track Link', '$canshort', '$link')";
|
||||
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
||||
}
|
||||
if($canshort != 1) return '<div id="error">Failed to report</div>';
|
||||
|
||||
$sql = "INSERT INTO `tracking` (time, apikey, ip, linkid) VALUES (NOW(), '$apikey', '$ip', '$linkid')";
|
||||
if(!$result = $sdb->query($sql)): die( 'ERROR: ['.$sdb->error.']');
|
||||
else: die("SUCCESS");
|
||||
endif;
|
||||
}
|
||||
|
||||
function resLink($link){
|
||||
$link = sanitize($link);
|
||||
$sql = "SELECT * FROM `links` WHERE `shortlink` = '$link' LIMIT 1;";
|
||||
if($result = $shortdb->query($sql)){
|
||||
if($row = $result->fetch_assoc()){
|
||||
$link = $row['link'];
|
||||
trackLink($apidb, $key, $sdb, $link);
|
||||
header("location:$link");
|
||||
exit(); // Stop script execution to save on resources
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End Short
|
||||
}
|
||||
|
||||
|
@@ -2,12 +2,12 @@
|
||||
|
||||
// DBSettings
|
||||
|
||||
$apidb = new mysqli('localhost', 'api', 'password', 'api'); // Connect to main APIDB
|
||||
global $apidb = new mysqli('localhost', 'api', 'password', 'api'); // Connect to main APIDB
|
||||
if($apidb->connect_errno > 0) die('Unable to connect to database [' . $apidb->connect_error . '] - Check dbsettings.php');
|
||||
|
||||
$shortdb = new mysqli('localhost', 'short', 'password', 'short'); // Connect to link shortener DB
|
||||
global $shortdb = new mysqli('localhost', 'short', 'password', 'short'); // Connect to link shortener DB
|
||||
if($shortdb->connect_errno > 0) die('Unable to connect to database [' . $shortdb->connect_error . '] - Check dbsettings.php');
|
||||
|
||||
$key = '9a211e90b0a0570ed33e47428231e702af47b6f54fb347960f661184e063a1d0'; // KEEP THIS PRIVATE! This is the only thing that authenticates the application
|
||||
global $key = '9a211e90b0a0570ed33e47428231e702af47b6f54fb347960f661184e063a1d0'; // KEEP THIS PRIVATE! This is the only thing that authenticates the application
|
||||
|
||||
?>
|
Reference in New Issue
Block a user