| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541 |
- <?php
- class userController extends Controller
- {
- private $uid;
- public $initphp_list = array(
- 'index',
- 'node',
- 'my',
- 'modify',
- 'login',
- 'logout',
- 'qr',
- 'reg',
- 'docheckin',
- 'code',
- 'unfreeze',
- 'reset'
- );
- public function __construct()
- {
- parent::__construct();
- $this->checkLogin();
- }
- public function run()
- {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- $this->view->set_tpl("index/user"); // 中间的模板
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $userinfo['gravatar'] = $this->get_gravatar($userinfo['email']);
- $this->view->assign("userinfo", $userinfo);
- $this->view->assign("active", "userindex");
- $this->view->assign("title", $title);
- $this->view->display();
- }
- public function index()
- {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- $this->view->set_tpl("index/user"); // 中间的模板
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $userinfo['gravatar'] = $this->get_gravatar($userinfo['email']);
- $this->view->assign("userinfo", $userinfo);
- $this->view->assign("active", "userindex");
- $this->view->assign("title", $title);
- $this->view->display();
- }
- /**
- * 节点列表
- */
- public function node()
- {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $node = self::getNode();
- $nodeinfo = $node->getAllNode();
- foreach ($nodeinfo as $k => $v) {
- $data[$v['node_type']][] = $v;
- }
- $userinfo['gravatar'] = $this->get_gravatar($userinfo['email']);
- $this->view->assign("userinfo", $userinfo);
- $this->view->assign("title", $title);
- $this->view->assign("active", "node");
- $this->view->assign("data", $data);
- $this->view->set_tpl("index/node");
- $this->view->display();
- }
- /**
- * 我的信息
- */
- public function my()
- {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- $this->view->set_tpl("index/myinfo"); // 中间的模板
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $userinfo['gravatar'] = $this->get_gravatar($userinfo['email']);
- $this->view->assign("userinfo", $userinfo);
- $this->view->assign("active", "info");
- $this->view->assign("title", $title);
- $this->view->display();
- }
- /**
- * 签到获取流量
- */
- public function docheckin()
- {
- $config = InitPHP::getConfig();
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- if ($userinfo['last_check_in_time'] > strtotime(date("Y-m-d"))) {
- JsMessage("您当前不能进行签到!", '/user/index.html');
- die();
- }
- if (($userinfo['transfer_enable'] - $userinfo['u'] - $userinfo['d']) < 2048 * 1024 * 1024) {
- $transfer_to_add = 2048;
- } else {
- $transfer_to_add = rand($config['check_min'], $config['check_max']);
- }
- $data['transfer_enable'] = $userinfo['transfer_enable'] + $transfer_to_add * 1024 * 1024;
- $data['last_check_in_time'] = time();
- $result = $user->updatePortPass($this->uid, $data);
- if ($result) {
-
- JsMessage("签到成功,你本次签到获得流量" . $transfer_to_add . "M!", '/user/index.html');
- } else
- JsMessage("您当前不能进行签到!", '/user/index.html');
- }
- /**
- * 获取邀请码
- */
- public function code()
- {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- if ($userinfo['plan'] != "VIP") {
- JsMessage("您无权查看邀请码!");
- }
- $userinfo['gravatar'] = $this->get_gravatar($userinfo['email']);
- $code = $user->getInvite();
- $code = array(
- $code
- );
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $this->view->set_tpl("index/code");
- $this->view->assign("userinfo", $userinfo);
- $this->view->assign("active", "code");
- $this->view->assign("title", $title);
- $this->view->assign("code", $code);
- $this->view->display();
- }
- /**
- * 二维码显示
- */
- public function qr()
- {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- $nodeid = $this->controller->get_get("id");
- $node = InitPHP::getService("node");
- $nodeinfo = $node->getNodeById($nodeid);
- $ssurl = $nodeinfo['node_method'] . ":" . $userinfo['passwd'] . "@" . $nodeinfo['node_server'] . ":" . $userinfo['port'];
- $ssqr = "ss://" . base64_encode($ssurl);
- $qrcode = InitPHP::getLibrarys("qrcode");
- $qrcode->getQr($ssqr);
- die();
- }
- /**
- * 修改用户资料
- */
- public function modify()
- {
- $do = $this->controller->get_gp("do");
- if ($do == "info") {
- $data = $this->controller->get_gp(array(
- 'nowpassword',
- 'password',
- 'email'
- ));
- $user = self::getUserService();
- $result = $user->updateUserinfo($this->uid, $data);
- if (! $result) {
- JsMessage("当前密码错误!");
- } else {
- JsMessage("修改成功!", "/user/index.html");
- }
- } elseif ($do == "port_pass") {
- $data = $this->controller->get_gp(array(
- 'passwd'
- ));
- $user = self::getUserService();
- $result = $user->updatePortPass($this->uid, $data);
- JsMessage("修改成功", "/user/index.html");
- } else {
- $user = self::getUserService();
- $userinfo = $user->getUserById($this->uid);
- $this->view->set_tpl("index/modify"); // 中间的模板
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $userinfo['gravatar'] = $this->get_gravatar($userinfo['email']);
- $this->view->assign("userinfo", $userinfo);
- $this->view->assign("active", "modify");
- $this->view->assign("title", $title);
- $this->view->display();
- }
- }
- public function reset(){
- $do=$this->controller->get_gp("do");
- $user = self::getUserService();
- if ($do=="pass"){
- $username=$this->controller->get_gp("username");
- $userinfo=$user->getUserByNameOrEmail($username);
- $code = md5(uniqid("shadowsocks" . time()));
- $result = $user->doReset($userinfo['uid'], $code);
- if ($userinfo) {
- $subject = '重置你的shadowsocks5密码,如果不是本人操作,请忽略本邮件!';
- $message = "<html>
- <head>
- <title>你正在重置你的shadowsocks5密码,如果不是本人操作,请忽略本邮件!</title>
- </head>
- <body>
- <p>尊敬的ss5用户:".$userinfo['user_name']."</p>
- <table style='width: 99.8%; '><tbody><tr><td id='QQMAILSTATIONERY’ style='background:url(https://rescdn.qqmail.com/zh_CN/htmledition/images/xinzhi/bg/a_08.jpg) no-repeat #f3f3eb; min-height:550px; padding: 100px 55px 200px 120px;'><font face=’宋体’ color='#FF0000’ size='5'>如需重置,请点击以下链接进行操作:<br > <a href='".SITE_URL."/user/reset.html?do=resetpass&uid=" . $userinfo['uid']. "&code=" . $code . "'>立即重置</a><br>如果您无法直接点击,请将以下网址复制到浏览器访问:".SITE_URL."/user/reset.html?do=resetpass&uid=" . $userinfo['uid'] . "&code=" . $code . "</font></td></tr></tbody></table>
- </body>
- </html>";
- sendmail($userinfo['email'],$subject,$message,'webmaster@tailsocks.com');
- JsMessage("重置密码已经提交,请查收邮箱".$userinfo['email']."进行下一步操作!");
- }else{
- JsMessage("用户不存在!");
- }
- }elseif ($do=='resetpass'){
- $uid=$this->controller->get_gp("uid");
- $code = $this->controller->get_gp("code");
- $pass=$this->controller->get_gp("password");
- if (strlen($pass)>6){
- $result=$user->doReset($uid, $code,$pass);
- if ($result) {
- JsMessage("密码修改成功,请使用新密码登录!","/user/login.html");
- } else {
- JsMessage("密码修改失败,可能是超时造成的!", '/');
- }
- }else {
- $result = $user->doReset($uid, $code, true);
- if ($result) {
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $this->view->assign("title", $title);
- $this->view->set_tpl("index/resetpass"); // 中间的模板
- $this->view->display();
- } else {
- JsMessage("非法访问!", '/user/index.html');
- }
- }
-
- }
- else {
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $this->view->assign("title", $title);
- $this->view->set_tpl("index/reset"); // 中间的模板
- $this->view->display();
- }
- }
- public function unfreeze()
- {
- $user = self::getUserService();
- $do = $this->controller->get_gp("do");
- if ($do == 'reset') {
- $code = $this->controller->get_gp("code");
- $result = $user->doFreeze($this->controller->get_gp("uid"), $code, true);
- if ($result) {
- JsMessage("您的账号已经解除冻结,可以正常使用!", '/user/index.html');
- } else {
- JsMessage("解冻失败,请确认步骤是否正确!", '/user/index.html');
- }
- } else {
- $code = md5(uniqid("shadowsocks" . time()));
- $result = $user->doFreeze($this->uid, $code);
- $userinfo = $user->getUserById($this->uid);
- if ($userinfo) {
- $subject = '请激活你的shadowsocks5!如果不是本人操作,请忽略本邮件!';
- $message = "<html>
- <head>
- <title>请激活你的shadowsocks5!如果不是本人操作,请忽略本邮件!</title>
- </head>
- <body>
- <p>尊敬的ss5用户:".$userinfo['user_name']."</p>
- <table style='width: 99.8%; '><tbody><tr><td id='QQMAILSTATIONERY’ style='background:url(https://rescdn.qqmail.com/zh_CN/htmledition/images/xinzhi/bg/a_08.jpg) no-repeat #f3f3eb; min-height:550px; padding: 100px 55px 200px 120px;'><font face=’宋体’ color='#FF0000’ size='5'>如需解除冻结,请点击以下链接进行解冻:<br > <a href='".SITE_URL."/user/unfreeze.html?do=reset&uid=" . $this->uid . "&code=" . $code . "'>立即激活</a><br>如果您无法直接点击,请将以下网址复制到浏览器访问:".SITE_URL."/user/unfreeze.html?do=reset&uid=" . $this->uid . "&code=" . $code . "</font></td></tr></tbody></table>
- </body>
- </html>";
- sendmail($userinfo['email'],$subject,$message,'webmaster@tailsocks.com');
- JsMessage("解冻申请已经提交,请查收邮箱进行下一步解冻!");
- }else{
- JsMessage("操作失败!");
- }
- }
- }
- public function login()
- {
- if ($this->controller->get_gp("do") == "login") {
- $data = $this->controller->get_gp(array(
- "username",
- "password",
- "remember_me"
- ));
- $user = self::getUserService();
- $result = $user->login($data);
- if ($result) {
- $session = self::getSession();
- $function = self::getFunction();
- $session->set('userid', intval($result['uid']));
- $session->set('username', htmlspecialchars($result['user_name']));
- $function->goto_url('/user/index.html');
- } else {
- JsMessage("用户名或密码错误!");
- }
- } else {
- $config = InitPHP::getConfig();
- $title = $config['sitename'];
- $this->view->assign("title", $title);
- $this->view->set_tpl("index/login"); // 中间的模板
- $this->view->display();
- }
- }
- public function reg()
- {
- $config = InitPHP::getConfig();
- if ($this->controller->get_gp("do") == "reg") {
- $user = self::getUserService();
- $userinfo = $this->controller->get_gp(array(
- "username",
- "password",
- "email",
- "code"
- ));
- if ($userinfo['username'] == "" || $userinfo['email'] == "") {
- JsMessage("用户名或邮箱不能为空!");
- }
- if ($config['isinviteonly']) {
- if ($user->checkInvite($userinfo['code'])) { // 检测邀请码
- if ($user->checkUser($userinfo)) {
- $data = array();
- $data['user_name'] = $userinfo['username'];
- $data['email'] = $userinfo['email'];
- $data['pass'] = md5($userinfo['password']);
- $data['passwd'] = rand(10000, 99999);
- $data['transfer_enable'] = $config['transfer'];
- // $data['port'] = $port;
- $data['t'] = 0;
- $data['u'] = 0;
- $data['d'] = 0;
- $data['plan'] = "A";
- $data['switch'] = 1;
- $data['enable'] = 1;
- $data['type'] = 7;
- $data['reg_date'] = date("Y-m-d H:i:s");
- $data['last_login_time'] = time();
- $data['invite_code'] = $userinfo['code'];
- $data['invite_num'] = $config['invite_num'];
- $data['money'] = 0.00;
- $uid = $user->createUser($data);
- if ($uid) {
- $user->deleteInvite($userinfo['code']);
- $session = self::getSession();
- $session->set('userid', intval($uid));
- $session->set('username', htmlspecialchars($data['user_name']));
- $this->sendMail($data['email']);
- JsMessage("注册成功,端口及密码请查看用户中心右下角", "/user/index.html");
- }
- } else {
- JsMessage("用户名或者Email已经被注册了!");
- }
- } else {
- JsMessage("站点开启了邀请注册,当前邀请码无效!");
- }
- } else { // 直接注册
- if ($user->checkUser($userinfo)) {
- $data = array();
- $data['user_name'] = $userinfo['username'];
- $data['email'] = $userinfo['email'];
- $data['pass'] = md5($userinfo['password']);
- $data['passwd'] = rand(10000, 99999);
- $data['transfer_enable'] = $config['transfer'];
- // $data['port'] = $port;
- $data['t'] = 0;
- $data['u'] = 0;
- $data['d'] = 0;
- $data['plan'] = "A";
- $data['switch'] = 1;
- $data['enable'] = 1;
- $data['type'] = 7;
- $data['reg_date'] = date("Y-m-d H:i:s");
- $data['invite_num'] = $config['invite_num'];
- $data['money'] = 0.00;
- $uid = $user->createUser($data);
- if ($uid) {
- $session = self::getSession();
- $session->set('userid', intval($uid));
- $session->set('username', htmlspecialchars($data['user_name']));
- $this->sendMail($data['email']);
- JsMessage("注册成功", "/user/run");
- }
- } else {
- JsMessage("用户名或者Email已经被注册了!");
- }
- }
- } else {
- $title = $config['sitename'];
- $isinviteonly = $config['isinviteonly'];
- $this->view->assign("title", $title);
- $this->view->assign("isinviteonly", $isinviteonly);
- $this->view->set_tpl("index/reg"); // 中间的模板
- $this->view->display();
- }
- }
- private function sendMail($to)
- {
- $subject = "欢迎使用ShadowSocks服务";
- $message = "<html>
- <head>
- <title>欢迎使用ShadowSocks服务</title>
- </head>
- <body>
- <p>欢迎您加入shadowsocks5.com</p>
- <table>
- <tr>
- 现在您可以免费使用我们的服务,每个月,您会有30G的流量供您使用SS服务,记得每天签到也会送流量哦!<br><font color='red'>注意:本系统会自动删除三天内使用流量为0的用户,请注册用户务必在三天内进行使用,否则将被判定为垃圾用户,及时释放资源以供其他用户使用!同时,请勿滥用本服务器进行发送垃圾邮件以及下载涉及版权的视频,谢谢合作!</font>
- </tr>
- </table>
- </body>
- </html>";
- // 当发送 HTML 电子邮件时,请始终设置 content-type
- sendmail($to,$subject,$message,'webmaster@tailsocks.com');
- }
- private function checkLogin()
- {
- $list = array(
- "login",
- 'reg',
- 'reset',
- 'unfreeze'
- );
- $session = self::getSession();
- $userid = $session->get('userid');
- $a = $this->getA();
- if (empty($userid)) {
- if (! in_array($a, $list)) {
- $function = self::getFunction();
- $function->goto_url('/user/login.html');
- }
- } else {
- $this->uid = $userid;
- }
-
- }
- public function logout()
- {
- $session = self::getSession();
- $function = self::getFunction();
- $session->clear();
- $function->goto_url('/user/login.html');
- }
- /**
- *
- * @return userService
- */
- private function getUserService()
- {
- return InitPHP::getService("user");
- }
- /**
- *
- * @return sessionInit
- */
- private function getSession()
- {
- return InitPHP::getUtils("session");
- }
- /**
- *
- * @return functionInit
- */
- private function getFunction()
- {
- return InitPHP::getLibrarys("function");
- }
- /**
- *
- * @return emailInit
- */
- private function getEmail()
- {
- return InitPHP::getLibrarys("email");
- }
- /**
- *
- * @return nodeService
- */
- private function getNode()
- {
- return InitPHP::getService("node");
- }
- /**
- * 获取头像
- *
- * @param unknown $email
- * @param number $s
- * @param string $d
- * @param string $r
- * @param string $img
- * @param unknown $atts
- * @return string
- */
- function get_gravatar($email, $s = 80, $d = 'mm', $r = 'g', $img = false, $atts = array())
- {
- $url = 'https://secure.gravatar.com/avatar/';
- $url .= md5(strtolower(trim($email)));
- $url .= "?s=$s&d=$d&r=$r";
- if ($img) {
- $url = '<img src="' . $url . '"';
- foreach ($atts as $key => $val)
- $url .= ' ' . $key . '="' . $val . '"';
- $url .= ' />';
- }
- return $url;
- }
- // public function getEmail(){
- // return InitPHP::getLibrarys("Email");
- // }
- }
|