array(), ); protected $_has_one = array( 'ca'=>array('model'=>'SSL_CA','far_key'=>'ssl_ca_id','foreign_key'=>'id'), ); protected $_display_filters = array( 'csr'=>array( array('SSL::csrsubject',array(':value')), ), 'cert'=>array( array('SSL::subject',array(':value')), ), ); protected $_save_message = TRUE; // Required abstract functions 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() {} // Not used public function username() {} // Not used // Local functions private $_so = NULL; /** * Resolve any queries to certificate details */ public function __call($name,$args) { $m = 'get_'.$name; if (method_exists($this->_so,$m)) return $this->_so->{$m}($args); else throw new Kohana_Exception('Unknown method :method',array(':method'=>$name)); } // We want to inject the SSL object into this Model protected function _load_values(array $values) { parent::_load_values($values); if ($this->cert) $this->_so = SSL::instance($this->cert); 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); if (array_key_exists('cert',$values)) $this->_so = SSL::instance($this->cert); return $this; } /** * Get specific service details for use in other modules * For Example: Invoice * * @todo Make the rendered items configurable * @todo Change this method name, now that it is public */ // @todo This needs to be validated for this model public function _details($type) { switch ($type) { case 'invoice_detail_items': return array(); break; default: return parent::$_details($type); } } public function download_button() { if (! $this->service->status OR ! preg_match('/client/',$this->service->product->plugin()->extensions) OR $this->valid_to() < time()) return ''; $output = Form::open(URL::link('user','ssl/download'),array('class'=>'form-inline')); $output .= Form::hidden('sid',$this->service->id); $output .= '