Status updates, SSL updates

This commit is contained in:
Deon George
2013-11-08 22:02:32 +11:00
parent 28ea1ac613
commit 2d9d7f383c
31 changed files with 688 additions and 299 deletions

View File

@@ -18,7 +18,7 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
'service'=>array(),
);
protected $_has_one = array(
'SSL_CA'=>array('far_key'=>'ssl_ca_id','foreign_key'=>'id'),
'ca'=>array('model'=>'SSL_CA','far_key'=>'ssl_ca_id','foreign_key'=>'id'),
);
protected $_display_filters = array(
@@ -31,9 +31,23 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
);
// Required abstract functions
public function username_value() {} // Not used
public function expire($format=FALSE) {
return $this->_so->get_valid_to($format);
}
public function name() {
return ($this->cert AND $this->ca->loaded()) ? sprintf('%s:%s',$this->ca->subject(),$this->display('cert')) : $this->display('csr');
}
public function password_value() {} // Not used
public function service_view() {
return View::factory('service/user/plugin/ssl/view')
->set('o',$this);
}
public function username_value() {} // Not used
private $_so = NULL;
/**
@@ -58,6 +72,10 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
return $this;
}
public function validCA() {
return $this->ca->validParent();
}
// 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);
@@ -68,19 +86,6 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
return $this;
}
public function expire($format=FALSE) {
return $this->_so->get_valid_to($format);
}
public function name() {
return ($this->cert AND $this->SSL_CA->loaded()) ? sprintf('%s:%s',$this->SSL_CA->subject(),$this->display('cert')) : $this->display('csr');
}
public function service_view() {
return View::factory('service/user/plugin/ssl/view')
->set('o',$this);
}
/**
* Get specific service details for use in other modules
* For Example: Invoice
@@ -103,7 +108,7 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
public function admin_update() {
return View::factory('service/admin/plugin/ssl/update')
->set('mediapath',Route::get('default/media'))
->set('so',$this);
->set('o',$this);
}
public function download_button() {
@@ -134,17 +139,21 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
return $result;
}
public function renew() {
$d = SSL::instance($this->cert);
/**
* Renew an SSL Certificate
*/
public function renew($force=FALSE) {
$sslo = SSL::instance($this->cert);
$ssl_conf = Kohana::$config->load('ssl');
// @todo change this so an admin can force this.
$force = TRUE;
// If our certificate is not old enough skip
if ($d->get_valid_to() > time()+$ssl_conf['min_renew_days']*86400 AND ! $force)
if ($sslo->get_valid_to() > time()+$ssl_conf['min_renew_days']*86400 AND ! $force)
return FALSE;
$res = openssl_csr_sign($this->csr,$this->SSL_CA->sign_cert,$this->SSL_CA->sign_pk,$this->service->product->plugin()->days,array(
$today = mktime(0,0,0,date('n'),date('j'),date('Y'));
$days = (int)(($this->service->invoiced_to()-$today)/86400);
$res = openssl_csr_sign($this->csr,$this->ca->sign_cert,$this->ca->sign_pk,$days,array(
'config'=>$ssl_conf['config'],
'x509_extensions'=>$this->service->product->plugin()->extensions,
'digest_alg'=>'sha1',
@@ -155,11 +164,12 @@ class Model_Service_Plugin_Ssl extends Model_Service_Plugin {
$this->save();
return TRUE;
} else {
print_r(array(
'csr'=>$this->csr,
'ca'=>$this->SSL_CA->sign_cert,
'capk'=>$this->SSL_CA->sign_pk,
'ca'=>$this->ca->sign_cert,
'capk'=>$this->ca->sign_pk,
'days'=>$this->service->product->plugin()->days,
'ssl'=>$ssl_conf,
'x509e'=>$this->service->product->plugin()->extensions