From 7749b8ae358149d611d4f634db59c62458176981 Mon Sep 17 00:00:00 2001 From: ghol Date: Sat, 11 Oct 2025 19:28:54 +0000 Subject: [PATCH] =?UTF-8?q?z.ai=20=E5=86=99=E7=9A=84=E5=8D=95=E6=96=87?= =?UTF-8?q?=E4=BB=B6php=E4=B8=AA=E4=BA=BA=E5=AF=BC=E8=88=AA=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E7=AE=A1=E7=90=86=E7=B3=BB=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- z.ai/url/index.php | 1406 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1406 insertions(+) create mode 100644 z.ai/url/index.php diff --git a/z.ai/url/index.php b/z.ai/url/index.php new file mode 100644 index 0000000..06bd78a --- /dev/null +++ b/z.ai/url/index.php @@ -0,0 +1,1406 @@ + '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi' // password: password +]; + +// 初始化用户文件 +if (!file_exists(USERS_FILE)) { + file_put_contents(USERS_FILE, json_encode($default_users)); +} + +// 初始化导航数据文件 +if (!file_exists(DATA_FILE)) { + $default_data = [ + 'quick_links' => [ + ['name' => 'Google', 'url' => 'https://www.google.com'], + ['name' => 'GitHub', 'url' => 'https://github.com'], + ['name' => 'YouTube', 'url' => 'https://www.youtube.com'], + ['name' => '哔哩哔哩', 'url' => 'https://www.bilibili.com'], + ['name' => '知乎', 'url' => 'https://www.zhihu.com'], + ['name' => '微博', 'url' => 'https://www.weibo.com'] + ], + 'categories' => [ + [ + 'title' => '工作相关', + 'links' => [ + ['name' => 'Gmail', 'url' => 'https://mail.google.com'], + ['name' => 'Google Calendar', 'url' => 'https://calendar.google.com'], + ['name' => 'Google Docs', 'url' => 'https://docs.google.com'], + ['name' => 'Trello', 'url' => 'https://trello.com'], + ['name' => 'Slack', 'url' => 'https://slack.com'] + ] + ], + [ + 'title' => '开发工具', + 'links' => [ + ['name' => 'Stack Overflow', 'url' => 'https://stackoverflow.com'], + ['name' => 'MDN Web Docs', 'url' => 'https://developer.mozilla.org'], + ['name' => 'CodePen', 'url' => 'https://codepen.io'], + ['name' => 'CodeSandbox', 'url' => 'https://codesandbox.io'], + ['name' => 'NPM', 'url' => 'https://npmjs.com'] + ] + ], + [ + 'title' => '设计资源', + 'links' => [ + ['name' => 'Dribbble', 'url' => 'https://dribbble.com'], + ['name' => 'Behance', 'url' => 'https://behance.net'], + ['name' => 'Unsplash', 'url' => 'https://unsplash.com'], + ['name' => 'Figma', 'url' => 'https://figma.com'], + ['name' => 'Coolors', 'url' => 'https://coolors.co'] + ] + ], + [ + 'title' => '学习平台', + 'links' => [ + ['name' => 'Coursera', 'url' => 'https://coursera.org'], + ['name' => 'edX', 'url' => 'https://edx.org'], + ['name' => 'Udemy', 'url' => 'https://udemy.com'], + ['name' => 'Khan Academy', 'url' => 'https://khanacademy.org'], + ['name' => 'freeCodeCamp', 'url' => 'https://freecodecamp.org'] + ] + ], + [ + 'title' => '新闻资讯', + 'links' => [ + ['name' => 'Hacker News', 'url' => 'https://news.ycombinator.com'], + ['name' => 'Reddit', 'url' => 'https://www.reddit.com'], + ['name' => 'Product Hunt', 'url' => 'https://producthunt.com'], + ['name' => 'TechCrunch', 'url' => 'https://techcrunch.com'], + ['name' => '36氪', 'url' => 'https://36kr.com'] + ] + ], + [ + 'title' => '娱乐休闲', + 'links' => [ + ['name' => 'Netflix', 'url' => 'https://www.netflix.com'], + ['name' => 'Spotify', 'url' => 'https://www.spotify.com'], + ['name' => 'SoundCloud', 'url' => 'https://soundcloud.com'], + ['name' => 'Twitch', 'url' => 'https://www.twitch.tv'], + ['name' => '豆瓣', 'url' => 'https://www.douban.com'] + ] + ] + ] + ]; + file_put_contents(DATA_FILE, json_encode($default_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); +} + +// 读取导航数据 +function getNavData() { + if (!file_exists(DATA_FILE)) { + return ['quick_links' => [], 'categories' => []]; + } + $json = file_get_contents(DATA_FILE); + $data = json_decode($json, true); + if (!$data) { + return ['quick_links' => [], 'categories' => []]; + } + if (!isset($data['quick_links'])) $data['quick_links'] = []; + if (!isset($data['categories'])) $data['categories'] = []; + return $data; +} + +// 保存导航数据 +function saveNavData($data) { + return file_put_contents(DATA_FILE, json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)); +} + +// 验证用户 +function verifyUser($username, $password) { + if (!file_exists(USERS_FILE)) { + return false; + } + $users = json_decode(file_get_contents(USERS_FILE), true); + if (!isset($users[$username])) { + return false; + } + return password_verify($password, $users[$username]); +} + +// 检查是否已登录 +function isLoggedIn() { + return isset($_SESSION['logged_in']) && $_SESSION['logged_in'] === true; +} + +// 处理登录 +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && $_POST['action'] === 'login') { + $username = $_POST['username'] ?? ''; + $password = $_POST['password'] ?? ''; + + if (verifyUser($username, $password)) { + $_SESSION['logged_in'] = true; + $_SESSION['username'] = $username; + header('Location: ?'); + exit; + } else { + $error = '用户名或密码错误'; + } +} + +// 处理登出 +if (isset($_GET['logout'])) { + session_destroy(); + header('Location: ?'); + exit; +} + +// 处理API请求 +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['api'])) { + if (!isLoggedIn()) { + http_response_code(401); + echo json_encode(['error' => '未授权']); + exit; + } + + header('Content-Type: application/json'); + $data = getNavData(); + + switch ($_POST['api']) { + case 'add_category': + $title = trim($_POST['title'] ?? ''); + if ($title) { + if (!isset($data['categories'])) { + $data['categories'] = []; + } + $data['categories'][] = ['title' => $title, 'links' => []]; + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '分类添加成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } else { + echo json_encode(['error' => '分类名称不能为空']); + } + break; + + case 'edit_category': + $index = intval($_POST['index'] ?? -1); + $title = trim($_POST['title'] ?? ''); + if ($index >= 0 && $title) { + if (isset($data['categories'][$index])) { + $data['categories'][$index]['title'] = $title; + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '分类修改成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } else { + echo json_encode(['error' => '分类不存在']); + } + } else { + echo json_encode(['error' => '参数错误']); + } + break; + + case 'delete_category': + $index = intval($_POST['index'] ?? -1); + if ($index >= 0 && isset($data['categories'][$index])) { + array_splice($data['categories'], $index, 1); + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '分类删除成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } else { + echo json_encode(['error' => '分类不存在']); + } + break; + + case 'add_link': + $type = $_POST['type'] ?? 'category'; + $index = intval($_POST['index'] ?? -1); + $name = trim($_POST['name'] ?? ''); + $url = trim($_POST['url'] ?? ''); + + if ($name && $url) { + if ($type === 'quick') { + if (!isset($data['quick_links'])) { + $data['quick_links'] = []; + } + $data['quick_links'][] = ['name' => $name, 'url' => $url]; + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '快速链接添加成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } elseif ($type === 'category' && $index >= 0 && isset($data['categories'][$index])) { + if (!isset($data['categories'][$index]['links'])) { + $data['categories'][$index]['links'] = []; + } + $data['categories'][$index]['links'][] = ['name' => $name, 'url' => $url]; + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '链接添加成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } else { + echo json_encode(['error' => '分类不存在']); + } + } else { + echo json_encode(['error' => '链接名称和地址不能为空']); + } + break; + + case 'edit_link': + $type = $_POST['type'] ?? 'category'; + $categoryIndex = intval($_POST['category_index'] ?? -1); + $linkIndex = intval($_POST['link_index'] ?? -1); + $name = trim($_POST['name'] ?? ''); + $url = trim($_POST['url'] ?? ''); + + if ($name && $url) { + if ($type === 'quick' && $linkIndex >= 0 && isset($data['quick_links'][$linkIndex])) { + $data['quick_links'][$linkIndex] = ['name' => $name, 'url' => $url]; + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '快速链接修改成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } elseif ($type === 'category' && $categoryIndex >= 0 && $linkIndex >= 0 && isset($data['categories'][$categoryIndex])) { + $data['categories'][$categoryIndex]['links'][$linkIndex] = ['name' => $name, 'url' => $url]; + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '链接修改成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } else { + echo json_encode(['error' => '链接不存在']); + } + } else { + echo json_encode(['error' => '链接名称和地址不能为空']); + } + break; + + case 'delete_link': + $type = $_POST['type'] ?? 'category'; + $categoryIndex = intval($_POST['category_index'] ?? -1); + $linkIndex = intval($_POST['link_index'] ?? -1); + + if ($type === 'quick' && $linkIndex >= 0 && isset($data['quick_links'][$linkIndex])) { + array_splice($data['quick_links'], $linkIndex, 1); + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '快速链接删除成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } elseif ($type === 'category' && $categoryIndex >= 0 && $linkIndex >= 0 && isset($data['categories'][$categoryIndex])) { + array_splice($data['categories'][$categoryIndex]['links'], $linkIndex, 1); + if (saveNavData($data)) { + echo json_encode(['success' => true, 'message' => '链接删除成功']); + } else { + echo json_encode(['error' => '保存失败']); + } + } else { + echo json_encode(['error' => '链接不存在']); + } + break; + + case 'get_data': + echo json_encode($data); + break; + + default: + echo json_encode(['error' => '未知操作']); + } + exit; +} + +// 如果未登录,显示登录页面 +if (!isLoggedIn()) { +?> + + + + + + 登录 - <?php echo APP_NAME; ?> + + + +
+ + + +
+ + +
+ +
+ + +
+
+ + +
+ +
+ +
+ 默认账号:
+ 用户名:admin
+ 密码:password +
+
+ + + + + + + + + <?php echo APP_NAME; ?> + + + +
+
+
+

+
+ + 退出 + +
+
+
+
+ +
+ +
+
+ + Ctrl+K +
+
+ + + + + + +
+ + + + + + + +
+ + + + + \ No newline at end of file