Updates for SSL Certificates

This commit is contained in:
Deon George 2011-12-27 00:52:46 +11:00
parent 7fdba208eb
commit fe317b9cb0
7 changed files with 80 additions and 27 deletions

View File

@ -21,6 +21,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'listdomainservicesbysupplier'=>TRUE, 'listdomainservicesbysupplier'=>TRUE,
'listhostservices'=>TRUE, 'listhostservices'=>TRUE,
'listhspaservices'=>TRUE, 'listhspaservices'=>TRUE,
'listwebservices'=>TRUE,
'listinvoicesoon'=>TRUE, 'listinvoicesoon'=>TRUE,
'update'=>TRUE, 'update'=>TRUE,
); );
@ -334,6 +335,33 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
)), )),
)); ));
} }
public function action_listwebservices() {
$svs = ORM::factory('service')->list_bylistgroup('WEB');
Sort::MAsort($svs,'name()');
Block::add(array(
'title'=>_('SSL Services'),
'body'=>Table::display(
$svs,
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
/** /**
* Reconcile billing for an ADSL supplier * Reconcile billing for an ADSL supplier
* *
@ -535,7 +563,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
Block::add(array( Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update Service'),$so->id(),$so->name()), 'title'=>sprintf('%s %s:%s',_('Update Service'),$so->id(),$so->name()),
'body'=>View::factory($so->viewpath()) 'body'=>View::factory($this->viewpath())
->set('so',$so) ->set('so',$so)
->set('mediapath',Route::get('default/media')) ->set('mediapath',Route::get('default/media'))
->set('plugin_form',$so->admin_update()), ->set('plugin_form',$so->admin_update()),

View File

@ -12,8 +12,9 @@
*/ */
class Controller_Admin_SSL extends Controller_TemplateDefault_Admin { class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
protected $secure_actions = array( protected $secure_actions = array(
'add'=>TRUE,
'list'=>TRUE, 'list'=>TRUE,
'update'=>TRUE, 'view'=>TRUE,
); );
public function action_list() { public function action_list() {
@ -23,7 +24,7 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
ORM::factory('ssl_ca')->find_all(), ORM::factory('ssl_ca')->find_all(),
25, 25,
array( array(
'id'=>array('label'=>'ID','url'=>'admin/ssl/update/'), 'id'=>array('label'=>'ID','url'=>'admin/ssl/view/'),
'sign_cert'=>array('label'=>'Cert'), 'sign_cert'=>array('label'=>'Cert'),
'issuer()'=>array('label'=>'Issuer'), 'issuer()'=>array('label'=>'Issuer'),
'expires()'=>array('label'=>'Expires'), 'expires()'=>array('label'=>'Expires'),
@ -31,31 +32,49 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
array( array(
'page'=>TRUE, 'page'=>TRUE,
'type'=>'select', 'type'=>'select',
'form'=>'admin/ssl/update', 'form'=>'admin/ssl/view',
)), )),
)); ));
} }
public function action_update() { private function add_view($id=NULL,$output='') {
list($id,$output) = Table::page(__METHOD__);
$so = ORM::factory('ssl_ca',$id); $so = ORM::factory('ssl_ca',$id);
if (! $so->loaded())
Request::current()->redirect('welcome/index');
if ($_POST) { if ($_POST) {
if (! $so->values($_POST)->update()->saved()) if (! $so->values($_POST)->check() OR ! $so->save())
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id())); throw new Kohana_Exception('Failed to save updates to data for record :record',array(':record'=>$so->id()));
else {
SystemMessage::add(array(
'title'=>'SSL Certificate Saved',
'type'=>'info',
'body'=>'SSL Certificate successfully recorded.',
));
}
} }
$output .= View::factory($this->viewpath()) $output .= Form::open();
$output .= View::factory('ssl/admin/add_view')
->set('so',$so) ->set('so',$so)
->set('mediapath',Route::get('default/media')); ->set('mediapath',Route::get('default/media'));
$output .= Form::submit('submit','submit',array('class'=>'form_button'));
$output .= Form::close();
return $output;
}
public function action_add() {
Block::add(array(
'title'=>_('Add SSL CA Certificate'),
'body'=>$this->add_view(),
));
}
public function action_view() {
list($id,$output) = Table::page(__METHOD__);
Block::add(array( Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update SSL Service'),$so->id,$so->display('sign_cert')), 'title'=>sprintf('%s: %s (%s)',_('View SSL CA Certificate'),$id,ORM::factory('ssl_ca',$id)->display('sign_cert')),
'body'=>$output, 'body'=>$this->add_view($id,$output),
)); ));
} }
} }

View File

@ -27,6 +27,9 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
'csr'=>array( 'csr'=>array(
array('SSL::csrsubject',array(':value')), array('SSL::csrsubject',array(':value')),
), ),
'cert'=>array(
array('SSL::subject',array(':value')),
),
); );
// Required abstract functions // Required abstract functions
@ -36,7 +39,7 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
} }
public function name() { public function name() {
return $this->display('csr'); return $this->display($this->cert ? 'cert' : 'csr');
} }
// @todo This needs to be validated for this model // @todo This needs to be validated for this model
@ -47,12 +50,12 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
return $this->service->product->plugin(); return $this->service->product->plugin();
} }
public function valid_from() { public function valid_from($format=FALSE) {
return SSL::from($this->cert); return SSL::from($this->cert,$format);
} }
public function valid_to() { public function valid_to($format=FALSE) {
return SSL::expire($this->cert); return SSL::expire($this->cert,$format);
} }
public function serial_num() { public function serial_num() {
@ -96,7 +99,7 @@ class Model_Service_Plugin_SSL extends Model_Service_Plugin {
} }
public function download_button() { public function download_button() {
if (! preg_match('/client/',$this->ssl->extensions)) if (! $this->service->active OR ! preg_match('/client/',$this->ssl->extensions) OR $this->valid_to() < time())
return ''; return '';
// @todo Do some password validation // @todo Do some password validation

View File

@ -33,5 +33,8 @@ class Model_SSL_CA extends ORMOSB {
public function issuer() { public function issuer() {
return SSL::issuer($this->sign_cert); return SSL::issuer($this->sign_cert);
} }
// @todo SAVE: auto work out the parent_ssl_ca_id
} }
?> ?>

View File

@ -24,14 +24,14 @@ class SSL {
return $k['issuer']['CN']; return $k['issuer']['CN'];
} }
public static function from($key) { public static function from($key,$format=FALSE) {
$k = static::details($key); $k = static::details($key);
return Config::date($k['validFrom_time_t']); return $format ? Config::date($k['validFrom_time_t']) : $k['validFrom_time_t'];
} }
public static function expire($key) { public static function expire($key,$format=FALSE) {
$k = static::details($key); $k = static::details($key);
return Config::date($k['validTo_time_t']); return $format ? Config::date($k['validTo_time_t']) : $k['validTo_time_t'];
} }
public static function hash($key) { public static function hash($key) {

View File

@ -15,11 +15,11 @@
</tr> </tr>
<tr> <tr>
<td>Valid From</td> <td>Valid From</td>
<td class="data"><?php echo $so->valid_from(); ?></td> <td class="data"><?php echo $so->valid_from(TRUE); ?></td>
</tr> </tr>
<tr> <tr>
<td>Valid To</td> <td>Valid To</td>
<td class="data"><?php echo $so->valid_to(); ?></td> <td class="data"><?php echo $so->valid_to(TRUE); ?></td>
</tr> </tr>
<tr> <tr>
<td>Serial Number</td> <td>Serial Number</td>