From c6ba22f591881daae4a2f3abf2990b427a3ad716 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 9 Oct 2011 18:49:25 -0400 Subject: Select ! to be username separator. --- src/models/Auth.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/models/Auth.class.php b/src/models/Auth.class.php index 031ee26..9017bd5 100644 --- a/src/models/Auth.class.php +++ b/src/models/Auth.class.php @@ -31,6 +31,7 @@ class Auth { return true && (!in_array($name, $illegal_names)) && (strpos($name,'.')===false) + && (strpos($name,'!')===false) && (strlen($name)<256); } -- cgit v1.2.3-2-g168b From ea13b80f93469d6d7790e02bfc4983918daa0315 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 9 Oct 2011 18:51:34 -0400 Subject: Fix bug in Users::getIndexAttribs() where auth_name was being omitted. --- src/controllers/Users.class.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php index dbd5120..447a70f 100644 --- a/src/controllers/Users.class.php +++ b/src/controllers/Users.class.php @@ -342,8 +342,8 @@ class Users extends Controller { $user = Auth::getObj(Login::isLoggedIn()); $attribs = array(); + $attribs[] = $this->attrib('auth_uid', 'UID'); if ($user->isUser()) { - $attribs[] = $this->attrib('auth_uid', 'UID'); $attribs[] = $this->attrib('auth_user', 'Active', 'bool'); if ($user->isAdmin()) { $attribs[] = $this->attrib('auth_admin', 'Admin', 'bool'); @@ -354,10 +354,9 @@ class Users extends Controller { $attribs[] = $this->attrib('hsclass','Class of'); $attribs[] = $this->attrib('phone','Phone number'); $attribs[] = $this->attrib('email','Email'); - } else { - $attribs[] = $this->attrib('auth_uid', 'UID'); - $attribs[] = $this->attrib('auth_name', 'Username'); } + $attribs[] = $this->attrib('auth_name', 'Username'); + return $attribs; } -- cgit v1.2.3-2-g168b From a580549d814adf828bf2bc6461a5572183ba114c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 23 Oct 2011 17:08:41 -0400 Subject: Refactor to *finally* get rid of the god-class "MessageManager". Accomplish this largely by using singletons. Now, I know this breaks the "build", at least in PHP 5.2. But there's a lot here that's good stuff, so just wait for the next commit. Now, a *LOT* changed, as you can see by the size of the diff; it's about a day and a half of editing worth of editing. I'll describe a little of it, but I'm not going to go into a ton of detail, and won't bother trying to break it into separate commits (they're all so interconnected, it would be mental masturbation). 'Cause I'm the only one looking at it at this point. 1. MessageManager did 3 things: A. Act as a global site class. This has been moved into `lib/Site.class.php' B. Act as a registry for singletons. Now there's a `lib/Singleton.class.php' abstract class to let them manage themselves. : Note: With the possible exception of Database, none of the : : singletons *need* to be singletons, but to create : : multiple of them would be wasteful. : C. Check if the database conf file exists, and if it doesn't show an error message. This has been moved into index.php, and the message has been turned into a proper view. 2. Recognize `Auth.class.php' for what it is, a multiton. Rename Auth::getObj to Auth::getInstance to be consistant with singletons. 3. Make Site->baseUrl() (formerly `MessageManager->baseUrl()') figure the base URL each time, either with or without the database. This way we can be more flexible with initing the Template. 4. Init Template (now a singleton) sanely. We can now use views with no DB. I will use the above to shorten the below file changes: index.php: [1C] Also, just tidy up. src/controllers/Users.class.php: [1B] [2] src/lib/Controller.class.php: [4] src/lib/DB.class.php: [1B] [2] src/lib/Database.class.php: [1B] src/lib/Hasher.class.php: [1B] (new file) A singleton wrapper around `ext/PasswordHash.class.php', use bcrypt while exposing fewer internals. src/lib/Login.class.php: [1B] src/lib/MessageManager.class.php: [1] src/lib/Model.class.php: [1B] (new file) A abstract class for models, so they don't have to worry about initing the DB. src/lib/PluginManager.class.php: [1B] src/lib/Singleton.class.php: [1B] (new file) An abstract class that will take care of being a singleton for you; in order to make a class a singleton, just extend Singleton. src/lib/Site.class.php: [1A] [3] (new file) src/lib/View.class.php: [4] src/models/Auth.class.php: [2] [1B] Also make getUsername safely return false if the DB isn't connected. src/models/ContactMethod: extend `Model' src/views/Template.class.php: [1B] [3] src/views/pages/no-conf.html.php: [1C] src/views/pages/plugins/index.html.php: [1B] src/views/pages/users/500.html.php: [1B] --- index.php | 49 ++++++++++++-------- src/controllers/AuthPage.class.php | 4 +- src/controllers/Config.class.php | 2 +- src/controllers/Messages.class.php | 3 +- src/controllers/Plugins.class.php | 9 ++-- src/controllers/Users.class.php | 33 +++++++------ src/lib/Controller.class.php | 7 +-- src/lib/DB.class.php | 16 +++---- src/lib/Database.class.php | 20 ++++---- src/lib/Hasher.class.php | 18 +++++++ src/lib/Login.class.php | 7 +-- src/lib/MessageManager.class.php | 85 ---------------------------------- src/lib/Model.class.php | 9 ++++ src/lib/PluginManager.class.php | 10 ++-- src/lib/Singleton.class.php | 12 +++++ src/lib/Site.class.php | 32 +++++++++++++ src/lib/View.class.php | 5 +- src/models/Auth.class.php | 42 +++++++++++------ src/models/ContactMethod.class.php | 3 +- src/views/Template.class.php | 27 ++++------- src/views/pages/no-conf.html.php | 8 ++++ src/views/pages/plugins/index.html.php | 5 +- src/views/pages/users/500.html.php | 5 +- 23 files changed, 212 insertions(+), 199 deletions(-) create mode 100644 src/lib/Hasher.class.php delete mode 100644 src/lib/MessageManager.class.php create mode 100644 src/lib/Model.class.php create mode 100644 src/lib/Singleton.class.php create mode 100644 src/lib/Site.class.php create mode 100644 src/views/pages/no-conf.html.php diff --git a/index.php b/index.php index ad16995..231b4d6 100644 --- a/index.php +++ b/index.php @@ -1,7 +1,8 @@ show(array()); + exit(); +} -global $mm; -require_once('MessageManager.class.php'); -$mm = new MessageManager(BASEPATH.'/conf.php'); +// Kludgy ugly hacky hack ////////////////////////////////////////////////////// +require_once('ContactMethod.class.php'); +require(BASEPATH.'/conf-contacts.php'); -// Actually do stuff +// Business //////////////////////////////////////////////////////////////////// +require_once('Router.class.php'); $router = new Router(CONTROLLERPATH); $router->route(PAGE); diff --git a/src/controllers/AuthPage.class.php b/src/controllers/AuthPage.class.php index b31d938..1f46f72 100644 --- a/src/controllers/AuthPage.class.php +++ b/src/controllers/AuthPage.class.php @@ -1,5 +1,6 @@ showView('auth/logout'); } private function maybe_login() { - global $mm; $uid = Login::isLoggedIn(); if ($uid===false) { $this->login(); } else { - $username = $mm->database()->getUsername($uid); + $username = Auth::getInstance($uid)->getName(); $this->showView('auth/index', array('username'=>$username)); } diff --git a/src/controllers/Config.class.php b/src/controllers/Config.class.php index 37d1f09..dc6a884 100644 --- a/src/controllers/Config.class.php +++ b/src/controllers/Config.class.php @@ -6,7 +6,7 @@ Router::register('config', 'Config', 'index'); class Config extends Controller { public function index($routed, $remainder) { $uid = Login::isLoggedIn(); - if ($uid===false || !Auth::getObj($uid)->isAdmin()) { + if ($uid===false || !Auth::getInstance($uid)->isAdmin()) { $this->http401($routed, $remainder); return; } diff --git a/src/controllers/Messages.class.php b/src/controllers/Messages.class.php index d28d968..717e18e 100644 --- a/src/controllers/Messages.class.php +++ b/src/controllers/Messages.class.php @@ -1,5 +1,6 @@ isUser()) { + if ($uid===false || !Auth::getInstance($uid)->isUser()) { $this->http401($routed, $remainder); return; } diff --git a/src/controllers/Plugins.class.php b/src/controllers/Plugins.class.php index e2b500c..2ed6e7a 100644 --- a/src/controllers/Plugins.class.php +++ b/src/controllers/Plugins.class.php @@ -2,13 +2,15 @@ require_once('Login.class.php'); require_once('Plugin.class.php'); require_once('PluginManager.class.php'); +require_once('Auth.class.php'); +require_once('Database.class.php'); Router::register('plugins', 'Plugins'); class Plugins extends Controller { public function index($routed, $remainder) { $uid = Login::isLoggedIn(); - if ($uid===false || !Auth::getObj($uid)->isAdmin()) { + if ($uid===false || !Auth::getInstance($uid)->isAdmin()) { $this->http401($routed, $remainder); return; } @@ -25,8 +27,7 @@ class Plugins extends Controller { } private function update() { - global $mm; - $db = $mm->database(); + $db = Database::getInstance(); if (isset($_POST['plugins'])) { $string = $db->arrayToValue($_POST['plugins']); @@ -45,7 +46,7 @@ class Plugins extends Controller { } private function show_index() { - global $mm; $pm = $mm->pluginManager(); + $pm = PluginManager::getInstance(); $all_plugins = $pm->listPlugins(); $enabled_plugins = $pm->getActivePlugins(); diff --git a/src/controllers/Users.class.php b/src/controllers/Users.class.php index 447a70f..9978ef8 100644 --- a/src/controllers/Users.class.php +++ b/src/controllers/Users.class.php @@ -2,6 +2,8 @@ require_once('Login.class.php'); require_once('Auth.class.php'); require_once('DB.class.php'); +require_once('PluginManager.class.php'); +require_once('Database.class.php'); Router::register('users/new' , 'Users', 'new_user'); Router::register('users/index', 'Users', 'index_file'); @@ -73,9 +75,8 @@ class Users extends Controller { } if (!isset($vars['errors'])) $vars['errors'] = array(); - global $mm; - $pm = $mm->pluginManager(); - $db = $mm->database(); + $db = Database::getInstance(); + $pm = PluginManager::getInstance(); $vars['antispam_html'] = $pm->callHook('antispam_html'); $vars['userlist'] = $db->getSysConf('anon_userlist'); @@ -83,9 +84,8 @@ class Users extends Controller { } public function individual($routed, $remainder) { - global $mm; // also used for pluginmanager - $db = $mm->database(); - $pm = $mm->pluginManager(); + $db = Database::getInstance(); + $pm = PluginManager::getInstance(); $username = implode('/', $remainder); if ($username == 'all') { @@ -97,7 +97,7 @@ class Users extends Controller { $vars = array(); if (count($uids)<2) { - $user = Auth::getObj($uid); + $user = Auth::getInstance($uid); if ($user->isGroup()) $uid = false; // ignore groups. @@ -127,7 +127,7 @@ class Users extends Controller { $vars['users'] = array(); foreach ($uids as $uid) { - $vars['users'][] = Auth::getObj($uid); + $vars['users'][] = Auth::getInstance($uid); } $vars['username'] = $username; $vars['config_options'] = $config_options; @@ -155,9 +155,8 @@ class Users extends Controller { * explained. */ private function create_user() { - global $mm; - $db = $mm->database(); - $pm = $mm->pluginManager(); + $db = Database::getInstance(); + $pm = PluginManager::getInstance(); $vars = array(); @$vars['username' ] = $_POST['auth_name']; @@ -238,8 +237,8 @@ class Users extends Controller { // Change information ////////////////////////////////////////// $config_options = array(); - global $mm; - $mm->pluginManager()->callHook('userConfig', &$config_options); + $pm = PluginManager::getInstance(); + $pm->callHook('userConfig', &$config_options); foreach ($config_options as $group=>$options) { foreach ($options as $option) { @@ -311,9 +310,9 @@ class Users extends Controller { * This will show the user index. */ private function show_index($routed, $remainder) { - global $mm; $db = $mm->database(); + $db = Database::getInstance(); - $logged_in_user = Auth::getObj(Login::isLoggedIn()); + $logged_in_user = Auth::getInstance(Login::isLoggedIn()); $anon_userlist = $db->getSysConf('anon_userlist')=='true'; if (!$anon_userlist && !$logged_in_user->isUser()) { $this->http401($routed, $remainder); @@ -339,7 +338,7 @@ class Users extends Controller { return array('key'=>$key, 'name'=>$name, 'type'=>$type); } private function getIndexAttribs() { - $user = Auth::getObj(Login::isLoggedIn()); + $user = Auth::getInstance(Login::isLoggedIn()); $attribs = array(); $attribs[] = $this->attrib('auth_uid', 'UID'); @@ -361,7 +360,7 @@ class Users extends Controller { } private function registrationOpen() { - global $mm; $db = $mm->database(); + $db = Database::getInstance(); $val = $db->getSysConf('registration_open'); switch ($val) { case 'true': return true; diff --git a/src/lib/Controller.class.php b/src/lib/Controller.class.php index f9ed59d..05736ee 100644 --- a/src/lib/Controller.class.php +++ b/src/lib/Controller.class.php @@ -1,18 +1,13 @@ template(); - + $obj = new View($view); $obj->show($vars); } diff --git a/src/lib/DB.class.php b/src/lib/DB.class.php index 5954726..ac8dafe 100644 --- a/src/lib/DB.class.php +++ b/src/lib/DB.class.php @@ -1,7 +1,7 @@ $editable); } private static function user_set($uid, $key, $value) { - $user = Auth::getObj($uid); + $user = Auth::getInstance($uid); switch ($key) { case 'auth_uid': @@ -127,8 +127,8 @@ class DB { } private static function admin_get($plugin, $key) { - global $mm; $db = $mm->database(); - $user = Auth::getObj(Login::isLoggedIn()); + $db = Database::getInstance(); + $user = Auth::getInstance(Login::isLoggedIn()); if ($user->isAdmin()) { $editable = true; switch ($plugin) { @@ -149,8 +149,8 @@ class DB { 'editable'=>$editable); } private static function admin_set($plugin, $key, $value) { - global $mm; $db = $mm->database(); - $user = Auth::getObj(Login::isLoggedIn()); + $db = Database::getInstance(); + $user = Auth::getInstance(Login::isLoggedIn()); if (!$user->isAdmin()) { return false; } diff --git a/src/lib/Database.class.php b/src/lib/Database.class.php index 13d9559..1e98511 100644 --- a/src/lib/Database.class.php +++ b/src/lib/Database.class.php @@ -1,12 +1,19 @@ conf = $conf_file; + self::$me = $this; + } + public static function getInstance() { + return self::$me; } // Low-Level SQL functions ///////////////////////////////////////////// @@ -114,9 +121,8 @@ class Database { if (!is_int($uid)) return false; $table = $this->mysql_table('auth'); - global $mm; - $hasher = $mm->hasher(); - @$hash = $hasher->HashPassword($password); + $hasher = Hasher::getInstance(); + @$hash = $hasher->hashPassword($password); $query = "UPDATE $table \n". "SET hash='$hash' \n". @@ -130,12 +136,10 @@ class Database { return false; } - global $mm; - $table = $this->mysql_table('auth'); $user = $this->mysql_escape($username); - $hasher = $mm->hasher(); - @$hash = $hasher->HashPassword($password); + $hasher = Hasher::getInstance(); + @$hash = $hasher->hashPassword($password); $status = 0; $query = "INSERT INTO $table ( name, hash , status) \n". diff --git a/src/lib/Hasher.class.php b/src/lib/Hasher.class.php new file mode 100644 index 0000000..dc16d68 --- /dev/null +++ b/src/lib/Hasher.class.php @@ -0,0 +1,18 @@ +pw_hash = new PasswordHash(8, false); + } + + public function hash($password) { + return $this->pw_hash->HashPassword($password); + } + public function check($password, $hash) { + return $this->pw_hash->CheckPassword($password, $hash); + } +} diff --git a/src/lib/Login.class.php b/src/lib/Login.class.php index 870774a..a470176 100644 --- a/src/lib/Login.class.php +++ b/src/lib/Login.class.php @@ -1,4 +1,6 @@ database(); - $hasher = $mm->hasher(); + $db = Database::getInstance(); + $hasher = Hasher::getInstance(); $uid = $db->getUID($username); if ($uid!==false && $db->getStatus($uid)>=3) diff --git a/src/lib/MessageManager.class.php b/src/lib/MessageManager.class.php deleted file mode 100644 index d327eb7..0000000 --- a/src/lib/MessageManager.class.php +++ /dev/null @@ -1,85 +0,0 @@ -conf = $conf_file; - if (!file_exists($this->conf)) { - $this->base = $_SERVER['REQUEST_URI']; - $t = $this->template(); - $t->header('Message Manager'); - $t->paragraph( - 'Awe shiz, dude, conf.php doesn\'t exist, you '. - 'need to go through the '. - 'installer.'); - $t->footer(); - exit(); - } - session_start(); - } - - // Load Things - - public function database() { - if (!isset($this->database)) { - require_once('Database.class.php'); - $this->database = new Database($this->conf); - } - return $this->database; - } - - public function hasher() { - if (!isset($this->pw_hasher)) { - require_once('PasswordHash.class.php'); - $this->pw_hasher = new PasswordHash(8, false); - } - return $this->pw_hasher; - } - - public function template() { - if (!isset($this->template)) { - require_once(VIEWPATH.'/Template.class.php'); - $this->template = new Template($this->baseUrl(), $this); - } - return $this->template; - } - - public function pluginManager() { - if (!isset($this->pluginManager)) { - require_once('PluginManager.class.php'); - $this->pluginManager = new PluginManager(); - } - return $this->pluginManager; - } - - // Utility functions - - public function shortUrl($longUrl) { - $ch = curl_init('http://ur1.ca'); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_POST, true); - curl_setopt($ch, CURLOPT_POSTFILEDS, - 'longurl='.urlencode($longUrl)); - $html = curl_exec(); - preg_match('/Your ur1 is: /',$html,$matches); - $shortUrl = $matches[1]; - curl_close($ch); - return $shortUrl; - } - - public function baseUrl() { - if (!isset($this->base)) { - $this->base = $this->database()->getSysConf('baseurl'); - } - return $this->base; - } -} diff --git a/src/lib/Model.class.php b/src/lib/Model.class.php new file mode 100644 index 0000000..14f59d4 --- /dev/null +++ b/src/lib/Model.class.php @@ -0,0 +1,9 @@ +database(); + $db = Database::getInstance(); require_once("$plugin_name.class.php"); $obj = new $plugin_name; @@ -53,7 +55,7 @@ class PluginManager { * Return an array of enabled plugin names. */ public function getActivePlugins() { - global $mm; $db = $mm->database(); + $db = Database::getInstance(); $string = $db->getSysConf('plugins'); return $db->valueToArray($string); } @@ -62,7 +64,7 @@ class PluginManager { * Set the enabled plugins. */ public function setActivePlugins($plugins) { - global $mm; $db = $mm->database(); + $db = Database::getInstance(); $string = $db->arrayToValue($plugins); return $db->setSysConf('plugins', $string); } diff --git a/src/lib/Singleton.class.php b/src/lib/Singleton.class.php new file mode 100644 index 0000000..4eb3bb3 --- /dev/null +++ b/src/lib/Singleton.class.php @@ -0,0 +1,12 @@ +/',$html,$matches); + $shortUrl = $matches[1]; + curl_close($ch); + return $shortUrl; + } + + public function baseUrl() { + $base = $_SERVER['REQUEST_URI']; + + $db = Database::getInstance(); + if ($db !== null) { + $b = $db->getSysConf('baseurl'); + if ($b != false) { + $base = $b; + } + } + + return $base; + } +} diff --git a/src/lib/View.class.php b/src/lib/View.class.php index 33a9c4e..d7a21d3 100644 --- a/src/lib/View.class.php +++ b/src/lib/View.class.php @@ -123,7 +123,10 @@ class View { $mimes = Mime::ext2mime($this->ext); header('Content-type: '.$mimes[0]); - + + require_once(VIEWPATH.'/Template.class.php'); + $vars['template'] = new Template(); + global $VARS; $VARS = $vars; include($file); diff --git a/src/models/Auth.class.php b/src/models/Auth.class.php index 9017bd5..bb35be5 100644 --- a/src/models/Auth.class.php +++ b/src/models/Auth.class.php @@ -1,15 +1,19 @@ database()->getStatus($uid)<3; + $type = Database::getInstance()->getStatus($uid)<3; switch ($type) { case 0: // unactivated user case 1: // user @@ -21,7 +25,10 @@ class Auth { } return self::$users[$uid]; } - + + /**********************************************************************\ + * Static stuff * + \**********************************************************************/ public static function isNameLegal($name) { // Current rules: // * Not in "$illegal_names" @@ -34,12 +41,13 @@ class Auth { && (strpos($name,'!')===false) && (strlen($name)<256); } - - protected $db = null; + + /**********************************************************************\ + * Class stuff * + \**********************************************************************/ protected $uid = false; public function __construct($uid) { - global $mm; - $this->db = $mm->database(); + parent::__construct(); $this->uid = $uid; } public function getUID() { @@ -60,7 +68,7 @@ class Auth { } protected function setType($type) { $logged_in_uid = Login::isLoggedIn(); - $logged_in_obj = Auth::getObj($logged_in_uid); + $logged_in_obj = Auth::getInstance($logged_in_uid); $is_admin = $logged_in_obj->isAdmin(); if (!$is_admin) return false; return $this->db->setStatus($this->uid, $type); @@ -97,7 +105,7 @@ class Auth { $logged_in_uid = Login::isLoggedIn(); $is_me = ($logged_in_uid === $this->uid); - $logged_in_obj = Auth::getObj($logged_in_uid); + $logged_in_obj = Auth::getInstance($logged_in_uid); $is_user = $logged_in_obj->isUser(); return ($is_me || $is_user); @@ -106,7 +114,7 @@ class Auth { $logged_in_uid = Login::isLoggedIn(); $is_me = ($logged_in_uid === $this->uid); - $logged_in_obj = Auth::getObj($logged_in_uid); + $logged_in_obj = Auth::getInstance($logged_in_uid); $is_admin = $logged_in_obj->isAdmin(); return ($is_me || $is_admin); @@ -114,7 +122,11 @@ class Auth { // [user|group]name //////////////////////////////////////////////////// public function getName() { - return $this->db->getUsername($this->uid); + if ($this->db===null) { + return false; + } else { + return $this->db->getUsername($this->uid); + } } public function setName($new_name) { if (!$this->canEdit()) return false; diff --git a/src/models/ContactMethod.class.php b/src/models/ContactMethod.class.php index b01e7d3..1dd40ee 100644 --- a/src/models/ContactMethod.class.php +++ b/src/models/ContactMethod.class.php @@ -1,11 +1,10 @@ base = $base_url; - if ($mm!==null) - $this->db = $mm->database(); - } - public function setRet($ret) { $this->ret = $ret; } @@ -92,7 +87,7 @@ class Template { echo $str; } public function url($page) { - return $this->base.$page; + return Site::getInstance()->baseUrl().$page; } public function row($cells) { @@ -112,12 +107,8 @@ class Template { echo $str; } public function header($title) { - $db = $this->db; - if ($db==null) { - $username = false; - } else { - $username = $db->getUsername(Login::isLoggedIn()); - } + // username=false if not logged in or not connected to DB + $username = Auth::getInstance(Login::isLoggedIn())->getName(); $ret = $this->ret; $this->ret = true; diff --git a/src/views/pages/no-conf.html.php b/src/views/pages/no-conf.html.php new file mode 100644 index 0000000..1f4e3d3 --- /dev/null +++ b/src/views/pages/no-conf.html.php @@ -0,0 +1,8 @@ +header('Message Manager'); +$t->paragraph('Awe shiz, dude, conf.php doesn\'t exist, you '. + 'need to go through the '. + 'installer.'); +$t->footer(); diff --git a/src/views/pages/plugins/index.html.php b/src/views/pages/plugins/index.html.php index 1f89344..b182288 100644 --- a/src/views/pages/plugins/index.html.php +++ b/src/views/pages/plugins/index.html.php @@ -1,7 +1,8 @@ -database(); +$db = Database::getInstance(); $t->header('Administrator Plugin Management'); $t->openTag('form',array('method'=>'post','action'=>$t->url('plugins'))); diff --git a/src/views/pages/users/500.html.php b/src/views/pages/users/500.html.php index f4f1c42..339fe63 100644 --- a/src/views/pages/users/500.html.php +++ b/src/views/pages/users/500.html.php @@ -1,6 +1,7 @@ -database(); +$db = Database::getInstance(); $t->status('500 Internal Server Error'); $t->header('Unknown error'); -- cgit v1.2.3-2-g168b From 40bef9550687ed2b5a0c55feafc0b0dd015177e2 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 23 Oct 2011 17:09:17 -0400 Subject: Add some developer tools to Makefile (check for syntax errors, check required classes.) --- .gitignore | 2 ++ Makefile | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/.gitignore b/.gitignore index 30b29a1..8f217a5 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ conf.php xss-check.php .htaccess +dev-* + *.bak *~ .sass-cache/* \ No newline at end of file diff --git a/Makefile b/Makefile index 4b6eae6..a8184d0 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,12 @@ all: style.css screen.css print.css %.css: %.scss $(SASS) $< $@ +# These are for developers +dev-grep-require.txt: src + echo '$@' > '$@' + grep -r 'require_once' '$<'|sed "s/^\([^:]*\):.*require_once('\([A-Za-z]*\)\.class\.php').*/\1:\t\2/"|grep -Ev '(require_once|Singleton)'|sort -u >> '$@' +dev-grep-singleton.txt: src + echo '$@' > '$@' + grep -r '::getInstance' '$<'|sed 's/^\([^:]*\):.*[^A-Za-z]\([A-Za-z]*\)::getInstance(.*/\1:\t\2/'|sort -u >> '$@' +dev-lint.txt: src + -find '$<' -name '*.php' -exec '$(PHP)' -l '{}' \; |grep -v '^No syntax errors detected in' > '$@' -- cgit v1.2.3-2-g168b From 29a3ffb99435827d5a7ea6886ac22bd2ee18d593 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 27 Oct 2011 19:44:10 -0400 Subject: I think this fixes everything, but it now depends on PHP 5.3+ The introduction of the dependency on PHP 5.3 is that lib/Singleton.class uses `get_called_class()' --- index.php | 2 ++ src/lib/Database.class.php | 4 ++-- src/lib/Login.class.php | 2 +- src/lib/Model.class.php | 2 +- src/lib/Singleton.class.php | 10 +++++----- src/models/Auth.class.php | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/index.php b/index.php index 231b4d6..6c17d47 100644 --- a/index.php +++ b/index.php @@ -52,7 +52,9 @@ require_once('View.class.php'); require_once('Controller.class.php'); // Check if we have a database configuration /////////////////////////////////// +$conf_file = BASEPATH.'/conf.php'; if (file_exists($conf_file)) { + require_once('Database.class.php'); new Database($conf_file); session_start(); } else { diff --git a/src/lib/Database.class.php b/src/lib/Database.class.php index 1e98511..a76d891 100644 --- a/src/lib/Database.class.php +++ b/src/lib/Database.class.php @@ -122,7 +122,7 @@ class Database extends Singleton { $table = $this->mysql_table('auth'); $hasher = Hasher::getInstance(); - @$hash = $hasher->hashPassword($password); + @$hash = $hasher->hash($password); $query = "UPDATE $table \n". "SET hash='$hash' \n". @@ -139,7 +139,7 @@ class Database extends Singleton { $table = $this->mysql_table('auth'); $user = $this->mysql_escape($username); $hasher = Hasher::getInstance(); - @$hash = $hasher->hashPassword($password); + @$hash = $hasher->hash($password); $status = 0; $query = "INSERT INTO $table ( name, hash , status) \n". diff --git a/src/lib/Login.class.php b/src/lib/Login.class.php index a470176..bb21928 100644 --- a/src/lib/Login.class.php +++ b/src/lib/Login.class.php @@ -19,7 +19,7 @@ class Login { return 2; } $hash = $db->getPasswordHash($uid); - if ($hasher->CheckPassword($password, $hash)) { + if ($hasher->check($password, $hash)) { // success $_SESSION['uid'] = $uid; return 0; diff --git a/src/lib/Model.class.php b/src/lib/Model.class.php index 14f59d4..0cce525 100644 --- a/src/lib/Model.class.php +++ b/src/lib/Model.class.php @@ -4,6 +4,6 @@ require_once('Database.class.php'); abstract class Model { protected $db; public function __construct() { - $db = Database::getInstance(); + $this->db = Database::getInstance(); } } diff --git a/src/lib/Singleton.class.php b/src/lib/Singleton.class.php index 4eb3bb3..2f8c74f 100644 --- a/src/lib/Singleton.class.php +++ b/src/lib/Singleton.class.php @@ -1,12 +1,12 @@ getStatus($uid)<3; + $type = Database::getInstance()->getStatus($uid); switch ($type) { case 0: // unactivated user case 1: // user -- cgit v1.2.3-2-g168b