`Sw1tch` is a FastAPI-based web application designed to enhance the `conduwuit` Matrix homeserver by addressing key shortcomings for public deployments. It manages account registration with email-based token requests and provides an admin API by relaying HTTP requests to a Matrix admin room, parsing responses for automation. Currently in use for the [We2.ee](https://we2.ee/about) homeserver at [join.we2.ee](https://join.we2.ee).
This project is specifically built around `conduwuit`, an excellent Matrix homeserver that lacks native SMTP authentication and a robust admin API—issues `sw1tch` resolves elegantly.
- **Purpose**: Generates a new, random 6-character hexadecimal registration token and writes it to `sw1tch/data/.registration_token`.
- **Behavior**: Overwrites the existing token, logs the new value, and exits on failure (e.g., if the file isn’t writable).
- **When to Use**:
- Daily via cron (e.g., at midnight UTC) to rotate tokens as a security measure.
- Manually if you suspect the current token has been compromised.
- **Example**: `./launch.sh --refresh-token`
2.**`--super-admin`**:
- **Purpose**: Generates a random 16-character emergency password for the `@conduit` user in `conduwuit` and passes it to the container via `CONDUWUIT_EMERGENCY_PASSWORD`.
- **Behavior**: Logs the username (`@conduit:we2.ee`) and password, which you can use to log in and regain admin access.
- **When to Use**:
- During initial setup to establish admin access.
- If you lose access to the admin account and need to recover it.
- **Example**: `./launch.sh --super-admin`
3.**`--update`**:
- **Purpose**: Updates the `conduwuit` Docker image by pulling the latest source from `REPO_PATH`, building it with Nix, and tagging it as `conduwuit:custom`.
- **Behavior**: Requires Git and Nix; exits on failure (e.g., if the build fails or no image is produced).
- **When to Use**:
- Weekly via cron to keep `conduwuit` up-to-date with the latest features or fixes.
- Manually when you want to apply a specific update.
- **Example**: `./launch.sh --update`
4.**`--force-restart`**:
- **Purpose**: Forces the `sw1tch` registration service to restart by killing any process on the configured port (from `config.yaml`) and starting a new instance.
- **Behavior**: Removes the PID file, starts `python3 -m sw1tch` detached, and verifies it’s running; logs errors if it fails to start.
- **When to Use**:
- After updating `sw1tch` code or configuration to ensure changes take effect.
- If the service is unresponsive or stuck.
- Combined with `--update` to refresh everything.
- **Example**: `./launch.sh --force-restart`
### Additional Notes
- **Combination**: Flags can be combined (e.g., `./launch.sh --update --force-restart`) for comprehensive updates.
- **Default Behavior**: Without flags, the script restarts the `conduwuit` container and ensures `sw1tch` is running (no forced restart).
- **Cron Integration**: The comments align with your crontab (daily `--refresh-token`, weekly `--update --force-restart`, reboot startup).
The warrant canary feature (in progress) generates signed statements posted to a Matrix room, using data from RSS feeds and Bitcoin blocks for freshness. Configure in `config.yaml` under `canary`. Current limitations include UI polish and broader testing.