forked from MitsubaBBS/Mitsuba
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimgboard.php
executable file
·313 lines (300 loc) · 9.27 KB
/
imgboard.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
307
308
309
310
311
312
313
<?php
if (!file_exists("./config.php"))
{
header("Location: ./install.php");
}
include("config.php");
include("inc/common.php");
include("inc/common.caching.php");
include("inc/common.posting.php");
include("inc/common.plugins.php");
if (isset($_POST['mode']))
{
$conn = new mysqli($db_host, $db_username, $db_password, $db_database);
loadPlugins($conn);
$mode = $_POST['mode'];
switch($mode)
{
case "regist":
$filename = null;
if (empty($_POST['board']))
{
?>
<html>
<head>
<title>Error</title>
</head>
<body>
<?php
echo "<center><h1>No board selected!</h1></center></body></html>";
exit;
}
$board = $_POST['board'];
banMessage($conn, $board);
if (!isBoard($conn, $_POST['board']))
{
echo "<h1>This board does not exist!</h1></body></html>"; exit;
}
?>
<html>
<head>
<title>Updating index</title>
</head>
<body>
<center><h1>Updating Index...</h1></center>
<?php
$md5 = "";
$bdata = getBoardData($conn, $_POST['board']);
if ($bdata['hidden'] == 1)
{
echo "<h1>This board does not exist!</h1></body></html>"; exit;
}
if (strlen($_POST['com']) > $bdata['maxchars'])
{
echo "<h1>Comment too long (".strlen($_POST['com'])."/".$bdata['maxchars'].")!</h1></body></html>"; exit;
}
if ((!empty($_POST['embed'])) && (!empty($_FILES['upfile']['tmp_name'])))
{
echo "<center><h1>Choose one: image or embed! ;_;</h1></center></body></html>";
exit;
}
if (isWhitelisted($conn, $_SERVER['REMOTE_ADDR']) != 2)
{
$lastdate = $conn->query("SELECT date FROM posts WHERE ip='".$_SERVER['REMOTE_ADDR']."' AND board='".$_POST['board']."' ORDER BY date DESC LIMIT 0, 1");
if ($lastdate->num_rows == 1)
{
$pdate = $lastdate->fetch_assoc();
$pdate = $pdate['date'];
if (($pdate + $bdata['time_between_posts']) > time())
{
echo "<center><h1>You'll have to wait more before posting a new post! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></center></body></html>";
exit;
}
}
$lastdate = $conn->query("SELECT date FROM posts WHERE ip='".$_SERVER['REMOTE_ADDR']."' AND resto=0 AND board='".$_POST['board']."' ORDER BY date DESC LIMIT 0, 1");
if ($lastdate->num_rows == 1)
{
$pdate = $lastdate->fetch_assoc();
$pdate = $pdate['date'];
if (($pdate + $bdata['time_between_threads']) > time())
{
echo "<center><h1>You'll have to wait more before posting a new thread! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></center></body></html>";
exit;
}
}
}
if (!empty($_POST['embed']))
{
if ($bdata['embeds']==0)
{
echo "<center><h1>Embed not supported! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></center></body></html>";
exit;
}
$embed_table = array();
$result = $conn->query("SELECT * FROM embeds;");
while ($row = $result->fetch_assoc())
{
$embed_table[] = $row;
}
if (isEmbed($_POST['embed'], $embed_table))
{
$filename = "embed:".$_POST['embed'];
} else {
echo "<center><h1>Embed not supported! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></center></body></html>";
exit;
}
} else {
if ((empty($_FILES['upfile']['tmp_name'])) && (!empty($_FILES['upfile']['name'])))
{
echo "<h1>File size too big! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></body></html>";
exit;
}
if (!empty($_FILES['upfile']['tmp_name']))
{
$target_path = "./".$board."/src/";
$fileid = time() . mt_rand(10000000, 999999999);
$ext = pathinfo($_FILES['upfile']['name'], PATHINFO_EXTENSION);
$filename = $fileid . "." . $ext;
$target_path .= $filename;
$file_size = $_FILES['upfile']['size'];
if ($file_size > $bdata['filesize'])
{
echo "<h1>File size too big! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></body></html>";
exit;
}
if (!isImage($_FILES['upfile']['tmp_name']))
{
echo "<h1>File is not an image! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></body></html>";
exit;
}
$md5 = md5_file($_FILES['upfile']['tmp_name']);
if ($bdata['nodup'] == 1)
{
$isit = $conn->query("SELECT * FROM posts WHERE filehash='".$md5."' AND board='".$_POST['board']."'");
if ($isit->num_rows >= 1)
{
echo "<h1>Duplicate file detected! [<a href='./".$_POST['board']."/'>RETURN</a>]</h1></body></html>";
exit;
}
}
if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
echo "The file ".basename( $_FILES['upfile']['name'])." has been uploaded";
} else {
echo "There was an error uploading the file, please try again!";
$filename = "";
}
}
}
$name = "Anonymous";
if ((!empty($_POST['name'])) && ($bdata['noname'] == 0)) { $name = $_POST['name']; }
$resto = 0;
if (isset($_POST['resto'])) { $resto = $_POST['resto']; }
$password = "";
if (empty($_POST['pwd']))
{
if (isset($_COOKIE['password']))
{
$password = $_COOKIE['password'];
} else {
$password = randomPassword();
}
} else {
$password = $_POST['pwd'];
}
$thumb_w = 0;
$thumb_h = 0;
if (substr($filename, 0, 6) != "embed:")
{
if (!empty($_FILES['upfile']['tmp_name']))
{
if ($resto != 0)
{
$returned = thumb($board, $fileid.".".$ext, 125);
if ((empty($returned['width'])) || (empty($returned['height'])))
{
echo "<h1>Could not create thumbnail!</h1></body></html>"; exit;
}
$thumb_w = $returned['width'];
$thumb_h = $returned['height'];
} else {
$returned = thumb($board, $fileid.".".$ext);
if ((empty($returned['width'])) || (empty($returned['height'])))
{
echo "<h1>Could not create thumbnail!</h1></body></html>"; exit;
}
$thumb_w = $returned['width'];
$thumb_h = $returned['height'];
}
}
}
$spoiler = 0;
if ((!empty($_POST['spoiler'])) && ($_POST['spoiler'] == 1) && ($bdata['spoilers'] == 1) && (substr($filename, 0, 6) != "embed:"))
{
$spoiler = 1;
}
setcookie("password", $password, time() + 86400*256);
$embed = 0;
if (substr($filename, 0, 6) != "embed:")
{
$fname = $_FILES['upfile']['name'];
$filename = "";
if (empty($_FILES['upfile']['tmp_name']))
{
$fname = "";
} else {
$filename = $fileid.".".$ext;
}
} else {
$embed = 1;
$fname = "embed";
}
$is = addPost($conn, $_POST['board'], $name, $_POST['email'], $_POST['sub'], $_POST['com'], $password, $filename, $fname, $resto, $md5, $thumb_w, $thumb_h, $spoiler, $embed);
if ($is == -16)
{
echo "<h1>This board does not exist!</h1></body></html>"; exit;
}
break;
case "usrform":
if (!empty($_POST['delete']))
{
$onlyimgdel = 0;
$password = "";
if (empty($_POST['board']))
{
echo "<h1>No board selected!</h1></body></html>";
exit;
}
$board = $_POST['board'];
banMessage($conn, $board);
if (isset($_COOKIE['password'])) { $password = $_COOKIE['password']; }
if ((isset($_POST['onlyimgdel']) && ($_POST['onlyimgdel'] == "on"))) { $onlyimgdel = 1; }
if (!empty($_POST['pwd'])) { $password = $_POST['pwd']; }
foreach ($_POST as $key => $value)
{
if ($value == "delete")
{
$done = deletePost($conn, $_POST['board'], $key, $password, $onlyimgdel);
if ($done == -1) {
echo "Bad password for post ".$key.".<br />";
} elseif ($done == -2) {
echo "Post ".$key." not found.<br />";
} elseif ($done == -3) {
echo "Post ".$key." has no image.<br />";
} elseif ($done == -4) {
echo "You'll have to wait more before deleting post ".$key.".<br />";
} elseif ($done == 1) {
echo "Deleted image from post ".$key.".<br />";
} elseif ($done == 2) {
echo "Deleted post ".$key.".<br />";
}
if ($done == -16)
{
echo "<h1>This board does not exist!</h1></body></html>"; exit;
}
}
}
echo '<meta http-equiv="refresh" content="2;URL='."'./".$_POST['board']."/index.html'".'">';
} elseif (!empty($_POST['report'])) {
if (empty($_POST['board']))
{
echo "<h1>No board selected!</h1></body></html>";
exit;
}
$board = $_POST['board'];
banMessage($conn, $board);
foreach ($_POST as $key => $value)
{
if ($value == "delete")
{
$done = reportPost($conn, $_POST['board'], $key, $_POST['reason']);
if ($done == 1)
{
echo "Post ".$key." reported.<br />";
}
}
}
echo '<meta http-equiv="refresh" content="2;URL='."'./".$_POST['board']."/index.html'".'">';
}
break;
case "usrapp":
//$_POST['email']; $_POST['msg'];
if (!empty($_POST['msg']))
{
$msg = $conn->real_escape_string(htmlspecialchars($_POST['msg']));
$email = $conn->real_escape_string(htmlspecialchars($_POST['email']));
$ip = $_SERVER['REMOTE_ADDR'];
$ban = isBanned($conn, $ip, $_POST['board']);
$ban_id = $ban['id'];
$range = 0;
if (!empty($bandata['start_ip'])) { $range = 1; }
$conn->query("INSERT INTO appeals (created, ban_id, ip, msg, email, rangeban) VALUES (".time().", ".$ban_id.", '".$ip."', '".$msg."', '".$email."', ".$range.")");
echo "Your appeal has been sent. Keep calm and wait for reply";
}
break;
}
mysqli_close($conn);
} else {
}
?>
</body>
</html>