diff --git a/README.md b/README.md index 44f6bd5..01c4cf8 100644 --- a/README.md +++ b/README.md @@ -3,9 +3,11 @@ 一个轻量化的留言板 / 记事本 / 社交系统 / 博客,没有明确的作用定义,一切都随心所欲。 -- 演示 demo:https://pigeon.ssr.wine/ +- 演示 demo:https://pigeon.ssr.wine/ (已关闭,请看下面这个) - 博客示例:https://tql.ink/ +> 上面链接为本人博客,可以测试发布内容,无意义内容请设置仅自己可见,或者发布后删除,避免影响版面整洁。 + ## 简介 你是否有些临时的想法,或者一小段代码,想找一个地方记下来? @@ -52,6 +54,8 @@ php install.php 安装程序是没有界面的,请通过命令行执行 `install.php`,而不是通过网页访问它。 +> 如需手动安装(不使用安装程序),请 [点击这里阅读安装方法](https://github.com/kasuganosoras/Pigeon/wiki/Install#%E6%89%8B%E5%8A%A8%E5%AE%89%E8%A3%85-pigeon) + ## 未来计划 - [x] 管理员后台系统(已实现) diff --git a/install.php b/install.php index 943878d..f48816d 100755 --- a/install.php +++ b/install.php @@ -23,6 +23,16 @@ echo "是否启用注册功能 (y/n)> "; $enable_registe = trim(fgets(STDIN)); $enable_registe = empty($enable_registe) ? "y" : strtolower($enable_registe); + +// https://github.com/kasuganosoras/Pigeon/issues/31 +$enable_smtp = 'false'; +$smtp_host = ""; +$smtp_port = 25; +$smtp_user = ""; +$smtp_pass = ""; +$smtp_name = ""; +$smtp_mail = ""; + if($enable_registe == "y") { $enable_registe = 'true'; echo "是否启用注册邮箱验证 (y/n)> "; @@ -45,17 +55,11 @@ echo "请输入 SMTP 邮箱 (noreply@example.com)> "; $smtp_mail = trim(fgets(STDIN)); $smtp_mail = empty($smtp_mail) ? "noreply@example.com" : $smtp_mail; - } else { - $enable_smtp = 'false'; - $smtp_host = ""; - $smtp_port = 25; - $smtp_user = ""; - $smtp_pass = ""; - $smtp_name = ""; } } else { $enable_registe = 'false'; } + echo "请输入站点名称 (Pigeon)> "; $sitename = trim(fgets(STDIN)); $sitename = empty($sitename) ? "Pigeon" : $sitename; diff --git a/pigeon/loader.php b/pigeon/loader.php index 8a4cae1..d0b263e 100755 --- a/pigeon/loader.php +++ b/pigeon/loader.php @@ -1,89 +1,52 @@ guid(); -} -// 判断传入参数 s -if(isset($_GET['s'])) { - switch($_GET['s']) { - case 'timeline': - if(isset($_GET['page']) && preg_match("/^[0-9]{0,6}$/", $_GET['page'])) { - $pigeon->before = null; - $pigeon->search = null; - if(isset($_GET['time']) && preg_match("/^[0-9\:\- ]+$/", $_GET['time'])) { - $beforeTime = strtotime($_GET['time']); - $pigeon->before = $beforeTime ? $beforeTime : null; - } - if(isset($_GET['search']) && $_GET['search'] !== '') { - $pigeon->search = mysqli_real_escape_string($pigeon->conn, $_GET['search']); - } - $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); - $pigeon->isAjax = (isset($_GET['ajax']) && $_GET['ajax'] == '1'); - if(isset($_GET['user']) && preg_match("/^[A-Za-z0-9\_\-]{0,32}$/", $_GET['user'])) { - $pigeon->getTimeline($_GET['user'], true, Intval($_GET['page'])); - } else { - $pigeon->getTimeline(null, true, Intval($_GET['page'])); - } - } - break; - case 'login': - $error = ""; - $alert = "danger"; - if(isset($_POST['username']) && isset($_POST['password'])) { - if(!isset($_POST['seid']) || $_POST['seid'] !== $_SESSION['seid']) { - $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); - } - if($pigeon->config['recaptcha_key'] !== '') { - if(!isset($_POST['g-recaptcha-response']) || !$pigeon->recaptcha_verify($_POST['g-recaptcha-response'])) { - $error = "Recaptcha 验证失败。"; + SESSION_START(); + // 加载函数库 + include(ROOT . "/pigeon/function.php"); + include(ROOT . "/pigeon/parsedown.php"); + // 实例化 Pigeon + $pigeon = new Pigeon(); + // 生成 SESSION ID + if(!isset($_SESSION['seid'])) { + $_SESSION['seid'] = $pigeon->guid(); + } + // 判断传入参数 s + if(isset($_GET['s'])) { + switch($_GET['s']) { + case 'timeline': + if(isset($_GET['page']) && preg_match("/^[0-9]{0,6}$/", $_GET['page'])) { + $pigeon->before = null; + $pigeon->search = null; + if(isset($_GET['time']) && preg_match("/^[0-9\:\- ]+$/", $_GET['time'])) { + $beforeTime = strtotime($_GET['time']); + $pigeon->before = $beforeTime ? $beforeTime : null; } - } - $username = mysqli_real_escape_string($pigeon->conn, $_POST['username']); - $login_ip = mysqli_real_escape_string($pigeon->conn, $_SERVER['REMOTE_ADDR']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `username`='{$username}'")); - if($rs) { - if($rs['status'] !== '200') { - switch($rs['status']) { - case "401": - $error = "您需要先验证邮箱才能登陆,点击重新发送邮件。"; - break; - case "403": - $error = "您的账号已被封禁。"; - break; - default: - $error = "您的账号为异常状态,请联系管理员。"; - } + if(isset($_GET['search']) && $_GET['search'] !== '') { + $pigeon->search = mysqli_real_escape_string($pigeon->conn, $_GET['search']); + } + $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); + $pigeon->isAjax = (isset($_GET['ajax']) && $_GET['ajax'] == '1'); + if(isset($_GET['user']) && preg_match("/^[A-Za-z0-9\_\-]{0,32}$/", $_GET['user'])) { + $pigeon->getTimeline($_GET['user'], true, Intval($_GET['page'])); } else { - if(password_verify($_POST['password'], $rs['password'])) { - if($error == '') { - mysqli_query($pigeon->conn, "UPDATE `users` SET `latest_ip`='{$login_ip}', `latest_time`='" . time() . "' WHERE `id`='{$rs['id']}'"); - $_SESSION['user'] = $rs['username']; - $_SESSION['email'] = $rs['email']; - $_SESSION['token'] = $rs['token']; - ?> - - - 跳转中... - - - - - - getTimeline(null, true, Intval($_GET['page'])); + } + } + break; + case 'login': + $error = ""; + $alert = "danger"; + if(isset($_POST['username']) && isset($_POST['password'])) { + if(!isset($_POST['seid']) || $_POST['seid'] !== $_SESSION['seid']) { + $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); + } + if($pigeon->config['recaptcha_key'] !== '') { + if(!isset($_POST['g-recaptcha-response']) || !$pigeon->recaptcha_verify($_POST['g-recaptcha-response'])) { + $error = "Recaptcha 验证失败。"; } } - } else { - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `email`='{$username}'")); + $username = mysqli_real_escape_string($pigeon->conn, $_POST['username']); + $login_ip = mysqli_real_escape_string($pigeon->conn, $_SERVER['REMOTE_ADDR']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `username`='{$username}'")); if($rs) { if($rs['status'] !== '200') { switch($rs['status']) { @@ -112,7 +75,7 @@ - getTemplate("header"); - $pigeon->getTemplate("login"); - $pigeon->getTemplate("footer"); - break; - case 'register': - $error = ""; - $alert = "danger"; - if(!$pigeon->config['enable_registe']) { - $error = "抱歉,本站暂不开放注册。"; - } - if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) { - if(!isset($_POST['seid']) || $_POST['seid'] !== $_SESSION['seid']) { - $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); - } - if(!preg_match("/^[A-Za-z0-9\_\-]+$/", $_POST['username'])) { - $error = "用户名不合法,只允许 A-Z a-z 0-9 _ -"; - } - if(mb_strlen($_POST['password']) < 5 || mb_strlen($_POST['password']) > 32) { - $error = "密码最少为 5 个字符,最大为 32 个字符。"; - } - if(!preg_match("/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims", $_POST['email'])) { - $error = "邮箱格式不正确。"; - } - if($pigeon->config['recaptcha_key'] !== '') { - if(!isset($_POST['g-recaptcha-response']) || !$pigeon->recaptcha_verify($_POST['g-recaptcha-response'])) { - $error = "Recaptcha 验证失败。"; - } - } - $username = mysqli_real_escape_string($pigeon->conn, $_POST['username']); - $password = password_hash($_POST['password'], PASSWORD_BCRYPT); - $email = mysqli_real_escape_string($pigeon->conn, $_POST['email']); - $registe_ip = mysqli_real_escape_string($pigeon->conn, $_SERVER['REMOTE_ADDR']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `username`='{$username}'")); - $token = md5(sha1($username . $password . $email . mt_rand(0, 99999999) . time())); - if($rs) { - $error = "此用户名已被注册。"; - } - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `email`='{$email}'")); - if($rs) { - $error = "此邮箱已被注册。"; - } - if($error == '') { - $ust = '200'; - $needVerify = ''; - if($pigeon->config['smtp']['enable']) { - $ust = '401'; - $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; - $siteurl = "{$http_type}{$_SERVER['HTTP_HOST']}/?s=checkmail&token={$token}"; - $pigeon->sendMail($email, "验证您的 {$pigeon->config['sitename']} 账号", "

您好,感谢您注册 {$pigeon->config['sitename']}。

请点击以下链接验证您的账号:

{$siteurl}

如果以上链接无法点击,请复制到浏览器地址栏中打开。

如果您没有注册本站账号,请忽略此邮件。

"); - $needVerify = "系统已发送一封邮件到您的邮箱,请点击邮件中的链接完成验证。"; - } - mysqli_query($pigeon->conn, "INSERT INTO `users` ( - `id`, - `username`, - `password`, - `email`, - `permission`, - `registe_ip`, - `registe_time`, - `latest_ip`, - `latest_time`, - `status`, - `token`) VALUES ( - NULL, - '{$username}', - '{$password}', - '{$email}', - 'user', - '{$registe_ip}', - '" . time() . "', - NULL, - NULL, - '{$ust}', - '{$token}' - )"); - $alert = "success"; - $error = "账号注册成功!{$needVerify}"; - } - } - $pigeon->getTemplate("header"); - $pigeon->getTemplate("register"); - $pigeon->getTemplate("footer"); - break; - case "logout": - if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { - echo ""; - exit; - } - unset($_SESSION['user']); - unset($_SESSION['email']); - unset($_SESSION['token']); - unset($_SESSION['seid']); - ?> - - - 跳转中... - - - - - - conn, $_GET['token']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `email`='{$username}'")); if($rs) { - $_SESSION['user'] = $rs['username']; - $_SESSION['email'] = $rs['email']; - $apiUser = true; + if($rs['status'] !== '200') { + switch($rs['status']) { + case "401": + $error = "您需要先验证邮箱才能登陆,点击重新发送邮件。"; + break; + case "403": + $error = "您的账号已被封禁。"; + break; + default: + $error = "您的账号为异常状态,请联系管理员。"; + } + } else { + if(password_verify($_POST['password'], $rs['password'])) { + if($error == '') { + mysqli_query($pigeon->conn, "UPDATE `users` SET `latest_ip`='{$login_ip}', `latest_time`='" . time() . "' WHERE `id`='{$rs['id']}'"); + $_SESSION['user'] = $rs['username']; + $_SESSION['email'] = $rs['email']; + $_SESSION['token'] = $rs['token']; + ?> + + + 跳转中... + + + + + + Exception("Permission denied"); + $error = "用户名或密码错误。"; } - } else { - $pigeon->Exception("请先登录。"); } } - if(!$apiUser) { - if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { + $pigeon->getTemplate("header"); + $pigeon->getTemplate("login"); + $pigeon->getTemplate("footer"); + break; + case 'register': + $error = ""; + $alert = "danger"; + if(!$pigeon->config['enable_registe']) { + $error = "抱歉,本站暂不开放注册。"; + } + if(isset($_POST['username']) && isset($_POST['password']) && isset($_POST['email'])) { + if(!isset($_POST['seid']) || $_POST['seid'] !== $_SESSION['seid']) { $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); } + if(!preg_match("/^[A-Za-z0-9\_\-]+$/", $_POST['username'])) { + $error = "用户名不合法,只允许 A-Z a-z 0-9 _ -"; + } + if(mb_strlen($_POST['password']) < 5 || mb_strlen($_POST['password']) > 32) { + $error = "密码最少为 5 个字符,最大为 32 个字符。"; + } + if(!preg_match("/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims", $_POST['email'])) { + $error = "邮箱格式不正确。"; + } + if($pigeon->config['recaptcha_key'] !== '') { + if(!isset($_POST['g-recaptcha-response']) || !$pigeon->recaptcha_verify($_POST['g-recaptcha-response'])) { + $error = "Recaptcha 验证失败。"; + } + } + $username = mysqli_real_escape_string($pigeon->conn, $_POST['username']); + $password = password_hash($_POST['password'], PASSWORD_BCRYPT); + $email = mysqli_real_escape_string($pigeon->conn, $_POST['email']); + $registe_ip = mysqli_real_escape_string($pigeon->conn, $_SERVER['REMOTE_ADDR']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `username`='{$username}'")); + $token = md5(sha1($username . $password . $email . mt_rand(0, 99999999) . time())); + if($rs) { + $error = "此用户名已被注册。"; + } + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `email`='{$email}'")); + if($rs) { + $error = "此邮箱已被注册。"; + } + if($error == '') { + $ust = '200'; + $needVerify = ''; + if($pigeon->config['smtp']['enable']) { + $ust = '401'; + $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; + $siteurl = "{$http_type}{$_SERVER['HTTP_HOST']}/?s=checkmail&token={$token}"; + $pigeon->sendMail($email, "验证您的 {$pigeon->config['sitename']} 账号", "

您好,感谢您注册 {$pigeon->config['sitename']}。

请点击以下链接验证您的账号:

{$siteurl}

如果以上链接无法点击,请复制到浏览器地址栏中打开。

如果您没有注册本站账号,请忽略此邮件。

"); + $needVerify = "系统已发送一封邮件到您的邮箱,请点击邮件中的链接完成验证。"; + } + mysqli_query($pigeon->conn, "INSERT INTO `users` ( + `id`, + `username`, + `password`, + `email`, + `permission`, + `registe_ip`, + `registe_time`, + `latest_ip`, + `latest_time`, + `status`, + `token`) VALUES ( + NULL, + '{$username}', + '{$password}', + '{$email}', + 'user', + '{$registe_ip}', + '" . time() . "', + NULL, + NULL, + '{$ust}', + '{$token}' + )"); + $alert = "success"; + $error = "账号注册成功!{$needVerify}"; + } } - if($_POST['ispublic'] !== '0' && $_POST['ispublic'] !== '1' && $_POST['ispublic'] !== '2') { - $pigeon->Exception("Bad Request"); - } - $content = mysqli_real_escape_string($pigeon->conn, $_POST['content']); - $textlen = mb_strlen($content); - if($textlen < 1 || $textlen > 1000000) { - $pigeon->Exception("最少输入 1 个字符,最大输入 100 万个字符,当前已输入:{$textlen}。"); - } - mysqli_query($pigeon->conn, "INSERT INTO `posts` (`id`, `content`, `author`, `time`, `public`) VALUES (NULL, '{$content}', '{$_SESSION['user']}', '" . time() . "', '{$_POST['ispublic']}')"); - echo "Successful"; - } - break; - case "deletepost": - if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id'])) { - $apiUser = false; - if(!isset($_SESSION['user'])) { - if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { - $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); - if($rs) { - $_SESSION['user'] = $rs['username']; - $_SESSION['email'] = $rs['email']; - $apiUser = true; + $pigeon->getTemplate("header"); + $pigeon->getTemplate("register"); + $pigeon->getTemplate("footer"); + break; + case "logout": + if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { + echo ""; + exit; + } + unset($_SESSION['user']); + unset($_SESSION['email']); + unset($_SESSION['token']); + unset($_SESSION['seid']); + ?> + + + 跳转中... + + + + + + conn, $_GET['token']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); + if($rs) { + $_SESSION['user'] = $rs['username']; + $_SESSION['email'] = $rs['email']; + $apiUser = true; + } else { + $pigeon->Exception("Permission denied"); + } } else { - $pigeon->Exception("Permission denied"); + $pigeon->Exception("请先登录。"); } - } else { - $pigeon->Exception("请先登录。"); } - } - if(!$apiUser) { - if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { - $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); + if(!$apiUser) { + if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { + $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); + } } - } - if(!$pigeon->isAdmin($_SESSION['user'])) { - $pigeon->Exception("请求被拒绝。"); - } - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `posts` WHERE `id`='{$_GET['id']}'")); - if($rs) { - mysqli_query($pigeon->conn, "DELETE FROM `posts` WHERE `id`='{$_GET['id']}'"); + if($_POST['ispublic'] !== '0' && $_POST['ispublic'] !== '1' && $_POST['ispublic'] !== '2') { + $pigeon->Exception("Bad Request"); + } + $content = mysqli_real_escape_string($pigeon->conn, $_POST['content']); + $textlen = mb_strlen($content); + if($textlen < 1 || $textlen > 1000000) { + $pigeon->Exception("最少输入 1 个字符,最大输入 100 万个字符,当前已输入:{$textlen}。"); + } + mysqli_query($pigeon->conn, "INSERT INTO `posts` (`id`, `content`, `author`, `time`, `public`) VALUES (NULL, '{$content}', '{$_SESSION['user']}', '" . time() . "', '{$_POST['ispublic']}')"); echo "Successful"; - } else { - $pigeon->Exception("内容不存在。"); } - } - break; - case "changepublic": - if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id']) && isset($_GET['newstatus']) && preg_match("/^[0-9]{1}$/", $_GET['newstatus'])) { - $apiUser = false; - if(!isset($_SESSION['user'])) { - if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { - $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); - if($rs) { - $_SESSION['user'] = $rs['username']; - $_SESSION['email'] = $rs['email']; - $apiUser = true; + break; + case "deletepost": + if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id'])) { + $apiUser = false; + if(!isset($_SESSION['user'])) { + if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { + $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); + if($rs) { + $_SESSION['user'] = $rs['username']; + $_SESSION['email'] = $rs['email']; + $apiUser = true; + } else { + $pigeon->Exception("Permission denied"); + } } else { - $pigeon->Exception("Permission denied"); + $pigeon->Exception("请先登录。"); + } + } + if(!$apiUser) { + if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { + $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); } + } + if(!$pigeon->isAdmin($_SESSION['user'])) { + $pigeon->Exception("请求被拒绝。"); + } + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `posts` WHERE `id`='{$_GET['id']}'")); + if($rs) { + mysqli_query($pigeon->conn, "DELETE FROM `posts` WHERE `id`='{$_GET['id']}'"); + echo "Successful"; } else { - $pigeon->Exception("请先登录。"); + $pigeon->Exception("内容不存在。"); } } - if(!$apiUser) { - if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { - $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); + break; + case "changepublic": + if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id']) && isset($_GET['newstatus']) && preg_match("/^[0-9]{1}$/", $_GET['newstatus'])) { + $apiUser = false; + if(!isset($_SESSION['user'])) { + if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { + $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); + if($rs) { + $_SESSION['user'] = $rs['username']; + $_SESSION['email'] = $rs['email']; + $apiUser = true; + } else { + $pigeon->Exception("Permission denied"); + } + } else { + $pigeon->Exception("请先登录。"); + } } - } - if(!$pigeon->isAdmin($_SESSION['user'])) { - $pigeon->Exception("请求被拒绝。"); - } - if($_GET['newstatus'] !== "0" && $_GET['newstatus'] !== "1" && $_GET['newstatus'] !== "2") { - $pigeon->Exception("请求被拒绝。"); - } - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `posts` WHERE `id`='{$_GET['id']}'")); - if($rs) { - mysqli_query($pigeon->conn, "UPDATE `posts` SET `public`='{$_GET['newstatus']}' WHERE `id`='{$_GET['id']}'"); - echo "Successful"; - } else { - $pigeon->Exception("内容不存在。"); - } - } - break; - case "resendmail": - if(isset($_GET['user']) && preg_match("/^[A-Za-z0-9\_\-]{0,32}$/", $_GET['user'])) { - $alert = "danger"; - $error = ""; - $username = mysqli_real_escape_string($pigeon->conn, $_GET['user']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `username`='{$username}'")); - if($rs) { - if($rs['status'] !== '401') { - $error = "此账号已经通过验证。"; + if(!$apiUser) { + if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { + $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); + } + } + if(!$pigeon->isAdmin($_SESSION['user'])) { + $pigeon->Exception("请求被拒绝。"); + } + if($_GET['newstatus'] !== "0" && $_GET['newstatus'] !== "1" && $_GET['newstatus'] !== "2") { + $pigeon->Exception("请求被拒绝。"); + } + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `posts` WHERE `id`='{$_GET['id']}'")); + if($rs) { + mysqli_query($pigeon->conn, "UPDATE `posts` SET `public`='{$_GET['newstatus']}' WHERE `id`='{$_GET['id']}'"); + echo "Successful"; } else { - $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; - $siteurl = "{$http_type}{$_SERVER['HTTP_HOST']}/?s=checkmail&token={$rs['token']}"; - $pigeon->sendMail($rs['email'], "验证您的 {$pigeon->config['sitename']} 账号", "

您好,感谢您注册 {$pigeon->config['sitename']}。

请点击以下链接验证您的账号:

{$siteurl}

如果以上链接无法点击,请复制到浏览器地址栏中打开。

如果您没有注册本站账号,请忽略此邮件。

"); - $error = "系统已发送一封邮件到您的邮箱,请点击邮件中的链接完成验证。"; - $alert = "success"; + $pigeon->Exception("内容不存在。"); } - } else { - $error = "此账号不存在。"; } - $pigeon->getTemplate("header"); - $pigeon->getTemplate("login"); - $pigeon->getTemplate("footer"); - } - break; - case "checkmail": - if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { - $alert = "danger"; - $error = ""; - $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); - if($rs) { - if($rs['status'] !== '401') { - $error = "无效的验证链接。"; + break; + case "resendmail": + if(isset($_GET['user']) && preg_match("/^[A-Za-z0-9\_\-]{0,32}$/", $_GET['user'])) { + $alert = "danger"; + $error = ""; + $username = mysqli_real_escape_string($pigeon->conn, $_GET['user']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `username`='{$username}'")); + if($rs) { + if($rs['status'] !== '401') { + $error = "此账号已经通过验证。"; + } else { + $http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; + $siteurl = "{$http_type}{$_SERVER['HTTP_HOST']}/?s=checkmail&token={$rs['token']}"; + $pigeon->sendMail($rs['email'], "验证您的 {$pigeon->config['sitename']} 账号", "

您好,感谢您注册 {$pigeon->config['sitename']}。

请点击以下链接验证您的账号:

{$siteurl}

如果以上链接无法点击,请复制到浏览器地址栏中打开。

如果您没有注册本站账号,请忽略此邮件。

"); + $error = "系统已发送一封邮件到您的邮箱,请点击邮件中的链接完成验证。"; + $alert = "success"; + } } else { - mysqli_query($pigeon->conn, "UPDATE `users` SET `status`='200' WHERE `id`='{$rs['id']}'"); - $error = "验证成功,您可以登录了。"; - $alert = "success"; + $error = "此账号不存在。"; } - } else { - $error = "无效的验证链接。"; - } - $pigeon->getTemplate("header"); - $pigeon->getTemplate("login"); - $pigeon->getTemplate("footer"); - } - break; - case "msg": - if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id'])) { - $message = $pigeon->getMessageById($_GET['id']); - $pigeon->isAjax = false; - $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); - if($message) { $pigeon->getTemplate("header"); - echo $message; + $pigeon->getTemplate("login"); $pigeon->getTemplate("footer"); - } else { - $pigeon->getTemplate("header"); - echo "

404 Not found

"; - echo "

未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。

"; - $pigeon->getTemplate("footer"); - } - } - break; - case "getmsg": - if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { - $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); - } - if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id'])) { - $message = $pigeon->getRawMessageById($_GET['id']); - $pigeon->isAjax = false; - $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); - if($message) { - echo json_encode(Array( - 'content' => $message['content'], - 'public' => $message['public'], - 'author' => $message['author'], - 'time' => $message['time'] - )); - } else { - $pigeon->Exception("未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。"); } - } - break; - case "editpost": - if(isset($_GET['id']) && preg_match("/^[0-9]{1,10}$/", $_GET['id'])) { - if(!isset($_SESSION['user'])) { - if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { - $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); - if($rs) { - $_SESSION['user'] = $rs['user']; - $_SESSION['email'] = $rs['email']; + break; + case "checkmail": + if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { + $alert = "danger"; + $error = ""; + $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); + if($rs) { + if($rs['status'] !== '401') { + $error = "无效的验证链接。"; } else { - $pigeon->Exception("Permission denied"); + mysqli_query($pigeon->conn, "UPDATE `users` SET `status`='200' WHERE `id`='{$rs['id']}'"); + $error = "验证成功,您可以登录了。"; + $alert = "success"; } + } else { + $error = "无效的验证链接。"; + } + $pigeon->getTemplate("header"); + $pigeon->getTemplate("login"); + $pigeon->getTemplate("footer"); + } + break; + case "msg": + if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id'])) { + $message = $pigeon->getMessageById($_GET['id']); + $pigeon->isAjax = false; + $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); + if($message) { + $pigeon->getTemplate("header"); + echo $message; + $pigeon->getTemplate("footer"); + } else { + $pigeon->getTemplate("header"); + echo "

404 Not found

"; + echo "

未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。

"; + $pigeon->getTemplate("footer"); } - $pigeon->Exception("请先登录。"); } - if($_POST['ispublic'] !== '0' && $_POST['ispublic'] !== '1' && $_POST['ispublic'] !== '2') { - $pigeon->Exception("Bad Request"); + break; + case "getmsg": + if(!isset($_GET['seid']) || $_GET['seid'] !== $_SESSION['seid']) { + $pigeon->Exception("CSRF 验证失败,请尝试重新登录。"); } - $id = mysqli_real_escape_string($pigeon->conn, $_GET['id']); - $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `posts` WHERE `id`='{$id}'")); - if($rs) { - if($rs['author'] !== $_SESSION['user'] && !$pigeon->isAdmin($_SESSION['user'])) { + if(isset($_GET['id']) && preg_match("/^[0-9]{0,10}$/", $_GET['id'])) { + $message = $pigeon->getRawMessageById($_GET['id']); + $pigeon->isAjax = false; + $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); + if($message) { + echo json_encode(Array( + 'content' => $message['content'], + 'public' => $message['public'], + 'author' => $message['author'], + 'time' => $message['time'] + )); + } else { $pigeon->Exception("未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。"); } - $content = mysqli_real_escape_string($pigeon->conn, $_POST['content']); - $public = mysqli_real_escape_string($pigeon->conn, $_POST['ispublic']); - $textlen = mb_strlen($content); - if($textlen < 1 || $textlen > 1000000) { - $pigeon->Exception("最少输入 1 个字符,最大输入 100 万个字符,当前已输入:{$textlen}。"); + } + break; + case "editpost": + if(isset($_GET['id']) && preg_match("/^[0-9]{1,10}$/", $_GET['id'])) { + if(!isset($_SESSION['user'])) { + if(isset($_GET['token']) && preg_match("/^[A-Za-z0-9]{32}$/", $_GET['token'])) { + $token = mysqli_real_escape_string($pigeon->conn, $_GET['token']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `users` WHERE `token`='{$token}'")); + if($rs) { + $_SESSION['user'] = $rs['user']; + $_SESSION['email'] = $rs['email']; + } else { + $pigeon->Exception("Permission denied"); + } + } + $pigeon->Exception("请先登录。"); + } + if($_POST['ispublic'] !== '0' && $_POST['ispublic'] !== '1' && $_POST['ispublic'] !== '2') { + $pigeon->Exception("Bad Request"); + } + $id = mysqli_real_escape_string($pigeon->conn, $_GET['id']); + $rs = mysqli_fetch_array(mysqli_query($pigeon->conn, "SELECT * FROM `posts` WHERE `id`='{$id}'")); + if($rs) { + if($rs['author'] !== $_SESSION['user'] && !$pigeon->isAdmin($_SESSION['user'])) { + $pigeon->Exception("未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。"); + } + $content = mysqli_real_escape_string($pigeon->conn, $_POST['content']); + $public = mysqli_real_escape_string($pigeon->conn, $_POST['ispublic']); + $textlen = mb_strlen($content); + if($textlen < 1 || $textlen > 1000000) { + $pigeon->Exception("最少输入 1 个字符,最大输入 100 万个字符,当前已输入:{$textlen}。"); + } + mysqli_query($pigeon->conn, "UPDATE `posts` SET `content`='{$content}',`public`='{$public}' WHERE `id`='{$id}'"); + echo "Successful"; + } else { + $pigeon->Exception("未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。"); } - mysqli_query($pigeon->conn, "UPDATE `posts` SET `content`='{$content}',`public`='{$public}' WHERE `id`='{$id}'"); - echo "Successful"; - } else { - $pigeon->Exception("未找到指定的消息内容,该消息已被删除或者您暂时没有权限查看。"); } - } - break; - } -} else { - // 默认首页 - $pigeon->before = null; - $pigeon->search = null; - if(isset($_GET['time']) && preg_match("/^[0-9\:\- ]+$/", $_GET['time'])) { - $beforeTime = strtotime($_GET['time']); - $pigeon->before = $beforeTime ? $beforeTime : null; - } - if(isset($_GET['search']) && $_GET['search'] !== '') { - $pigeon->search = mysqli_real_escape_string($pigeon->conn, $_GET['search']); - } - $pigeon->isAjax = false; - $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); - $pigeon->getTemplate("header"); - if(isset($_GET['user']) && preg_match("/^[A-Za-z0-9\_\-]{0,32}$/", $_GET['user'])) { - $pigeon->getTimeline($_GET['user'], true, 1); + break; + } } else { - $pigeon->getTimeline(null, true, 1); + // 默认首页 + $pigeon->before = null; + $pigeon->search = null; + if(isset($_GET['time']) && preg_match("/^[0-9\:\- ]+$/", $_GET['time'])) { + $beforeTime = strtotime($_GET['time']); + $pigeon->before = $beforeTime ? $beforeTime : null; + } + if(isset($_GET['search']) && $_GET['search'] !== '') { + $pigeon->search = mysqli_real_escape_string($pigeon->conn, $_GET['search']); + } + $pigeon->isAjax = false; + $pigeon->isLogin = (isset($_SESSION['user']) && $_SESSION['user'] !== ''); + $pigeon->getTemplate("header"); + if(isset($_GET['user']) && preg_match("/^[A-Za-z0-9\_\-]{0,32}$/", $_GET['user'])) { + $pigeon->getTimeline($_GET['user'], true, 1); + } else { + $pigeon->getTimeline(null, true, 1); + } + $pigeon->getTemplate("footer"); } - $pigeon->getTemplate("footer"); -} +?>