diff --git a/app/Helpers.php b/app/Helpers.php index 9f2f158..d886364 100644 --- a/app/Helpers.php +++ b/app/Helpers.php @@ -6,32 +6,37 @@ if (! function_exists('create_log')) { /** * Append a line to public/log/{type}/Ymd.log * + * Failures are swallowed so logging never breaks the HTTP request + * (e.g. www cannot mkdir under public/ on a fresh Baota deploy). + * * @param array|string $str */ function create_log($str, string $type = 'c2'): void { - $str = is_array($str) ? json_encode($str, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : (string) $str; - $logPath = public_path('log/'.$type); - if (! is_dir($logPath)) { - $old = umask(0); - mkdir($logPath, 0777, true); - umask($old); - } - - $logName = $logPath.'/'.date('Ymd').'.log'; try { - $url = request()->getRequestUri(); - } catch (\Throwable) { - $url = $_SERVER['REQUEST_URI'] ?? ''; - } - $logStr = date('Y-m-d H:i:s').' '.$url.' '.$str."\r\n\r\n"; - $isNew = ! file_exists($logName); - file_put_contents($logName, $logStr, FILE_APPEND); - if ($isNew) { - try { - chmod($logName, 0777); - } catch (\Throwable) { + $str = is_array($str) ? json_encode($str, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) : (string) $str; + $type = preg_replace('/[^a-z0-9_-]+/i', '', $type) ?: 'c2'; + $logPath = public_path('log/'.$type); + if (! is_dir($logPath) && ! @mkdir($logPath, 0775, true) && ! is_dir($logPath)) { + return; } + + $logName = $logPath.'/'.date('Ymd').'.log'; + try { + $url = request()->getRequestUri(); + } catch (\Throwable) { + $url = $_SERVER['REQUEST_URI'] ?? ''; + } + $logStr = date('Y-m-d H:i:s').' '.$url.' '.$str."\r\n\r\n"; + $isNew = ! file_exists($logName); + if (@file_put_contents($logName, $logStr, FILE_APPEND) === false) { + return; + } + if ($isNew) { + @chmod($logName, 0664); + } + } catch (\Throwable) { + // never break the request for logging } } } diff --git a/docs/BAOTA_DEPLOY.md b/docs/BAOTA_DEPLOY.md index c3ffb88..6dda357 100644 --- a/docs/BAOTA_DEPLOY.md +++ b/docs/BAOTA_DEPLOY.md @@ -446,6 +446,19 @@ tail -n 80 /www/server/php/82/var/log/php-fpm.log +### `mkdir(): Permission denied` at `Helpers.php` / `public/log` + +C2 中间件会写 `public/log/c2/Ymd.log`。站点运行用户(宝塔多为 `www`)对 `public/log` 无写权限时会报错。 + +```bash +cd /www/wwwroot/coruna-lab +mkdir -p public/log/c2 +chown -R www:www public/log storage bootstrap/cache +chmod -R ug+rwx public/log storage bootstrap/cache +``` + +同时确认网站「运行目录 / 用户」与上述属主一致。部署后建议立刻执行一次,避免首个 C2 请求踩坑。 + ### Composer:`putenv()` undefined PHP「禁用函数」含 `putenv`。在 PHP 8.2 设置里移除后重试。 diff --git a/resources/views/admin/channels/index.blade.php b/resources/views/admin/channels/index.blade.php index a6b33c4..6353fe8 100644 --- a/resources/views/admin/channels/index.blade.php +++ b/resources/views/admin/channels/index.blade.php @@ -178,7 +178,7 @@ layui.use(['table', 'form', 'layer'], function () { '' + '' + '' + - '