0, 'download'=>0, 'view'=>0, ); public function action_add() { 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!'), )); else { $so = ORM::factory('SSL'); $so->account_id = (string)Auth::instance()->get_user(); // 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)); } } Block::factory() ->type('form-horizontal') ->title('SSL Certificate') ->title_icon('fa-certificate') ->body(View::factory('ssl/user/add')->set('o',$this->ao)); } public function action_download() { $passwd_len = Kohana::$config->load('ssl')->minpass_length; $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 ($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)); } } ?>