Merge branch 'deffcolony:master' into master

This commit is contained in:
Alex 2025-04-22 02:07:50 +00:00 committed by GitHub
commit b30232f773
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 225 additions and 92 deletions

View File

@ -10,19 +10,50 @@ INSTANCE=0
# SSL_KEY_PATH=/path/to/key.pem
# PHP Service Settings
VICHAN_MYSQL__HOST=db
VICHAN_MYSQL__USER=vichan
VICHAN_MYSQL__NAME=vichan
VICHAN_MYSQL__PASSWORD=vichan!
## Database settings
VICHAN_MYSQL_HOST=db
VICHAN_MYSQL_USER=vichan
VICHAN_MYSQL_NAME=vichan
VICHAN_MYSQL_PASSWORD=vichan!
## Security
VICHAN_SECURE_LOGIN_ONLY=0
# Redis Settings
VICHAN_REDIS_HOST=redis
VICHAN_REDIS_PORT=6379
VICHAN_REDIS_PASSWORD=redis!
## Cookies
VICHAN_COOKIES_MOD=mod
## Flood Control
VICHAN_FLOOD_TIME=30
VICHAN_FLOOD_TIME_IP=120
VICHAN_FLOOD_TIME_SAME=3600
VICHAN_MAX_BODY=1800
VICHAN_REPLY_LIMIT=250
VICHAN_MAX_LINKS=20
## Images
VICHAN_IMAGES_MAX_FILESIZE=10485760
VICHAN_IMAGES_THUMB_WIDTH=250
VICHAN_IMAGES_THUMB_HEIGHT=250
VICHAN_IMAGES_MAX_WIDTH=10000
VICHAN_IMAGES_MAX_HEIGHT=10000
## Display
VICHAN_DISPLAY_THREADS_PER_PAGE=10
VICHAN_DISPLAY_MAX_PAGES=11
VICHAN_DISPLAY_THREADS_PREVIEW=5
## Directories
VICHAN_DIRECTORIES_ROOT=/
# Database Service (MariaDB) Settings
MYSQL_DATABASE=vichan
MYSQL_USER=vichan
MYSQL_PASSWORD=vichan!
MYSQL_ROOT_PASSWORD=vichan!!
# Redis
VICHAN_REDIS_HOST=redis
VICHAN_REDIS_PORT=6379
VICHAN_REDIS_PASSWORD=redis!

View File

@ -32,14 +32,38 @@ services:
- ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini
- ./docker/php/php.ini:/usr/local/etc/php/php.ini
environment:
VICHAN_MYSQL__HOST: ${VICHAN_MYSQL__HOST}
VICHAN_MYSQL__USER: ${VICHAN_MYSQL__USER}
VICHAN_MYSQL__NAME: ${VICHAN_MYSQL__NAME}
VICHAN_MYSQL__PASSWORD: ${VICHAN_MYSQL__PASSWORD}
# Database settings
VICHAN_MYSQL_HOST: ${VICHAN_MYSQL_HOST}
VICHAN_MYSQL_USER: ${VICHAN_MYSQL_USER}
VICHAN_MYSQL_NAME: ${VICHAN_MYSQL_NAME}
VICHAN_MYSQL_PASSWORD: ${VICHAN_MYSQL_PASSWORD}
# Security
VICHAN_SECURE_LOGIN_ONLY: ${VICHAN_SECURE_LOGIN_ONLY}
# Redis settings
VICHAN_REDIS_HOST: ${VICHAN_REDIS_HOST}
VICHAN_REDIS_PORT: ${VICHAN_REDIS_PORT}
VICHAN_REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
# Cookies
VICHAN_COOKIES_MOD: ${VICHAN_COOKIES_MOD}
# Flood Control
VICHAN_FLOOD_TIME: ${VICHAN_FLOOD_TIME}
VICHAN_FLOOD_TIME_IP: ${VICHAN_FLOOD_TIME_IP}
VICHAN_FLOOD_TIME_SAME: ${VICHAN_FLOOD_TIME_SAME}
VICHAN_MAX_BODY: ${VICHAN_MAX_BODY}
VICHAN_REPLY_LIMIT: ${VICHAN_REPLY_LIMIT}
VICHAN_MAX_LINKS: ${VICHAN_MAX_LINKS}
# Images
VICHAN_IMAGES_MAX_FILESIZE: ${VICHAN_IMAGES_MAX_FILESIZE}
VICHAN_IMAGES_THUMB_WIDTH: ${VICHAN_IMAGES_THUMB_WIDTH}
VICHAN_IMAGES_THUMB_HEIGHT: ${VICHAN_IMAGES_THUMB_HEIGHT}
VICHAN_IMAGES_MAX_WIDTH: ${VICHAN_IMAGES_MAX_WIDTH}
VICHAN_IMAGES_MAX_HEIGHT: ${VICHAN_IMAGES_MAX_HEIGHT}
# Display
VICHAN_DISPLAY_THREADS_PER_PAGE: ${VICHAN_DISPLAY_THREADS_PER_PAGE}
VICHAN_DISPLAY_MAX_PAGES: ${VICHAN_DISPLAY_MAX_PAGES}
VICHAN_DISPLAY_THREADS_PREVIEW: ${VICHAN_DISPLAY_THREADS_PREVIEW}
# Directories
VICHAN_DIRECTORIES_ROOT: ${VICHAN_DIRECTORIES_ROOT}
depends_on:
- db
@ -61,6 +85,8 @@ services:
image: redis:latest
container_name: vichan_redis
restart: unless-stopped
environment:
REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
volumes:
- ./local-instances/${INSTANCE:-0}/redis:/data
command: redis-server --requirepass ${VICHAN_REDIS_PASSWORD}

View File

@ -1,20 +1,63 @@
# Vichan Docker Setup
The `php-fpm` process runs containerized.
The php application always uses `/var/www` as it's work directory and home folder, and if `/var/www` is bind mounted it
is necessary to adjust the path passed via FastCGI to `php-fpm` by changing the root directory to `/var/www`.
This can achieved in nginx by setting the `fastcgi_param SCRIPT_FILENAME` to `/var/www/$fastcgi_script_name;`
The PHP application always uses `/var/www` as its work directory and home folder. If `/var/www` is bind mounted, you must adjust the path passed via FastCGI to `php-fpm`.
The default docker compose settings are intended for development and testing purposes.
The folder structure expected by compose is as follows
To fix this:
1. **Adjust the root path**: Set `fastcgi_param SCRIPT_FILENAME` to `/var/www/$fastcgi_script_name;` in your nginx config.
The default Docker Compose settings are meant for development and testing.
Expected folder structure:
```
<vichan-project>
└── local-instances
└── 1
├── mysql
├── db
└── www
```
The vichan container is by itself much less rigid.
To run the app:
1. **Start all containers**: Run `docker compose up -d --build` at the root of vichan directory
2. **Rebuild just the PHP container**: Run `docker compose up -d --build php` (useful during development)
Use `docker compose up --build` to start the docker compose.
Use `docker compose up --build -d php` to rebuild just the vichan container while the compose is running. Useful for development.
---
## PHP File Size Limit
To upload larger files, increase the default PHP file size limit (2MB). Since this setup uses Docker, follow these steps:
1. **Open the config file**: Edit `./docker/php/php.ini` in your project directory.
2. **Add or update these lines** to increase the file size limit to 10MB:
```ini
upload_max_filesize = 10M
post_max_size = 10M
```
3. **Restart your containers** to apply the changes:
```bash
docker compose restart
```
---
By default, PHP limits file uploads to **2MB** — so increasing this is often required when uploading images or documents.
---
## Using the `.env` File
Environment variables for the Docker Compose setup can be managed easily using a `.env` file.
### Steps to Use It:
1. **Copy the example**: Start by copying `.env.example` to `.env`
```bash
cp .env.example .env
```
2. **Edit `.env`**: Please make sure to change the default passwords for your setup.
### What It Controls:
- Instance folder reference (e.g. `local-instances/0`)
- Database credentials
- Redis connection details
- Secure login
- Optional SSL certificate paths for nginx

View File

@ -137,44 +137,43 @@
* ====================
*/
/*
* On top of the static file caching system, you can enable the additional caching system which is
* designed to minimize request processing can significantly increase speed when posting or using
* the moderator interface.
*
* https://github.com/vichan-devel/vichan/wiki/cache
*/
// Determine if Redis is configured via environment variables
$redis_enabled = getenv('VICHAN_REDIS_HOST') !== false && getenv('VICHAN_REDIS_PORT') !== false;
// Uses a PHP array. MUST NOT be used in multiprocess environments.
$config['cache']['enabled'] = 'php';
// The recommended in-memory method of caching. Requires the extension. Due to how APCu works, this should be
// disabled when you run tools from the cli.
// $config['cache']['enabled'] = 'apcu';
// The Memcache server. Requires the memcached extension, with a final D.
// $config['cache']['enabled'] = 'memcached';
// The Redis server. Requires the extension.
// $config['cache']['enabled'] = 'redis';
// Use the local cache folder. Slower than native but available out of the box and compatible with multiprocess
// environments. You can mount a ram-based filesystem in the cache directory to improve performance.
// $config['cache']['enabled'] = 'fs';
// Technically available, offers a no-op fake cache. Don't use this outside of testing or debugging.
// $config['cache']['enabled'] = 'none';
// Configure cache
if ($redis_enabled) {
$config['cache']['enabled'] = 'redis';
$config['cache']['redis'] = [
'host' => getenv('VICHAN_REDIS_HOST') ?: 'localhost',
'port' => (int)(getenv('VICHAN_REDIS_PORT') ?: 6379),
'password' => getenv('VICHAN_REDIS_PASSWORD') ?: '',
'database' => 1,
];
} else {
$config['cache']['enabled'] = 'php';
}
// Timeout for cached objects such as posts and HTML.
// Configure sessions to use Redis if enabled
if ($redis_enabled) {
$config['session']['enabled'] = 'redis';
$config['session']['redis'] = [
'host' => getenv('VICHAN_REDIS_HOST') ?: 'localhost',
'port' => (int)(getenv('VICHAN_REDIS_PORT') ?: 6379),
'password' => getenv('VICHAN_REDIS_PASSWORD') ?: '',
'database' => 1,
];
}
// Cache timeout for cached objects
$config['cache']['timeout'] = 60 * 60 * 48; // 48 hours
// Optional prefix if you're running multiple vichan instances on the same machine.
// Optional prefix for multiple vichan instances
$config['cache']['prefix'] = '';
// Memcached servers to use. Read more: http://www.php.net/manual/en/memcached.addservers.php
$config['cache']['memcached'] = array(
array('localhost', 11211)
);
// Redis server to use. Location, port, password, database id.
// Note that vichan may clear the database at times, so you may want to pick a database id just for
// vichan to use.
$config['cache']['redis'] = array('localhost', 6379, '', 1);
// Memcached servers (not used)
$config['cache']['memcached'] = [
['localhost', 11211]
];
// EXPERIMENTAL: Should we cache configs? Warning: this changes board behaviour, i'd say, a lot.
// If you have any lambdas/includes present in your config, you should move them to instance-functions.php

View File

@ -916,30 +916,62 @@ if ($step == 0) {
} elseif ($step == 2) {
$page['title'] = 'Configuration';
$sg = new SaltGen();
$config['cookies']['salt'] = $sg->generate();
// Initialize configuration with defaults and override with environment variables
$config['cookies'] = array(
'mod' => getenv('VICHAN_COOKIES_MOD') !== false ? getenv('VICHAN_COOKIES_MOD') : 'mod',
'salt' => $sg->generate(),
);
$config['flood_time'] = getenv('VICHAN_FLOOD_TIME') !== false ? (int)getenv('VICHAN_FLOOD_TIME') : 30;
$config['flood_time_ip'] = getenv('VICHAN_FLOOD_TIME_IP') !== false ? (int)getenv('VICHAN_FLOOD_TIME_IP') : 120;
$config['flood_time_same'] = getenv('VICHAN_FLOOD_TIME_SAME') !== false ? (int)getenv('VICHAN_FLOOD_TIME_SAME') : 3600;
$config['max_body'] = getenv('VICHAN_MAX_BODY') !== false ? (int)getenv('VICHAN_MAX_BODY') : 1800;
$config['reply_limit'] = getenv('VICHAN_REPLY_LIMIT') !== false ? (int)getenv('VICHAN_REPLY_LIMIT') : 250;
$config['max_links'] = getenv('VICHAN_MAX_LINKS') !== false ? (int)getenv('VICHAN_MAX_LINKS') : 20;
$config['max_filesize'] = getenv('VICHAN_IMAGES_MAX_FILESIZE') !== false ? (int)getenv('VICHAN_IMAGES_MAX_FILESIZE') : 10485760; // This is 10MB
$config['thumb_width'] = getenv('VICHAN_IMAGES_THUMB_WIDTH') !== false ? (int)getenv('VICHAN_IMAGES_THUMB_WIDTH') : 250;
$config['thumb_height'] = getenv('VICHAN_IMAGES_THUMB_HEIGHT') !== false ? (int)getenv('VICHAN_IMAGES_THUMB_HEIGHT') : 250;
$config['max_width'] = getenv('VICHAN_IMAGES_MAX_WIDTH') !== false ? (int)getenv('VICHAN_IMAGES_MAX_WIDTH') : 10000;
$config['max_height'] = getenv('VICHAN_IMAGES_MAX_HEIGHT') !== false ? (int)getenv('VICHAN_IMAGES_MAX_HEIGHT') : 10000;
$config['threads_per_page'] = getenv('VICHAN_DISPLAY_THREADS_PER_PAGE') !== false ? (int)getenv('VICHAN_DISPLAY_THREADS_PER_PAGE') : 10;
$config['max_pages'] = getenv('VICHAN_DISPLAY_MAX_PAGES') !== false ? (int)getenv('VICHAN_DISPLAY_MAX_PAGES') : 11;
$config['threads_preview'] = getenv('VICHAN_DISPLAY_THREADS_PREVIEW') !== false ? (int)getenv('VICHAN_DISPLAY_THREADS_PREVIEW') : 5;
$config['root'] = getenv('VICHAN_DIRECTORIES_ROOT') !== false ? getenv('VICHAN_DIRECTORIES_ROOT') : '/';
$config['secure_trip_salt'] = $sg->generate();
$config['secure_password_salt'] = $sg->generate();
// Set database configuration from Docker environment variables, leave empty if not found
$config['db'] = array(
'type' => 'mysql', // Default, required for MySQL
'server' => getenv('VICHAN_MYSQL__HOST') !== false ? getenv('VICHAN_MYSQL__HOST') : '',
'database' => getenv('VICHAN_MYSQL__NAME') !== false ? getenv('VICHAN_MYSQL__NAME') : '',
'user' => getenv('VICHAN_MYSQL__USER') !== false ? getenv('VICHAN_MYSQL__USER') : '',
'password' => getenv('VICHAN_MYSQL__PASSWORD') !== false ? getenv('VICHAN_MYSQL__PASSWORD') : '',
'server' => getenv('VICHAN_MYSQL_HOST') !== false ? getenv('VICHAN_MYSQL_HOST') : '',
'database' => getenv('VICHAN_MYSQL_NAME') !== false ? getenv('VICHAN_MYSQL_NAME') : '',
'user' => getenv('VICHAN_MYSQL_USER') !== false ? getenv('VICHAN_MYSQL_USER') : '',
'password' => getenv('VICHAN_MYSQL_PASSWORD') !== false ? getenv('VICHAN_MYSQL_PASSWORD') : '',
);
// Append secure_login_only to $_SESSION['more'] if VICHAN_SECURE_LOGIN_ONLY is set from Docker environment variables
// Append secure_login_only to $_SESSION['more'] if VICHAN_SECURE_LOGIN_ONLY is set
if (getenv('VICHAN_SECURE_LOGIN_ONLY') !== false) {
$secure_login_only = (int)getenv('VICHAN_SECURE_LOGIN_ONLY');
$_SESSION['more'] .= "\n\$config['cookies']['secure_login_only'] = $secure_login_only;";
}
// Configuration notice at the top
$page['body'] = '<div class="ban"><h2>Configuration Note</h2>' .
'<p style="text-align:center;">The following settings can still be configured later. For more customization options, <a href="https://github.com/vichan-devel/vichan/wiki/config" target="_blank" rel="noopener noreferrer">check the Vichan configuration wiki.</a></p></div>';
// Append the configuration form
$page['body'] .= Element('installer/config.html', array(
'config' => $config,
'more' => $_SESSION['more'],
));
echo Element('page.html', array(
'body' => Element('installer/config.html', array(
'config' => $config,
'more' => $_SESSION['more'],
)),
'body' => $page['body'],
'title' => 'Configuration',
'config' => $config
));
@ -1014,14 +1046,18 @@ if ($step == 0) {
}
$page['title'] = 'Installation complete';
$page['body'] = '<p style="text-align:center">Thank you for installing vichan. Please report any bugs you discover. <a href="https://github.com/vichan-devel/vichan/wiki/Configuration-Basics">How do I edit the config files?</a></p>';
$page['body'] = '<p style="text-align:center">Thank you for using vichan. <a href="https://github.com/vichan-devel/vichan/issues/new/choose" target="_blank" rel="noopener noreferrer">Please report any bugs you discover.</a></p>' .
'<p style="text-align:center">If you are new to vichan, <a href="https://github.com/vichan-devel/vichan/wiki" target="_blank" rel="noopener noreferrer">please check out the documentation.</a></p>';
// notice and button
// Admin panel notice
$page['body'] .= '<div class="ban"><h2>Next Steps</h2>' .
'<p>You can now log in to the admin panel at <strong>/mod.php</strong> using the default credentials: <strong>Username: admin</strong>, <strong>Password: password</strong>.</p>' .
'<p>You can now log in to the admin panel at <strong>/mod.php</strong> using the default credentials:</p>' .
'<p><strong>Username:</strong> admin</p>' .
'<p><strong>Password:</strong> password</p>' .
'<p><strong>Important:</strong> For security, please change the administrator password immediately after logging in.</p>' .
'<p style="text-align:center"><button onclick="window.location.href=\'/mod.php\'">Go to Admin Panel</button></p></div>';
if (!empty($sql_errors)) {
$page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>SQL errors were encountered when trying to install the database. This may be the result of using a database which is already occupied with a vichan installation; if so, you can probably ignore this.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul>' .
'<p style="text-align:center;color:#d00"><strong>Warning:</strong> Ignoring errors is not recommended and may cause installation issues.</p>' .
@ -1042,18 +1078,18 @@ if ($step == 0) {
echo Element('page.html', $page);
} elseif ($step == 5) {
$page['title'] = 'Installation complete';
$page['body'] = '<p style="text-align:center">Thank you for installing vichan. Please report any bugs you discover.</p>';
$page['body'] = '<p style="text-align:center">Thank you for using vichan. Please report any bugs you discover.</p>' .
'<p style="text-align:center">If you are new to vichan, <a href="https://github.com/vichan-devel/vichan/wiki">please check out the documentation</a>.</p>';
// onboarding notice and button to mod.php
// Admin panel notice
$page['body'] .= '<div class="ban"><h2>Next Steps</h2>' .
'<p>You can now log in to the admin panel at <strong>/mod.php</strong> using the default credentials:</p>' .
'<ul>' .
'<li><strong>Username:</strong> admin</li>' .
'<li><strong>Password:</strong> password</li>' .
'</ul>' .
'<p><strong>Username:</strong> admin</p>' .
'<p><strong>Password:</strong> password</p>' .
'<p><strong>Important:</strong> For security, please change the administrator password immediately after logging in.</p>' .
'<p style="text-align:center"><button onclick="window.location.href=\'/mod.php\'">Go to Admin Panel</button></p></div>';
$boards = listBoards();
foreach ($boards as &$_board) {
setupBoard($_board);

View File

@ -15,9 +15,6 @@
<label for="db_pass">Password:</label>
<input type="password" id="db_pass" name="db[password]" value="{{ config.db.password }}">
</fieldset>
<p style="text-align:center" class="unimportant">The following is all later configurable. For more options, <a href="http://tinyboard.org/docs/?p=Config">edit your configuration files</a> after installing.</p>
<fieldset>
<legend>Cookies</legend>
<label for="cookies_mod">Moderator cookie:</label>
<input type="text" id="cookies_mod" name="cookies[mod]" value="{{ config.cookies.mod }}">
@ -52,34 +49,35 @@
<label for="max_filesize">Maximum image filesize (bytes):</label>
<input type="text" id="max_filesize" name="max_filesize" value="{{ config.max_filesize }}">
<div class="expandable">
<legend>PHP file size limit</legend>
<legend>PHP File Size Limit</legend>
<div class="body">
<p>The php file size limit can be configured in php.ini ( /usr/local/etc/php/php.ini )</p>
<p>Configure the PHP file size limit in the <code>php.ini</code> file. If it doesn't exist, create one.</p>
<div class="expandable">
<legend>Using docker</legend>
<legend>Using Docker</legend>
<div class="body">
<p>if you have pulled this from <a href="https://github.com/vichan-devel/vichan">GitHub</a></p>
<p>Then you can set the file size limit at ./docker/php/php.ini</p>
<p>For example, to set the limit to 10MB, add the following lines:</p>
<p>Edit or create <code>./vichan/docker/php/php.ini</code> in the project root.</p>
<p>To set the limit to 10MB, add:</p>
<pre>
upload_max_filesize = 10M
post_max_size = 10M</pre>
upload_max_filesize = 10M
post_max_size = 10M
</pre>
<p>Then restart the containers.</p>
</div>
</div>
<div class="expandable">
<legend>Manual Configuration</legend>
<div class="body">
<p>If you are not using docker, you can set the file size limit in the php.ini file:</p>
<p>For example, to set the limit to 10MB, add the following lines:</p>
<p>Edit or create <code>/usr/local/etc/php/php.ini</code>.</p>
<p>To set the limit to 10MB, add:</p>
<pre>
upload_max_filesize = 10M
post_max_size = 10M</pre>
upload_max_filesize = 10M
post_max_size = 10M
</pre>
<p>Then restart the PHP server.</p>
</div>
</div>
<hr>
<p>If this is not set, the default value is 2MB.</p>
<p>Default limit is 2MB if not set.</p>
</div>
</div>
<label for="thumb_width">Thumbnail width:</label>