Пример #1
0
function early_exception_handler($e)
{
    if (!headers_sent()) {
        header("Content-type: text/plain");
        header(sprintf("HTTP/1.1 %d %s", 500, getStatusMessage(500)));
    } else {
        echo "<pre>\n";
        // Too late to set resultcode :-(
    }
    try {
        @ob_flush();
        // Seems like it should be better to do the following but is problematic on PHP5.3 at least: while ( ob_get_level() > 0 ) ob_end_flush();
    } catch (Exception $ignored) {
    }
    echo "Exception [" . $e->getCode() . "] " . $e->getmessage() . "\n";
    echo "At line ", $e->getLine(), " of ", $e->getFile(), "\n";
    echo "================= Stack Trace ===================\n";
    $trace = array_reverse($e->getTrace());
    foreach ($trace as $k => $v) {
        printf("%s[%d] %s%s%s()\n", $v['file'], $v['line'], isset($v['class']) ? $v['class'] : '', isset($v['type']) ? $v['type'] : '', isset($v['function']) ? $v['function'] : '');
    }
}
Пример #2
0
            $url = secureUrl("GET", $url);

        // Open the Curl session
        $session = curl_init($url);

        // fix this security leak
        curl_setopt($session, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
        curl_setopt($session, CURLOPT_HTTPHEADER, getRelevantRequestHeaders());
        curl_setopt($session, CURLOPT_HEADER, false);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($session, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($session, CURLOPT_SSL_VERIFYHOST, 2);

        $response = curl_exec($session);
        header("Content-Type: application/xml");
        header(getStatusMessage("".curl_getinfo($session, CURLINFO_HTTP_CODE)));

        echo $response;
        curl_close($session);
        break;
      case 'HEAD':
        rest_head($request);
        break;
      case 'DELETE':
        rest_delete($request);
        break;
      case 'OPTIONS':
        rest_options($request);
        break;
      default:
        rest_error($request);
Пример #3
0
 /**
  * Utility function we call when we have a simple status-based response to
  * return to the client.  Possibly
  *
  * @param int $status The HTTP status code to send.
  * @param string $message The friendly text message to send with the response.
  */
 function DoResponse($status, $message = "", $content_type = "text/plain; charset=\"utf-8\"")
 {
     global $session, $c;
     if (!headers_sent()) {
         @header(sprintf("HTTP/1.1 %d %s", $status, getStatusMessage($status)));
     }
     if (!headers_sent()) {
         @header(sprintf("X-DAViCal-Version: DAViCal/%d.%d.%d; DB/%d.%d.%d", $c->code_major, $c->code_minor, $c->code_patch, $c->schema_major, $c->schema_minor, $c->schema_patch));
     }
     if (!headers_sent()) {
         header("Content-type: " . $content_type);
     }
     if (isset($c->dbg['ALL']) && $c->dbg['ALL'] || isset($c->dbg['response']) && $c->dbg['response'] || $status == 400 || $status == 402 || $status == 403 || $status > 404) {
         @dbg_error_log("LOG ", 'Response status %03d for %s %s', $status, $this->method, $_SERVER['REQUEST_URI']);
         $lines = headers_list();
         dbg_error_log("LOG ", "***************** Response Header ****************");
         foreach ($lines as $v) {
             dbg_error_log("LOG headers", "-->%s", $v);
         }
         dbg_error_log("LOG ", "******************** Response ********************");
         // Log the request in all it's gory detail.
         $lines = preg_split('#[\\r\\n]+#', $message);
         foreach ($lines as $v) {
             dbg_error_log("LOG response", "-->%s", $v);
         }
     }
     if ($message != '') {
         if (!headers_sent()) {
             header("Content-Length: " . strlen($message));
         }
         echo $message;
     }
     if (isset($c->dbg['caldav']) && $c->dbg['caldav']) {
         if (strlen($message) > 100 || strstr($message, "\n")) {
             $message = substr(preg_replace("#\\s+#m", ' ', $message), 0, 100) . (strlen($message) > 100 ? "..." : "");
         }
         dbg_error_log("caldav", "Status: %d, Message: %s, User: %d, Path: %s", $status, $message, $session->principal->user_no(), $this->path);
     }
     if (isset($c->dbg['statistics']) && $c->dbg['statistics']) {
         $script_time = microtime(true) - $c->script_start_time;
         $memory = '';
         if (function_exists('memory_get_usage')) {
             $memory = sprintf(', Memory: %dk, Peak: %dk', memory_get_usage() / 1024, memory_get_peak_usage(true) / 1024);
         }
         @dbg_error_log("statistics", "Method: %s, Status: %d, Script: %5.3lfs, Queries: %5.3lfs, URL: %s%s", $this->method, $status, $script_time, $c->total_query_time, $this->path, $memory);
     }
     try {
         @ob_flush();
         // Seems like it should be better to do the following but is problematic on PHP5.3 at least: while ( ob_get_level() > 0 ) ob_end_flush();
     } catch (Exception $ignored) {
     }
     if (isset($c->exit_after_memory_exceeds) && function_exists('memory_get_peak_usage') && memory_get_peak_usage(true) > $c->exit_after_memory_exceeds) {
         // 64M
         @dbg_error_log("statistics", "Peak memory use exceeds %d bytes (%d) - killing process %d", $c->exit_after_memory_exceeds, memory_get_peak_usage(true), getmypid());
         register_shutdown_function('CalDAVRequest::kill_on_exit');
     }
     exit(0);
 }
function display_status($status_code)
{
    return sprintf('HTTP/1.1 %03d %s', intval($status_code), getStatusMessage($status_code));
}
Пример #5
0
 /**
  * Utility function we call when we have a simple status-based response to
  * return to the client.  Possibly
  *
  * @param int $status The HTTP status code to send.
  * @param string $message The friendly text message to send with the response.
  */
 function DoResponse($status, $message = "", $content_type = "text/plain; charset=\"utf-8\"")
 {
     global $session, $c;
     @header(sprintf("HTTP/1.1 %d %s", $status, getStatusMessage($status)));
     @header(sprintf("X-DAViCal-Version: DAViCal/%d.%d.%d; DB/%d.%d.%d", $c->code_major, $c->code_minor, $c->code_patch, $c->schema_major, $c->schema_minor, $c->schema_patch));
     @header("Content-type: " . $content_type);
     if (isset($c->dbg['ALL']) && $c->dbg['ALL'] || isset($c->dbg['response']) && $c->dbg['response'] || $status > 399) {
         $lines = headers_list();
         dbg_error_log("LOG ", "***************** Response Header ****************");
         foreach ($lines as $v) {
             dbg_error_log("LOG headers", "-->%s", $v);
         }
         dbg_error_log("LOG ", "******************** Response ********************");
         // Log the request in all it's gory detail.
         $lines = preg_split('#[\\r\\n]+#', $message);
         foreach ($lines as $v) {
             dbg_error_log("LOG response", "-->%s", $v);
         }
     }
     header("Content-Length: " . strlen($message));
     echo $message;
     if (isset($c->dbg['caldav']) && $c->dbg['caldav']) {
         if (strlen($message) > 100 || strstr($message, "\n")) {
             $message = substr(preg_replace("#\\s+#m", ' ', $message), 0, 100) . (strlen($message) > 100 ? "..." : "");
         }
         dbg_error_log("caldav", "Status: %d, Message: %s, User: %d, Path: %s", $status, $message, $session->user_no, $this->path);
     }
     if (isset($c->dbg['statistics']) && $c->dbg['statistics']) {
         $script_time = microtime(true) - $c->script_start_time;
         @dbg_error_log("statistics", "Method: %s, Status: %d, Script: %5.3lfs, Queries: %5.3lfs, URL: %s", $this->method, $status, $script_time, $c->total_query_time, $this->path);
     }
     exit(0);
 }