From 7e2cdac7e96ef2fc99e03183df906d4c377f224d Mon Sep 17 00:00:00 2001 From: Deon George Date: Tue, 5 Jun 2012 13:50:21 +1000 Subject: [PATCH] Basic layout and login functioning --- .gitignore | 1 + .htaccess | 21 ++ application/bootstrap.php | 150 +++++++++++++ .../classes/{auth/ldap.php => Auth/LDAP.php} | 2 +- application/classes/{block.php => Block.php} | 0 application/classes/Config.php | 107 ++++++++++ .../template.php => Controller/Template.php} | 0 .../classes/Controller/TemplateDefault.php | 47 ++++ .../{database/ldap.php => Database/LDAP.php} | 0 .../search.php => Database/LDAP/Search.php} | 0 .../LDAP/Search/Builder/Query.php} | 0 .../{pla/auth/ldap.php => PLA/Auth/Ldap.php} | 2 +- .../classes/{pla/block.php => PLA/Block.php} | 28 +-- .../Controller/Template.php} | 13 +- .../ldap.php => PLA/Database/LDAP.php} | 0 .../Database/LDAP/Search.php} | 0 .../Database/LDAP/Search/Builder/Query.php} | 2 +- application/classes/PLA/Exception.php | 31 +++ application/classes/PLA/SystemMessage.php | 65 ++++++ .../classes/{config.php => SystemMessage.php} | 2 +- application/classes/URL.php | 51 +++++ application/classes/controller/login.php | 4 - application/classes/controller/logout.php | 4 - application/classes/controller/media.php | 4 - application/classes/htmlrender.php | 4 - application/classes/meta.php | 4 - application/classes/pla/config.php | 105 --------- application/classes/pla/controller/login.php | 200 ------------------ application/classes/pla/controller/logout.php | 26 --- application/classes/pla/controller/media.php | 59 ------ application/classes/pla/htmlrender.php | 92 -------- application/classes/pla/meta.php | 34 --- application/classes/pla/script.php | 53 ----- application/classes/pla/style.php | 54 ----- application/classes/script.php | 4 - application/classes/style.php | 4 - application/config/auth.php | 1 + application/config/config.php | 11 +- application/config/debug.php | 24 +++ application/config/userguide.php | 23 ++ .../media/img}/favicon.ico | Bin .../media/img}/logo-small.png | Bin application/media/notimplemented.txt | 1 + .../media/theme/claro/css/image}/key.png | Bin .../media/theme/claro/css/image}/ldap-uid.png | Bin application/media/theme/claro/css/style.css | 95 +++++++++ application/views/claro.php | 83 ++++++++ application/views/claro/block.php | 3 + application/views/login.php | 14 ++ index.php | 132 +++++++++++- 50 files changed, 861 insertions(+), 699 deletions(-) create mode 100644 .htaccess create mode 100644 application/bootstrap.php rename application/classes/{auth/ldap.php => Auth/LDAP.php} (61%) rename application/classes/{block.php => Block.php} (100%) create mode 100644 application/classes/Config.php rename application/classes/{controller/template.php => Controller/Template.php} (100%) create mode 100644 application/classes/Controller/TemplateDefault.php rename application/classes/{database/ldap.php => Database/LDAP.php} (100%) rename application/classes/{database/ldap/search.php => Database/LDAP/Search.php} (100%) rename application/classes/{database/ldap/search/builder/query.php => Database/LDAP/Search/Builder/Query.php} (100%) rename application/classes/{pla/auth/ldap.php => PLA/Auth/Ldap.php} (98%) rename application/classes/{pla/block.php => PLA/Block.php} (62%) rename application/classes/{pla/controller/template.php => PLA/Controller/Template.php} (91%) rename application/classes/{pla/database/ldap.php => PLA/Database/LDAP.php} (100%) rename application/classes/{pla/database/ldap/search.php => PLA/Database/LDAP/Search.php} (100%) rename application/classes/{pla/database/ldap/search/builder/query.php => PLA/Database/LDAP/Search/Builder/Query.php} (99%) create mode 100644 application/classes/PLA/Exception.php create mode 100644 application/classes/PLA/SystemMessage.php rename application/classes/{config.php => SystemMessage.php} (57%) create mode 100644 application/classes/URL.php delete mode 100644 application/classes/controller/login.php delete mode 100644 application/classes/controller/logout.php delete mode 100644 application/classes/controller/media.php delete mode 100644 application/classes/htmlrender.php delete mode 100644 application/classes/meta.php delete mode 100644 application/classes/pla/config.php delete mode 100644 application/classes/pla/controller/login.php delete mode 100644 application/classes/pla/controller/logout.php delete mode 100644 application/classes/pla/controller/media.php delete mode 100644 application/classes/pla/htmlrender.php delete mode 100644 application/classes/pla/meta.php delete mode 100644 application/classes/pla/script.php delete mode 100644 application/classes/pla/style.php delete mode 100644 application/classes/script.php delete mode 100644 application/classes/style.php create mode 100644 application/config/debug.php create mode 100644 application/config/userguide.php rename {htdocs/images => application/media/img}/favicon.ico (100%) rename {htdocs/images/default => application/media/img}/logo-small.png (100%) create mode 100644 application/media/notimplemented.txt rename {htdocs/images/default => application/media/theme/claro/css/image}/key.png (100%) rename {htdocs/images/default => application/media/theme/claro/css/image}/ldap-uid.png (100%) create mode 100644 application/media/theme/claro/css/style.css create mode 100644 application/views/claro.php create mode 100644 application/views/claro/block.php create mode 100644 application/views/login.php diff --git a/.gitignore b/.gitignore index ac7db53..d8aca7b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ config/config.php queries/custom_* templates/*/custom_* +devel diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000..1e2e54e --- /dev/null +++ b/.htaccess @@ -0,0 +1,21 @@ +# Turn on URL rewriting +RewriteEngine On + +# Installation directory +RewriteBase /pla + +# Protect hidden files from being viewed + + Order Deny,Allow + Deny From All + + +# Protect application and system files from being viewed +RewriteRule ^(?:application|modules|includes/kohana)\b.* index.php/$0 [L] + +# Allow any files or directories that exist to be displayed directly +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d + +# Rewrite all other URLs to index.php/URL +RewriteRule .* index.php/$0 [PT] diff --git a/application/bootstrap.php b/application/bootstrap.php new file mode 100644 index 0000000..e082096 --- /dev/null +++ b/application/bootstrap.php @@ -0,0 +1,150 @@ +" + */ +if (isset($_SERVER['KOHANA_ENV'])) +{ + Kohana::$environment = constant('Kohana::'.strtoupper($_SERVER['KOHANA_ENV'])); +} + +/** + * Initialize Kohana, setting the default options. + * + * The following options are available: + * + * - string base_url path, and optionally domain, of your application NULL + * - string index_file name of your index file, usually "index.php" index.php + * - string charset internal character set used for input and output utf-8 + * - string cache_dir set the internal cache directory APPPATH/cache + * - integer cache_life lifetime, in seconds, of items cached 60 + * - boolean errors enable or disable error handling TRUE + * - boolean profile enable or disable internal profiling TRUE + * - boolean caching enable or disable internal caching FALSE + * - boolean expose set the X-Powered-By header FALSE + */ +Kohana::init(array( + 'base_url' => '/pla', + 'caching' => TRUE, + 'index_file' => '', +)); + +/** + * Attach the file write to logging. Multiple writers are supported. + */ +Kohana::$log->attach(new Log_File(APPPATH.'logs')); + +/** + * Attach a file reader to config. Multiple readers are supported. + */ +Kohana::$config->attach(new Config_File); + +/** + * Enable modules. Modules are referenced by a relative or absolute path. + */ +Kohana::modules(array( + 'lnapp' => MODPATH.'lnApp', + 'auth' => SMDPATH.'auth', // Basic authentication + 'cache' => SMDPATH.'cache', // Caching with multiple backends + // 'codebench' => SMDPATH.'codebench', // Benchmarking tool + 'database' => SMDPATH.'database', // Database access + // 'image' => SMDPATH.'image', // Image manipulation + 'minion' => SMDPATH.'minion', // CLI Tasks + 'orm' => SMDPATH.'orm', // Object Relationship Mapping + // 'pagination' => SMDPATH.'pagination', // Kohana Pagination module for Kohana 3 PHP Framework + // 'unittest' => SMDPATH.'unittest', // Unit testing + // 'userguide' => SMDPATH.'userguide', // User guide and API documentation + 'xml' => SMDPATH.'xml', // XML module for Kohana 3 PHP Framework + )); + +// Static file serving (CSS, JS, images) +Route::set('default/media', 'media(/)', array('file' => '.+')) + ->defaults(array( + 'controller' => 'media', + 'action' => 'get', + )); + +/** + * Set the routes. Each route must have a minimum of a name, a URI and a set of + * defaults for the URI. + */ +Route::set('default', '((/(/)))', array('id'=>'[a-zA-Z0-9_.-]+')) + ->defaults(array( + 'controller' => 'welcome', + 'action' => 'index', + )); + +/** + * If APC is enabled, and we need to clear the cache + */ +if (file_exists(APPPATH.'cache/CLEAR_APC_CACHE') AND function_exists('apc_clear_cache') AND (PHP_SAPI !== 'cli')) { + if (! apc_clear_cache() OR ! unlink(APPPATH.'cache/CLEAR_APC_CACHE')) + throw new Kohana_Exception('Unable to clear the APC cache.'); +} +?> diff --git a/application/classes/auth/ldap.php b/application/classes/Auth/LDAP.php similarity index 61% rename from application/classes/auth/ldap.php rename to application/classes/Auth/LDAP.php index f6eced6..6cb9cfe 100644 --- a/application/classes/auth/ldap.php +++ b/application/classes/Auth/LDAP.php @@ -1,4 +1,4 @@ diff --git a/application/classes/block.php b/application/classes/Block.php similarity index 100% rename from application/classes/block.php rename to application/classes/Block.php diff --git a/application/classes/Config.php b/application/classes/Config.php new file mode 100644 index 0000000..7d9f554 --- /dev/null +++ b/application/classes/Config.php @@ -0,0 +1,107 @@ +load('config')->cache_type) ? 'file' : Kohana::$config->load('config')->cache_type; + } + + public static function copywrite() { + return '(c) phpLDAPadmin Development Team'; + } + + public static function country() { + return NULL; + } + + public static function language() { + // @todo To implement + return 'auto'; + } + + /** + * The URI to show for the login prompt. + * Normally if the user is logged in, we can replace it with something else + */ + public static function login_uri() { + return ($ao = Auth::instance()->get_user() AND is_object($ao)) ? $ao->name() : HTML::anchor('login',_('Login')); + } + + public static function logo() { + return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo'))); + } + + public static function logo_uri($protocol=NULL) { + list ($path,$suffix) = explode('.',static::$logo); + + return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),$protocol); + } + + public static function siteid($format=FALSE) { + return ''; + } + + /** + * Work out our site mode (dev,test,prod) + */ + public static function sitemode() { + return Kohana::$config->load('config.site')->mode; + } + + public static function sitename() { + return 'phpLDAPadmin'; + } + + public static function theme() { + return Kohana::$config->load('config')->theme; + } + + public static function version() { + // @todo Work out our versioning + return 'TBA'; + } +} +?> diff --git a/application/classes/controller/template.php b/application/classes/Controller/Template.php similarity index 100% rename from application/classes/controller/template.php rename to application/classes/Controller/Template.php diff --git a/application/classes/Controller/TemplateDefault.php b/application/classes/Controller/TemplateDefault.php new file mode 100644 index 0000000..a26f1d7 --- /dev/null +++ b/application/classes/Controller/TemplateDefault.php @@ -0,0 +1,47 @@ +template = Config::theme().'/page'; + + return parent::__construct($request,$response); + } + + protected function _headimages() { + // This is where we should be able to change our country + // @todo To implement + $co = Config::country(); + /* + HeadImages::add(array( + 'img'=>sprintf('img/country/%s.png',strtolower($co->two_code)), + 'attrs'=>array('onclick'=>"target='_blank';",'title'=>$co->display('name')) + )); + */ + + return HeadImages::factory(); + } + + protected function _left() { + if ($this->template->left) + return $this->template->left; + + elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) + return Controller_Tree::js(); + } + + protected function _right() { + return empty($this->template->right) ? '' : $this->template->right; + } +} +?> diff --git a/application/classes/database/ldap.php b/application/classes/Database/LDAP.php similarity index 100% rename from application/classes/database/ldap.php rename to application/classes/Database/LDAP.php diff --git a/application/classes/database/ldap/search.php b/application/classes/Database/LDAP/Search.php similarity index 100% rename from application/classes/database/ldap/search.php rename to application/classes/Database/LDAP/Search.php diff --git a/application/classes/database/ldap/search/builder/query.php b/application/classes/Database/LDAP/Search/Builder/Query.php similarity index 100% rename from application/classes/database/ldap/search/builder/query.php rename to application/classes/Database/LDAP/Search/Builder/Query.php diff --git a/application/classes/pla/auth/ldap.php b/application/classes/PLA/Auth/Ldap.php similarity index 98% rename from application/classes/pla/auth/ldap.php rename to application/classes/PLA/Auth/Ldap.php index 0b64e03..ff1eafb 100644 --- a/application/classes/pla/auth/ldap.php +++ b/application/classes/PLA/Auth/Ldap.php @@ -9,7 +9,7 @@ * @copyright (c) phpLDAPadmin Development Team * @license http://dev.phpldapadmin.org/license.html */ -class PLA_Auth_LDAP extends Auth { +class PLA_Auth_Ldap extends Auth { // Unnused required abstract functions public function password($username) {} public function check_password($password) {} diff --git a/application/classes/pla/block.php b/application/classes/PLA/Block.php similarity index 62% rename from application/classes/pla/block.php rename to application/classes/PLA/Block.php index dc9e8d2..bcb0a0c 100644 --- a/application/classes/pla/block.php +++ b/application/classes/PLA/Block.php @@ -15,7 +15,6 @@ */ abstract class PLA_Block extends HTMLRender { protected static $_data = array(); - protected static $_spacer = '
 
'; protected static $_required_keys = array('body'); /** @@ -52,28 +51,13 @@ abstract class PLA_Block extends HTMLRender { */ protected function render() { $output = ''; - $styles = array(); - $i = 0; - foreach (static::$_data as $value) { - if ($i++) - $output .= static::$_spacer; - - $output .= ''; - - if (! empty($value['title'])) - $output .= sprintf('',$value['title']); - - if (! empty($value['subtitle'])) - $output .= sprintf('',$value['subtitle']); - - $output .= sprintf('',$value['body']); - - if (! empty($value['footer'])) - $output .= sprintf('',$value['footer']); - - $output .= '
%s
%s
%s
'; - } + foreach (static::$_data as $value) + $output .= View::factory(Kohana::Config('config.theme').'/block') + ->set('title',empty($value['title']) ? '' : $value['title']) + ->set('subtitle',empty($value['subtitle']) ? '' : $value['subtitle']) + ->set('body',empty($value['body']) ? '' : $value['body']) + ->set('footer',empty($value['footer']) ? '' : $value['footer']); return $output; } diff --git a/application/classes/pla/controller/template.php b/application/classes/PLA/Controller/Template.php similarity index 91% rename from application/classes/pla/controller/template.php rename to application/classes/PLA/Controller/Template.php index 4b189b1..6c5f7f6 100644 --- a/application/classes/pla/controller/template.php +++ b/application/classes/PLA/Controller/Template.php @@ -15,7 +15,7 @@ abstract class PLA_Controller_Template extends Kohana_Controller_Template { private $meta; public function __construct(Request $request, Response $response) { - $this->template = Kohana::Config('config.theme'); + $this->template = Kohana::$config->load('config')->theme; return parent::__construct($request,$response); } @@ -38,14 +38,14 @@ abstract class PLA_Controller_Template extends Kohana_Controller_Template { $this->template->content = ''; // Setup the page template - $this->meta = new meta; + $this->meta = new Meta; View::bind_global('meta',$this->meta); } public function after() { if ($this->auto_render === TRUE) { // Application Title - $this->meta->title = Kohana::Config('config.appname'); + $this->meta->title = Kohana::$config->load('config')->appname; // Language // @todo @@ -80,7 +80,6 @@ abstract class PLA_Controller_Template extends Kohana_Controller_Template { // Our default script(s) foreach (array('file'=>array_reverse(array( - 'js/jquery-1.6.4.min.js', ))) as $type => $datas) { foreach ($datas as $data) { @@ -91,12 +90,6 @@ abstract class PLA_Controller_Template extends Kohana_Controller_Template { } } - // Add our logo - Style::add(array( - 'type'=>'stdin', - 'data'=>'h1 span{background:url('.Config::logo_uri().') no-repeat;}', - )); - // For any ajax rendered actions, we'll need to capture the content and put it in the response // @todo } elseif ($this->request->is_ajax() && isset($this->template->content) && ! $this->response->body()) { diff --git a/application/classes/pla/database/ldap.php b/application/classes/PLA/Database/LDAP.php similarity index 100% rename from application/classes/pla/database/ldap.php rename to application/classes/PLA/Database/LDAP.php diff --git a/application/classes/pla/database/ldap/search.php b/application/classes/PLA/Database/LDAP/Search.php similarity index 100% rename from application/classes/pla/database/ldap/search.php rename to application/classes/PLA/Database/LDAP/Search.php diff --git a/application/classes/pla/database/ldap/search/builder/query.php b/application/classes/PLA/Database/LDAP/Search/Builder/Query.php similarity index 99% rename from application/classes/pla/database/ldap/search/builder/query.php rename to application/classes/PLA/Database/LDAP/Search/Builder/Query.php index 63c1c21..5905cf3 100644 --- a/application/classes/pla/database/ldap/search/builder/query.php +++ b/application/classes/PLA/Database/LDAP/Search/Builder/Query.php @@ -91,7 +91,7 @@ abstract class PLA_Database_LDAP_Search_Builder_Query extends Database_Query_Bui return $this; } - public function compile(Database $db) { + public function compile($db = NULL) { $filter = ''; return $this->_compile_conditions($db,$this->_where); diff --git a/application/classes/PLA/Exception.php b/application/classes/PLA/Exception.php new file mode 100644 index 0000000..959a29f --- /dev/null +++ b/application/classes/PLA/Exception.php @@ -0,0 +1,31 @@ +redirect('login'); + break; + + } + + echo debug::vars(array('m'=>$message,'v'=>$variables,'c'=>$code,'t'=>$this));die(); + } + + public function __toString() { + echo __METHOD__;die(); + } +} +?> diff --git a/application/classes/PLA/SystemMessage.php b/application/classes/PLA/SystemMessage.php new file mode 100644 index 0000000..3492919 --- /dev/null +++ b/application/classes/PLA/SystemMessage.php @@ -0,0 +1,65 @@ +$media) + Style::add(array( + 'type'=>'file', + 'data'=>$data, + 'media'=>$media, + )); + } + + /** + * Return an instance of this class + * + * @return Block + */ + public static function factory() { + return new SystemMessage; + } + + /** + * Render this block + * + * @see HTMLRender::render() + */ + protected function render() { + $output = ''; + + foreach (static::$_data as $value) + $output .= View::factory(Kohana::Config('config.theme').'/block') + ->set('title',empty($value['title']) ? '' : $value['title']) + ->set('subtitle',empty($value['subtitle']) ? '' : $value['subtitle']) + ->set('body',empty($value['body']) ? '' : $value['body']) + ->set('footer',empty($value['footer']) ? '' : $value['footer']); + + return $output; + } +} +?> diff --git a/application/classes/config.php b/application/classes/SystemMessage.php similarity index 57% rename from application/classes/config.php rename to application/classes/SystemMessage.php index 65daaae..bf43e7e 100644 --- a/application/classes/config.php +++ b/application/classes/SystemMessage.php @@ -1,4 +1,4 @@ diff --git a/application/classes/URL.php b/application/classes/URL.php new file mode 100644 index 0000000..a62c98e --- /dev/null +++ b/application/classes/URL.php @@ -0,0 +1,51 @@ +'', + ); + + /** + * Wrapper to provide a URL::site() link based on function + */ + public static function link($dir,$src,$site=FALSE) { + if (! $dir) + return $src; + + if (! array_key_exists($dir,URL::$method_directory)) + throw new Kohana_Exception('Unknown directory :dir for :src',array(':dir'=>$dir,':src'=>$src)); + + $x = URL::$method_directory[$dir].'/'.$src; + + return $site ? URL::site($x) : $x; + } + + /** + * Function to reveal the real directory for a URL + */ + public static function dir($dir) { + // Quick check if we can do something here + if (! in_array(strtolower($dir),URL::$method_directory)) + return $dir; + + // OK, we can, find it. + foreach (URL::$method_directory as $k=>$v) + if (strtolower($dir) == $v) + return ucfirst($k); + + // If we get here, we didnt have anything. + return $dir; + } +} +?> diff --git a/application/classes/controller/login.php b/application/classes/controller/login.php deleted file mode 100644 index f0c1b01..0000000 --- a/application/classes/controller/login.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/classes/controller/logout.php b/application/classes/controller/logout.php deleted file mode 100644 index b60b0ee..0000000 --- a/application/classes/controller/logout.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/classes/controller/media.php b/application/classes/controller/media.php deleted file mode 100644 index 53bdf41..0000000 --- a/application/classes/controller/media.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/classes/htmlrender.php b/application/classes/htmlrender.php deleted file mode 100644 index ed9c6a0..0000000 --- a/application/classes/htmlrender.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/classes/meta.php b/application/classes/meta.php deleted file mode 100644 index 8750207..0000000 --- a/application/classes/meta.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/classes/pla/config.php b/application/classes/pla/config.php deleted file mode 100644 index 2c0e5b4..0000000 --- a/application/classes/pla/config.php +++ /dev/null @@ -1,105 +0,0 @@ -'Production', - Kohana::STAGING=>'Staging', - Kohana::TESTING=>'Testing', - Kohana::DEVELOPMENT=>'Development', - ); - - return (! isset($modes[static::sitemode()])) ? 'Unknown' : $modes[static::sitemode()]; - } - - public static function submode() { - $submode = Kohana::Config('config.debug.submode'); - - return (isset($submode[Request::$client_ip])) ? $submode[Request::$client_ip] : FALSE; - } - - public static function sitename() { - return Kohana::Config('config.site.name'); - } - - // Called in Invoice/Emailing to embed the file. - public static function logo_file() { - list ($path,$suffix) = explode('.',static::$logo); - return Kohana::find_file(sprintf('media/%s',Config::siteid()),$path,$suffix); - } - - public static function logo_uri() { - list ($path,$suffix) = explode('.',static::$logo); - return URL::site(Route::get('default/media')->uri(array('file'=>$path.'.'.$suffix),array('alt'=>static::sitename())),'http'); - } - - public static function logo() { - return HTML::image(static::logo_uri(),array('class'=>'headlogo','alt'=>_('Logo'))); - } - - public static function login_uri() { - return ($ao = Auth::instance()->get_user()) ? $ao->name() : HTML::anchor('login',_('Login')); - } - - public static function copywrite() { - return '(c) phpLDAPadmin Development Team'; - } - - /** - * Return our caching mechanism - */ - public static function cachetype() { - return is_null(Kohana::config('config.cache_type')) ? 'file' : Kohana::config('config.cache_type'); - } -} -?> diff --git a/application/classes/pla/controller/login.php b/application/classes/pla/controller/login.php deleted file mode 100644 index a361c7b..0000000 --- a/application/classes/pla/controller/login.php +++ /dev/null @@ -1,200 +0,0 @@ -logged_in()!= 0) { - // Redirect to the user account - Request::current()->redirect('user/welcome'); - } - - // If there is a post and $_POST is not empty - if ($_POST) { -//echo debug::vars(array('p'=>$_POST,'ai'=>Auth::instance()));die(); - // Store our details in a session key - Session::instance()->set('login',$_POST['username']); - Session::instance()->set('password',$_POST['password']); - - // If the post data validates using the rules setup in the user model - if (Auth::instance()->login($_POST['username'],$_POST['password'])) { - // Redirect to the user account - if ($redir = Session::instance()->get('afterlogin')) { - Session::instance()->delete('afterlogin'); - Request::current()->redirect($redir); - - } else - Request::current()->redirect('user/welcome'); - - } else { - SystemMessage::add(array( - 'title'=>_('Invalid username or password'), - 'type'=>'error', - 'body'=>_('The username or password was invalid.') - )); - } - } - - Block::add(array( - 'title'=>_('Login to server'), - 'body'=>View::factory('login'), - 'style'=>array('css/login.css'=>'screen'), - )); - - Script::add(array('type'=>'stdin','data'=>' - $(document).ready(function() { - $("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;}); - });' - )); - } - - public function action_register() { - // If user already signed-in - if (Auth::instance()->logged_in()!= 0) { - // Redirect to the user account - Request::current()->redirect('welcome/index'); - } - - // Instantiate a new user - $account = ORM::factory('account'); - - // If there is a post and $_POST is not empty - if ($_POST) { - // Check Auth - $status = $account->values($_POST)->check(); - - if (! $status) { - foreach ($account->validation()->errors('form/register') as $f => $r) { - // $r[0] has our reason for validation failure - switch ($r[0]) { - // Generic validation reason - default: - SystemMessage::add(array( - 'title'=>_('Validation failed'), - 'type'=>'error', - 'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r) - )); - } - } - } - - $ido = ORM::factory('module') - ->where('name','=','account') - ->find(); - - $account->id = $ido->record_id->next_id($ido->id); - // Save the user details - if ($account->save()) {} - - } - - SystemMessage::add(array( - 'title'=>_('Already have an account?'), - 'type'=>'info', - 'body'=>_('If you already have an account, please login..') - )); - - Block::add(array( - 'title'=>_('Register'), - 'body'=>View::factory('bregister') - ->set('account',$account) - ->set('errors',$account->validation()->errors('form/register')), - )); - - $this->template->left = HTML::anchor('login','Login').'...'; - } - - /** - * Enable user password reset - */ - public function action_reset() { - // If user already signed-in - if (Auth::instance()->logged_in()!= 0) { - // Redirect to the user account - Request::current()->redirect('welcome/index'); - } - - // If the user posted their details to reset their password - if ($_POST) { - // If the email address is correct, create a method token - if (! empty($_POST['email']) AND ($ao=ORM::factory('account',array('email'=>$_POST['email']))) AND $ao->loaded()) { - $mt = ORM::factory('module_method_token'); - - // Find out our password reset method id - // @todo move this to a more generic method, so that it can be called by other methods - $mo = ORM::factory('module',array('name'=>'account')); - $mmo = ORM::factory('module_method',array('name'=>'user_resetpassword','module_id'=>$mo->id)); - - // Check to see if there is already a token, if so, do nothing. - if ($mt->where('account_id','=',$ao->id)->and_where('method_id','=',$mmo->id)->find()) { - if ($mt->date_expire < time()) { - $mt->delete(); - $mt->clear(); - } - } - - if (! $mt->loaded()) { - $mt->account_id = $ao->id; - $mt->method_id = $mmo->id; - $mt->date_expire = time() + 15*3600; - $mt->token = md5(sprintf('%s:%s:%s',$mt->account_id,$mt->method_id,$mt->date_expire)); - $mt->save(); - - // Send our email with the token - $et = EmailTemplate::instance('account_reset_password'); - $et->to = array($mt->account->email=>sprintf('%s %s',$mt->account->first_name,$mt->account->last_name)); - $et->variables = array( - 'SITE'=>URL::base(TRUE,TRUE), - 'SITE_ADMIN'=>Config::sitename(), - 'SITE_NAME'=>Config::sitename(), - 'TOKEN'=>$mt->token, - 'USER_NAME'=>sprintf('%s %s',$mt->account->first_name,$mt->account->last_name), - ); - $et->send(); - } - - // Redirect to our password reset, the Auth will validate the token. - } elseif (! empty($_REQUEST['token'])) { - Request::current()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token'])); - } - - // Show our token screen even if the email was invalid. - if (isset($_POST['email'])) - Block::add(array( - 'title'=>_('Reset your password'), - 'body'=>View::factory('login_reset_sent'), - 'style'=>array('css/login.css'=>'screen'), - )); - else - Request::current()->redirect('login'); - - } else { - Block::add(array( - 'title'=>_('Reset your password'), - 'body'=>View::factory('login_reset'), - 'style'=>array('css/login.css'=>'screen'), - )); - } - } - - public function action_noaccess() { - SystemMessage::add(array( - 'title'=>_('No access to requested resource'), - 'type'=>'error', - 'body'=>_('You do not have access to the requested resource, please contact your administrator.') - )); - } -} -?> diff --git a/application/classes/pla/controller/logout.php b/application/classes/pla/controller/logout.php deleted file mode 100644 index ded76b5..0000000 --- a/application/classes/pla/controller/logout.php +++ /dev/null @@ -1,26 +0,0 @@ -logged_in()!= 0) { - Auth::instance()->logout(); - - Request::current()->redirect('login'); - } - - Request::current()->redirect('welcome/index'); - } -} -?> diff --git a/application/classes/pla/controller/media.php b/application/classes/pla/controller/media.php deleted file mode 100644 index 9413a08..0000000 --- a/application/classes/pla/controller/media.php +++ /dev/null @@ -1,59 +0,0 @@ -request->param('file'); - - // Find the file extension - $ext = pathinfo($file,PATHINFO_EXTENSION); - - // Remove the extension from the filename - $file = substr($file,0,-(strlen($ext)+1)); - $f = ''; - - // If our file is pathed with session, our file is in our session. - if ($fd = Session::instance()->get_once($this->request->param('file'))) { - $this->response->body($fd); - - // If not found try a default media file - } elseif ($f = Kohana::find_file('media/'.Kohana::Config('config.theme'),$file,$ext)) { - // Send the file content as the response - $this->response->body(file_get_contents($f)); - - // If not found try a default media file - } elseif ($f = Kohana::find_file('media',$file,$ext)) { - // Send the file content as the response - $this->response->body(file_get_contents($f)); - - } else { - // Return a 404 status - $this->response->status(404); - } - - // Generate and check the ETag for this file - if (Kohana::$environment === Kohana::PRODUCTION) - $this->response->check_cache(NULL,$this->request); - - // Set the proper headers to allow caching - $this->response->headers('Content-Type',File::mime_by_ext($ext)); - $this->response->headers('Content-Length',(string)$this->response->content_length()); - $this->response->headers('Last-Modified',date('r', $f ? filemtime($f) : time())); - } -} -?> diff --git a/application/classes/pla/htmlrender.php b/application/classes/pla/htmlrender.php deleted file mode 100644 index 5bf2100..0000000 --- a/application/classes/pla/htmlrender.php +++ /dev/null @@ -1,92 +0,0 @@ -get_called_class())); - } - - /** - * Add an item to be rendered - * - * @param array Item to be added - */ - public static function add($item,$prepend=FALSE) { - foreach (static::$_required_keys as $key) - if (! isset($item[$key])) - throw new Kohana_Exception('Missing key :key for image',array(':key'=>$key)); - - // Check for unique keys - if (static::$_unique_vals) - foreach (static::$_unique_vals as $v=>$u) - foreach (static::$_data as $d) - if (isset($d[$u]) && $d['data'] == $item['data']) - return; - - if ($prepend) - array_unshift(static::$_data,$item); - else - array_push(static::$_data,$item); - } - - /** - * Set the space used between rendering output - */ - public static function setSpacer($spacer) { - static::$_spacer = $spacer; - } - - /** - * Set the Kohana Media Path, used to determine where to find additional - * HTML content required for rendering. - */ - public static function setMediaPath($path) { - static::$_media_path = $path; - } - - /** - * Factory instance method must be declared by the child class - */ - public static function factory() { - throw new Kohana_Exception(':class is calling :method, when it should have its own method', - array(':class'=>get_called_class(),':method'=>__METHOD__)); - } - - /** - * Return the HTML to render the header images - */ - public function __toString() { - try { - return static::render(); - } - - // Display the exception message - catch (Exception $e) { - Kohana_Exception::handler($e); - } - } - - /** - * Rendering must be declared by the child class - */ - protected function render() { - throw new Kohana_Exception(':class is calling :method, when it should have its own method', - array(':class'=>get_called_class(),':method'=>__METHOD__)); - } -} -?> diff --git a/application/classes/pla/meta.php b/application/classes/pla/meta.php deleted file mode 100644 index f87c496..0000000 --- a/application/classes/pla/meta.php +++ /dev/null @@ -1,34 +0,0 @@ -_array_keys) && empty($this->_data[$key])) - return array(); - - if (empty($this->_data[$key])) - return null; - else - return $this->_data[$key]; - } - - public function __set($key,$value) { - if (in_array($key,$this->_array_keys) && ! is_array($value)) - throw new Kohana_Exception('Key :key must be an array',array(':key'=>$key)); - - $this->_data[$key] = $value; - } -} -?> diff --git a/application/classes/pla/script.php b/application/classes/pla/script.php deleted file mode 100644 index 00d8839..0000000 --- a/application/classes/pla/script.php +++ /dev/null @@ -1,53 +0,0 @@ -'type'); - - /** - * Return an instance of this class - * - * @return Script - */ - public static function factory() { - return new Script; - } - - /** - * Render the script tag - * - * @see HTMLRender::render() - */ - protected function render() { - $foutput = $soutput = ''; - $mediapath = Route::get(static::$_media_path); - - foreach (static::$_data as $value) { - switch ($value['type']) { - case 'file': - $foutput .= HTML::script($mediapath->uri(array('file'=>$value['data']))); - break; - case 'stdin': - $soutput .= sprintf("",$value['data']); - break; - default: - throw new Kohana_Exception('Unknown style type :type',array(':type'=>$value['type'])); - } - } - - return $foutput.static::$_spacer.$soutput; - } -} -?> diff --git a/application/classes/pla/style.php b/application/classes/pla/style.php deleted file mode 100644 index 29abd5e..0000000 --- a/application/classes/pla/style.php +++ /dev/null @@ -1,54 +0,0 @@ -'type'); - - /** - * Return an instance of this class - * - * @return Style - */ - public static function factory() { - return new Style; - } - - /** - * Render the style tag - * - * @see HTMLRender::render() - */ - protected function render() { - $foutput = $soutput = ''; - $mediapath = Route::get(static::$_media_path); - - foreach (static::$_data as $value) { - switch ($value['type']) { - case 'file': - $foutput .= HTML::style($mediapath->uri(array('file'=>$value['data'])), - array('media'=>(! empty($value['media'])) ? $value['media'] : 'screen'),TRUE); - break; - case 'stdin': - $soutput .= sprintf("",$value['data']); - break; - default: - throw new Kohana_Exception('Unknown style type :type',array(':type'=>$value['type'])); - } - } - - return $foutput.static::$_spacer.$soutput; - } -} -?> diff --git a/application/classes/script.php b/application/classes/script.php deleted file mode 100644 index 676a71a..0000000 --- a/application/classes/script.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/classes/style.php b/application/classes/style.php deleted file mode 100644 index e5a03bf..0000000 --- a/application/classes/style.php +++ /dev/null @@ -1,4 +0,0 @@ - diff --git a/application/config/auth.php b/application/config/auth.php index 6bc0cd8..d91bdac 100644 --- a/application/config/auth.php +++ b/application/config/auth.php @@ -17,5 +17,6 @@ return array( 'lifetime' => 1209600, // 'session_key' => 'auth_user', // 'forced_key' => 'auth_forced', + 'pwreset' => FALSE, ); ?> diff --git a/application/config/config.php b/application/config/config.php index 034e13b..136b4af 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -10,15 +10,14 @@ * @copyright (c) phpLDAPadmin Development Team * @license http://dev.phpldapadmin.org/license.html */ + return array( - // Our application name, as shown in the title bar of pages - 'appname' => 'phpLDAPadmin - LDAP Administration', + 'appname' => 'phpLDAPadmin - LDAP Administration', // Our application name, as shown in the title bar of pages + 'method_security' => FALSE, // Enables Method Security. Setting to false means any method can be run without authentication // Our mode level (PRODUCTION, STAGING, TESTING, DEVELOPMENT) - see [Kohana] 'mode' => Kohana::PRODUCTION, - 'site' => array( - 'name'=>'phpLDAPadmin', - ), // Our custom theme - 'theme' => 'original', + 'loginpage' => 'welcome', + 'theme' => 'claro', ); ?> diff --git a/application/config/debug.php b/application/config/debug.php new file mode 100644 index 0000000..534ff36 --- /dev/null +++ b/application/config/debug.php @@ -0,0 +1,24 @@ +FALSE, // AJAX actions can only be run by ajax calls if set to FALSE + 'etag'=>FALSE, // Force generating ETAGS + 'checkout_notify'=>FALSE, // Test mode to test a particular checkout_notify item + 'invoice'=>0, // Number of invoices to generate in a pass + 'site'=>FALSE, // Glogal site debug + 'show_inactive'=>FALSE, // Show Inactive Items + 'task_sim'=>FALSE, // Simulate running tasks +); +?> diff --git a/application/config/userguide.php b/application/config/userguide.php new file mode 100644 index 0000000..57507b8 --- /dev/null +++ b/application/config/userguide.php @@ -0,0 +1,23 @@ + array( + + // This should be the path to this modules userguide pages, without the 'guide/'. Ex: '/guide/modulename/' would be 'modulename' + 'pla' => array( + + // Whether this modules userguide pages should be shown + 'enabled' => TRUE, + + // The name that should show up on the userguide index page + 'name' => 'phpLDAPadmin', + + // A short description of this module, shown on the index page + 'description' => 'phpLDAPadmin API guide.', + + // Copyright message, shown in the footer for this module + 'copyright' => '© 2008–2010 phpLDAPadmin Developer Team', + ) + ) +); diff --git a/htdocs/images/favicon.ico b/application/media/img/favicon.ico similarity index 100% rename from htdocs/images/favicon.ico rename to application/media/img/favicon.ico diff --git a/htdocs/images/default/logo-small.png b/application/media/img/logo-small.png similarity index 100% rename from htdocs/images/default/logo-small.png rename to application/media/img/logo-small.png diff --git a/application/media/notimplemented.txt b/application/media/notimplemented.txt new file mode 100644 index 0000000..a594f2d --- /dev/null +++ b/application/media/notimplemented.txt @@ -0,0 +1 @@ +This hasnt been implemented yet! diff --git a/htdocs/images/default/key.png b/application/media/theme/claro/css/image/key.png similarity index 100% rename from htdocs/images/default/key.png rename to application/media/theme/claro/css/image/key.png diff --git a/htdocs/images/default/ldap-uid.png b/application/media/theme/claro/css/image/ldap-uid.png similarity index 100% rename from htdocs/images/default/ldap-uid.png rename to application/media/theme/claro/css/image/ldap-uid.png diff --git a/application/media/theme/claro/css/style.css b/application/media/theme/claro/css/style.css new file mode 100644 index 0000000..5ce03ab --- /dev/null +++ b/application/media/theme/claro/css/style.css @@ -0,0 +1,95 @@ +html, body { + height: 100%; + margin: 0; + overflow: hidden; + padding: 0; +} + +.claro #appLayout { + height: 100%; +} +.claro #appHeader { + border: 0px; + padding-bottom: 0px; +} +.claro #appControl { + border-top: 1px #AAAACC solid; + border-bottom: 0; + border-left: 0; + border-right: 0; + padding-top: 5px; + padding-bottom: 0; +} +.claro #appLeft { + border: 1px #AAAACC solid; + width: 14em; +} +.claro #appBody { + border: 1px #AAAACC solid; + padding: 0; +} +.claro #appStatus { + display: none; +} +.claro #appContent { + border: 0; + padding: 0; +} +.claro #appFooter { + border-top: 1px #AAAACC solid; + border-bottom: 0; + border-left: 0; + border-right: 0; + padding-top: 3px; + padding-bottom: 1px; +} + +.claro .headlogo { + border: 0px; +} +.claro .foottext { + text-align: right; + font-size: 75%; + font-weight: bold; +} +/* Login Box */ +.claro table.login { + background-color: #FAFAFF; + border: 1px #AAAACC solid; + padding: 5px; + margin-left: auto; + margin-right: auto; +} +.claro table.login .username { + background: url('image/ldap-uid.png') no-repeat 0 1px; + background-color: #FAFAFF; + color: #500000; + padding-left: 17px; +} + +.claro table.login .username:focus { + background-color: #F0F0FF; + color: #000000; +} + +.claro table.login .username:disabled { + background-color: #DDDDFF; + color: #000000; +} + +.claro table.login .password { + background: url('image/key.png') no-repeat 0 1px; + background-color: #FAFAFF; + color: #000000; + padding-left: 17px; +} + +.claro table.login .password:focus { + background-color: #F0F0FF; + color: #000000; +} + +.claro table.login .password:disabled { + background-color: #DDDDFF; + color: #000000; +} diff --git a/application/views/claro.php b/application/views/claro.php new file mode 100644 index 0000000..d568b1c --- /dev/null +++ b/application/views/claro.php @@ -0,0 +1,83 @@ + + + + + <?php echo $meta->title; ?> + + + + + + + + 'screen')); ?> + 'async: true, parseOnLoad: true')); ?> + 'screen')); ?> + + + + + + + + +
+
+ +
+
+ +
+
+ logged_in()) { ?> +
+
+
+
+
+
+
+
+ +
+
+
+
+ +
+ +
+ +
+
+
+
+ + diff --git a/application/views/claro/block.php b/application/views/claro/block.php new file mode 100644 index 0000000..02a7408 --- /dev/null +++ b/application/views/claro/block.php @@ -0,0 +1,3 @@ +
+ +
diff --git a/application/views/login.php b/application/views/login.php new file mode 100644 index 0000000..8cb656f --- /dev/null +++ b/application/views/login.php @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/index.php b/index.php index 716e607..c7bb26f 100644 --- a/index.php +++ b/index.php @@ -1,11 +1,131 @@ = 5.3, it is recommended to disable + * deprecated notices. Disable with: E_ALL & ~E_DEPRECATED + */ +error_reporting(E_ALL | E_STRICT); + +/** + * End of standard configuration! Changing any of the code below should only be + * attempted by those with a working knowledge of Kohana internals. + * + * @link http://kohanaframework.org/guide/using.configuration */ -# You should secure your PLA by making the htdocs/ your docroot. -header('Location: htdocs/index.php'); -die(); -?> +// Set the full path to the docroot +define('DOCROOT', realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR); + +// Make the application relative to the docroot, for symlink'd index.php +if ( ! is_dir($application) AND is_dir(DOCROOT.$application)) + $application = DOCROOT.$application; + +// Make the modules relative to the docroot, for symlink'd index.php +if ( ! is_dir($modules) AND is_dir(DOCROOT.$modules)) + $modules = DOCROOT.$modules; + +// Make the system relative to the docroot, for symlink'd index.php +if ( ! is_dir($sysmodules) AND is_dir(DOCROOT.$sysmodules)) + $sysmodules = DOCROOT.$sysmodules; + +// Make the system relative to the docroot, for symlink'd index.php +if ( ! is_dir($system) AND is_dir(DOCROOT.$system)) + $system = DOCROOT.$system; + +// Define the absolute paths for configured directories +define('APPPATH', realpath($application).DIRECTORY_SEPARATOR); +define('MODPATH', realpath($modules).DIRECTORY_SEPARATOR); +define('SMDPATH', realpath($sysmodules).DIRECTORY_SEPARATOR); +define('SYSPATH', realpath($system).DIRECTORY_SEPARATOR); + +// Clean up the configuration vars +unset($application, $modules, $sysmodules, $system); + +if (file_exists('install'.EXT)) +{ + // Load the installation check + return include 'install'.EXT; +} + +/** + * Define the start time of the application, used for profiling. + */ +if ( ! defined('KOHANA_START_TIME')) +{ + define('KOHANA_START_TIME', microtime(TRUE)); +} + +/** + * Define the memory usage at the start of the application, used for profiling. + */ +if ( ! defined('KOHANA_START_MEMORY')) +{ + define('KOHANA_START_MEMORY', memory_get_usage()); +} + +// Bootstrap the application +require APPPATH.'bootstrap'.EXT; + +if (PHP_SAPI == 'cli') // Try and load minion +{ + class_exists('Minion_Task') OR die('Please enable the Minion module for CLI support.'); + set_exception_handler(array('Minion_Exception', 'handler')); + + Minion_Task::factory(Minion_CLI::options())->execute(); +} +else +{ + /** + * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO']. + * If no source is specified, the URI will be automatically detected. + */ + echo Request::factory(TRUE, array(), FALSE) + ->execute() + ->send_headers(TRUE) + ->body(); +}