123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use app\common\model\UserTraffic;
- use fast\Random;
- use think\Queue;
- /**
- * 首页接口
- */
- class Index extends Api
- {
- protected $noNeedLogin = ['*'];
- protected $noNeedRight = ['*'];
- /**
- * 首页
- *
- */
- public function index()
- {
- $proxy_ip = $this->request->request('local_addr');
- $user_ip = $this->request->request('client_addr');
- $service = $this->request->request('service');
- $is_sps = $this->request->request('sps')=='1';
- $account = $this->request->request('user');
- $password = $this->request->request('pass');
- $target = $this->request->request('target');
- if (!$account || !$password) {
- return $this->err();
- }
- $ret = $this->auth->login($account, $password);
- if ($ret) {
- $user = \app\common\model\User::where(['username'=>$account])->find();
- $nowTime = time();
- $usable = UserTraffic::where('uid', $user->id)
- ->where('is_usable', '1')
- ->where('start_time', '<', $nowTime)
- ->where('expired_time', '>', $nowTime)
- ->find();
- if (!$usable) {
- return $this->err();
- }
- $user_ip = explode(":",$user_ip)[0];
- \app\common\model\User::where(['id'=>$this->auth->id])->update(['loginip'=>$user_ip]);
- header("userconns:1000"); // 用户的最大连接数,不限制为0或者不设置这个头部。
- header("ipconns:2000"); // 用户IP的最大连接数,不限制为0或者不设置这个头部。
- //header("userrate:3000"); // 用户的单个TCP连接速率限制,单位:字节/秒,不限制为0或者不设置这个头部。
- //header("iprate:8000"); // 用户IP的单个TCP连接速率限制,单位:字节/秒,不限制为0或者不设置这个头部。
- //header("UPSTREAM:http://127.0.0.1:3500?parent-type=tcp"); // 使用的上级,没有为空,或者不设置这个头部。
- header("HTTP/1.1 204 No Content");
- exit;
- return 'true';
- } else {
- return $this->err();
- }
- }
- /**
- * 功能: 流量上报, 生成队列, 后台进程处理流量数据
- * @return bool|void
- */
- public function traffic()
- {
- $jobData = $this->request->request();
- $jobHandlerClassName = "app\job\FlowLog";
- $jobName = "FlowLog";
- $jobData['time'] = time();
- $ret = Queue::push($jobHandlerClassName, $jobData, $jobName);
- if ($ret) {
- return header('HTTP/1.0 204 Success');
- }
- return false;
- }
- // 状态上报
- public function status()
- {
- #接收proxy post过来的数据
- $userArr = $this->request->request('user');
- $ipArr = $this->request->request('ip');
- //无效用户列表
- $badUsers=[];
- $userArr = explode(',',$userArr);
- $badUsers = \app\common\model\User::whereIn('mobile', $userArr)->where("traffic > ifnull(total_traffic, traffic-1)")->column('mobile');
- $data = ["user"=>implode(",",$badUsers ?? []),"ip"=>""];
- // $data = ["user"=>implode(",",[]),"ip"=>""];
- echo json_encode($data);
- exit;
- }
- public function birth()
- {
- $username = time().Random::numeric(3);
- $password = Random::numeric(6);
- $email = $password."@qq.com";
- $mobile = Random::numeric(6).Random::numeric(5);
- $ret = $this->auth->register($username, $password, $email, $mobile, []);
- if ($ret) {
- $user = $this->auth->getUserinfo();
- $data = ['userinfo' => $user];
- $this->success(__('Sign up successful'), $data);
- } else {
- $this->error($this->auth->getError());
- }
- }
- public function err(){
- header("HTTP/1.1 404 No Content");
- return "";
- }
- }
|