11
This commit is contained in:
@@ -13,41 +13,6 @@ class AccessControl implements MiddlewareInterface
|
|||||||
public function process(Request $request, callable $handler) : Response
|
public function process(Request $request, callable $handler) : Response
|
||||||
{
|
{
|
||||||
|
|
||||||
function setFileWritePermission($filePath, $permission = 0664) {
|
|
||||||
// 检查文件是否存在
|
|
||||||
if (!file_exists($filePath)) {
|
|
||||||
// 如果文件不存在,先创建文件
|
|
||||||
if (!touch($filePath)) {
|
|
||||||
error_log("无法创建文件: $filePath");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 检查当前是否已有写入权限
|
|
||||||
if (is_writable($filePath)) {
|
|
||||||
return true; // 已有写入权限,无需修改
|
|
||||||
}
|
|
||||||
// 尝试设置权限
|
|
||||||
if (chmod($filePath, $permission)) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
error_log("无法给文件设置权限:" . $filePath . "权限值:" . $permission);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用示例
|
|
||||||
$logFile = '/rh/webman_duanju/runtime/logs/webman-' . date('Y-m-d') . '.log';
|
|
||||||
// 确保目录存在
|
|
||||||
$logDir = dirname($logFile);
|
|
||||||
if (!is_dir($logDir)) {
|
|
||||||
mkdir($logDir, 0755, true); // 创建目录,权限755
|
|
||||||
}
|
|
||||||
// 给文件设置写入权限(使用0664权限,比0666更安全)
|
|
||||||
setFileWritePermission($logFile);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 如果是options请求则返回一个空响应,否则继续向洋葱芯穿越,并得到一个响应
|
// 如果是options请求则返回一个空响应,否则继续向洋葱芯穿越,并得到一个响应
|
||||||
$response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
|
$response = $request->method() == 'OPTIONS' ? response('') : $handler($request);
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,45 @@ class LogMiddleware implements MiddlewareInterface
|
|||||||
{
|
{
|
||||||
public function process(Request $request, callable $handler): Response
|
public function process(Request $request, callable $handler): Response
|
||||||
{
|
{
|
||||||
|
|
||||||
|
function setFileWritePermission($filePath, $permission = 0664) {
|
||||||
|
// 检查文件是否存在
|
||||||
|
if (!file_exists($filePath)) {
|
||||||
|
// 如果文件不存在,先创建文件
|
||||||
|
if (!touch($filePath)) {
|
||||||
|
error_log("无法创建文件: $filePath");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 检查当前是否已有写入权限
|
||||||
|
if (is_writable($filePath)) {
|
||||||
|
return true; // 已有写入权限,无需修改
|
||||||
|
}
|
||||||
|
// 尝试设置权限
|
||||||
|
if (chmod($filePath, $permission)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
error_log("无法给文件设置权限:" . $filePath . "权限值:" . $permission);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 使用示例
|
||||||
|
$logFile = '/rh/webman_duanju/runtime/logs/webman-' . date('Y-m-d') . '.log';
|
||||||
|
// 确保目录存在
|
||||||
|
$logDir = dirname($logFile);
|
||||||
|
if (!is_dir($logDir)) {
|
||||||
|
mkdir($logDir, 0755, true); // 创建目录,权限755
|
||||||
|
}
|
||||||
|
// 给文件设置写入权限(使用0664权限,比0666更安全)
|
||||||
|
setFileWritePermission($logFile);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 定义颜色
|
// 定义颜色
|
||||||
$green = "\033[32m"; // 标题/分隔
|
$green = "\033[32m"; // 标题/分隔
|
||||||
$yellow = "\033[33m"; // 方法/状态码
|
$yellow = "\033[33m"; // 方法/状态码
|
||||||
|
|||||||
Reference in New Issue
Block a user