From 125407656d4510446a8bd1dcab6bfe8c60f46002 Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 30 Dec 2011 10:54:54 +1100 Subject: [PATCH] Minor fixes to ssl and core --- .../controller/templatedefault/user.php | 4 +-- application/classes/kohana.php | 36 +++++++++++++++++++ application/classes/orm.php | 1 + application/views/lnapp/default.php | 4 +++ .../classes/controller/admin/product.php | 1 - modules/product/classes/model/product.php | 5 +-- modules/ssl/classes/controller/admin/ssl.php | 5 +-- modules/ssl/classes/model/ssl/ca.php | 31 +++++++++++++++- modules/ssl/views/ssl/admin/add_view.php | 3 -- 9 files changed, 77 insertions(+), 13 deletions(-) create mode 100644 application/classes/kohana.php diff --git a/application/classes/controller/templatedefault/user.php b/application/classes/controller/templatedefault/user.php index 186b7e0d..763fb514 100644 --- a/application/classes/controller/templatedefault/user.php +++ b/application/classes/controller/templatedefault/user.php @@ -23,8 +23,8 @@ class Controller_TemplateDefault_User extends Controller_TemplateDefault { parent::before(); $this->ao = Auth::instance()->get_user(); - if (! $this->ao->loaded()) - throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>Auth::instance()->get_user()->id)); + if (is_string($this->ao) OR ! $this->ao->loaded()) + throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>is_string($this->ao) ? $this->ao : Auth::instance()->get_user()->id)); } public function after() { diff --git a/application/classes/kohana.php b/application/classes/kohana.php new file mode 100644 index 00000000..7a977028 --- /dev/null +++ b/application/classes/kohana.php @@ -0,0 +1,36 @@ + diff --git a/application/classes/orm.php b/application/classes/orm.php index a46197c9..b4742a43 100644 --- a/application/classes/orm.php +++ b/application/classes/orm.php @@ -124,6 +124,7 @@ class ORM extends Kohana_ORM { ->from($this->_has_many[$alias]['through']) ->where($this->_has_many[$alias]['foreign_key'], '=', $this->pk()) ->where($this->_has_many[$alias]['far_key'], 'IN', $far_keys) + ->where('site_id', '=', Config::siteid()) ->execute($this->_db)->get('records_found'); } } diff --git a/application/views/lnapp/default.php b/application/views/lnapp/default.php index 30509d16..21578eae 100644 --- a/application/views/lnapp/default.php +++ b/application/views/lnapp/default.php @@ -82,6 +82,10 @@ + = Kohana::STAGING) { ?> + + + diff --git a/modules/product/classes/controller/admin/product.php b/modules/product/classes/controller/admin/product.php index 597df355..5514b063 100644 --- a/modules/product/classes/controller/admin/product.php +++ b/modules/product/classes/controller/admin/product.php @@ -28,7 +28,6 @@ class Controller_Admin_Product extends Controller_TemplateDefault_Admin { 'id'=>array('label'=>'ID','url'=>'product/view/'), 'name()'=>array('label'=>'Details'), 'active'=>array('label'=>'Active'), - 'prod_plugin'=>array('label'=>'Plugin'), 'prod_plugin_file'=>array('label'=>'Plugin Name'), 'prod_plugin_data'=>array('label'=>'Plugin Data'), 'price_type'=>array('label'=>'Price Type'), diff --git a/modules/product/classes/model/product.php b/modules/product/classes/model/product.php index d02cff5e..d2f2b9fb 100644 --- a/modules/product/classes/model/product.php +++ b/modules/product/classes/model/product.php @@ -89,7 +89,7 @@ class Model_Product extends ORMOSB { // Work out the best price for the user $price = array(); foreach (unserialize($this->price_group) as $bill_freq => $pg) { - if ($pg['show']) + if (isset($pg['show']) AND $pg['show']) foreach ($groups as $gid) { if (! empty($pg[$gid])) { if (empty($price[$bill_freq]['price_base']) @@ -101,7 +101,8 @@ class Model_Product extends ORMOSB { } } - return $price; + // @todo Ugly hack + return $price ? $price : array('0'=>array('price_base'=>0,'price_setup'=>0)); } /** diff --git a/modules/ssl/classes/controller/admin/ssl.php b/modules/ssl/classes/controller/admin/ssl.php index af7f1c14..1e3e0995 100644 --- a/modules/ssl/classes/controller/admin/ssl.php +++ b/modules/ssl/classes/controller/admin/ssl.php @@ -41,15 +41,12 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin { $so = ORM::factory('ssl_ca',$id); if ($_POST) { - if (! $so->values($_POST)->check() OR ! $so->save()) - throw new Kohana_Exception('Failed to save updates to data for record :record',array(':record'=>$so->id())); - else { + if ($so->values($_POST)->check() AND $so->save()) SystemMessage::add(array( 'title'=>'SSL Certificate Saved', 'type'=>'info', 'body'=>'SSL Certificate successfully recorded.', )); - } } $output .= Form::open(); diff --git a/modules/ssl/classes/model/ssl/ca.php b/modules/ssl/classes/model/ssl/ca.php index 16acd89a..a40a5330 100644 --- a/modules/ssl/classes/model/ssl/ca.php +++ b/modules/ssl/classes/model/ssl/ca.php @@ -34,7 +34,36 @@ class Model_SSL_CA extends ORMOSB { return SSL::issuer($this->sign_cert); } + public function subject() { + return SSL::subject($this->sign_cert); + } - // @todo SAVE: auto work out the parent_ssl_ca_id + public function save(Validation $validation = NULL) { + // If our parent_ssl_ca_id is null, we'll need to work it out + if (is_null($this->parent_ssl_ca_id)) { + $i = SSL::issuer($this->sign_cert); + + $po = NULL; + foreach (ORM::factory('ssl_ca')->find_all() as $sco) + if ($sco->subject() == $i) { + $po = $sco; + break; + } + + if (is_null($po)) { + SystemMessage::add(array( + 'title'=>'Certificate NOT Recorded', + 'type'=>'warning', + 'body'=>sprintf('Parent Certificate is not available (%s)',$this->issuer()), + )); + + return FALSE; + } else + $this->parent_ssl_ca_id = $po->id; + } + + // Save the record + return parent::save($validation); + } } ?> diff --git a/modules/ssl/views/ssl/admin/add_view.php b/modules/ssl/views/ssl/admin/add_view.php index c8a2571c..110ab052 100644 --- a/modules/ssl/views/ssl/admin/add_view.php +++ b/modules/ssl/views/ssl/admin/add_view.php @@ -1,4 +1,3 @@ - @@ -37,5 +36,3 @@
Subjectsign_cert,array('cols'=>64,'rows'=>13)); ?>
-'form_button')); ?> -