Ejemplo n.º 1
0
 /**
  * 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]);
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 /**
  * 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));
 }
Ejemplo n.º 4
0
 /**
  * Qos settings
  *
  * @package     las
  * @version     1.0
  */
 public function qosAction()
 {
     $this->tag->setTitle(__('Settings') . ' / ' . __(ucfirst($this->dispatcher->getActionName())));
     $settings = Settings::find(['category = :category: AND status = :status:', 'bind' => [':category' => $this->dispatcher->getActionName(), ':status' => Settings::ACTIVE]]);
     $this->view->setVars(['settings' => $settings, 'category' => __(ucfirst($this->dispatcher->getActionName())), 'priority' => \Las\Models\Services::priority(true)]);
     // Check if the form has been sent
     if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
         // Try to update settings
         $valid = Settings::qos($settings);
         // Check if data are valid
         if ($valid === TRUE) {
             $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 {
         // Values to fill out the form
         $this->tag->setDefaults($this->las[$this->dispatcher->getActionName()]);
     }
 }
Ejemplo n.º 5
0
 /**
  * Get service's priority(s)
  *
  * @package     las
  * @version     1.0
  *
  * @param mixed $key key to get priority
  * @return mixed
  */
 public static function priority($key = false, $type = 'text')
 {
     $priority = [Services::DISABLED => ['text' => __('Disabled'), 'name' => 'disabled'], Services::HIGHEST => ['text' => __('Highest'), 'name' => 'highest'], Services::HIGH => ['text' => __('High'), 'name' => 'high'], Services::MEDIUM => ['text' => __('Medium'), 'name' => 'medium'], Services::LOW => ['text' => __('Low'), 'name' => 'low'], Services::LOWEST => ['text' => __('Lowest'), 'name' => 'lowest']];
     if ($key === 'qos') {
         unset($priority[Services::DISABLED]);
         $settings = Arr::from_model(Settings::find('category="qos"'), 'name', 'value');
         foreach ($priority as $prio => $values) {
             $priority[$prio]['rate'] = isset($settings[$values['name'] . 'Rate']) ? $settings[$values['name'] . 'Rate'] : null;
             $priority[$prio]['ceil'] = isset($settings[$values['name'] . 'Ceil']) ? $settings[$values['name'] . 'Ceil'] : null;
         }
         return $priority;
     } elseif ($key !== false) {
         if ($key !== true) {
             return $priority[$key][$type];
         } else {
             $array = [];
             foreach ($priority as $key => $value) {
                 $array[$key] = $value[$type];
             }
             return $array;
         }
     } else {
         return array_keys($priority);
     }
 }
Ejemplo n.º 6
0
 /**
  * Edit action - edit the network
  *
  * @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]) && ($network = Networks::findFirst($params[0]))) {
         // Set title, pick view and send variables
         $this->tag->setTitle(__('Networks') . ' / ' . __('Edit'));
         $this->view->pick('networks/write');
         $this->view->setVars(['type' => Networks::type(true), 'status' => Networks::status(true), 'bitRate' => Settings::options('bitRate', $this->las['general']['bitRate'])]);
         // Check if the form has been sent
         if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
             $valid = $network->write('update');
             // Check if data are valid
             if ($valid instanceof Networks) {
                 $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 = ['subnetwork' => long2ip($network->subnetwork), 'IP' => long2ip($network->IP), 'gateway' => long2ip($network->gateway)];
             // Values to fill out the form
             $this->tag->setDefaults(array_merge(get_object_vars($network), $diff));
         }
     } else {
         parent::notFoundAction();
     }
 }
Ejemplo n.º 7
0
 /**
  * Qos method - save Qos settings
  *
  * @package     las
  * @version     1.0
  */
 public static function qos($settings)
 {
     $validation = new \Las\Extension\Validation();
     $validation->add('defaultClass', new Validator\InclusionIn(array('domain' => Services::priority())));
     $validation->add('enableQos', new Validator\InclusionIn(array('domain' => [0, 1])));
     $validation->add('highestRate', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('highestRate', null, $settings)))));
     $validation->add('highestRate', new Validator\Between(array('minimum' => 1, 'maximum' => Services::rate('highestRate'))));
     $validation->add('highestCeil', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('highestCeil', null, $settings)))));
     $validation->add('highRate', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('highRate', null, $settings)))));
     $validation->add('highRate', new Validator\Between(array('minimum' => 1, 'maximum' => Services::rate('highRate'))));
     $validation->add('highCeil', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('highCeil', null, $settings)))));
     $validation->add('mediumRate', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('mediumRate', null, $settings)))));
     $validation->add('mediumRate', new Validator\Between(array('minimum' => 1, 'maximum' => Services::rate('mediumRate'))));
     $validation->add('mediumCeil', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('mediumCeil', null, $settings)))));
     $validation->add('lowRate', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('lowRate', null, $settings)))));
     $validation->add('lowRate', new Validator\Between(array('minimum' => 1, 'maximum' => Services::rate('lowRate'))));
     $validation->add('lowCeil', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('lowCeil', null, $settings)))));
     $validation->add('lowestRate', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('lowestRate', null, $settings)))));
     $validation->add('lowestRate', new Validator\Between(array('minimum' => 1, 'maximum' => Services::rate('lowestRate'))));
     $validation->add('lowestCeil', new Validator\InclusionIn(array('domain' => array_keys(Settings::options('lowestCeil', null, $settings)))));
     $validation->setLabels(array('defaultClass' => __('Default class'), 'enableQos' => __('Enable qos'), 'highestRate' => __('Highest rate'), 'highestCeil' => __('Highest ceil'), 'highRate' => __('High rate'), 'highCeil' => __('High ceil'), 'mediumRate' => __('Medium rate'), 'mediumCeil' => __('Medium ceil'), 'lowRate' => __('Low rate'), 'lowCeil' => __('Low ceil'), 'lowestRate' => __('Lowest rate'), 'lowestCeil' => __('Lowest ceil')));
     return Settings::updateSettings($settings, $validation);
 }
Ejemplo n.º 8
0
 /**
  * Edit action - edit the tariff
  *
  * @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]) && ($tariff = Tariffs::findFirst($params[0]))) {
         $networks = Networks::find(['type=:type:', 'bind' => ['type' => Networks::WAN]]);
         if (!count($networks)) {
             $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the network first") . ': ' . $this->tag->linkTo('admin/networks/add', __('Add')));
         }
         // Set title, pick view and send variables
         $this->tag->setTitle(__('Tariffs') . ' / ' . __('Edit'));
         $this->view->pick('tariffs/write');
         $this->view->setVars(['status' => Tariffs::status(true), 'bitRate' => \Las\Models\Settings::options('bitRate', $this->las['general']['bitRate'])]);
         // Check if the form has been sent
         if ($this->request->isPost() === true && $this->request->hasPost('submit')) {
             $valid = $tariff->write('update');
             // Check if data are valid
             if ($valid instanceof Tariffs) {
                 $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 {
             // Values to fill out the form
             $this->tag->setDefaults(get_object_vars($tariff));
         }
     } else {
         parent::notFoundAction();
     }
 }