$max_log_size) { $archive_dir = $log_dir . date('Y-m-d') . '/'; if (!is_dir($archive_dir)) mkdir($archive_dir, 0777, true); rename($log_file, $archive_dir . basename($log_file)); } file_put_contents($log_file, $formatted_message, FILE_APPEND); echo $formatted_message; } // 遍历目录函数 function traverse_directory($dir, $dir_username, $dir_password) { log_message("开始遍历目录: $dir"); $files = array_diff(scandir($dir), ['.', '..']); foreach ($files as $file) { $path = "$dir/$file"; if (is_dir($path)) { log_message("进入子目录: $path"); traverse_directory($path, $dir_username, $dir_password); } elseif (pathinfo($file, PATHINFO_EXTENSION) === 'json') { log_message("找到JSON文件: $path"); process_json_file($path, $dir_username); } } log_message("结束遍历目录: $dir"); } // 处理每个JSON文件的函数 function process_json_file($file_path, $dir_username) { log_message("开始处理JSON文件: $file_path"); $json_content = file_get_contents($file_path); $data = json_decode($json_content, true); $dqtime = $data['dqtime'] ?? null; $mod = $data['mod'] ?? null; $auto = $data['auto'] ?? null; $name = $data['name'] ?? null; $json_username = $data['username'] ?? null; $status = $data['status'] ?? null; log_message("提取的数据: dqtime=$dqtime, mod=$mod, auto=$auto, name=$name, json_username=$json_username, status=$status"); if ($status === '已到期') { log_message("产品状态为'已到期',跳过进一步操作。"); $_SESSION['user'] = $dir_username; log_wt($name, "主机名 [{$json_username}] 已在 [{$dqtime}] 到期!", "products"); unlink($file_path); return; } if ($auto == 1 && $dqtime <= date('Y-m-d')) { log_message("产品已到期或今天到期: $dqtime,准备执行模块操作..."); $_SESSION['user'] = $dir_username; log_wt($name, "主机名 [{$json_username}] 已在 [{$dqtime}] 到期!", "products"); $Main_route = "./mods/$mod/Main.php"; if (file_exists($Main_route)) { log_message("加载模块文件: $Main_route"); include_once $Main_route; $re = @stop_product($data); log_message("结果: $re"); unlink($file_path); log_message("产品操作完成: $file_path"); sendMail("{$dir_username}@qq.com", '#Fuxsto Host 到期提醒', "您所购买的 [{$name}], 主机名 [{$json_username}]
已在 [{$dqtime}] 到期!"); log_message("邮件已发送给: {$dir_username}@qq.com"); } else { log_message("模块文件不存在: $Main_route", 'ERROR'); } } else { log_message("auto字段不为1或产品未到期,跳过操作。"); } log_message("结束处理JSON文件: $file_path"); } // 主函数,遍历 ./me/ 目录 function main() { log_message("程序启动,开始遍历目录 ./me/"); $base_dir = './me/'; $users = array_diff(scandir($base_dir), ['.', '..']); foreach ($users as $user) { $passwords_dir = "$base_dir$user"; log_message("发现用户目录: $user"); $passwords = array_diff(scandir($passwords_dir), ['.', '..']); foreach ($passwords as $password) { $products_dir = "$passwords_dir/$password/products"; if (is_dir($products_dir)) { log_message("发现产品目录: $products_dir"); traverse_directory($products_dir, $user, $password); } else { log_message("未找到产品目录: $products_dir", 'WARNING'); } } } log_message("程序运行结束。"); } // 启动主程序 main(); ?>