/** * Initialize * * @package las * @version 1.0 */ public function initialize() { // Redirect to home page if user is not admin if (!$this->auth->logged_in('admin')) { $adminRole = Roles::findFirst('name="admin"'); if (!RolesUsers::count('role_id=' . $adminRole->id)) { $this->response->redirect('install'); } else { $this->response->redirect(''); } } // Check the session lifetime if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) { $this->session->destroy(); } $this->session->set('last_active', time()); // Set the language from session if ($this->session->has('lang')) { $this->i18n->lang($this->session->get('lang')); // Set the language from cookie } elseif ($this->cookies->has('lang')) { $this->i18n->lang($this->cookies->get('lang')->getValue()); } // Get the settings $this->las = Arr::from_model(Settings::find(['status = ' . Settings::ACTIVE]), 'category', ['name' => 'value']); // Send langs to the view $this->view->setVars(['siteLangs' => array_map('__', $this->config->i18n->langs->toArray()), 'las' => $this->las]); }
/** * 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(); } } }
/** * Write method - add/edit the client * * @package las * @version 1.0 * * @param string $method type: create/update * @return mixed */ public function write($method = 'create') { $validation = new \Las\Extension\Validation(); $validation->add('fullName', new Validator\PresenceOf()); $validation->add('fullName', new Validator\StringLength(['min' => 3, 'max' => 32])); $validation->add('address', new Validator\StringLength(['max' => 256])); $validation->add('tariff', new Validator\PresenceOf()); $validation->add('tariff', new Validator\InclusionIn(['domain' => Arr::from_model($this->tariffs, NULL, 'id')])); $validation->add('description', new Validator\StringLength(['max' => 1024])); $validation->add('status', new Validator\InclusionIn(['domain' => Clients::status()])); $validation->setLabels(['fullName' => __('Full name'), 'address' => __('Address'), 'tariff' => __('Tariff'), 'description' => __('Description'), 'status' => __('Status')]); $messages = $validation->validate($_POST); // Return messages if validation not pass if (count($messages)) { return $validation->getMessages(); } else { $this->fullName = $this->request->getPost('fullName', 'string'); $this->address = $this->request->getPost('address', 'string'); $this->tariff_id = $this->request->getPost('tariff', 'int'); $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(); } } }
/** * Options method - get option value(s) * * @package las * @version 1.0 */ public static function options($name, $value = null, $settings = null) { if ($settings === null) { $settings = Settings::find(); } $options = json_decode(Arr::from_model($settings, 'name')[$name]['options'], true); return $value ? $options[$value] : $options; }
public static function cmd($str, $root = false) { $las = \Las\Library\Arr::from_model(Settings::find(array('status = ' . Settings::ACTIVE)), 'category', array('name' => 'value')); if ($root) { $crypt = \Phalcon\DI::getDefault()->getShared('crypt'); exec('echo ' . $crypt->decryptBase64($las['general']['rootPassword']) . ' | su -c ' . '"' . $str . '"', $results); } else { exec($str, $results); } if ($las['general']['debugCmd']) { $results = Dump::one($results, 'output'); $results .= Dump::one($str, 'commands'); } return $results; }
/** * Initialize * * @package las * @version 1.0 */ public function initialize() { // Check the session lifetime if ($this->session->has('last_active') && time() - $this->session->get('last_active') > $this->config->session->options->lifetime) { $this->session->destroy(); } $this->session->set('last_active', time()); // Set the language from session if ($this->session->has('lang')) { I18n::instance()->lang($this->session->get('lang')); // Set the language from cookie } elseif ($this->cookies->has('lang')) { I18n::instance()->lang($this->cookies->get('lang')->getValue()); } $this->las = \Las\Library\Arr::from_model(Settings::find(array('status = ' . Settings::ACTIVE)), 'category', array('name' => 'value')); // Send i18n, auth and langs to the view $this->view->setVars(array('auth' => Auth::instance(), 'i18n' => I18n::instance(), 'siteLangs' => array_map('__', $this->config->i18n->langs->toArray()), 'las' => $this->las)); }
/** * 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(); } } }
/** * 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(); } } }
/** * 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(); } } }
/** * 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(); } } }
/** * 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(); } } }