/** * Get available ceil for download/upload * * @package las * @version 1.0 * * @param mixed $type type of ceil * @return int */ public static function ceil($type) { $wans = Networks::find(['type=:type: AND status=:status:', 'bind' => ['type' => Networks::WAN, 'status' => Networks::ACTIVE]]); $ceil = 0; foreach ($wans as $wan) { $ceil += $wan->{$type}; } return $ceil; }
/** * Index action - display all networks * * @package las * @version 1.0 */ public function indexAction() { $this->tag->setTitle(__('Networks')); // Available sort to choose $this->filter->add('in_array', function ($value) { return in_array($value, ['interface', 'interface DESC', 'name', 'name DESC', 'subnetwork', 'subnetwork DESC', 'status', 'status DESC', 'type', 'type DESC']) ? $value : null; }); // Get networks and prepare pagination $paginator = new Paginator(["data" => Networks::find(['order' => $this->request->getQuery('order', 'in_array', 'id', true)]), "limit" => $this->request->getQuery('limit', 'int', 20, true), "page" => $this->request->getQuery('page', 'int', 1, true)]); $this->view->setVars(['pagination' => $paginator->getPaginate(), 'bitRate' => Settings::options('bitRate', $this->las['general']['bitRate'])]); }
/** * 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)); }
/** * Edit action - edit the device * * @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]) && ($device = Devices::findFirst($params[0]))) { $clients = Clients::find(['status!=:status:', 'bind' => ['status' => Clients::UNACTIVE]]); $networks = Networks::find(['status=:status:', 'bind' => ['status' => Networks::ACTIVE]]); if (!count($clients)) { $this->flashSession->notice($this->tag->linkTo(['#', 'class' => 'close', 'title' => __("Close"), '×']) . '<strong>' . __('Notice') . '!</strong> ' . __("Please add the client first") . ': ' . $this->tag->linkTo('admin/clients/add', __('Add'))); } 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(__('Devices') . ' / ' . __('Edit')); $this->view->pick('devices/write'); $this->view->setVars(['clients' => $clients, 'networks' => $networks, 'type' => Devices::type(true), 'status' => Devices::status(true)]); // Check if the form has been sent if ($this->request->isPost() === true && $this->request->hasPost('submit')) { $device->__set('clients', $clients); $device->__set('networks', $networks); $valid = $device->write('update'); // Check if data are valid if ($valid instanceof Devices) { $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(['name' => $device->name, 'network' => $device->network_id, 'client' => $device->client_id, 'type' => $device->type, 'IP' => long2ip($device->IP), 'MAC' => $device->MAC, 'description' => $device->description, 'status' => $device->status]); } } else { parent::notFoundAction(); } }
/** * 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(); } }