1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 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 () {
24: global $c;
25:
26:
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:
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 () {
55: global $c;
56:
57: 58: 59: 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:
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:
90: send_dav_header();
91:
92: $allowed = implode( ', ', array_keys($request->supported_methods) );
93:
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:
98:
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:
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: