From d3f36e48f7b5faec52782506f956cf7b1a288b72 Mon Sep 17 00:00:00 2001
From: deffcolony <61471128+deffcolony@users.noreply.github.com>
Date: Sun, 20 Apr 2025 22:46:12 +0200
Subject: [PATCH 01/34] Enhance Docker setup and installation process
- Updated Docker Compose configuration for web, PHP, and database services.
- Added Redis service with health checks and environment variables.
- Improved error handling and user prompts in installation scripts.
- Introduced example environment variables for easier configuration.
- Updated Nginx and PHP Docker images to latest versions.
---
.env.example | 28 +++
compose.yml | 57 +++++--
docker/nginx/Dockerfile | 2 +-
docker/php/Dockerfile | 2 +-
inc/Data/Driver/RedisCacheDriver.php | 109 +++++++-----
install.php | 178 +++++++++++---------
templates/installer/check-requirements.html | 111 ++++++------
templates/installer/config.html | 2 +-
8 files changed, 301 insertions(+), 188 deletions(-)
create mode 100644 .env.example
diff --git a/.env.example b/.env.example
new file mode 100644
index 00000000..122a244f
--- /dev/null
+++ b/.env.example
@@ -0,0 +1,28 @@
+# Example environment variables for the vichan imageboard Docker Compose setup.
+# Copy this file to `.env` and customize values as needed.
+# Do not commit `.env` with sensitive data to version control.
+
+# General Settings
+INSTANCE=0
+
+# Web Service (Nginx) Settings
+# SSL_CERT_PATH=/path/to/cert.pem
+# 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!
+VICHAN_SECURE_LOGIN_ONLY=0
+
+# Redis Settings
+VICHAN_REDIS_HOST=redis
+VICHAN_REDIS_PORT=6379
+VICHAN_REDIS_PASSWORD=redis!
+
+# Database Service (MariaDB) Settings
+MYSQL_DATABASE=vichan
+MYSQL_USER=vichan
+MYSQL_PASSWORD=vichan!
+MYSQL_ROOT_PASSWORD=vichan!!
\ No newline at end of file
diff --git a/compose.yml b/compose.yml
index 4b87e0b6..0480a33b 100644
--- a/compose.yml
+++ b/compose.yml
@@ -1,18 +1,22 @@
services:
- #nginx webserver + php 8.x
web:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
+ container_name: vichan_frontend
+ restart: unless-stopped
ports:
- "9090:80"
+# - "9092:443" # optional for SSL
depends_on:
- db
+ - php
volumes:
- ./local-instances/${INSTANCE:-0}/www:/var/www/html
- ./docker/nginx/vichan.conf:/etc/nginx/conf.d/default.conf
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/proxy.conf:/etc/nginx/conf.d/proxy.conf
+# - ./docker/nginx/ssl:/etc/nginx/ssl # optional For SSL
links:
- php
@@ -20,21 +24,48 @@ services:
build:
context: .
dockerfile: ./docker/php/Dockerfile
+ container_name: vichan_php
+ restart: unless-stopped
volumes:
- ./local-instances/${INSTANCE:-0}/www:/var/www
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./docker/php/jit.ini:/usr/local/etc/php/conf.d/jit.ini
-
- #MySQL Service
- db:
- image: mysql:8.0.35
- container_name: db
- restart: unless-stopped
- tty: true
- ports:
- - "3306:3306"
environment:
- MYSQL_DATABASE: vichan
- MYSQL_ROOT_PASSWORD: password
+ VICHAN_MYSQL__HOST: ${VICHAN_MYSQL__HOST}
+ VICHAN_MYSQL__USER: ${VICHAN_MYSQL__USER}
+ VICHAN_MYSQL__NAME: ${VICHAN_MYSQL__NAME}
+ VICHAN_MYSQL__PASSWORD: ${VICHAN_MYSQL__PASSWORD}
+ VICHAN_SECURE_LOGIN_ONLY: ${VICHAN_SECURE_LOGIN_ONLY}
+ VICHAN_REDIS_HOST: ${VICHAN_REDIS_HOST}
+ VICHAN_REDIS_PORT: ${VICHAN_REDIS_PORT}
+ VICHAN_REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
+ depends_on:
+ - db
+
+ db:
+ image: mariadb:latest
+ container_name: vichan_mariadb
+ restart: unless-stopped
+ ports:
+ - "9091:3306"
+ environment:
+ MYSQL_DATABASE: ${MYSQL_DATABASE}
+ MYSQL_USER: ${MYSQL_USER}
+ MYSQL_PASSWORD: ${MYSQL_PASSWORD}
+ MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- - ./local-instances/${INSTANCE:-0}/mysql:/var/lib/mysql
+ - ./local-instances/${INSTANCE:-0}/db:/var/lib/mysql
+
+ redis:
+ image: redis:latest
+ container_name: vichan_redis
+ restart: unless-stopped
+ volumes:
+ - ./local-instances/${INSTANCE:-0}/redis:/data
+ command: redis-server --requirepass ${VICHAN_REDIS_PASSWORD}
+ healthcheck:
+ test: ["CMD", "redis-cli", "-a", "${VICHAN_REDIS_PASSWORD}", "ping"]
+ interval: 10s
+ timeout: 5s
+ retries: 5
+ start_period: 30s
\ No newline at end of file
diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile
index d9d4bcc4..6ddce075 100644
--- a/docker/nginx/Dockerfile
+++ b/docker/nginx/Dockerfile
@@ -1,4 +1,4 @@
-FROM nginx:1.25.3-alpine
+FROM nginx:1.27.5-alpine-slim
COPY . /code
RUN adduser --system www-data \
diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile
index 1882bc9d..c3e855ac 100644
--- a/docker/php/Dockerfile
+++ b/docker/php/Dockerfile
@@ -1,7 +1,7 @@
# Based on https://github.com/dead-guru/devichan/blob/master/php-fpm/Dockerfile
FROM composer:lts AS composer
-FROM php:8.1-fpm-alpine
+FROM php:8.3-fpm-alpine
RUN apk add --no-cache \
zlib \
diff --git a/inc/Data/Driver/RedisCacheDriver.php b/inc/Data/Driver/RedisCacheDriver.php
index 46e602d4..ad193acd 100644
--- a/inc/Data/Driver/RedisCacheDriver.php
+++ b/inc/Data/Driver/RedisCacheDriver.php
@@ -1,48 +1,73 @@
inner = new \Redis();
- $this->inner->connect($host, $port);
- if ($password) {
- $this->inner->auth($password);
- }
- if (!$this->inner->select($database)) {
- throw new \RuntimeException('Unable to connect to Redis!');
- }
-
- $$this->prefix = $prefix;
- }
-
- public function get(string $key): mixed {
- $ret = $this->inner->get($this->prefix . $key);
- if ($ret === false) {
- return null;
- }
- return \json_decode($ret, true);
- }
-
- public function set(string $key, mixed $value, mixed $expires = false): void {
- if ($expires === false) {
- $this->inner->set($this->prefix . $key, \json_encode($value));
- } else {
- $expires = $expires * 1000; // Seconds to milliseconds.
- $this->inner->setex($this->prefix . $key, $expires, \json_encode($value));
- }
- }
-
- public function delete(string $key): void {
- $this->inner->del($this->prefix . $key);
- }
-
- public function flush(): void {
- $this->inner->flushDB();
- }
+// Defines the required methods for any cache driver
+interface CacheDriver {
+ public function get(string $key): mixed;
+ public function set(string $key, mixed $value, mixed $expires = false): void;
+ public function delete(string $key): void;
+ public function flush(): void;
+}
+
+// Handles caching using Redis, a fast in-memory data store
+class RedisCacheDriver implements CacheDriver {
+ private string $prefix;
+ private \Redis $inner;
+
+ // Sets up the Redis connection
+ public function __construct(string $prefix, string $host, int $port, ?string $password, int $database) {
+ $this->inner = new \Redis();
+ $this->inner->connect($host, $port);
+
+ if ($password) {
+ $this->inner->auth($password);
+ }
+
+ if (!$this->inner->select($database)) {
+ throw new \RuntimeException('Unable to select Redis database ' . $database);
+ }
+
+ $this->prefix = $prefix;
+ }
+
+ // Retrieves a value from the cache by key
+ public function get(string $key): mixed {
+
+ $ret = $this->inner->get($this->prefix . $key);
+ if ($ret === false) {
+ // Return null if the key doesn't exist
+ return null;
+ }
+
+ return \json_decode($ret, true);
+ }
+
+ // Stores a value in the cache with an optional expiration time
+ public function set(string $key, mixed $value, mixed $expires = false): void {
+ // Convert the value to JSON for storage
+ $encodedValue = \json_encode($value);
+
+ if ($expires === false || !is_numeric($expires) || $expires <= 0) {
+ // Store the value without an expiration
+ $this->inner->set($this->prefix . $key, $encodedValue);
+ } else {
+ // Store the value with an expiration time (in seconds)
+ $ttl_seconds = (int)$expires;
+ $this->inner->setex($this->prefix . $key, $ttl_seconds, $encodedValue);
+ }
+ }
+
+ // Deletes a specific key from the cache
+ public function delete(string $key): void {
+ // Remove the key from Redis
+ $this->inner->del($this->prefix . $key);
+ }
+
+ // Clears all data in the current Redis database
+ public function flush(): void {
+ $this->inner->flushDB();
+ }
}
diff --git a/install.php b/install.php
index 6c8d627d..ec33fdc5 100644
--- a/install.php
+++ b/install.php
@@ -387,7 +387,7 @@ if (file_exists($config['has_installed'])) {
CHANGE `theme` `theme` VARCHAR( 40 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
CHANGE `name` `name` VARCHAR( 40 ) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
CHANGE `value` `value` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
- DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or eror(db_error());
+ DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;") or error(db_error());
case 'v0.9.6-dev-10':
query("ALTER TABLE `antispam`
CHANGE `board` `board` VARCHAR( 58 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL;") or error(db_error());
@@ -680,12 +680,12 @@ function create_config_from_array(&$instance_config, &$array, $prefix = '') {
session_start();
if ($step == 0) {
- // Agreeement
- $page['body'] = '
-
-
- I have read and understood the agreement. Proceed to installation.
-
';
+ // Agreement
+ $page['body'] = '
+
+
+ I have read and understood the agreement. Proceed to installation.
+
';
echo Element('page.html', $page);
} elseif ($step == 1) {
@@ -914,23 +914,35 @@ if ($step == 0) {
'config' => $config,
));
} elseif ($step == 2) {
+ $page['title'] = 'Configuration';
+ $sg = new SaltGen();
+ $config['cookies']['salt'] = $sg->generate();
+ $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') : '',
+ );
- // Basic config
- $page['title'] = 'Configuration';
-
- $sg = new SaltGen();
- $config['cookies']['salt'] = $sg->generate();
- $config['secure_trip_salt'] = $sg->generate();
- $config['secure_password_salt'] = $sg->generate();
-
- echo Element('page.html', array(
- 'body' => Element('installer/config.html', array(
- 'config' => $config,
- 'more' => $_SESSION['more'],
- )),
- 'title' => 'Configuration',
- 'config' => $config
- ));
+ // Append secure_login_only to $_SESSION['more'] if VICHAN_SECURE_LOGIN_ONLY is set from Docker environment variables
+ 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;";
+ }
+
+ echo Element('page.html', array(
+ 'body' => Element('installer/config.html', array(
+ 'config' => $config,
+ 'more' => $_SESSION['more'],
+ )),
+ 'title' => 'Configuration',
+ 'config' => $config
+ ));
} elseif ($step == 3) {
$more = $_POST['more'];
unset($_POST['more']);
@@ -973,69 +985,85 @@ if ($step == 0) {
echo Element('page.html', $page);
}
} elseif ($step == 4) {
- // SQL installation
+ buildJavascript();
- buildJavascript();
+ $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql.");
- $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql.");
+ sql_open();
+ $mysql_version = mysql_version();
- sql_open();
- $mysql_version = mysql_version();
+ // This code is probably horrible, but what I'm trying
+ // to do is find all of the SQL queires and put them
+ // in an array.
+ preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries);
+ $queries = $queries[2];
- // This code is probably horrible, but what I'm trying
- // to do is find all of the SQL queires and put them
- // in an array.
- preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries);
- $queries = $queries[2];
+ $queries[] = Element('posts.sql', array('board' => 'b'));
- $queries[] = Element('posts.sql', array('board' => 'b'));
+ $sql_errors = '';
+ $sql_err_count = 0;
+ foreach ($queries as $query) {
+ if ($mysql_version < 50503)
+ $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
+ $query = preg_replace('/^([\w\s]*)`([0-9a-zA-Z$_\x{0080}-\x{FFFF}]+)`/u', '$1``$2``', $query);
+ if (!query($query)) {
+ $sql_err_count++;
+ $error = db_error();
+ $sql_errors .= "$sql_err_count ";
+ }
+ }
- $sql_errors = '';
- $sql_err_count = 0;
- foreach ($queries as $query) {
- if ($mysql_version < 50503)
- $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
- $query = preg_replace('/^([\w\s]*)`([0-9a-zA-Z$_\x{0080}-\x{FFFF}]+)`/u', '$1``$2``', $query);
- if (!query($query)) {
- $sql_err_count++;
- $error = db_error();
- $sql_errors .= "$sql_err_count ";
- }
- }
+ $page['title'] = 'Installation complete';
+ $page['body'] = 'Thank you for installing vichan. Please report any bugs you discover. How do I edit the config files?
';
- $page['title'] = 'Installation complete';
- $page['body'] = 'Thank you for using vichan. Please remember to report any bugs you discover. How do I edit the config files?
';
+ // notice and button
+ $page['body'] .= 'Next Steps ' .
+ '
You can now log in to the admin panel at /mod.php using the default credentials: Username: admin , Password: password .
' .
+ '
Important: For security, please change the administrator password immediately after logging in.
' .
+ '
Go to Admin Panel
';
- if (!empty($sql_errors)) {
- $page['body'] .= 'SQL errors 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.
The errors encountered were:
Ignore errors and complete installation.
';
- } else {
- $boards = listBoards();
- foreach ($boards as &$_board) {
- setupBoard($_board);
- buildIndex();
- }
+ if (!empty($sql_errors)) {
+ $page['body'] .= 'SQL errors 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.
The errors encountered were:
' .
+ '
Warning: Ignoring errors is not recommended and may cause installation issues.
' .
+ '
Next
';
+ } else {
+ $boards = listBoards();
+ foreach ($boards as &$_board) {
+ setupBoard($_board);
+ buildIndex();
+ }
- file_write($config['has_installed'], VERSION);
- /*if (!file_unlink(__FILE__)) {
- $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
- }*/
- }
+ file_write($config['has_installed'], VERSION);
+ /*if (!file_unlink(__FILE__)) {
+ $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
+ }*/
+ }
- echo Element('page.html', $page);
+ echo Element('page.html', $page);
} elseif ($step == 5) {
- $page['title'] = 'Installation complete';
- $page['body'] = 'Thank you for using vichan. Please remember to report any bugs you discover.
';
+ $page['title'] = 'Installation complete';
+ $page['body'] = 'Thank you for installing vichan. Please report any bugs you discover.
';
- $boards = listBoards();
- foreach ($boards as &$_board) {
- setupBoard($_board);
- buildIndex();
- }
+ // onboarding notice and button to mod.php
+ $page['body'] .= 'Next Steps ' .
+ '
You can now log in to the admin panel at /mod.php using the default credentials:
' .
+ '
' .
+ 'Username: admin ' .
+ 'Password: password ' .
+ ' ' .
+ '
Important: For security, please change the administrator password immediately after logging in.
' .
+ '
Go to Admin Panel
';
- file_write($config['has_installed'], VERSION);
- if (!file_unlink(__FILE__)) {
- $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
- }
+ $boards = listBoards();
+ foreach ($boards as &$_board) {
+ setupBoard($_board);
+ buildIndex();
+ }
- echo Element('page.html', $page);
-}
+ file_write($config['has_installed'], VERSION);
+ if (!file_unlink(__FILE__)) {
+ $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
+ }
+
+ echo Element('page.html', $page);
+}
\ No newline at end of file
diff --git a/templates/installer/check-requirements.html b/templates/installer/check-requirements.html
index f8ea6410..d564efaa 100644
--- a/templates/installer/check-requirements.html
+++ b/templates/installer/check-requirements.html
@@ -1,56 +1,57 @@
-
Pre-installation tests
-
-
- Category
- Test
- Result
-
- {% set errors = 0 %}
- {% set warnings = 0 %}
- {% for test in tests %}
-
- {{ test.category }}
- {{ test.name }}
-
- {% if test.result %}
-
- {% else %}
- {% if test.required %}
- {% set errors = errors + 1 %}
-
- {% else %}
- {% set warnings = warnings + 1 %}
-
- {% endif %}
- {% endif %}
-
-
- {% endfor %}
-
- {% if errors or warnings %}
-
There were {{ errors }} error(s) and {{ warnings }} warning(s).
-
- {% for test in tests %}
- {% if not test.result %}
-
- {% if test.required %}
- Error:
- {% else %}
- Warning:
- {% endif %}
- {{ test.message }}
-
- {% endif %}
- {% endfor %}
-
- {% if errors %}
-
Click here to ignore errors and attempt installing anyway (not recommended).
- {% else %}
-
Click here to proceed with installation.
- {% endif %}
- {% else %}
-
There were no errors or warnings. Good!
-
Clik here to proceed with installation.
- {% endif %}
-
+ Pre-installation tests
+
+
+ Category
+ Test
+ Result
+
+ {% set errors = 0 %}
+ {% set warnings = 0 %}
+ {% for test in tests %}
+
+ {{ test.category }}
+ {{ test.name }}
+
+ {% if test.result %}
+
+ {% else %}
+ {% if test.required %}
+ {% set errors = errors + 1 %}
+
+ {% else %}
+ {% set warnings = warnings + 1 %}
+
+ {% endif %}
+ {% endif %}
+
+
+ {% endfor %}
+
+ {% if errors or warnings %}
+ There were {{ errors }} error(s) and {{ warnings }} warning(s).
+
+ {% for test in tests %}
+ {% if not test.result %}
+
+ {% if test.required %}
+ Error:
+ {% else %}
+ Warning:
+ {% endif %}
+ {{ test.message }}
+
+ {% endif %}
+ {% endfor %}
+
+ {% if errors %}
+ Warning: Ignoring these problems is not recommended and may cause installation issues.
+ Proceed Anyway
+ {% else %}
+ Next
+ {% endif %}
+ {% else %}
+ There were no errors or warnings. Good!
+ Next
+ {% endif %}
+
\ No newline at end of file
diff --git a/templates/installer/config.html b/templates/installer/config.html
index 00a5b241..adf69913 100644
--- a/templates/installer/config.html
+++ b/templates/installer/config.html
@@ -14,7 +14,7 @@
Password:
-
+
The following is all later configurable. For more options, edit your configuration files after installing.
From 64419af5f96d8a1cb279912c1a8f44740ac22652 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Sun, 20 Apr 2025 21:51:07 +0000
Subject: [PATCH 02/34] add php.ini to /docker/php
---
.gitignore | 1 +
compose.yml | 3 ++
docker/php/php.ini | 3 ++
templates/installer/config.html | 80 ++++++++++++++++++++++++++++++++-
4 files changed, 86 insertions(+), 1 deletion(-)
create mode 100644 docker/php/php.ini
diff --git a/.gitignore b/.gitignore
index 5e0ab052..e8d786e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@
thumbs.db
Icon?
Thumbs.db
+.env
*.patch
*.diff
*.rej
diff --git a/compose.yml b/compose.yml
index 0480a33b..57cd133a 100644
--- a/compose.yml
+++ b/compose.yml
@@ -30,6 +30,7 @@ services:
- ./local-instances/${INSTANCE:-0}/www:/var/www
- ./docker/php/www.conf:/usr/local/etc/php-fpm.d/www.conf
- ./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}
@@ -39,6 +40,8 @@ services:
VICHAN_REDIS_HOST: ${VICHAN_REDIS_HOST}
VICHAN_REDIS_PORT: ${VICHAN_REDIS_PORT}
VICHAN_REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
+ PHP_UPLOAD_MAX_FILESIZE: 10M
+ PHP_POST_MAX_SIZE: 10M
depends_on:
- db
diff --git a/docker/php/php.ini b/docker/php/php.ini
new file mode 100644
index 00000000..0e4afdc0
--- /dev/null
+++ b/docker/php/php.ini
@@ -0,0 +1,3 @@
+post_max_size=10M
+upload_max_filesize=10M
+max_file_uploads=5
\ No newline at end of file
diff --git a/templates/installer/config.html b/templates/installer/config.html
index adf69913..c2ca6ec6 100644
--- a/templates/installer/config.html
+++ b/templates/installer/config.html
@@ -51,7 +51,37 @@
Images
Maximum image filesize (bytes):
-
+
+
PHP file size limit
+
+
The php file size limit can be configured in php.ini ( /usr/local/etc/php/php.ini )
+
+
Using docker
+
+
if you have pulled this from GitHub
+
Then you can set the file size limit at ./docker/php/php.ini
+
For example, to set the limit to 10MB, add the following lines:
+
+upload_max_filesize = 10M
+post_max_size = 10M
+
Then restart the containers.
+
+
+
+
Manual Configuration
+
+
If you are not using docker, you can set the file size limit in the php.ini file:
+
For example, to set the limit to 10MB, add the following lines:
+
+upload_max_filesize = 10M
+post_max_size = 10M
+
Then restart the PHP server.
+
+
+
+
If this is not set, the default value is 2MB.
+
+
Thumbnail width:
@@ -99,3 +129,51 @@
+
+
+
From 7e674103a7a865370dcc03583501c4737b78ef18 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Sun, 20 Apr 2025 21:51:49 +0000
Subject: [PATCH 03/34] remove env
---
compose.yml | 2 --
1 file changed, 2 deletions(-)
diff --git a/compose.yml b/compose.yml
index 57cd133a..9ebe3ef3 100644
--- a/compose.yml
+++ b/compose.yml
@@ -40,8 +40,6 @@ services:
VICHAN_REDIS_HOST: ${VICHAN_REDIS_HOST}
VICHAN_REDIS_PORT: ${VICHAN_REDIS_PORT}
VICHAN_REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
- PHP_UPLOAD_MAX_FILESIZE: 10M
- PHP_POST_MAX_SIZE: 10M
depends_on:
- db
From 292ce42cd7610d043b4dadffa514ad7b8b2a2961 Mon Sep 17 00:00:00 2001
From: deffcolony <61471128+deffcolony@users.noreply.github.com>
Date: Mon, 21 Apr 2025 20:47:08 +0200
Subject: [PATCH 04/34] environment variable handling and better configuration
options in Docker setup
---
.env.example | 49 +++++++++++++++++----
compose.yml | 34 ++++++++++++--
docker/doc.md | 63 +++++++++++++++++++++-----
inc/config.php | 63 +++++++++++++-------------
install.php | 78 ++++++++++++++++++++++++---------
templates/installer/config.html | 30 ++++++-------
6 files changed, 225 insertions(+), 92 deletions(-)
diff --git a/.env.example b/.env.example
index 122a244f..8e459397 100644
--- a/.env.example
+++ b/.env.example
@@ -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!!
\ No newline at end of file
+MYSQL_ROOT_PASSWORD=vichan!!
+
+
+# Redis
+VICHAN_REDIS_HOST=redis
+VICHAN_REDIS_PORT=6379
+VICHAN_REDIS_PASSWORD=redis!
diff --git a/compose.yml b/compose.yml
index 9ebe3ef3..852ea849 100644
--- a/compose.yml
+++ b/compose.yml
@@ -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}
diff --git a/docker/doc.md b/docker/doc.md
index 051ae56e..c481757a 100644
--- a/docker/doc.md
+++ b/docker/doc.md
@@ -1,20 +1,63 @@
-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;`
+# Vichan Docker Setup
-The default docker compose settings are intended for development and testing purposes.
-The folder structure expected by compose is as follows
+The `php-fpm` process runs containerized.
+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`.
+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:
```
└── 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
diff --git a/inc/config.php b/inc/config.php
index 4f917f82..e7655634 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -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
diff --git a/install.php b/install.php
index ec33fdc5..1dce4154 100644
--- a/install.php
+++ b/install.php
@@ -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'] = '';
+
+ // 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'] = 'Thank you for installing vichan. Please report any bugs you discover. How do I edit the config files?
';
+ $page['body'] = 'Thank you for using vichan. Please report any bugs you discover.
' .
+ 'If you are new to vichan, please check out the documentation.
';
- // notice and button
+ // Admin panel notice
$page['body'] .= 'Next Steps ' .
- '
You can now log in to the admin panel at /mod.php using the default credentials: Username: admin , Password: password .
' .
+ '
You can now log in to the admin panel at /mod.php using the default credentials:
' .
+ '
Username: admin
' .
+ '
Password: password
' .
'
Important: For security, please change the administrator password immediately after logging in.
' .
'
Go to Admin Panel
';
+
if (!empty($sql_errors)) {
$page['body'] .= 'SQL errors 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.
The errors encountered were:
' .
'
Warning: Ignoring errors is not recommended and may cause installation issues.
' .
@@ -1042,18 +1078,18 @@ if ($step == 0) {
echo Element('page.html', $page);
} elseif ($step == 5) {
$page['title'] = 'Installation complete';
- $page['body'] = '
Thank you for installing vichan. Please report any bugs you discover.
';
+ $page['body'] = '
Thank you for using vichan. Please report any bugs you discover.
' .
+ '
If you are new to vichan, please check out the documentation .
';
- // onboarding notice and button to mod.php
+ // Admin panel notice
$page['body'] .= '
Next Steps ' .
'
You can now log in to the admin panel at /mod.php using the default credentials:
' .
- '
' .
- 'Username: admin ' .
- 'Password: password ' .
- ' ' .
+ '
Username: admin
' .
+ '
Password: password
' .
'
Important: For security, please change the administrator password immediately after logging in.
' .
'
Go to Admin Panel
';
+
$boards = listBoards();
foreach ($boards as &$_board) {
setupBoard($_board);
diff --git a/templates/installer/config.html b/templates/installer/config.html
index c2ca6ec6..09111c34 100644
--- a/templates/installer/config.html
+++ b/templates/installer/config.html
@@ -15,9 +15,6 @@
Password:
-
-
The following is all later configurable. For more options, edit your configuration files after installing.
-
Cookies
Moderator cookie:
@@ -52,34 +49,35 @@
Maximum image filesize (bytes):
-
PHP file size limit
+
PHP File Size Limit
-
The php file size limit can be configured in php.ini ( /usr/local/etc/php/php.ini )
+
Configure the PHP file size limit in the php.ini file. If it doesn't exist, create one.
-
Using docker
+
Using Docker
-
if you have pulled this from GitHub
-
Then you can set the file size limit at ./docker/php/php.ini
-
For example, to set the limit to 10MB, add the following lines:
+
Edit or create ./vichan/docker/php/php.ini in the project root.
+
To set the limit to 10MB, add:
-upload_max_filesize = 10M
-post_max_size = 10M
+ upload_max_filesize = 10M
+ post_max_size = 10M
+
Then restart the containers.
Manual Configuration
-
If you are not using docker, you can set the file size limit in the php.ini file:
-
For example, to set the limit to 10MB, add the following lines:
+
Edit or create /usr/local/etc/php/php.ini.
+
To set the limit to 10MB, add:
-upload_max_filesize = 10M
-post_max_size = 10M
+ upload_max_filesize = 10M
+ post_max_size = 10M
+
Then restart the PHP server.
-
If this is not set, the default value is 2MB.
+
Default limit is 2MB if not set.
Thumbnail width:
From d3f49bfd0465f7b0e574a9eaff5bcae2ab1cf636 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Tue, 22 Apr 2025 02:02:03 +0000
Subject: [PATCH 05/34] undo line 687 in install.php
---
install.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/install.php b/install.php
index ec33fdc5..02b40b1b 100644
--- a/install.php
+++ b/install.php
@@ -684,7 +684,7 @@ if ($step == 0) {
$page['body'] = '
- I have read and understood the agreement. Proceed to installation.
+ I have read and understood the agreement. Proceed to installation.
';
echo Element('page.html', $page);
From 1671ec36c7105d00764ffbbe9ee7395b781f8db5 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Tue, 22 Apr 2025 02:17:29 +0000
Subject: [PATCH 06/34] use tab indendation
https://github.com/vichan-devel/vichan/pull/930#discussion_r2052987496
---
install.php | 239 ++++++++++++++++++++++++++--------------------------
1 file changed, 119 insertions(+), 120 deletions(-)
diff --git a/install.php b/install.php
index 3c7bd3dd..e3649c2d 100644
--- a/install.php
+++ b/install.php
@@ -914,67 +914,67 @@ if ($step == 0) {
'config' => $config,
));
} elseif ($step == 2) {
- $page['title'] = 'Configuration';
- $sg = new SaltGen();
+ $page['title'] = 'Configuration';
+ $sg = new SaltGen();
- // Initialize configuration with defaults and override with environment variables
+ // 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();
+ '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') : '',
- );
+ $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') : '',
+ );
- // 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;";
- }
+ // 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'] = '';
+ $page['body'] = '';
- // Append the configuration form
- $page['body'] .= Element('installer/config.html', array(
- 'config' => $config,
- 'more' => $_SESSION['more'],
- ));
+ // Append the configuration form
+ $page['body'] .= Element('installer/config.html', array(
+ 'config' => $config,
+ 'more' => $_SESSION['more'],
+ ));
- echo Element('page.html', array(
- 'body' => $page['body'],
- 'title' => 'Configuration',
- 'config' => $config
- ));
+ echo Element('page.html', array(
+ 'body' => $page['body'],
+ 'title' => 'Configuration',
+ 'config' => $config
+ ));
} elseif ($step == 3) {
$more = $_POST['more'];
unset($_POST['more']);
@@ -1017,89 +1017,88 @@ if ($step == 0) {
echo Element('page.html', $page);
}
} elseif ($step == 4) {
- buildJavascript();
+ buildJavascript();
- $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql.");
+ $sql = @file_get_contents('install.sql') or error("Couldn't load install.sql.");
- sql_open();
- $mysql_version = mysql_version();
+ sql_open();
+ $mysql_version = mysql_version();
- // This code is probably horrible, but what I'm trying
- // to do is find all of the SQL queires and put them
- // in an array.
- preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries);
- $queries = $queries[2];
+ // This code is probably horrible, but what I'm trying
+ // to do is find all of the SQL queires and put them
+ // in an array.
+ preg_match_all("/(^|\n)((SET|CREATE|INSERT).+)\n\n/msU", $sql, $queries);
+ $queries = $queries[2];
- $queries[] = Element('posts.sql', array('board' => 'b'));
+ $queries[] = Element('posts.sql', array('board' => 'b'));
- $sql_errors = '';
- $sql_err_count = 0;
- foreach ($queries as $query) {
- if ($mysql_version < 50503)
- $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
- $query = preg_replace('/^([\w\s]*)`([0-9a-zA-Z$_\x{0080}-\x{FFFF}]+)`/u', '$1``$2``', $query);
- if (!query($query)) {
- $sql_err_count++;
- $error = db_error();
- $sql_errors .= "$sql_err_count ";
- }
- }
+ $sql_errors = '';
+ $sql_err_count = 0;
+ foreach ($queries as $query) {
+ if ($mysql_version < 50503)
+ $query = preg_replace('/(CHARSET=|CHARACTER SET )utf8mb4/', '$1utf8', $query);
+ $query = preg_replace('/^([\w\s]*)`([0-9a-zA-Z$_\x{0080}-\x{FFFF}]+)`/u', '$1``$2``', $query);
+ if (!query($query)) {
+ $sql_err_count++;
+ $error = db_error();
+ $sql_errors .= "$sql_err_count ";
+ }
+ }
- $page['title'] = 'Installation complete';
- $page['body'] = 'Thank you for using vichan. Please report any bugs you discover.
' .
- 'If you are new to vichan, please check out the documentation.
';
+ $page['title'] = 'Installation complete';
+ $page['body'] = 'Thank you for using vichan. Please report any bugs you discover.
' .
+ 'If you are new to vichan, please check out the documentation.
';
// Admin panel notice
- $page['body'] .= 'Next Steps ' .
- '
You can now log in to the admin panel at /mod.php using the default credentials:
' .
- '
Username: admin
' .
- '
Password: password
' .
- '
Important: For security, please change the administrator password immediately after logging in.
' .
- '
Go to Admin Panel
';
+ $page['body'] .= 'Next Steps ' .
+ '
You can now log in to the admin panel at /mod.php using the default credentials:
' .
+ '
Username: admin
' .
+ '
Password: password
' .
+ '
Important: For security, please change the administrator password immediately after logging in.
' .
+ '
Go to Admin Panel
';
- if (!empty($sql_errors)) {
- $page['body'] .= 'SQL errors 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.
The errors encountered were:
' .
- '
Warning: Ignoring errors is not recommended and may cause installation issues.
' .
- '
Next
';
- } else {
- $boards = listBoards();
- foreach ($boards as &$_board) {
- setupBoard($_board);
- buildIndex();
- }
+ if (!empty($sql_errors)) {
+ $page['body'] .= 'SQL errors 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.
The errors encountered were:
' .
+ '
Warning: Ignoring errors is not recommended and may cause installation issues.
' .
+ '
Next
';
+ } else {
+ $boards = listBoards();
+ foreach ($boards as &$_board) {
+ setupBoard($_board);
+ buildIndex();
+ }
- file_write($config['has_installed'], VERSION);
- /*if (!file_unlink(__FILE__)) {
- $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
- }*/
- }
+ file_write($config['has_installed'], VERSION);
+ /*if (!file_unlink(__FILE__)) {
+ $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
+ }*/
+ }
- echo Element('page.html', $page);
+ echo Element('page.html', $page);
} elseif ($step == 5) {
- $page['title'] = 'Installation complete';
- $page['body'] = 'Thank you for using vichan. Please report any bugs you discover.
' .
- 'If you are new to vichan, please check out the documentation .
';
+ $page['title'] = 'Installation complete';
+ $page['body'] = 'Thank you for using vichan. Please report any bugs you discover.
' .
+ 'If you are new to vichan, please check out the documentation .
';
- // Admin panel notice
- $page['body'] .= 'Next Steps ' .
- '
You can now log in to the admin panel at /mod.php using the default credentials:
' .
- '
Username: admin
' .
- '
Password: password
' .
- '
Important: For security, please change the administrator password immediately after logging in.
' .
- '
Go to Admin Panel
';
+ // Admin panel notice
+ $page['body'] .= 'Next Steps ' .
+ '
You can now log in to the admin panel at /mod.php using the default credentials:
' .
+ '
Username: admin
' .
+ '
Password: password
' .
+ '
Important: For security, please change the administrator password immediately after logging in.
' .
+ '
Go to Admin Panel
';
+ $boards = listBoards();
+ foreach ($boards as &$_board) {
+ setupBoard($_board);
+ buildIndex();
+ }
- $boards = listBoards();
- foreach ($boards as &$_board) {
- setupBoard($_board);
- buildIndex();
- }
+ file_write($config['has_installed'], VERSION);
+ if (!file_unlink(__FILE__)) {
+ $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
+ }
- file_write($config['has_installed'], VERSION);
- if (!file_unlink(__FILE__)) {
- $page['body'] .= 'Delete install.php! I couldn\'t remove install.php . You will have to remove it manually.
';
- }
-
- echo Element('page.html', $page);
+ echo Element('page.html', $page);
}
\ No newline at end of file
From 7013f26eb2ed91784598cdd470a2a156fdc4709c Mon Sep 17 00:00:00 2001
From: deffcolony <61471128+deffcolony@users.noreply.github.com>
Date: Tue, 22 Apr 2025 17:12:36 +0200
Subject: [PATCH 07/34] corrected compose.yml and add podman docs
---
compose.yml | 22 ++++++-------
docker/doc.md | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 96 insertions(+), 11 deletions(-)
diff --git a/compose.yml b/compose.yml
index 852ea849..49809abe 100644
--- a/compose.yml
+++ b/compose.yml
@@ -3,20 +3,20 @@ services:
build:
context: .
dockerfile: ./docker/nginx/Dockerfile
- container_name: vichan_frontend
+ container_name: vichan_web
restart: unless-stopped
- ports:
- - "9090:80"
-# - "9092:443" # optional for SSL
- depends_on:
- - db
- - php
volumes:
- ./local-instances/${INSTANCE:-0}/www:/var/www/html
- ./docker/nginx/vichan.conf:/etc/nginx/conf.d/default.conf
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
- ./docker/nginx/proxy.conf:/etc/nginx/conf.d/proxy.conf
# - ./docker/nginx/ssl:/etc/nginx/ssl # optional For SSL
+ ports:
+ - "9090:80"
+# - "9092:443" # optional for SSL
+ depends_on:
+ - db
+ - php
links:
- php
@@ -71,6 +71,8 @@ services:
image: mariadb:latest
container_name: vichan_mariadb
restart: unless-stopped
+ volumes:
+ - ./local-instances/${INSTANCE:-0}/db:/var/lib/mysql
ports:
- "9091:3306"
environment:
@@ -78,17 +80,15 @@ services:
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
- volumes:
- - ./local-instances/${INSTANCE:-0}/db:/var/lib/mysql
redis:
image: redis:latest
container_name: vichan_redis
restart: unless-stopped
- environment:
- REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
volumes:
- ./local-instances/${INSTANCE:-0}/redis:/data
+ environment:
+ REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
command: redis-server --requirepass ${VICHAN_REDIS_PASSWORD}
healthcheck:
test: ["CMD", "redis-cli", "-a", "${VICHAN_REDIS_PASSWORD}", "ping"]
diff --git a/docker/doc.md b/docker/doc.md
index c481757a..37565da7 100644
--- a/docker/doc.md
+++ b/docker/doc.md
@@ -61,3 +61,88 @@ Environment variables for the Docker Compose setup can be managed easily using a
- Redis connection details
- Secure login
- Optional SSL certificate paths for nginx
+
+
+# Vichan Podman Setup (Docker alternative)
+
+**Podman** offers a daemonless, rootless alternative for running Vichan in containers. Podman is API-compatible with Docker, allowing you to use the existing `compose.yml` file with minimal changes, while providing a more secure and lightweight environment.
+
+This tutorial is for administrators who prefer to avoid Docker, addressing security concerns and ensuring a robust Vichan install.
+
+---
+
+## Why Podman?
+
+- **Daemonless**: Unlike Docker, Podman doesn’t require a central daemon, reducing the attack surface and eliminating the need for a privileged process.
+- **Rootless**: Podman runs containers as a non-root user by default, improving security by limiting the impact of potential container escapes.
+- **Lightweight**: Podman has a smaller footprint and is better suited for environments where simplicity and security are priorities.
+- **Docker Compatibility**: Podman supports Docker Compose files via Podman Compose, making it easy to adapt the existing Vichan setup.
+
+Learn more at: https://podman.io
+---
+
+## Prerequisites
+
+**Install Podman**
+
+The official installation tutorial can be found at: https://podman.io/docs/installation
+
+**Configure the `.env` file** as described in the main setup guide (copy `.env.example` to `.env` and update passwords).
+
+---
+
+## Steps to Run Vichan with Podman
+
+### 1. Prepare File Permissions
+
+Since Podman runs rootless, ensure the `local-instances/1/db` and `local-instances/1/www` directories are writable by your user:
+
+```bash
+chmod -R u+rw local-instances/1
+```
+
+If using SELinux (e.g., on Fedora), you may need to set the correct context:
+
+```bash
+chcon -R -t container_file_t local-instances/1
+```
+
+### 2. Start Containers with Podman Compose
+
+Run the following command from the root of the Vichan project directory to build and start all containers:
+
+```bash
+podman-compose up -d --build
+```
+
+This command mirrors `docker compose up -d --build` but uses Podman’s container engine.
+
+### 3. Rebuild Specific Containers
+
+To rebuild only the PHP container (e.g., during development):
+
+```bash
+podman-compose up -d --build php
+```
+
+---
+
+## Managing Podman Containers
+
+**List running containers:**
+
+```bash
+podman ps
+```
+
+**Stop all containers:**
+
+```bash
+podman-compose down
+```
+
+**View logs for a specific service (e.g., PHP):**
+
+```bash
+podman logs vichan_php
+```
From 38d96b80a54e34a189cb3a6001f36699f601014d Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Tue, 22 Apr 2025 20:22:08 +0000
Subject: [PATCH 08/34] Add Redis cache configuration and temp logging
functionality
---
inc/_LOGGER_.php | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
inc/cache.php | 28 +++++++++++++++++---
inc/config.php | 26 +++++++-----------
3 files changed, 102 insertions(+), 21 deletions(-)
create mode 100755 inc/_LOGGER_.php
diff --git a/inc/_LOGGER_.php b/inc/_LOGGER_.php
new file mode 100755
index 00000000..fc427074
--- /dev/null
+++ b/inc/_LOGGER_.php
@@ -0,0 +1,69 @@
+ $value) {
+ $function = isset($value['function']) ? $value['function'] : "unknown";
+ $file = isset($value['file']) ? $value['file'] : "unknown";
+ $line = isset($value['line']) ? $value['line'] : "unknown";
+
+ $message = isset($value['args']) ? print_r($value['args'], true) : "unknown";
+
+ // if ($key == 0) {
+ // $log .= " " . $function . " at: " . $file . " : " . $line . "\n";
+ // $log .= " " . $message[1] . "\n";
+ // continue;
+ // }
+ $log .= " " . $function . " at: " . $file . " : " . $line . "\n";
+ }
+ } catch (Exception $e) {
+ echo '';
+ echo "Original stack trace: \n";
+ echo $e->getMessage();
+ print_r($callStack->getTrace());
+ echo ' ';
+ echo '';
+ echo 'Current stack trace: \n';
+ echo $e->getMessage();
+ print_r($e->getTrace());
+ echo ' ';
+
+ die("Unable to parse stack trace");
+ }
+ self::log($log, $includeDate);
+ }
+}
\ No newline at end of file
diff --git a/inc/cache.php b/inc/cache.php
index 293660fd..fe508610 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -12,6 +12,7 @@ defined('TINYBOARD') or exit;
class Cache {
private static function buildCache(): CacheDriver {
global $config;
+ $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
switch ($config['cache']['enabled']) {
case 'memcached':
@@ -20,12 +21,31 @@ class Cache {
$config['cache']['memcached']
);
case 'redis':
+ $host = $config['cache']['redis'][0] ?? 'localhost';
+ $port = $config['cache']['redis'][1] ?? 6379;
+ $password = $config['cache']['redis'][2] ?? '';
+ $database = $config['cache']['redis'][3] ?? 1;
+
+ if ($isDocker) {
+ $host = getenv('VICHAN_REDIS_HOST') ?: $host;
+ $port = getenv('VICHAN_REDIS_PORT') ?: $port;
+ $password = getenv('VICHAN_REDIS_PASSWORD') ?: $password;
+ $database = getenv('VICHAN_REDIS_DATABASE') ?: $database;
+ }
+ // $log->log("Cache info:\n"
+ // . 'Cache driver: redis' . "\n"
+ // . '├ Redis host: ' . $host . "\n"
+ // . '├ Redis port: ' . $port . "\n"
+ // . '├ Redis password: ' . str_repeat('*', strlen($password)) . "\n"
+ // . '└ Redis database: ' . $database . "\n"
+ // );
+
return new RedisCacheDriver(
$config['cache']['prefix'],
- $config['cache']['redis'][0],
- $config['cache']['redis'][1],
- $config['cache']['redis'][2],
- $config['cache']['redis'][3]
+ $host,
+ $port,
+ $password,
+ $database
);
case 'apcu':
return new ApcuCacheDriver;
diff --git a/inc/config.php b/inc/config.php
index e7655634..8341a072 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -143,27 +143,10 @@
// 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';
}
- // 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
@@ -1869,6 +1852,15 @@
// Enable public logs? 0: NO, 1: YES, 2: YES, but drop names
$config['public_logs'] = 0;
+/*
+ * ====================
+ * Docker settings
+ * ===================
+ */
+
+ $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
+ $config['docker'] = $isDocker;
+
/*
* ====================
* Events (PHP 5.3.0+)
From 37fec1b82f85c0d051abda14d0b2ac6b7025e113 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Tue, 22 Apr 2025 20:23:10 +0000
Subject: [PATCH 09/34] update is_docker
---
inc/cache.php | 3 +--
inc/config.php | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/inc/cache.php b/inc/cache.php
index fe508610..ff15a0ab 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -12,7 +12,6 @@ defined('TINYBOARD') or exit;
class Cache {
private static function buildCache(): CacheDriver {
global $config;
- $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
switch ($config['cache']['enabled']) {
case 'memcached':
@@ -26,7 +25,7 @@ class Cache {
$password = $config['cache']['redis'][2] ?? '';
$database = $config['cache']['redis'][3] ?? 1;
- if ($isDocker) {
+ if ($config['is_docker']) {
$host = getenv('VICHAN_REDIS_HOST') ?: $host;
$port = getenv('VICHAN_REDIS_PORT') ?: $port;
$password = getenv('VICHAN_REDIS_PASSWORD') ?: $password;
diff --git a/inc/config.php b/inc/config.php
index 8341a072..5b488baa 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -1859,7 +1859,7 @@
*/
$isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
- $config['docker'] = $isDocker;
+ $config['is_docker'] = $isDocker;
/*
* ====================
From 0a0cf68d64a687a7ea736d9d0aedc7a73a9debe2 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Tue, 22 Apr 2025 22:37:12 +0000
Subject: [PATCH 10/34] fix enable php extentions
---
docker/php/Dockerfile | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile
index c3e855ac..86c161d1 100644
--- a/docker/php/Dockerfile
+++ b/docker/php/Dockerfile
@@ -47,7 +47,7 @@ RUN apk add --no-cache \
&& pecl install -o -f igbinary \
&& pecl install redis \
&& pecl install imagick \
- $$ docker-php-ext-enable \
+ && docker-php-ext-enable \
igbinary \
redis \
imagick \
From 240bb247f9efe387b09791272013aca88df2ae04 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 23 Apr 2025 15:13:07 +0000
Subject: [PATCH 11/34] update config and remove check for container in
cache.php
---
inc/cache.php | 19 +++++--------------
inc/config.php | 26 +++++++++++++++-----------
2 files changed, 20 insertions(+), 25 deletions(-)
diff --git a/inc/cache.php b/inc/cache.php
index ff15a0ab..ba9c35a7 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -25,20 +25,11 @@ class Cache {
$password = $config['cache']['redis'][2] ?? '';
$database = $config['cache']['redis'][3] ?? 1;
- if ($config['is_docker']) {
- $host = getenv('VICHAN_REDIS_HOST') ?: $host;
- $port = getenv('VICHAN_REDIS_PORT') ?: $port;
- $password = getenv('VICHAN_REDIS_PASSWORD') ?: $password;
- $database = getenv('VICHAN_REDIS_DATABASE') ?: $database;
- }
- // $log->log("Cache info:\n"
- // . 'Cache driver: redis' . "\n"
- // . '├ Redis host: ' . $host . "\n"
- // . '├ Redis port: ' . $port . "\n"
- // . '├ Redis password: ' . str_repeat('*', strlen($password)) . "\n"
- // . '└ Redis database: ' . $database . "\n"
- // );
-
+ $host = getenv('VICHAN_CACHE_HOST') ?: $host;
+ $port = getenv('VICHAN_CACHE_PORT') ?: $port;
+ $password = getenv('VICHAN_CACHE_PASSWORD') ?: $password;
+ $database = getenv('VICHAN_CACHE_DATABASE') ?: $database;
+
return new RedisCacheDriver(
$config['cache']['prefix'],
$host,
diff --git a/inc/config.php b/inc/config.php
index 5b488baa..897eab5f 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -137,15 +137,16 @@
* ====================
*/
+ $config['cache']['enabled'] = 'php';
+ $config['cache']['redis'] = array(
+ 'host' => 'localhost',
+ 'port' => 6379,
+ 'password' => '',
+ 'database' => 1
+ );
+
// Determine if Redis is configured via environment variables
- $redis_enabled = getenv('VICHAN_REDIS_HOST') !== false && getenv('VICHAN_REDIS_PORT') !== false;
-
- // Configure cache
- if ($redis_enabled) {
- $config['cache']['enabled'] = 'redis';
- } else {
- $config['cache']['enabled'] = 'php';
- }
+ getenv('VICHAN_CACHE_ENGINE') && $config['cache']['enabled'] = getenv('VICHAN_CACHE_ENGINE');
// Cache timeout for cached objects
$config['cache']['timeout'] = 60 * 60 * 48; // 48 hours
@@ -1854,12 +1855,15 @@
/*
* ====================
- * Docker settings
+ * Container settings
* ===================
*/
- $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
- $config['is_docker'] = $isDocker;
+ $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
+ $isKubernetes = is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
+ $config['is_container'] = $isDocker || $isKubernetes ? true : false;
+ $config['is_docker'] = $isDocker;
+ $config['is_kubernetes'] = $isKubernetes;
/*
* ====================
From d35b435e7ee5db9dfc21a64600660d9bb3da597e Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 23 Apr 2025 15:13:16 +0000
Subject: [PATCH 12/34] update env for compose
---
.env.example | 9 +++++----
compose.yml | 15 ++++++++-------
2 files changed, 13 insertions(+), 11 deletions(-)
diff --git a/.env.example b/.env.example
index 8e459397..4af6c61a 100644
--- a/.env.example
+++ b/.env.example
@@ -53,7 +53,8 @@ MYSQL_PASSWORD=vichan!
MYSQL_ROOT_PASSWORD=vichan!!
-# Redis
-VICHAN_REDIS_HOST=redis
-VICHAN_REDIS_PORT=6379
-VICHAN_REDIS_PASSWORD=redis!
+# Cache Settings
+VICHAN_CACHE_ENGINE=redis
+VICHAN_CACHE_HOST=redis
+VICHAN_CACHE_PORT=6379
+VICHAN_CACHE_PASSWORD=redis!
diff --git a/compose.yml b/compose.yml
index 49809abe..2e7077df 100644
--- a/compose.yml
+++ b/compose.yml
@@ -39,10 +39,11 @@ services:
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}
+ # Cache settings
+ VICHAN_CACHE_ENGINE: ${VICHAN_CACHE_ENGINE}
+ VICHAN_CACHE_HOST: ${VICHAN_CACHE_HOST}
+ VICHAN_CACHE_PORT: ${VICHAN_CACHE_PORT}
+ VICHAN_CACHE_PASSWORD: ${VICHAN_CACHE_PASSWORD}
# Cookies
VICHAN_COOKIES_MOD: ${VICHAN_COOKIES_MOD}
# Flood Control
@@ -88,10 +89,10 @@ services:
volumes:
- ./local-instances/${INSTANCE:-0}/redis:/data
environment:
- REDIS_PASSWORD: ${VICHAN_REDIS_PASSWORD}
- command: redis-server --requirepass ${VICHAN_REDIS_PASSWORD}
+ REDIS_PASSWORD: ${VICHAN_CACHE_PASSWORD}
+ command: redis-server --requirepass ${VICHAN_CACHE_PASSWORD}
healthcheck:
- test: ["CMD", "redis-cli", "-a", "${VICHAN_REDIS_PASSWORD}", "ping"]
+ test: ["CMD", "redis-cli", "-a", "${VICHAN_CACHE_PASSWORD}", "ping"]
interval: 10s
timeout: 5s
retries: 5
From ffb8759fb1d28f000c09847e8c2af02cb58f5be5 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 23 Apr 2025 15:31:49 +0000
Subject: [PATCH 13/34] remove logger
---
inc/_LOGGER_.php | 69 ------------------------------------------------
1 file changed, 69 deletions(-)
delete mode 100755 inc/_LOGGER_.php
diff --git a/inc/_LOGGER_.php b/inc/_LOGGER_.php
deleted file mode 100755
index fc427074..00000000
--- a/inc/_LOGGER_.php
+++ /dev/null
@@ -1,69 +0,0 @@
- $value) {
- $function = isset($value['function']) ? $value['function'] : "unknown";
- $file = isset($value['file']) ? $value['file'] : "unknown";
- $line = isset($value['line']) ? $value['line'] : "unknown";
-
- $message = isset($value['args']) ? print_r($value['args'], true) : "unknown";
-
- // if ($key == 0) {
- // $log .= " " . $function . " at: " . $file . " : " . $line . "\n";
- // $log .= " " . $message[1] . "\n";
- // continue;
- // }
- $log .= " " . $function . " at: " . $file . " : " . $line . "\n";
- }
- } catch (Exception $e) {
- echo '';
- echo "Original stack trace: \n";
- echo $e->getMessage();
- print_r($callStack->getTrace());
- echo ' ';
- echo '';
- echo 'Current stack trace: \n';
- echo $e->getMessage();
- print_r($e->getTrace());
- echo ' ';
-
- die("Unable to parse stack trace");
- }
- self::log($log, $includeDate);
- }
-}
\ No newline at end of file
From 8360bf0ca74711b2100da28f749c6115cb8f6a15 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 23 Apr 2025 16:01:19 +0000
Subject: [PATCH 14/34] sohw "running in docker" in the footer
---
templates/footer.html | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/templates/footer.html b/templates/footer.html
index 2288b013..8565cd25 100644
--- a/templates/footer.html
+++ b/templates/footer.html
@@ -1,6 +1,10 @@
\ No newline at end of file
From 58c275472f5e235b8231d19cb3fcf2ad7ef1277b Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Thu, 24 Apr 2025 17:10:56 +0000
Subject: [PATCH 18/34] use tab indents
---
inc/Data/Driver/RedisCacheDriver.php | 97 +++++++++++++---------------
1 file changed, 45 insertions(+), 52 deletions(-)
diff --git a/inc/Data/Driver/RedisCacheDriver.php b/inc/Data/Driver/RedisCacheDriver.php
index ad193acd..f2c445c1 100644
--- a/inc/Data/Driver/RedisCacheDriver.php
+++ b/inc/Data/Driver/RedisCacheDriver.php
@@ -4,70 +4,63 @@ namespace Vichan\Data\Driver;
// Prevent direct access to this file for security
defined('TINYBOARD') or exit;
-// Defines the required methods for any cache driver
-interface CacheDriver {
- public function get(string $key): mixed;
- public function set(string $key, mixed $value, mixed $expires = false): void;
- public function delete(string $key): void;
- public function flush(): void;
-}
// Handles caching using Redis, a fast in-memory data store
class RedisCacheDriver implements CacheDriver {
- private string $prefix;
- private \Redis $inner;
+ private string $prefix;
+ private \Redis $inner;
- // Sets up the Redis connection
- public function __construct(string $prefix, string $host, int $port, ?string $password, int $database) {
- $this->inner = new \Redis();
- $this->inner->connect($host, $port);
+ // Sets up the Redis connection
+ public function __construct(string $prefix, string $host, int $port, ?string $password, int $database) {
+ $this->inner = new \Redis();
+ $this->inner->connect($host, $port);
- if ($password) {
- $this->inner->auth($password);
- }
+ if ($password) {
+ $this->inner->auth($password);
+ }
- if (!$this->inner->select($database)) {
- throw new \RuntimeException('Unable to select Redis database ' . $database);
- }
+ if (!$this->inner->select($database)) {
+ throw new \RuntimeException('Unable to select Redis database ' . $database);
+ }
- $this->prefix = $prefix;
- }
+ $this->prefix = $prefix;
+ }
- // Retrieves a value from the cache by key
- public function get(string $key): mixed {
+ // Retrieves a value from the cache by key
+ public function get(string $key): mixed {
- $ret = $this->inner->get($this->prefix . $key);
- if ($ret === false) {
- // Return null if the key doesn't exist
- return null;
- }
+ $ret = $this->inner->get($this->prefix . $key);
+ if ($ret === false) {
+ // Return null if the key doesn't exist
+ return null;
+ }
- return \json_decode($ret, true);
- }
+ return \json_decode($ret, true);
+ }
- // Stores a value in the cache with an optional expiration time
- public function set(string $key, mixed $value, mixed $expires = false): void {
- // Convert the value to JSON for storage
- $encodedValue = \json_encode($value);
+ // Stores a value in the cache with an optional expiration time
+ public function set(string $key, mixed $value, mixed $expires = false): void {
+ // Convert the value to JSON for storage
+ $encodedValue = \json_encode($value);
- if ($expires === false || !is_numeric($expires) || $expires <= 0) {
- // Store the value without an expiration
- $this->inner->set($this->prefix . $key, $encodedValue);
- } else {
- // Store the value with an expiration time (in seconds)
- $ttl_seconds = (int)$expires;
- $this->inner->setex($this->prefix . $key, $ttl_seconds, $encodedValue);
- }
- }
+ if ($expires === false || !is_numeric($expires) || $expires <= 0) {
+ // Store the value without an expiration
+ $this->inner->set($this->prefix . $key, $encodedValue);
+ } else {
+ // Store the value with an expiration time (in seconds)
+ $ttl_seconds = (int)$expires;
+ $this->inner->setex($this->prefix . $key, $ttl_seconds, $encodedValue);
+ }
+ }
- // Deletes a specific key from the cache
- public function delete(string $key): void {
- // Remove the key from Redis
- $this->inner->del($this->prefix . $key);
- }
+ // Deletes a specific key from the cache
+ public function delete(string $key): void {
+ // Remove the key from Redis
+ $this->inner->del($this->prefix . $key);
+ }
- // Clears all data in the current Redis database
- public function flush(): void {
- $this->inner->flushDB();
- }
+ // Clears all data in the current Redis database
+ public function flush(): void {
+ $this->inner->flushDB();
+ }
}
From 3b45f4a897eda6fd2b711a471c85a45565391794 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Thu, 24 Apr 2025 17:13:15 +0000
Subject: [PATCH 19/34] remove button onclick hrefs
---
install.php | 44 ++++++++++++++++++++++----------------------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/install.php b/install.php
index e3649c2d..a2f6f3a5 100644
--- a/install.php
+++ b/install.php
@@ -590,12 +590,12 @@ if (file_exists($config['has_installed'])) {
case '4.9.90':
case '4.9.91':
case '4.9.92':
- foreach ($boards as &$board) {
- query(sprintf('ALTER TABLE ``posts_%s`` ADD `slug` VARCHAR(255) DEFAULT NULL AFTER `embed`;', $board['uri'])) or error(db_error());
+ foreach ($boards as &$board) {
+ query(sprintf('ALTER TABLE ``posts_%s`` ADD `slug` VARCHAR(255) DEFAULT NULL AFTER `embed`;', $board['uri'])) or error(db_error());
}
- case '4.9.93':
- query('ALTER TABLE ``mods`` CHANGE `password` `password` VARCHAR(255) NOT NULL;') or error(db_error());
- query('ALTER TABLE ``mods`` CHANGE `salt` `salt` VARCHAR(64) NOT NULL;') or error(db_error());
+ case '4.9.93':
+ query('ALTER TABLE ``mods`` CHANGE `password` `password` VARCHAR(255) NOT NULL;') or error(db_error());
+ query('ALTER TABLE ``mods`` CHANGE `salt` `salt` VARCHAR(64) NOT NULL;') or error(db_error());
case '5.0.0':
query('ALTER TABLE ``mods`` CHANGE `salt` `version` VARCHAR(64) NOT NULL;') or error(db_error());
case '5.0.1':
@@ -611,9 +611,9 @@ if (file_exists($config['has_installed'])) {
UNIQUE KEY `u_pages` (`name`,`board`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;') or error(db_error());
case '5.1.1':
- foreach ($boards as &$board) {
- query(sprintf("ALTER TABLE ``posts_%s`` ADD `cycle` int(1) NOT NULL AFTER `locked`", $board['uri'])) or error(db_error());
- }
+ foreach ($boards as &$board) {
+ query(sprintf("ALTER TABLE ``posts_%s`` ADD `cycle` int(1) NOT NULL AFTER `locked`", $board['uri'])) or error(db_error());
+ }
case '5.1.2':
query('CREATE TABLE IF NOT EXISTS ``nntp_references`` (
`board` varchar(60) NOT NULL,
@@ -680,12 +680,12 @@ function create_config_from_array(&$instance_config, &$array, $prefix = '') {
session_start();
if ($step == 0) {
- // Agreement
- $page['body'] = '
-
-
+ // Agreement
+ $page['body'] = '
+
+
I have read and understood the agreement. Proceed to installation.
-
';
+ ';
echo Element('page.html', $page);
} elseif ($step == 1) {
@@ -918,7 +918,7 @@ if ($step == 0) {
$sg = new SaltGen();
// Initialize configuration with defaults and override with environment variables
- $config['cookies'] = array(
+ $config['cookies'] = array(
'mod' => getenv('VICHAN_COOKIES_MOD') !== false ? getenv('VICHAN_COOKIES_MOD') : 'mod',
'salt' => $sg->generate(),
);
@@ -944,8 +944,8 @@ if ($step == 0) {
$config['secure_trip_salt'] = $sg->generate();
$config['secure_password_salt'] = $sg->generate();
-
- // Set database configuration from Docker environment variables, leave empty if not found
+
+ // 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') : '',
@@ -953,14 +953,14 @@ if ($step == 0) {
'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
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
+ // Configuration notice at the top
$page['body'] = '';
@@ -1049,19 +1049,19 @@ if ($step == 0) {
$page['body'] = 'Thank you for using vichan. Please report any bugs you discover.
' .
'If you are new to vichan, please check out the documentation.
';
- // Admin panel notice
+ // Admin panel notice
$page['body'] .= 'Next Steps ' .
'
You can now log in to the admin panel at /mod.php using the default credentials:
' .
'
Username: admin
' .
'
Password: password
' .
'
Important: For security, please change the administrator password immediately after logging in.
' .
- '
Go to Admin Panel
';
+ 'Go to Admin Panel
';
if (!empty($sql_errors)) {
$page['body'] .= 'SQL errors 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.
The errors encountered were:
' .
'
Warning: Ignoring errors is not recommended and may cause installation issues.
' .
- '
Next
';
+ 'Next
';
} else {
$boards = listBoards();
foreach ($boards as &$_board) {
@@ -1087,7 +1087,7 @@ if ($step == 0) {
'Username: admin
' .
'Password: password
' .
'Important: For security, please change the administrator password immediately after logging in.
' .
- 'Go to Admin Panel
';
+ 'Go to Admin Panel
';
$boards = listBoards();
foreach ($boards as &$_board) {
From 135904ece0451edb166bc916b710763e7bb435d6 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Thu, 24 Apr 2025 17:14:21 +0000
Subject: [PATCH 20/34] use tab indents
---
templates/installer/check-requirements.html | 110 ++++++++++----------
1 file changed, 55 insertions(+), 55 deletions(-)
diff --git a/templates/installer/check-requirements.html b/templates/installer/check-requirements.html
index 5c2c434f..52484967 100644
--- a/templates/installer/check-requirements.html
+++ b/templates/installer/check-requirements.html
@@ -1,57 +1,57 @@
-
Pre-installation tests
-
-
- Category
- Test
- Result
-
- {% set errors = 0 %}
- {% set warnings = 0 %}
- {% for test in tests %}
-
- {{ test.category }}
- {{ test.name }}
-
- {% if test.result %}
-
- {% else %}
- {% if test.required %}
- {% set errors = errors + 1 %}
-
- {% else %}
- {% set warnings = warnings + 1 %}
-
- {% endif %}
- {% endif %}
-
-
- {% endfor %}
-
- {% if errors or warnings %}
-
There were {{ errors }} error(s) and {{ warnings }} warning(s).
-
- {% for test in tests %}
- {% if not test.result %}
-
- {% if test.required %}
- Error:
- {% else %}
- Warning:
- {% endif %}
- {{ test.message }}
-
- {% endif %}
- {% endfor %}
-
- {% if errors %}
-
Warning: Ignoring these problems is not recommended and may cause installation issues.
-
Proceed Anyway
- {% else %}
-
Next
- {% endif %}
- {% else %}
-
There were no errors or warnings. Good!
-
Next
- {% endif %}
+
Pre-installation tests
+
+
+ Category
+ Test
+ Result
+
+ {% set errors = 0 %}
+ {% set warnings = 0 %}
+ {% for test in tests %}
+
+ {{ test.category }}
+ {{ test.name }}
+
+ {% if test.result %}
+
+ {% else %}
+ {% if test.required %}
+ {% set errors = errors + 1 %}
+
+ {% else %}
+ {% set warnings = warnings + 1 %}
+
+ {% endif %}
+ {% endif %}
+
+
+ {% endfor %}
+
+ {% if errors or warnings %}
+
There were {{ errors }} error(s) and {{ warnings }} warning(s).
+
+ {% for test in tests %}
+ {% if not test.result %}
+
+ {% if test.required %}
+ Error:
+ {% else %}
+ Warning:
+ {% endif %}
+ {{ test.message }}
+
+ {% endif %}
+ {% endfor %}
+
+ {% if errors %}
+
Warning: Ignoring these problems is not recommended and may cause installation issues.
+
Proceed Anyway
+ {% else %}
+
Next
+ {% endif %}
+ {% else %}
+
There were no errors or warnings. Good!
+
Next
+ {% endif %}
\ No newline at end of file
From c3c9352f0a51d728977148e436b588b67af3f83a Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Fri, 25 Apr 2025 14:22:15 +0000
Subject: [PATCH 21/34] sperate code from config.php
---
inc/cache.php | 10 ++++++----
inc/config.php | 41 +++++++++++++++++++++++++----------------
2 files changed, 31 insertions(+), 20 deletions(-)
diff --git a/inc/cache.php b/inc/cache.php
index ba9c35a7..33e03746 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -12,6 +12,8 @@ defined('TINYBOARD') or exit;
class Cache {
private static function buildCache(): CacheDriver {
global $config;
+ // Determine if Redis is configured via environment variables
+ getenv('VICHAN_CACHE_ENGINE') && $config['cache']['enabled'] = getenv('VICHAN_CACHE_ENGINE');
switch ($config['cache']['enabled']) {
case 'memcached':
@@ -20,10 +22,10 @@ class Cache {
$config['cache']['memcached']
);
case 'redis':
- $host = $config['cache']['redis'][0] ?? 'localhost';
- $port = $config['cache']['redis'][1] ?? 6379;
- $password = $config['cache']['redis'][2] ?? '';
- $database = $config['cache']['redis'][3] ?? 1;
+ $host = $config['cache']['redis']["host"] ?? 'localhost';
+ $port = $config['cache']['redis']["port"] ?? 6379;
+ $password = $config['cache']['redis']["password"] ?? '';
+ $database = $config['cache']['redis']["database"] ?? 1;
$host = getenv('VICHAN_CACHE_HOST') ?: $host;
$port = getenv('VICHAN_CACHE_PORT') ?: $port;
diff --git a/inc/config.php b/inc/config.php
index 897eab5f..284fa8ad 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -137,16 +137,37 @@
* ====================
*/
+ /*
+ * 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
+ */
+
+ // Uses a PHP array. MUST NOT be used in multiprocess environments.
+ // This will be ignored if a environment variable ( VICHAN_CACHE_ENGINE ) is set.
$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';
+
+ // Timeout for cached objects such as posts and HTML.
$config['cache']['redis'] = array(
'host' => 'localhost',
'port' => 6379,
'password' => '',
'database' => 1
);
-
- // Determine if Redis is configured via environment variables
- getenv('VICHAN_CACHE_ENGINE') && $config['cache']['enabled'] = getenv('VICHAN_CACHE_ENGINE');
// Cache timeout for cached objects
$config['cache']['timeout'] = 60 * 60 * 48; // 48 hours
@@ -182,7 +203,7 @@
// Used for communicating with Javascript; telling it when posts were successful.
$config['cookies']['js'] = 'serv';
- // Cookies path. Defaults to $config['root']. If $config['root'] is a URL, you need to set this. Should
+ // Cooakies path. Defaults to $config['root']. If $config['root'] is a URL, you need to set this. Should
// be '/' or '/board/', depending on your installation.
// $config['cookies']['path'] = '/';
// Where to set the 'path' parameter to $config['cookies']['path'] when creating cookies. Recommended.
@@ -1852,18 +1873,6 @@
// Enable public logs? 0: NO, 1: YES, 2: YES, but drop names
$config['public_logs'] = 0;
-
-/*
- * ====================
- * Container settings
- * ===================
- */
-
- $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
- $isKubernetes = is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
- $config['is_container'] = $isDocker || $isKubernetes ? true : false;
- $config['is_docker'] = $isDocker;
- $config['is_kubernetes'] = $isKubernetes;
/*
* ====================
From 4d2f369af6fc6fd798b6fc18749053dc8481c765 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Fri, 25 Apr 2025 14:22:42 +0000
Subject: [PATCH 22/34] add twig to template.php: check container?
---
inc/template.php | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/inc/template.php b/inc/template.php
index 17df316b..47b7bc0f 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -225,3 +225,19 @@ function twig_secure_link_confirm($text, $title, $confirm_message, $href) {
function twig_secure_link($href) {
return $href . '/' . make_secure_link_token($href);
}
+
+// /*
+// * ====================
+// * Container Detection
+// * ===================
+// */
+
+function twig_check_container() {
+ global $config;
+ $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
+ $isKubernetes = is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
+ $config['is_container'] = $isDocker || $isKubernetes ? true : false;
+ $config['is_docker'] = $isDocker;
+ $config['is_kubernetes'] = $isKubernetes;
+ return $config['is_container'];
+}
\ No newline at end of file
From 12b4356a6a46cd72d47dbfba61f5fd112c5afdde Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Fri, 25 Apr 2025 17:58:48 +0200
Subject: [PATCH 23/34] cache.php: use local vars
---
inc/cache.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/inc/cache.php b/inc/cache.php
index 33e03746..6e81039a 100644
--- a/inc/cache.php
+++ b/inc/cache.php
@@ -12,10 +12,10 @@ defined('TINYBOARD') or exit;
class Cache {
private static function buildCache(): CacheDriver {
global $config;
- // Determine if Redis is configured via environment variables
- getenv('VICHAN_CACHE_ENGINE') && $config['cache']['enabled'] = getenv('VICHAN_CACHE_ENGINE');
+ // Determine if the cache engine is configured via environment variables.
+ $engine = \getenv('VICHAN_CACHE_ENGINE') ?: $config['cache']['enabled'];
- switch ($config['cache']['enabled']) {
+ switch ($engine) {
case 'memcached':
return new MemcachedCacheDriver(
$config['cache']['prefix'],
@@ -31,7 +31,7 @@ class Cache {
$port = getenv('VICHAN_CACHE_PORT') ?: $port;
$password = getenv('VICHAN_CACHE_PASSWORD') ?: $password;
$database = getenv('VICHAN_CACHE_DATABASE') ?: $database;
-
+
return new RedisCacheDriver(
$config['cache']['prefix'],
$host,
From 553c925f404557ad6568f66570e9019f297e84cd Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Fri, 25 Apr 2025 17:59:17 +0200
Subject: [PATCH 24/34] template.php: use PHP style comments
---
inc/template.php | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/inc/template.php b/inc/template.php
index 47b7bc0f..db206ab1 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -226,11 +226,11 @@ function twig_secure_link($href) {
return $href . '/' . make_secure_link_token($href);
}
-// /*
-// * ====================
-// * Container Detection
-// * ===================
-// */
+/*
+ * ====================
+ * Container Detection
+ * ===================
+ */
function twig_check_container() {
global $config;
From 2c023ee644bfa14aae5ae4e5beaee354f79c5f27 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Fri, 25 Apr 2025 18:00:54 +0200
Subject: [PATCH 25/34] templates.php: use local vars for container checking
---
inc/template.php | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/inc/template.php b/inc/template.php
index db206ab1..fbe8e9b3 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -233,11 +233,11 @@ function twig_secure_link($href) {
*/
function twig_check_container() {
- global $config;
- $isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
- $isKubernetes = is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
- $config['is_container'] = $isDocker || $isKubernetes ? true : false;
- $config['is_docker'] = $isDocker;
- $config['is_kubernetes'] = $isKubernetes;
- return $config['is_container'];
-}
\ No newline at end of file
+ static $is_container = null;
+ if ($is_container === null) {
+ $is_docker = \is_file("/.dockerenv") || \is_file("/run/.containerenv");
+ $is_kubernetes = \is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
+ $is_container = $is_docker || $is_kubernetes;
+ }
+ return $is_container;
+}
From f959e790fd162f6c9be3b7da24a35fba3f5479f1 Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Fri, 25 Apr 2025 18:02:12 +0200
Subject: [PATCH 26/34] template.php: expose check_container function in twig
templates
---
inc/template.php | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/inc/template.php b/inc/template.php
index fbe8e9b3..11d9ea10 100644
--- a/inc/template.php
+++ b/inc/template.php
@@ -142,7 +142,8 @@ class Tinyboard extends Twig\Extension\AbstractExtension
new Twig\TwigFunction('ratio', 'twig_ratio_function'),
new Twig\TwigFunction('secure_link_confirm', 'twig_secure_link_confirm'),
new Twig\TwigFunction('secure_link', 'twig_secure_link'),
- new Twig\TwigFunction('link_for', 'link_for')
+ new Twig\TwigFunction('link_for', 'link_for'),
+ new Twig\TwigFunction('check_container', 'twig_check_container')
);
}
From 4f99c62850da22c9e936b9b9b9b4b8af9f4989da Mon Sep 17 00:00:00 2001
From: Zankaria
Date: Fri, 25 Apr 2025 18:32:25 +0200
Subject: [PATCH 27/34] docker: use mariadb LTS
---
compose.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compose.yml b/compose.yml
index bb6a095e..527945c5 100644
--- a/compose.yml
+++ b/compose.yml
@@ -69,7 +69,7 @@ services:
- db
db:
- image: mariadb:latest
+ image: mariadb:lts
container_name: vichan_mariadb
restart: unless-stopped
volumes:
From 14b8ce42a800cf61b977b424e2169220414f5dbf Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 30 Apr 2025 02:02:10 +0000
Subject: [PATCH 28/34] undo db image from mariadb, using `mysql:latest`
---
compose.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compose.yml b/compose.yml
index 527945c5..af04c985 100644
--- a/compose.yml
+++ b/compose.yml
@@ -69,7 +69,7 @@ services:
- db
db:
- image: mariadb:lts
+ image: mysql:lts
container_name: vichan_mariadb
restart: unless-stopped
volumes:
From a5e6470f568ddf52b0677f80417f89abc2bfcf31 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 30 Apr 2025 19:19:48 +0000
Subject: [PATCH 29/34] update compose
---
compose.yml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/compose.yml b/compose.yml
index af04c985..079223c5 100644
--- a/compose.yml
+++ b/compose.yml
@@ -70,12 +70,12 @@ services:
db:
image: mysql:lts
- container_name: vichan_mariadb
+ container_name: vichan_db
restart: unless-stopped
volumes:
- ./local-instances/${INSTANCE:-0}/db:/var/lib/mysql
- ports:
- - "9082:3306"
+ # ports:
+ # - "9082:3306" # optional for external access
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
From fe115048ac095deee52d1d750f97f13be7b03dc1 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 30 Apr 2025 19:33:53 +0000
Subject: [PATCH 30/34] make optional for mariadb
---
compose.yml | 1 +
1 file changed, 1 insertion(+)
diff --git a/compose.yml b/compose.yml
index 079223c5..072c3f82 100644
--- a/compose.yml
+++ b/compose.yml
@@ -70,6 +70,7 @@ services:
db:
image: mysql:lts
+ # image: mariadb:latest # optional for more higher performance
container_name: vichan_db
restart: unless-stopped
volumes:
From 23652b9830d3e8cbbb3dcec77013bba65d7f24d0 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Wed, 30 Apr 2025 19:34:47 +0000
Subject: [PATCH 31/34] lts
---
compose.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/compose.yml b/compose.yml
index 072c3f82..5666d154 100644
--- a/compose.yml
+++ b/compose.yml
@@ -70,7 +70,7 @@ services:
db:
image: mysql:lts
- # image: mariadb:latest # optional for more higher performance
+ # image: mariadb:lts # optional for more higher performance
container_name: vichan_db
restart: unless-stopped
volumes:
From 0518178a4783db3b02ad261f47978f626f00a6be Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Thu, 1 May 2025 15:08:46 +0000
Subject: [PATCH 32/34] fix typo
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/config.php b/inc/config.php
index 284fa8ad..3996d99c 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -203,7 +203,7 @@
// Used for communicating with Javascript; telling it when posts were successful.
$config['cookies']['js'] = 'serv';
- // Cooakies path. Defaults to $config['root']. If $config['root'] is a URL, you need to set this. Should
+ // Cookies path. Defaults to $config['root']. If $config['root'] is a URL, you need to set this. Should
// be '/' or '/board/', depending on your installation.
// $config['cookies']['path'] = '/';
// Where to set the 'path' parameter to $config['cookies']['path'] when creating cookies. Recommended.
From 3050876be09af7c943bed18491c66e220200387b Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Thu, 1 May 2025 15:09:36 +0000
Subject: [PATCH 33/34] remove space
---
inc/config.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/inc/config.php b/inc/config.php
index 3996d99c..458b9ee1 100644
--- a/inc/config.php
+++ b/inc/config.php
@@ -1873,7 +1873,7 @@
// Enable public logs? 0: NO, 1: YES, 2: YES, but drop names
$config['public_logs'] = 0;
-
+
/*
* ====================
* Events (PHP 5.3.0+)
From e4104d4b0518e7d50956c5a011f6dd6a6d424015 Mon Sep 17 00:00:00 2001
From: alexveebee
Date: Thu, 1 May 2025 15:16:53 +0000
Subject: [PATCH 34/34] update to check_container()
---
templates/footer.html | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/templates/footer.html b/templates/footer.html
index be188fb6..05ad6645 100644
--- a/templates/footer.html
+++ b/templates/footer.html
@@ -1,7 +1,7 @@