public function run() { $users = User::getUserArrayByExpire(); $notificationMail = Option::get('mail_stop_expire_notification'); $mailContentTemplate = Option::get('custom_mail_stop_expire_content'); if (!$notificationMail) { Option::set('mail_stop_expire_notification', 0); // 设置邮件提醒的系统参数 } $mailer = Mailer::getInstance(); $mailer->toQueue(true); foreach ($users as $user) { $user->stop(); Logger::getInstance()->info('user [' . $user->email . '] 未续费或流量超用已被暂停服务'); if ($notificationMail) { $mail = new Mail(); $mail->to = $user->email; $mail->subject = '[' . SITE_NAME . '] ' . "用户 {$user->nickname},您的账户由于未续费或流量超用已被暂停服务"; $params = ['nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)]; $mailContent = Utils::placeholderReplace($mailContentTemplate, $params); $mailContent .= "<p style=\"padding: 1.5em 1em 0; color: #999; font-size: 12px;\">—— 本邮件由 " . SITE_NAME . " (<a href=\"" . BASE_URL . "\">" . BASE_URL . "</a>) 账户管控系统发送</p>"; $mail->content = $mailContent; $mailer->send($mail); } } // 避免频繁更新 Option 单例对象,循环结束后再执行 if ($notificationMail) { Option::set('mail_queue', 1); } // 2016-04-26 15:00 - by @Sendya Fixed issue #62 // User::enableUsersByExpireTime(); // 启用已续费且流量未超过的用户 }
public function index() { $data['user'] = UserModel::getCurrent(); $data['users'] = UserModel::getUserList(); $data['planList'] = json_decode(Option::get('custom_plan_name'), true); Template::setContext($data); Template::setView('admin/user'); }
public function inviteOldList() { $data['user'] = User::getCurrent(); $data['inviteList'] = InviteModel::getInviteArray(1); $data['planList'] = json_decode(Option::get('custom_plan_name'), true); array_splice($data['planList'], -1, 1); Template::setContext($data); Template::setView('admin/invite'); }
public function toQueue($bool, $flag = false) { $this->queued = $bool; if (!$flag) { Option::set('mail_queue', $bool === true ? 1 : 0); } else { Option::set('mail_queue', 1); } }
public function __construct() { $className = Utils::getShortName($this); $this->isAvailable(); $config = Option::get('MAIL_' . $className); if (!$config) { throw new Error("邮件模块 " . $className . " 配置不完整,无法使用。"); } $this->config = json_decode($config, true); }
/** * 创建订单 * */ public function create() { $user = User::getCurrent(); $data['custom_plan_name'] = json_decode(Option::get('custom_plan_name'), true); $data['custom_transfer_level'] = json_decode(Option::get('custom_transfer_level'), true); $plan = strtoupper($_GET['plan']); $money = 0; switch ($plan) { case 'B': $money = 12; break; case 'C': $money = 20; break; case 'D': $money = 35; break; case 'VIP': $money = 50; break; case 'Z': $money = 50; break; } /* if(count(MOrder::getByUserId($user->uid)) > 0) { header("Location: /order/lists"); exit(); } */ $order = new MOrder(); $order->uid = $user->uid; $order->createTime = time(); $order->money = $money; $order->plan = $plan; $order->status = 0; $order->type = 0; // 类型: 0 - 购买套餐 1 - 账户金额充值 2 - 购买卡号 $remark = $order->type == 0 ? "购买套餐 " : $order->type == 1 ? "金额充值 " : "购买卡号 "; $remark .= $plan . ', ' . $money . '元'; $order->remark = $remark; $order->save(Model::SAVE_INSERT); Template::putContext("order_id", $order->id); Template::putContext('transfer', $data['custom_transfer_level'][$plan]); Template::putContext('plan', $plan); Template::putContext('plan_name', $data['custom_plan_name'][$plan]); Template::putContext('money', $money); Template::putContext('user', $user); Template::setView('panel/order_create'); }
public static function set($k, $v) { $sql = "UPDATE options SET v=:v WHERE k=:k"; if (Option::get($k) == null) { $sql = "INSERT INTO options(k, v) VALUES(:k, :v)"; } $inTransaction = DB::getInstance()->inTransaction(); if (!$inTransaction) { DB::getInstance()->beginTransaction(); } $statement = DB::getInstance()->prepare($sql); $statement->bindParam(":k", $k); $statement->bindParam(":v", $v); $statement->execute(); if (!$inTransaction) { DB::getInstance()->commit(); } self::$list = self::init(); }
public function run() { if (!Option::get('mail_queue')) { return; } Logger::getInstance()->info('mail queue running..'); $mailer = Mailer::getInstance(); $mailer->toQueue(false, true); // set to queue. $mailQueue = MMail::getQueueList(); if (count($mailQueue) > 0) { foreach ($mailQueue as $mail) { $mail->delete(); $mail->content = htmlspecialchars_decode($mail->content); Logger::getInstance()->info('send mail to ' . $mail->to); $mailer->send($mail); } } else { Option::set('mail_queue', 0); } }
/** * 签到 * * @JSON */ public function checkIn() { $user = User::getCurrent(); $result = array('error' => 1, 'message' => '签到失败或已签到。'); if ($user->lastCheckinTime <= strtotime(date('Y-m-d 00:00:00', time()))) { $user = User::getUserByUserId($user->uid); $user->lastCheckinTime = time(); $checkinTransfer = rand(intval(Option::get('check_transfer_min')), intval(Option::get('check_transfer_max'))) * Utils::MB; $user->transfer = $user->transfer + $checkinTransfer; $_SESSION['currentUser'] = $user; $user->save(); $result['time'] = date("m-d H:i:s", $user->lastCheckinTime); $result['message'] = '签到成功, 获得' . Utils::flowAutoShow($checkinTransfer) . ' 流量'; $result['error'] = 0; } else { $result['message'] = '你已经在 ' . date('Y-m-d H:i:s', $user->lastCheckinTime) . " 时签到过."; } return $result; }
} catch (PDOException $e) { echo colorize('Database not available! Please modify ./Data/Config.php and try again', 'WARNING') . PHP_EOL; break; } if (Option::getConfig('ENCRYPT_KEY') == 'Please generate key and paste here') { Option::setConfig('ENCRYPT_KEY', Option::createKey()); } if (Option::getConfig('COOKIE_KEY') === null) { $str = file_get_contents(DATA_PATH . 'Config.php'); preg_match("/define\\('ENCRYPT_KEY', '(.*)'\\);/", $str, $res); if (count($res) >= 1) { $str2 = preg_replace("/define\\('ENCRYPT_KEY', '(.*)'\\);/", $res[0] . PHP_EOL . "define('COOKIE_KEY', '" . Option::createKey() . "');", $str); } file_put_contents(DATA_PATH . 'Config.php', $str2); } elseif (Option::getConfig('COOKIE_KEY') == 'Please generate key and paste here' || Option::getConfig('COOKIE_KEY') == '') { Option::setConfig('COOKIE_KEY', Option::createKey()); } echo 'Done!' . PHP_EOL; echo 'Now migrating database...' . PHP_EOL; if (PATH_SEPARATOR != ':') { $phinxCommand = ROOT_PATH . 'Package\\bin\\phinx.bat'; } else { $phinxCommand = PHP_BINARY . ' ' . ROOT_PATH . 'Package/robmorgan/phinx/bin/phinx'; } exec($phinxCommand . ' migrate', $return_arr, $return_arr2); print_arr($return_arr); if (stripos($return_arr[count($return_arr) - 1], 'All Done.') === false) { echo colorize(PHP_EOL . PHP_EOL . 'Failed to migrate database, you can try it manually: ', 'WARNING') . colorize('./Package/bin/phinx migrate', 'WARNING') . PHP_EOL; // rollback exec($phinxCommand . ' rollback', $return_arr, $return_arr2); break;
/** * @JSON * @Authorization */ public function nodeQuery() { $API_BASE = "https://nodequery.com/api/"; $API_KEY = Option::get('SERVER_NODE_QUERY_API_KEY'); if (!$API_KEY) { throw new Error('API_KEY is not available', 500); } $status = array(); $result = Http::doGet($API_BASE . 'servers?api_key=' . $API_KEY, array()); if ($result) { $result = json_decode($result, true); foreach ($result['data'] as $node) { $status[] = array('id' => $node['id'], 'status' => $node['status'], 'availability' => $node['availability'], 'update_time' => $node['update_time'], 'name' => $node['name'], 'load_percent' => $node['load_percent'], 'load_average' => $node['load_average'], 'ram_total' => $node['ram_total'], 'ram_usage' => $node['ram_usage'], 'disk_total' => $node['disk_total'], 'disk_usage' => $node['disk_usage_'], 'current_rx' => $node['current_rx'], 'current_tx' => $node['current_tx']); } } return $status; }
/** * 激活(使用)卡号 * @JSON */ public function activation() { $user = User::getUserByUserId(User::getCurrent()->uid); $result = array('error' => 1, 'message' => '该卡已经被使用或不存在。'); if ($_POST['actCard'] != null) { $actCard = htmlspecialchars(trim($_POST['actCard'])); $card = Mcard::queryCard($actCard); if (!$card || !$card->status) { return $result; } $custom_transfer_level = json_decode(Option::get('custom_transfer_level'), true); $custom_transfer_repeat = json_decode(Option::get('custom_transfer_repeat'), true); /* 0-套餐卡 1-流量卡 2-测试卡 3-余额卡 */ if ($card->type == 0) { if ($user->plan == 'Z' && $user->transfer > $user->flow_up + $user->flow_down) { $result['message'] = '您的流量套餐尚未使用完毕。无法转换到 ' . Utils::planAutoShow($card->info) . ' 套餐'; return $result; } //判断账户卡号类型是否一致 一致则无视系统叠加开关进行 叠加时间 $user->payTime = time(); if ($user->flow_up + $user->flow_down < $user->transfer) { $user->enable = 1; } else { $user->enable = 0; } $cardDay = 31; if (is_numeric($card->expireTime)) { $cardDay = intval($card->expireTime); } $expireTime = 0; if ($user->plan == $card->info) { // 卡片与账户类型相等 if ($user->expireTime > time()) { $expireTime = $user->expireTime + 3600 * 24 * $cardDay; // 到期时间 = 当前账户到期时间+卡片时间 } else { $expireTime = time() + 3600 * 24 * $cardDay; // 到期时间 = 当前系统续费时间+卡片时间 } } else { if ($user->expireTime < time() || !$custom_transfer_repeat) { $expireTime = time() + 3600 * 24 * $cardDay; // 到期时间 = 不叠加原时间 (当前系统续费时间+卡片时间) } else { $expireTime = $user->expireTime + 3600 * 24 * $cardDay; // 到期时间 = 当前账户到期时间+卡片时间 } } $user->expireTime = $expireTime; $user->plan = $card->info; $user->transfer = Utils::GB * intval($custom_transfer_level[$user->plan]); $result['message'] = '您的账户已升级到 ' . Utils::planAutoShow($user->plan) . ' ,共有流量 ' . Utils::flowAutoShow($user->transfer) . ', 已用 ' . Utils::flowAutoShow($user->flow_down + $user->flow_up) . ', 到期时间:' . date('Y-m-d H:i:s', $user->expireTime); } elseif ($card->type == 1) { if ($user->plan == 'Z') { $user->transfer += intval($card->info) * Utils::GB; // 如果之前是 流量 套餐,则递增 } else { $user->transfer = intval($card->info) * Utils::GB; // 如果之前是 普通套餐,则清空总流量并设定新流量 $user->flow_up = 0; $user->flow_down = 0; } if ($user->flow_up + $user->flow_down < $user->transfer) { $user->enable = 1; } else { $user->enable = 0; } $user->plan = 'Z'; // 强制设定为Z $user->expireTime = strtotime("+1 year"); // 账户可用时间增加一年 $result['message'] = '您的账户已经激活固定流量套餐,共有流量' . Utils::flowAutoShow($user->transfer) . ' ,该流量到期时间 ' . date('Y-m-d H:i:s', $user->expireTime) . ', 感谢您的使用(注意:流量使用完毕前无法通过套餐卡转换为套餐包月用户)'; } elseif ($card->type == 2) { $user_test_day = Option::get('user_test_day') ?: 7; if ($user->plan != 'A') { return array('error' => 1, 'message' => '喂喂,你不是测试账户诶? 没办法帮你续命。'); } $user->plan = 'A'; $user->payTime = time(); if ($user->expireTime < time()) { $user->expireTime = time() + 3600 * 24 * intval($user_test_day); // 到期时间 } else { $user->expireTime = $user->expireTime + 3600 * 24 * intval($user_test_day); // 到期时间 } $user->transfer = Utils::GB * intval($custom_transfer_level[$user->plan]); $user->flow_down = 0; $user->flow_up = 0; $user->enable = 1; $result['message'] = '您的账户已经激活测试套餐,共有流量' . Utils::flowAutoShow($user->transfer) . ' ,到期时间 ' . date('Y-m-d H:i:s', $user->expireTime) . ', 感谢您的使用'; } elseif ($card->type == 3) { // 余额卡 $user->money += intval($card->info); $user->save(); $result['message'] = '余额充值成功,您当前余额为 ' . $user->money . ' 元'; } $card->destroy(); // 将此卡片禁止 $user->save(); $_SESSION['currentUser'] = $user; // 将用户信息更新到 session 中. } return $result; }
/** * 账户类型显示自定义名称 * * @param $plan * @return string */ public static function planAutoShow($plan) { // planNames 从数据库中获取 $planNames = json_decode(Option::get('custom_plan_name'), true); $planName = $planNames[$plan]; if ($planName == '') { $planName = '测试账户'; } return $planName; }
/** * 更新 邮件系统设置 * * @JSON */ public function update() { $result['error'] = 0; $result['message'] = '保存完成'; foreach ($_POST as $key => $val) { if (!empty($val) && strpos($key, 'mail_') !== false) { if (strpos($key, 'mailer') === false) { // 判断是否为 mail_mailer <- 这个字段是用于是被当前设定的邮件类名,此配置无需存入数据库 $k = str_replace('mail_', '', $key); $data[$k] = trim($val); } } } if (!empty($_POST['mail_mailer'])) { $config = json_encode($data); $mailer = trim($_POST['mail_mailer']); Option::set('MAIL_' . $mailer, $config); Option::set('MAIL_AVAILABLE', $mailer); } else { $result['error'] = 1; $result['message'] = '保存失败,参数不完整'; } Option::init(); return $result; }
public function test() { $alipay = new Alipay(Option::get('alipay_conf')); $alipay->run(); }
public static function fileCheck() { $channel = Option::get('channel') == 'dev' ?: 'stable'; $current_version = Option::get("version"); $data = self::doGet(self::UPDATE_SERVER . "file.json?channel={$channel}&ver={$current_version}"); if (!$data) { return -1; } // 请求更新服务器失败 $data = json_decode($data, true); $file_list = $data['list']; if (!$file_list) { return -2; } // 更新服务器文件列表为空 $err_file = $list = array(); foreach ($file_list as $file) { $path = $file['path']; $hash = $file['hash']; $file_hash = md5_file(ROOT_PATH . "{$path}"); if ($file_hash != $hash) { $err_file[] = array($path, $hash); $list[] = $path; } } if (!$list) { return 0; } // 无文件更新 Option::set('new_version', 1); sort($list); sort($err_file); Downloader::save('kk_updater', $err_file); Downloader::save('need_download', $err_file); return $list; }
/** * @JSON * @return array * @throws Error */ public function saveCustomMailContent() { $type = $_POST['custom_type']; // 获得修改类型 if (strpos($type, 'custom_mail_') !== false) { $content = $_POST['content']; // 取得修改的内容 if (!$content) { throw new Error('Parameter error', 405); } Option::set('$type', $content); return array('error' => 0, 'message' => '保存完毕'); } else { throw new Error('Parameter error', 405); } }
public function __construct() { $className = Utils::getShortName($this); $this->isAvailable(); $config = Option::get('MAIL_' . $className); if (!$config) { throw new Error("邮件模块 " . $className . " 配置不完整,无法使用。"); } $this->config = json_decode($config, true); $this->setFrom($this->config['from']); //设置发件人 格式为( 发件人名称 <*****@*****.**> ) $this->setAddress($this->config['smtp_name']); // if ($this->config['smtp_ssl'] == 'ssl') { //ssl 模式 $this->setServer($this->config['server'], $this->config['smtp_name'], $this->config['smtp_pass'], 465, true); } else { // 非ssl $this->setServer($this->config['server'], $this->config['smtp_name'], $this->config['smtp_pass']); } }
/** * @JSON * @throws \Core\Error */ public function forgePwd() { $result = array('error' => 1, 'message' => '请求找回密码失败,请刷新页面重试。'); $siteName = SITE_NAME; if (isset($_POST['email']) && $_POST['email'] != '') { $user = User::getUserByEmail(htmlspecialchars(trim($_POST['email']))); if (!$user) { return $result; } if ($user->enable == 0) { $verify_code = json_decode($user->forgePwdCode, true)['verification']; if ($verify_code != null) { $result['message'] = '您的账户还未进行邮箱校验,请校验完毕后再试!'; return $result; } } $user->lastFindPasswdTime = time(); if ($user->lastFindPasswdCount != 0 && $user->lastFindPasswdCount > 2) { $result['message'] = '找回密码重试次数已达上限!'; return $result; } $code = Utils::randomChar(10); $forgePwdCode['code'] = $code; $forgePwdCode['time'] = time(); $user->forgePwdCode = json_encode($forgePwdCode); $content = Option::get('custom_mail_forgePassword_content'); $params = ['code' => $code, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)]; $content = Utils::placeholderReplace($content, $params); $mailer = Mailer::getInstance(); $mail = new \Model\Mail(); $mail->to = $user->email; $mail->subject = "[" . SITE_NAME . "] Password Recovery"; $mail->content = $content; $mailer->toQueue(true); // 添加到邮件列队 $isOk = $mailer->send($mail); $user->save(); $result['uid'] = $user->uid; if ($isOk) { $result['message'] = '验证代码已经发送到该注册邮件地址,请注意查收!<br/>请勿关闭本页面,您还需要验证码来验证您的账户所有权才可重置密码!!'; $result['error'] = 0; } else { $result['message'] = '邮件发送失败, 请联系管理员检查邮件系统设置!'; $result['error'] = 1; } return $result; } else { if ($_POST['code'] != '' && $_POST['uid'] != '') { $uid = $_POST['uid']; $code = trim($_POST['code']); $user = User::GetUserByUserId(trim($uid)); $forgePwdCode = json_decode($user->forgePwdCode, true); // forgePwdCode.length > 1 且 验证码一样 且 时间不超过600秒(10分钟) if (count($forgePwdCode) > 1 && $forgePwdCode['code'] == $code && time() - intval($forgePwdCode['time']) < 600) { $newPassword = Utils::randomChar(10); $user->setPassword($newPassword); $user->lastFindPasswdCount = 0; $user->lastFindPasswdTime = 0; $user->save(); $content = Option::get('custom_mail_forgePassword_content_2'); $params = ['code' => $code, 'newPassword' => $newPassword, 'nickname' => $user->nickname, 'email' => $user->email, 'useTraffic' => Utils::flowAutoShow($user->flow_up + $user->flow_down), 'transfer' => Utils::flowAutoShow($user->transfer), 'expireTime' => date('Y-m-d H:i:s', $user->expireTime)]; $content = Utils::placeholderReplace($content, $params); $mailer = Mailer::getInstance(); $mail = new \Model\Mail(); $mail->to = $user->email; $mail->subject = "[" . SITE_NAME . "] Your new Password"; $mail->content = $content; $mailer->toQueue(true); // 添加到邮件列队 $isOk = $mailer->send($mail); if ($isOk) { $result['message'] = '新密码已经发送到该账户邮件地址,请注意查收!<br/> 并且请在登录后修改密码!'; $result['error'] = 0; } else { $result['message'] = '邮件发送失败, 请联系管理员检查邮件系统设置!'; $result['error'] = 1; } } else { $result['message'] = '验证码已经超时或者 验证码填写不正确。请再次确认'; $result['error'] = -1; } return $result; } else { Template::putContext('user', User::getCurrent()); Template::setView('panel/forgePwd'); } } return $result; }