public function getNodeId($ip)
 {
     $query = DcmdNode::findOne(['ip' => $ip]);
     if ($query) {
         return $query['nid'];
     }
     return "";
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $unuse = false)
 {
     $con_str = "";
     if ($unuse) {
         $q = DcmdServicePoolNode::find()->asArray()->all();
         $con_str = " ip not in(0";
         foreach ($q as $item) {
             $con_str .= ",'" . $item['ip'] . "'";
         }
         $con_str .= ")";
     }
     $query = DcmdNode::find()->where($con_str)->orderBy('ip');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => '20']]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['nid' => $this->nid, 'ngroup_id' => $this->ngroup_id, 'online_time' => $this->online_time, 'purchase_time' => $this->purchase_time, 'maintain_time' => $this->maintain_time, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]);
     $query->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'host', $this->host])->andFilterWhere(['like', 'sid', $this->sid])->andFilterWhere(['like', 'did', $this->did])->andFilterWhere(['like', 'os_type', $this->os_type])->andFilterWhere(['like', 'os_ver', $this->os_ver])->andFilterWhere(['like', 'bend_ip', $this->bend_ip])->andFilterWhere(['like', 'public_ip', $this->public_ip])->andFilterWhere(['like', 'mach_room', $this->mach_room])->andFilterWhere(['like', 'rack', $this->rack])->andFilterWhere(['like', 'seat', $this->seat])->andFilterWhere(['like', 'server_brand', $this->server_brand])->andFilterWhere(['like', 'server_model', $this->server_model])->andFilterWhere(['like', 'cpu', $this->cpu])->andFilterWhere(['like', 'memory', $this->memory])->andFilterWhere(['like', 'disk', $this->disk])->andFilterWhere(['like', 'maintain_fac', $this->maintain_fac])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 private function importNodeTxt($fnamei, $ngroup_id)
 {
     $fd = fopen($fname, "r");
     $msg = "";
     if ($fd) {
         while (!feof($fd)) {
             $line = fgets($fd);
             $ar = explode(" ", $line);
             if (count($ar) != 21) {
                 $msg .= "<font color=red>{$line}: 格式非法!</font><br>";
             } else {
                 $node = new DcmdNode();
                 $node->ip = $ar[0];
                 $node->ngroup_id = $ngroup_id;
                 $node->host = $ar[1];
                 $node->sid = $ar[2];
                 $node->did = $ar[3];
                 $node->os_type = $ar[4];
                 $node->os_ver = $ar[5];
                 $node->band_ip = $ar[6];
                 $node->public_ip = $ar[7];
                 $node->mach_room = $var[8];
                 $node->rack = $var[9];
                 $node->seat = $var[10];
                 $node->online_time = $var[11];
                 $node->server_brand = $var[12];
                 $node->server_model = $var[13];
                 $node->cpu = $var[14];
                 $node->memory = $var[15];
                 $node->disk = $var[16];
                 $node->purchase_time = $var[17];
                 $node->maintain_time = $var[18];
                 $node->maintain_fac = $var[19];
                 $node->comment = $var[20];
                 $node->utime = date('Y-m-d H:i:s');
                 $node->ctime = $model->utime;
                 $node->opr_uid = Yii::$app->user->getId();
                 if ($node->save()) {
                     $msg .= "{$line}: 添加成功!<br>";
                 } else {
                     $err_str = "";
                     foreach ($model->getErrors() as $k => $v) {
                         $err_str .= $k . ":" . $v[0] . "<br>";
                     }
                     $msg .= "<font color=red>{$line} :添加失败: {$err_str}</font><br>";
                 }
             }
         }
     } else {
         $msg = "打开文件失败";
     }
     return $msg;
 }
 public function actionAddNode()
 {
     $app_id = Yii::$app->request->post()["app_id"];
     $svr_id = Yii::$app->request->post()["svr_id"];
     $svr_pool_id = Yii::$app->request->post()["svr_pool_id"];
     $model = DcmdApp::findOne($app_id);
     ///判断用户所属的系统组是否和该应用相同
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $model['sa_gid']]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!");
         return $this->redirect(array('dcmd-service-pool/view', 'id' => $svr_pool_id, 'show_div' => 'dcmd-service-pool-node'));
     }
     $service = DcmdService::findOne($svr_id);
     $success_msg = "";
     $err_msg = "";
     if (array_key_exists("selection", Yii::$app->request->post())) {
         $success_msg = "成功添加以下设备:";
         $nid_str = "nid in (0";
         foreach (Yii::$app->request->post()["selection"] as $k => $v) {
             $nid_str .= "," . $v;
         }
         $nid_str .= ")";
         $query = DcmdNode::find()->where($nid_str)->asArray()->all();
         $tm = date('Y-m-d H:i:s');
         foreach ($query as $item) {
             if ($service->node_multi_pool == 0) {
                 ///不可重复节点
                 $temp = DcmdServicePoolNode::findOne(['svr_id' => $svr_id, 'ip' => $item['ip']]);
                 if ($temp) {
                     $err_msg .= "已经有池子使用该节点:" . $item['ip'] . " ";
                     continue;
                 }
             }
             $server_pool_node = new DcmdServicePoolNode();
             $server_pool_node->svr_pool_id = $svr_pool_id;
             $server_pool_node->svr_id = $svr_id;
             $server_pool_node->app_id = $app_id;
             $server_pool_node->nid = $item['nid'];
             $server_pool_node->ip = $item['ip'];
             $server_pool_node->utime = $tm;
             $server_pool_node->ctime = $tm;
             $server_pool_node->opr_uid = Yii::$app->user->getId();
             $server_pool_node->save();
             $this->oprlog(1, "add ip:" . $item['ip']);
             $success_msg .= $item['ip'] . " ";
         }
     }
     if ($success_msg != "") {
         Yii::$app->getSession()->setFlash('success', $success_msg);
     }
     if ($err_msg != "") {
         Yii::$app->getSession()->setFlash('error', $err_msg);
     }
     return $this->redirect(array('dcmd-service-pool/view', 'id' => $svr_pool_id, 'show_div' => 'dcmd-service-pool-node'));
 }
 /**
  * Finds the DcmdNode model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DcmdNode the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdNode::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }