Profpatsch/users/Profpatsch/calweb

calweb(1)

calweb - the primary Google calendar of one account, as text, with confirmed writes

calweb --client-id-cmd cmd --client-secret-cmd cmd [--listen addr] [--db path] [--timezone zone]

calweb answers questions about one Google account's primary calendar over HTTP, in the text rendering the mail frontends of this tree use (text/llm), and lets a client propose changes that a person then confirms in a browser.

Every read asks Google; nothing about the calendar is stored. The only state is the OAuth grant and the proposals, in one SQLite file.

Nothing calweb sends to Google can invite or notify anybody: it has no attendees field, every write carries sendUpdates=none, and it refuses to propose changes to events somebody else organised or that have attendees. See calweb(7) for why each of these holds.

--client-id-cmd cmd, --client-secret-cmd cmd

Shell commands whose first line of output is the OAuth client id and secret of a "Desktop app" client: a pass(1) invocation when run by hand, a cat(1) of a systemd credential in the shipped unit, see FILES. Run once at startup.

--listen addr

Default 127.0.0.1:8779. Must be a loopback address; anything else is refused at startup, because calweb has no authentication. The OAuth redirect is built from this address, so it must be the one the browser reaches.

--db path

Default ~/.local/state/calweb/calweb.db. Created mode 0600.

--timezone zone

Default Europe/Berlin. Times are shown in it and form fields are read in it.

A new database has no grant, and every route then answers 503 saying so. A person opens http://127.0.0.1:8779/login in a browser, which redirects to Google; after consent Google redirects back to /oauth/callback and the refresh token is stored. This is never done by a client on its own.

If Google later answers invalid_grant – access revoked, password changed, or the client's consent screen left in "Testing", which expires grants after seven days – the grant is deleted and the same 503 appears, so logging in again is the same step.

Every route answers text, as text/llm when asked for with Accept: text/llm or ?view=llm, otherwise as text/plain. The exceptions are the two pages a person confirms on, which answer a browser (Accept: text/html) with HTML: /proposals and the page of one proposal.

/

The agenda, grouped by day. since defaults to today and until to fourteen days later. Both take YYYY-MM-DD, today, tomorrow, yesterday, or an offset in days, weeks or months (14d, +2w, -1m) that points forward unless it starts with a minus – the reverse of mailweb(1), where offsets point into the past. until includes its whole day. A window holding more than 500 events is cut there and says so.

/search?q=‌words

Google's own search over title, description and place. The window defaults to one year back to one year ahead and takes the same parameters as the agenda.

/event/‌id

One event with its description, organiser, attendees, recurrence, and whether calweb will propose changes to it. The description is framed as text written by somebody else.

All three take application/x-www-form-urlencoded and answer 201 with the URL of the proposal. None of them writes to Google.

/events (POST)

A new event. summary is required. Either start and end as YYYY-MM-DD HH:MM, or date for an all-day event, with optional until as its last day, inclusive. location and description are optional. weekly_until, a day as YYYY-MM-DD, makes the event a series repeating every week on the weekday it starts, up to and including that day; except lists days, comma-separated, on which an occurrence is left out. An excepted day that is not an occurrence of the series, and except without weekly_until, refuse the request. The proposal lists every day the series will have. A field named attendees, attendee, guests or invite refuses the request.

/event/‌id‌/edit (POST)

The same fields, each optional; only those present change, and a present but empty one is cleared. On a series, except replaces the whole list of excepted days and weekly_until the last day, each keeping the other as it is; an empty weekly_until makes the series a single event. Moving a series' start time moves its excepted occurrences with it. A series made in Google Calendar with anything other than weekly_until and except can have its title, place and description changed, but not its times or how it repeats.

/event/‌id‌/delete (POST)

No fields.

Edit and delete fetch the event first and record its etag; they answer 403 for an event organised by somebody else, one with attendees, one occurrence of a recurring series, or a special event type, saying which.

/proposals

Proposals waiting for confirmation, then the ten most recently closed. In a browser each links to its HTML page.

/proposal/‌token

In a browser: an HTML page showing each field before and after, with a button that writes the change and one that discards it. As text: the same content, without buttons.

/proposal/‌token‌/apply (POST)

Writes the change to Google, then redirects to /proposals, which names the proposal just applied and what Google stored above the ones still waiting, so that several are confirmed one after the other. An edit or delete is sent with If-Match of the recorded etag; if the event changed in Google since, nothing is written and the response says so. Applying an already applied or discarded proposal is refused with 409. A request whose Origin or Sec-Fetch-Site says it came from another site is refused with 403.

/proposal/‌token‌/discard (POST)

Closes the proposal without writing anything, and redirects to /proposals like apply. A proposal already applied or discarded is refused with 409: an applied change is in Google, and undoing it is a new edit proposal, not a discard.

Once applied, the text rendering of a proposal has a result section naming the event's /event/‌id, which is how to find a newly created event to edit it further.

/login

Redirects to Google's consent screen.

/oauth/callback

Google's redirect target; stores the grant.

~/.local/state/calweb/calweb.db

The grant (oauth), logins in progress (oauth_pending), and every proposal ever made (proposals), applied ones keeping what Google stored. The refresh token is stored unencrypted; the file is mode 0600.

calweb.service

The systemd user unit, beside the sources. It has no access to any password manager: the client id and secret are loaded with LoadCredentialEncrypted= and read through --client-id-cmd='cat %d/calweb-client-id', and the home directory is an empty tmpfs into which only the nix profile and ~/.local/state/calweb are mounted.

~/.config/credstore.encrypted/calweb-client-id, ~/.config/credstore.encrypted/calweb-client-secret

The two credentials, sealed to this machine's TPM. Each is a copy of an entry in the KeePassXC database ~/Passwords/Passwords.kdbx, named in the unit's X-CredentialSource= lines; the comment above them gives the command that recreates one after the entry changes.

$ curl -s -H 'Accept: text/llm' 'localhost:8779/?since=today&until=+7d'
$ curl -s -H 'Accept: text/llm' 'localhost:8779/search?q=Einf"uhrung'
$ curl -s -H 'Accept: text/llm' localhost:8779/events \
    --data-urlencode 'summary=Einf"uhrung BA VL' \
    --data-urlencode 'start=2026-10-09 10:00' \
    --data-urlencode 'end=2026-10-09 13:00' \
    --data-urlencode 'location=Raum 2107, Geb"aude D'

The last answers with a proposal URL to open in a browser.

Google Calendar treats location as a text search when it is opened on a map, so a readable address ('Universität Augsburg, Gebäude D, Universitätsstraße 10') is the useful thing to put there; a room number in it only makes the search worse. Exact positions go into description as CoMaps links, one per place, with coordinates taken from OpenStreetMap:

https://comaps.at/map?v=1&ll=48.335118,10.896656&n=Uni%20Augsburg%20Geb%C3%A4ude%20D

ll is latitude,longitude and n the URL-encoded label; several ll/n pairs may follow one another. The format is documented at https://comaps.at/api. Coordinates of a named building come from the Overpass API, which answers 406 unless the request carries a User-Agent and Accept: application/json; 'out tags center;' gives one point per building outline.

mailweb(1), systemd-creds(1), calweb(7)

Profpatsch mail@profpatsch.de

Only the primary calendar is reachable.

A response is only as current as the request: there is no cache, so the same URL twice may differ.

The confirmation step guards against mistakes, not against a client that ignores it: anything that can reach the listen address can also send the apply request.

calweb(7)

calweb - why calweb is shaped the way it is

This page is the reasoning behind calweb(1). Read it before changing something the reference merely states.

mailweb(1) keeps a full copy of the mailbox, because IMAP cannot answer the questions asked of it: it is slow, it has no useful search, and listing a day's mail across mailboxes is many round trips.

Google's Calendar API answers every question calweb is asked in one request. A time window comes back sorted, with recurring events already expanded into their occurrences; a search is done on Google's side. A mirror would add a sync loop, change tokens, a resync path for when those expire, and a schema – roughly half the program – to buy offline reading and speed that a calendar consulted a few times a day does not need. And recurrence would have to be expanded locally, which is exactly where calendar software is most often wrong.

The cost is that nothing works without the network, and there is no history of what an event looked like before it changed.

The SQLite file is therefore not a mirror. It holds what is calweb's own: the grant, and the proposals.

Google publishes a generated Go client. It is spread over dozens of modules, each of which would need a pin in go-deps.nix kept in step with the workspace, to wrap what is here four API calls and two token requests. They are written against net/http instead, and calweb adds no dependency the workspace did not already have.

Every change to the calendar is a proposal first. The route that asks for it stores it and answers with a URL; only the button on that URL's page writes.

The reason is the one behind drafts in mailweb(7): the client is usually an agent, and asking for something is not the same as somebody having read what will happen. The page shows each field before and after, rendered from the same code for both sides, so what is shown is what is sent.

It is a convention, not a barrier. calweb has no authentication, and whatever can reach the listen address can send the apply request as easily as a browser can. The text responses say not to, which is what a well-behaved client needs; a client that ignores them was never going to be stopped by a button. What the step reliably prevents is the ordinary mistake: an event created at the wrong hour because nobody looked.

Two guards are real rather than conventional. Cross-site requests are refused, so a web page cannot submit the form on a visitor's behalf. And an edit or delete is conditional on the version it was proposed against, so a proposal confirmed a day late cannot silently undo a change made in the meantime.

calweb never puts anybody but the account owner in a calendar.

Adding an attendee makes Google send them an invitation, which is mail sent in the owner's name to a third party – the one thing in this tree that is always a person's decision. So the write type has no attendees field: a request cannot carry what the type cannot hold. A form field that looks like one is refused rather than ignored, so a client learns it was not done instead of believing it was.

sendUpdates=none is sent with every write anyway, so that the rule does not rest on the absence of a field alone.

Changing an event that already has attendees is refused too. sendUpdates=none suppresses the notification mail, but the change still appears in their calendars; moving a shared meeting is something to do where the other people are visible. An event somebody else organised is refused for a similar reason: a change either fails or quietly diverges the owner's copy from the organiser's.

Changing a single occurrence through the API detaches it from its series as an exception. That is legitimate, but it is rarely what "move this appointment" means when the appointment is weekly, and the series itself has a different id. Rather than guess, calweb refuses and names the series.

A series is written as weekly_until and except, not as an RRULE a client composes. RFC 5545 recurrence is a language, and what a person confirming would be shown is a line of it; whether UNTIL=20270203T225959Z includes the third of February is not something to check by eye. What the proposal shows instead is every day the series will have, computed by the same code that wrote the rule, so the dates are compared with the course plan and not the syntax.

Weekly up to a day, minus some weeks, is the shape of a semester's course, which is what this was added for. Anything richer – two weekdays, every other week, a count – can be made in Google Calendar's editor, and calweb then shows the rule raw and leaves the series' times alone, rather than rewrite a rule it cannot read back.

Two details of the rule are easy to get wrong and are why the client does not write it. UNTIL must be in UTC when the event has a time zone, so the last day ends at 23:59:59 Berlin time, which is 22:59:59Z in winter. And an EXDATE removes an occurrence only if it names its start to the second; a bare date, or the old time after the series was moved, silently removes nothing. That is why moving a series rewrites its exceptions, and why an excepted day that is not an occurrence is refused: Google would accept it, and the person would find the lecture in the calendar on the day it was cancelled.

In mailweb(1), ?since=7d means seven days ago, because nobody asks a mail archive about next week. A calendar is asked about next week constantly, so here a bare offset points forward and a leading minus points back. The two programs differ on purpose; sharing mailweb(1)'s parser would have made until=14d silently mean two weeks ago.

Every date is printed with a two-letter German weekday: '2026-10-09 Fr'. That is the format of the Wiedervorlage ledger these dates are copied into, and wiedervorlage(7) explains why the weekday is there at all: dating happens by arithmetic, and nothing in a bare date says a call to an office has landed on a Sunday.

Google's exclusive end date for all-day events is moved back a day before it is printed. An event on the 25th alone ends on the 26th in the API, and printing that would say it lasts two days.

The grant lives in the SQLite file in plain text, protected by the file's mode and the account. Encrypting it with a key from pass(1) was considered and declined: it would need the gpg agent at every start, and the scope it protects is narrow. calendar.events can read and change events, and nothing else - not calendar settings, not sharing, not mail or the rest of the Google account.

The gpg agent has since been taken away from the service altogether, for the client id and secret too. An agent that is unlocked decrypts every entry in the store for whoever asks, so a service holding it was one bug away from all of them, a far larger thing than one calendar grant. The unit loads those two as systemd credentials instead, sealed to the machine's TPM, and hides the rest of the home directory; see FILES in calweb(1). What that leaves of the argument above is the same: the token is still plain text in a file the service can read, and moving it into a credential would mean writing one at runtime, which systemd does not offer.

calweb(1), mailweb(7), wiedervorlage(7)