From c8c062d96024a23e67e73f1ebffcf7009b18eed1 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 31 Jan 2012 15:54:41 -0800 Subject: add spam engine --- library/spam/install/setup_berkeleydb.php | 240 ++++++++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 library/spam/install/setup_berkeleydb.php (limited to 'library/spam/install/setup_berkeleydb.php') diff --git a/library/spam/install/setup_berkeleydb.php b/library/spam/install/setup_berkeleydb.php new file mode 100644 index 000000000..81e1d5afa --- /dev/null +++ b/library/spam/install/setup_berkeleydb.php @@ -0,0 +1,240 @@ + +# +# This file is part of the b8 package +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as published by +# the Free Software Foundation in version 2.1 of the License. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public +# License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. + +echo << + + + + + + + +b8 Berkeley DB setup + + + + + + + + + + +
+ +

b8 Berkeley DB setup

+ + +END; + +$failed = FALSE; + +if(isset($_POST['handler'])) { + + $dbfile = $_POST['dbfile']; + $dbfile_directory = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']); + + echo "

Creating database

\n\n"; + + echo "

\n"; + + echo "Checking database file name … "; + + if($dbfile == "") { + echo "Please provide the name of the database file!
\n"; + $failed = TRUE; + } + else + echo "$dbfile
\n"; + + if(!$failed) { + + echo "Touching/Creating " . htmlentities($dbfile) . " … "; + + if(touch($dbfile) === FALSE) { + echo "Failed to touch the database file. Please check the given filename and/or fix the permissions of $dbfile_directory.
\n"; + $failed = TRUE; + } + else + echo "done
\n"; + + } + + if(!$failed) { + + echo "Setting file permissions to 0666 &hellip "; + + if(chmod($dbfile, 0666) === FALSE) { + echo "Failed to change the permissions of $dbfile_directory/$dbfile. Please adjust them manually.
\n"; + $failed = TRUE; + } + else + echo "done
\n"; + + } + + if(!$failed) { + + echo "Checking if the given file is empty &hellip "; + + if(filesize($dbfile) > 0) { + echo "$dbfile_directory/$dbfile is not empty. Can't create a new database. Please delete/empty this file or give another filename.
\n"; + $failed = TRUE; + } + else + echo "it is
\n"; + + } + + if(!$failed) { + + echo "Connecting to $dbfile … "; + + $db = dba_open($dbfile, "c", $_POST['handler']); + + if($db === FALSE) { + echo "Could not connect to the database!
\n"; + $failed = TRUE; + } + else + echo "done
\n"; + + } + + if(!$failed) { + + echo "Storing necessary internal variables &hellip "; + + $internals = array( + "bayes*dbversion" => "2", + "bayes*texts.ham" => "0", + "bayes*texts.spam" => "0" + ); + + foreach($internals as $key => $value) { + if(dba_insert($key, $value, $db) === FALSE) { + echo "Failed to insert data!
\n"; + $failed = TRUE; + break; + } + } + + if(!$failed) + echo "done
\n"; + + } + + if(!$failed) { + + echo "Trying to read data from the database &hellip "; + + $dbversion = dba_fetch("bayes*dbversion", $db); + + if($dbversion != "2") { + echo "Failed to read data!
\n"; + $failed = TRUE; + } + else + echo "success
\n"; + } + + if(!$failed) { + + dba_close($db); + + echo "

\n\n"; + echo "

Successfully created a new b8 database!

\n\n"; + echo "\n"; + echo "\n"; + echo "\n"; + echo "
Filename:$dbfile_directory/$dbfile
DBA handler:{$_POST['handler']}
\n\n"; + echo "

Move this file to it's destination directory (default: the base directory of b8) to use it with b8. Be sure to use the right DBA handler in b8's configuration."; + + } + + echo "

\n\n"; + +} + +if($failed === TRUE or !isset($_POST['handler'])) { + +echo << + +

DBA Handler

+ +

+The following table shows all available DBA handlers. Please choose the "Berkeley DB" one. +

+ + + + +END; + +foreach(dba_handlers(TRUE) as $name => $version) { + + $checked = ""; + + if(!isset($_POST['handler'])) { + if(strpos($version, "Berkeley") !== FALSE ) + $checked = " checked=\"checked\""; + } + else { + if($_POST['handler'] == $name) + $checked = " checked=\"checked\""; + } + + echo "\n"; + +} + +echo << + +

Database file

+ +

+Please the name of the desired database file. It will be created in the directory where this script is located. +

+ +

+ +

+ +

+ +

+ + + + +END; + +} + +?> + + + + + + -- cgit v1.2.3
HandlerDescription
$name$version