Пример #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DcmdCenter::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['master' => $this->master, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'host', $this->host]);
     return $dataProvider;
 }
 /**
  * Lists all DcmdNode models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = DcmdCenter::findOne(['master' => 1]);
     $agent = array();
     if ($query) {
         list($ip, $port) = explode(':', $query["host"]);
         $invalidAgent = getInvalidAgent($ip, $port);
         if ($invalidAgent->getState() == 0) {
             $agentInfo = $invalidAgent->getAgentinfo();
             foreach ($agentInfo as $item) {
                 array_push($agent, array('report_ip' => $item->getReportedIp(), 'conn_ip' => $item->getConnectedIp(), 'version' => $item->getVersion()));
             }
         }
     }
     return $this->render('index', ['ips' => $agent]);
 }
Пример #3
0
 public function getAgentState($ip)
 {
     $query = DcmdCenter::findOne(['master' => 1]);
     if ($query) {
         list($host, $port) = explode(':', $query["host"]);
         $agent_info = getAgentInfo($host, $port, array($ip), 1);
         if ($agent_info->getState() == 0) {
             foreach ($agent_info->getAgentinfo() as $agent) {
                 if ($agent->getState() == 3) {
                     return "连接";
                 }
                 return "未连接";
             }
         }
     }
     return "未连接";
 }
Пример #4
0
 function actionFinishTask()
 {
     $suc_msg = "";
     $err_msg = "";
     if (array_key_exists('selection', Yii::$app->request->post())) {
         $task_ids = Yii::$app->request->post()['selection'];
         $query = DcmdCenter::findOne(['master' => 1]);
         if ($query) {
             list($host, $port) = explode(':', $query["host"]);
             foreach ($task_ids as $tid) {
                 $task = $this->findModel($tid);
                 if (Yii::$app->user->getIdentity()->admin != 1 && $task->opr_uid != Yii::$app->user->getId()) {
                     ///判断是否为同一产品组
                     $app = DcmdApp::findOne($task->app_id);
                     $ug = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['svr_gid']]);
                     if ($ug == NULL) {
                         $err_msg .= $task->task_name . ": 没有权限<br>";
                         continue;
                     }
                 }
                 $reply = execTaskCmd($host, $port, $tid, Yii::$app->user->getId(), 5);
                 if ($reply->getState() == 0) {
                     $suc_msg .= $task->task_name . ": 完成成功<br>";
                 } else {
                     $err_msg .= $task->task_name . ": 完成失败 " . $reply->getErr() . "<br>";
                 }
             }
         } else {
             $err_msg = "无法获取Center!";
         }
     }
     if ($suc_msg != "") {
         Yii::$app->getSession()->setFlash('success', $suc_msg);
     }
     if ($err_msg != "") {
         Yii::$app->getSession()->setFlash('error', $err_msg);
     }
     $this->redirect(array('index'));
 }
 public function actionShellRun()
 {
     $repeat_cmd_name = Yii::$app->request->post()['repeat_cmd_name'];
     $repeat_cmd = DcmdOprCmdRepeatExec::findOne(['repeat_cmd_name' => $repeat_cmd_name]);
     $ips = array();
     if ($repeat_cmd->ip_mutable) {
         $t = Yii::$app->request->post()['ips'];
         $ips = explode(";", $t);
     }
     $args = array();
     if ($repeat_cmd->arg_mutable) {
         $temp = explode(";", Yii::$app->request->post()['args']);
         foreach ($temp as $ag) {
             $i = explode("=", $ag);
             if (sizeof($i) != 2) {
                 continue;
             }
             $args[$i[0]] = $i[1];
         }
     }
     $retcontent = array();
     $query = DcmdCenter::findOne(['master' => 1]);
     if ($query) {
         list($ip, $port) = explode(':', $query["host"]);
         $reply = execRepeatOprCmd($ip, $port, $repeat_cmd_name, $args, $ips);
         if ($reply->getState() == 0) {
             $ret_msg = "State:success<br>Detail:<br>";
             foreach ($reply->getResult() as $agent) {
                 $ret_msg .= "-------------------------------------------------------<br>";
                 $ret_msg .= "Ip:" . $agent->getIp() . "<br>";
                 if ($agent->getState() == 0) {
                     $ret_msg .= "State:success<br>";
                     $ret_msg .= "Status:" . $agent->getStatus() . "<br>";
                     $ret_msg .= "Result:<br>" . str_replace("\n", "<br/>", $agent->getResult()) . "<br>";
                 } else {
                     $ret_msg .= "State:error<br>";
                     $ret_msg .= "Detail:<br>" . str_replace("\n", "<br/>", $agent->getErr()) . "<br>";
                 }
                 $retContent["result"] = $ret_msg;
             }
         } else {
             $retContent["result"] = "State:error<br>detail:" . str_replace("\n", "<br/>", $reply->getErr()) . "<br>";
         }
     } else {
         $retContent["result"] = "无法获取Center.";
     }
     echo json_encode($retContent);
     exit;
 }
Пример #6
0
 public function getProcess($subtask_id)
 {
     $query = DcmdCenter::findOne(['master' => 1]);
     if ($query) {
         list($host, $port) = explode(':', $query["host"]);
         $agent_info = getAgentTaskProcess($host, $port, array($subtask_id));
         if ($agent_info->getState() == 0) {
             foreach ($agent_info->getProcess() as $proc) {
                 return $proc->getProcess();
             }
         }
         return $agent_info->getErr();
     }
     return "无法获取Center";
 }
Пример #7
0
 public function actionGetOprList()
 {
     $prefix = Yii::$app->request->post()["prefix"];
     $query = DcmdCenter::findOne(['master' => 1]);
     $retContent = "";
     if ($query) {
         list($ip, $port) = explode(':', $query["host"]);
         $reply = getOprScriptList($ip, $port, $prefix);
         if ($reply->getState() == 0) {
             foreach ($reply->getScripts() as $item) {
                 $retContent .= $item . ";";
             }
         }
     }
     echo $retContent;
     exit;
 }
Пример #8
0
 /**
  * Finds the DcmdCenter model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return DcmdCenter the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdCenter::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionDel($task_id)
 {
     $svr_pool_array = array();
     $query = DcmdTaskServicePool::find()->andWhere(['task_id' => $task_id])->asArray()->all();
     foreach ($query as $item) {
         $svr_pool_array[$item['svr_pool']] = $item['svr_pool'];
     }
     if (Yii::$app->request->post() && array_key_exists('selection', Yii::$app->request->post())) {
         $ret_msg = "";
         $query = DcmdCenter::findOne(['master' => 1]);
         if ($query) {
             list($host, $port) = explode(':', $query["host"]);
             $select = Yii::$app->request->post()['selection'];
             foreach ($select as $subtask_id) {
                 $reply = execTaskCmd($host, $port, $task_id, Yii::$app->user->getId(), 17, $subtask_id);
                 if ($reply->getState() == 0) {
                     $ret_msg .= $subtask_id . ":删除成功 ";
                 } else {
                     $ret_msg .= $subtask_id . ":删除失败:" . $reply->getErr() . " ";
                 }
             }
         } else {
             $ret_msg = "删除失败:无法获取Center!";
         }
         Yii::$app->getSession()->setFlash('success', $ret_msg);
     }
     $params = array();
     $params['DcmdTaskNodeSearch'] = array('task_id' => $task_id);
     if (array_key_exists('DcmdTaskNodeSearch', Yii::$app->request->queryParams)) {
         $params['DcmdTaskNodeSearch'] = Yii::$app->request->queryParams['DcmdTaskNodeSearch'] + $params['DcmdTaskNodeSearch'];
     }
     $searchModel = new DcmdTaskNodeSearch();
     $dataProvider = $searchModel->search($params, 20);
     return $this->render('delete', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'task_id' => $task_id, 'svr_pool' => $svr_pool_array]);
 }
 public function actionSubtaskOutput($subtask_id, $ip, $os)
 {
     $query = DcmdCenter::findOne(['master' => 1]);
     if ($query) {
         list($host, $port) = explode(':', $query["host"]);
         $reply = getTaskOutput($host, $port, $subtask_id, $ip, $os);
         if ($reply->getState() == 0) {
             return '<div id="' . $reply->getOffset() . '">' . str_replace("\n", "<br/>", $reply->getResult()) . '</div>';
         }
         return "<div id='0'>" . $reply->getErr() . "</div>";
     }
     return "<div id='0'>无法获取Center</div>";
 }
Пример #11
0
 public function actionGetAgentHostname()
 {
     $agent_ip = Yii::$app->request->post()["ip"];
     $query = DcmdCenter::findOne(['master' => 1]);
     $retcontent = array("hostname" => "");
     if ($query) {
         list($ip, $port) = explode(':', $query["host"]);
         $reply = getAgentHostName($ip, $port, $agent_ip);
         if ($reply->getState() == 0 && $reply->getIsExist() == true) {
             $retContent["hostname"] = $reply->getHostname();
         }
     }
     echo json_encode($retContent);
     exit;
 }