Browse Source

Download & install b8, a Bayesian spam filter implemented in PHP5

I am leveraging this software to categorize and automatically discard / hide
spam posted to RAL; because most of the spam I receive is easily categorizable
by such a statistical filter, b8 suits this role well.
yumi 1 month ago
parent
commit
a7e131163c
4 changed files with 46 additions and 9 deletions
  1. 1
    0
      .gitignore
  2. 30
    6
      bin/install.php
  3. 4
    3
      docs/INSTALL.md
  4. 11
    0
      patch/b8-abspath-fix.patch

+ 1
- 0
.gitignore View File

@@ -19,3 +19,4 @@ www/css/Classic
19 19
 info/MOTD
20 20
 
21 21
 includes/jBBCode
22
+includes/b8

+ 30
- 6
bin/install.php View File

@@ -39,8 +39,8 @@ $queries[] = <<<SQL
39 39
 	`Content` text NOT NULL DEFAULT '',
40 40
 	`Replies` int(11) DEFAULT 0,
41 41
 	`Year` int(4) NOT NULL DEFAULT year(`Created`),
42
-	`USER` VARCHAR(64),
43
-	`Deleted` int(11) DEFAULT NULL,
42
+	`User` VARCHAR(64),
43
+	`Deleted` bit DEFAULT 0 NOT NULL,
44 44
 	PRIMARY KEY (`Continuity`,`Year`,`Id`)
45 45
 	) ENGINE=InnoDB DEFAULT CHARSET=utf8
46 46
 SQL;
@@ -52,8 +52,8 @@ $queries[] = <<<SQL
52 52
 	`Year` int(4) NOT NULL DEFAULT year(`Created`),
53 53
 	`Topic` int(11) NOT NULL,
54 54
 	`Content` text NOT NULL DEFAULT '',
55
-	`USER` VARCHAR(64),
56
-	`Deleted` int(11) DEFAULT NULL,
55
+	`User` VARCHAR(64),
56
+	`Deleted` bit DEFAULT 0 NOT NULL,
57 57
 	PRIMARY KEY (`Continuity`,`Year`,`Topic`,`Id`)
58 58
 	) ENGINE=InnoDB DEFAULT CHARSET=utf8
59 59
 SQL;
@@ -89,7 +89,7 @@ foreach ($queries as $q) {
89 89
 	if (!$dbh->query($q)) {
90 90
 		printf("MySQL Error: %s\n", $dbh->error);
91 91
 		printf("Please resolve this before continuing!\n");
92
-		exit(1);
92
+		// exit(1);
93 93
 	}
94 94
 }
95 95
 
@@ -118,8 +118,32 @@ CMD;
118 118
 	rm -r {$tmp}/jBBCode-1.3.0
119 119
 CMD;
120 120
 	system($cmd);
121
+} if (is_dir("{$installfolder}/b8")) {
122
+	print "It seems like you aleady have b8 installed!\n";
123
+} else {
124
+	print "Downloadng b8-0.6.2...\n";
125
+	$zipfilepath = "b8-0.6.2/b8";
126
+	$tmp = realpath("{$ROOT}tmp/");
127
+	$relevpath = "{$tmp}/$zipfilepath";
128
+
129
+	$installto = escapeshellarg("{$installfolder}/b8");
130
+	$tmpfile = escapeshellarg("{$tmp}/b8-0.6.2.tar.xz");
131
+	$tmp = escapeshellarg($tmp);
132
+	$cmd = <<<CMD
133
+	curl https://nasauber.de/opensource/b8/b8-0.6.2.tar.xz --output \
134
+	$tmpfile
135
+CMD;
136
+	system($cmd);
137
+	$cmd = <<<CMD
138
+	tar xvf $tmpfile -C $tmp ; \
139
+	mv $relevpath $installto ; \
140
+	rm $tmpfile ; \
141
+	rm -r {$tmp}/b8-0.6.2
142
+	patch -p0 -d $installto < ${ROOT}patch/b8-abspath-fix.patch
143
+CMD;
144
+	system($cmd);
121 145
 }
122 146
 print <<<FIN
123
-	Finished!
147
+Finished!
124 148
 
125 149
 FIN;

+ 4
- 3
docs/INSTALL.md View File

@@ -19,10 +19,11 @@ Tools
19 19
 	- fpm-PHP (PHP pool manager)
20 20
 	- Graphics Draw (GD) Library for PHP
21 21
 	- jBBCode
22
+	- b8
22 23
 
23
-Ensure that your webserver can serve PHP files. Then install jBBCode into
24
-`/includes/jBBCode`. jBBCode can be downloaded from
25
-[the official website](http://jbbcode.com/).
24
+Ensure that your webserver can serve PHP files. Then run the setup utility
25
+(`bin/install.php`) which will automatically download and install jBBCode
26
+and b8.
26 27
 
27 28
 Example Setup
28 29
 -------------

+ 11
- 0
patch/b8-abspath-fix.patch View File

@@ -0,0 +1,11 @@
1
+--- storage/storage_dba.php	2014-09-03 09:07:31.000000000 -0400
2
++++ storage/storage_dba.php	2019-07-09 02:47:42.525387736 -0400
3
+@@ -61,7 +61,7 @@
4
+         }
5
+ 
6
+         # Connect to the database
7
++        $dbfile = $this->config['database'];
8
+-        $dbfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->config['database'];
9
+         if (is_file($dbfile) !== true) {
10
+             throw new Exception(
11
+                 "b8_storage_dba: Database file \"{$this->config['database']}\" not found."