Exemplo n.º 1
0
 /**
  * Display firewall code
  *
  * @package     las
  * @version     1.0
  */
 public static function display($path, $vars = [])
 {
     $di = \Phalcon\DI::getDefault();
     if ($di->getShared('router')->getModuleName() == 'cli') {
         $view = $di->getShared('view');
     } else {
         $view = new \Phalcon\Mvc\View();
         $view->setDI($di);
         $view->registerEngines(\Las\Library\Tool::registerEngines($view, $di));
     }
     $settings = json_decode(json_encode(\Las\Library\Arr::from_model(Settings::find('status=' . Settings::ACTIVE), 'name', 'value')));
     $lans = Networks::find('status = ' . Networks::ACTIVE . ' AND type = ' . Networks::LAN);
     $wans = Networks::find('status = ' . Networks::ACTIVE . ' AND type = ' . Networks::WAN);
     $vars = ['clients' => Clients::find(), 'devices' => Devices::find('status=' . Devices::ACTIVE), 'messages' => Messages::find('status=' . Messages::ACTIVE), 'tariffs' => Tariffs::find('status=' . Tariffs::ACTIVE), 'settings' => $settings, 'redirects' => Redirects::find('status=' . Redirects::ACTIVE), 'services' => Services::find('status=' . Services::ACTIVE . ' AND client_id=0 AND device_id=0'), 'lans' => $lans, 'lan' => $lans->getFirst(), 'wans' => $wans, 'wan' => $wans->getFirst(), 'ipt' => $settings->iptables, 'tc' => $settings->tc, 'EOL' => PHP_EOL];
     $view->setViewsDir(ROOT_PATH . '/app/common/cache/volt/app/cli/views/');
     ob_start();
     $view->partial($path, $vars);
     return preg_replace(['/^\\s+|^[\\t\\s]*\\n+/m', "/\r/"], '', ob_get_clean());
     //return preg_replace('/^\s+|^[\t\s]*\n+/m', "/\x0D/"], '', $view->partial($path, $vars, false));
 }
Exemplo n.º 2
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();
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Edit action - edit the redirect
  *
  * @package     las
  * @version     1.0
  */
 public function editAction()
 {
     // Get id from url params and check if record exist
     $params = $this->router->getParams();
     if (isset($params[0]) && ($redirect = Redirects::findFirst($params[0]))) {
         $devices = Devices::find(['status=:status:', 'bind' => ['status' => Devices::ACTIVE]]);
         if (!count($devices)) {
             $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the device first") . ': ' . $this->tag->linkTo('admin/devices/add', __('Add')));
         }
         // Set title, pick view and send variables
         $this->tag->setTitle(__('Redirects') . ' / ' . __('Edit'));
         $this->view->pick('redirects/write');
         $this->view->setVars(['devices' => $devices, 'status' => Redirects::status(true), 'type' => Redirects::type(true)]);
         // Check if the form has been sent
         if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
             $redirect->__set('devices', $devices);
             $valid = $redirect->write('update');
             // Check if data are valid
             if ($valid instanceof Redirects) {
                 $this->flashSession->success($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Success') . '!</strong> ' . __("The data has been saved."));
             } else {
                 $this->view->setVar('errors', $valid);
                 $this->flashSession->warning($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors."));
             }
         } else {
             $diff = ['device' => $redirect->device_id];
             // Values to fill out the form
             $this->tag->setDefaults(array_merge(get_object_vars($redirect), $diff));
         }
     } else {
         parent::notFoundAction();
     }
 }