144 lines
5.2 KiB
Markdown
144 lines
5.2 KiB
Markdown
# CYBERCHAT v2.0
|
|
|
|
A self-contained, embed-ready real-time web chat built with **PHP, JavaScript, HTML5, and SQLite**. No external dependencies beyond PHP 8.0+.
|
|
|
|
---
|
|
|
|
## Features
|
|
|
|
- **Register on the fly** — pick a callsign (username) and passphrase, start chatting instantly
|
|
- **Session-locked** — one login per user enforced by IP + cookie; no multi-location sessions
|
|
- **Daily chat rooms** — each day starts fresh; yesterday's messages are automatically archived
|
|
- **SQLite archives** — stored per `archive/{year}/{month}/{day}.sqlite`; browseable via `archive-viewer.php`
|
|
- **Neon cyberpunk UI** — dark by default, light mode toggle per user (saved to localStorage)
|
|
- **Embed-ready** — drop into any `<div>` container; auto-adapts to any size
|
|
- **Fully configurable** — `config.json` controls all limits, intervals, and theming
|
|
- **Voice clips** — record, review, send, and queue WAV/WebM clips one at a time using normal PHP polling
|
|
- **No Node.js or WebSockets** — voice uses browser recording, HTTP uploads, and the existing poll loop
|
|
|
|
---
|
|
|
|
## Requirements
|
|
|
|
- PHP 8.0+ with **PDO SQLite** extension enabled
|
|
- Any web server (Apache, Nginx, Caddy, PHP built-in)
|
|
- Write permissions on `db/`, `archive/`, and `uploads/voice/` directories
|
|
- PHP/web-server upload limits at or above `voice.max_upload_bytes`
|
|
|
|
---
|
|
|
|
## Quick Start
|
|
|
|
```bash
|
|
# 1. Copy files to your web root (or a subdirectory)
|
|
cp -r cyberchat/ /var/www/html/chat/
|
|
|
|
# 2. Make sure database, archive, and voice storage are writable
|
|
chmod 755 /var/www/html/chat/db/
|
|
chmod 755 /var/www/html/chat/archive/
|
|
chmod 755 /var/www/html/chat/uploads/voice/
|
|
|
|
# 3. Visit in browser
|
|
# http://yourdomain.com/chat/
|
|
```
|
|
|
|
The SQLite database is created automatically on first visit.
|
|
|
|
---
|
|
|
|
## Embed in Your Own Page
|
|
|
|
```html
|
|
<!-- Fonts -->
|
|
<link href="https://fonts.googleapis.com/css2?family=Share+Tech+Mono&family=Rajdhani:wght@400;600;700&family=Orbitron:wght@700;900&display=swap" rel="stylesheet">
|
|
|
|
<!-- Stylesheet -->
|
|
<link rel="stylesheet" href="/chat/assets/css/cyberchat.css">
|
|
|
|
<!-- Container — set any size -->
|
|
<div id="my-chat" style="width:100%; height:600px;"></div>
|
|
|
|
<!-- Script -->
|
|
<script src="/chat/assets/js/cyberchat.js"></script>
|
|
<script>
|
|
window.CYBERCHAT_BASE = '/chat'; // path to your cyberchat install
|
|
CyberChat.init('#my-chat');
|
|
</script>
|
|
```
|
|
|
|
See `embed-example.html` for a live demo.
|
|
|
|
---
|
|
|
|
## Configuration — `config.json`
|
|
|
|
| Key | Default | Description |
|
|
|-----|---------|-------------|
|
|
| `chat.max_message_length` | 500 | Max characters per message |
|
|
| `chat.max_username_length` | 12 | Max callsign length |
|
|
| `chat.poll_interval_ms` | 2000 | How often client polls for new messages (ms) |
|
|
| `chat.messages_per_page` | 100 | Messages loaded on initial connect |
|
|
| `chat.session_lock_ip` | true | Enforce single login per IP |
|
|
| `chat.session_lock_cookie` | true | Enforce single login per cookie |
|
|
| `voice.enabled` | true | Enable voice clip controls and uploads |
|
|
| `voice.max_duration_seconds` | 60 | Maximum voice clip duration |
|
|
| `voice.max_upload_bytes` | 12582912 | Maximum voice upload size |
|
|
| `voice.auto_play_default` | true | Queue and play new incoming clips one at a time by default |
|
|
| `voice.upload_dir` | "uploads/voice" | Voice recording storage path |
|
|
| `security.min_password_length` | 4 | Minimum passphrase length |
|
|
| `security.session_timeout_hours` | 24 | Session expiry |
|
|
| `security.bcrypt_cost` | 10 | bcrypt work factor for passwords |
|
|
| `ui.default_theme` | "dark" | Default theme (`dark` or `light`) |
|
|
| `ui.app_title` | "CYBERCHAT" | Title shown in header |
|
|
| `ui.app_subtitle` | "v3.0 // SECURE CHANNEL" | Subtitle shown in header |
|
|
| `colors.user_palette` | [...] | Array of hex colors assigned randomly to users |
|
|
|
|
---
|
|
|
|
## File Structure
|
|
|
|
```
|
|
cyberchat/
|
|
├── index.html ← Main chat page
|
|
├── embed-example.html ← Embed usage example
|
|
├── archive-viewer.php ← Browse archived days
|
|
├── bootstrap.php ← DB init, helpers, session auth
|
|
├── config.json ← All configuration
|
|
├── api/
|
|
│ ├── auth.php ← Register / Login / Logout / Check
|
|
│ ├── messages.php ← Send / Poll / History
|
|
│ └── config.php ← Serves safe config to frontend
|
|
├── assets/
|
|
│ ├── css/cyberchat.css ← Full cyberpunk stylesheet
|
|
│ └── js/cyberchat.js ← Chat client (no framework)
|
|
├── db/
|
|
│ └── chat.sqlite ← Created automatically; today's messages
|
|
├── uploads/
|
|
│ └── voice/ ← WAV/WebM voice recordings
|
|
└── archive/
|
|
└── {year}/{month}/ ← Auto-archived per day as .sqlite files
|
|
└── {day}.sqlite
|
|
```
|
|
|
|
---
|
|
|
|
## Archive Viewer
|
|
|
|
Visit `archive-viewer.php` to browse historical chat logs. Select a day from the sidebar to read its messages.
|
|
|
|
---
|
|
|
|
## Nginx Config Example
|
|
|
|
See `nginx-example.conf` for a ready-to-use virtual host config.
|
|
|
|
---
|
|
|
|
## Security Notes
|
|
|
|
- Passwords are hashed with **bcrypt** (configurable cost factor)
|
|
- Session tokens are 64-char cryptographically random hex strings
|
|
- Session cookies are `HttpOnly`, `SameSite=Strict`, and `Secure` when served over HTTPS
|
|
- All user input is escaped on output; no raw HTML accepted
|
|
- Single-login enforcement via IP + cookie prevents session sharing
|