2013-08-11 21:21:53 +00:00
|
|
|
<?php
|
2013-08-26 06:36:28 +00:00
|
|
|
session_start();
|
|
|
|
|
2013-09-26 23:41:42 +00:00
|
|
|
$appname = " Shortener";
|
|
|
|
|
2013-08-26 06:36:28 +00:00
|
|
|
// Generate a token on the fly. This should prevent POST spam attacks directly into process.php
|
|
|
|
$token = substr(number_format(time() * mt_rand(),0,'',''),0,10);
|
|
|
|
$token = base_convert($token, 10, 36);
|
|
|
|
$_SESSION['token'] = $token;
|
|
|
|
|
|
|
|
$catchid = substr(number_format(time() * mt_rand(),0,'',''),0,10);
|
|
|
|
$catchVal = hash('sha256', $catchid.mt_rand().time().substr(number_format(time() * mt_rand(),0,'',''),0,10));
|
|
|
|
$catchVal = base_convert($catchVal.$catchid, 10, 36);
|
|
|
|
$_SESSION['catch'] = $catchid.":".$catchVal;
|
2013-08-11 21:21:53 +00:00
|
|
|
|
2014-01-29 07:52:03 +00:00
|
|
|
// This has been depreciated. Still here for backwards compatibility with existing links
|
2013-08-11 21:21:53 +00:00
|
|
|
if(!empty($_GET['l'])){
|
|
|
|
include('api/dbsettings.php');
|
|
|
|
$link = $shortdb->real_escape_string(strtolower(stripslashes(strip_tags($_GET['l']))));
|
|
|
|
$sql = "SELECT * FROM `links` WHERE `shortlink` = '$link' LIMIT 1;";
|
|
|
|
if($result = $shortdb->query($sql)){
|
|
|
|
if($row = $result->fetch_assoc()){
|
|
|
|
$link = $row['link'];
|
|
|
|
header("location:$link");
|
2014-01-29 07:52:03 +00:00
|
|
|
exit(); // Stop script execution to save on resources
|
2013-08-11 21:21:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-01-29 07:31:27 +00:00
|
|
|
|
2014-01-29 07:52:03 +00:00
|
|
|
// New way to check for valid short links, two characters shorter than the if statement above
|
2014-01-29 07:31:27 +00:00
|
|
|
if(!empty($_GET)){
|
2014-01-29 07:41:05 +00:00
|
|
|
$key = key($_GET);
|
|
|
|
include('api/dbsettings.php');
|
|
|
|
$link = $shortdb->real_escape_string(strtolower(stripslashes(strip_tags($key))));
|
|
|
|
$sql = "SELECT * FROM `links` WHERE `shortlink` = '$link' LIMIT 1;";
|
|
|
|
if($result = $shortdb->query($sql)){
|
|
|
|
if($row = $result->fetch_assoc()){
|
|
|
|
$link = $row['link'];
|
|
|
|
header("location:$link");
|
2014-01-29 07:52:03 +00:00
|
|
|
exit(); // Stop script execution to save on resources
|
2014-01-29 07:31:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-08-11 21:21:53 +00:00
|
|
|
?>
|
2013-12-26 02:32:04 +00:00
|
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
|
|
<html xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns# fb: http://www.facebook.com/2008/fbml">
|
2013-08-11 21:21:53 +00:00
|
|
|
<head>
|
|
|
|
<title>UnPS Link Shortener</title>
|
|
|
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
|
|
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
|
|
|
|
<meta name="description" content="UnPS Link Shortener"/>
|
|
|
|
<meta name="keywords" content="UnPS, GAMA, Shorten, Link"/>
|
|
|
|
<meta name="author" content="David Todd"/>
|
2013-10-31 00:45:42 +00:00
|
|
|
<meta property="og:image" content="http://fox.gy/fCDIjceUvkk.png"/>
|
2013-08-11 21:21:53 +00:00
|
|
|
|
2014-03-02 02:39:18 +00:00
|
|
|
<link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen" />
|
2013-08-11 21:21:53 +00:00
|
|
|
<link href="assets/css/elements.css?<?php echo time(); ?>" rel="stylesheet" />
|
2013-12-11 20:20:30 +00:00
|
|
|
|
2013-08-11 21:21:53 +00:00
|
|
|
<link rel="shortcut icon" type="image/ico" href="favicon.ico"/>
|
|
|
|
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico"/>
|
|
|
|
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="wrap">
|
2013-09-26 23:41:42 +00:00
|
|
|
<?php include('navbar.php'); ?>
|
2013-08-11 21:21:53 +00:00
|
|
|
|
2014-02-19 16:23:56 +00:00
|
|
|
<div class="container" style="float:center;padding-bottom:7%;">
|
|
|
|
<p></p>
|
|
|
|
</div>
|
2013-08-11 21:21:53 +00:00
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
<form class="form-shorten" id="form-shorten">
|
2014-02-13 18:21:33 +00:00
|
|
|
|
2013-08-11 21:21:53 +00:00
|
|
|
<h2 class="form-shorten-heading">Please give me a link to shorten...</h2>
|
|
|
|
<input type="text" id="link" class="form-control" name="link" placeholder="http://" autofocus>
|
|
|
|
<div id="shorten-password">
|
2013-08-26 06:36:28 +00:00
|
|
|
<input type="text" id="pass" class="form-control" name="password" placeholder="Password">
|
2013-08-11 21:21:53 +00:00
|
|
|
</div>
|
2013-10-08 15:47:14 +00:00
|
|
|
|
2013-08-26 06:36:28 +00:00
|
|
|
<input type="hidden" name="<?php echo $catchid; ?>" value="<?php echo $catchVal; ?>"/>
|
2013-10-08 15:47:14 +00:00
|
|
|
<button class="btn btn-block btn-primary" id="short-button" type="submit">Shorten</button>
|
|
|
|
|
2013-08-11 21:21:53 +00:00
|
|
|
</form>
|
2014-02-13 18:21:33 +00:00
|
|
|
<div id="message">
|
2014-03-02 02:11:52 +00:00
|
|
|
<div id="theLoader">
|
|
|
|
<div id="ajaxloader"></div><p id="loading">Loading...</p>
|
2014-02-13 18:21:33 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2014-03-02 02:28:47 +00:00
|
|
|
</div>
|
2013-08-11 21:21:53 +00:00
|
|
|
</div>
|
|
|
|
|
2014-02-19 14:41:40 +00:00
|
|
|
<div id="footer" style="position:absolute;width:100%;bottom:1%;">
|
2013-08-11 21:21:53 +00:00
|
|
|
<div class="container">
|
2014-02-19 14:41:40 +00:00
|
|
|
<p class="text-muted credit" style="padding-bottom:2.3%;">
|
|
|
|
Copyright © 2014 Unified Programming Solutions - Fork me on <a href="https://github.com/alopexc0de/UnPS-Short">GitHub</a>
|
|
|
|
<a id="tos-link" href="terms.php">Terms Of Service</a>
|
2013-08-11 21:21:53 +00:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<!-- Load the JS after the DOM so speed up load times -->
|
2013-10-08 15:47:14 +00:00
|
|
|
<script type="text/javascript" language="JavaScript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
|
2014-03-02 02:39:18 +00:00
|
|
|
<script type="text/javascript" language="JavaScript" src="assets/bootstrap/js/bootstrap.min.js"></script>
|
2014-03-02 02:47:27 +00:00
|
|
|
|
|
|
|
<script type="text/javascript" language="JavaScript">
|
|
|
|
jQuery(document).ready(function(){
|
|
|
|
$('#link').focus();
|
|
|
|
$('#error').fadeIn("fast");
|
|
|
|
});
|
|
|
|
|
|
|
|
function copyToClipboard(text){
|
|
|
|
window.prompt ("Copy to clipboard: Ctrl+C, Enter (when closed I will open your link in a new tab)", text);
|
|
|
|
}
|
|
|
|
</script>
|
2013-12-11 20:20:30 +00:00
|
|
|
|
2013-10-08 15:47:14 +00:00
|
|
|
<script type="text/javascript" language="JavaScript">
|
2013-08-11 21:21:53 +00:00
|
|
|
// This is our AJAX - Thank you Wizzy <3
|
|
|
|
$("#form-shorten").submit(function(event){
|
2014-02-16 23:00:42 +00:00
|
|
|
$("#theLoader").fadeIn("fast");
|
2013-08-11 21:21:53 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2013-08-26 06:36:28 +00:00
|
|
|
$.post("process.php?token=<?php echo $token; ?>", $(this).serialize(), function(data){
|
2014-02-13 18:21:33 +00:00
|
|
|
$("#message").hide().html(data+'<br /><div class="gab"></div>').fadeIn("fast");
|
2014-02-13 18:51:01 +00:00
|
|
|
$("#theLoader").hide();
|
2013-10-08 15:47:14 +00:00
|
|
|
if($('#error').length){
|
|
|
|
$('#short-button').removeClass('btn-primary');
|
|
|
|
$('#short-button').removeClass('btn-success');
|
|
|
|
$('#short-button').addClass('btn-danger');
|
|
|
|
}else if($('#success').length){
|
|
|
|
$('#short-button').removeClass('btn-primary');
|
|
|
|
$('#short-button').removeClass('btn-danger');
|
|
|
|
$('#short-button').addClass('btn-success');
|
|
|
|
}
|
2013-08-11 21:21:53 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</body>
|
|
|
|
</html>
|