This repository has been archived by the owner on Jun 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.php
306 lines (249 loc) · 8.36 KB
/
make.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
<?php
require_once ("session.php");
$banned_ip = CheckBannedIP($_SERVER['REMOTE_ADDR']);
if ($banned_ip == 1)
{
ShowBlankPage();
exit;
}
if($session->logged_in)
{
$username = $session->username;
$ncane_id = $_POST['ncane_id'];
$ncane_desc = $_POST['ncane_desc'];
$optID = $_POST['optID'];
}
else
{
$username = 'free_user';
$ncane_desc = 'Free';
}
$m_adult = trim($_POST['m_adult']);
$strAdult = 0;
if ($m_adult == "checked")
{
$strAdult = 1;
}
$strURL = $_POST['strURL'];
if (trim($strURL) == "")
$strURL = $_GET['strURL'];
$strURL = ltrim($strURL, "/");
$strURL = rtrim($strURL, "/");
$strURL = trim($strURL);
$strURL = preg_replace("/\s\s+/", " ", $strURL);// multiple spaces
$strURL = preg_replace("/ /", "%20", $strURL);// spaces to %20
$tab = "\t\t\t\t\t\t\t";
if (strlen($strURL) > 512)
{
$strURL = substr(trim($strURL), 0, 2000);
echo "<b>IMPORTANT NOTE</b>: Your URL has been truncated to the first 2000 characters. It may not function correctly.<br><br>";
}// checks for URLs over 2000 characters long
if (trim($strURL) == "")
{
header("Location: index.php");
}
if (strtolower(substr($strURL, 0, 7)) != "http://")
{
if (strtolower(substr($strURL, 0, 8)) != "https://")
{
$strURL = "http://" . $strURL;
}
}
// prepends "http://" to the string ... does not validate existing string, merely attaches if it can't be found at the beginning.
// Check that the link being added does not contain the URLs from any of the group's sites:
// ncane.com, ncane.net, ncane.co.za, kleinurl.com, kleinurl.net,
// kleinurl.co.za, minurl.net, minurl.co.za, adres.co.za or derivations
$sr_flag = CheckBannedDomains($strURL);
if ($sr_flag == 1)
{
// Self-Referencing flag raised to avoid people creating infinite loops
require_once ("header.php");
echo "<br>";
echo "<font face=\"sans-serif\" size=\"2\">\n\n";
echo "<font color=\"#FF0000\"><b>FORBIDDEN URL WARNING</b></font>\n\n";
echo "<br><br>You may not create a link using the URL you provided. This behaviour is by design.\n\n";
require_once ("footer.php");
$strURL = "";
exit;
}
if (strlen(trim($strURL)) == 0)
{
$URL = "/";
header("Location: $URL");
}
else
{
require_once ("header.php"); ?>
<br>
<font face="sans-serif" size="2">
<?php
if (preg_match('/^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}' .
'((:[0-9]{1,5})?\/.*)?$/i', $strURL))
{
// Load the random strings from the database to compare against the random string.
DBConnect();
$check_id = mysql_query("SELECT ncane_id FROM ncane_tbl") or die(mysql_error());
$x = 0;
while ($row = mysql_fetch_assoc($check_id))
{
// Add all elements of SQL to array
$check_array[$x] = trim($row['ncane_id']);
$x++;
}
//DBCloseConnection();
unset($x);
if ($optID == "own")
{
$randomString = $ncane_id;
}
else
{
$i = 1;
$randomString = RandomString($i);
}
// DEBUG $randomString = "8j";
$result = CheckArray($randomString, $check_array);
while ($result != 0)
{
// Check if logged in, otherwise do normal random generation
if($session->logged_in)
{
if ($optID == "own")
{
echo "You have selected a short URL that already occurs in the database. Please try again.";
echo "<input type=\"hidden\" name=\"strURL\" value=\"" . $strURL . "\">";
echo "<br><br>Target URL: <b>" . $strURL . "</b>";
echo "<br><br>";
echo "<input type=\"hidden\" name=\"optID\" value=\"own\"> Choose own link (max 15-char): http://ncane.com/<input type=\"text\" size=\"10\" maxlength=\"15\" name=\"ncane_id\">";
echo "<br><br>";
echo "<input type=\"hidden\" name=\"ncane_desc\" value=\"" . $ncane_desc . "\">";
echo "Description:<br>";
echo "<b>" . $ncane_desc . "</b>";
echo "<input type=\"hidden\" name=\"username\" value=\"" . $username . "\">";
echo "<br><br>";
echo "<input type=\"submit\" value=\"Ncane! (Create URL)\">";
echo "<input type=\"reset\" value=\"Sula! (Clear)\">";
echo "<p><hr></p>";
}
else
{
for ($i = 1; $i < 9; $i++)
{
$randomString = RandomString($i);
//echo "Getting new Random String!";
$result = CheckArray($randomString, $check_array);
if ($result == 0)
break;
}
}
}
else
{
for ($i = 1; $i < 9; $i++)
{
$randomString = RandomString($i);
//echo "Getting new Random String!";
$result = CheckArray($randomString, $check_array);
if ($result == 0)
break;
}
}
}
if ($result == 0)
{
// Continue Processing
// ----
// Check that the URL does not already exist in the database.
DBConnect();
$check_url = mysql_query("SELECT ncane_id, ncane_url FROM ncane_tbl WHERE ncane_url = '" .
$strURL . "'") or die(mysql_error());
while ($row = mysql_fetch_assoc($check_url))
{
$result_id = $row['ncane_id'];
$result_url = $row['ncane_url'];
}
//DBCloseConnection();
if ($result_url == $strURL)
{
// echo $tab . "THIS SITE IS IN A BETA TESTING PHASE!<br><br>\n";
echo $tab . "You have requested a Ncane URL for the following address:<br><br>" .
$strURL . "<br><br><hr><br>\n";
echo $tab . "The URL was already added to the Ncane database. Please bookmark the following link:<br><br>\n";
$newString = "http://ncane.com/" . $result_id;
echo $tab . "<a href=\"" . $newString . "\" target=\"_blank\">" . $newString . "</a>\n";
echo $tab . "<br><br><i>This link is " . strlen($newString) . " characters, or " .
number_format(strlen($newString) / strlen($strURL) * 100, 2, ".", "") .
"% of the size of your original link (" . strlen($strURL) . " characters)</i>\n";
echo $tab . "<br><br>";
echo URLCounter();
$form_writer = WriteMailer($result_id);
echo $form_writer;
}
else
{
$isValidURL = CheckURLExists($strURL);
if ($isValidURL == true)
{
// Insert this row into the database:
$strIP = $_SERVER['REMOTE_ADDR'];
DBConnectInsert();
// ip address as string
// $sql = "INSERT INTO ncane_tbl VALUES ('" . $randomString . "', '" . $username . "', '" . $strURL .
// "', '" . $ncane_desc . "', 0, '" . $strIP . "', NOW(), NOW(), 0, " . $strAdult . ")";
// ip address as int
$sql = "INSERT INTO ncane_tbl (ncane_id, user_name, ncane_url, ncane_desc, ncane_hit, ncane_ip, ncane_date,
ncane_lastdate, ncane_exp, ncane_adult) VALUES ('" . $randomString . "', '" . $username . "', '" .
$strURL . "', '" . $ncane_desc . "', 0, INET_ATON('" . $strIP . "'), NOW(), NOW(), 0, " . $strAdult . ")";
mysql_query($sql) or die(mysql_error());
//DBCloseConnectionInsert();
// echo $tab . "THIS SITE IS IN A BETA TESTING PHASE!<br><br>\n";
echo $tab . "You have requested a Ncane URL for the following address:<br><br>" .
$strURL . "<br><br><hr><br>\n";
echo $tab . "Add this link to your bookmarks by right-clicking on the link below.<br><br>\n";
$newString = "http://ncane.com/" . $randomString;
echo $tab . "<a href=\"" . $newString . "\" target=\"_blank\">" . $newString .
"</a>\n";
echo $tab . "<br><br><i>This link is " . strlen($newString) . " characters, or " .
number_format(strlen($newString) / strlen($strURL) * 100, 2, ".", "") .
"% of the size of your original link (" . strlen($strURL) . " characters)</i>\n";
echo $tab . "<br><br>\n";
/* start temp code
{
mail("<[email protected]>", "[ncane.com] New link created", $sql,
"From: <[email protected]>\r\n" . "Reply-To: <[email protected]>");
}
finish temp code */
echo URLCounter();
$form_writer = WriteMailer($randomString);
echo $form_writer;
}
else
{
echo $strURL . ' does not exist. Please try again.<br><br>';
}
}
}
else
{
echo "An unlikely event has occurred! Error # x030.<br><br>Please mail us at <a href=\"mailto:[email protected]\"><i>[email protected]</i></a> to let us know, or click <a href=\"/\">here</a> to try again.";
}
}
else
{
echo $strURL . ' is <b>not</b> a valid URL. Please try again.<br><br>';
}
if($session->logged_in)
{
echo "<table><tr><td><p><hr></p>";
echo "[<a href=\"userinfo.php\">My Account</a>] ";
echo "[<a href=\"useredit.php\">Edit Account</a>] ";
echo "[<a href=\"userlinks.php\">My URLs</a>] ";
if($session->isAdmin())
{
echo "[<a href=\"admin.php\">Admin Centre</a>] ";
}
echo "[<a href=\"process.php\">Logout</a>]";
echo "</td></tr></table>";
}
require_once ("footer.php");
} ?>