This repository has been archived by the owner on Mar 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
139 lines (120 loc) · 5.58 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
session_start();
$appname = " Shortener";
// 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;
// This has been depreciated. Still here for backwards compatibility with existing links
if(!empty($_GET['l'])){
include('api/dbsettings.php');
$link = $shortdb->real_escape_string(strtolower(stripslashes(strip_tags($_GET['l']))));
$link = str_replace('/', '', $link);
$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");
exit(); // Stop script execution to save on resources
}
}
}
// New way to check for valid short links, two characters shorter than the if statement above
if(!empty($_GET)){
$key = key($_GET);
include('api/dbsettings.php');
$link = $shortdb->real_escape_string(strtolower(stripslashes(strip_tags($key))));
$link = str_replace('/', '', $link);
$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");
exit(); // Stop script execution to save on resources
}
}
}
?>
<!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">
<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"/>
<meta property="og:image" content="http://fox.gy/fCDIjceUvkk.png"/>
<link href="assets/bootstrap/css/bootstrap.min.css" rel="stylesheet" media="screen" />
<link href="assets/css/elements.css?<?php echo time(); ?>" rel="stylesheet" />
<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">
<?php include('navbar.php'); ?>
<div class="container" style="float:center;padding-bottom:7%;">
<p></p>
</div>
<div class="container">
<form class="form-shorten" id="form-shorten">
<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>
<input type="hidden" name="<?php echo $catchid; ?>" value="<?php echo $catchVal; ?>"/>
<input type="hidden" name="linkmod" value="shorten"/>
<button class="btn btn-block btn-primary" id="short-button" type="submit">Shorten</button>
</form>
<div id="message">
<div id="theLoader">
<div id="ajaxloader"></div><p id="loading">Loading...</p>
</div>
</div>
</div>
</div>
<div id="footer" style="position:absolute;width:100%;bottom:1px;">
<div class="container">
<p class="text-muted credit">
Copyright © 2014 Unified Programming Solutions - Version 4-2.8.6 - Fork me on <a href="https://github.com/alopexc0de/UnPS-Short">GitHub</a>
<a id="tos-link" href="terms.php">Terms Of Service</a>
</p>
</div>
</div>
<!-- Load the JS after the DOM so speed up load times -->
<script type="text/javascript" language="JavaScript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script type="text/javascript" language="JavaScript" src="assets/bootstrap/js/bootstrap.min.js"></script>
<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>
<script type="text/javascript" language="JavaScript">
// This is our AJAX - Thank you Wizzy <3
$("#form-shorten").submit(function(event){
$("#theLoader").fadeIn("fast");
event.preventDefault();
event.stopPropagation();
$.post("process.php?token=<?php echo $token; ?>", $(this).serialize(), function(data){
$("#message").hide().html(data+'<br /><div class="gab"></div>').fadeIn("fast");
$("#theLoader").hide();
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');
}
});
});
</script>
</body>
</html>