/** * Create config instance from config data. * @param array $data Data from config file * @return $this */ public function createFromData($data = []) { if (!is_array($data)) { $data = []; } $context = Context::createFromData('root', $data, null, Context::TYPE_DEFAULT, $this->pixie); $this->rootContext = $context; $this->currentContext = $this->rootContext; return $this; }
/** * @inheritdoc */ public function run($action) { $action = 'action_' . $action; $forceHyphens = $this->request->param('force_hyphens'); if (!method_exists($this, $action)) { // Try to change hyphens to underscores in action name $underscoredAction = str_replace('-', '_', $action); if (!$forceHyphens || !method_exists($this, $underscoredAction)) { throw new NotFoundException("Method {$action} doesn't exist in " . get_class($this)); } else { $action = $underscoredAction; } } $this->execute = true; $this->before(); $service = null; $isControllerLevel = true; if ($this->execute) { // Check referrer vulnerabilities $service = $this->pixie->getVulnService(); $config = $service->getConfig(); $isControllerLevel = $config->getLevel() <= 1; $actionName = $this->request->param('action'); if ($isControllerLevel) { if (!$config->has($actionName)) { $context = $config->getCurrentContext(); $context->addContext(Context::createFromData($actionName, [], $context)); } $service->goDown($actionName); // Check referrer for action level $this->vulninjection->checkReferrer(); } } if ($this->execute) { $this->{$action}(); } if ($this->execute) { $this->after(); } if ($this->execute && $isControllerLevel) { $service->goUp(); } }
/** * Add controller context as a child of root. * @param $name * @return $this */ public function addControllerContext($name) { $this->controllerSettings = $this->pixie->config->get("vulninjection/{$name}"); if (!is_array($this->controllerSettings)) { $this->controllerSettings = array(); } $controllerContext = Context::createFromData($name, $this->controllerSettings, $this->config->getRootContext(), Context::TYPE_DEFAULT, $this->pixie); $this->config->addControllerContext($controllerContext); return $this; }
/** * Add possibility to return data from actions as a response. * * @inheritdoc * @throws \App\Exception\NotFoundException */ public function run($action, array $params = []) { $action = 'action_' . $action; if (!method_exists($this, $action)) { throw new NotFoundException("Method {$action} doesn't exist in " . get_class($this), 404, null, 'Not Found'); } $this->execute = true; $this->before(); if (!$this instanceof ErrorController) { // Check referrer vulnerabilities $service = $this->pixie->getVulnService(); $config = $service->getConfig(); $isControllerLevel = $config->getLevel() <= 1; $actionName = $this->request->param('action'); if ($isControllerLevel) { if (!$config->has($actionName)) { $context = $config->getCurrentContext(); $context->addContext(Context::createFromData($actionName, [], $context)); } $service->goDown($actionName); } } if ($this->execute) { $result = call_user_func_array([$this, $action], $params); if (empty($this->response->body) && !is_numeric($this->response->body) && $result !== null) { $this->response->body = $result; } } if ($this->execute) { $this->after(); } }