コード例 #1
0
ファイル: ApiController.php プロジェクト: SharkIng/ss-panel
 public function newToken($request, $response, $args)
 {
     // $data = $request->post('sdf');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     // Handle Login
     $user = User::where('email', '=', $email)->first();
     if ($user == null) {
         $res['ret'] = 0;
         $res['msg'] = "401 邮箱或者密码错误";
         return $this->echoJson($response, $res);
     }
     if (!Hash::checkPassword($user->pass, $passwd)) {
         $res['ret'] = 0;
         $res['msg'] = "402 邮箱或者密码错误";
         return $this->echoJson($response, $res);
     }
     $tokenStr = Tools::genToken();
     $storage = Factory::createTokenStorage();
     $expireTime = time() + 3600 * 24 * 7;
     if ($storage->store($tokenStr, $user, $expireTime)) {
         $res['ret'] = 1;
         $res['msg'] = "ok";
         $res['data']['token'] = $tokenStr;
         $res['data']['user_id'] = $user->id;
         return $this->echoJson($response, $res);
     }
     $res['ret'] = 0;
     $res['msg'] = "system error";
     return $this->echoJson($response, $res);
 }
コード例 #2
0
ファイル: Redis.php プロジェクト: cainiaocome/ss-panel
 public function login($uid, $time)
 {
     $sid = Tools::genSID();
     Cookie::set(['sid' => $sid], $time + time());
     $value = $uid;
     $this->client->setex($sid, $time, $value);
 }
コード例 #3
0
ファイル: NodeController.php プロジェクト: SharkIng/ss-panel
 public function postTraffic($request, $response, $args)
 {
     $nodeId = $args['id'];
     $node = Node::find($nodeId);
     $rate = $node->traffic_rate;
     $input = $request->getBody();
     $datas = json_decode($input, true);
     foreach ($datas as $data) {
         $user = User::find($data['user_id']);
         $user->t = time();
         $user->u = $user->u + $data['u'] * $rate;
         $user->d = $user->d + $data['d'] * $rate;
         $user->save();
         // log
         $totalTraffic = Tools::flowAutoShow(($data['u'] + $data['d']) * $rate);
         $traffic = new TrafficLog();
         $traffic->user_id = $data['user_id'];
         $traffic->u = $data['u'];
         $traffic->d = $data['d'];
         $traffic->node_id = $nodeId;
         $traffic->rate = $rate;
         $traffic->traffic = $totalTraffic;
         $traffic->log_time = time();
         $traffic->save();
     }
     $res = ["ret" => 1, "msg" => "ok"];
     return $this->echoJson($response, $res);
 }
コード例 #4
0
ファイル: UserController.php プロジェクト: SharkIng/ss-panel
 public function update($request, $response, $args)
 {
     $id = $args['id'];
     $user = User::find($id);
     $user->email = $request->getParam('email');
     if ($request->getParam('pass') != '') {
         $user->pass = Hash::passwordHash($request->getParam('pass'));
     }
     if ($request->getParam('passwd') != '') {
         $user->passwd = $request->getParam('passwd');
     }
     $user->port = $request->getParam('port');
     $user->transfer_enable = Tools::toGB($request->getParam('transfer_enable'));
     $user->invite_num = $request->getParam('invite_num');
     $user->method = $request->getParam('method');
     $user->enable = $request->getParam('enable');
     $user->is_admin = $request->getParam('is_admin');
     $user->ref_by = $request->getParam('ref_by');
     if (!$user->save()) {
         $rs['ret'] = 0;
         $rs['msg'] = "修改失败";
         return $response->getBody()->write(json_encode($rs));
     }
     $rs['ret'] = 1;
     $rs['msg'] = "修改成功";
     return $response->getBody()->write(json_encode($rs));
 }
コード例 #5
0
ファイル: Auth.php プロジェクト: SharkIng/ss-panel
 public static function login($uid, $time)
 {
     $sid = Tools::genSID();
     Cookie::set(['sid' => $sid], $time + time());
     $key = $sid;
     $value = $uid;
     self::getCache()->set($key, $value, $time);
 }
コード例 #6
0
ファイル: User.php プロジェクト: nymc/ss-panel
 public function addInviteCode()
 {
     $uid = $this->attributes['id'];
     $code = new InviteCode();
     $code->code = Tools::genRandomChar(32);
     $code->user = $uid;
     $code->save();
 }
コード例 #7
0
ファイル: Node.php プロジェクト: SharkIng/ss-panel
 function getTrafficFromLogs()
 {
     $id = $this->attributes['id'];
     $traffic = TrafficLog::where('node_id', $id)->sum('u') + TrafficLog::where('node_id', $id)->sum('d');
     if ($traffic == 0) {
         return "暂无数据";
     }
     return Tools::flowAutoShow($traffic);
 }
コード例 #8
0
ファイル: CheckInLogTest.php プロジェクト: SharkIng/ss-panel
 public function testCheckInLog()
 {
     $log = new CheckInLog();
     $log->user_id = 1;
     $log->checkin_at = time();
     $log->traffic = 1024;
     $log->save();
     $this->assertEquals(Tools::toDateTime($log->checkin_at), $log->CheckInTime());
     $this->assertEquals(Tools::flowAutoShow($log->traffic), $log->traffic());
 }
コード例 #9
0
ファイル: TestController.php プロジェクト: SharkIng/ss-panel
 public function sendMailPost($request, $response, $args)
 {
     $to = $request->getParam('email');
     try {
         Mail::send($to, "Test", 'test.tpl', ['time' => Tools::toDateTime(time())], [BASE_PATH . '/LICENSE']);
         $res = ["ret" => 1, "msg" => "ok"];
     } catch (\Exception $e) {
         $res = ["ret" => 0, "msg" => $e->getMessage()];
     }
     return $this->echoJson($response, $res);
 }
コード例 #10
0
ファイル: UserController.php プロジェクト: holotr/ss-panel
 public function traffic($request, $response, $args)
 {
     $id = $args['id'];
     $counts = TrafficCount::where('user_id', '=', $id)->get();
     foreach ($counts as $counter) {
         $counter->u = Tools::flowAutoShow($counter->u);
         $counter->d = Tools::flowAutoShow($counter->d);
         $counter->v = Tools::flowAutoShow($counter->v);
     }
     return $this->view()->assign('counts', $counts)->display('admin/user/traffic.tpl');
 }
コード例 #11
0
ファイル: TrafficLogTest.php プロジェクト: SharkIng/ss-panel
 public function testNewTrafficLog()
 {
     // log
     $u = 1024;
     $d = 1024;
     $rate = 1;
     $id = 1;
     $nodeId = 1;
     $totalTraffic = Tools::flowAutoShow(($u + $d) * $rate);
     $traffic = new TrafficLog();
     $traffic->user_id = $id;
     $traffic->u = $u;
     $traffic->d = $d;
     $traffic->node_id = $nodeId;
     $traffic->rate = $rate;
     $traffic->traffic = $totalTraffic;
     $traffic->log_time = time();
     $this->assertEquals(true, $traffic->save());
 }
コード例 #12
0
ファイル: Password.php プロジェクト: SharkIng/ss-panel
 /**
  * @param $email string
  * @return bool
  */
 public static function sendResetEmail($email)
 {
     $pwdRst = new PasswordReset();
     $pwdRst->email = $email;
     $pwdRst->init_time = time();
     $pwdRst->expire_time = time() + 3600 * 24;
     // @todo
     $pwdRst->token = Tools::genRandomChar(64);
     if (!$pwdRst->save()) {
         return false;
     }
     $subject = Config::get('appName') . "重置密码";
     $resetUrl = Config::get('baseUrl') . "/password/token/" . $pwdRst->token;
     try {
         Mail::send($email, $subject, 'password/reset.tpl', ["resetUrl" => $resetUrl], []);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
コード例 #13
0
ファイル: AdminController.php プロジェクト: SharkIng/ss-panel
 public function addInvite($request, $response, $args)
 {
     $n = $request->getParam('num');
     $prefix = $request->getParam('prefix');
     $uid = $request->getParam('uid');
     if ($n < 1) {
         $res['ret'] = 0;
         return $response->getBody()->write(json_encode($res));
     }
     for ($i = 0; $i < $n; $i++) {
         $char = Tools::genRandomChar(32);
         $code = new InviteCode();
         $code->code = $prefix . $char;
         $code->user_id = $uid;
         $code->save();
     }
     $res['ret'] = 1;
     $res['msg'] = "邀请码添加成功";
     return $response->getBody()->write(json_encode($res));
 }
コード例 #14
0
ファイル: UserController.php プロジェクト: SharkIng/ss-panel
 public function addTraffic($request, $response, $args)
 {
     // $data = json_decode($request->getParsedBody(),true);
     $id = $args['id'];
     $u = $request->getParam('u');
     $d = $request->getParam('d');
     $nodeId = $request->getParam('node_id');
     $node = Node::find($nodeId);
     $rate = $node->traffic_rate;
     $user = User::find($id);
     $user->t = time();
     $user->u = $user->u + $u * $rate;
     $user->d = $user->d + $d * $rate;
     if (!$user->save()) {
         $res = ["msg" => "update failed"];
         return $this->echoJson($response, $res, 400);
     }
     // log
     $totalTraffic = Tools::flowAutoShow(($u + $d) * $rate);
     $traffic = new TrafficLog();
     $traffic->user_id = $id;
     $traffic->u = $u;
     $traffic->d = $d;
     $traffic->node_id = $nodeId;
     $traffic->rate = $rate;
     $traffic->traffic = $totalTraffic;
     $traffic->log_time = time();
     $traffic->save();
     $res = ["ret" => 1, "msg" => "ok"];
     if (Config::get('log_traffic_dynamodb')) {
         try {
             $client = new DynamoTrafficLog();
             $id = $client->store($u, $d, $nodeId, $id, $totalTraffic, $rate);
             $res["id"] = $id;
         } catch (\Exception $e) {
             $res["msg"] = $e->getMessage();
             Logger::error($e->getMessage());
         }
     }
     return $this->echoJson($response, $res);
 }
コード例 #15
0
ファイル: XCat.php プロジェクト: SharkIng/ss-panel
 public function createAdmin()
 {
     echo "add admin/ 创建管理员帐号.....";
     // ask for input
     fwrite(STDOUT, "Enter your email/输入管理员邮箱: ");
     // get input
     $email = trim(fgets(STDIN));
     // write input back
     fwrite(STDOUT, "Enter password for: {$email} / 为 {$email} 添加密码 ");
     $passwd = trim(fgets(STDIN));
     echo "Email: {$email}, Password: {$passwd}! ";
     fwrite(STDOUT, "Press [Y] to create admin..... 按下[Y]确认来确认创建管理员账户..... ");
     $y = trim(fgets(STDIN));
     if (strtolower($y) == "y") {
         echo "start create admin account";
         // create admin user
         // do reg user
         $user = new User();
         $user->user_name = "admin";
         $user->email = $email;
         $user->pass = Hash::passwordHash($passwd);
         $user->passwd = Tools::genRandomChar(6);
         $user->port = Tools::getLastPort() + 1;
         $user->t = 0;
         $user->u = 0;
         $user->d = 0;
         $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
         $user->invite_num = Config::get('inviteNum');
         $user->ref_by = 0;
         $user->is_admin = 1;
         if ($user->save()) {
             echo "Successful/添加成功!";
             return true;
         }
         echo "添加失败";
         return false;
     }
     echo "cancel";
     return false;
 }
コード例 #16
0
ファイル: EmailVerify.php プロジェクト: SharkIng/ss-panel
 /**
  * @param $email string
  * @return bool
  */
 public static function sendVerification($email)
 {
     $ttl = Config::get('emailVerifyTTL');
     $verification = EmailVerifyModel::where('email', '=', $email)->first();
     if ($verification == null) {
         $verification = new EmailVerifyModel();
         $verification->email = $email;
     }
     $verification->token = Tools::genRandomChar(Config::get('emailVerifyCodeLength'));
     $verification->expire_at = time() + $ttl * 60;
     if (!$verification->save()) {
         return false;
     }
     $appName = Config::get('appName');
     $subject = $appName . ' 邮箱验证';
     try {
         Mail::send($email, $subject, 'auth/verify.tpl', ['verification' => $verification, 'ttl' => $ttl], []);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
コード例 #17
0
ファイル: AuthController.php プロジェクト: SharkIng/ss-panel
 public function registerHandle($request, $response, $args)
 {
     $name = $request->getParam('name');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     $repasswd = $request->getParam('repasswd');
     $code = $request->getParam('code');
     $verifycode = $request->getParam('verifycode');
     // check code
     $c = InviteCode::where('code', $code)->first();
     if ($c == null) {
         $res['ret'] = 0;
         $res['error_code'] = self::WrongCode;
         $res['msg'] = "邀请码无效";
         return $this->echoJson($response, $res);
     }
     // check email format
     if (!Check::isEmailLegal($email)) {
         $res['ret'] = 0;
         $res['error_code'] = self::IllegalEmail;
         $res['msg'] = "邮箱无效";
         return $this->echoJson($response, $res);
     }
     // check pwd length
     if (strlen($passwd) < 8) {
         $res['ret'] = 0;
         $res['error_code'] = self::PasswordTooShort;
         $res['msg'] = "密码太短";
         return $this->echoJson($response, $res);
     }
     // check pwd re
     if ($passwd != $repasswd) {
         $res['ret'] = 0;
         $res['error_code'] = self::PasswordNotEqual;
         $res['msg'] = "两次密码输入不符";
         return $this->echoJson($response, $res);
     }
     // check email
     $user = User::where('email', $email)->first();
     if ($user != null) {
         $res['ret'] = 0;
         $res['error_code'] = self::EmailUsed;
         $res['msg'] = "邮箱已经被注册了";
         return $this->echoJson($response, $res);
     }
     // verify email
     if (Config::get('emailVerifyEnabled') && !EmailVerify::checkVerifyCode($email, $verifycode)) {
         $res['ret'] = 0;
         $res['msg'] = '邮箱验证代码不正确';
         return $this->echoJson($response, $res);
     }
     // check ip limit
     $ip = Http::getClientIP();
     $ipRegCount = Check::getIpRegCount($ip);
     if ($ipRegCount >= Config::get('ipDayLimit')) {
         $res['ret'] = 0;
         $res['msg'] = '当前IP注册次数超过限制';
         return $this->echoJson($response, $res);
     }
     // do reg user
     $user = new User();
     $user->user_name = $name;
     $user->email = $email;
     $user->pass = Hash::passwordHash($passwd);
     $user->passwd = Tools::genRandomChar(6);
     $user->port = Tools::getLastPort() + 1;
     $user->t = 0;
     $user->u = 0;
     $user->d = 0;
     $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
     $user->invite_num = Config::get('inviteNum');
     $user->reg_ip = Http::getClientIP();
     $user->ref_by = $c->user_id;
     if ($user->save()) {
         $res['ret'] = 1;
         $res['msg'] = "注册成功";
         $c->delete();
         return $this->echoJson($response, $res);
     }
     $res['ret'] = 0;
     $res['msg'] = "未知错误";
     return $this->echoJson($response, $res);
 }
コード例 #18
0
ファイル: UserController.php プロジェクト: Kaisir/ss-panel
 public function doCheckIn($request, $response, $args)
 {
     if (!$this->user->isAbleToCheckin()) {
         $res['msg'] = "您似乎已经签到过了...";
         $res['ret'] = 1;
         return $response->getBody()->write(json_encode($res));
     }
     $traffic = rand(Config::get('checkinMin'), Config::get('checkinMax'));
     $this->user->transfer_enable = $this->user->transfer_enable + Tools::toMB($traffic);
     $this->user->last_check_in_time = time();
     $this->user->save();
     $res['msg'] = sprintf("获得了 %u MB流量.", $traffic);
     $res['ret'] = 1;
     return $response->getBody()->write(json_encode($res));
 }
コード例 #19
0
ファイル: Check.php プロジェクト: SharkIng/ss-panel
 /**
  * @param $ip
  * @param int $time
  * @return int
  */
 public static function getIpRegCount($ip, $time = 3600 * 24)
 {
     return User::where('reg_ip', $ip)->where('reg_date', '>', Tools::toDateTime(time() - $time))->count();
 }
コード例 #20
0
ファイル: AuthTest.php プロジェクト: SharkIng/ss-panel
 protected function getRandomEmail()
 {
     return Tools::genRandomChar(8) . "@sp3.me";
 }
コード例 #21
0
ファイル: User.php プロジェクト: ss-panel/ss-panel
 public function unusedTraffic()
 {
     $total = $this->attributes['u'] + $this->attributes['d'];
     $enable = $this->attributes['transfer_enable'];
     return Tools::flowAutoShow($enable - $total);
 }
コード例 #22
0
ファイル: Analytic.php プロジェクト: SharkIng/ss-panel
 public function totalTraffic()
 {
     $u = User::all()->sum('u');
     $d = User::all()->sum('d');
     return Tools::flowAutoShow($u + $d);
 }
コード例 #23
0
ファイル: TrafficLog.php プロジェクト: SharkIng/ss-panel
 public function logTime()
 {
     return Tools::toDateTime($this->attributes['log_time']);
 }
コード例 #24
0
ファイル: UserController.php プロジェクト: 872517414/ss-panel
 public function doCheckIn($request, $response, $args)
 {
     if (!$this->user->isAbleToCheckin()) {
         $res['msg'] = "您似乎已经签到过了...";
         $res['ret'] = 1;
         return $response->getBody()->write(json_encode($res));
     }
     $traffic = rand(Config::get('checkinMin'), Config::get('checkinMax'));
     $trafficToAdd = Tools::toMB($traffic);
     $this->user->transfer_enable = $this->user->transfer_enable + $trafficToAdd;
     $this->user->last_check_in_time = time();
     $this->user->save();
     // checkin log
     try {
         $log = new CheckInLog();
         $log->user_id = Auth::getUser()->id;
         $log->traffic = $trafficToAdd;
         $log->checkin_at = time();
         $log->save();
     } catch (\Exception $e) {
     }
     $res['msg'] = sprintf("获得了 %u MB流量.", $traffic);
     $res['ret'] = 1;
     return $this->echoJson($response, $res);
 }
コード例 #25
0
ファイル: User.php プロジェクト: ChromiumX/ss-panel
 public function lastCheckInTime()
 {
     return Tools::toDateTime($this->attributes['last_check_in_time']);
 }
コード例 #26
0
 public function registerHandle($request, $response, $next)
 {
     $name = $request->getParam('name');
     $email = $request->getParam('email');
     $email = strtolower($email);
     $passwd = $request->getParam('passwd');
     $repasswd = $request->getParam('repasswd');
     $code = $request->getParam('code');
     // check code
     $c = InviteCode::where('code', $code)->first();
     if ($c == null) {
         $res['ret'] = 0;
         $res['msg'] = "邀请码无效";
         return $response->getBody()->write(json_encode($res));
     }
     // check email format
     if (!Check::isEmailLegal($email)) {
         $res['ret'] = 0;
         $res['msg'] = "邮箱无效";
         return $response->getBody()->write(json_encode($res));
     }
     // check pwd length
     if (strlen($passwd) < 8) {
         $res['ret'] = 0;
         $res['msg'] = "密码太短";
         return $response->getBody()->write(json_encode($res));
     }
     // check pwd re
     if ($passwd != $repasswd) {
         $res['ret'] = 0;
         $res['msg'] = "两次密码输入不符";
         return $response->getBody()->write(json_encode($res));
     }
     // check email
     $user = User::where('email', $email)->first();
     if ($user != null) {
         $res['ret'] = 0;
         $res['msg'] = "邮箱已经被注册了";
         return $response->getBody()->write(json_encode($res));
     }
     // do reg user
     $user = new User();
     $user->user_name = $name;
     $user->email = $email;
     $user->pass = Hash::passwordHash($passwd);
     $user->passwd = Tools::genRandomChar(6);
     $user->port = Tools::getLastPort() + 1;
     $user->t = 0;
     $user->u = 0;
     $user->d = 0;
     $user->transfer_enable = Tools::toGB(Config::get('defaultTraffic'));
     $user->invite_num = Config::get('inviteNum');
     $user->ref_by = $c->user_id;
     if ($user->save()) {
         $res['ret'] = 1;
         $res['msg'] = "注册成功";
         $c->delete();
         return $response->getBody()->write(json_encode($res));
     }
     $res['ret'] = 0;
     $res['msg'] = "未知错误";
     return $response->getBody()->write(json_encode($res));
 }
コード例 #27
0
ファイル: ToolsTest.php プロジェクト: SharkIng/ss-panel
 public function testCheckHtml()
 {
     $legalText = 'xoxo';
     $this->assertEquals($legalText, Tools::checkHtml($legalText));
 }
コード例 #28
0
ファイル: CheckInLog.php プロジェクト: SharkIng/ss-panel
 /**
  * @return mixed
  */
 public function CheckInTime()
 {
     return Tools::toDateTime($this->attributes['checkin_at']);
 }
コード例 #29
0
ファイル: Analytics.php プロジェクト: aliqingyun/ss-panel
 public function getTrafficUsage()
 {
     $total = User::sum('u') + USer::sum('d');
     return Tools::flowAutoShow($total);
 }
コード例 #30
0
ファイル: HashTest.php プロジェクト: SharkIng/ss-panel
 public function testCookieHash()
 {
     $str = Tools::genRandomChar();
     Hash::cookieHash($str);
 }