Beispiel #1
0
 public function download($path)
 {
     if (is_null($path) || empty($path)) {
         throw new InvalidArgumentException('You must specify the item to download.', 400);
     } else {
         if (!$this->exists($path) || !is_file($this->realRootDirectory . DIRECTORY_SEPARATOR . $path)) {
             throw new FileNotFoundException('The specified file does not exist.', 404);
         }
     }
     $fileObject = new \SplFileObject($this->realRootDirectory . DIRECTORY_SEPARATOR . $path);
     HttpResponse::setContentDisposition($fileObject->getBasename());
     HttpResponse::setContentType('application/octet-stream');
     HttpResponse::setHeader('Content-Length', $fileObject->getSize());
     $fileObject->fpassthru();
     exit(0);
 }
 public function db($params = null)
 {
     $db = $this->app->getDatabase();
     if (!empty($params) && $params === 'backup') {
         HttpResponse::setContentType('application/octet-stream');
         HttpResponse::setContentDisposition('db-' . DOMAIN . '-' . date('Ymd-Hi') . '.sql.gz');
         passthru($db->getBackupCommand() . ' | gzip --best', $error);
         if (!empty($error)) {
             $this->logger->error("Error backing up database: {$error}");
         }
         exit(0);
     }
     $this->loadView('db');
     if (!isset($_SESSION['QueryHistory'])) {
         $_SESSION['QueryHistory'] = array();
     }
     $result = $db->fetchAll('SHOW TABLES;', null, PDO::FETCH_NUM);
     if ($result !== false) {
         $tables = array();
         foreach (array_values($result) as $tableArray) {
             foreach ($tableArray as $table) {
                 $tables[] = $table;
             }
         }
         $this->view->setData('Tables', $tables);
     }
     if (!empty($params) && isset($params['query'])) {
         $query = trim($params['query']);
         // If it exists, remove the current query from the history before appending it. -- cwells
         $historyIndex = array_search($query, $_SESSION['QueryHistory']);
         if ($historyIndex !== false) {
             array_splice($_SESSION['QueryHistory'], $historyIndex, 1);
         }
         $_SESSION['QueryHistory'][] = $query;
         if (stripos($query, 'SELECT') === 0 || stripos($query, 'SHOW') === 0 || stripos($query, 'DESCRIBE') === 0) {
             $result = $db->fetchAll($query);
         } else {
             $result = $db->execute($query);
         }
         $errorInfo = $db->getErrorInfo();
         if (!is_null($errorInfo) && count($errorInfo) > 2) {
             //				$this->view->setStatus($errorInfo[2], 500);
             $this->view->setData('DBError', $errorInfo[2]);
         }
         $this->view->setData(array('Query' => $query, 'Result' => $result, 'RowCount' => $db->getRowCount()));
     }
     $this->view->setData('History', $_SESSION['QueryHistory']);
 }
Beispiel #3
0
echo '<?xml version="1.0" encoding="utf-8"?>';
?>
<feed xmlns="http://www.w3.org/2005/Atom"
	  xml:lang="en"
	  xml:base="<?php 
echo PROTOCOL_HOST_PORT . \CWA\APP_ROOT;
?>
">

	<id><?php 
echo 'tag:' . DOMAIN . ',2015:' . $ControllerURL . ':feed/atom';
?>
</id>
	<link rel="self" type="<?php 
echo \CWA\Net\HTTP\HttpResponse::getContentType();
?>
" href="<?php 
echo $ControllerURL;
?>
?format=atom" />
	<link rel="alternate" type="text/html" href="<?php 
echo $ControllerURL;
?>
" />
	<updated><?php 
echo $LastUpdated->format(DateTime::ATOM);
?>
</updated>
	<title><?php 
echo SITE_NAME;
Beispiel #4
0
 protected function setHeaders()
 {
     if (function_exists('http_response_code')) {
         // This method is defined in PHP 5.4. -- cwells
         http_response_code($this->statusCode);
     } else {
         header("X-PHP-Response-Code: {$this->statusCode}", true, $this->statusCode);
     }
     if ($this->format === 'json') {
         HttpResponse::setContentType('application/json');
     } else {
         if ($this->format === 'atom') {
             HttpResponse::setContentType('application/atom+xml');
         } else {
             // Also set charset for text subtypes. -- cwells
             HttpResponse::setContentType('text/html; charset=utf-8');
         }
     }
     if (!is_null($this->canonicalURL)) {
         HttpResponse::setHeader('Link', "<{$this->canonicalURL}>; rel=\"canonical\"");
     }
     // Security related headers. -- cwells
     HttpResponse::setHeader('Content-Security-Policy', \CWA\MVC\VIEWS\HEADERS\CONTENT_SECURITY_POLICY);
     HttpResponse::setHeader('X-Content-Type-Options', \CWA\MVC\VIEWS\HEADERS\X_CONTENT_TYPE_OPTIONS);
     HttpResponse::setHeader('X-Frame-Options', \CWA\MVC\VIEWS\HEADERS\X_FRAME_OPTIONS);
     HttpResponse::setHeader('X-XSS-Protection', \CWA\MVC\VIEWS\HEADERS\X_XSS_PROTECTION);
 }
Beispiel #5
0
 public function redirectToLogin()
 {
     // Cannot send a 401 here because it's a redirect (302). -- cwells
     HttpResponse::redirect($this->loginURL, array('returnURL' => $_SERVER['REQUEST_URI']));
 }