### Run Setup Script Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Executes the setup script, which installs pm2 (Node.js process manager) and gulp (task system). It also runs some initial gulp tasks required for the project setup. ```bash npm run-script setup ``` -------------------------------- ### Install and Configure MongoDB for jschan Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs MongoDB Community Edition version 6.0 on Debian, enables it to start on boot, and configures it with authentication enabled. It also creates a dedicated user 'jschan' with read-write permissions for the 'jschan' database. Remember to replace the placeholder password with a secure one. ```bash wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add - echo "deb http://repo.mongodb.org/apt/debian $(lsb_release -sc)/mongodb-org/6.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list sudo apt update -y sudo apt install -y mongodb-org sudo systemctl enable --now mongod #NOTE: change "CHANGE-ME-YOUR-SECURE-MONGODB-PASSWORD" to something secure. mongosh admin --eval "db.getSiblingDB('jschan').createUser({user: 'jschan', pwd: 'CHANGE-ME-YOUR-SECURE-MONGODB-PASSWORD', roles: [{role:'readWrite', db:'jschan'}]})" sudo sh -c "cat > /etc/mongod.conf" <<'EOF' storage: dbPath: /var/lib/mongodb journal: enabled: true systemLog: destination: file logAppend: true path: /var/log/mongodb/mongod.log net: port: 27017 bindIp: 127.0.0.1 processManagement: timeZoneInfo: /usr/share/zoneinfo security: authorization: "enabled" EOF sudo systemctl restart mongod #NOTE: to access to DB directly in future: #mongosh "mongodb://jschan:CHANGE-ME-YOUR-SECURE-MONGODB-PASSWORD@127.0.0.1:27017/jschan" ``` -------------------------------- ### Configure PM2 Startup Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Configures pm2 to run as a system service and start on system boot. This command outputs additional instructions that must be followed to complete the setup. ```bash pm2 startup ``` -------------------------------- ### Install Node.js Dependencies Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs all the necessary Node.js dependencies required for the jschan project. This command should be run after cloning the repository or updating dependencies. ```bash npm install ``` -------------------------------- ### Start Backend Processes Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Starts all the backend processes for jschan using npm scripts and pm2. It also saves the current pm2 process list. ```bash npm run-script start gulp pm2 save ``` -------------------------------- ### Docker Compose for Development Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Provides Docker Compose commands for setting up the jschan development environment. This includes starting databases (mongodb, redis), running a reset task, starting the main jschan application, and starting the Nginx server. ```bash docker-compose up -d mongodb redis docker-compose up jschan-reset docker-compose up -d jschan docker-compose up -d nginx ``` -------------------------------- ### View PM2 Logs Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Starts tailing the logs for all processes managed by pm2. This is useful for debugging issues during setup or after updates. ```bash pm2 logs ``` -------------------------------- ### Setup Lokinet SNApp for jschan Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs Lokinet and configures it to run a SNApp for the jschan project. It sets up the necessary configuration file and provides instructions on how to find the .loki address. This enables access via the Lokinet network. ```bash sudo curl -so /etc/apt/trusted.gpg.d/oxen.gpg https://deb.oxen.io/pub.gpg echo "deb https://deb.oxen.io $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/oxen.list sudo apt update -y sudo apt install lokinet -y sudo systemctl enable --now lokinet sudo sh -c "cat > /var/lib/lokinet/lokinet.ini" <<'EOF' [router] [network] keyfile=/var/lib/lokinet/snappkey.private [paths] [dns] [bind] [api] [bootstrap] [logging] EOF sudo systemctl restart lokinet nslookup -type=cname localhost.loki # Your loki address is the "canonical name". ``` -------------------------------- ### Standard Nginx Installation Script Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Executes the standard Nginx installation script for jschan. This script handles prompts for installation directory, domains, onion/lokinet integration, geoip enablement, and Let's Encrypt certificate installation using certbot. ```bash sudo bash configs/nginx/nginx.sh ``` -------------------------------- ### Install and Configure Redis for jschan Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs the Redis server and configures it to use systemd for supervision. It also enables password authentication by modifying the Redis configuration file. Remember to replace the placeholder password with a secure one. ```bash sudo apt update -y sudo apt install redis-server -y sed -i 's/supervised no/supervised systemd/' /etc/redis/redis.conf sudo systemctl enable --now redis-server # Enable authentication: echo "requirepass CHANGE-ME-YOUR-SECURE-REDIS-PASSWORD" | sudo tee -a /etc/redis/redis.conf sudo systemctl restart redis-server ``` -------------------------------- ### Install Node.js using NVM Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs Node Version Manager (nvm) and then uses it to install the latest Long Term Support (LTS) version of Node.js. This is the recommended method for managing Node.js versions for the jschan project. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" nvm install --lts ``` -------------------------------- ### Copy and Edit Secrets Configuration Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Copies the example secrets file to a new file and opens it for editing. This is where users input their MongoDB, Redis credentials, cookie secrets, and other sensitive information. ```bash cp configs/secrets.js.example configs/secrets.js && editor configs/secrets.js ``` -------------------------------- ### Edit Custom Pages (Rules and FAQ) Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Opens the Pug template files for the rules and FAQ pages in the editor. This allows users to customize the content of these pages. ```bash editor views/custompages/faq.pug views/custompages/rules.pug ``` -------------------------------- ### Setup Tor Hidden Service for jschan Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs the Tor service and configures it to run a hidden service for the jschan application. It sets up the necessary configuration file and outputs the generated .onion address. This allows for anonymous access to the application. ```bash sudo apt install tor -y sudo systemctl enable --now tor sudo sh -c "cat > /etc/tor/torrc" <<'EOF' HiddenServiceDir /var/lib/tor/jschan/ HiddenServiceVersion 3 HiddenServicePort 80 unix:/var/run/nginx-tor.sock EOF sudo systemctl restart tor sudo cat /var/lib/tor/jschan/hostname ``` -------------------------------- ### Install System Dependencies for jschan Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Installs essential system packages required for the jschan project, including curl, wget, Node.js, MongoDB, Redis, Nginx, image manipulation tools, and Certbot for SSL certificates. This command assumes a Debian-based system. ```bash sudo apt update -y sudo apt install curl wget gnupg nginx ffmpeg imagemagick graphicsmagick python3-certbot-nginx fonts-dejavu -y ``` -------------------------------- ### List Running PM2 Processes Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Displays a list of all processes currently being managed by pm2, including their status and resource usage. ```bash pm2 list ``` -------------------------------- ### Update Node.js and NPM using NVM Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Updates Node.js to the latest LTS version, installs the latest npm, and reinstalls global packages using NVM (Node Version Manager). This command assumes Node.js was installed via NVM. ```bash nvm install --lts --reinstall-packages-from=$(node --version) --latest-npm ``` -------------------------------- ### Build Custom Pages with Pug Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Instructions for adding custom pages to the jschan site by creating Pug (.pug) files in the `views/custompages/` directory. The build system will process these files into HTML. A command to build all custom pages is provided. ```bash gulp custompages ``` -------------------------------- ### Compare Nginx Configuration Versions Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Compares the Nginx configuration files between two specified git tags (versions). This helps identify changes that might require manual intervention. ```bash git diff v0.9.2 v0.8.0 configs/nginx ``` -------------------------------- ### Run Gulp Migrate and Default Task Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Executes the gulp migrate task to apply database schema or file structure updates, followed by the default gulp task. This is typically run after updating the installation. ```bash gulp migrate && gulp ``` -------------------------------- ### Build CSS Files Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Command to build all CSS files, combining and minifying them into the main `style.css`. This command should also be run if themes are added or removed, as it updates related scripts and templates. ```bash gulp css ``` -------------------------------- ### Restart Backend Processes in Production Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Restarts all backend processes defined in the ecosystem configuration file, specifically loading them in the production environment. ```bash pm2 restart ecosystem.config.js --env production ``` -------------------------------- ### Run Default Gulp Task Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Executes the default Gulp task. This can be used for various build or development-related operations. ```bash gulp ``` -------------------------------- ### Reset Database and Folder Structure Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Initializes the database and folder structure using the gulp reset task. This command also creates an admin account with a random password, which will be printed to the console. Running this command again will irreversibly wipe all data. ```bash gulp reset ``` -------------------------------- ### Commit Message Example Source: https://github.com/crisbon/jschan/blob/master/CONTRIBUTING.md Demonstrates the format for writing clear and concise commit messages, including a summary line and a detailed paragraph for larger changes. ```git $ git commit -m "A brief summary of the commit A paragraph describing what changed and its impact." ``` -------------------------------- ### Pull Latest Git Changes Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Fetches and merges the latest changes from the git repository into the current branch. ```bash git pull ``` -------------------------------- ### Reload Backend Processes Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Reloads all backend processes defined in the ecosystem configuration file. This is useful for applying configuration changes without a full restart. ```bash pm2 reload ecosystem.config.js ``` -------------------------------- ### Stop Backend Processes Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Stops all running backend processes managed by pm2, using the provided ecosystem configuration file. ```bash pm2 stop ecosystem.config.js ``` -------------------------------- ### Add Custom CSS for Theming Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Explains how to add custom CSS rules that will override the default styles. Create a `custom.css` file in `gulp/res/css/` and add your styles there. This file will be included after the main `style.css`, ensuring your rules take precedence. ```css /* Add your custom CSS rules here */ body { background-color: #f0f0f0; } ``` -------------------------------- ### Run Tests in jschan Source: https://github.com/crisbon/jschan/blob/master/CONTRIBUTING.md Commands to execute unit, integration, and all tests for the jschan project. Integration tests require a password from the docker setup. ```bash #unit tests npm run test # OR npm run test:unit #integration tests TEST_ADMIN_PASSWORD= npm run test:integration #all tests npm run test:all #specific test(s) npm run test:all ``` -------------------------------- ### Manage Two-Factor Authentication (2FA) Source: https://context7.com/crisbon/jschan/llms.txt Set up, enable, or disable TOTP-based two-factor authentication for an account. Setup returns a QR code, while enabling/disabling requires a 2FA code and authentication. ```bash # Setup 2FA (returns QR code) curl "https://your-instance.com/twofactor.html" \ -H "Cookie: connect.sid=your-session-cookie" # Enable 2FA curl -X POST "https://your-instance.com/forms/twofactor" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "twofactor=123456" # Disable 2FA curl -X POST "https://your-instance.com/forms/twofactor" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "twofactor=654321" \ -d "disable=1" ``` -------------------------------- ### Public Page Routes (GET Endpoints) Source: https://context7.com/crisbon/jschan/llms.txt Public page routes for viewing boards, threads, and catalogs. ```APIDOC ## GET / ### Description Returns the homepage. ### Method GET ### Endpoint / ## GET /b/index.html ### Description Returns the index page for a board (page 1). ### Method GET ### Endpoint /b/index.html ## GET /b/{page}.html ### Description Returns a specific page of a board. ### Method GET ### Endpoint /b/{page}.html ### Parameters #### Path Parameters - **page** (integer) - Required - The page number to retrieve. ## GET /b/thread/{threadId}.html ### Description Returns a specific thread. ### Method GET ### Endpoint /b/thread/{threadId}.html ### Parameters #### Path Parameters - **threadId** (integer) - Required - The ID of the thread to retrieve. ## GET /b/catalog.html ### Description Returns the catalog for a board. ### Method GET ### Endpoint /b/catalog.html ## GET /overboard.html ### Description Returns the overboard page (all boards). ### Method GET ### Endpoint /overboard.html ## GET /catalog.html ### Description Returns the global catalog. ### Method GET ### Endpoint /catalog.html ## GET /boards.html ### Description Returns the list of all boards. ### Method GET ### Endpoint /boards.html ## GET /b/index.json ### Description Returns the index page for a board in JSON format. ### Method GET ### Endpoint /b/index.json ## GET /b/thread/{threadId}.json ### Description Returns a specific thread in JSON format. ### Method GET ### Endpoint /b/thread/{threadId}.json ### Parameters #### Path Parameters - **threadId** (integer) - Required - The ID of the thread to retrieve. ## GET /b/catalog.json ### Description Returns the catalog for a board in JSON format. ### Method GET ### Endpoint /b/catalog.json ## GET /boards.json ### Description Returns the list of all boards in JSON format. ### Method GET ### Endpoint /boards.json ## GET /b/settings.json ### Description Returns public board settings in JSON format. ### Method GET ### Endpoint /b/settings.json ## GET /settings.json ### Description Returns global settings in JSON format. ### Method GET ### Endpoint /settings.json ### Response #### Success Response (200) Returns a JSON object containing the requested data. #### Response Example ```json { "example": "JSON response body" } ``` ``` -------------------------------- ### Configure UFW Firewall for Lokinet Interface Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Configures the Uncomplicated Firewall (ufw) to manage traffic for the Lokinet interface. It denies all incoming traffic on the 'lokitun0' interface except for TCP traffic on port 80, ensuring secure communication within the Lokinet network. ```bash sudo ufw deny in on lokitun0 to any sudo ufw allow in on lokitun0 to any port 80 proto tcp ``` -------------------------------- ### Nginx and Tor Communication via Unix Socket Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Configures Nginx and Tor to communicate using a Unix socket instead of TCP for potential performance gains. This involves setting the listen directive in Nginx and the HiddenServicePort in Tor's configuration. Ensure correct file permissions for the socket. ```nginx server { listen unix:/var/run/nginx-tor.sock; allow "unix:"; deny all; } ``` ```torrc HiddenServicePort 80 unix:/var/run/nginx-tor.sock ``` -------------------------------- ### Nginx Upstream Configuration for Multiple Node.js Processes Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Configures the Nginx upstream block to distribute traffic across multiple Node.js processes, each listening on a different port. This is used in conjunction with disabling Node.js clustering. ```nginx upstream chan { server 127.0.0.1:7000; server 127.0.0.1:7001; server 127.0.0.1:7002; server 127.0.0.1:7003; } ``` -------------------------------- ### Disable Node.js Clustering with PM2 Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Modifies PM2 configuration and server code to disable Node.js clustering. Instead of a master process delegating requests, each process listens on a sequential port. This removes the overhead of the master process but sacrifices zero-downtime reloads. ```diff diff --git a/ecosystem.config.js b/ecosystem.config.js index fc000094..f2b53c1b 100644 --- a/ecosystem.config.js +++ b/ecosystem.config.js @@ -30,0 +31 @@ module.exports = { + exec_mode: 'fork', diff --git a/server.js b/server.js index f9e19dbc..1630dce0 100644 --- a/server.js +++ b/server.js @@ -152 +152 @@ const express = require('express') - server.listen(port, '127.0.0.1', () => { + server.listen(port+parseInt(process.env.NODE_APP_INSTANCE), '127.0.0.1', () => { ``` -------------------------------- ### Public Page Routes using cURL Source: https://context7.com/crisbon/jschan/llms.txt Retrieves public content such as the homepage, board indexes, threads, catalogs, and settings via GET requests. Supports both HTML and JSON formats for various endpoints. ```bash # Homepage curl "https://your-instance.com/index.html" # Board index (page 1) curl "https://your-instance.com/b/index.html" # Board page 2 curl "https://your-instance.com/b/2.html" # View thread curl "https://your-instance.com/b/thread/12345.html" # Board catalog curl "https://your-instance.com/b/catalog.html" # Overboard (all boards) curl "https://your-instance.com/overboard.html" # Overboard catalog curl "https://your-instance.com/catalog.html" # Board list curl "https://your-instance.com/boards.html" # JSON API variants curl "https://your-instance.com/b/index.json" curl "https://your-instance.com/b/thread/12345.json" curl "https://your-instance.com/b/catalog.json" curl "https://your-instance.com/boards.json" # Public board settings curl "https://your-instance.com/b/settings.json" # Global settings curl "https://your-instance.com/settings.json" ``` -------------------------------- ### Captcha and Block Bypass Source: https://context7.com/crisbon/jschan/llms.txt Get captcha images and handle block bypass for posting. ```APIDOC ## GET /captcha ### Description Retrieves a captcha image. This endpoint typically sets a session cookie. ### Method GET ### Endpoint /captcha ### Response #### Success Response (200) Returns an image file (e.g., JPEG). Sets `Set-Cookie` header for session management. #### Response Example (Image data, no JSON example) ## POST /forms/blockbypass ### Description Submits a solution to a block bypass captcha. ### Method POST ### Endpoint /forms/blockbypass ### Parameters #### Query Parameters None #### Request Body - **captcha** (string) - Required - The user's solution to the captcha. ### Request Example ```json { "captcha": "SOLUTION123" } ``` ## GET /csrf.json ### Description Retrieves a CSRF token for authenticated requests. ### Method GET ### Endpoint /csrf.json ### Parameters #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **_csrf** (string) - The CSRF token value. #### Response Example ```json { "_csrf": "token-value-here" } ``` ``` -------------------------------- ### Reset Admin Password Source: https://github.com/crisbon/jschan/blob/master/INSTALLATION.md Resets the admin account password for jschan. This command is useful if the admin password has been forgotten. ```bash gulp password ``` -------------------------------- ### Create a New Board Source: https://context7.com/crisbon/jschan/llms.txt Allows authenticated users to create new imageboards with custom URIs, names, and descriptions. ```APIDOC ## POST /forms/create ### Description Allows logged-in users to create their own boards with custom settings. ### Method POST ### Endpoint `/forms/create` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **uri** (string) - Required - The unique identifier for the new board. - **name** (string) - Required - The display name of the board. - **description** (string) - Optional - A description for the board. - **captcha** (string) - Required - The captcha solution. ### Request Example ```bash # Create a new board curl -X POST "https://your-instance.com/forms/create" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Cookie: connect.sid=your-session-cookie" \ -d "uri=myboard" \ -d "name=My Awesome Board" \ -d "description=A board for discussing awesome things" \ -d "captcha=CAPTCHA123" ``` ### Response #### Success Response (302 Redirect) Redirects to the newly created board's index page (e.g., `/myboard/index.html`). #### Response Example Redirects to: `/myboard/index.html` ``` -------------------------------- ### Create New Board (Bash) Source: https://context7.com/crisbon/jschan/llms.txt Allows logged-in users to create a new board with a unique URI, name, and description. Requires a session cookie and captcha. ```bash curl -X POST "https://your-instance.com/forms/create" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Cookie: connect.sid=your-session-cookie" \ -d "uri=myboard" \ -d "name=My Awesome Board" \ -d "description=A board for discussing awesome things" \ -d "captcha=CAPTCHA123" ``` -------------------------------- ### User Authentication and Registration (Bash) Source: https://context7.com/crisbon/jschan/llms.txt Handles user login, registration, and logout. Login supports optional two-factor authentication. Registration requires username, password, and captcha. Logout requires a session cookie. ```bash # Login to an account curl -X POST "https://your-instance.com/forms/login" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=myuser" \ -d "password=mypassword" \ -d "twofactor=123456" # Register a new account curl -X POST "https://your-instance.com/forms/register" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=newuser" \ -d "password=securepass" \ -d "passwordconfirm=securepass" \ -d "captcha=XYZ789" # Logout curl -X POST "https://your-instance.com/forms/logout" \ -H "Cookie: connect.sid=your-session-cookie" ``` -------------------------------- ### Run ESLint for Code Linting Source: https://github.com/crisbon/jschan/blob/master/CONTRIBUTING.md Commands to run ESLint for code style enforcement and issue detection across the entire project or specific directories/files. ```bash #whole project eslint ./ #specific directory/file eslint /path/to/whatever ``` -------------------------------- ### Create Post with File Upload (Bash) Source: https://context7.com/crisbon/jschan/llms.txt Creates a new thread or reply on a board using a POST request with multipart/form-data. Supports messages, file uploads, and post passwords. Requires a captcha. ```bash curl -X POST "https://your-instance.com/forms/board/b/post" \ -H "Content-Type: multipart/form-data" \ -F "message=Hello, this is my first post!" \ -F "name=Anonymous" \ -F "subject=New Thread" \ -F "file=@/path/to/image.jpg" \ -F "postpassword=secretpass123" \ -F "captcha=ABC123" ``` -------------------------------- ### Get Random Banner Source: https://context7.com/crisbon/jschan/llms.txt Retrieve a random banner for a specified board. This is a simple GET request and does not require authentication. ```bash curl "https://your-instance.com/randombanner?board=b" ``` -------------------------------- ### User Authentication API Source: https://context7.com/crisbon/jschan/llms.txt Handles user login, registration, and logout. Supports standard username/password authentication and optional two-factor authentication. ```APIDOC ## User Authentication Endpoints ### Login Authenticates a user with their credentials. #### Method POST #### Endpoint `/forms/login` #### Parameters ##### Request Body - **username** (string) - Required - The user's username. - **password** (string) - Required - The user's password. - **twofactor** (string) - Optional - The two-factor authentication code. ### Register Creates a new user account. #### Method POST #### Endpoint `/forms/register` #### Parameters ##### Request Body - **username** (string) - Required - The desired username. - **password** (string) - Required - The user's password. - **passwordconfirm** (string) - Required - Confirmation of the user's password. - **captcha** (string) - Required - The captcha solution. ### Logout Logs out the currently authenticated user. #### Method POST #### Endpoint `/forms/logout` #### Parameters ##### Request Body - **Cookie: connect.sid** (string) - Required - The user's session cookie. ### Request Example ```bash # Login to an account curl -X POST "https://your-instance.com/forms/login" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=myuser" \ -d "password=mypassword" \ -d "twofactor=123456" # Register a new account curl -X POST "https://your-instance.com/forms/register" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "username=newuser" \ -d "password=securepass" \ -d "passwordconfirm=securepass" \ -d "captcha=XYZ789" # Logout curl -X POST "https://your-instance.com/forms/logout" \ -H "Cookie: connect.sid=your-session-cookie" ``` ``` -------------------------------- ### Create a New Post Source: https://context7.com/crisbon/jschan/llms.txt Allows users to create new threads or reply to existing ones on a board. Supports file uploads, markdown, spoilers, and custom post options. ```APIDOC ## POST /forms/board/{boardUri}/post ### Description Creates a new thread or reply on a board. Supports file uploads, markdown formatting, and various post options like spoilers and custom flags. ### Method POST ### Endpoint `/forms/board/{boardUri}/post` ### Parameters #### Path Parameters - **boardUri** (string) - Required - The unique identifier for the board. #### Query Parameters None #### Request Body - **message** (string) - Optional - The content of the post, supports markdown. - **name** (string) - Optional - The name to display for the post (defaults to 'Anonymous'). - **subject** (string) - Optional - The subject of the thread. - **file** (file) - Optional - The file to upload with the post. - **postpassword** (string) - Optional - Password for post actions like deletion. - **captcha** (string) - Required - The captcha solution. - **thread** (integer) - Optional - The ID of the thread to reply to. If not provided, a new thread is created. - **spoiler** (string) - Optional - A hash or identifier for spoiler images. ### Request Example ```bash # Create a new thread with a message and file curl -X POST "https://your-instance.com/forms/board/b/post" \ -H "Content-Type: multipart/form-data" \ -F "message=Hello, this is my first post!" \ -F "name=Anonymous" \ -F "subject=New Thread" \ -F "file=@/path/to/image.jpg" \ -F "postpassword=secretpass123" \ -F "captcha=ABC123" # Reply to an existing thread curl -X POST "https://your-instance.com/forms/board/b/post" \ -H "Content-Type: multipart/form-data" \ -F "thread=12345" \ -F "message=>12340\nGreat post! I agree." \ -F "file=@/path/to/image.png" \ -F "spoiler=abc123sha256hash" \ -F "postpassword=mypassword" ``` ### Response #### Success Response (200) - **postId** (integer) - The ID of the newly created post. - **redirect** (string) - The URL to redirect to, typically the thread page with the new post. #### Response Example ```json { "postId": 12346, "redirect": "/b/thread/12345.html#12346" } ``` ``` -------------------------------- ### Banner and Asset Management Source: https://context7.com/crisbon/jschan/llms.txt Upload and manage board banners, flags, and assets. ```APIDOC ## POST /forms/board/b/upload_asset ### Description Uploads banners, flags, or other assets for a board. ### Method POST ### Endpoint /forms/board/b/upload_asset ### Parameters #### Query Parameters None #### Request Body - **asset** (file) - Required - The asset file to upload. - **asset_type** (string) - Required - The type of asset (e.g., 'banner', 'flag'). ### Request Example (This would typically involve multipart/form-data for file uploads, not a JSON body) ### Response #### Success Response (200) Returns a success message or redirect upon successful upload. #### Response Example (No specific JSON response example provided, often redirects or simple success message) ``` -------------------------------- ### Update Board Settings (Bash) Source: https://context7.com/crisbon/jschan/llms.txt Allows board owners or staff to update board settings such as name, description, theme, file limits, and moderation options. Requires a session cookie and CSRF token. ```bash curl -X POST "https://your-instance.com/forms/board/myboard/settings" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "name=Updated Board Name" \ -d "description=New description" \ -d "theme=dark" \ -d "captcha_mode=1" \ -d "max_files=3" \ -d "thread_limit=100" \ -d "reply_limit=500" \ -d "bump_limit=300" \ -d "force_anon=0" \ -d "ids=1" \ -d "geo_flags=1" ``` -------------------------------- ### Post Actions: Delete, Report, Spoiler (Bash) Source: https://context7.com/crisbon/jschan/llms.txt Performs actions on posts, including deletion (requires password), reporting (with optional reason), global reporting, and marking files as spoilers. Requires captcha. ```bash # Delete own posts (requires password) curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "checkedposts=12346" \ -d "delete=1" \ -d "postpassword=mypassword" \ -d "captcha=ABC123" # Report a post curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "report=1" \ -d "report_reason=Spam content" \ -d "captcha=XYZ789" # Global report curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "global_report=1" \ -d "report_reason=Illegal content" \ -d "captcha=ABC123" # Spoiler files (user action) curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "spoiler=1" \ -d "postpassword=mypassword" \ -d "captcha=DEF456" ``` -------------------------------- ### Post Actions API Source: https://context7.com/crisbon/jschan/llms.txt Provides endpoints for performing various actions on posts, including deletion, reporting, and marking files as spoilers. ```APIDOC ## POST /forms/board/{boardUri}/actions ### Description Perform actions on posts including deletion, reporting, spoilering files, and moderation actions. ### Method POST ### Endpoint `/forms/board/{boardUri}/actions` ### Parameters #### Path Parameters - **boardUri** (string) - Required - The unique identifier for the board. #### Query Parameters None #### Request Body - **checkedposts** (integer) - Required - One or more post IDs to perform the action on. - **delete** (integer) - Optional - Set to 1 to delete the selected posts. - **postpassword** (string) - Required if deleting own posts - The password for the post. - **report** (integer) - Optional - Set to 1 to report the selected posts. - **report_reason** (string) - Required if reporting - The reason for the report. - **global_report** (integer) - Optional - Set to 1 for a global report (requires higher privileges). - **spoiler** (integer) - Optional - Set to 1 to mark files of selected posts as spoilers. - **captcha** (string) - Required - The captcha solution. ### Request Example ```bash # Delete own posts (requires password) curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "checkedposts=12346" \ -d "delete=1" \ -d "postpassword=mypassword" \ -d "captcha=ABC123" # Report a post curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "report=1" \ -d "report_reason=Spam content" \ -d "captcha=XYZ789" # Global report curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "global_report=1" \ -d "report_reason=Illegal content" \ -d "captcha=ABC123" # Spoiler files (user action) curl -X POST "https://your-instance.com/forms/board/b/actions" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "checkedposts=12345" \ -d "spoiler=1" \ -d "postpassword=mypassword" \ -d "captcha=DEF456" ``` ### Response #### Success Response (200) Typically returns a redirect to the board page or a success message. Specific response details may vary based on the action performed. #### Response Example (No specific JSON response example provided in source, often a redirect) ``` -------------------------------- ### Two-Factor Authentication API Source: https://context7.com/crisbon/jschan/llms.txt APIs for setting up, enabling, and disabling TOTP-based two-factor authentication for accounts. ```APIDOC ## GET /twofactor.html ### Description Initiates the setup process for two-factor authentication and returns a QR code for the user to scan with their authenticator app. ### Method GET ### Endpoint /twofactor.html ### Request Example ```bash curl "https://your-instance.com/twofactor.html" \ -H "Cookie: connect.sid=your-session-cookie" ``` ## POST /forms/twofactor (Enable 2FA) ### Description Enables two-factor authentication for the account after the user has scanned the QR code and entered the verification code. ### Method POST ### Endpoint /forms/twofactor ### Parameters #### Form Data - **twofactor** (string) - Required - The TOTP code generated by the user's authenticator app. ### Request Example ```bash curl -X POST "https://your-instance.com/forms/twofactor" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "twofactor=123456" ``` ## POST /forms/twofactor (Disable 2FA) ### Description Disables two-factor authentication for the account. Requires the current TOTP code and a disable flag. ### Method POST ### Endpoint /forms/twofactor ### Parameters #### Form Data - **twofactor** (string) - Required - The TOTP code generated by the user's authenticator app. - **disable** (integer) - Required - Set to '1' to disable two-factor authentication. ### Request Example ```bash curl -X POST "https://your-instance.com/forms/twofactor" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "twofactor=654321" \ -d "disable=1" ``` ``` -------------------------------- ### Board Settings API Source: https://context7.com/crisbon/jschan/llms.txt Allows board owners or moderators to update the settings of a specific board. ```APIDOC ## POST /forms/board/{boardUri}/settings ### Description Update board settings as a board owner or staff member with appropriate permissions. ### Method POST ### Endpoint `/forms/board/{boardUri}/settings` ### Parameters #### Path Parameters - **boardUri** (string) - Required - The unique identifier for the board. #### Query Parameters None #### Request Body - **name** (string) - Optional - The new display name for the board. - **description** (string) - Optional - The new description for the board. - **theme** (string) - Optional - The theme to apply to the board (e.g., 'dark'). - **captcha_mode** (integer) - Optional - The captcha mode (e.g., 0=off, 1=on). - **max_files** (integer) - Optional - Maximum number of files allowed per post. - **thread_limit** (integer) - Optional - Limit for the number of threads on the board. - **reply_limit** (integer) - Optional - Limit for the number of replies per thread. - **bump_limit** (integer) - Optional - Limit for thread bumps. - **force_anon** (integer) - Optional - Whether to force anonymous posting (0=no, 1=yes). - **ids** (integer) - Optional - Whether to display post IDs (0=no, 1=yes). - **geo_flags** (integer) - Optional - Whether to display geo flags (0=no, 1=yes). - **lock_mode** (integer) - Optional - Board lock status (0=unlocked, 1=thread creation locked, 2=board locked). - **Cookie: connect.sid** (string) - Required - The user's session cookie. - **X-CSRF-Token** (string) - Required - The CSRF token for the request. ### Request Example ```bash # Update board settings curl -X POST "https://your-instance.com/forms/board/myboard/settings" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "name=Updated Board Name" \ -d "description=New description" \ -d "theme=dark" \ -d "captcha_mode=1" \ -d "max_files=3" \ -d "thread_limit=100" \ -d "reply_limit=500" \ -d "bump_limit=300" \ -d "force_anon=0" \ -d "ids=1" \ -d "geo_flags=1" ``` ### Response #### Success Response (200) Typically returns a redirect to the board's settings page or a success message. Specific response details may vary. #### Response Example (No specific JSON response example provided in source, often a redirect) ``` -------------------------------- ### Staff Management API Source: https://context7.com/crisbon/jschan/llms.txt APIs for managing staff members on a board, including adding, editing permissions, and removing staff. ```APIDOC ## POST /forms/board/myboard/addstaff ### Description Adds a new staff member to a board. ### Method POST ### Endpoint /forms/board/myboard/addstaff ### Parameters #### Form Data - **username** (string) - Required - The username of the staff member to add. ### Request Example ```bash curl -X POST "https://your-instance.com/forms/board/myboard/addstaff" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "username=newmod" ``` ## POST /forms/board/myboard/editstaff ### Description Edits the permissions for an existing staff member on a board. ### Method POST ### Endpoint /forms/board/myboard/editstaff ### Parameters #### Form Data - **username** (string) - Required - The username of the staff member to edit. - **MANAGE_BOARD_BANS** (integer) - Optional - Set to '1' to grant ban management permissions. - **MANAGE_BOARD_LOGS** (integer) - Optional - Set to '1' to grant log management permissions. ### Request Example ```bash curl -X POST "https://your-instance.com/forms/board/myboard/editstaff" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "username=existingmod" \ -d "MANAGE_BOARD_BANS=1" \ -d "MANAGE_BOARD_LOGS=1" ``` ## POST /forms/board/myboard/deletestaff ### Description Removes a staff member from a board. ### Method POST ### Endpoint /forms/board/myboard/deletestaff ### Parameters #### Form Data - **checkedstaff** (string) - Required - The username of the staff member to remove. ### Request Example ```bash curl -X POST "https://your-instance.com/forms/board/myboard/deletestaff" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "checkedstaff=oldmod" ``` ## POST /forms/board/myboard/transfer ### Description Transfers ownership of a board to another user. ### Method POST ### Endpoint /forms/board/myboard/transfer ### Parameters #### Form Data - **username** (string) - Required - The username of the new owner. ### Request Example ```bash curl -X POST "https://your-instance.com/forms/board/myboard/transfer" \ -H "Cookie: connect.sid=your-session-cookie" \ -H "X-CSRF-Token: your-csrf-token" \ -d "username=newowner" ``` ``` -------------------------------- ### WebSocket Real-time Updates Source: https://context7.com/crisbon/jschan/llms.txt Connect to WebSocket for live thread updates and management notifications. ```APIDOC ## WebSocket Connection ### Description Establishes a WebSocket connection for real-time updates on posts and management events. ### Endpoint `wss://your-instance.com` (or similar WebSocket endpoint) ### Events #### Client Emits - **room** (string): Joins a specific room. Format: `b-{boardId}-{threadId}` for threads, `b-manage-recent-hashed` for board management, `globalmanage-recent-hashed` for global management. - **ping** (function): Sends a ping to keep the connection alive. #### Server Emits - **joined** (): Emitted when the client successfully joins a room. - **newPost** (object): Emitted when a new post is made in a subscribed thread. The object contains post details like `postId`, `message`, `files`, `name`, `date`, etc. - **Pong** (): Response to a client 'ping'. ### Client-side Example (JavaScript) ```javascript const socket = io('https://your-instance.com'); socket.emit('room', 'b-12345'); // Join a thread room socket.on('joined', () => { console.log('Joined thread room'); }); socket.on('newPost', (post) => { console.log('New post:', post); }); socket.emit('room', 'b-manage-recent-hashed'); // Join management room socket.emit('ping', () => { console.log('Pong received'); }); ``` ``` -------------------------------- ### WebSocket Real-time Updates using JavaScript Source: https://context7.com/crisbon/jschan/llms.txt Establishes a WebSocket connection for real-time updates on new posts and management notifications. Clients can join specific rooms for threads or management events and listen for incoming data. ```javascript // Client-side WebSocket connection for live updates const socket = io('https://your-instance.com'); // Join a thread room for live posts socket.emit('room', 'b-12345'); // board-threadId format socket.on('joined', () => { console.log('Joined thread room'); }); // Listen for new posts socket.on('newPost', (post) => { console.log('New post:', post); // post contains: postId, message, files, name, date, etc. }); // For moderators - join manage rooms socket.emit('room', 'b-manage-recent-hashed'); // Board management socket.emit('room', 'globalmanage-recent-hashed'); // Global management // Ping to keep connection alive socket.emit('ping', () => { console.log('Pong received'); }); ```