/** * Contact Action * * @package las * @version 1.0 */ public function contactAction() { $this->tag->setTitle(__('Contact')); if ($this->request->isPost() === true) { $validation = new \Las\Extension\Validation(); $validation->add('fullName', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('content', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('content', new \Phalcon\Validation\Validator\StringLength(array('max' => 5000, 'min' => 10))); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email'))); $validation->setLabels(array('fullName' => __('Full name'), 'content' => __('Content'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email'))); $messages = $validation->validate($_POST); if (count($messages)) { $this->view->setVar('errors', $validation->getMessages()); $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors.")); } else { $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Message was sent")); $email = new \Las\Library\Email(); $email->prepare(__('Contact'), $this->config->app->admin, 'contact', array('fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content'))); $email->addReplyTo($this->request->getPost('email')); if ($email->Send() === true) { unset($_POST); } else { \Las\Bootstrap::log($email->ErrorInfo); } } } }
/** * Tmp action - run the temporarily firewall * * @package las * @version 1.0 */ public function tmpAction() { if ($task = Tasks::findFirst('status=' . Tasks::ACTIVE . ' AND when="@tmp"')) { $firewall = $task->getFirewall(); if ($firewall) { if ($firewall->status == Firewalls::RELOAD) { // Display notice flash $this->tag->setTitle(__('Notice')); $this->view->setVar('title', __('Notice')); $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("The :name firewall was scheduled to reload.", [':name' => '<i>' . $firewall->name . '</i>'])); } elseif ($firewall->status == Firewalls::COMPILED) { $this->tag->setTitle(__('Turn on the temporary access')); $this->view->pick('msg'); // Reload at real time or trigger reload if ($this->las['general']['realTime'] && $this->las['general']['rootPassword']) { try { // Try to run command as root Las::cmd('php ' . ROOT_PATH . '/private/index.php firewall display ' . $firewall->id . ' | sh', true); $this->tag->setTitle(__('Success')); $this->view->setVar('title', __('Success')); $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("The :name firewall was reloaded.", [':name' => '<i>' . $firewall->name . '</i>'])); } catch (Exception $e) { $errors = ['error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"]; \Las\Bootstrap::log($errors); // Display warning flash $this->tag->setTitle(__('Warning')); $this->view->setVar('title', __('Warning')); $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Something is wrong!")); } } else { // Trigger reload - update firewall's status $firewall->status = Firewalls::RELOAD; $firewall->update(); // Display notice flash $this->tag->setTitle(__('Notice')); $this->view->setVar('title', __('Notice')); $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("The :name firewall was scheduled to reload.", [':name' => '<i>' . $firewall->name . '</i>'])); } } } else { $this->response->redirect(null); } } else { parent::notFoundAction(); } }
/** * Delete action - delete the network * * @package las * @version 1.0 */ public function deleteAction() { // Get id from url params and check if record exist $params = $this->router->getParams(); if (isset($params[0]) && ($network = Networks::findFirst($params[0]))) { $this->view->pick('msg'); if ($network->delete() == true) { // Display success flash and redirect $this->tag->setTitle(__('Success')); $this->view->setVars(['title' => __('Success'), 'redirect' => 'admin/networks']); $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("Record has been deleted.")); } else { // Display warning flash and log $this->tag->setTitle(__('Warning')); $this->view->setVars(['title' => __('Warning'), 'content' => \Las\Bootstrap::log($network->getMessages())]); $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Something is wrong!")); } } else { parent::notFoundAction(); } }
/** * 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 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(); } } }
/** * Catch the exception and log it, display pretty view * * @package las * @version 1.0 * * @param \Exception $e */ public static function exception(\Exception $e) { $config = \Phalcon\DI::getDefault()->getShared('config'); $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"); if ($config->app->env == "development") { // Display debug output echo Dump::all($errors); } else { // Display pretty view of the error $di = new \Phalcon\DI\FactoryDefault(); $view = new \Phalcon\Mvc\View\Simple(); $view->setDI($di); $view->setViewsDir(ROOT_PATH . '/app/frontend/views/'); $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di)); echo $view->render('error', array('i18n' => I18n::instance(), 'config' => $config)); // Log errors to file and send email with errors to admin \Las\Bootstrap::log($errors); } }
// Global translation function if (!function_exists('__')) { /** * Translate message * * @package las * @version 1.0 * * @param string $string string to translate * @param array $values replace substrings * * @return string translated string */ function __($string, array $values = NULL) { return \Las\Library\I18n::instance()->_($string, $values); } } if (!defined('ROOT_PATH')) { define('ROOT_PATH', dirname(__DIR__)); } require_once ROOT_PATH . '/app/Bootstrap.php'; $app = new \Las\Bootstrap(new \Phalcon\DI\FactoryDefault()); echo $app->handle()->getContent(); } catch (\Phalcon\Exception $e) { \Las\Bootstrap::exception($e); } catch (\PDOException $e) { \Las\Bootstrap::exception($e); } catch (\Exception $e) { \Las\Bootstrap::exception($e); }
/** * Reload action - run the firewall * * @package las * @version 1.0 */ public function reloadAction() { // Get id from url params and check if record exist $params = $this->router->getParams(); if (isset($params[0]) && ($firewall = Firewalls::findFirst(intval($params[0]) ? $params[0] : ['name=:name:', 'bind' => ['name' => $params[0]]]))) { $this->tag->setTitle(__('Firewalls') . ' / ' . __('Run')); $this->view->pick('msg'); // Reload at real time or trigger reload if ($this->las['general']['realTime'] && $this->las['general']['rootPassword']) { try { // Try to run command as root $output = Las::cmd('php ' . ROOT_PATH . '/private/index.php firewall display ' . $firewall->id . ' | sh', true); $this->tag->setTitle(__('Success')); $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("The :name firewall was reloaded.", [':name' => '<i>' . $firewall->name . '</i>'])); $this->view->setVar('title', __('Success')); // Display debug if setting is enabled if ($this->las['general']['debugCmd']) { $this->view->setVars(['content' => $output, 'redirect' => false]); } else { $this->view->setVars(['redirect' => 'admin/firewalls/display/' . $firewall->id]); } } catch (Exception $e) { $errors = ['error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"]; // Display warning flash and log $this->tag->setTitle(__('Warning')); $this->view->setVars(['title' => __('Warning'), 'content' => \Las\Bootstrap::log($errors)]); $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Something is wrong!")); } } else { // Trigger reload $this->tag->setTitle(__('Notice')); $this->view->setVars(['title' => __('Notice'), 'redirect' => 'admin/firewalls']); $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("The :name firewall was scheduled to reload.", [':name' => '<i>' . $firewall->name . '</i>'])); // Update firewall's status $firewall->status = Firewalls::RELOAD; $firewall->update(); } } }
/** * 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(); } } }
/** * Write method - add/edit the tariff * * @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('name', new Validator\PresenceOf()); $validation->add('name', new Validator\StringLength(['min' => 3, 'max' => 32])); $validation->add('amount', new Validator\PresenceOf()); $validation->add('amount', new Validator\Regex(['pattern' => '/\\d+(\\.\\d{2})?/'])); $validation->add('priority', new Validator\Between(['minimum' => 10, 'maximum' => 99])); $validation->add('downloadRate', new Validator\Between(['minimum' => 0, 'maximum' => Tariffs::rate('download')])); $validation->add('downloadCeil', new Validator\Between(['minimum' => 0, 'maximum' => Networks::ceil('download')])); $validation->add('uploadRate', new Validator\Between(['minimum' => 0, 'maximum' => Tariffs::rate('upload')])); $validation->add('uploadCeil', new Validator\Between(['minimum' => 0, 'maximum' => Networks::ceil('upload')])); $validation->add('limit', new Validator\Regex(['allowEmpty' => true, 'pattern' => '/\\d+/'])); $validation->add('description', new Validator\StringLength(['max' => 1024])); $validation->add('status', new Validator\InclusionIn(['domain' => Tariffs::status()])); $validation->setLabels(['name' => __('Name'), 'amount' => __('Amount'), 'priority' => __('Priority'), 'downloadRate' => __('Download rate'), 'downloadCeil' => __('Download ceil'), 'uploadRate' => __('Upload rate'), 'uploadCeil' => __('Upload ceil'), 'limit' => __('Limit'), '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->amount = $this->request->getPost('amount'); $this->priority = $this->request->getPost('priority', 'int'); $this->downloadRate = $this->request->getPost('downloadRate', 'float'); $this->downloadCeil = $this->request->getPost('downloadCeil', 'float'); $this->uploadRate = $this->request->getPost('uploadRate', 'float'); $this->uploadCeil = $this->request->getPost('uploadCeil', 'float'); $this->limit = $this->request->getPost('limit', 'int', null, ture); $this->description = $this->request->getPost('description'); $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(); } } }
/** * Sign up User method * * @version 1.0 */ public function signup($role = 'login') { $validation = new \Las\Extension\Validation(); $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('username', new \Las\Extension\Uniqueness(array('model' => '\\Las\\Models\\Users'))); $validation->add('username', new \Phalcon\Validation\Validator\StringLength(array('min' => 4, 'max' => 24))); $validation->add('password', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('repeatPassword', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'password'))); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->add('email', new \Las\Extension\Uniqueness(array('model' => '\\Las\\Models\\Users'))); $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email'))); $validation->setLabels(array('username' => __('Username'), 'password' => __('Password'), 'repeatPassword' => __('Repeat password'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email'))); $messages = $validation->validate($_POST); if (count($messages)) { return $validation->getMessages(); } else { $this->username = $this->getDI()->getShared('request')->getPost('username'); $this->password = Auth::instance()->hash($this->getDI()->getShared('request')->getPost('password')); $this->email = $this->getDI()->getShared('request')->getPost('email'); $this->logins = 0; if ($this->create() === true) { if ($role == 'admin') { return $this; } else { $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key); $email = new Email(); $email->prepare(__('Activation'), $this->getDI()->getShared('request')->getPost('email'), 'activation', array('username' => $this->getDI()->getShared('request')->getPost('username'), 'hash' => $hash)); if ($email->Send() === true) { unset($_POST); return true; } else { \Las\Bootstrap::log($email->ErrorInfo); return false; } } } else { \Las\Bootstrap::log($this->getMessages()); return $this->getMessages(); } } }
/** * 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(); } } }
/** * Catch the exception and log it * * @package las * @version 1.0 * * @param \Exception $e */ public static function exception(\Exception $e) { $config = \Phalcon\DI::getDefault()->getShared('config'); $errors = array('error' => get_class($e) . '[' . $e->getCode() . ']: ' . $e->getMessage(), 'info' => $e->getFile() . '[' . $e->getLine() . ']', 'debug' => "Trace: \n" . $e->getTraceAsString() . "\n"); if ($config->app->env == "development") { // Display debug output print_r($e); } else { // Log errors to file and send email with errors to admin \Las\Bootstrap::log($errors); } }
/** * 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(); } } }
/** * 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(); } } }
/** * Umpdate settings method - validate and update settings * * @package las * @version 1.0 */ public static function updateSettings($settings, $validation) { $crypt = \Phalcon\DI::getDefault()->getShared('crypt'); foreach ($settings as $setting) { // If checkbox is unchecked index not exist if ($setting->type == Settings::CHECK && !isset($_POST[$setting->name])) { $_POST[$setting->name] = 0; } // Check if value was changed if (isset($_POST[$setting->name]) && $_POST[$setting->name] != $setting->value) { // Validate the new value $messages = $validation->validate($_POST); if (count($messages)) { return $validation->getMessages(); } else { // Encrypt password field if ($setting->type == Settings::PASSWORD) { $_POST[$setting->name] = $crypt->encryptBase64($_POST[$setting->name]); } $setting->value = $_POST[$setting->name]; if ($setting->update() === true) { continue; } else { \Las\Bootstrap::log($setting->getMessages()); return $setting->getMessages(); } } } } return TRUE; }
/** * 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 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(); } } }