anonsubmit/README.md

122 lines
5.7 KiB
Markdown

# anonchat
A simple Flask-based web application for anonymous inquiries or messages, designed for easy deployment and management.
## Features
* **Anonymous Inquiries:** Allows users to submit inquiries without revealing their identity.
* **Admin Interface:** Secure area for administrators to view and manage inquiries.
* **Webhook Notifications:** Optionally sends notifications to a specified URL upon new inquiry submissions.
* **Automatic Data Deletion:** Periodically deletes inquiries older than a configurable duration (default: 48 hours) to maintain privacy.
* **Rate Limiting:** Protects against abuse by limiting the number of requests from a single IP address.
* **CSRF Protection:** Implemented using Flask-WTF to prevent cross-site request forgery attacks.
* **Configurable:** Easily configured using environment variables.
* **Containerized:** Ready for deployment using Docker and Docker Compose.
* **Database Migrations:** Simple migration system managed via Flask CLI commands.
* **Optional Sentry Integration:** Supports error tracking with Sentry.
## Technology Stack
* **Backend:** Python 3.11+, Flask
* **Database:** PostgreSQL (recommended) or SQLite (default) via Flask-SQLAlchemy
* **Session Management:** Redis (recommended) or Filesystem via Flask-Session
* **Rate Limiting:** Redis via Flask-Limiter
* **Task Scheduling:** Flask-APScheduler
* **Password Hashing:** Argon2 via argon2-cffi
* **WSGI Server:** Gunicorn
* **Dependency Management:** Poetry
* **Containerization:** Docker, Docker Compose
* **Deployment:** Configured for Fly.io (optional)
## Configuration
The application is configured via environment variables. You can set these in a `.env` file in the project root or directly in your deployment environment.
**Required:**
* `SECRET_KEY`: A long, random string used for session signing and security. Generate one using `python -c 'import secrets; print(secrets.token_hex(24))'`.
* `DATABASE_URL`: The connection string for your database (e.g., `postgresql://user:password@host:port/dbname` or `sqlite:///instance/anonchat.db`).
* `REDIS_URL`: The connection string for your Redis instance (e.g., `redis://localhost:6379/0`). Used for sessions (if `SESSION_TYPE=redis`) and rate limiting.
* `ADMIN_PASSWORD`: The password for the admin user. Set this on first run or when needing to reset.
**Optional:**
* `SITE_TITLE`: The title displayed on the website (default: `AnonChat`).
* `WEBHOOK_ENABLED`: Set to `true` to enable webhook notifications (default: `false`).
* `WEBHOOK_URL`: The URL to send webhook notifications to.
* `WEBHOOK_SECRET`: A secret key to sign webhook payloads (recommended if webhooks are enabled).
* `ADMIN_USERNAME`: The username for the admin user (default: `admin`).
* `ADMIN_FORCE_RESET`: Set to `true` to force reset the admin password on startup using `ADMIN_PASSWORD`.
* `AUTO_DELETE_HOURS`: The number of hours after which inquiries are automatically deleted (default: `48`).
* `RATELIMIT_STORAGE_URI`: Overrides `REDIS_URL` specifically for rate limiting.
* `BEHIND_PROXY`: Set to `true` if the application is running behind a reverse proxy (e.g., Nginx, Traefik) to correctly identify client IPs (default: `false`).
* `SESSION_TYPE`: `redis` (default) or `filesystem`.
* `SESSION_FILE_DIR`: Directory for filesystem sessions (if `SESSION_TYPE=filesystem`, default: `/dev/shm/flask_session`).
* `SENTRY_DSN`: Your Sentry DSN to enable error tracking.
## Setup and Installation
**Prerequisites:**
* Python 3.11+
* Poetry
* Docker & Docker Compose (Recommended for ease of setup)
* Redis Server (if using Redis for sessions/rate limiting)
* PostgreSQL Server (if using PostgreSQL)
**1. Clone the Repository:**
```bash
git clone <repository-url>
cd anonchat
```
**2. Using Docker (Recommended):**
This is the easiest way to get started.
* **Create a `.env` file:** Copy `.env.example` (if it exists) or create a new `.env` file and fill in the required environment variables (see Configuration section). Pay special attention to `SECRET_KEY`, `DATABASE_URL`, `REDIS_URL`, and `ADMIN_PASSWORD`.
* **Build and Run:**
```bash
docker-compose up --build -d
```
The application should now be accessible at `http://localhost:5000` (or the port mapped in `docker-compose.yml`).
**3. Local Development (Without Docker):**
* **Install Dependencies:**
```bash
poetry install
```
* **Set Environment Variables:** Create a `.env` file in the project root and define the necessary variables (see Configuration).
* **Ensure Services are Running:** Make sure your PostgreSQL (if used) and Redis servers are running and accessible based on your `.env` configuration.
* **Run the Development Server:**
```bash
poetry run start
```
The application should be running at `http://localhost:5000`.
## Running the Application
* **Docker:** Use `docker-compose up -d` to start and `docker-compose down` to stop.
* **Local:** Use `poetry run start` for the development server. For production-like environments without Docker, use `gunicorn`:
```bash
# Example gunicorn command (adjust workers as needed)
poetry run gunicorn --workers 4 --bind 0.0.0.0:5000 "anonchat:app"
```
## Deployment
This application includes configuration files for deployment:
* `Dockerfile`: Defines the container image.
* `docker-compose.yml`: For local multi-container setups (app, db, redis).
* `fly.toml`: Configuration for deploying to Fly.io.
Refer to the specific platform's documentation for deployment steps using these files. Ensure all necessary environment variables are set in your deployment environment.
## License
This project is licensed under the 0BSD license - see the [LICENSE.txt](LICENSE.txt) file for details.