Status updates, SSL updates
This commit is contained in:
@@ -13,7 +13,11 @@ class Model_SSL_CA extends ORM_OSB {
|
||||
protected $_updated_column = FALSE;
|
||||
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'parent'=>array('model'=>'ssl_ca','foreign_key'=>'parent_ssl_ca_id'),
|
||||
);
|
||||
protected $_has_many = array(
|
||||
'children'=>array('model'=>'ssl_ca','far_key'=>'id','foreign_key'=>'parent_ssl_ca_id'),
|
||||
'service'=>array('through'=>'service__ssl'),
|
||||
);
|
||||
|
||||
@@ -23,6 +27,14 @@ class Model_SSL_CA extends ORM_OSB {
|
||||
),
|
||||
);
|
||||
|
||||
public function filters() {
|
||||
return array(
|
||||
'parent_ssl_ca_id'=>array(
|
||||
array(array($this,'filter_getParent')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function rules() {
|
||||
return array(
|
||||
'sign_cert'=>array(
|
||||
@@ -30,19 +42,11 @@ class Model_SSL_CA extends ORM_OSB {
|
||||
array(array($this,'isCA')),
|
||||
),
|
||||
'parent_ssl_ca_id'=>array(
|
||||
array(array($this,'Rule_ParentExists')),
|
||||
array(array($this,'rule_parentExist')),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
public function filters() {
|
||||
return array(
|
||||
'parent_ssl_ca_id'=>array(
|
||||
array(array($this,'Filter_GetParent')),
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private $_so = NULL;
|
||||
|
||||
/**
|
||||
@@ -51,10 +55,13 @@ class Model_SSL_CA extends ORM_OSB {
|
||||
public function __call($name,$args) {
|
||||
$m = 'get_'.$name;
|
||||
|
||||
if (is_null($this->_so))
|
||||
return NULL;
|
||||
|
||||
if (method_exists($this->_so,$m))
|
||||
return $this->_so->{$m}($args);
|
||||
else
|
||||
throw new Kohana_Exception('Unknown method :method',array(':method'=>$name));
|
||||
throw new Kohana_Exception('Unknown method :method for :class',array(':method'=>$m,':class'=>get_class($this->_so)));
|
||||
}
|
||||
|
||||
// We want to inject the SSL object into this Model
|
||||
@@ -67,6 +74,42 @@ class Model_SSL_CA extends ORM_OSB {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* List the child CA certs
|
||||
*/
|
||||
public function childca($children=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
if ($children)
|
||||
foreach ($this->list_childca() as $cao)
|
||||
$result += $cao->childca($children);
|
||||
|
||||
return $result+$this->list_childca()->count();
|
||||
}
|
||||
|
||||
public function childcrt($children=FALSE) {
|
||||
$result = 0;
|
||||
|
||||
if ($children)
|
||||
foreach ($this->list_childca() as $cao)
|
||||
$result += $cao->childcrt($children);
|
||||
|
||||
return $result+$this->list_childcrt()->count();
|
||||
}
|
||||
|
||||
/**
|
||||
* Make sure we have our parent in the DB too
|
||||
*/
|
||||
public function validParent($format=FALSE) {
|
||||
$result = NULL;
|
||||
|
||||
// If we are a root cert, we are valid
|
||||
if (is_null($this->parent_ssl_ca_id) AND $this->isRoot())
|
||||
return StaticList_YesNo::get(TRUE,$format);
|
||||
|
||||
return StaticList_YesNo::get($this->aki_keyid() == $this->parent->ski(),$format);
|
||||
}
|
||||
|
||||
// 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);
|
||||
@@ -77,20 +120,23 @@ class Model_SSL_CA extends ORM_OSB {
|
||||
return $this;
|
||||
}
|
||||
|
||||
// @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() {
|
||||
public function filter_getParent() {
|
||||
foreach (ORM::factory($this->_object_name)->find_all() as $sco)
|
||||
if ($sco->aki_keyid() == $this->aki_keyid())
|
||||
return $sco->id;
|
||||
}
|
||||
|
||||
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();
|
||||
public function list_childca() {
|
||||
return $this->children->find_all();
|
||||
}
|
||||
|
||||
public function list_issued() {
|
||||
return $this->service->find_all();
|
||||
public function list_childcrt() {
|
||||
return $this->service->where_active()->find_all();
|
||||
}
|
||||
|
||||
public function rule_parentExist() {
|
||||
// Our parent_ssl_ca_id should have been populated by filter_GetParent().
|
||||
return $this->parent_ssl_ca_id OR $this->isRoot();
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
Reference in New Issue
Block a user