Browse Source

Robocheck: The human operator is the key to unlock VIRTUAL WORLD

Robocheck uses advanced coding & algorithms (and ImageMagick and a word list)
to generate pictures with text. These pictures are useful in combatting spam,
because robots get nervous regarding pictures
yumi 1 year ago
parent
commit
a582d4171f
11 changed files with 134 additions and 57 deletions
  1. 8
    0
      .gitignore
  2. 0
    1
      B4U/announce.txt
  3. 19
    19
      B4U/css/base.css
  4. 1
    1
      B4U/index.php
  5. 6
    18
      B4U/info.php
  6. 27
    16
      B4U/max.php
  7. 0
    0
      B4U/robocheck/.keep
  8. 2
    0
      includes/config.template.php
  9. 69
    0
      includes/mod.php
  10. 2
    2
      includes/render.php
  11. 0
    0
      tmp/robocheck-answers/.keep

+ 8
- 0
.gitignore View File

@@ -1 +1,9 @@
1 1
 includes/config.php
2
+
3
+B4U/robocheck/*
4
+!B4U/robocheck/.keep
5
+
6
+tmp/*
7
+!tmp/robocheck-answers
8
+tmp/robocheck-answers/*
9
+!tmp/robocheck-answers/.keep

+ 0
- 1
B4U/announce.txt View File

@@ -1 +0,0 @@
1
-There are no announements

+ 19
- 19
B4U/css/base.css View File

@@ -62,30 +62,19 @@ body {
62 62
 	justify-content: center;
63 63
 }
64 64
 
65
-.collection > a,
66
-.minorbox,
67
-.reply .buttons > * {
65
+.hoverbox {
68 66
 	display: block;
69
-	margin-bottom: 15px;
70 67
 	padding-left: 5px;
71 68
 	padding-right: 5px;
72 69
 	transition: box-shadow 0.5s, color 1s;
73 70
 	border: 1px solid;
74 71
 	cursor: pointer;
75 72
 }
76
-.collection > a:hover,
77
-.minorbox:hover,
78
-.reply .buttons > *:hover {
73
+.hoverbox:hover {
79 74
 	box-shadow: -3px 3px 10px;
80 75
 }
81
-.collection a,
82
-.minorbox,
83
-.choicebox a,
84
-.timeline .content a,
85
-.reply .buttons > a,
86
-.leftnav,
87
-.rightnav,
88
-footer .minorbox a {
76
+.hoverbox a,
77
+a.hoverbox {
89 78
 	text-decoration: none;
90 79
 }
91 80
 .collection > a {
@@ -154,22 +143,32 @@ footer .minorbox a {
154 143
 }
155 144
 .reply {
156 145
 	display: flex;
157
-	align-content: flex-end;
158 146
 	flex: 0 0 auto;
159 147
 }
160
-.reply .buttons .cancel {
148
+.reply .buttons {
149
+	float: right;
150
+}
151
+.reply .cancel {
161 152
 	border-top: 0;
162 153
 	display: block;
163 154
 	margin: 0;
164 155
 	top: 0;
165 156
 }
157
+.reply img {
158
+	display: block;
159
+	width: 100%;
160
+}
166 161
 .reply .buttons input[type=submit] {
167
-	color: inherit;
168
-	margin-left: auto;
169 162
 	display: block;
163
+	color: inherit;
170 164
 	border-top: 0;
165
+	width: 100%;
166
+}
167
+.reply .buttons a {
168
+	text-align: center;
171 169
 }
172 170
 .reply textarea {
171
+	flex: 0 1 auto;
173 172
 	border-top: 0;
174 173
 	border-left: 0;
175 174
 	border-right: 0;
@@ -361,6 +360,7 @@ input, select, textarea {
361 360
 	margin-bottom: 1px;
362 361
 	font-size: 1em;
363 362
 	background-color: inherit;
363
+	margin: 0;
364 364
 }
365 365
 input[type=submit] {
366 366
 	padding-left: 5px;

+ 1
- 1
B4U/index.php View File

@@ -11,7 +11,7 @@ if (!isset($page)) $page = 0;
11 11
 <!DOCTYPE HTML>
12 12
 <HTML>
13 13
 <head>
14
-<?php head('RAL')?>
14
+<?php head('Home')?>
15 15
 </head>
16 16
 <body>
17 17
 <div id=welcome>

+ 6
- 18
B4U/info.php View File

@@ -39,20 +39,18 @@ function nl22br($string)
39 39
 			$a = CONFIG_WEBROOT . "info/";
40 40
 			print
41 41
 <<<HTML
42
-		<a href={$a}theme>Theme</a>
43
-		<a href={$a}announce>Notices</a>
44
-		<a href={$a}>About</a>
45
-		<a href={$a}help>Help</a>
42
+		<a class=hoverbox href={$a}theme>Theme</a>
43
+		<a class=hoverbox href={$a}>About</a>
44
+		<a class=hoverbox href={$a}help>Help</a>
46 45
 
47 46
 HTML;
48 47
 		}
49 48
 		else
50 49
 			print
51 50
 <<<HTML
52
-		<a href=?theme>Theme</a>
53
-		<a href=?staff>Staff</a>
54
-		<a href=?>About</a>
55
-		<a href=?help>Help</a>
51
+		<a class=hoverbox href=?theme>Theme</a>
52
+		<a class=hoverbox href=?>About</a>
53
+		<a class=hoverbox href=?help>Help</a>
56 54
 
57 55
 HTML;
58 56
 ?>
@@ -90,16 +88,6 @@ HTML;
90 88
 
91 89
 HTML;
92 90
 
93
-	} else if (isset($_GET['announce'])) {
94
-		$txt = nl22br(bbbbbbb(file_get_contents('announce.txt')));
95
-		print
96
-<<<HTML
97
-		<h3>Announcements</h3>
98
-		<div class=reader>
99
-		$txt
100
-		</div>
101
-
102
-HTML;
103 91
 	} else if (isset($_GET['help'])) {
104 92
 		$mail = CONFIG_ADMIN_MAIL; $name = ucfirst(CONFIG_ADMIN_NAME);
105 93
 		// Probably read this in from a file

+ 27
- 16
B4U/max.php View File

@@ -204,17 +204,24 @@ HTML;
204 204
 			else
205 205
 				$target = CONFIG_WEBROOT
206 206
 				. "max.php";
207
-			if (empty($q)) $href = "$target";
207
+			if (empty($q)) $href = $target;
208 208
 			else $href = "$target?$q";
209
+			$robocheck = gen_robocheck($_COOKIE['auth']);
210
+			$robosrc = $robocheck['src'];
211
+			$robocode = $robocheck['id'];
209 212
 			print
210 213
 <<<HTML
211 214
 	<form class=reply method=POST action="?$q">
212
-		<textarea rows=5
213
-		maxlength=CONFIG_RAL_POSTMAXLEN
214
-		name=content></textarea>
215
+			<textarea rows=5
216
+			maxlength=CONFIG_RAL_POSTMAXLEN
217
+			name=content></textarea>
215 218
 		<div class=buttons>
216
-		<a href="$href" class=cancel>Cancel</a>
217
-		<input value=Post type=submit>
219
+			<img src="$robosrc">
220
+			<input type=hidden value=$robocode>
221
+			<input name=answer placeholder="Type the above text">
222
+			<input value=Post class=hoverbox type=submit>
223
+			<a href="$href" class="cancel hoverbox">Cancel</a>
224
+
218 225
 		</div>
219 226
 	</form>
220 227
 
@@ -230,8 +237,8 @@ HTML;
230 237
 			print
231 238
 <<<HTML
232 239
 	<footer>
233
-	<span class=minorbox>
234
-	<a href='$a'>Reply to Topic</a>
240
+	<span class=hoverbox>
241
+		<a href='$a'>Reply to Topic</a>
235 242
 	</span>
236 243
 
237 244
 HTML;
@@ -250,7 +257,7 @@ HTML;
250 257
 			}
251 258
 			print
252 259
 <<<HTML
253
-	<span class=minorbox>
260
+	<span class=hoverbox>
254 261
 		<a href=$a>Return</a>
255 262
 	</span>
256 263
 	</footer>
@@ -317,12 +324,16 @@ HTML;
317 324
 
318 325
 			print
319 326
 <<<HTML
320
-	<form class=reply method=POST action=?$q>
321
-		<textarea rows=5 maxlength=CONFIG_RAL_POSTMAXLEN
322
-		name=content></textarea>
327
+	<form class=reply method=POST action="?$q">
328
+			<textarea rows=5
329
+			maxlength=CONFIG_RAL_POSTMAXLEN
330
+			name=content></textarea>
323 331
 		<div class=buttons>
324
-		<a href='$href' class='cancel'>Cancel</a>
325
-		<input value=Post type=submit>
332
+			<img src="https://ral.howler.space/robocheck/5a4d30565da36/5a54e4e2769bb.jpg">
333
+			<input name=answer placeholder="Type the above text">
334
+			<input value=Post class=hoverbox type=submit>
335
+			<a href="$href" class="cancel hoverbox">Cancel</a>
336
+
326 337
 		</div>
327 338
 	</form>
328 339
 
@@ -339,8 +350,8 @@ HTML;
339 350
 			print
340 351
 <<<HTML
341 352
 	<footer>
342
-		<span class=minorbox>
343
-		<a href=$a>Create a Topic</a>
353
+		<span class=hoverbox>
354
+			<a href=$a>Create a Topic</a>
344 355
 		</span>
345 356
 	</footer>
346 357
 

+ 0
- 0
B4U/robocheck/.keep View File


+ 2
- 0
includes/config.template.php View File

@@ -34,6 +34,8 @@ define("CONFIG_WEBROOT", "https:ral.space/");
34 34
 
35 35
 define("CONFIG_CLEAN_URL", false);
36 36
 
37
+define("CONFIG_WORDLIST", "/usr/share/wordlists/rockyou.txt");
38
+
37 39
 define("CONFIG_THEMES",
38 40
 [
39 41
 	'20XX',

+ 69
- 0
includes/mod.php View File

@@ -32,5 +32,74 @@ function clearban($auth)
32 32
 		mysqli_query($dbh, $query);
33 33
 	}
34 34
 }
35
+function gen_robocheck($user)
36
+{
37
+	$imgpath = CONFIG_LOCALROOT . "B4U/robocheck/$user/";
38
+	$keypath = CONFIG_LOCALROOT . "tmp/robocheck-answers/$user/";
39
+	if (strpos(get_absolute_path($imgpath)
40
+	, CONFIG_LOCALROOT . "B4U/robocheck") !== 0
41
+	|| (!is_dir($imgpath) && !mkdir($imgpath))
42
+	|| (!is_dir($keypath) && !mkdir($keypath)))
43
+		die;
44
+
45
+	$id = uniqid();
46
+	$imgfile = "$id.jpg";
47
+	$keyfile = "$id.txt";
48
+
49
+	$tmp = CONFIG_LOCALROOT . "tmp/";
50
+	$key = rand_line(CONFIG_WORDLIST);
51
+
52
+	system("convert -size 165x70 plasma:fractal $tmp/$id-fractal.jpg");
53
+	system("convert $tmp/$id-fractal.jpg -paint 10 $tmp/$id-background.jpg");
54
+	system("convert -size 165x -background 'rgba(0,0,0,0)' -fill black -blur 0x1 -blur 0x1 label:'$key' $tmp/$id-text.png");
55
+	system("composite -gravity center $tmp/$id-text.png $tmp/$id-background.jpg $tmp/$id-final.jpg");
35 56
 
57
+	unlink("$tmp/$id-background.jpg");
58
+	unlink("$tmp/$id-fractal.jpg");
59
+	unlink("$tmp/$id-text.png");
60
+
61
+	rename("$tmp/$id-final.jpg", $imgpath . $imgfile);
62
+	file_put_contents($keypath . $keyfile, $key);
63
+
64
+	return [
65
+		"id" => $id,
66
+		"src" => CONFIG_WEBROOT . "robocheck/$user/$imgfile",
67
+	];
68
+}
69
+function check_robocheck($user, $id, $answer)
70
+{
71
+	$imgfile = CONFIG_LOCALROOT . "B4U/robocheck/$user/$id.jpg";
72
+	$keyfile = CONFIG_LOCALROOT . "tmp/robocheck-answers/$user/$id.txt";
73
+
74
+	if (file_get_contents($keyfile) !== $answer)
75
+		return false;
76
+	unlink($imgfile);
77
+	unlink($keyfile);
78
+	return true;
79
+}
80
+function rand_line($fname, $maxlen = 4096) {
81
+	$handle = fopen($fname, "r");
82
+	if (!$handle) return False;
83
+	$random_line = null;
84
+	$count = 0;
85
+	while (($line = fgets($handle, $maxlen)) !== false) {
86
+		$count++;
87
+		if(rand() % $count == 0) {
88
+			$random_line = $line;
89
+		}
90
+	}
91
+	fclose($handle);
92
+	return $random_line;
93
+}
94
+function get_absolute_path($path)
95
+{
96
+	$parts = explode('/', $path);
97
+	$absolutes = [];
98
+	foreach($parts as $part) {
99
+		if ($part == '.') continue;
100
+		if ($part == '..') array_pop($absolutes);
101
+		else $absolutes[] = $part;
102
+	}
103
+	return implode('/', $absolutes);
104
+}
36 105
 ?>

+ 2
- 2
includes/render.php View File

@@ -24,13 +24,13 @@ HTML;
24 24
 		|| $i >= ($page + 1) * $per_page)
25 25
 			print
26 26
 <<<HTML
27
-	<a href="$a"
27
+	<a class=hoverbox href="$a"
28 28
 	style="visibility: hidden; display:none">$name</a>
29 29
 
30 30
 HTML;
31 31
 		else print
32 32
 <<<HTML
33
-	<a href="$a">$name</a>
33
+	<a class=hoverbox href="$a">$name</a>
34 34
 
35 35
 HTML;
36 36
 	}

+ 0
- 0
tmp/robocheck-answers/.keep View File