-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
213 lines (197 loc) · 4.82 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php
/*
* Copyright (c) 2013 nwxxeh
* http://github.com/nwxxeh/lrkr
*
*/
// CONFIGURATION - change this after importing links.sql into your database
$host = "localhost";
$username = "";
$password = "";
$database = "";
$website_name = "Generic Shortener";
$links_table = "links";
$domain = "example.com"; //change it!
$complaints = "[email protected]"; //complaints/abuse email
$path = "/l"; //change it to "/index.php?u=" if you don't have mod_rewrite enabled
mysql_connect($host, $username, $password) or die("ERROR");
mysql_select_db($database) or die("TERROR");
function alphaID($in, $to_num = false, $pad_up = false, $passKey = null)
{
$index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if ($passKey !== null) {
for ($n = 0; $n<strlen($index); $n++) {
$i[] = substr( $index,$n ,1);
}
$passhash = hash('sha256',$passKey);
$passhash = (strlen($passhash) < strlen($index))
? hash('sha512',$passKey)
: $passhash;
for ($n=0; $n < strlen($index); $n++) {
$p[] = substr($passhash, $n ,1);
}
array_multisort($p, SORT_DESC, $i);
$index = implode($i);
}
$base = strlen($index);
if ($to_num) {
// Digital number <<-- alphabet letter code
$in = strrev($in);
$out = 0;
$len = strlen($in) - 1;
for ($t = 0; $t <= $len; $t++) {
$bcpow = pow($base, $len - $t);
$out = $out + strpos($index, substr($in, $t, 1)) * $bcpow;
}
if (is_numeric($pad_up)) {
$pad_up--;
if ($pad_up > 0) {
$out -= pow($base, $pad_up);
}
}
$out = sprintf('%F', $out);
$out = substr($out, 0, strpos($out, '.'));
} else {
// Digital number -->> alphabet letter code
if (is_numeric($pad_up)) {
$pad_up--;
if ($pad_up > 0) {
$in += pow($base, $pad_up);
}
}
$out = "";
for ($t = floor(log($in, $base)); $t >= 0; $t--) {
$bcp = pow($base, $t);
$a = floor($in / $bcp) % $base;
$out = $out . substr($index, $a, 1);
$in = $in - ($a * $bcp);
}
$out = strrev($out); // reverse
}
return $out;
}
if (isset($_GET['u']))
{
$result = mysql_query("SELECT * FROM ".$links_table." WHERE id=".mysql_real_escape_string(alphaID($_GET['u'],true)));
if (($result) && (mysql_num_rows($result) == 1))
{
$row = mysql_fetch_assoc($result);
header("Location: ".$row['url']);
}
}
?>
<html>
<head>
<title><?php echo $website_name; ?></title>
<style type="text/css">
body{
font-size: 24px;
font-family: "Verdana";
color: #FFFFFF;
background: #CCCCCC url('./bg.png') repeat;
}
#logo {
width: 500px;
margin: auto;
font-size: 50px;
font-family: "Verdana";
color: #FFFFFF;
text-align: center;
text-shadow: 0px 2px 3px #555;
}
#main {
text-align: center;
background-color: #AAAAAA;
width: 500px;
padding-top: 20px;
margin: auto;
border: 1px solid #A0A0A0;
box-shadow: 0px 4px 4px #555;
border-radius: 2px;
}
#footer {
text-align: center;
width: 500px;
margin: auto;
font-size: 9px;
color: #FFFFFF;
margin-top: 7px;
}
a, a:visited {
color: #F0F0F0;
text-decoration: none;
}
a:hover {
color: #F000F0;
text-decoration: none;
}
input {
border: none;
}
input[type='text']
{
width: 150px;
font-size: 15px;
font-family: "Verdana";
height: 30px;
}
input[name='url']
{
width: 350px !important;
font-size: 20px !important;
font-family: "Verdana" !important;
height: 40px !important;
}
input[type='submit']
{
height: 40px;
font-size: 20px;
font-family: "Verdana";
color: #FFFFFF;
text-shadow: 0px 2px 3px #555;
background: #777;
}
</style>
</head>
<body>
<div id="logo">
<?php echo $website_name; ?>
</div>
<div id="main">
<?php
if (isset($_GET['f']))
{
switch ($_GET['f'])
{
case "add":
if (isset($_POST['url']))
{
if (filter_var(trim($_POST['url']), FILTER_VALIDATE_URL) == false)
{
echo "<b>Please enter valid URL!</b><br />";
} else {
$result = mysql_query("SELECT * FROM links WHERE url='".mysql_real_escape_string(trim($_POST['url']))."'");
if ((!$result) || (mysql_num_rows($result) == 0))
{
$result = mysql_query("INSERT INTO links (url) VALUES ('".mysql_real_escape_string(trim($_POST['url']))."')") or die("ERROR");
$id = mysql_insert_id();
} else {
$row = mysql_fetch_assoc($result);
$id = $row['id'];
}
echo "Shorter url: <input type='text' value='http://".$domain.$path.alphaID($id)."' /><br /><br />";
}
}
break;
}
}
?>
<form action="./fadd" method="POST">
<input type="text" name="url" /><input type="submit" name="sub" value="Short me!" />
</form>
</div>
<div id="footer">
Made by <a href="http://github.com/nwxxeh">nwxxeh</a> • <a href="mailto:<?php echo $complaints; ?>">Abuse/complaints</a>
</div>
</body>
</html>