コード例 #1
0
ファイル: FirewallTask.php プロジェクト: RobBickel/las
 /**
  * Display Action - display/run the firewall
  *
  * @package     las
  * @version     1.0
  */
 public function displayAction()
 {
     $params = $this->dispatcher->getParams();
     if (isset($params[0]) && ($firewall = Firewalls::findFirst(intval($params[0]) ? $params[0] : ['name=:name:', 'bind' => ['name' => $params[0]]]))) {
         echo Las::display($firewall->name);
     }
 }
コード例 #2
0
ファイル: TasksController.php プロジェクト: RobBickel/las
 /**
  * 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();
     }
 }
コード例 #3
0
ファイル: FirewallsController.php プロジェクト: RobBickel/las
 /**
  * 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();
         }
     }
 }