-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
196 lines (159 loc) · 7.35 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
<?php
include "config.php";
date_default_timezone_set($setting_time_zone);
if (($setting_admin_pass == "CHANGEME") || ($setting_admin_key == "CHANGEME") || ($crypt_iv == "CHANGEME")){
die("<div class=post><h1>A FATAL MISTAKE HAS BEEN MADE!</h1>You need to go inside <b>config.php</b> and change one or more of the following settings to something valid. They currently are set to <b>CHANGEME</b>.<br><ul><li>setting_admin_pass</li><li>setting_admin_key</li><li>crypt_iv</li></ul></div>");
}
echo "<form action='admin.php' method='post'>
<input required type='password' name='adminpass' maxlength='32'><input type='submit' value='Admin'>
</form>";
if (isset($_POST['mode'])){
$mode = $_POST['mode'];
} else {
$mode = 'view';
}
## Robot test
$math1 = rand(1,99);
$math2 = rand(1,25);
$mtype = rand(0,1);
if ($mtype == 0) {
$mtype = '+';
} elseif ($mtype == 1) {
$mtype = '-';
}
# Posting mode
if ($mode == 'post'){
$text = $_POST['text'];
$name = $_POST['name'];
$text = strip_tags($text);
# Check if banned
$your_ip = $_SERVER['REMOTE_ADDR'];
$user_json = file_get_contents("users.json");
$user_list = json_decode($user_json, true);
$user_id_list = array_column($user_list['users'], 'id');
$user_id = openssl_encrypt($your_ip, $crypt_cipher, $setting_admin_key, $crypt_options, $crypt_iv);
# Blacklist
if (in_array($user_id, $user_id_list)){
$user_place = array_search($user_id, $user_id_list);
if ($user_list['users'][$user_place]['blacklist'] == "1"){
die("<div class='post'><h1>You're banned!</h1>You're not allowed to create new posts!</div>");
}
}
## SPAM BLOCKERS
if (preg_match('/^(.)\1*$/u ', $text)) {
die ("<div class='post'><h1>Spam detected!</h1>Try posting something that's not spam.</div>");
}
$post_length = strlen($text);
if ($post_length < $setting_minchar) {
die ("<div class='post'><h1>Post too short!</h1>You wrote <b>$post_length characters</b>. The minimum is <b>$setting_minchar characters</b>.</div>");
}
if ($post_length > $setting_maxchar) {
die ("<div class='post'><h1>Post too long!</h1>You wrote <b>$post_length characters</b>. The minimum is <b>$setting_maxchar characters</b>.</div>");
}
if (substr_count($text, ' ') === strlen($text)) {
die ("<div class='post'><h1>Spam detected!</h1>Post contained only spaces!</div>");
}
# Spam timer
$spam_time = time() + $setting_post_wait;
if (in_array($user_id, $user_id_list)){
$user_place = array_search($user_id, $user_id_list);
$user_wait = $user_list['users'][$user_place]['lastpost'] - time();
if ($user_list['users'][$user_place]['lastpost'] > time()){
die("<div class='post'><h1>Spam timer</h1>Wait $user_wait seconds before posting!</div>");
}
}
## See if user is verified
if ($setting_usercodes == 1){
if (isset($_POST['trip']) && $_POST['trip'] == 1){
$name_verify = substr(sha1($user_id), 0, 8);
}
}
if (!isset($name_verify)){
$name_verify = 0;
}
## Check if math is correct
$math1 = $_POST['math1'];
$math2 = $_POST['math2'];
$mtype = $_POST['mtype'];
$manswer = $_POST['manswer'];
if ($mtype == '+') {
$answer = $math1 + $math2;
} elseif ($mtype == '-') {
$answer = $math1 - $math2;
}
if ($manswer <> $answer) {
$spam_time = time() + $setting_wrong_penalty;
}
## Update the user's next permitted posting time
if (in_array($user_id, $user_id_list)){
$user_list['users'][$user_place]['lastpost'] = $spam_time;
$new_user_json = json_encode($user_list, true);
file_put_contents("users.json", $new_user_json);
} else {
$new_user = array("id" => "$user_id", "lastpost" => $spam_time, "blacklist" => 0);
array_push($user_list['users'], $new_user);
$new_user_json = json_encode($user_list, true);
file_put_contents("users.json", $new_user_json);
}
if ($manswer <> $answer) {
die("<div class='post'><h1>Spam timer</h1><div class='post'>Your answer to the math question was incorrect!<br>Because of this... you must wait $setting_wrong_penalty seconds.</h1></div>");
}
if(isset($_POST['name']) && isset($_POST['text'])) {
$board_json = file_get_contents("board.json");
$board_list = json_decode($board_json, true);
$board_list['id'] = $board_list['id'] + 1;
$new_post = array("id" => $board_list['id'], "user" => "$user_id", "name" => "$name", "verified" => "$name_verify", "time" => time(), "text" => "$text");
array_push($board_list['posts'], $new_post);
$new_board_json = json_encode($board_list, true);
file_put_contents("board.json", $new_board_json);
echo "<div class='post'><h1>Post completed!</h1><a href='index.php'>Back</a></div>";
}
}
If ($mode == 'view'){
## DISPLAY POSTS MODE
print "<title>$setting_board_name</title><center><div class=main>";
$mode = 0;
$your_ip = $_SERVER['REMOTE_ADDR'];
print "$setting_board_title";
print "<center><h2>Compose a post</h2> <form action='index.php' method='post'>
<table class='newpost'>
<tr><td>Name</td><td><input required type='text' name='name' maxlength='64' value='Anonymous'><input type='submit' value='Submit'><br><input type='checkbox' name='trip' value='1'>Show tripcode?</td></tr>
<tr><td>Text</td><td><textarea rows='4' cols='16' name='text' maxlength='$setting_maxchar' required placeholder='Type your text here...'></textarea></td></tr>";
print "<tr><td>Math</td><td><input required type='hidden' name='math1' maxlength='32' value='$math1'><input required type='hidden' name='math2' maxlength='32' value='$math2'><input required type='hidden' name='mtype' maxlength='32' value='$mtype'><input required type='hidden' name='mode' maxlength='4' value='post'>";
print "$math1 $mtype $math2" . ' <input type="text" required name="manswer" maxlength=32 placeholder="Answer"></td></form></table></center><hr>' . "\n \n";
$board_json = file_get_contents("board.json");
$board_posts = json_decode($board_json, true);
if ($setting_board_flow == '1'){
$board_posts['posts'] = array_reverse($board_posts['posts']);
}
$total_posts = count($board_posts['posts']);
# Post amount limiter
$post_limit = 10;
if(isset($_GET['m'])) {
$post_limit = $_GET['m'];
if ($post_limit > 500) {
die("<div class='post'><h1>Not cool!</h1><div class='post'>You aren't able to see more than 500 posts at once!</div>");
}
}
## PRINT EACH POST
$display_posts = array_slice($board_posts['posts'], 0, $post_limit);
foreach ($display_posts as $display_post){
$post_date = date("d M y - H:i:s T",$display_post['time']);
$post_id = $display_post['id'];
$post_name = $display_post['name'];
$post_text = $display_post['text'];
$post_verify = $display_post['verified'];
if($post_verify == "0"){
$name_splash = '';
} else {
$verify_bg_color = substr($post_verify, 0, 6);
$name_splash = "<span class=poster style='background-color:#$verify_bg_color;'>$post_verify</span>";
}
echo "<div class='post'><span class=info>#$post_id <b>$post_name</b> $name_splash : <i>$post_date</i></span><br>$post_text</div> \n \n";
}
print "<div class=$setting_static_div>$total_posts posts total<br><b>Amount of posts to display</b><br><a href='index.php'>10</a> - <a href='index.php?m=25'>25</a> - <a href='index.php?m=50'>50</a> - <a href='index.php?m=100'>100</a> - <a href='index.php?m=250'>250</a> - <a href='index.php?m=500'>500</a></div>";
print "</div><footer>$setting_footer_content";
}
?>
</footer>
</html>