/** * unlock package * @param string $pkg_name package name to unlock * @return array status * @throws \Exception */ public function unlockAction($pkg_name) { $backend = new Backend(); $response = array(); if ($this->request->isPost()) { $response['status'] = 'ok'; // sanitize package name $filter = new \Phalcon\Filter(); $filter->add('pkgname', function ($value) { return preg_replace('/[^0-9a-zA-Z-_]/', '', $value); }); $pkg_name = $filter->sanitize($pkg_name, "pkgname"); // execute action $response['msg_uuid'] = trim($backend->configdpRun("firmware unlock", array($pkg_name), true)); } else { $response['status'] = 'failure'; } return $response; }
private function definirVariablesCommunes() { $this->view->setVar("version", $this->config->application->version); $this->view->setVar("apps", "js/app"); $this->view->setVar("widgets", "js/widgets"); $configClient = $this->config->navigateur; $configClient->uri = $this->config->uri; $this->view->setVar("configClient", $configClient); global $application; $libelleProfil = ''; $user = ''; $count = 0; $application->getDI()->getSession()->set('page', '../' . $application->getDi()['router']->getRewriteUri()); if ($application->getDI()->getSession()->has("info_utilisateur")) { if ($application->getDI()->getSession()->get("info_utilisateur")->identifiant) { $user = $application->getDI()->getSession()->get("info_utilisateur")->identifiant; $idProfil = $application->getDI()->getSession()->get("info_utilisateur")->profilActif; if (isset($application->getDI()->getSession()->get("info_utilisateur")->profils)) { $count = count($application->getDI()->getSession()->get("info_utilisateur")->profils); foreach ($application->getDI()->getSession()->get("info_utilisateur")->profils as $value) { if ($value['id'] == $idProfil) { $libelleProfil = $value['libelle']; break; } } } if ($libelleProfil === '') { $count = 0; } } } $this->view->setVar("profil", $libelleProfil); $this->view->setVar("utilisateur", $user); $this->view->setVar("nbProfil", $count); if ($this->request->get('url') || $this->request->get('URL')) { $filter = new \Phalcon\Filter(); $filter->add('url', function ($value) { filter_var($value, FILTER_SANITIZE_URL); }); $url = $this->request->get('url') ? $this->request->get('url') : $this->request->get('URL'); $layers = $this->request->get('layers') ? $this->request->get('layers', 'string') : $this->request->get('LAYERS', 'string'); if ($layers == null && strrpos($url, 'layers') !== false) { $layers = substr($url, strrpos($url, 'layers') + 7); $url = substr($url, 0, strrpos($url, 'layers')); } if ($layers == null && strrpos($url, 'LAYERS') !== false) { $layers = substr($url, strrpos($url, 'LAYERS') + 7); $url = substr($url, 0, strrpos($url, 'LAYERS')); } $filter->sanitize($url, 'url'); $active = $layers == null ? 'false' : 'true'; $fonctionCallback = "function(e){\n var coucheWMS = new Igo.Couches.WMS(\n {\n url:'{$url}', \n nom:'{$layers}',\n fond:false,\n active:{$active},\n mode: 'getCapabilities'\n }\n );\n Igo.nav.carte.gestionCouches.ajouterCouche(coucheWMS);\n };"; $this->view->setVar("callbackInitIGO", $fonctionCallback); } else { $this->view->setVar("callbackInitIGO", 'null'); } }
<?php require_once __DIR__ . '/../app/bootstrap.php'; $di->set('filter', function () { $filter = new Phalcon\Filter(); $filter->add('string', function ($value) { return '' . $value; /* is_string($value) ? $value : ''; */ }); $filter->add('uint', function ($value) { return is_scalar($value) && preg_match('/^[0-9]+$/iD', $value) && $value >= 0 ? $value : 0; }); $filter->add('array', function ($value) { return is_array($value) ? $value : []; }); $filter->add('intbool', function ($value) { return empty($value) ? 0 : 1; }); return $filter; }, true); $di->set('request', new Phalcon\Http\Request()); $di->set('router', function () use($di) { $router = new \Phalcon\Mvc\Router(); return $router; }, true); $di->set('flash', function () { return new Phalcon\Flash\Session(['error' => 'alert alert-danger', 'success' => 'alert alert-success', 'notice' => 'alert alert-info', 'warning' => 'alert alert-warning']); }); $di->set('session', function () use($di) { $class = Config::instance()->session->class; session_name(Config::instance()->session->name);
/** * Set the filter service * * @return void */ protected function filter() { $this->_di->set('filter', function () { $filter = new \Phalcon\Filter(); $filter->add('repeat', new Extension\Repeat()); $filter->add('escape', new Extension\Escape()); return $filter; }); }
<?php $filter = new \Phalcon\Filter(); //Using an anonymous function $filter->add('md5', function ($value) { return preg_replace('/[^0-9a-f]/', '', $value); }); //Sanitize with the "md5" filter $filtered = $filter->sanitize($possibleMd5, "md5");
}); $di->setShared('response', function () { $response = new \Phalcon\Http\Response(); return $response; }); //注入DB服务 $di->setShared('gcoperator', function () use($di) { $dbclass = '\\Phalcon\\Db\\Adapter\\Pdo\\' . $di['config']->v3opDB->driver; return new $dbclass(array('host' => $di['config']->v3opDB->host, 'username' => $di['config']->v3opDB->username, 'password' => $di['config']->v3opDB->password, 'dbname' => $di['config']->v3opDB->database, 'charset' => $di['config']->v3opDB->charset)); }); //注入sphinx 服务 $di->setShared('sphinxCon', function () use($di) { $conn = new \Foolz\SphinxQL\Connection(); $conn->setParams(array('host' => $di['config']->sphinx->host, 'port' => intval($di['config']->sphinx->port))); return $conn; }); $di->setShared('filter', function () { $filter = new \Phalcon\Filter(); $filter->add('price', function ($value) { return round(abs($value), 2); }); return $filter; }); $di->set('memObj', function () use($di) { $mcObj = new \Xz\Lib\Memcached($di['config']->memcommon); return $mcObj; }); $di->set('request', function () { $request = new \Phalcon\Http\Request(); return $request; });
<?php class IPv4Filter { public function filter($value) { return filter_var($value, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4); } } $filter = new \Phalcon\Filter(); //Using an object $filter->add('ipv4', new IPv4Filter()); //Sanitize with the "ipv4" filter $filteredIp = $filter->sanitize("127.0.0.1", "ipv4");
<?php $di->setShared('filter', function () { $filter = new \Phalcon\Filter(); // Remove quotation marks (single and double): $filter->add('removeq', function ($value) { if (preg_match("/[^']'\$/", $value) and !preg_match("/^'[^']/", $value)) { return $value; } return preg_replace("/^[\"']+|[\"']+\$/u", '', $value); }); // Saxon genitive replacement: $filter->add('saxgen', function ($value) { return preg_replace("/'+/u", '’', $value); }); // Empty value null replacement: $filter->add('null', function ($value) { return strlen($value) === 0 ? null : $value; }); // Title case modifier: $filter->add('title', function ($value) { return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8'); }); // Lower case modifier: $filter->add('lower', function ($value) { return mb_convert_case($value, MB_CASE_LOWER, 'UTF-8'); }); // Upper case modifier: $filter->add('upper', function ($value) { return mb_convert_case($value, MB_CASE_UPPER, 'UTF-8'); });