mirror of
https://github.com/gamaio/unps.us-Shortener.git
synced 2024-12-22 10:12:41 +00:00
Add red error boxes in return messages
This is continuing development on the interface, they will fade in the next commit
This commit is contained in:
parent
c3848688a5
commit
cfe1a23a33
@ -31,16 +31,16 @@ class api{
|
|||||||
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Link Shorten', '$canshort', '$link')";
|
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Link Shorten', '$canshort', '$link')";
|
||||||
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
||||||
}
|
}
|
||||||
if($canshort != 1) return 'You are not authorized to shorten links';
|
if($canshort != 1) return '<div id="error">You are not authorized to shorten links</div>';
|
||||||
|
|
||||||
$sql = "SELECT * FROM `links` WHERE `link` = '$link' LIMIT 1;";
|
$sql = "SELECT * FROM `links` WHERE `link` = '$link' LIMIT 1;";
|
||||||
if($result = $sdb->query($sql)){
|
if($result = $sdb->query($sql)){
|
||||||
if($row = $result->fetch_assoc()){
|
if($row = $result->fetch_assoc()){
|
||||||
$short = $row['shortlink'];
|
$short = $row['shortlink'];
|
||||||
return "Existing link: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a>";
|
return "<div id=\"error\">Existing link: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a></div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(checkRemoteFile($link) !== true) return "Dead Link: $link";
|
if(checkRemoteFile($link) !== true) return "<div id=\"error\">Dead Link: $link</div>";
|
||||||
$short = substr(number_format(time() * mt_rand(),0,'',''),0,10);
|
$short = substr(number_format(time() * mt_rand(),0,'',''),0,10);
|
||||||
$short = base_convert($short, 10, 36);
|
$short = base_convert($short, 10, 36);
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ class api{
|
|||||||
endif;
|
endif;
|
||||||
|
|
||||||
if($result = $sdb->query($sql)): return "Shortened: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a><br />Your link deletion password (write this down): $dpass";
|
if($result = $sdb->query($sql)): return "Shortened: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a><br />Your link deletion password (write this down): $dpass";
|
||||||
else: return 'ERROR: ['.$sdb->error.']';
|
else: return '<div id="error">ERROR: ['.$sdb->error.']</div>';
|
||||||
endif;
|
endif;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ class api{
|
|||||||
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Short Link Delete', '$canshort', '$link')";
|
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Short Link Delete', '$canshort', '$link')";
|
||||||
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
||||||
}
|
}
|
||||||
if($canshort != 1) return 'You are not authorized to delete short links';
|
if($canshort != 1) return '<div id="error">You are not authorized to delete short links</div>';
|
||||||
|
|
||||||
$sql = "SELECT * FROM `links` WHERE `shortlink` = '$link' LIMIT 1;";
|
$sql = "SELECT * FROM `links` WHERE `shortlink` = '$link' LIMIT 1;";
|
||||||
if($result = $sdb->query($sql)){
|
if($result = $sdb->query($sql)){
|
||||||
@ -80,12 +80,12 @@ class api{
|
|||||||
|
|
||||||
if($apikey == $password){
|
if($apikey == $password){
|
||||||
$sql = "DELETE FROM `links` WHERE `shortlink` = '$link' AND `dpass` = '$apikey' LIMIT 1;";
|
$sql = "DELETE FROM `links` WHERE `shortlink` = '$link' AND `dpass` = '$apikey' LIMIT 1;";
|
||||||
if(!$result = $sdb->query($sql)) return 'ERROR: ['.$sdb->error.']';
|
if(!$result = $sdb->query($sql)) return '<div id="error">ERROR: ['.$sdb->error.'</div>]';
|
||||||
echo "Deleted: $link";
|
echo "Deleted: $link";
|
||||||
return;
|
return;
|
||||||
}else{ return "The password doesn't match. Delete $link aborted!"; }
|
}else{ return "<div id=\"error\">The password doesn't match. Delete $link aborted!</div>"; }
|
||||||
}
|
}
|
||||||
}else{ return 'ERROR: ['.$sdb->error.']'; }
|
}else{ return '<div id="error">ERROR: ['.$sdb->error.']</div>'; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function reportLink($apidb, $apikey, $sdb, $link, $reason){
|
function reportLink($apidb, $apikey, $sdb, $link, $reason){
|
||||||
@ -100,10 +100,10 @@ class api{
|
|||||||
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Report Link', '$canshort', '$link')";
|
$apisql = "INSERT INTO `apiuse` (time, name, apikey, ip, type, allowed, misc) VALUES (NOW(), '$name', '$apikey', '$ip', 'Report Link', '$canshort', '$link')";
|
||||||
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
if(!$result = $apidb->query($apisql)) return 'ERROR: ['.$apidb->error.']';
|
||||||
}
|
}
|
||||||
if($canshort != 1) return 'You are not authorized to shorten links, meaning you also can\'t report false negatives';
|
if($canshort != 1) return '<div id="error">You are not authorized to shorten links, meaning you also can\'t report false negatives</div>';
|
||||||
|
|
||||||
$sql = "INSERT INTO `manual` (time, apikey, ip, link, reason) VALUES(NOW(), '$apikey', '$ip', '$link', '$reason');";
|
$sql = "INSERT INTO `manual` (time, apikey, ip, link, reason) VALUES(NOW(), '$apikey', '$ip', '$link', '$reason');";
|
||||||
if(!$result = $sdb->query($sql)) return 'ERROR: ['.$sdb->error.']';
|
if(!$result = $sdb->query($sql)) return '<div id="error">ERROR: ['.$sdb->error.']</div>';
|
||||||
return "Reported $link. Please check back in a day or two";
|
return "Reported $link. Please check back in a day or two";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,6 @@ body{
|
|||||||
.form-shorten input[type="text"], .form-shorten textarea{
|
.form-shorten input[type="text"], .form-shorten textarea{
|
||||||
position: relative;
|
position: relative;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
height: auto;
|
|
||||||
padding: 7px;
|
padding: 7px;
|
||||||
-webkit-box-sizing: border-box;
|
-webkit-box-sizing: border-box;
|
||||||
-moz-box-sizing: border-box;
|
-moz-box-sizing: border-box;
|
||||||
@ -142,6 +141,16 @@ body{
|
|||||||
float: center;
|
float: center;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #bbb;
|
color: #bbb;
|
||||||
|
padding-left: 25.6% !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
#message #error{
|
||||||
|
float: center;
|
||||||
|
text-align: center;
|
||||||
|
background-color: #cb3434;
|
||||||
|
border-radius: 5px;
|
||||||
|
padding: 5px;
|
||||||
|
width: 66%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#footer {
|
#footer {
|
||||||
|
22
process.php
22
process.php
@ -1,4 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
$catches = explode(":", $_SESSION['catch']);
|
||||||
|
$catchid = $catches[0];
|
||||||
|
$catchVal = $catches[1];
|
||||||
|
|
||||||
|
if(empty($_GET['token']) || $_GET['token'] != $_SESSION['token'] || empty($_POST[$catchid]) || $_POST[$catchid] != $catchVal){
|
||||||
|
die("Oh Noes! Something happened and I can't continue.<br />Please try again by using the form located at <a href=\"http://unps.us\">http://unps.us</a>.");
|
||||||
|
}
|
||||||
|
|
||||||
require('api/api.backend.php');
|
require('api/api.backend.php');
|
||||||
require('api/dbsettings.php');
|
require('api/dbsettings.php');
|
||||||
@ -6,7 +15,7 @@
|
|||||||
$key = '9a211e90b0a0570ed33e47428231e702af47b6f54fb347960f661184e063a1d0'; // KEEP THIS PRIVATE! This is the only thing that authenticates the application
|
$key = '9a211e90b0a0570ed33e47428231e702af47b6f54fb347960f661184e063a1d0'; // KEEP THIS PRIVATE! This is the only thing that authenticates the application
|
||||||
|
|
||||||
function sanitize($input){
|
function sanitize($input){
|
||||||
if ($input == null) die("Sanatize() - No Input Provided, Aborting\r\n<br>");
|
if ($input == null) die("<div id=\"error\">Sanatize() - No Input Provided, Aborting</div>");
|
||||||
include('api/dbsettings.php');
|
include('api/dbsettings.php');
|
||||||
$output = strip_tags($input);
|
$output = strip_tags($input);
|
||||||
$output = stripslashes($output);
|
$output = stripslashes($output);
|
||||||
@ -23,22 +32,25 @@
|
|||||||
echo $unpsAPI->shorten($apidb, $key, $shortdb, $short);
|
echo $unpsAPI->shorten($apidb, $key, $shortdb, $short);
|
||||||
break;
|
break;
|
||||||
case "dellink":
|
case "dellink":
|
||||||
if(empty($_POST['password'])) die("Something went wrong somewhere, but there's no password here");
|
if(empty($_POST['password'])) die("<div id=\"error\">Something went wrong somewhere, but there's no password here</div>");
|
||||||
$link = sanitize($_POST['link']);
|
$link = sanitize($_POST['link']);
|
||||||
$password = sanitize($_POST['password']);
|
$password = sanitize($_POST['password']);
|
||||||
$link = explode("=", $link);
|
$link = explode("=", $link);
|
||||||
|
if(count($link) != 2){
|
||||||
|
die("<div id=\"error\">I'm sorry, but something went wrong... did you paste the whole link?</div>");
|
||||||
|
}
|
||||||
$link = $link[1];
|
$link = $link[1];
|
||||||
echo $unpsAPI->delShort($apidb, $key, $shortdb, $link, $password);
|
echo $unpsAPI->delShort($apidb, $key, $shortdb, $link, $password);
|
||||||
break;
|
break;
|
||||||
case "replink":
|
case "replink":
|
||||||
if(empty($_POST['report-details'])) die("Something went wrong somewhere, but I can't find the reason for reporting this link");
|
if(empty($_POST['report-details'])) die("<div id=\"error\">Something went wrong somewhere, but I can't find the reason for reporting this link</div>");
|
||||||
$link = sanitize($_POST['link']);
|
$link = sanitize($_POST['link']);
|
||||||
$details = sanitize($_POST['report-details']);
|
$details = sanitize($_POST['report-details']);
|
||||||
echo $unpsAPI->reportLink($apidb, $key, $shortdb, $link, $details);
|
echo $unpsAPI->reportLink($apidb, $key, $shortdb, $link, $details);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("I don't know what you want to do... [-Check linkmod-]");
|
die("<div id=\"error\">I don't know what you want to do... [-Check linkmod-]</div>");
|
||||||
}
|
}
|
||||||
}else{ die("I can't do my job if I'm not given a link to work on..."); }
|
}else{ die("<div id=\"error\">I can't do my job if I'm not given a link to work on...</div>"); }
|
||||||
|
|
||||||
?>
|
?>
|
Loading…
Reference in New Issue
Block a user