/** * 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]); }
/** * 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)); }
/** * 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()]); } }
/** * 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); } }