$dav_resource = new DAVResource($request->path); if (!$dav_resource->HavePrivilegeTo('DAV::write-content')) { $request->DoResponse(403); } if (!$dav_resource->Exists() && !$dav_resource->HavePrivilegeTo('DAV::bind')) { $request->DoResponse(403); } if (!ini_get('open_basedir') && (isset($c->dbg['ALL']) || isset($c->dbg['put']) && $c->dbg['put'])) { $fh = fopen('/tmp/PUT.txt', 'w'); if ($fh) { fwrite($fh, $request->raw_post); fclose($fh); } } include_once 'caldav-PUT-functions.php'; controlRequestContainer($dav_resource->GetProperty('username'), $dav_resource->GetProperty('user_no'), $dav_resource->bound_from(), true); $lock_opener = $request->FailIfLocked(); if ($dav_resource->IsCollection()) { if ($dav_resource->IsPrincipal() || $dav_resource->IsBinding() || !isset($c->readonly_webdav_collections) || $c->readonly_webdav_collections == true) { $request->DoResponse(405); // Method not allowed return; } $appending = isset($_GET['mode']) && $_GET['mode'] == 'append'; /** * CalDAV does not define the result of a PUT on a collection. We treat that * as an import. The code is in caldav-PUT-functions.php */ import_collection($request->raw_post, $request->user_no, $request->path, true, $appending); $request->DoResponse(200); return;
static function importFromDirectory() { global $c; if (empty($_POST["calendar_path"])) { dbg_error_log("importFromDirectory", "calendar path not given"); return; } $path_ics = $_POST["calendar_path"]; if (substr($path_ics, -1, 1) != '/') { $path_ics .= '/'; } // ensure that we target a collection if (substr($path_ics, 0, 1) != '/') { $path_ics = '/' . $path_ics; } // ensure that we target a collection if (empty($_POST["directory_path"])) { dbg_error_log("importFromDirectory", "directory path not given"); return; } $dir = $_POST["directory_path"]; if (!is_readable($dir)) { $c->messages[] = sprintf(i18n('directory %s is not readable'), htmlspecialchars($dir)); dbg_error_log("importFromDirectory", "directory is not readable"); return; } if ($handle = opendir($dir)) { $c->readonly_webdav_collections = false; // Override this setting so we can create collections/events on import. while (false !== ($file = readdir($handle))) { if ($file == "." || $file == ".." || substr($file, -4) != '.ics') { continue; } if (!is_readable($dir . '/' . $file)) { dbg_error_log("importFromDirectory", "ics file '%s' is not readable", $dir . '/' . $file); continue; } $ics = file_get_contents($dir . '/' . $file); $ics = trim($ics); if ($ics != '') { if (!check_string($ics)) { $c->messages[] = sprintf(translate('The file "%s" is not UTF-8 encoded, please check error for more details'), $dir . '/' . $file); continue; } $username = substr($file, 0, -4); $principal = new Principal('username', $username); if (!$principal->Exists()) { $c->messages[] = sprintf(translate('The principal "%s" does not exist'), $username); continue; } $path = "/" . $username . $path_ics; $user_no = $principal->user_no(); if (controlRequestContainer($username, $user_no, $path, false) === -1) { continue; } dbg_error_log("importFromDirectory", "importing to {$path}"); import_collection($ics, $user_no, $path, 1); $c->messages[] = sprintf(translate('All events of user "%s" were deleted and replaced by those from file %s'), substr($file, 0, -4), $dir . '/' . $file); } } closedir($handle); } }
} $this->username = $principal->username(); $this->principal_id = $principal->principal_id(); $this->email = $principal->email(); $this->dav_name = $principal->dav_name(); $this->principal = $principal; $this->logged_in = true; } function AllowedTo($do_something) { return $this->logged_in; } } $session = new FakeSession(); $dest = new DAVResource($target); $session = new FakeSession($dest->user_no()); if ($mode == 'append' && !$dest->Exists()) { printf("The target '%s' does not exist.\n", $target); exit(1); } if (!$dest->IsCollection()) { printf("The target '%s' is not a collection.\n", $target); exit(1); } $user_no = $dest->user_no(); $username = $session->username; param_to_global('mode'); include_once 'caldav-PUT-functions.php'; controlRequestContainer($session->username, $dest->user_no(), $target, false, $dest->IsPublic() ? true : false); import_collection($ics, $dest->user_no(), $target, $session->user_no, $mode == 'append'); printf(translate("Calendar '%s' was loaded from file.\n"), $target);
* If the user has uploaded a .ics file as a calendar, we fake this out * as if it were a "PUT" request against a collection. This is something * of a hack. It works though :-) */ $ics = trim(file_get_contents($_FILES['ics_file']['tmp_name'])); dbg_error_log('collection-edit', ':Write: Loaded %d bytes from %s', strlen($ics), $_FILES['ics_file']['tmp_name']); include_once 'check_UTF8.php'; if (!check_string($ics)) { $ics = force_utf8($ics); } if (check_string($ics)) { $path = $editor->Value('dav_name'); $user_no = $editor->Value('user_no'); $username = $editor->Value('username'); include_once 'caldav-PUT-functions.php'; controlRequestContainer($username, $user_no, $path, false, $publicly_readable == 'on' ? true : false); import_collection($ics, $user_no, $path, $session->user_no); $c->messages[] = sprintf(translate('Calendar "%s" was loaded from file.'), $path); } else { $c->messages[] = i18n('The file is not UTF-8 encoded, please check the error for more details.'); } } } } else { if ($id > 0) { $editor->GetRecord(); } if ($editor->IsSubmit()) { $c->messages[] = i18n('You do not have permission to modify this record.'); } }