From d3f49bfd0465f7b0e574a9eaff5bcae2ab1cf636 Mon Sep 17 00:00:00 2001 From: alexveebee Date: Tue, 22 Apr 2025 02:02:03 +0000 Subject: [PATCH 1/8] 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.

'; 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 2/8] 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'] = '

Configuration Note

' . - '

The following settings can still be configured later. For more customization options, check the Vichan configuration wiki.

'; + $page['body'] = '

Configuration Note

' . + '

The following settings can still be configured later. For more customization options, check the Vichan configuration wiki.

'; - // 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
    • $query
    • $error
  • "; - } - } + $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
    • $query
    • $error
  • "; + } + } - $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.

    ' . - '

    '; + $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.

    ' . + '

    '; - 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:

      ' . $sql_errors . '
    ' . - '

    Warning: Ignoring errors is not recommended and may cause installation issues.

    ' . - '

    '; - } 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:

      ' . $sql_errors . '
    ' . + '

    Warning: Ignoring errors is not recommended and may cause installation issues.

    ' . + '

    '; + } 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.

    ' . - '

    '; + // 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.

    ' . + '

    '; + $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 38d96b80a54e34a189cb3a6001f36699f601014d Mon Sep 17 00:00:00 2001 From: alexveebee Date: Tue, 22 Apr 2025 20:22:08 +0000 Subject: [PATCH 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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