/** * Povolí zápis cookies do IFRAMe a pokud má aplikace appNamespace, povolí vložení aplikace do IFRAMe */ private function setHeaders() { $this->httpResponse->addHeader('P3P', 'CP="CAO PSA OUR"'); if ($this->config["appNamespace"] !== FALSE) { $this->httpResponse->setHeader('X-Frame-Options', NULL); } }
/** * Authenticate user * @param string $username * @param string $password * @return void */ public function authenticate($username, $password) { $url = $this->httpRequest->url; if ($url->user !== $username || $url->password !== $password) { $this->httpResponse->setHeader('WWW-Authenticate', 'Basic realm="HTTP Authentication"'); $this->httpResponse->setCode(Nette\Http\IResponse::S401_UNAUTHORIZED); echo '<h1>Authentication failed.</h1>'; if ($this->exit_on_bad_credentials) { die; } } }
public function onResponse(NA\Application $application, NA\IResponse $response) { if ($this->config["panel"]["ajax"] && $application->getPresenter() instanceof \Nette\Application\UI\Presenter && $application->getPresenter()->isAjax()) { $debug = ["count" => count($this->_getElapsed())]; if ($debug["count"]) { ob_start(); include __DIR__ . "/panel/templates/results.phtml"; $debug["template"] = ob_get_clean(); } $data = base64_encode(json_encode($debug)); // Workaround for Chrome header limit as https://github.com/Seldaek/monolog/issues/172 if (strlen($data) > 240 * 1024) { $debug["template"] = "Incomplete logs, chrome header size limit reached!"; $data = base64_encode(json_encode($debug)); } $this->response->setHeader(self::HEADER_PREFIX, $data); } }
/** * Upload signal */ public function handleUpload() { // HTTP headers for no cache etc $httpResponse = new Response(); $httpResponse->setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); $httpResponse->setHeader("Last-Modified", gmdate("D, d M Y H:i:s") . " GMT"); $httpResponse->setHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); $httpResponse->setHeader("Pragma", "no-cache"); $response = array("jsonrpc" => "2.0", "result" => "", "id" => "id", "type" => ""); if ($this->system->parameters["readonly"]) { $response["result"] = "Read-only mode enabled, files can not be uploaded!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } $fileSize = $this->system->filesystem->getSize($_FILES["file"]["tmp_name"]); if ($this->getFreeSpace() < $fileSize) { $response["result"] = "Disk space is full!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } $actualDir = $this->system->session->actualdir; $targetDir = $this->getAbsolutePath($actualDir); if (!is_dir($targetDir)) { $response["result"] = "Target directory '{$actualDir}' not found!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } // Settings $maxFileAge = 60 * 60; // Temp file age in seconds // Get parameters $chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0; $chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0; $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : ""; $fileName = $this->system->filesystem->safeFilename($fileName); // Make sure the fileName is unique but only if chunking is disabled if ($chunks < 2 && is_file("{$targetDir}/{$fileName}")) { $ext = strrpos($fileName, "."); $fileName_a = substr($fileName, 0, $ext); $fileName_b = substr($fileName, $ext); $count = 1; while (is_file("{$targetDir}/{$fileName_a}" . "_{$count}" . $fileName_b)) { $count++; } $fileName = $fileName_a . "_{$count}" . $fileName_b; } // Remove old temp files if (is_dir($targetDir) && ($dir = opendir($targetDir))) { while (($file = readdir($dir)) !== false) { // Remove temp files if they are older than the max age $filePath = "{$targetDir}/{$file}"; if (preg_match("/\\.tmp\$/", $file) && filemtime($filePath) < time() - $maxFileAge) { unlink($filePath); } } closedir($dir); } else { $response["result"] = "Failed to open temp directory!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } // Look for the content type header if (isset($_SERVER["HTTP_CONTENT_TYPE"])) { $contentType = $_SERVER["HTTP_CONTENT_TYPE"]; } if (isset($_SERVER["CONTENT_TYPE"])) { $contentType = $_SERVER["CONTENT_TYPE"]; } // Handle non multipart uploads older WebKit versions didn"t support multipart in HTML5 if (strpos($contentType, "multipart") !== false) { if (isset($_FILES["file"]["tmp_name"]) && is_uploaded_file($_FILES["file"]["tmp_name"])) { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if (!$out) { $response["result"] = "Failed to open output stream!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } // Read binary input stream and append it to temp file $in = fopen($_FILES["file"]["tmp_name"], "rb"); if (!$in) { $response["result"] = "Failed to open output stream!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } fclose($out); fclose($in); unlink($_FILES["file"]["tmp_name"]); } else { $response["result"] = "Failed to move uploaded file!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } } else { // Open temp file $out = fopen($targetDir . DIRECTORY_SEPARATOR . $fileName, $chunk == 0 ? "wb" : "ab"); if (!$out) { $response["result"] = "Failed to open output stream!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } // Read binary input stream and append it to temp file $in = fopen("php://input", "rb"); if (!$in) { $response["result"] = "Failed to open input stream!"; $response["type"] = "error"; $this->presenter->sendResponse(new JsonResponse($response)); } while ($buff = fread($in, 4096)) { fwrite($out, $buff); } fclose($out); fclose($in); } if ($this->system->parameters["cache"]) { $this->system->caching->deleteItem(array("content", $targetDir)); } $response["result"] = "Successfuly uploaded."; $response["type"] = "info"; $this->presenter->sendResponse(new JsonResponse($response)); }