--- /dev/null
+<Files loader*.php>
+ Deny from all
+</Files>
+<Files config.php*>
+ Deny from all
+</Files>
+
--- /dev/null
+<?
+include('loader.php');
+
+if(!$db->canAdministrate())
+ die("Administration is turned off. Sorry.");
+?>
+<h1>Magic Smoke Admin Utility</h1>
+
+<h2>Checking DB</h2>
\ No newline at end of file
--- /dev/null
+<?
+/**Abstract base class for database engines*/
+abstract class DbEngine
+{
+ /**passcode for admin.php*/
+ private $adminpass=false;
+
+ //public function __construct();
+
+ /**connect to the database, must be overwritten by DB driver*/
+ public abstract function tryConnect();
+
+ /**set the admin passcode*/
+ public function setAdminPassCode($p)
+ {
+ $this->adminpass=$p;
+ }
+
+ /**returns whether a passcode is known and admin.php may be used*/
+ public function canAdministrate()
+ {
+ return $this->adminpass!==false;
+ }
+
+ /**returns the version of the DB layout that is required by this version of Magic Smoke*/
+ public function needVersion(){return "00.01";}
+
+ /**returns whether the table exists; must be implemented by driver*/
+ protected abstract function haveTable($tablename);
+
+ /**begins a transaction; must be implemented by driver*/
+ protected abstract function beginTransaction();
+
+ /**ends a transaction successfully; must be implemented by driver; returns true on success*/
+ protected abstract function commitTransaction();
+
+ /**ends a transaction with a rollback; must be implemented by driver; returns true on success*/
+ protected abstract function rollbackTransaction();
+
+ /**gets some data from the database; $table is the name of the table, $cols is the list of columns to return or "*" for all, $where is the where clause of the SQL-statement; returns array of rows, which are in *_fetch_array format; returns false on error*/
+ protected abstract function select($table,$cols,$where);
+
+ /**returns a configuration setting*/
+ public function getConfig($key)
+ {
+ $mar=$this->select("config","cval","ckey='".addslashes($key)."'");
+ if(count($mar)>0)return $mar[0][0];
+ }
+
+ /**tries to find out whether the connected DB version is usable*/
+ public function canUseDb()
+ {
+ if(!$this->haveTable("config"))
+ return false;
+ return getConfig("MagicSmokeVersion")==$this->needVersion();
+ }
+};
+
+?>
\ No newline at end of file
--- /dev/null
+<?
+class MysqlEngine extends DbEngine
+{
+ /**prefix for table names*/
+ protected $prefix="";
+
+ private $user;
+ private $server;
+ private $pass;
+ private $dbhdl=false;
+ private $dbname="";
+ private $engine="InnoDB";
+
+ /**initialize driver*/
+ public function __construct($server,$user,$pass)
+ {
+ $this->user=$user;
+ $this->server=$server;
+ $this->pass=$pass;
+ }
+
+ /**set a table-name prefix for the database*/
+ public function setPrefix($pre)
+ {
+ $this->prefix=$pre;
+ }
+
+ /**set the name of the database to be used*/
+ public function setDbName($dbn)
+ {
+ $this->dbname=$dbn;
+ }
+
+ /**set the name of the storage engine to be used on DB creation*/
+ public function setStorageEngine($e)
+ {
+ $this->engine=$e;
+ }
+
+ public function tryConnect()
+ {
+ $this->dbhdl=mysql_connect($this->server,$this->user,$this->pass);
+ if($this->dbhdl===false)
+ die("Unable to connect to database system. Giving up.");
+ if(mysql_query("use $this->dbname",$this->dbhdl)===false)
+ die("Unable to select database \"$this->dbname\". Giving up.");
+ }
+
+ protected function haveTable($tnm)
+ {
+ $res=mysql_query("select * from ".$this->prefix.$tnm." where 1=2",$this->dbhdl);
+ if($res===false)return false;
+ mysql_free_result($res);
+ return true;
+ }
+ protected function beginTransaction()
+ {
+ mysql_query("begin transaction");
+ }
+
+ protected function commitTransaction()
+ {
+ return mysql_query("commit transaction");
+ }
+
+ protected function rollbackTransaction()
+ {
+ return mysql_query("rollback transaction");
+ }
+
+ protected function select($table,$cols,$where)
+ {
+ $res=mysql_query("select $cols from ".$this->prefix.$table." where ".$where);
+ if($res===false)return false;
+ $nr=mysql_num_rows($res);
+ $ret=array();
+ for($i=0;$i<$max;$i++){
+ $ret[]=mysql_fetch_array($res,MYSQL_BOTH);
+ }
+ mysql_free_result($res);
+ return $ret;
+ }
+};
\ No newline at end of file
<?
-//include other scripts
-include('config.php');
+//basics
+include('loader.php');
+include('loader2.php');
+//include display scripts
include('inc/listing.php');
include('inc/parser.php');
--- /dev/null
+<?
+//load DB drivers
+include('inc/db.php');
+include('inc/db_mysql.php');
+include('config.php');
+//try to connect
+$db->tryConnect();
+//move on in loader2.php (or admin.php)
+?>
\ No newline at end of file
--- /dev/null
+<?
+//check database
+if(!$db->canUseDb())
+ die("Database is not correctly configured. Giving up.");
+?>
\ No newline at end of file