Updated to work with KH 3.1

This commit is contained in:
Deon George
2011-05-23 20:01:27 +10:00
parent 4765770a1a
commit a244d693b5
28 changed files with 1027 additions and 553 deletions

View File

@@ -3,7 +3,7 @@
/**
* This class overrides Kohana's Auth so that we can login to TSM
*
* @package PTA
* @package PTA/Modifications
* @subpackage Auth
* @category Overrides
* @author Deon George
@@ -11,19 +11,16 @@
* @license http://phptsmadmin.sf.net/license.html
*/
class Auth_ORM extends Kohana_Auth_ORM {
/**
* Attempt to log in a user by using an ORM object and plain-text password.
*
* @param string username to log in
* @param string password to check against
* @param boolean enable autologin
* @return boolean
*/
public function login($username, $password, $remember = FALSE) {
// With TSM, if we get this far, we are logged in
return $username->loaded();
// Override Kohana Auth requirement to have a hash_key
public function hash($str) {
switch ($this->_config['hash_method']) {
case '' : return $str;
case 'md5': return md5($str);
default: return hash_hmac($this->_config['hash_method'], $str, $this->_config['hash_key']);
}
}
// Override Kohana logged_in() - if we can get the user, we are logged in.
public function logged_in($role = NULL, $all_required = TRUE) {
return FALSE !== $this->get_user();
}

View File

@@ -0,0 +1,37 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* OSB Auth driver.
*
* @package PTA
* @subpackage Account
* @category Auth
* @author Deon George
* @copyright (c) phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Auth_TSM extends Auth_ORM {
/**
* Logs a user in.
*
* @param string username
* @param string password
* @param boolean enable autologin
* @return boolean
*/
protected function _login($user, $password, $remember) {
if ( ! is_object($user))
{
$username = $user;
// Load the user
$user = ORM::factory('admin')
->where('ADMIN_NAME','=',$username)
->find();
}
// Normally, if we get this far, we are already logged in.
return TRUE;
}
}
?>

View File

@@ -11,6 +11,14 @@
* @license http://dev.leenooks.net/license.html
*/
abstract class Controller_lnApp_Default extends Controller {
/**
* The variable that our output is stored in
*/
protected $output = NULL;
/**
* @var string page media route as per [Route]
*/
protected $mediaroute = 'default/media';
/**
* Controls access to this controller.
* Can be set to a string or an array, for example 'login' or array('login', 'admin')
@@ -48,8 +56,8 @@ abstract class Controller_lnApp_Default extends Controller {
return FALSE;
return (($this->auth_required !== FALSE && Auth::instance()->logged_in() === FALSE) ||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
Auth::instance()->logged_in($this->secure_actions[$this->request->action]) === FALSE));
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
Auth::instance()->logged_in($this->secure_actions[$this->request->action()]) === FALSE));
}
public function before() {
@@ -58,16 +66,16 @@ abstract class Controller_lnApp_Default extends Controller {
// Check user auth and role
if ($this->_auth_required()) {
// For AJAX/JSON requests, authorisation is controlled in the method.
if (Request::$is_ajax && $this->request->action === 'json') {
if (Request::current()->is_ajax() && $this->request->action() === 'json') {
// Nothing required.
// For no AJAX/JSON requests, display an access page
} elseif (Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__)) {
Request::instance()->redirect('login/noaccess');
Request::current()->redirect('login/noaccess');
} else {
Session::instance()->set('afterlogin',Request::instance()->uri());
Request::instance()->redirect($this->noauth_redirect);
Session::instance()->set('afterlogin',Request::detect_uri());
Request::current()->redirect($this->noauth_redirect);
}
}
}

View File

@@ -12,34 +12,30 @@
* @also [logout]
*/
class Controller_lnApp_Login extends Controller_TemplateDefault {
protected $auth_required = FALSE;
public function action_index() {
// If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
// Redirect to the user account
Request::instance()->redirect('welcome/index');
Request::current()->redirect('welcome/index');
}
// If there is a post and $_POST is not empty
if ($_POST) {
// Store our details in a session key
Session::instance()->set('username',$_POST['username']);
Session::instance()->set(Kohana::config('auth.session_key'),$_POST['username']);
Session::instance()->set('password',$_POST['password']);
// Instantiate a new user
$user = ORM::factory('account');
// Check Auth
$status = $user->login($_POST);
// If the post data validates using the rules setup in the user model
if ($status) {
if (Auth::instance()->login($_POST['username'],$_POST['password'])) {
// Redirect to the user account
if ($redir = Session::instance()->get('afterlogin')) {
Session::instance()->delete('afterlogin');
Request::instance()->redirect($redir);
Request::current()->redirect($redir);
} else
Request::instance()->redirect('welcome/index');
Request::current()->redirect('welcome/index');
} else {
SystemMessage::add(array(
@@ -56,9 +52,6 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
'style'=>array('css/login.css'=>'screen'),
));
$this->template->control = HTML::anchor($this->request->uri(),'Login',array('id'=>'ajxbody'));
$this->template->content = Block::factory();
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("#ajxbody").click(function() {$("#ajBODY").load("'.$this->request->uri().'/"); return false;});
@@ -70,7 +63,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
// If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
// Redirect to the user account
Request::instance()->redirect('welcome/index');
Request::current()->redirect('welcome/index');
}
// Instantiate a new user
@@ -82,7 +75,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
$status = $account->values($_POST)->check();
if (! $status) {
foreach ($account->validate()->errors() as $f=>$r) {
foreach ($account->validation()->errors('form/register') as $f => $r) {
// $r[0] has our reason for validation failure
switch ($r[0]) {
// Generic validation reason
@@ -90,7 +83,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
SystemMessage::add(array(
'title'=>_('Validation failed'),
'type'=>'error',
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r[0])
'body'=>sprintf(_('The defaults on your submission were not valid for field %s (%s).'),$f,$r)
));
}
}
@@ -116,12 +109,9 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
'title'=>_('Register'),
'body'=>View::factory('bregister')
->set('account',$account)
->set('errors',$account->validate()->errors()),
'style'=>array('css/bregister.css'=>'screen'),
->set('errors',$account->validation()->errors('form/register')),
));
$this->template->control = HTML::anchor($this->request->uri(),'Register',array('id'=>'ajxbody'));
$this->template->content = Block::factory();
$this->template->left = HTML::anchor('login','Login').'...';
}
@@ -132,7 +122,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
// If user already signed-in
if (Auth::instance()->logged_in()!= 0) {
// Redirect to the user account
Request::instance()->redirect('welcome/index');
Request::current()->redirect('welcome/index');
}
// If the user posted their details to reset their password
@@ -176,7 +166,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
// Redirect to our password reset, the Auth will validate the token.
} elseif (! empty($_REQUEST['token'])) {
Request::instance()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
Request::current()->redirect(sprintf('user/account/resetpassword?token=%s',$_REQUEST['token']));
}
// Show our token screen even if the email was invalid.
@@ -187,7 +177,7 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
'style'=>array('css/login.css'=>'screen'),
));
else
Request::instance()->redirect('login');
Request::current()->redirect('login');
} else {
Block::add(array(
@@ -196,13 +186,9 @@ class Controller_lnApp_Login extends Controller_TemplateDefault {
'style'=>array('css/login.css'=>'screen'),
));
}
$this->template->content = Block::factory();
}
public function action_noaccess() {
$this->template->content = '&nbsp;';
SystemMessage::add(array(
'title'=>_('No access to requested resource'),
'type'=>'error',

View File

@@ -17,10 +17,10 @@ class Controller_lnApp_Logout extends Controller {
if (Auth::instance()->logged_in()!= 0) {
Auth::instance()->logout();
Request::instance()->redirect('login');
Request::current()->redirect('login');
}
Request::instance()->redirect('welcome/index');
Request::current()->redirect('welcome/index');
}
}
?>

View File

@@ -15,10 +15,6 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
* @var string page template
*/
public $template = 'lnapp/default';
/**
* @var string page media route as per [Route]
*/
protected $mediaroute = 'default/media';
/**
* @var object meta object information as per [meta]
*/
@@ -62,8 +58,8 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
return FALSE;
return (($this->auth_required !== FALSE && Auth::instance()->logged_in(NULL,get_class($this).'|'.__METHOD__) === FALSE) ||
(is_array($this->secure_actions) && array_key_exists($this->request->action,$this->secure_actions) &&
Auth::instance()->logged_in($this->secure_actions[$this->request->action],get_class($this).'|'.__METHOD__) === FALSE));
(is_array($this->secure_actions) && array_key_exists($this->request->action(),$this->secure_actions) &&
Auth::instance()->logged_in($this->secure_actions[$this->request->action()],get_class($this).'|'.__METHOD__) === FALSE));
}
/**
@@ -74,7 +70,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
*/
public function before() {
// Do not template media files
if ($this->request->action === 'media') {
if ($this->request->action() === 'media') {
$this->auto_render = FALSE;
return;
}
@@ -84,7 +80,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
// Check user auth and role
if ($this->_auth_required()) {
if (Kohana::$is_cli)
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action));
throw new Kohana_Exception('Cant run :method, authentication not possible',array(':method'=>$this->request->action()));
// If auth is required and the user is logged in, then they dont have access.
// (We have already checked authorisation.)
@@ -93,24 +89,24 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
SystemMessage::add(array(
'title'=>_('Insufficient Access'),
'type'=>'debug',
'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action,'user'=>Auth::instance()->get_user()->username)),
'body'=>Kohana::debug(array('required'=>$this->auth_required,'action'=>$this->request->action(),'user'=>Auth::instance()->get_user()->username)),
));
// @todo Login No Access redirects are not handled in JS?
if (Request::$is_ajax) {
if ($this->request->is_ajax()) {
echo _('You dont have enough permissions.');
die();
} else
Request::instance()->redirect('login/noaccess');
Request::current()->redirect('login/noaccess');
} else {
Session::instance()->set('afterlogin',Request::instance()->uri());
Request::instance()->redirect($this->noauth_redirect);
Session::instance()->set('afterlogin',Request::detect_uri());
Request::current()->redirect($this->noauth_redirect);
}
}
// For AJAX calls, we dont need to render the complete page.
if (Request::$is_ajax) {
if ($this->request->is_ajax()) {
$this->auto_render = FALSE;
return;
}
@@ -148,6 +144,9 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
}
public function after() {
if (! is_string($this->template) AND empty($this->template->content))
$this->template->content = Block::factory();
if ($this->auto_render) {
// Application Title
$this->meta->title = 'Application Title';
@@ -181,18 +180,16 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
$this->template->footer = $this->_footer();
// For any ajax rendered actions, we'll need to capture the content and put it in the response
} elseif (Request::$is_ajax && isset($this->template->content) && ! $this->request->response) {
} elseif ($this->request->is_ajax() && isset($this->template->content) && ! $this->response->body()) {
// @todo move this formatting to a view?
if ($s = $this->_sysmsg() AND (string)$s) {
$this->request->response = sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s);
} else
$this->request->response = '';
if ($s = $this->_sysmsg() AND (string)$s)
$this->response->body(sprintf('<table class="sysmsg"><tr><td>%s</td></tr></table>',$s));
# In case there any style sheets or scrpits for this render.
$this->request->response .= Style::factory();
$this->response->bodyadd(Style::factory());
# Get the response body
$this->request->response .= sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content);
$this->response->bodyadd(sprintf('<table class="content"><tr><td>%s</td></tr></table>',$this->template->content));
}
parent::after();
@@ -244,7 +241,7 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
*/
final public function action_media() {
// Generate and check the ETag for this file
$this->request->check_cache(sha1($this->request->uri));
$this->response->check_cache(NULL,$this->request);
// Get the file path from the request
$file = $this->request->param('file');
@@ -258,22 +255,22 @@ abstract class Controller_lnApp_TemplateDefault extends Controller_Template {
// First try and find media files for the site_id
if ($f = Kohana::find_file(sprintf('media/%s',Config::siteid()), $file, $ext)) {
// Send the file content as the response
$this->request->response = file_get_contents($f);
$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->request->response = file_get_contents($f);
$this->response->body(file_get_contents($f));
} else {
// Return a 404 status
$this->request->status = 404;
$this->response->status(404);
}
// Set the proper headers to allow caching
$this->request->headers['Content-Type'] = File::mime_by_ext($ext);
$this->request->headers['Content-Length'] = filesize($f);
$this->request->headers['Last-Modified'] = date('r', filemtime($f));
$this->response->headers('Content-Type',File::mime_by_ext($ext));
$this->response->headers('Content-Length',(string)filesize($f));
$this->response->headers('Last-Modified',date('r', filemtime($f)));
}
}
?>

View File

@@ -11,22 +11,20 @@
* @license http://dev.osbill.net/license.html
*/
class Controller_lnApp_Tree extends Controller_Default {
// Our tree data
protected $treedata;
/**
* @var string page media route as per [Route]
*/
protected static $mediaroute = 'default/media';
protected static $jsmediaroute = 'default/media';
public function after() {
parent::after();
$this->request->headers['Content-Type'] = 'application/json';
$this->request->response = sprintf('[%s]',json_encode($this->treedata));
$this->response->headers('Content-Type','application/json');
$this->response->body(sprintf('[%s]',json_encode($this->output)));
}
public static function js() {
$mediapath = Route::get(static::$mediaroute);
$mediapath = Route::get(static::$jsmediaroute);
return '
<div id="tree" class=""></div>
@@ -85,28 +83,18 @@ $(function () {
*
* @param id
*/
public function action_json($id=null) {
if (! Auth::instance()->logged_in()) {
$this->treedata = array('attr'=>array('id'=>'a_login'),
public function action_json($id=null,array $data=array()) {
if ($this->_auth_required() AND ! Auth::instance()->logged_in()) {
$this->output = array('attr'=>array('id'=>'a_login'),
'data'=>array('title'=>_('Please Login').'...','attr'=>array('id'=>'N_login','href'=>URL::site('/login'))));
return;
}
$this->treedata = array();
$data = array();
// @todo Our menu options
array_push($data,array(
'id'=>'node',
'name'=>'Node Info',
'state'=>'none',
'attr_id'=>'1',
'attr_href'=>URL::Site('/node'),
));
$this->output = array();
foreach ($data as $branch) {
array_push($this->treedata,array(
array_push($this->output,array(
'attr'=>array('id'=>sprintf('B_%s',$branch['id'])),
'state'=>$branch['state'],
'data'=>array('title'=>$branch['name']),

View File

@@ -1,4 +1,16 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_TemplateDefault extends Controller_lnApp_TemplateDefault {}
/**
* This class provides the default template controller for rendering pages.
*
* @package PTA
* @subpackage Page/Template
* @category Controllers
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Controller_TemplateDefault extends Controller_lnApp_TemplateDefault {
protected $auth_required = TRUE;
}
?>

View File

@@ -1,4 +1,37 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_Tree extends Controller_lnApp_Tree {}
/**
* This class extends renders OSB menu tree.
*
* @package lnApp
* @subpackage Tree
* @category Controllers
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Tree extends Controller_lnApp_Tree {
protected $auth_required = TRUE;
/**
* Draw the Tree Menu
*
* The incoming ID is either a Branch B_x or a Node N_x
* Where X is actually the module.
*
* @param id
*/
public function action_json($id=null,array $data=array()) {
// @todo Our menu options
array_push($data,array(
'id'=>'node',
'name'=>'Node Info',
'state'=>'none',
'attr_id'=>'1',
'attr_href'=>URL::Site('/node'),
));
return parent::action_json($id,$data);
}
}
?>

View File

@@ -1,16 +1,21 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* phpTSMadmin Main home page
*
* @package PTA
* @subpackage Page/Home
* @category Controllers
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class Controller_Welcome extends Controller_TemplateDefault {
public function action_index()
{
public function action_index() {
Block::add(array(
'title'=>sprintf('%s: %s (%s)',_('Server'),TSM::name(),TSM::version()),
'body'=>'hello, world!',
));
$this->template->content = Block::factory();
}
} // End Welcome
}
?>

View File

@@ -11,7 +11,6 @@
* @license http://phptsmadmin.sf.net/license.html
*/
class Database_TSM extends Database {
// Database in use by each connection
protected static $_current_databases = array();
@@ -39,8 +38,13 @@ class Database_TSM extends Database {
'ANR2034E', // SELECT: No match found using this criteria.
);
public function connect()
{
// Our required abstract methods
public function begin($mode = NULL) {}
public function commit() {}
public function rollback() {}
public function set_charset($charset) {}
public function connect() {
if ($this->_connection)
return;
@@ -55,7 +59,7 @@ class Database_TSM extends Database {
// Get user login details from user session - these are set by login
if (! $username)
$username = Session::instance()->get_once('username');
$username = Session::instance()->get_once(Kohana::config('auth.session_key'));
if (! $password)
$password = Session::instance()->get_once('password');
@@ -71,25 +75,22 @@ class Database_TSM extends Database {
}
if (! $username OR ! $password)
Request::instance()->redirect('/login?need_login=1');
Request::current()->redirect('/login?need_login=1');
try
{
if ($persistent)
{
try {
if ($persistent) {
// Create a persistent connection
throw new Kohana_Exception('Cant do persistant connections');
}
else
{
} else {
// Create a connection and force it to be a new link
$this->_connection = sprintf('%s %s -id=%s -password=%s -displ=list -dataonly=YES %s %s',
$this->_connection = sprintf('%s %s -id=%s -password=%s -displ=list -editor=no -dataonly=YES %s %s ',
Kohana::config('config.client'),
Kohana::config('config.stanza') ? '-server='.Kohana::config('config.stanza') : '',
$database ? '-server='.$database : '',
$username,
$password,
Kohana::config('config.client_errorlogname') ? sprintf('-errorlogname=%s',Kohana::config('config.client_errorlogname')) : '',
Kohana::config('config.client_stanza') ? sprintf('-se=%s',Kohana::config('config.client_stanza')) : ''
$database ? sprintf('-se=%s',$database) : ''
);
$result = $this->query(Database::SELECT,'SELECT server_name,platform,version,release,level,sublevel FROM status');
@@ -97,11 +98,10 @@ class Database_TSM extends Database {
if ($result)
return TSM::instance()->set($username,$password,$result);
else
Request::instance()->redirect(Request::instance()->uri());
Request::current()->redirect(Request::detect_uri());
}
}
catch (ErrorException $e)
{
} catch (ErrorException $e) {
// No connection exists
$this->_connection = NULL;
@@ -114,69 +114,24 @@ class Database_TSM extends Database {
// \xFF is a better delimiter, but the PHP driver uses underscore
$this->_connection_id = sha1($hostname.'_'.$username.'_'.$password);
if ( ! empty($this->_config['charset']))
{
if ( ! empty($this->_config['charset'])) {
// Set the character set
$this->set_charset($this->_config['charset']);
}
}
public function disconnect()
{
try
{
// Database is assumed disconnected
$status = TRUE;
if (is_resource($this->_connection))
{
if ($status = mysql_close($this->_connection))
{
// Clear the connection
$this->_connection = NULL;
}
}
}
catch (Exception $e)
{
// Database is probably not disconnected
$status = ! is_resource($this->_connection);
}
return $status;
}
public function set_charset($charset)
{
// Make sure the database is connected
$this->_connection or $this->connect();
// Nothing to do for TSM
$status = TRUE;
if ($status === FALSE)
{
throw new Database_Exception(':error',
array(':error' => mysql_error($this->_connection)),
mysql_errno($this->_connection));
}
}
private function clear() {
$this->_query_msg_codes = array();
}
public function query($type, $sql, $as_object = FALSE, array $params = NULL)
{
public function query($type, $sql, $as_object = FALSE, array $params = NULL) {
// Make sure the database is connected
$this->_connection or $this->connect();
$this->clear();
if ( ! empty($this->_config['profiling']))
{
// Benchmark this query for the current instance
$benchmark = Profiler::start("Database ({$this->_instance})", $sql);
}
// We need to escape any back slashes, since the exec will transpose them
// @todo Is there a better way of doing this?
@@ -211,98 +166,75 @@ class Database_TSM extends Database {
}
if (isset($benchmark))
{
Profiler::stop($benchmark);
}
// Set the last query
$this->last_query = $sql;
if ($type === Database::SELECT)
{
// Return an iterator of results
return new Database_TSM_Result($result, $sql, $as_object, $params);
}
elseif ($type === Database::INSERT)
{
throw new Kohana_Exception('Database INSERTS are not supported');
}
}
public function list_tables($like = NULL)
{
public function list_tables($like = NULL) {
if (is_string($like))
{
// Search for table names
$result = $this->query(Database::SELECT, 'SHOW TABLES LIKE '.$this->quote($like), FALSE);
}
else
{
// Find all table names
$result = $this->query(Database::SELECT, 'SHOW TABLES', FALSE);
}
$tables = array();
foreach ($result as $row)
{
$tables[] = reset($row);
}
return $tables;
}
public function list_columns($table, $like = NULL, $add_prefix = TRUE)
{
public function list_columns($table, $like = NULL, $add_prefix = TRUE) {
// Quote the table name
$table = ($add_prefix === TRUE) ? $this->quote_table($table) : $table;
if (is_string($like))
{
// Search for column names
$result = $this->query(Database::SELECT, 'SHOW FULL COLUMNS FROM '.$table.' LIKE '.$this->quote($like), FALSE);
}
else
{
// Find all column names
$result = $this->query(Database::SELECT, sprintf('SELECT * FROM SYSCAT.COLUMNS WHERE TABNAME=\'%s\'',$table), FALSE);
}
$count = 0;
$columns = array();
foreach ($result as $row)
{
foreach ($result as $row) {
list($type, $length) = $this->_parse_type($row['TYPENAME']);
$column = $this->datatype($type);
$column['column_name'] = $row['COLNAME'];
// $column['column_default'] = $row['Default'];
$column['data_type'] = $type;
$column['is_nullable'] = ($row['NULLS'] == 'TRUE');
$column['ordinal_position'] = ++$count;
switch (strtolower($column['data_type']))
{
switch (strtolower($column['data_type'])) {
case 'float':
if (isset($length))
{
list($column['numeric_precision'], $column['numeric_scale']) = explode(',', $length);
}
break;
break;
case 'int':
if (isset($length))
{
// MySQL attribute
$column['display'] = $length;
}
break;
break;
case 'string':
switch ($column['data_type'])
{
switch ($column['data_type']) {
case 'binary':
case 'varbinary':
$column['character_maximum_length'] = $length;
break;
break;
case 'char':
case 'varchar':
$column['character_maximum_length'] = $length;
@@ -311,27 +243,27 @@ class Database_TSM extends Database {
case 'mediumtext':
case 'longtext':
$column['collation_name'] = $row['Collation'];
break;
break;
case 'enum':
case 'set':
$column['collation_name'] = $row['Collation'];
$column['options'] = explode('\',\'', substr($length, 1, -1));
break;
break;
}
break;
break;
}
// TSM attributes
$column['comment'] = $row['REMARKS'];
$columns[$row['COLNAME']] = $column;
}
return $columns;
}
public function escape($value)
{
public function escape($value) {
// Make sure the database is connected
$this->_connection or $this->connect();

View File

@@ -73,7 +73,7 @@ class Database_TSM_Result extends Database_Result {
// Return an object of given class name
$o = new $this->_as_object;
return $o->values($this->_rows[$this->_current_row]);
return $o->load_object($this->_rows[$this->_current_row]);
}
else
{

View File

@@ -0,0 +1,19 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's Form
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Form extends Kohana_Form {
// Enable 3.0 features, default to current URI for empty Form::open()
public static function open($action = NULL, array $attributes = NULL) {
return parent::open(is_null($action) ? Request::detect_uri() : $action,$attributes);
}
}
?>

View File

@@ -0,0 +1,30 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's 404 Exception
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 {
public function __construct($message, array $variables = NULL, $code = 0)
{
set_exception_handler(array(get_class($this),'handler'));
parent::__construct($message, $variables, (int) $code);
}
public static function handler(Exception $e)
{
SystemMessage::add(array(
'title'=>_('Page not found'),
'type'=>'error',
'body'=>sprintf(_('The page [%s] you requested was not found?'),Request::detect_uri()),
));
Request::factory()->redirect('/welcome');
}
}

View File

@@ -49,7 +49,7 @@ class lnApp_Breadcrumb extends HTMLRender {
protected function render() {
$output = HTML::anchor('/',_('Home'));
$data = empty(static::$_data['path']) ? explode('/',Request::instance()->uri) : static::$_data['path'];
$data = empty(static::$_data['path']) ? explode('/',preg_replace('/^\//','',Request::detect_uri())) : static::$_data['path'];
foreach ($data as $k => $v) {
$output .= static::$_spacer;

View File

@@ -11,7 +11,7 @@
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
abstract class lnApp_Config extends Kohana {
abstract class lnApp_Config extends Kohana_Config {
/**
* Return our site name
*/

View File

@@ -10,7 +10,7 @@
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Model_Account extends Model_Auth_UserDefault {
class Model_ADMIN extends Model_Auth_UserDefault {
protected $_table_name = 'ADMINS';
protected $_primary_key = 'ADMIN_NAME';
}

View File

@@ -16,16 +16,34 @@ class Model_NODE extends ORMTSM {
'FILESPACE'=>array('foreign_key'=>'NODE_NAME','far_key'=>'FILESPACE_NAME'),
);
protected $_formats = array(
'REG_TIME'=>array('ORMTSM::date'=>array('d-M-Y')),
'PWSET_TIME'=>array('ORMTSM::date'=>array('d-M-Y')),
'LASTACC_TIME'=>array('ORMTSM::date'=>array('d-M-Y')),
'LASTSESS_SENT'=>array('number_format'=>array(0)),
'LASTSESS_RECVD'=>array('number_format'=>array(0)),
'LASTSESS_DURATION'=>array('number_format'=>array(2)),
'LASTSESS_IDLEWAIT'=>array('number_format'=>array(2)),
'LASTSESS_COMMWAIT'=>array('number_format'=>array(2)),
'LASTSESS_MEDIAWAIT'=>array('number_format'=>array(2)),
protected $_display_filters = array(
'REG_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
'PWSET_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
'LASTACC_TIME'=>array(
array('ORMTSM::date',array(':value','d-M-Y')),
),
'LASTSESS_SENT'=>array(
array('number_format',array(':value',0)),
),
'LASTSESS_RECVD'=>array(
array('number_format',array(':value',0)),
),
'LASTSESS_DURATION'=>array(
array('number_format',array(':value',2)),
),
'LASTSESS_IDLEWAIT'=>array(
array('number_format',array(':value',2)),
),
'LASTSESS_COMMWAIT'=>array(
array('number_format',array(':value',2)),
),
'LASTSESS_MEDIAWAIT'=>array(
array('number_format',array(':value',2)),
),
);
protected $_sorting = array(

View File

@@ -0,0 +1,69 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's ORM
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class ORM extends Kohana_ORM {
protected $_table_names_plural = false;
private $_object_formated = array();
private $_formated = FALSE;
// Our filters used to display values in a friendly format
protected $_display_filters = array();
// Override check() so that it doesnt throw an exception.
// @todo Need to figure out how to show the items that fail validation
final public function check(Validation $extra_validation = NULL) {
// Determine if any external validation failed
$extra_errors = ($extra_validation AND ! $extra_validation->check());
// Always build a new validation object
$this->_validation();
$array = $this->_validation;
if (($this->_valid = $array->check()) === FALSE OR $extra_errors)
{
return FALSE;
}
return $this;
}
/**
* Format fields for display purposes
*
* @param string column name
* @return mixed
*/
private function _format() {
foreach ($this->_display_filters as $column => $formats)
$this->_object_formated[$column] = $this->run_filter($column,$this->__get($column),array($column=>$formats));
$this->_formated = TRUE;
}
/**
* Return a formated columns, as per the model definition
*/
public function display($column) {
// Trigger a load of the record.
$value = $this->__get($column);
// If some of our fields need to be formated for display purposes.
if ($this->_loaded AND ! $this->_formated AND $this->_display_filters)
$this->_format();
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return $value;
}
}
?>

View File

@@ -3,14 +3,14 @@
/**
* This class extends Kohana's [ORM] class to create defaults for TSM.
*
* @package TSM
* @package PTA
* @subpackage Core
* @category ORM
* @author Deon George
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://dev.osbill.net/license.html
*/
abstract class ORMTSM extends ORM {
class ORMTSM extends ORM {
// Suppress ORMs inclusion of <table_name>.*
protected $_disable_wild_select = TRUE;
// Suppress ORMs inclusion of <table_name>. to column joins
@@ -23,70 +23,13 @@ abstract class ORMTSM extends ORM {
protected $_formated = FALSE;
protected $_formats = array();
/**
* Format fields for display purposes
*
* @param string column name
* @return mixed
*/
protected function _format() {
$format = Validate::factory($this->_object);
foreach ($this->_formats as $column => $formats)
$format->filters($column,$formats);
if ($format->check())
foreach ($format as $column => $value)
$this->_object_formated[$column] = $value;
$this->_formated = TRUE;
}
/**
* Return a formated columns, as per the model definition
*/
public function display($column) {
// Trigger a load of the record.
$value = $this->__get($column);
// If some of our fields need to be formated for display purposes.
if ($value AND ! $this->_formated AND $this->_formats)
$this->_format();
if (isset($this->_object_formated[$column]))
return $this->_object_formated[$column];
else
return $value;
// Load our values into the ORM object
public function load_object(array $values) {
return parent::_load_values($values);
}
public static function date($date,$format) {
return date($format,strtotime($date));
}
/**
* This function will enhance the [Validate::filter], since it always passes
* the value as the first argument and sometimes functions need that to not
* be the first argument.
*
* Currently this implements:
* [date()][date-ref]
*
* [date-ref]: http://www.php.net/date
*
* This function will throw an exception if called without a function
* defined.
*
* @param mixed $val Value to be processed
* @param string $func Name of function to call
* @param string $arg Other arguments for the function
*/
final public static function _filters($val,$func,$arg) {
switch ($func) {
case 'date':
return date($arg,$val);
default:
throw new Exception(sprintf(_('Unknown function: %s (%s,%s)'),$func,$arg,$val));
}
}
}
?>

View File

@@ -0,0 +1,19 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's Response
*
* @package lnApp/Modifications
* @category Classes
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Response extends Kohana_Response {
// Append to the body.
public function bodyadd($content) {
$this->_body .= (string) $content;
}
}
?>

View File

@@ -7,13 +7,13 @@
* @subpackage Core
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
* @copyright (c) 2010 phpTSMadmin Development Team
* @license http://phptsmadmin.sf.net/license.html
*/
class TSM {
public function set($username,$password,Database_TSM_Result $server) {
// @todo Consider encrypting this
Session::instance()->set('username',$username);
Session::instance()->set(Kohana::config('auth.session_key'),$username);
Session::instance()->set('password',$password);
Session::instance()->set('SERVER',$server);

View File

@@ -0,0 +1,27 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* Array and variable validation.
*
* @package lnApp/Modifications
* @category Classes
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Valid extends Kohana_Valid {
/**
* Checks if a field matches the value of another field, if it is set.
* Field is ignored if it is blank.
*
* @param array array of values
* @param string field name
* @param string field name to match
* @return boolean
*/
public static function matches_ifset($array, $field, $match)
{
return isset($array[$match]) ? ($array[$field] === $array[$match]) : TRUE;
}
}
?>