Overview

Packages

  • awl
    • caldav-client-v2
    • RRule
  • davical
    • authentication
      • drivers
    • caldav
    • DAViCalSession
    • DAVTicket
    • external-bind
    • feed
    • HTTPAuthSession
    • iSchedule
    • iSchedule-POST
    • logging
    • metrics
    • Principal
    • propfind
    • PublicSession
    • Request
    • Resource
    • tzservice
  • None
  • PHP

Functions

  • add_failure
  • check_for_expansion
  • component_to_xml
  • controlRequestContainer
  • delete_collection
  • deliverItipCancel
  • display_status
  • do_scheduling_for_delete
  • do_scheduling_reply
  • do_scheduling_requests
  • doImipMessage
  • doItipAttendeeReply
  • doItipOrganizerCancel
  • export_iCalendar
  • GetItip
  • GetTZID
  • handle_cancel_request
  • handle_freebusy_request
  • handle_schedule_reply
  • handle_schedule_request
  • import_addressbook_collection
  • import_calendar_collection
  • import_collection
  • late_catch_fatal_error
  • logRequestHeaders
  • obfuscated_event
  • process_ace
  • processItipCancel
  • property_response
  • public_events_only
  • rollback
  • rollback_on_error
  • send_dav_header
  • simple_write_resource
  • write_alarms
  • write_attendees
  • write_resource
  • Overview
  • Package
  • Function
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: /**
  3: * CalDAV Server - main program
  4: *
  5: * @package   davical
  6: * @subpackage   caldav
  7: * @author    Andrew McMillan <andrew@mcmillan.net.nz>
  8: * @copyright Catalyst .Net Ltd, Morphoss Ltd <http://www.morphoss.com/>
  9: * @license   http://gnu.org/copyleft/gpl.html GNU GPL v2 or later
 10: */
 11: 
 12: require_once('./always.php');
 13: 
 14: if ( isset($_SERVER['PATH_INFO']) && preg_match( '{^/\.well-known/(.+)$}', $_SERVER['PATH_INFO'], $matches ) ) {
 15:   require ('well-known.php');
 16:   @ob_flush(); exit(0);
 17: }
 18: elseif ( isset($_SERVER['PATH_INFO']) && $_SERVER['PATH_INFO'] == '/autodiscover/autodiscover.xml' ) {
 19:   require ('autodiscover-handler.php');
 20:   @ob_flush(); exit(0);
 21: }
 22: 
 23: function logRequestHeaders() {
 24:   global $c;
 25: 
 26:   /** Log the request headers */
 27:   $lines = apache_request_headers();
 28:   dbg_error_log( "LOG ", "***************** Request Header ****************" );
 29:   dbg_error_log( "LOG ", "%s %s", $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI'] );
 30:   foreach( $lines AS $k => $v ) {
 31:     if ( $k != 'Authorization' || (isset($c->dbg['password']) && $c->dbg['password'] ) )
 32:       dbg_error_log( "LOG headers", "-->%s: %s", $k, $v );
 33:     else
 34:       dbg_error_log( "LOG headers", "-->%s: %s", $k, 'Delicious tasty password eaten by debugging monster!' );
 35:   }
 36:   dbg_error_log( "LOG ", "******************** Request ********************" );
 37: 
 38:   // Log the request in all it's gory detail.
 39:   $lines = preg_split( '#[\r\n]+#', $c->raw_post );
 40:   foreach( $lines AS $v ) {
 41:     dbg_error_log( "LOG request", "-->%s", $v );
 42:   }
 43:   unset($lines);
 44: }
 45: 
 46: if ( !isset($c->raw_post) ) $c->raw_post = file_get_contents( 'php://input');
 47: if ( (isset($c->dbg['ALL']) && $c->dbg['ALL']) || (isset($c->dbg['request']) && $c->dbg['request']) )
 48:   logRequestHeaders();
 49: 
 50: 
 51: require_once('HTTPAuthSession.php');
 52: $session = new HTTPAuthSession();
 53: 
 54: function send_dav_header() {
 55:   global $c;
 56: 
 57:   /**
 58:   * access-control is rfc3744, we do most of it, but no way to say that.
 59:   * calendar-schedule is another one we do most of, but the spec is not final yet either.
 60:   */
 61:   if ( isset($c->override_dav_header) ) {
 62:     $dav = $c->override_dav_header;
 63:   }
 64:   else {
 65:     $dav = '1, 2, 3, access-control, calendar-access, calendar-schedule, extended-mkcol, bind, addressbook';
 66:     if ( $c->enable_auto_schedule ) $dav .= ', calendar-auto-schedule';
 67:     if ( !isset($c->disable_caldav_proxy) || $c->disable_caldav_proxy == false) $dav .= ', calendar-proxy';
 68:   }
 69:   $dav = explode( "\n", wordwrap( $dav ) );
 70:   foreach( $dav AS $v ) {
 71:     header( 'DAV: '.trim($v, ', '), false);
 72:   }
 73: }
 74: 
 75: require_once('CalDAVRequest.php');
 76: $request = new CalDAVRequest();
 77: 
 78: function late_catch_fatal_error() {
 79:   global $request;
 80: 
 81:   // Getting Last Error
 82:   $e =  error_get_last();
 83:   if (isset($e['type']) && $e['type'] == E_ERROR) {
 84:     $request->DoResponse(500, "Fatal PHP Error");
 85:   }
 86: }
 87: register_shutdown_function('late_catch_fatal_error');
 88: 
 89: //if ( $request->method == 'OPTIONS' || $c->always_send_dav_header )
 90:     send_dav_header();  // Avoid polluting global namespace
 91: 
 92: $allowed = implode( ', ', array_keys($request->supported_methods) );
 93: // header( 'Allow: '.$allowed);
 94: 
 95: if ( ! ($request->IsPrincipal() || isset($request->collection) || $request->method == 'PUT' || $request->method == 'MKCALENDAR' || $request->method == 'MKCOL' ) ) {
 96:   if ( preg_match( '#^/principals/users(/.*/)$#', $request->path, $matches ) ) {
 97:     // Although this doesn't work with the iPhone, perhaps it will with iCal...
 98:     /** @todo integrate handling this URL into CalDAVRequest.php */
 99:     $redirect_url = ConstructURL('/caldav.php'.$matches[1]);
100:     dbg_error_log( 'LOG WARNING', 'Redirecting %s for "%s" to "%s"', $request->method, $request->path, $redirect_url );
101:     header('Location: '.$redirect_url );
102:     @ob_flush(); exit(0);
103:   }
104: }
105: param_to_global('add_member', '.*', 'add-member');
106: $add_member = isset($add_member);
107: 
108: try {
109: 
110:   switch ( $request->method ) {
111:     case 'OPTIONS':    include_once('caldav-OPTIONS.php');   break;
112:     case 'REPORT':     include_once('caldav-REPORT.php');    break;
113:     case 'PROPFIND':   include('caldav-PROPFIND.php');       break;
114:     case 'GET':        include('caldav-GET.php');            break;
115:     case 'HEAD':       include('caldav-GET.php');            break;
116:     case 'PROPPATCH':  include('caldav-PROPPATCH.php');      break;
117:     case 'POST':
118:       if ( $request->content_type != 'text/vcard' && !$add_member ) {
119:         include('caldav-POST.php');
120:         break;
121:       }
122:       // fall through if POST add member
123:     case 'PUT':
124:       switch( $request->content_type ) {
125:         case 'text/calendar':
126:           include('caldav-PUT-vcalendar.php');
127:           break;
128:         case 'text/vcard':
129:         case 'text/x-vcard':
130:           include('caldav-PUT-vcard.php');
131:           break;
132:         default:
133:           include('caldav-PUT-default.php');
134:           break;
135:       }
136:       break;
137:     case 'MKCALENDAR': include('caldav-MKCOL.php');          break;
138:     case 'MKCOL':      include('caldav-MKCOL.php');          break;
139:     case 'DELETE':     include('caldav-DELETE.php');         break;
140:     case 'MOVE':       include('caldav-MOVE.php');           break;
141:     case 'ACL':        include('caldav-ACL.php');            break;
142:     case 'LOCK':       include('caldav-LOCK.php');           break;
143:     case 'UNLOCK':     include('caldav-LOCK.php');           break;
144:     case 'MKTICKET':   include('caldav-MKTICKET.php');       break;
145:     case 'DELTICKET':  include('caldav-DELTICKET.php');      break;
146:     case 'BIND':       include('caldav-BIND.php');           break;
147: 
148:     case 'TESTRRULE':  include('test-RRULE-v2.php');         break;
149: 
150:     default:
151:       dbg_error_log( 'caldav', 'Unhandled request method >>%s<<', $request->method );
152:       dbg_log_array( 'caldav', '_SERVER', $_SERVER, true );
153:       dbg_error_log( 'caldav', 'RAW: %s', str_replace("\n", '',str_replace("\r", '', $request->raw_post)) );
154:   }
155: 
156: } catch (Exception $e) {
157:   trace_bug('DAViCal Fatal Error');
158:   $request->DoResponse( 500, translate('DAViCal Fatal Error') );
159: }
160: 
161: $request->DoResponse( 400, translate('The application program does not understand that request.') );
162: 
DAViCal API documentation generated by ApiGen 2.8.0