From: konrad Date: Sat, 14 Jul 2007 15:27:43 +0000 (+0000) Subject: hint at db admin X-Git-Url: http://git.silmor.de/gitweb/?a=commitdiff_plain;h=81ead4026788ac188b4524ce7cb787d56593b05e;p=konrad%2Fsmoke.git hint at db admin git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@12 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- diff --git a/www/admin.php b/www/admin.php index 4a7e3a3..b0904ee 100644 --- a/www/admin.php +++ b/www/admin.php @@ -3,6 +3,13 @@ include('loader.php'); if(!$db->canAdministrate()) die("Administration is turned off. Sorry."); +if(!$db->checkAdmin()){ + header("HTTP/1.0 401 Authentication needed"); + header("WWW-Authenticate: Basic; Realm=Smoke Admin Login"); + echo "Need to login in order to administrate."; + exit; +} +#phpinfo(); ?>

Magic Smoke Admin Utility

diff --git a/www/inc/db.php b/www/inc/db.php index 22567c5..b4bf6e0 100644 --- a/www/inc/db.php +++ b/www/inc/db.php @@ -4,6 +4,7 @@ abstract class DbEngine { /**passcode for admin.php*/ private $adminpass=false; + private $adminuser=false; //public function __construct(); @@ -11,15 +12,27 @@ abstract class DbEngine public abstract function tryConnect(); /**set the admin passcode*/ - public function setAdminPassCode($p) + public function setAdminPassCode($u,$p) { + $this->adminuser=$u; $this->adminpass=$p; } + /**check admin credentials*/ + public function checkAdmin() + { + global $_SERVER; + if(!$this->canAdministrate())return false; + if(!isset($_SERVER["PHP_AUTH_USER"]) || !isset($_SERVER["PHP_AUTH_PW"])){ + return false; + } + return $_SERVER["PHP_AUTH_USER"]==$this->adminuser && $_SERVER["PHP_AUTH_PW"]==$this->adminpass; + } + /**returns whether a passcode is known and admin.php may be used*/ public function canAdministrate() { - return $this->adminpass!==false; + return $this->adminpass!==false && $this->adminuser!==false; } /**returns the version of the DB layout that is required by this version of Magic Smoke*/ @@ -40,6 +53,36 @@ abstract class DbEngine /**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); + /**creates a table; the argument is an array of the form "col-name" => array("col-type", "flags"...); use sqlCreate() etc. to create the actual statement*/ + protected abstract function createTable($tablename,$table); + + /**returns the correct type name for the required abstract data type; + types that must be understood are: int32 (INTEGER), int64 (LONG INTEGER), autoint32 (auto-incrementing int), autoint64, string:$length (text up to 255 chars, length is optional, default is 255; VARCHAR($length)), text (unlimited text)*/ + protected function dataType($type) + { + if($type=="int32")return "INTEGER"; + if($type=="int64")return "LONG INTEGER"; + if(strncmp(7,$type,"string:")){ + return "VARCHAR("."??".")"; + } + return false; + } + + /**returns the correct name/coding of a flag: + primarykey, notnull, unique (implies notnull), foreignkey:$table:$col, defaultint:$val, defaultstr:$val, index*/ + protected function columnFlag($flag) + { + if($flag=="primarykey")return "PRIMARY KEY"; + if($flag=="notnull")return "NOT NULL"; + if($flag=="unique")return "NOT NULL,UNIQUE"; + if($flag=="index")return "INDEX"; + } + + /**creates a SQL92 statement for creating a table*/ + protected function sqlCreateTable($tablename,$table) + { + } + /**returns a configuration setting*/ public function getConfig($key) { diff --git a/www/inc/db_mysql.php b/www/inc/db_mysql.php index d3a43b0..7452bf2 100644 --- a/www/inc/db_mysql.php +++ b/www/inc/db_mysql.php @@ -80,4 +80,6 @@ class MysqlEngine extends DbEngine mysql_free_result($res); return $ret; } + + protected function createTable($tn,$t){} }; \ No newline at end of file diff --git a/www/inc/db_scheme.php b/www/inc/db_scheme.php new file mode 100644 index 0000000..e782422 --- /dev/null +++ b/www/inc/db_scheme.php @@ -0,0 +1,17 @@ +scheme["users"]=array( + "uname" => array("string:64","primarykey"), + "passwd" => array("string","notnull") + ); + $this->scheme["userrole"]=array( + "uname" =>array("string:64","notnull","foreignkey:users:uname","index"), + "role" =>array("string:32","notnull") + ); + } +}; +$dbScheme=new DbScheme; +?> \ No newline at end of file diff --git a/www/loader.php b/www/loader.php index cd67ba4..76df225 100644 --- a/www/loader.php +++ b/www/loader.php @@ -3,6 +3,7 @@ include('inc/db.php'); include('inc/db_mysql.php'); include('config.php'); +include('inc/db_scheme.php'); //try to connect $db->tryConnect(); //move on in loader2.php (or admin.php)