Inclusion of lnauth module
This commit is contained in:
parent
b74fdc930f
commit
34e1e40f04
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -7,3 +7,6 @@
|
|||||||
[submodule "modules/lnapp"]
|
[submodule "modules/lnapp"]
|
||||||
path = modules/lnapp
|
path = modules/lnapp
|
||||||
url = git@dev.leenooks.net:deon/lnapp.git
|
url = git@dev.leenooks.net:deon/lnapp.git
|
||||||
|
[submodule "modules/lnauth"]
|
||||||
|
path = modules/lnauth
|
||||||
|
url = git@dev.leenooks.net:deon/lnauth.git
|
||||||
|
@ -131,6 +131,7 @@ Kohana::$config->attach(new Config_File);
|
|||||||
*/
|
*/
|
||||||
Kohana::modules(array(
|
Kohana::modules(array(
|
||||||
'oauth' => MODPATH.'oauth', // OAuth Module for External Authentication
|
'oauth' => MODPATH.'oauth', // OAuth Module for External Authentication
|
||||||
|
'lnauth' => MODPATH.'lnauth', // lnAuth Base Authentication Tools
|
||||||
'lnapp' => MODPATH.'lnapp', // lnApp Base Application Tools
|
'lnapp' => MODPATH.'lnapp', // lnApp Base Application Tools
|
||||||
'auth' => SMDPATH.'auth', // Basic authentication
|
'auth' => SMDPATH.'auth', // Basic authentication
|
||||||
'cache' => SMDPATH.'cache', // Caching with multiple backends
|
'cache' => SMDPATH.'cache', // Caching with multiple backends
|
||||||
|
@ -1,197 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides MODULE management
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Controllers/Admin
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Controller_Admin_Module extends Controller_Module {
|
|
||||||
protected $secure_actions = array(
|
|
||||||
'add'=>TRUE,
|
|
||||||
'edit'=>TRUE,
|
|
||||||
'list'=>TRUE,
|
|
||||||
);
|
|
||||||
|
|
||||||
protected function _classes($dir,$class,$array=NULL,$key='') {
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
if (is_null($array)) {
|
|
||||||
$array = Kohana::list_files('classes');
|
|
||||||
$array = $array['classes/Controller'];
|
|
||||||
$key = 'classes/Controller';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! $class)
|
|
||||||
return array_keys($array);
|
|
||||||
|
|
||||||
if (! $dir) {
|
|
||||||
if (! empty($array[$key.'/'.$class]))
|
|
||||||
$result = Arr::merge($result,$this->_classes('','',$array[$key.'/'.$class],$key.'/'.$class));
|
|
||||||
|
|
||||||
if (! empty($array[$key.'/'.$class.'.php']))
|
|
||||||
array_push($result,$key.'/'.$class);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (! empty($array[$key.'/'.$dir]))
|
|
||||||
$result = Arr::merge($result,$this->_classes('',$class,$array[$key.'/'.$dir],$key.'/'.$dir));
|
|
||||||
|
|
||||||
if (! empty($array[$key.'/'.$dir.'/'.$class.'.php']))
|
|
||||||
array_push($result,$key.'/'.$dir.'/'.$class);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($result as $k=>$v)
|
|
||||||
$result[$k] = str_replace('.php','',str_replace('/','_',preg_replace('/^classes\//','',$v)));
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the list of methods for a class
|
|
||||||
*/
|
|
||||||
protected function _methods($class) {
|
|
||||||
$class = Kohana::classname($class);
|
|
||||||
// Get a list of methods this module has
|
|
||||||
$methods = $secure_actions = $auth_required = array();
|
|
||||||
|
|
||||||
// List of classes where all our methods are, including this one.
|
|
||||||
$classes = URL::$method_directory;
|
|
||||||
array_unshift($classes,'');
|
|
||||||
|
|
||||||
foreach ($classes as $c) {
|
|
||||||
$x = URL::dir($c);
|
|
||||||
$cp = $this->_classes($x,$class);
|
|
||||||
|
|
||||||
foreach ($cp as $cn)
|
|
||||||
if (class_exists($cn)) {
|
|
||||||
$sc = preg_replace(sprintf('/^Controller_%s%s_?/',$x ? $x.'_' : '',$class),'',$cn);
|
|
||||||
$r = new ReflectionClass($cn);
|
|
||||||
|
|
||||||
$rdp = $r->getDefaultProperties();
|
|
||||||
$secure_actions[$cn] = $rdp['secure_actions'];
|
|
||||||
$auth_required[$cn] = $rdp['auth_required'];
|
|
||||||
|
|
||||||
foreach ($r->getMethods() as $method)
|
|
||||||
if (preg_match('/^action_/',$method->name))
|
|
||||||
array_push($methods,
|
|
||||||
str_replace('action_',
|
|
||||||
#strtolower(($x ? $x.'_' : '').($sc ? $sc.'_' : '')),
|
|
||||||
strtolower($x.($sc ? '_'.$sc : '').':'),
|
|
||||||
$method->name)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return array('methods'=>$methods,'secure_actions'=>$secure_actions,'auth_required'=>$auth_required);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit a Module Configuration
|
|
||||||
*/
|
|
||||||
public function action_edit() {
|
|
||||||
$id = $this->request->param('id');
|
|
||||||
$mo = ORM::factory('Module',$id);
|
|
||||||
|
|
||||||
$this->meta->title = 'Module: '.$mo->name();
|
|
||||||
|
|
||||||
$methods = array();
|
|
||||||
|
|
||||||
if (! $mo->loaded()) {
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title(_('Invalid Module ID'))
|
|
||||||
->type('error')
|
|
||||||
->body(sprintf(_('Module with ID %s doesnt appear to exist?'),$id));
|
|
||||||
|
|
||||||
HTTP::redirect(URL::link('admin','module/list'));
|
|
||||||
}
|
|
||||||
|
|
||||||
$mm = $this->_methods($mo->name);
|
|
||||||
$methods['exist'] = array();
|
|
||||||
foreach ($mo->module_method->find_all() as $mmo) {
|
|
||||||
if (in_array($mmo->name,$mm['methods'])) {
|
|
||||||
$k = array_search($mmo->name,$mm['methods']);
|
|
||||||
unset($mm['methods'][$k]);
|
|
||||||
|
|
||||||
$mmo->status('INDB');
|
|
||||||
} else
|
|
||||||
$mmo->status('ORPHAN');
|
|
||||||
|
|
||||||
if (! empty($mm['secure_actions'][$mmo->controller()][$mmo->method()]))
|
|
||||||
unset($mm['secure_actions'][$mmo->controller()][$mmo->method()]);
|
|
||||||
|
|
||||||
array_push($methods['exist'],$mmo);
|
|
||||||
}
|
|
||||||
|
|
||||||
$methods['missing'] = array();
|
|
||||||
foreach ($mm['methods'] as $k=>$method) {
|
|
||||||
$mmo = ORM::factory('Module_Method');
|
|
||||||
$mmo->module_id = $mo->id;
|
|
||||||
$mmo->name = $method;
|
|
||||||
|
|
||||||
if (! empty($mm['auth_required'][$mmo->controller()]) AND $mm['auth_required'][$mmo->controller()])
|
|
||||||
$mmo->status('MISSING');
|
|
||||||
|
|
||||||
array_push($methods['missing'],$mmo);
|
|
||||||
}
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf('%s: %s ',_('Defined Module Methods For'),$mo->display('name')))
|
|
||||||
->title_icon('fa fa-cog')
|
|
||||||
->body(Table::factory()
|
|
||||||
->data($methods['exist'])
|
|
||||||
->columns(array(
|
|
||||||
'id'=>'ID',
|
|
||||||
'name'=>'Name',
|
|
||||||
'notes'=>'Notes',
|
|
||||||
'menu_display'=>'Menu',
|
|
||||||
'status()'=>'Status',
|
|
||||||
))
|
|
||||||
->prepend(array(
|
|
||||||
'id'=>array('url'=>URL::link('admin','module_method/edit/')),
|
|
||||||
))
|
|
||||||
);
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf('%s: %s ',_('Missing Module Methods For'),$mo->display('name')))
|
|
||||||
->title_icon('fa fa-question')
|
|
||||||
->body(Table::factory()
|
|
||||||
->data($methods['missing'])
|
|
||||||
->columns(array(
|
|
||||||
'name'=>'Name',
|
|
||||||
'status()'=>'Status',
|
|
||||||
))
|
|
||||||
->prepend(array(
|
|
||||||
'name'=>array('url'=>URL::link('admin','module_method/add/'.$mo->id.'/')),
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List our installed modules
|
|
||||||
*/
|
|
||||||
public function action_list() {
|
|
||||||
$this->meta->title = 'Module List';
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title('Defined Modules')
|
|
||||||
->title_icon('fa fa-cog')
|
|
||||||
->body(Table::factory()
|
|
||||||
->data(ORM::factory('Module')->where('parent_id','is',NULL)->find_all())
|
|
||||||
->jssort(TRUE)
|
|
||||||
->columns(array(
|
|
||||||
'id'=>'ID',
|
|
||||||
'name'=>'Name',
|
|
||||||
'notes'=>'Notes',
|
|
||||||
'status'=>'Active',
|
|
||||||
'external'=>'External',
|
|
||||||
))
|
|
||||||
->prepend(array(
|
|
||||||
'id'=>array('url'=>URL::link('admin','module/edit/')),
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,107 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides MODULE management
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Controllers/Admin
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Controller_Admin_Module_Method extends Controller_Admin_Module {
|
|
||||||
/**
|
|
||||||
* Add a method to the database
|
|
||||||
*/
|
|
||||||
public function action_add() {
|
|
||||||
$id = $this->request->param('id');
|
|
||||||
$method = $this->request->param('sid');
|
|
||||||
|
|
||||||
$mo = ORM::factory('Module',$id);
|
|
||||||
$mm = $this->_methods($mo->name);
|
|
||||||
|
|
||||||
if (! $mo->loaded() OR ! in_array($method,$mm['methods']))
|
|
||||||
HTTP::redirect(URL::link('admin','module/list'));
|
|
||||||
|
|
||||||
if ($this->request->post()) {
|
|
||||||
$mmo = $mo->module_method;
|
|
||||||
$mmo->name = $method;
|
|
||||||
$mmo->module_id = $mo->id;
|
|
||||||
$mmo->values($this->request->post());
|
|
||||||
|
|
||||||
if (! $this->save($mmo))
|
|
||||||
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($this->request->post())));
|
|
||||||
|
|
||||||
HTTP::redirect(URL::link('admin','module/edit/'.$mo->id));
|
|
||||||
}
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf(_('Add Method (%s) to Database for (%s)'),strtoupper($method),strtoupper($mo->name)))
|
|
||||||
->title_icon('fa fa-plus')
|
|
||||||
->type('form-horizontal')
|
|
||||||
->body(View::factory('module/method/admin/add')
|
|
||||||
->set('name',$method)
|
|
||||||
->set('o',$mo)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit a Module Configuration
|
|
||||||
*/
|
|
||||||
public function action_edit() {
|
|
||||||
$id = $this->request->param('id');
|
|
||||||
$mmo = ORM::factory('Module_Method',$id);
|
|
||||||
|
|
||||||
if (! $mmo->loaded()) {
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title(_('Invalid Method ID'))
|
|
||||||
->type('error')
|
|
||||||
->body(sprintf(_('Method with ID %s doesnt appear to exist?'),$id));
|
|
||||||
|
|
||||||
HTTP::redirect(URL::link('admin','module/list'));
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->request->post()) {
|
|
||||||
$mmo->values($this->request->post());
|
|
||||||
|
|
||||||
if (! $this->save($mmo))
|
|
||||||
throw HTTP_Exception::factory(501,'Unable to save data :post',array(':post'=>serialize($this->request->post())));
|
|
||||||
|
|
||||||
foreach (ORM::factory('Group')->find_all() as $go) {
|
|
||||||
// If the group was defined and no longer
|
|
||||||
if ($mmo->has('group',$go) AND (! $this->request->post('groups') OR ! in_array($go->id,$this->request->post('groups')))) {
|
|
||||||
$gmo = ORM::factory('Group_Method',array('method_id'=>$mmo->id,'group_id'=>$go->id));
|
|
||||||
|
|
||||||
if (! $gmo->delete())
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title(_('Unable to DELETE Group Method'))
|
|
||||||
->type('error')
|
|
||||||
->body(sprintf(_('Unable to delete Group Method for method %s and group %s'),$mmo->name,$go->name));
|
|
||||||
|
|
||||||
// If the group was not defined and now is
|
|
||||||
} elseif (! $mmo->has('group',$go) AND $this->request->post('groups') AND in_array($go->id,$this->request->post('groups'))) {
|
|
||||||
$gmo = ORM::factory('Group_Method')
|
|
||||||
->values(array(
|
|
||||||
'method_id'=>$mmo->id,
|
|
||||||
'group_id'=>$go->id,
|
|
||||||
));
|
|
||||||
|
|
||||||
if (! $this->save($gmo))
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title(_('Unable to SAVE Group Method'))
|
|
||||||
->type('error')
|
|
||||||
->body(sprintf(_('Unable to save Group Method for method %s and group %s'),$mmo->name,$go->name));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HTTP::redirect(URL::link('admin','module/edit/'.$mmo->module_id));
|
|
||||||
}
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf(_('Configure access to method (%s::%s)'),$mmo->controller(),$mmo->method()))
|
|
||||||
->title_icon('fa fa-lock')
|
|
||||||
->type('form')
|
|
||||||
->body(View::factory('module/method/admin/edit')->set('o',$mmo));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,14 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides MODULE management
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Controllers
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Controller_Module extends Controller_TemplateDefault {
|
|
||||||
}
|
|
||||||
?>
|
|
@ -9,7 +9,7 @@
|
|||||||
* @copyright (c) 2009-2013 Open Source Billing
|
* @copyright (c) 2009-2013 Open Source Billing
|
||||||
* @license http://dev.osbill.net/license.html
|
* @license http://dev.osbill.net/license.html
|
||||||
*/
|
*/
|
||||||
abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefault {
|
abstract class Controller_TemplateDefault extends lnAuth_Controller_TemplateDefault {
|
||||||
protected $auth_required = TRUE;
|
protected $auth_required = TRUE;
|
||||||
|
|
||||||
protected function save(Model $o) {
|
protected function save(Model $o) {
|
||||||
@ -25,22 +25,5 @@ abstract class Controller_TemplateDefault extends lnApp_Controller_TemplateDefau
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function setup(array $config_items=array()) {
|
|
||||||
$mo = ORM::factory('Module',array('name'=>Request::current()->controller()));
|
|
||||||
if (! $mo->loaded())
|
|
||||||
throw HTTP_Exception::factory(501,'Unknown module :module',array(':module'=>Request::current()->controller()));
|
|
||||||
|
|
||||||
if ($this->request->post() AND array_key_exists($mo->id,$this->request->post('module_config')))
|
|
||||||
Config::instance()->module_config($mo->name,$this->request->post('module_config.'.$mo->id))->save();
|
|
||||||
|
|
||||||
if ($config_items) {
|
|
||||||
Block::factory()
|
|
||||||
->title('Update Module Configuration')
|
|
||||||
->title_icon('fa fa-wrench')
|
|
||||||
->type('form-horizontal')
|
|
||||||
->body(View::factory('setup/admin/module')->set('o',Company::instance()->so())->set('mid',$mo->id));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -1,104 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class provides User Account Update functions
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Controllers/User
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Controller_User_Account extends Controller_Account {
|
|
||||||
protected $secure_actions = array(
|
|
||||||
'edit'=>TRUE,
|
|
||||||
'resetpassword'=>TRUE,
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Enable User to Edit their Account Details
|
|
||||||
*/
|
|
||||||
public function action_edit() {
|
|
||||||
if ($this->request->post() AND $this->ao->values($this->request->post())->changed() AND (! $this->save($this->ao)))
|
|
||||||
$this->ao->reload();
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf('Account: %s',$this->ao->refnum()))
|
|
||||||
->title_icon('icon-wrench')
|
|
||||||
->type('form-horizontal')
|
|
||||||
->body(View::factory('account/user/edit')->set('o',$this->ao));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function action_resetpassword() {
|
|
||||||
if ($this->request->post()) {
|
|
||||||
$validation = Validation::factory($this->request->post())
|
|
||||||
->rule('password','not_empty')
|
|
||||||
->rule('password','min_length',array(':value',6))
|
|
||||||
->rule('password_confirm','matches',array(':validation',':field','password'));
|
|
||||||
|
|
||||||
// Store our new values
|
|
||||||
$this->ao->values($this->request->post());
|
|
||||||
|
|
||||||
if (! $validation->check())
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title(_('Record NOT updated'))
|
|
||||||
->type('error')
|
|
||||||
->body(_('Your password didnt pass validation.'));
|
|
||||||
|
|
||||||
// Run validation and save
|
|
||||||
elseif ($this->ao->changed())
|
|
||||||
if ($this->ao->save()) {
|
|
||||||
SystemMessage::factory()
|
|
||||||
->title('Record updated')
|
|
||||||
->type('success')
|
|
||||||
->body(_('Your account record has been updated.'));
|
|
||||||
|
|
||||||
// Log the password reset
|
|
||||||
$this->ao->log('Password reset');
|
|
||||||
|
|
||||||
HTTP::redirect('login');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Kohana::$environment >= Kohana::TESTING OR Request::current()->secure())
|
|
||||||
Script::factory()
|
|
||||||
->type('src')
|
|
||||||
->data('media/js/jquery/jquery.validate-1.11.1.min.js');
|
|
||||||
else
|
|
||||||
Script::factory()
|
|
||||||
->type('src')
|
|
||||||
->data('http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js');
|
|
||||||
|
|
||||||
Script::factory()
|
|
||||||
->type('stdin')
|
|
||||||
->data('
|
|
||||||
$("#reset").validate({
|
|
||||||
wrapper: "div",
|
|
||||||
errorElement: "span",
|
|
||||||
|
|
||||||
rules: {
|
|
||||||
password_confirm: {
|
|
||||||
equalTo: "input[name=password]",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
highlight: function(element) {
|
|
||||||
$(element).parents(".control-group").removeClass("success").addClass("error");
|
|
||||||
},
|
|
||||||
success: function(element) {
|
|
||||||
$(element).parents(".control-group").removeClass("error").addClass("success");
|
|
||||||
},
|
|
||||||
errorPlacement: function(error, element) {
|
|
||||||
error.appendTo(element.parents(".controls"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
');
|
|
||||||
|
|
||||||
Block::factory()
|
|
||||||
->title(sprintf('Password Reset: %s',$this->ao->refnum()))
|
|
||||||
->title_icon('icon-cog')
|
|
||||||
->id('reset')
|
|
||||||
->type('form-horizontal')
|
|
||||||
->body(View::factory('account/user/resetpassword')->set('o',$this->ao));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,35 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class overrides Kohana's DB
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Modifications
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class DB extends Kohana_DB {
|
|
||||||
// Add the site_id to the delete query
|
|
||||||
final public static function delete($table = NULL)
|
|
||||||
{
|
|
||||||
$db = new Database_Query_Builder_Delete($table);
|
|
||||||
|
|
||||||
if (! in_array($table,ORM::$no_site_id_tables))
|
|
||||||
return $db->where($table.'.site_id','=',Company::instance()->site());
|
|
||||||
else
|
|
||||||
return $db;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the site_id to the update query
|
|
||||||
final public static function update($table = NULL)
|
|
||||||
{
|
|
||||||
$db = new Database_Query_Builder_Update($table);
|
|
||||||
|
|
||||||
if (! in_array($table,ORM::$no_site_id_tables))
|
|
||||||
return $db->where($table.'.site_id','=',Company::instance()->site());
|
|
||||||
else
|
|
||||||
return $db;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -19,6 +19,7 @@ class Kohana_Exception extends Kohana_Kohana_Exception {
|
|||||||
*/
|
*/
|
||||||
public static function log(Exception $e,$level=Log::EMERGENCY) {
|
public static function log(Exception $e,$level=Log::EMERGENCY) {
|
||||||
try {
|
try {
|
||||||
|
if (class_exists('Model_Log_Error')) {
|
||||||
$eo = ORM::factory('Log_Error');
|
$eo = ORM::factory('Log_Error');
|
||||||
$eo->message = Kohana_Exception::text($e);
|
$eo->message = Kohana_Exception::text($e);
|
||||||
$eo->account_id = (PHP_SAPI === 'cli' OR ! Auth::instance()->logged_in()) ? NULL : Auth::instance()->get_user()->id;
|
$eo->account_id = (PHP_SAPI === 'cli' OR ! Auth::instance()->logged_in()) ? NULL : Auth::instance()->get_user()->id;
|
||||||
@ -29,6 +30,7 @@ class Kohana_Exception extends Kohana_Kohana_Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$eo->save();
|
$eo->save();
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception $x) {
|
} catch (Exception $x) {
|
||||||
return parent::log($e,$level);
|
return parent::log($e,$level);
|
||||||
@ -48,11 +50,13 @@ class Kohana_Exception extends Kohana_Kohana_Exception {
|
|||||||
return parent::response($e);
|
return parent::response($e);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
if (class_exists('SystemMessage')) {
|
||||||
SystemMessage::add(array(
|
SystemMessage::add(array(
|
||||||
'title'=>'An Error Occured.',
|
'title'=>'An Error Occured.',
|
||||||
'type'=>'error',
|
'type'=>'error',
|
||||||
'body'=>'Dont panic, its been logged.',
|
'body'=>'Dont panic, its been logged.',
|
||||||
));
|
));
|
||||||
|
}
|
||||||
|
|
||||||
// We'll redirect to the main page.
|
// We'll redirect to the main page.
|
||||||
$response = Response::factory();
|
$response = Response::factory();
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class is used to create our Menu/Navbars
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Helpers
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Menu extends lnApp_Menu {
|
|
||||||
private static function collapse(array $array) {
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
foreach ($array as $mmo) {
|
|
||||||
if (isset($result[$mmo->module->name])) {
|
|
||||||
if (! is_array($result[$mmo->module->name]))
|
|
||||||
$result[$mmo->module->name] = array($result[$mmo->module->name]);
|
|
||||||
|
|
||||||
array_push($result[$mmo->module->name],$mmo);
|
|
||||||
|
|
||||||
continue;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
$result[$mmo->module->name] = $mmo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function items($type,array $list=array()) {
|
|
||||||
$result = array();
|
|
||||||
|
|
||||||
if (empty(URL::$method_directory[$type]))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
$ao = Auth::instance()->get_user();
|
|
||||||
|
|
||||||
if (is_object($ao))
|
|
||||||
foreach ($ao->methods() as $mmo)
|
|
||||||
if ($mmo->menu_display AND $type == $mmo->directory())
|
|
||||||
if (empty($result[$mmo->id]))
|
|
||||||
$result[$mmo->id] = $mmo;
|
|
||||||
|
|
||||||
return self::collapse($result);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function ul($type,array $result,array $append=NULL,$sub=FALSE,$method=NULL) {
|
|
||||||
$output = $sub ? '<ul class="dropdown-menu">' : '<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">';
|
|
||||||
|
|
||||||
foreach ($result as $k => $v)
|
|
||||||
if (is_array($v))
|
|
||||||
$output .= sprintf('<li class="dropdown-submenu">%s%s',HTML::anchor('#',$k,array('nocg'=>TRUE)),self::ul($type,$v,NULL,TRUE).'</li>');
|
|
||||||
else
|
|
||||||
$output .= '<li>'.HTML::anchor($v->url(),$v->menu_display(),array('tabindex'=>-1,'nocg'=>TRUE)).'</li>';
|
|
||||||
|
|
||||||
if ($append) {
|
|
||||||
$output .= '<li class="divider"></li>';
|
|
||||||
|
|
||||||
foreach ($append as $k => $v)
|
|
||||||
$output .= sprintf('<li>%s</li>',HTML::anchor($k,$v,array('nocg'=>TRUE)));
|
|
||||||
}
|
|
||||||
|
|
||||||
$output .= '</ul>';
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,27 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class supports Account Login Logging
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Models
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Model_Account_Log extends ORM {
|
|
||||||
protected $_belongs_to = array(
|
|
||||||
'account'=>array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $_sorting = array(
|
|
||||||
'id'=>'DESC',
|
|
||||||
);
|
|
||||||
|
|
||||||
protected $_display_filters = array(
|
|
||||||
'date_orig'=>array(
|
|
||||||
array('Site::Datetime',array(':value')),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,25 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OSB Application Module Method Model
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Models
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Model_Group_Method extends ORM {
|
|
||||||
// Relationships
|
|
||||||
protected $_has_one = array(
|
|
||||||
'record_id'=>array(),
|
|
||||||
);
|
|
||||||
protected $_belongs_to = array(
|
|
||||||
'group'=>array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// This module doesnt keep track of column updates automatically
|
|
||||||
protected $_created_column = FALSE;
|
|
||||||
protected $_updated_column = FALSE;
|
|
||||||
}
|
|
||||||
?>
|
|
@ -56,6 +56,10 @@ class Model_Module_Method extends ORM {
|
|||||||
return substr($this->name,0,substr_count($this->name,'_') ? strpos($this->name,'_') : strpos($this->name,':'));
|
return substr($this->name,0,substr_count($this->name,'_') ? strpos($this->name,'_') : strpos($this->name,':'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function method() {
|
||||||
|
return substr($this->name,strpos($this->name,':')+1);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the description for this method on any menu link
|
* Calculate the description for this method on any menu link
|
||||||
*/
|
*/
|
||||||
@ -67,10 +71,6 @@ class Model_Module_Method extends ORM {
|
|||||||
return sprintf('%s: %s',$this->module->name,$this->name);
|
return sprintf('%s: %s',$this->module->name,$this->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function method() {
|
|
||||||
return substr($this->name,strpos($this->name,':')+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function status($status=NULL) {
|
public function status($status=NULL) {
|
||||||
if ($status)
|
if ($status)
|
||||||
$this->status = $status;
|
$this->status = $status;
|
||||||
|
@ -1,112 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* OSB Application Module Method Token Model
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Models
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Model_Module_Method_Token extends ORM {
|
|
||||||
// This module doesnt keep track of column updates automatically
|
|
||||||
protected $_updated_column = FALSE;
|
|
||||||
|
|
||||||
// Relationships
|
|
||||||
protected $_belongs_to = array(
|
|
||||||
'account'=>array(),
|
|
||||||
'module_method'=>array('foreign_key'=>'method_id'),
|
|
||||||
);
|
|
||||||
protected $_has_one = array(
|
|
||||||
'record_id'=>array(),
|
|
||||||
);
|
|
||||||
|
|
||||||
public function method(array $modmeth) {
|
|
||||||
list($module,$method) = $modmeth;
|
|
||||||
|
|
||||||
if (! $method instanceof Model_Module_Method) {
|
|
||||||
if (is_numeric($module))
|
|
||||||
$mo = ORM::factory('Module',$module);
|
|
||||||
elseif (is_string($module))
|
|
||||||
$mo = ORM::factory('Module',array('name'=>$module));
|
|
||||||
elseif (! $module instanceof Model_Module)
|
|
||||||
throw new Kohana_Exception('Unknown module :module',array(':module'=>serialize($module)));
|
|
||||||
else
|
|
||||||
$mo = $module;
|
|
||||||
|
|
||||||
if (! $mo->loaded())
|
|
||||||
throw new Kohana_Exception('Unknown module :module - not loaded?',array(':module'=>$mo->id));
|
|
||||||
|
|
||||||
if (is_numeric($method))
|
|
||||||
$mmo = ORM::factory('Module_Method',$method);
|
|
||||||
elseif (is_string($method))
|
|
||||||
$mmo = ORM::factory('Module_Method',array('name'=>$method,'module_id'=>$mo->id));
|
|
||||||
else
|
|
||||||
throw new Kohana_Exception('Unknown method :method',array(':method'=>serialize($method)));
|
|
||||||
} else
|
|
||||||
$mmo = $method;
|
|
||||||
|
|
||||||
if (! $mmo->loaded())
|
|
||||||
throw new Kohana_Exception('Unknown method :method - not loaded?',array(':method'=>$mmo->id));
|
|
||||||
|
|
||||||
$this->method_id = $mmo->id;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function account($account) {
|
|
||||||
if (! $account instanceof Model_Account) {
|
|
||||||
if (is_numeric($account))
|
|
||||||
$ao = ORM::factory('Account',$account);
|
|
||||||
else
|
|
||||||
throw new Kohana_Exception('Unknown account :account',array(':account'=>serialize($account)));
|
|
||||||
} else
|
|
||||||
$ao = $account;
|
|
||||||
|
|
||||||
$this->account_id = $ao->id;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function uses($uses) {
|
|
||||||
$this->uses = $uses;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function expire($expire) {
|
|
||||||
$this->date_expire = $expire;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// @todo Login Reset: When called within a timelimit (so existing token already exists), is returning true but password reset emails have blanks where the tokens are
|
|
||||||
public function generate() {
|
|
||||||
if (! $this->account_id OR ! $this->method_id OR ! ($this->date_expire OR $this->uses))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
// Check we dont already have a valid token
|
|
||||||
$mmto = ORM::factory('Module_Method_Token')
|
|
||||||
->where('account_id','=',$this->account_id)
|
|
||||||
->where('method_id','=',$this->method_id)
|
|
||||||
->find();
|
|
||||||
|
|
||||||
if ($mmto->loaded()) {
|
|
||||||
// Check that the token is still good
|
|
||||||
if ((is_null($mmto->date_expire) OR $mmto->date_expire > time()) AND (is_null($mmto->uses) OR $mmto->uses > 0)) {
|
|
||||||
$this->token = $mmto->token;
|
|
||||||
return $this->token;
|
|
||||||
|
|
||||||
// Token expired
|
|
||||||
} else
|
|
||||||
$mmto->delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->token = md5(sprintf('%s:%s:%s',$this->account_id,$this->method_id,time()));
|
|
||||||
$this->save();
|
|
||||||
|
|
||||||
return $this->saved() ? $this->token : NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,40 +0,0 @@
|
|||||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @package OSB
|
|
||||||
* @category Models
|
|
||||||
* @author Deon George
|
|
||||||
* @copyright (c) 2009-2013 Open Source Billing
|
|
||||||
* @license http://dev.osbill.net/license.html
|
|
||||||
*/
|
|
||||||
class Model_Record_ID extends ORM {
|
|
||||||
protected $_primary_key = 'module_id';
|
|
||||||
|
|
||||||
// This module doesnt keep track of column updates automatically
|
|
||||||
protected $_created_column = FALSE;
|
|
||||||
protected $_updated_column = FALSE;
|
|
||||||
|
|
||||||
public function next_id($mid) {
|
|
||||||
if (is_null($this->id)) {
|
|
||||||
$this->module_id = $mid;
|
|
||||||
|
|
||||||
// We'll get the next ID as the MAX(id) of the table
|
|
||||||
$mo = ORM::factory('Module',$mid);
|
|
||||||
|
|
||||||
$max = DB::select(array('MAX(id)','id'))
|
|
||||||
->from($mo->name)
|
|
||||||
->where('site_id','=',Company::instance()->site());
|
|
||||||
|
|
||||||
$this->id = $max->execute()->get('id');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->id++;
|
|
||||||
|
|
||||||
if (! $this->save())
|
|
||||||
throw HTTP_Exception::factory(501,'Unable to increase ID for :table',array(':table'=>$mid));
|
|
||||||
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
?>
|
|
@ -1,14 +0,0 @@
|
|||||||
<div class="span11">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Reset Password</legend>
|
|
||||||
|
|
||||||
<?php echo Form::input('password','',array('label'=>'Password','type'=>'password','required','minlength'=>8)); ?>
|
|
||||||
<?php echo Form::input('password_confirm','',array('label'=>'Confirm','type'=>'password','required','minlength'=>8)); ?>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="offset2">
|
|
||||||
<button type="submit" class="btn btn-primary">Update</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> <!-- /span -->
|
|
@ -1,16 +0,0 @@
|
|||||||
<div class="span11">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Add Method</legend>
|
|
||||||
|
|
||||||
<?php echo Form::input('name',$name,array('label'=>'Method','disabled')); ?>
|
|
||||||
<?php echo Form::input('notes','',array('label'=>'Description','placeholder'=>'Method Description','class'=>'span8')); ?>
|
|
||||||
<?php echo Form::input('menu_display','',array('label'=>'Menu Title','placeholder'=>'Menu Title')); ?>
|
|
||||||
</fieldset>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="offset2">
|
|
||||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
|
||||||
<button type="button" class="btn">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div> <!-- /span -->
|
|
@ -1,44 +0,0 @@
|
|||||||
<div class="row">
|
|
||||||
<div class="col-md-3">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Method Details</legend>
|
|
||||||
|
|
||||||
<?php echo Form::input('notes',$o->notes,array('label'=>'Description','placeholder'=>'Method Description')); ?>
|
|
||||||
<?php echo Form::input('menu_display',$o->menu_display,array('label'=>'Menu Title','placeholder'=>'Menu Title')); ?>
|
|
||||||
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="col-md-7">
|
|
||||||
<fieldset>
|
|
||||||
<legend>Method Security</legend>
|
|
||||||
|
|
||||||
<table class="table table-striped table-condensed table-hover" id="list-table">
|
|
||||||
<thead><tr>
|
|
||||||
<th>Method</th>
|
|
||||||
<th>Notes</th>
|
|
||||||
<th>Group Active</th>
|
|
||||||
<th>Method Enable</th>
|
|
||||||
</tr></thead>
|
|
||||||
|
|
||||||
<tbody>
|
|
||||||
<?php foreach (ORM::factory('Group')->find_all() as $go) : ?>
|
|
||||||
<tr>
|
|
||||||
<td><?php echo HTML::anchor(URL::link('admin','group/edit/'.$go->id,TRUE),$go->display('name')); ?></td>
|
|
||||||
<td><?php echo $go->display('notes'); ?></td>
|
|
||||||
<td><?php echo $go->display('status'); ?></td>
|
|
||||||
<td><?php echo Form::checkbox('groups[]',$go->id,$o->has('group',$go),array('nocg'=>TRUE)); ?></td>
|
|
||||||
</tr>
|
|
||||||
<?php endforeach ?>
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</fieldset>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="row">
|
|
||||||
<div class="col-md-4">
|
|
||||||
<button type="submit" class="btn btn-primary">Save changes</button>
|
|
||||||
<button type="button" class="btn">Cancel</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
@ -1 +1 @@
|
|||||||
Subproject commit 6415652743526a9b25a53b0cab4ffa0db020f42b
|
Subproject commit 898371c849356932afe44d00f29f881430792c46
|
@ -1 +1 @@
|
|||||||
Subproject commit 2b48dde8f7297e49914e742d85e14783d900902c
|
Subproject commit 68d96ca85f0befb37754de7caf6f861e6df64e3a
|
1
modules/lnauth
Submodule
1
modules/lnauth
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit 4b432d2eb44bc8cf264c3082b009f9918c5e552b
|
Reference in New Issue
Block a user