mirror of
https://github.com/c0de-archive/GAMA-Site.git
synced 2024-12-22 17:42:40 +00:00
Cleaned up source + commented all php + HTML4 clean
This commit is contained in:
parent
7d97d477a8
commit
4f2fd52fe4
234
short/index.php
234
short/index.php
@ -1,132 +1,140 @@
|
|||||||
<?php
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
require('dbsettings.php');
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
<head>
|
||||||
|
<title>URL Shortner</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
|
||||||
|
<meta name="description" content="Link shortener for UnProfessional Standards" />
|
||||||
|
<meta name="keywords" content="GAMA,UnPS,upstandards,unps-gama,gama-unps,unps,gama,davitech,davitodd" />
|
||||||
|
<meta name="author" content="David Todd" />
|
||||||
|
<link rel="shortcut icon" type="image/ico" href="http://unps-gama.info/favicon.ico" />
|
||||||
|
<link rel="shortcut icon" type="image/x-icon" href="http://unps-gama.info/favicon.ico" />
|
||||||
|
|
||||||
|
<style type="text/css">
|
||||||
|
#content{
|
||||||
|
text-align: center;
|
||||||
|
background: #000;
|
||||||
|
color: #090;
|
||||||
|
padding: 5px;
|
||||||
|
float: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
function input($input){
|
<?php
|
||||||
if ($input == null) die("No Input Provided, Aborting\r\n<br>");
|
require('dbsettings.php'); // Gotta connect to dem databases
|
||||||
|
|
||||||
|
function input($input){ // Cleans input to be used in mysql
|
||||||
|
if ($input == null) die("No Input Provided, Aborting\r\n<br />");
|
||||||
$input = mysql_real_escape_string($input);
|
$input = mysql_real_escape_string($input);
|
||||||
return $input;
|
return $input;
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepOutputText($text) {
|
function prepOutputText($text) { // Takes mysql string and makes it able to be used
|
||||||
if ($text == null) die("No Input Provided, Aborting\r\n<br>");
|
if ($text == null) die("No Input Provided, Aborting\r\n<br />");
|
||||||
$output = htmlentities(stripslashes($text),ENT_QUOTES);
|
$output = htmlentities(stripslashes($text),ENT_QUOTES);
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*function is_available($url, $timeout = 30) {
|
function getServerStatus($ip, $port = 80) { // Tests if host is online or not
|
||||||
$ch = curl_init(); // get cURL handle
|
return @fsockopen($ip, $port, $errnum, $errstr) == false ? 'offline' : 'online';
|
||||||
$opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
|
}
|
||||||
CURLOPT_URL => $url, // set URL
|
|
||||||
CURLOPT_NOBODY => true, // do a HEAD request only
|
|
||||||
CURLOPT_TIMEOUT => $timeout); // set timeout
|
|
||||||
curl_setopt_array($ch, $opts);
|
|
||||||
curl_exec($ch); // do it!
|
|
||||||
$retval = curl_getinfo($ch, CURLINFO_HTTP_CODE) == 200; // check if HTTP OK
|
|
||||||
curl_close($ch); // close handle
|
|
||||||
return $retval;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
function GetServerStatus($site, $port){
|
$submit; // Declare this since my logs are annoying me to no end x.x
|
||||||
$status = array("OFFLINE", "ONLINE");
|
|
||||||
$fp = @fsockopen($site, $port, $errno, $errstr, 2);
|
|
||||||
if (!$fp){
|
|
||||||
return $status[0];
|
|
||||||
} else{
|
|
||||||
return $status[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$submit;
|
if(isset($_GET['l'])) { // if there is a link...
|
||||||
|
$l = $_GET['l']; // Bring the link into a variable
|
||||||
if(isset($_GET['l'])) {
|
$l = input($l); // Clean said variable to be used in mysql
|
||||||
$l = $_GET['l'];
|
$sql = "SELECT id, link, shortlink FROM $tbl_name WHERE shortlink='$l'"; // Find the link in the table
|
||||||
$l = input($l);
|
$result = mysql_query($sql); // mysql stuff
|
||||||
$sql = "SELECT id, link, shortlink FROM $tbl_name WHERE shortlink='$l'";
|
$count = mysql_num_rows($result); // How many rows were found?
|
||||||
$result = mysql_query($sql);
|
if($count == 1){ // There should only be one row
|
||||||
$count = mysql_num_rows($result);
|
while ($row = mysql_fetch_assoc($result)){ // Start pulling data from the row
|
||||||
if($count == 1){
|
$id = $row['id']; // Lets get the id - not used, just a number used to identify the link or something, it's unique
|
||||||
while ($row = mysql_fetch_assoc($result)){ // Attempt to pull all data concerning that one user from table
|
$link = $row['link']; // This is the full link
|
||||||
$id = $row['id'];
|
$short = $row['shortlink']; // This is the short link - Should be a unique number
|
||||||
$link = $row['link'];
|
mysql_close(); // close the mysql connection
|
||||||
$short = $row['shortlink'];
|
echo "Redirecting you to your site, please wait..."; // never seen
|
||||||
mysql_close();
|
$link = prepOutputText($link); // make the link work
|
||||||
echo "Redirecting you to your site, please wait...";
|
header("location:".$link); // redirect right away
|
||||||
$link = prepOutputText($link);
|
|
||||||
header("location:".$link);
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
echo "Hmmm... It appears that your link doesn't exist in my database. Try again?";
|
echo "Hmmm... It appears that your link doesn't exist in my database. Try again?"; // not seen
|
||||||
header("location:http://unps.us/");
|
header("location:http://unps.us/"); // redirect right away
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<title>URL Shortner</title>
|
|
||||||
<link rel="shortcut icon" type="image/ico" href="http://unps-gama.info/favicon.ico" />
|
|
||||||
<link rel="shortcut icon" type="image/x-icon" href="http://unps-gama.info/favicon.ico" />
|
|
||||||
<body bgcolor="black" text="greem"><div align="center">
|
|
||||||
<img src="http://unps-gama.info/upload/Pictures/header.png"><br>
|
|
||||||
<h4>Welcome to the UnPS-GAMA link shortner</h4><hr>
|
|
||||||
<p>All you gotta do is put a link into the box and click submit</p>
|
|
||||||
<?php
|
|
||||||
if(!$_POST['submit']){
|
|
||||||
?>
|
|
||||||
<form id="short" action="index.php" method="POST" >
|
|
||||||
<p>Destination:<br><input name="dest" id="dest" class="dest" title="Insert URL here" placeholder="Insert URL here" value="" type="text" size="30" ></p>
|
|
||||||
<input type="submit" name="submit" value="submit">
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<?php
|
<body>
|
||||||
}
|
<div class="content" id="content">
|
||||||
if($_POST["submit"]){
|
<img src="http://unps-gama.info/upload/Pictures/header.png" alt="Header image" /><br />
|
||||||
if(isset($_POST['dest'])) {
|
<h4>Welcome to the UnPS-GAMA link shortner</h4><hr />
|
||||||
$dest=$_POST['dest'];
|
<p>All you gotta do is put a link into the box and click submit</p>
|
||||||
$dest = input($dest);
|
|
||||||
$sql = "SELECT id, link, shortlink FROM $tbl_name WHERE link='$dest'";
|
<?php
|
||||||
$result = mysql_query($sql);
|
if(!$_POST['submit']){ // If the submit button was not pressed show the form
|
||||||
$count = mysql_num_rows($result);
|
?>
|
||||||
if($count == 1){
|
|
||||||
while ($row = mysql_fetch_assoc($result)){ // Attempt to pull all data concerning that one user from table
|
<form id="short" title="short" action="index.php" method="POST" >
|
||||||
$id = $row['id'];
|
<p>Destination:<br />
|
||||||
$link = $row['link'];
|
<input name="dest" id="dest" class="dest" title="Insert URL here" placeholder="Insert URL here" value="" type="text" size="30" /></p>
|
||||||
$short = $row['shortlink'];
|
<input type="submit" name="submit" value="submit" />
|
||||||
echo "From what I can tell, this particular link was already shortened before.<br>Here's the link: <a href=\"http://unps.us/?l=$short\">http://unps.us/?l=$short</a>";
|
</form>
|
||||||
}
|
|
||||||
}else{
|
<?php
|
||||||
if (strpos($dest, 'http://') === false) {
|
}
|
||||||
if (strpos($dest, 'https://') === false){
|
if($_POST["submit"]){ // If submit button was pressed...
|
||||||
$ip = gethostbyname($dest);
|
if(isset($_POST['dest'])) { // If the text box has something in it
|
||||||
$dest = 'http://'.$dest;
|
$dest=$_POST['dest']; // Pull that into a variable
|
||||||
|
$dest = input($dest); // Clean the variable for mysql
|
||||||
|
$sql = "SELECT id, link, shortlink FROM $tbl_name WHERE link='$dest'"; // Check the table if the link was posted before
|
||||||
|
$result = mysql_query($sql); // mysql stuff
|
||||||
|
$count = mysql_num_rows($result); // Count the rows returned, if any
|
||||||
|
if($count == 1){ // If a row is returned, there should only be one
|
||||||
|
while ($row = mysql_fetch_assoc($result)){ // Pull all the data from the returned row
|
||||||
|
$id = $row['id']; // Lets get the id - not used, just a number used to identify the link or something, it's unique
|
||||||
|
$link = $row['link']; // This is the full link
|
||||||
|
$short = $row['shortlink']; // This is the short link - Should be a unique number
|
||||||
|
echo "From what I can tell, this particular link was already shortened before.<br>Here's the link: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a>"; // Return link that's already in table
|
||||||
|
}
|
||||||
|
}else{ // If no row is returned, it is assumed that the link isn't there
|
||||||
|
if (strpos(strtolower($dest), 'http://') === false) { // Simple test to see if http:// not part of the link
|
||||||
|
if (strpos(strtolower($dest), 'https://') === false){ // Simple test to see if https:// not part of the link passing the above check
|
||||||
|
$ip = gethostbyname($dest); // Get IP address of link
|
||||||
|
$dest = 'http://'.$dest; // Add http:// to link
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (strpos(strtolower($dest), 'http://') !== false) { // Simple test to see if http:// is part of the link
|
||||||
|
if (strpos(strtolower($dest), 'https://') !== false){ // Simple test to see if https:// is part of the link failing the above check
|
||||||
|
$dest = str_replace("https://", "", $dest); // If https:// exists, remove it
|
||||||
|
$ip = gethostbyname($dest); // Get IP address of link
|
||||||
|
$dest = 'https://'.$dest; // Re-add https:// to link
|
||||||
|
}
|
||||||
|
$dest = str_replace("http://", "", $dest); // if http:// exists, remove it
|
||||||
|
$ip = gethostbyname($dest); // Get IP address of link
|
||||||
|
$dest = 'http://'.$dest; // Re-add http:// to link
|
||||||
|
}
|
||||||
|
if(GetServerStatus($ip, 80) != "online") die("Hmmm it seems that your link is dead.\r\nPlease try again"); // Check to see if the host is alive
|
||||||
|
$short = substr(number_format(time() * rand(),0,'',''),0,10); // Create a random number 10 digits long
|
||||||
|
$short = base_convert($short, 10, 36); // Convert the 10 digit random number into Base36
|
||||||
|
$sql="INSERT INTO $tbl_name (link, shortlink) VALUES ('$dest', '$short')"; // Try to add the link and short link into table
|
||||||
|
$result=mysql_query($sql); // mysql stuff
|
||||||
|
if($result){ // If the link is added to the table
|
||||||
|
echo "It appears that I have succeded in making a short link.<br>You'll find it here: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a> ";
|
||||||
|
}else { // If the link is not added to the table
|
||||||
|
echo "There was a problem trying to register your link - Could be a database error";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if(!$dest){ // If the textbox was empty when loaded
|
||||||
if (strpos($dest, 'http://') !== false) {
|
echo '
|
||||||
if (strpos($dest, 'https://') !== false){
|
<p>Sorry, you are not able to shorten something without a url<br /></p>\r\n
|
||||||
$dest = str_replace("https://", "", $dest);
|
<a href="http://unps.us">Back to index</a><br />\r\n
|
||||||
$ip = gethostbyname($dest);
|
<a href="http://unps-gama.info">Home</a>
|
||||||
$dest = 'https://'.$dest;
|
';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$dest = str_replace("http://", "", $dest);
|
mysql_close(); // Close any mysql connections still open
|
||||||
$ip = gethostbyname($dest);
|
?>
|
||||||
$dest = 'http://'.$dest;
|
</div>
|
||||||
}
|
</body>
|
||||||
if(GetServerStatus($ip, 80) != "ONLINE") die("Hmmm it seems that your link is dead.\r\nPlease try again");
|
</html>
|
||||||
$short = substr(number_format(time() * rand(),0,'',''),0,10);
|
|
||||||
$short = base_convert($short, 10, 36);
|
|
||||||
$sql="INSERT INTO $tbl_name (link, shortlink) VALUES ('$dest', '$short')";
|
|
||||||
$result=mysql_query($sql);
|
|
||||||
if($result){
|
|
||||||
echo "It appears that I have succeded in making a short link.<br>You'll find it here: <a href=\"http://unps.us/?l=$short\" target=\"$short\">http://unps.us/?l=$short</a> ";
|
|
||||||
}else {
|
|
||||||
echo "There was a problem trying to register your link - Could be a database error";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!$dest){
|
|
||||||
echo '
|
|
||||||
Sorry, you are not able to shorten something without a url <br>
|
|
||||||
<a href="http://unps.us">Back to index</a><br>
|
|
||||||
<a href="http://unps-gama.info">Home</a>
|
|
||||||
';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mysql_close();
|
|
||||||
?>
|
|
||||||
|
Loading…
Reference in New Issue
Block a user