Exemple #1
0
 /**
  * Write method - add/edit the payment
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type of method: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->add('client', new Validator\PresenceOf());
     $validation->add('client', new Validator\InclusionIn(['domain' => Arr::from_model($this->clients, NULL, 'id')]));
     $validation->add('amount', new Validator\PresenceOf());
     $validation->add('amount', new Validator\Regex(['pattern' => '/[-]?\\d+(\\.\\d{2})?/']));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Payments::status()]));
     $validation->setLabels(['client' => __('Client'), 'amount' => __('Amount'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->client_id = $this->request->getPost('client', 'int');
         $this->amount = $this->request->getPost('amount');
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #2
0
 /**
  * Write method - add/edit the firewall
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type of method: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['max' => 32]));
     $validation->add('content', new Validator\PresenceOf());
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Firewalls::status()]));
     $validation->setLabels(['name' => __('Name'), 'content' => __('Content'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->content = $this->request->getPost('content');
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #3
0
 /**
  * Write method - add/edit the service
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['min' => 3, 'max' => 32]));
     $validation->add('chain', new Validator\PresenceOf());
     $validation->add('chain', new Validator\InclusionIn(['domain' => Services::chain(), 'message' => __('Field :field must be a part of list: :domain', [':domain' => join(', ', Services::chain(true))])]));
     $validation->add('protocol', new Validator\InclusionIn(['domain' => Services::protocol(), 'allowEmpty' => true]));
     $validation->add('direction', new Extension\Together(['withOr' => ['client', 'device', 'IP'], 'allowEmpty' => true]));
     $validation->add('client', new Extension\Together(['with' => ['direction'], 'without' => ['device', 'IP'], 'allowEmpty' => true]));
     $validation->add('device', new Extension\Together(['with' => ['direction'], 'without' => ['IP'], 'allowEmpty' => true]));
     $validation->add('IP', new Extension\Together(['with' => ['direction'], 'allowEmpty' => true]));
     $validation->add('client', new Validator\InclusionIn(['domain' => Arr::from_model($this->clients, null, 'id'), 'allowEmpty' => true]));
     $validation->add('device', new Validator\InclusionIn(['domain' => Arr::from_model($this->devices, null, 'id'), 'allowEmpty' => true]));
     $validation->add('IP', new Extension\Ip(['value' => $this->request->getPost('IP'), 'allowEmpty' => true]));
     $validation->add('string', new Validator\StringLength(['max' => 128]));
     $validation->add('portDirection', new Extension\Together(['with' => ['startingPort'], 'allowEmpty' => true]));
     $validation->add('startingPort', new Validator\StringLength(['max' => 16]));
     $validation->add('startingPort', new Extension\Together(['with' => ['portDirection'], 'allowEmpty' => true]));
     $validation->add('endingPort', new Validator\Between(['minimum' => 1, 'maximum' => 65535, 'allowEmpty' => true]));
     $validation->add('endingPort', new Extension\Together(['with' => ['startingPort'], 'allowEmpty' => true]));
     $validation->add('priority', new Validator\InclusionIn(['domain' => Services::priority()]));
     $validation->add('sorting', new Validator\Between(['minimum' => 1, 'maximum' => 65535, 'allowEmpty' => true]));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Services::status()]));
     $validation->setFilters('IP', 'ip2long');
     $validation->setLabels(['name' => __('Name'), 'chain' => __('Chain'), 'protocol' => __('Protocol'), 'direction' => __('Direction'), 'client' => __('Client'), 'device' => __('Device'), 'IP' => __('IP'), 'string' => __('String'), 'portDirection' => __('Port direction'), 'startingPort' => __('Starting port'), 'endingPort' => __('Ending port'), 'lengthEnd' => __('Length end'), 'lengthStart' => __('Length start'), 'priority' => __('Priority'), 'sorting' => __('Sorting'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->chain = $this->request->getPost('chain', 'int');
         $this->protocol = $this->request->getPost('protocol', 'int', null, true);
         $this->direction = $this->request->getPost('direction', 'int', null, true);
         $this->client_id = $this->request->getPost('client', 'int', 0, true);
         $this->device_id = $this->request->getPost('device', 'int', 0, true);
         $this->IP = $this->request->getPost('IP', 'ip2long');
         $this->portDirection = $this->request->getPost('portDirection', 'int');
         $this->startingPort = $this->request->getPost('startingPort', 'string', null, true);
         $this->endingPort = $this->request->getPost('endingPort', 'int', null, true);
         $this->internalStartingPort = $this->request->getPost('internalStartingPort', 'int', null, true);
         $this->internalEndingPort = $this->request->getPost('internalEndingPort', 'int', null, true);
         $this->priority = $this->request->getPost('priority', 'int', 0, true);
         $this->sorting = $this->request->getPost('sorting', 'int', 100, true);
         $this->description = $this->request->getPost('description', 'string', null, true);
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #4
0
 /**
  * Write method - add/edit the task
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type of method: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->setDefaultMessages(['TogetherWith' => 'Field :field must occur together with :with', 'TogetherWithOr' => 'Field :field must occur together with one of: :with', 'TogetherWithout' => 'Field :field must not occur together with :with']);
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['max' => 32]));
     $validation->add('when', new Validator\PresenceOf());
     $validation->add('when', new Validator\StringLength(['max' => 64]));
     $validation->add('type', new Validator\PresenceOf());
     $validation->add('type', new Validator\InclusionIn(['domain' => Tasks::type()]));
     if ($this->request->getPost('type', 'int') == Tasks::FIREWALL) {
         $validation->add('type', new Extension\Together(['with' => ['firewall']]));
     }
     $validation->add('firewall', new Extension\Together(['with' => ['type' => Tasks::FIREWALL], 'allowEmpty' => true]));
     $validation->add('firewall', new Validator\InclusionIn(['domain' => Arr::from_model($this->firewalls, null, 'id'), 'allowEmpty' => true]));
     $validation->add('next', new Validator\Regex(['pattern' => '/\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}/', 'message' => 'Required format: YYYY-MM-DD hh:mm', 'allowEmpty' => true]));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Tasks::status()]));
     $validation->setLabels(['name' => __('Name'), 'when' => __('When'), 'type' => __('Type'), 'firewall' => __('Firewall'), 'next' => __('Next'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->when = $this->request->getPost('when', 'string');
         $this->type = $this->request->getPost('type', 'int');
         $this->firewall_id = $this->request->getPost('firewall', 'int', 0, true);
         $this->next = strtotime($this->request->getPost('next', 'string'));
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #5
0
 /**
  * Write method - edit the message
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type: create/update
  * @return mixed
  */
 public function edit()
 {
     $validation = new Extension\Validation();
     $validation->add('title', new Validator\StringLength(['min' => 3, 'max' => 64, 'allowEmpty' => true]));
     $validation->add('client', new Validator\InclusionIn(['domain' => Arr::from_model($this->clients, null, 'id')]));
     $validation->add('content', new Validator\PresenceOf());
     $validation->add('status', new Validator\InclusionIn(['domain' => Messages::status()]));
     $validation->setLabels(['title' => __('Title'), 'client' => __('Client'), 'content' => __('Content'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->title = $this->request->getPost('title', 'string');
         $this->client_id = $this->request->getPost('client', 'int');
         $this->content = $this->request->getPost('content', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the records
         if ($this->update() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #6
0
 /**
  * Write method - add/edit the device
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $this->getDI()->getShared('filter')->add('mac', function ($mac) {
         return strtoupper(str_replace('-', ':', $mac));
     });
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['min' => 3, 'max' => 32]));
     $validation->add('name', new Validator\Regex(['pattern' => '/([A-Z][A-Z0-9_-]{2,})/']));
     $validation->add('network', new Validator\PresenceOf());
     $validation->add('network', new Validator\InclusionIn(['domain' => Arr::from_model($this->networks, null, 'id')]));
     $validation->add('client', new Validator\PresenceOf());
     $validation->add('client', new Validator\InclusionIn(['domain' => Arr::from_model($this->clients, null, 'id')]));
     $validation->add('type', new Validator\PresenceOf());
     $validation->add('type', new Validator\InclusionIn(['domain' => Devices::type()]));
     $validation->add('IP', new Validator\PresenceOf());
     $validation->add('IP', new Extension\Ip(['value' => $this->request->getPost('IP')]));
     $validation->add('IP', new Validator\ExclusionIn(['domain' => Arr::from_model($this->networks, null, 'IP'), 'message' => __('Field :field is reserved')]));
     $validation->add('IP', new Extension\Uniqueness(['model' => __CLASS__, 'except' => isset($this->IP) ? $this->IP : null]));
     $network = Networks::findFirst($this->request->getPost('network', 'int'));
     $validation->add('IP', new Extension\Cidr(['cidr' => $network->subnetwork . $network->mask]));
     $validation->add('MAC', new Validator\PresenceOf());
     $validation->add('MAC', new Validator\Regex(['pattern' => '/([0-9a-fA-F]{2}[:|\\-]){5}[0-9a-fA-F]{2}/']));
     $validation->add('MAC', new Extension\Uniqueness(['model' => __CLASS__, 'except' => isset($this->MAC) ? $this->MAC : null]));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Devices::status()]));
     $validation->setFilters('IP', 'ip2long');
     $validation->setFilters('MAC', 'mac');
     $validation->setLabels(['name' => __('Name'), 'network' => __('Network'), 'client' => __('Client'), 'type' => __('Type'), 'IP' => __('IP'), 'MAC' => __('MAC'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->network_id = $this->request->getPost('network', 'int');
         $this->client_id = $this->request->getPost('client', 'int');
         $this->type = $this->request->getPost('type', 'int');
         $this->IP = $this->request->getPost('IP', 'ip2long');
         $this->MAC = $this->request->getPost('MAC', 'mac');
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #7
0
 /**
  * Write method - add/edit the network
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type of method: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['max' => 32]));
     $validation->add('interface', new Validator\PresenceOf());
     $validation->add('interface', new Validator\StringLength(['max' => 32]));
     $validation->add('interface', new Extension\Uniqueness(['model' => __CLASS__, 'except' => isset($this->interface) ? $this->interface : null]));
     $validation->add('subnetwork', new Validator\PresenceOf());
     $validation->add('subnetwork', new Extension\Ip(['value' => $this->request->getPost('subnetwork')]));
     $validation->add('subnetwork', new Extension\Uniqueness(['model' => __CLASS__, 'except' => isset($this->subnetwork) ? $this->subnetwork : null]));
     $validation->add('type', new Validator\PresenceOf());
     $validation->add('type', new Validator\InclusionIn(['domain' => Networks::type()]));
     $validation->add('IP', new Validator\PresenceOf());
     $validation->add('IP', new Extension\Ip(['value' => $this->request->getPost('IP')]));
     $validation->add('IP', new Extension\Uniqueness(['model' => __CLASS__, 'except' => isset($this->IP) ? $this->IP : null]));
     $validation->add('gateway', new Validator\PresenceOf());
     $validation->add('gateway', new \Las\Extension\Ip(['value' => $this->request->getPost('gateway')]));
     $validation->add('DNS', new Extension\Dns(['allowEmpty' => true]));
     $validation->add('DNS', new Extension\Together(['with' => ['type' => Networks::WAN], 'allowEmpty' => true]));
     $validation->add('DHCP', new Extension\Dhcp(['allowEmpty' => true]));
     $validation->add('DHCP', new Extension\Together(['with' => ['type' => Networks::LAN], 'allowEmpty' => true]));
     $validation->add('mask', new Validator\InclusionIn(['domain' => array_keys(Networks::mask())]));
     $validation->add('download', new Validator\Between(['minimum' => 0, 'maximum' => 1000]));
     $validation->add('upload', new Validator\Between(['minimum' => 0, 'maximum' => 1000]));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Networks::status()]));
     $validation->setFilters('subnetwork', 'ip2long');
     $validation->setFilters('IP', 'ip2long');
     $validation->setFilters('gateway', 'ip2long');
     $validation->setLabels(['name' => __('Name'), 'interface' => __('Interface'), 'subnetwork' => __('Subnetwork'), 'type' => __('Type'), 'IP' => __('IP'), 'gateway' => __('Gateway'), 'DNS' => __('DNS'), 'DHCP' => __('DHCP'), 'mask' => __('Mask'), 'download' => __('Download'), 'upload' => __('Upload'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->interface = $this->request->getPost('interface', 'string');
         $this->subnetwork = $this->request->getPost('subnetwork', 'ip2long');
         $this->type = $this->request->getPost('type', 'int');
         $this->IP = $this->request->getPost('IP', 'ip2long');
         $this->mask = $this->request->getPost('mask', 'string');
         $this->gateway = $this->request->getPost('gateway', 'ip2long');
         $this->DNS = $this->request->getPost('DNS', 'string');
         $this->DHCP = $this->request->getPost('DHCP', 'string');
         $this->download = $this->request->getPost('download', 'int', 0, true);
         $this->upload = $this->request->getPost('upload', 'int', 0, true);
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }
Exemple #8
0
 /**
  * Write method - add/edit the redirect
  *
  * @package     las
  * @version     1.0
  *
  * @param string $method type: create/update
  * @return mixed
  */
 public function write($method = 'create')
 {
     $validation = new Extension\Validation();
     $validation->add('name', new Validator\PresenceOf());
     $validation->add('name', new Validator\StringLength(['min' => 3, 'max' => 32]));
     $validation->add('device', new Validator\PresenceOf());
     $validation->add('device', new Validator\InclusionIn(['domain' => Arr::from_model($this->devices, null, 'id')]));
     $validation->add('type', new Validator\InclusionIn(['domain' => Redirects::type()]));
     $validation->add('externalStartingPort', new Validator\Between(['minimum' => 1, 'maximum' => 65535]));
     $validation->add('externalEndingPort', new Validator\Between(['minimum' => 1, 'maximum' => 65535, 'allowEmpty' => true]));
     $validation->add('internalStartingPort', new Validator\Between(['minimum' => 1, 'maximum' => 65535, 'allowEmpty' => true]));
     $validation->add('internalEndingPort', new Validator\Between(['minimum' => 1, 'maximum' => 65535, 'allowEmpty' => true]));
     $validation->add('description', new Validator\StringLength(['max' => 1024]));
     $validation->add('status', new Validator\InclusionIn(['domain' => Redirects::status()]));
     $validation->setLabels(['name' => __('Name'), 'device' => __('Device'), 'type' => __('Type'), 'externalStartingPort' => __('External starting port'), 'externalEndingPort' => __('External ending port'), 'internalStartingPort' => __('Internal starting port'), 'internalEndingPort' => __('Internal ending port'), 'description' => __('Description'), 'status' => __('Status')]);
     $messages = $validation->validate($_POST);
     // Return messages if validation not pass
     if (count($messages)) {
         return $validation->getMessages();
     } else {
         $this->name = $this->request->getPost('name', 'string');
         $this->device_id = $this->request->getPost('device', 'int');
         $this->type = $this->request->getPost('type', 'int');
         $this->externalStartingPort = $this->request->getPost('externalStartingPort', 'int');
         $this->externalEndingPort = $this->request->getPost('externalEndingPort', 'int', null, true);
         $this->internalStartingPort = $this->request->getPost('internalStartingPort', 'int', null, true);
         $this->internalEndingPort = $this->request->getPost('internalEndingPort', 'int', null, true);
         $this->description = $this->request->getPost('description', 'string');
         $this->status = $this->request->getPost('status', 'int');
         $this->date = date('Y-m-d H:i:s');
         // Try to write the record
         if ($this->{$method}() === true) {
             return $this;
         } else {
             \Las\Bootstrap::log($this->getMessages());
             return $this->getMessages();
         }
     }
 }