public function nodeInfo($request, $response, $args) { $id = $args['id']; $node = Node::find($id); if ($node == null) { } }
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); }
public function deleteGet($request, $response, $args) { $id = $args['id']; $node = Node::find($id); $node->delete(); return $this->redirect($response, '/admin/node'); }
public function deleteGet($request, $response, $args) { $id = $args['id']; $node = Node::find($id); $node->delete(); $newResponse = $response->withStatus(302)->withHeader('Location', '/admin/node'); return $newResponse; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Node::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['like', '_id', $this->_id])->andFilterWhere(['like', 'node', $this->node])->andFilterWhere(['like', 'node_name', $this->node_name])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'remark', $this->remark])->andFilterWhere(['like', 'pid', $this->pid])->andFilterWhere(['like', 'level', $this->level]); return $dataProvider; }
public function actionIndex() { $model = new Node(); if ($model->load(Yii::$app->getRequest()->post())) { $node = Node::find()->select(['id', 'name', 'ename'])->where(['name' => $model->name])->asArray()->one(); return $this->render('search', ['model' => $model, 'node' => $node]); } else { $query = Node::find(); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count('id')]); $nodes = $query->orderBy(['id' => SORT_DESC])->offset($pages->offset)->limit($pages->limit)->asArray()->all(); return $this->render('index', ['model' => $model, 'nodes' => $nodes, 'pages' => $pages]); } }
public function nodeInfo($request, $response, $args) { $id = $args['id']; $node = Node::find($id); if ($node == null) { } $ary['server'] = $node->server; $ary['server_port'] = $this->user->port; $ary['password'] = $this->user->passwd; $ary['method'] = $node->method; $json = json_encode($ary); $ssurl = $node->method . ":" . $this->user->passwd . "@" . $node->server . ":" . $this->user->port; $ssqr = "ss://" . base64_encode($ssurl); return $this->view()->assign('json', $json)->assign('ssqr', $ssqr)->display('user/nodeinfo.tpl'); }
public function nodeInfo($request, $response, $args) { $id = $args['id']; $node = Node::find($id); if ($node == null) { } $ary['server'] = $node->server; $ary['server_port'] = $this->user->port; $ary['password'] = $this->user->passwd; $ary['method'] = $node->method; if ($node->custom_method) { $ary['method'] = $this->user->method; } $json = "{\n\"server\":" . $ary['server'] . ",\n\"server_port\":" . $ary['server_port'] . ",\n\"local_port\":1080,\n\"password\":" . $ary['password'] . ",\n\"timeout\":600,\n\"method\":" . $ary['method'] . "\n}"; $ssurl = $ary['method'] . ":" . $this->user->passwd . "@" . $node->server . ":" . $this->user->port; $ssqr = "ss://" . base64_encode($ssurl); return $this->view()->assign('json', $json)->assign('ssqr', $ssqr)->display('user/nodeinfo.tpl'); }
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); }
public function nodeInfo($request, $response, $args) { $id = $args['id']; $node = Node::find($id); if ($node == null) { } $ary['server'] = $node->server; $ary['server_port'] = $this->user->port; $ary['password'] = $this->user->passwd; $ary['method'] = $node->method; if ($node->custom_method) { $ary['method'] = $this->user->method; } $json = json_encode($ary); $json_show = json_encode($ary, JSON_PRETTY_PRINT); $ssurl = $ary['method'] . ":" . $ary['password'] . "@" . $ary['server'] . ":" . $ary['server_port']; $ssqr = "ss://" . base64_encode($ssurl); $surge_base = Config::get('baseUrl') . "/downloads/ProxyBase.conf"; $surge_proxy = "#!PROXY-OVERRIDE:ProxyBase.conf\n"; $surge_proxy .= "[Proxy]\n"; $surge_proxy .= "Proxy = custom," . $ary['server'] . "," . $ary['server_port'] . "," . $ary['method'] . "," . $ary['password'] . "," . Config::get('baseUrl') . "/downloads/SSEncrypt.module"; return $this->view()->assign('json', $json)->assign('json_show', $json_show)->assign('ssqr', $ssqr)->assign('surge_base', $surge_base)->assign('surge_proxy', $surge_proxy)->display('user/nodeinfo.tpl'); }
public function node() { return Node::find($this->attributes['node_id']); }
protected function findNodeModel($name, $with = null) { $model = Node::find()->select(['id', 'name', 'ename', 'topic_count', 'about'])->where(['ename' => $name]); if (!empty($with)) { $model = $model->with($with); } $model = $model->asArray()->one(); if ($model !== null) { return $model; } else { throw new NotFoundHttpException('未找到[' . $name . ']的节点'); } }
function init() { parent::init(); $session = yii::$app->session; if (empty($session['admin_user']['id'])) { echo "<script>alert('请先登录');location.href='index.php?r=public/login'</script>"; } else { /** * 查询当前用户的所有权限 */ $uid = $session['admin_user']['id']; //查询用户所对应的角色 $arr_role = AdminRole::find()->select(['role_id'])->where(['admin_user_id' => "{$uid}"])->asarray()->all(); //->where(['admin._id' => $session['admin_user']['id'],'admin._id'=>"admin_role.admin_user_id"])->all(); //$aa = yii::$app->mongodb->getcollection('admin_role')->find(array('admin_user_id'=>$session['admin']['id'])); //print_r($arr_role);die; //查询角色所对应的权限id foreach ($arr_role as $k => $v) { $role_node[$k] = RoleNode::find()->select(['node_id'])->where(array('role_id' => $v['role_id']))->asarray()->all(); } //print_r($role_node);die; foreach ($role_node as $k => $v) { foreach ($v as $kk => $vv) { $acces[$k][$kk] = $vv['node_id']; } } foreach ($acces as $k => $val) { foreach ($acces[$k] as $key => $value) { $access[] = $value; } } //根据node_id查询权限 foreach ($access as $k => $val) { $all_node[$k] = Node::find()->where(array('_id' => "{$val}"))->asarray()->all(); } //print_r($all_node);die; foreach ($all_node as $k => $value) { foreach ($value as $kk => $v) { if ($v['level'] == 0) { $all_c[$k][$kk]['id'] = $v['_id']; $all_c[$k][$kk]['node'] = $v['node']; $all_c[$k][$kk]['node_name'] = $v['node_name']; $all_c[$k][$kk]['pid'] = $v['pid']; } else { $all_fun[$k][$kk]['id'] = $v['_id']; $all_fun[$k][$kk]['node'] = $v['node']; $all_fun[$k][$kk]['node_name'] = $v['node_name']; $all_fun[$k][$kk]['pid'] = $v['pid']; } } } /** * $all_c获取到当前用户的所有控制器权限 * * * $all_fun获取到当前用户的所有方法的权限 */ //print_r($all_fun);die; foreach ($all_c as $k => $v) { foreach ($v as $key => $value) { foreach ($all_fun as $kk => $vv) { foreach ($vv as $kkk => $vvv) { //判断当前用户的控制器是否含有子方法 if ($vvv['pid'] == $value['id']) { $c_f[$k][$kk] = $value['node'] . '/' . $vvv['node']; } } } } } //print_r($c_f);die; /** * 已获得 所有控制器与方法的拼接!! * * 下列转换成一维数组 */ foreach ($c_f as $k => $val) { foreach ($c_f[$k] as $key => $value) { $c_fno[] = $value; } } //print_r($c_fno); /*实施重复值删除 保留*/ $c_fyes = array_flip(array_flip($c_fno)); //print_r($c_fyes);die; //获取当前管理者访问的控制器和方法 $now_node = yii::$app->requestedRoute; if (!in_array($now_node, $c_fyes)) { echo "<script>alert('您无权限');history.back();</script>"; } } }
public function modifyConfig($id) { $node = Node::find($id); $loIP = $node['name']; $connIP = $node['ip']; }