Implement PLESK, SSL Services

This commit is contained in:
Deon George
2011-12-17 10:31:35 +11:00
parent cb18209369
commit c8fd44f844
29 changed files with 1038 additions and 438 deletions

View File

@@ -0,0 +1,59 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Admin SSL functions
*
* @package OSB
* @subpackage SSL
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'list'=>TRUE,
'update'=>TRUE,
);
public function action_list() {
Block::add(array(
'title'=>_('SSL Services'),
'body'=>Table::display(
ORM::factory('ssl_ca')->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'admin/ssl/update/'),
'sign_cert'=>array('label'=>'Cert'),
'issuer()'=>array('label'=>'Issuer'),
'expires()'=>array('label'=>'Expires'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'admin/ssl/update',
)),
));
}
public function action_update() {
$id = $this->request->param('id');
$so = ORM::factory('ssl_ca',$id);
if (! $so->loaded())
Request::current()->redirect('welcome/index');
if ($_POST) {
if (! $so->values($_POST)->update()->saved())
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
}
Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update SSL Service'),$so->id,$so->display('sign_cert')),
'body'=>View::factory('ssl/admin/update')
->set('so',$so)
->set('mediapath',Route::get('default/media'))
));
}
}
?>

View File

@@ -0,0 +1,25 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides OSB SSL task capabilities.
*
* @package OSB
* @subpackage SSL
* @category Controllers/Task
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Task_SSL extends Controller_Task {
/**
* Renew a certificate
*/
public function action_renew() {
// @todo, Change this to be a SSL id, maybe list all the certs expiring
$id = $this->request->param('id');
$so = ORM::factory('service',$id);
$so->plugin()->renew();
}
}
?>

View File

@@ -0,0 +1,51 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User SSL functions
*
* @package OSB
* @subpackage SSL
* @category Controllers/Admin
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_User_SSL extends Controller_TemplateDefault_User {
protected $secure_actions = array(
'download'=>FALSE,
);
public function action_download() {
$id = $_POST['sid'];
$so = ORM::factory('service',$id);
if (! $so->loaded())
Request::current()->redirect('welcome/index');
$passwd = $_POST['passwd'];
if (strlen($passwd) < Kohana::config('ssl.minpass_length')) {
SystemMessage::add(array(
'title'=>_('Validation failed'),
'type'=>'error',
'body'=>_('Your requested password is too short.'),
));
Request::current()->redirect('user/service/view/'.$so->id);
}
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account_id,$so->affiliate_id)) {
$this->template->content = 'Unauthorised or doesnt exist?';
return FALSE;
}
$file = Kohana::config('config.tmpdir').'/'.$so->name().'.pkcs12';
openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts()));
$x = file_get_contents($file);
unlink($file);
$this->response->headers('Content-Type','application/pks12');
$this->response->headers('Content-Disposition','attachment; filename="'.basename($file).'"');
$this->response->body($x);
$this->auto_render = FALSE;
}
}
?>