mirror of https://github.com/MISP/MISP
140 lines
3.6 KiB
PHP
Executable File
140 lines
3.6 KiB
PHP
Executable File
<?php
|
|
App::uses('AppModel', 'Model');
|
|
/**
|
|
* Server Model
|
|
*
|
|
*/
|
|
class Server extends AppModel {
|
|
|
|
public $name = 'Server'; // TODO general
|
|
|
|
public $actsAs = array('SysLogLogable.SysLogLogable' => array( // TODO Audit, logable, check: 'userModel' and 'userKey' can be removed given default
|
|
'userModel' => 'User',
|
|
'userKey' => 'user_id',
|
|
'change' => 'full'
|
|
));
|
|
|
|
/**
|
|
* Display field
|
|
*
|
|
* @var string
|
|
*/
|
|
public $displayField = 'url';
|
|
|
|
/**
|
|
* Validation rules
|
|
*
|
|
* @var array
|
|
*/
|
|
public $validate = array(
|
|
'url' => array( // TODO add extra validation to refuse multiple time the same url from the same org
|
|
'url' => array(
|
|
'rule' => array('url'),
|
|
'message' => 'Please enter a valid base-url.',
|
|
//'allowEmpty' => false,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
)
|
|
),
|
|
'authkey' => array(
|
|
'minlength' => array(
|
|
'rule' => array('minlength', 40),
|
|
'message' => 'A authkey of a minimum length of 40 is required.',
|
|
'required' => true,
|
|
),
|
|
'notempty' => array(
|
|
'rule' => array('notempty'),
|
|
'message' => 'Please enter a valid authentication key.',
|
|
//'allowEmpty' => false,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'org' => array(
|
|
'notempty' => array(
|
|
'rule' => array('notempty'),
|
|
//'message' => 'Your custom message here',
|
|
//'allowEmpty' => false,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'push' => array(
|
|
'boolean' => array(
|
|
'rule' => array('boolean'),
|
|
//'message' => 'Your custom message here',
|
|
'allowEmpty' => true,
|
|
'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'pull' => array(
|
|
'boolean' => array(
|
|
'rule' => array('boolean'),
|
|
//'message' => 'Your custom message here',
|
|
'allowEmpty' => true,
|
|
//'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'lastpushedid' => array(
|
|
'numeric' => array(
|
|
'rule' => array('numeric'),
|
|
//'message' => 'Your custom message here',
|
|
'allowEmpty' => true,
|
|
'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
'lastpulledid' => array(
|
|
'numeric' => array(
|
|
'rule' => array('numeric'),
|
|
//'message' => 'Your custom message here',
|
|
'allowEmpty' => true,
|
|
'required' => false,
|
|
//'last' => false, // Stop validation after this rule
|
|
//'on' => 'create', // Limit validation to 'create' or 'update' operations
|
|
),
|
|
),
|
|
);
|
|
|
|
/**
|
|
* Trim Array Elements (this should probably be in a behavior)
|
|
*
|
|
* @param $array
|
|
*/
|
|
protected function _trimArray(&$array = array()) {
|
|
// process some..
|
|
foreach ($array as &$field) {
|
|
// remove leading and trailing blanks
|
|
if (is_string($field)) {
|
|
$field = trim($field);
|
|
}
|
|
}
|
|
return $array;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param $options
|
|
*/
|
|
public function beforeValidate($options = array()) {
|
|
parent::beforeValidate();
|
|
|
|
// process some..
|
|
$this->_trimArray($this->data['Server']);
|
|
|
|
return true;
|
|
}
|
|
|
|
public function isOwnedByOrg($serverid, $org) {
|
|
return $this->field('id', array('id' => $serverid, 'org' => $org)) === $serverid;
|
|
}
|
|
}
|