2011-12-16 23:31:35 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class supports SSL
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage SSL
|
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2012-12-10 21:48:30 +00:00
|
|
|
class Model_SSL_CA extends ORM_OSB {
|
2011-12-16 23:31:35 +00:00
|
|
|
protected $_updated_column = FALSE;
|
|
|
|
|
|
|
|
// Relationships
|
2012-10-22 12:24:28 +00:00
|
|
|
protected $_has_many = array(
|
|
|
|
'service'=>array('through'=>'service__ssl'),
|
2011-12-16 23:31:35 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
protected $_display_filters = array(
|
|
|
|
'sign_cert'=>array(
|
|
|
|
array('SSL::subject',array(':value')),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2012-12-19 06:28:39 +00:00
|
|
|
public function rules() {
|
|
|
|
return array(
|
|
|
|
'sign_cert'=>array(
|
|
|
|
array(array($this,'isCert')),
|
|
|
|
array(array($this,'isCA')),
|
|
|
|
),
|
|
|
|
'parent_ssl_ca_id'=>array(
|
|
|
|
array(array($this,'Rule_ParentExists')),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function filters() {
|
|
|
|
return array(
|
|
|
|
'parent_ssl_ca_id'=>array(
|
|
|
|
array(array($this,'Filter_GetParent')),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private $_so = NULL;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve any queries to certificate details
|
|
|
|
*/
|
|
|
|
public function __call($name,$args) {
|
|
|
|
$m = 'get_'.$name;
|
|
|
|
|
|
|
|
if (method_exists($this->_so,$m))
|
|
|
|
return $this->_so->{$m}($args);
|
|
|
|
else
|
|
|
|
throw new Kohana_Exception('Unknown method :method',array(':method'=>$name));
|
2011-12-16 23:31:35 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:28:39 +00:00
|
|
|
// We want to inject the SSL object into this Model
|
|
|
|
protected function _load_values(array $values) {
|
|
|
|
parent::_load_values($values);
|
|
|
|
|
|
|
|
if ($this->sign_cert)
|
|
|
|
$this->_so = SSL::instance($this->sign_cert);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we change the SSL certificate, we need to reload our SSL object
|
|
|
|
public function values(array $values, array $expected = NULL) {
|
|
|
|
parent::values($values,$expected);
|
|
|
|
|
|
|
|
if (array_key_exists('sign_cert',$values))
|
|
|
|
$this->_so = SSL::instance($this->sign_cert);
|
|
|
|
|
|
|
|
return $this;
|
2011-12-16 23:31:35 +00:00
|
|
|
}
|
2011-12-26 13:52:46 +00:00
|
|
|
|
2012-12-19 06:28:39 +00:00
|
|
|
// @todo This could require some optimisation, by storing the keyid in the database and then getting the DB just to return that parent
|
|
|
|
public function Filter_GetParent() {
|
|
|
|
foreach (ORM::factory($this->_object_name)->find_all() as $sco)
|
|
|
|
if ($sco->aki_keyid() == $this->aki_keyid())
|
|
|
|
return $sco->id;
|
2011-12-29 23:54:54 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 06:28:39 +00:00
|
|
|
public function Rule_ParentExists() {
|
|
|
|
// Our parent_ssl_ca_id should have been populated by Filter_GetParent().
|
|
|
|
return $this->parent_ssl_ca_id OR $this->isRoot();
|
2011-12-29 23:54:54 +00:00
|
|
|
}
|
2012-10-22 12:24:28 +00:00
|
|
|
|
|
|
|
public function list_issued() {
|
|
|
|
return $this->service->find_all();
|
|
|
|
}
|
2011-12-16 23:31:35 +00:00
|
|
|
}
|
|
|
|
?>
|