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 nodeInfo($request, $response, $args) { $id = $args['id']; $node = Node::find($id); if ($node == null) { } }
public function deleteGet($request, $response, $args) { $id = $args['id']; $node = Node::find($id); $node->delete(); return $this->redirect($response, '/admin/node'); }
public function node($request, $response, $args) { $nodes = Node::where('type', 1)->orderBy('sort')->get(); $res['ret'] = 1; $res['msg'] = "ok"; $res['data'] = $nodes; return $this->echoJson($response, $res); }
protected function findModel($id) { if (($model = Node::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('未找到id为[' . $id . ']的节点'); } }
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; }
public function find($name) { $this->_node = Node::findByName($name); if ($this->_node !== null) { $this->attributes = $this->_node->attributes; } return $this->_node !== null; }
public function testNode() { $this->get('/user/node'); $this->assertEquals('200', $this->response->getStatusCode()); $node = Node::first(); if ($node != null) { $this->get("/user/node/{$node->id}"); $this->assertEquals('200', $this->response->getStatusCode()); } }
public function sshExec($id) { $node = Node::getById($id); $connection = ssh2_connect(Config::get('ssh.host'), Config::get('ssh.port')); if (!$connection) { die('Connection failed'); } ssh2_auth_password($connection, Config::get('ssh.username'), Config::get('ssh.password')); $stream = ssh2_exec($connection, '/usr/local/bin/php -i'); return Redirect::back(); }
public function afterSave($insert, $changedAttributes) { if ($insert === true) { (new History(['user_id' => $this->topic->user_id, 'action' => History::ACTION_ADD_TOPIC, 'action_time' => $this->topic->created_at, 'target' => $this->topic_id]))->save(false); Siteinfo::updateCounterInfo('addTopic'); UserInfo::updateCounterInfo('addTopic', $this->topic->user_id); Node::updateCounterInfo('addTopic', $this->topic->node_id); Notice::afterTopicInsert($this); Tag::afterTopicInsert($this); } return parent::afterSave($insert, $changedAttributes); }
public function testNodeMethod() { $node = new Node(); $node->id = 1; $node->getLastNodeInfoLog(); $node->getNodeUptime(); $node->getNodeLoad(); $node->getLastNodeOnlineLog(); $node->getOnlineUserCount(); $node->getTrafficFromLogs(); }
/** * 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 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 actionChangeNode($id) { $request = Yii::$app->getRequest(); $model = $this->findTopicModel($id); $model->scenario = Topic::SCENARIO_ADMIN_CHGNODE; $ext['oldNode'] = $model->node->toArray(); if ($model->load($request->post()) && $model->save(false)) { unset($model->node); $ext['newNode'] = $model->node->toArray(); (new History(['user_id' => Yii::$app->getUser()->id, 'action' => History::ACTION_EDIT_TOPIC, 'action_time' => $model->updated_at, 'target' => $model->id, 'ext' => json_encode($ext)]))->save(false); Node::updateAllCounters(['topic_count' => 1], ['id' => $ext['newNode']['id']]); Node::updateAllCounters(['topic_count' => -1], ['id' => $ext['oldNode']['id']]); $url = ['topic/view', 'id' => $id]; if (($ip = $request->get('ip', 1)) > 1) { $url['ip'] = $ip; } return $this->redirect($url); } return $this->render('changeNode', ['model' => $model]); }
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'); }
/** * Create a new child node * * @param Request $request * @param $id * @return \Illuminate\Http\JsonResponse */ public function addChild(Request $request, $id) { $parent = $this->findModelById($id); $name = $request->get('name'); $child = new Node(['name' => $name]); $child->save(); $child->makeChildOf($parent); return Response::json('success'); }
public function afterDelete() { if ($this->type === self::TYPE_NODE) { $action = 'unfollowNode'; Node::updateCounterInfo($action, $this->target_id); } else { if ($this->type === self::TYPE_TOPIC) { $action = 'unfollowTopic'; Topic::updateCounterInfo($action, $this->target_id); } else { if ($this->type === self::TYPE_USER) { $action = 'unfollowUser'; UserInfo::updateCounterInfo('unfollowed', $this->target_id); } } } UserInfo::updateCounterInfo($action, Yii::$app->getUser()->getId()); return parent::afterDelete(); }
<div class="row"> <!-- sf-left start --> <div class="col-md-8 col-sm-12 sf-left"> <?php if (intval($settings['cache_enabled']) === 0 || $this->beginCache('f-all-nodes', ['duration' => intval($settings['cache_time']) * 60])) { ?> <div class="box"> <div class="inner"> <?php echo Html::a('首页', ['topic/index']), ' / ', $this->title; ?> </div> <div class="inner hot-nodes sf-btn"> <?php $nodes = \app\models\Node::getAllNodes(); foreach ($nodes as $node) { echo Html::a(Html::encode($node['name']), ['topic/node', 'name' => $node['ename']], ['class' => 'btn btn-default']); } ?> </div> </div> <?php if (intval($settings['cache_enabled']) !== 0) { $this->endCache(); } } ?> </div> <!-- sf-left end -->
public function node() { return Node::find($this->attributes['node_id']); }
public function getTotalNode() { return Node::count(); }
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>"; } } }
<div class="row"> <div class="col-md-8 sf-left"> <div class="box"> <div class="inner"> <?php echo Html::a('首页', $indexUrl), ' / ', Html::a(Html::encode($model['node']['name']), $nodeUrl), ' / ', $this->title; ?> </div> <div class="cell"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'node_id')->dropDownList(\app\models\Node::getNodeList(), ['class' => 'form-control select2']); ?> <?php echo $form->field($model, 'title')->textArea(['rows' => '4', 'maxlength' => 120, 'readonly' => 'readonly']); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? '创建' : '修改', ['class' => 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?> </div> </div>
public function index() { $nodes = Node::all(); return $this->view()->assign('nodes', $nodes)->display('admin/node.tpl'); }
$form = ActiveForm::begin(); ?> <p>主题标题 <span class="gray">( 如果标题能够表达完整内容,主题内容可为空 )</span></p> <?php echo $form->field($model, 'title')->textArea(['rows' => '4', 'maxlength' => 120])->label(false); ?> <p>主题内容</p> <?php echo $form->field($content, 'content')->textArea(['id' => 'editor', 'maxlength' => 30000])->label(false); ?> <?php echo $form->field($model, 'node_id')->dropDownList(array('' => '') + Node::getNodeList(), ['class' => 'form-control nodes-select2'])->label(false); ?> <div class="new-hot-nodes">热门节点: <?php $hotNodes = Node::getHotNodes(); foreach ($hotNodes as $hn) { echo Html::a(Html::encode($hn['name']), 'javascript:chooseNode("' . $hn['id'] . '");', ['class' => 'node']); } ?> </div> <p>标签 <span class="gray">( 最多4个,以空格分隔 )</span></p> <?php echo $form->field($model, 'tags')->textInput(['id' => 'tags', 'maxlength' => 60])->label(false); if (Yii::$app->getUser()->getIdentity()->canUpload($settings)) { $editor->registerUploadAsset($this); echo '<div class="form-group"><div id="fileuploader">图片上传</div></div>'; } ?> <div class="form-group"> <?php
/** pole koloru zwraca ttablicę gdzie mamy wybrane kolory w kolejnosci 0 'zolty NIE', 1 'zolty TAK', 2 'zielony NIE', 3 'zielony TAK', 4 'szary NIE', 5 'szary TAK', 6 'czerwony NIE', 7 'czerwony TAK' czyli np "color" => array:4 [▼ 0 => "0" 1 => "2" 2 => "5" 3 => "7" ] **/ public function vplsView(Request $request) { if (Request::isMethod('post')) { $data = $request::all(); if (isset($data['color'])) { $affinity = $this->makeMask($data['color']); } else { $affinity = 15; } $router1 = Node::getbyID($data['ruter1']); $router2 = Node::getbyID($data['ruter2']); $interface1 = $data['interface1']; $interface2 = $data['interface2']; //Traffic eng interface $config1 = 'interface traffic-eng add name=' . $data['ruter1'] . 'to' . $data['ruter2'] . ' primary-path=dyn record-route=yes bandwidth=' . $data['bitrate'] . 'M bandwidth-limit=100 affinity-include-any=' . $affinity . ' from-address=' . $router1['name'] . ' to-address=' . $router2['name'] . ' disabled=no; '; //VPLS $config1 .= 'interface vpls add name=vpls-' . $data['ruter1'] . 'to' . $data['ruter2'] . ' remote-peer=' . $router2['name'] . ' vpls-id=' . $data['ruter1'] . ':' . $data['ruter2'] . ' disabled=no; '; //Bridge VPLS and local interface $config1 .= 'interface bridge add name=vpls-bridge-' . $interface1 . '; '; $config1 .= 'interface bridge port add bridge=vpls-bridge-' . $interface1 . ' interface=vpls-' . $data['ruter1'] . 'to' . $data['ruter2'] . '; '; $config1 .= 'interface bridge port add bridge=vpls-bridge-' . $interface1 . ' interface=' . $interface1 . '; '; $config2 = 'interface traffic-eng add name=' . $data['ruter2'] . 'to' . $data['ruter1'] . ' primary-path=dyn record-route=yes bandwidth=' . $data['bitrate'] . 'M bandwidth-limit=100 affinity-include-any=' . $affinity . ' from-address=' . $router2['name'] . ' to-address=' . $router1['name'] . ' disabled=no; '; //VPLS $config2 .= 'interface vpls add name=vpls-' . $data['ruter2'] . 'to' . $data['ruter1'] . ' remote-peer=' . $router1['name'] . ' vpls-id=' . $data['ruter1'] . ':' . $data['ruter2'] . ' disabled=no; '; //Bridge VPLS and local interface $config2 .= 'interface bridge add name=vpls-bridge-' . $interface2 . '; '; $config2 .= 'interface bridge port add bridge=vpls-bridge-' . $interface2 . ' interface=vpls-' . $data['ruter2'] . 'to' . $data['ruter1'] . '; '; $config2 .= 'interface bridge port add bridge=vpls-bridge-' . $interface2 . ' interface=' . $interface2 . '; '; $sshService1 = new SshService($router1['ip'], $router1['login'], $router1['password'], 22, '/tmp/log.txt'); $sshService1->cmd($config1); $sshService1->disconnect(); $sshService2 = new SshService($router2['ip'], $router2['login'], $router2['password'], 22, '/tmp/log.txt'); $sshService2->cmd($config2); $sshService2->disconnect(); return view('scripts.simulator.vplsConfig')->with(compact('config1', 'config2')); } $nodes = Node::get(); return view('scripts.simulator.vpls')->with('nodes', $nodes); }
public function afterDelete() { (new History(['user_id' => $this->user_id, 'action' => History::ACTION_DELETE_TOPIC, 'target' => $this->id]))->save(false); TopicContent::deleteAll(['topic_id' => $this->id]); Node::updateCounterInfo('deleteTopic', $this->node_id); UserInfo::updateCounterInfo('deleteTopic', $this->user_id); $count = Comment::afterTopicDelete($this->id); Siteinfo::updateCountersInfo(['topics' => -1, 'comments' => -$count]); Favorite::afterTopicDelete($this->id); Notice::afterTopicDelete($this->id); return parent::afterDelete(); }
protected function getLastNode() { return Node::orderBy('id', "DESC")->first(); }