alextselegidis / easyappointments

:date: Easy!Appointments - Self Hosted Appointment Scheduler
https://easyappointments.org
GNU General Public License v3.0
3.26k stars 1.25k forks source link

Fix CalDAV event syncing problems with server that have obfuscated calendar URLs #1574

Open sandro-byte32 opened 1 month ago

sandro-byte32 commented 1 month ago

Hello Alex,

I am currently trying to get CalDAV syncing to work, but so far, I have not had any success. I am using a CalDAV server integrated with Namecheap Mail.

When I enter my credentials to enable CalDAV syncing, it indicates success. I can successfully synchronize between my phone and Thunderbird on the PC. However, EasyAppointment does not show the appointments made on my phone, and vice versa—I cannot see the appointments made through EasyAppointment on my phone or Thunderbird.

Is Baikal as a CalDAV server a necessity for EasyAppointment to work? The link to my CalDAV server looks something like this (obfuscated):

https://example.com:2080/calendars/__uids__/fafafadnasdnjandono384732897438293/calendar

Edit: I also tried it with a local Baikal server with Nginx Proxy Manager, where WebDAV authentication is Basic. The same behavior occurs—no appointments get created on the server with EasyAppointment. When I create an appointment in Thunderbird, which is also connected to the local Baikal server, it instantly creates an event that can be seen on the Baikal web interface.

In conclusion, there seems to be a problem with EasyAppointment, as it cannot sync with either of the two completely different servers.

Edit2: I managed to get some Error Logs:

ERROR - 2024-07-25 23:59:22 --> Failed to save CalDAV event (Status Code: 405): <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">

405 Method Not Allowed

Method Not Allowed

The requested method PUT is not allowed for this URL.


Apache/2.4.59 (Debian) Server at traefik.geeknest.stream Port 80

The Thing is with this Curl command the PUT is allowed, i also allow it on my Server:

curl -X PUT -u obfuscaed:obfuscated -T calendar.ics -H "Content-Type: text/calendar" -H "User-Agent: GuzzleHttp/7" https://ocfuscated/dav.php/calendars/bla/default/some-event.ics

What can I do to resolve this issue? I have already contacted Namecheap, and they confirmed that everything is functioning correctly on their end.

Thank you for your assistance.

alextselegidis commented 1 month ago

Hello!

This is strange indeed, but I would need to do some research on that and get back to you.

Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!

sandro-byte32 commented 1 month ago

If you need my login credentials, just let me know.

sandro-byte32 commented 1 month ago

The issue seems to be with how the get_caldav_event_uri method constructs the URI. The current implementation of the method does not take the base URL into account. Instead, it only appends the event ID to a root path.

Here's the current implementation of the get_caldav_event_uri method:

/**
 * Generate the event URI, used in various requests.
 *
 * @param string|null $caldav_event_id
 *
 * @return string
 */
private function get_caldav_event_uri(?string $caldav_event_id = null): string
{
    return $caldav_event_id ? '/' . $caldav_event_id . '.ics' : '';
}

This method only appends the event ID to a root path, which is why you are seeing incorrect URIs being generated.

To fix this, you need to modify the method to include the base URL (calendar URL) when constructing the URI. Here is a revised version of the method:

/**
 * Generate the event URI, used in various requests.
 *
 * @param string $caldav_calendar The base CalDAV calendar URL.
 * @param string|null $caldav_event_id The CalDAV event ID.
 *
 * @return string
 */
private function get_caldav_event_uri(string $caldav_calendar, ?string $caldav_event_id = null): string
{
    return rtrim($caldav_calendar, '/') . ($caldav_event_id ? '/' . $caldav_event_id . '.ics' : '');
}

This should resolve the issue and generate the correct URIs.

So, either no one is using CalDav at all, because it shouldn't have worked for anyone in the first place. I'm surprised that no one else has complained about it yet.

alextselegidis commented 1 month ago

Hello!

Thanks for looking into this and sharing the solution.

I will give it a try and integrate as needed.

Alex Tselegidis, Easy!Appointments Creator
Need a customization? Get a free quote!

sandro-byte32 commented 3 weeks ago

FYI:

I obfuscated it for privcacy reason.