3 # Copyright (C) 2010 Tobias Leupold <tobias.leupold@web.de>
5 # This file is part of the b8 package
7 # This program is free software; you can redistribute it and/or modify it
8 # under the terms of the GNU Lesser General Public License as published by
9 # the Free Software Foundation in version 2.1 of the License.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 # License for more details.
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 <?xml version="1.0" encoding="UTF-8"?>
23 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
24 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
26 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
30 <title>b8 Berkeley DB setup</title>
32 <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
34 <meta name="dc.creator" content="Tobias Leupold" />
35 <meta name="dc.rights" content="Copyright (c) by Tobias Leupold" />
43 <h1>b8 Berkeley DB setup</h1>
50 if(isset($_POST['handler'])) {
52 $dbfile = $_POST['dbfile'];
53 $dbfile_directory = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['PHP_SELF']);
55 echo "<h2>Creating database</h2>\n\n";
59 echo "Checking database file name … ";
62 echo "<span style=\"color:red;\">Please provide the name of the database file!</span><br />\n";
66 echo "$dbfile<br />\n";
70 echo "Touching/Creating " . htmlentities($dbfile) . " … ";
72 if(touch($dbfile) === FALSE) {
73 echo "<span style=\"color:red;\">Failed to touch the database file. Please check the given filename and/or fix the permissions of $dbfile_directory.</span><br />\n";
83 echo "Setting file permissions to 0666 &hellip ";
85 if(chmod($dbfile, 0666) === FALSE) {
86 echo "<span style=\"color:red;\">Failed to change the permissions of $dbfile_directory/$dbfile. Please adjust them manually.</span><br />\n";
96 echo "Checking if the given file is empty &hellip ";
98 if(filesize($dbfile) > 0) {
99 echo "<span style=\"color:red;\">$dbfile_directory/$dbfile is not empty. Can't create a new database. Please delete/empty this file or give another filename.</span><br />\n";
103 echo "it is<br />\n";
109 echo "Connecting to $dbfile … ";
111 $db = dba_open($dbfile, "c", $_POST['handler']);
114 echo "<span style=\"color:red;\">Could not connect to the database!</span><br />\n";
124 echo "Storing necessary internal variables &hellip ";
127 "bayes*dbversion" => "2",
128 "bayes*texts.ham" => "0",
129 "bayes*texts.spam" => "0"
132 foreach($internals as $key => $value) {
133 if(dba_insert($key, $value, $db) === FALSE) {
134 echo "<span style=\"color:red;\">Failed to insert data!</span><br />\n";
147 echo "Trying to read data from the database &hellip ";
149 $dbversion = dba_fetch("bayes*dbversion", $db);
151 if($dbversion != "2") {
152 echo "<span style=\"color:red;\">Failed to read data!</span><br />\n";
156 echo "success<br />\n";
164 echo "<p style=\"color:green;\">Successfully created a new b8 database!</p>\n\n";
166 echo "<tr><td>Filename:</td><td>$dbfile_directory/$dbfile</td></tr>\n";
167 echo "<tr><td>DBA handler:</td><td>{$_POST['handler']}</td><tr>\n";
169 echo "<p>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.";
177 if($failed === TRUE or !isset($_POST['handler'])) {
180 <form action="{$_SERVER['PHP_SELF']}" method="post">
185 The following table shows all available DBA handlers. Please choose the "Berkeley DB" one.
189 <tr><td></td><td><b>Handler</b></td><td><b>Description</b></td></tr>
193 foreach(dba_handlers(TRUE) as $name => $version) {
197 if(!isset($_POST['handler'])) {
198 if(strpos($version, "Berkeley") !== FALSE )
199 $checked = " checked=\"checked\"";
202 if($_POST['handler'] == $name)
203 $checked = " checked=\"checked\"";
206 echo "<tr><td><input type=\"radio\" name=\"handler\" value=\"$name\"$checked /></td><td>$name</td><td>$version</td></tr>\n";
213 <h2>Database file</h2>
216 Please the name of the desired database file. It will be created in the directory where this script is located.
220 <input type="text" name="dbfile" value="wordlist.db" />
224 <input type="submit" value="Create the database" />