This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
tsmac/modules/ssl/classes/Controller/User/Ssl.php

124 lines
3.4 KiB
PHP
Raw Normal View History

2014-10-08 12:17:00 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User SSL functions
*
* @package SSL
* @category Controllers/User
* @author Deon George
* @copyright (c) 2009-2013 Deon George
* @license http://dev.leenooks.net/license.html
*/
2014-10-09 12:23:02 +00:00
class Controller_User_Ssl extends Controller_Ssl {
2014-10-08 12:17:00 +00:00
protected $auth_required = TRUE;
protected $secure_actions = array(
'add'=>0,
'download'=>0,
'view'=>0,
);
public function action_add() {
2014-10-09 12:23:02 +00:00
if ($this->request->post() OR $_FILES) {
if ($_FILES AND $this->request->post('csr'))
SystemMessage::add(array(
'title'=>_('Validation failed'),
'type'=>'info',
'body'=>_('Only supply a CSR file OR the CSR text, not both!'),
));
2014-10-08 12:17:00 +00:00
2014-10-09 12:23:02 +00:00
else {
2014-10-08 12:17:00 +00:00
2014-10-09 12:23:02 +00:00
$so = ORM::factory('SSL');
$so->account_id = (string)Auth::instance()->get_user();
2014-10-08 12:17:00 +00:00
2014-10-09 12:23:02 +00:00
// Set our values, so that our filters have data
$so->values($this->request->post());
if ($_FILES) {
// Process upload
$files = Validation::factory($_FILES)
->rule('csr_file','Upload::valid')
->rule('csr_file','Upload::not_empty')
->rule('csr_file','Upload::type',array(':value',array('csr')))
->rule('csr_file','Upload::size',array(':value','512K'));
if ($files->check())
foreach ($files->data() as $file) {
$so->csr = file_get_contents($file['tmp_name']);
break;
}
if (! $so->csr)
throw HTTP_Exception::factory(501,'No CSR data :csr_file?',$files->errors('user/ssl/add'));
}
$this->save($so);
if ($so->saved())
HTTP::redirect(URL::link('user','ssl/view/'.$so->id));
}
2014-10-08 12:17:00 +00:00
}
Block::factory()
->type('form-horizontal')
2014-10-09 12:23:02 +00:00
->title('SSL Certificate')
->title_icon('fa-certificate')
2014-10-08 12:17:00 +00:00
->body(View::factory('ssl/user/add')->set('o',$this->ao));
}
public function action_download() {
$passwd_len = Kohana::$config->load('ssl')->minpass_length;
2014-10-09 12:23:02 +00:00
$so = ORM::factory('SSL',$this->request->param('id'));
2014-10-08 12:17:00 +00:00
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account))
throw HTTP_Exception::factory(403,'SSL either doesnt exist, or you are not authorised to see it');
if ($passwd_len) {
$passwd = $this->request->post('passwd');
if (strlen($passwd) < $passwd_len) {
SystemMessage::add(array(
'title'=>_('Validation failed'),
'type'=>'danger',
'body'=>_('Your requested password is too short.'),
));
HTTP::redirect(URL::link('user','ssl/view/'.$so->id));
}
}
$this->auto_render = FALSE;
$this->response->headers('Content-Type','plain/text');
$this->response->headers('Content-Disposition','attachment; filename="'.$this->ao->id().'.crt"');
$this->response->body($so->cert);
}
public function action_view() {
$so = ORM::factory('SSL',$this->request->param('id'));
if (! $so->loaded() OR ! Auth::instance()->authorised($so->account))
throw HTTP_Exception::factory(403,'SSL either doesnt exist, or you are not authorised to see it');
if ($this->request->post()) {
$so->account_id = (string)Auth::instance()->get_user();
// Set our values, so that our filters have data
$so->values($this->request->post());
if ($so->changed() AND ! $this->save($so))
$so->reload();
if ($so->saved())
HTTP::redirect(URL::link('user','ssl/view/'.$so->id));
}
Block::factory()
->title('SSL Certificate')
->title_icon('fa-certificate')
->body(View::factory('ssl/user/view')->set('o',$so));
}
}
?>