Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = DcmdOprCmdExec::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['exec_id' => $this->exec_id, 'opr_cmd_id' => $this->opr_cmd_id, 'timeout' => $this->timeout, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]);
     $query->andFilterWhere(['like', 'opr_cmd', $this->opr_cmd])->andFilterWhere(['like', 'run_user', $this->run_user])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'arg', $this->arg]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 public function actionShellRun()
 {
     $temp = explode(";", Yii::$app->request->post()['args']);
     $args = array();
     foreach ($temp as $ag) {
         $i = explode("=", $ag);
         if (sizeof($i) != 2) {
             continue;
         }
         $args[$i[0]] = $i[1];
     }
     $opr_cmd_id = Yii::$app->request->post()['opr_cmd_id'];
     $opr_cmd = $this->findModel($opr_cmd_id);
     $opr_exec = new DcmdOprCmdExec();
     $opr_exec->opr_cmd_id = $opr_cmd_id;
     $opr_exec->opr_cmd = $opr_cmd->opr_cmd;
     $opr_exec->run_user = $opr_cmd->run_user;
     $opr_exec->timeout = Yii::$app->request->post()['timeout'];
     $opr_exec->ip = Yii::$app->request->post()['ips'];
     $opr_exec->arg = arrToXml($args);
     $opr_exec->utime = date('Y-m-d H:i:s');
     $opr_exec->ctime = $opr_exec->utime;
     $opr_exec->opr_uid = Yii::$app->user->getId();
     $retcontent = array();
     if ($opr_exec->save()) {
         $query = DcmdCenter::findOne(['master' => 1]);
         if ($query) {
             list($ip, $port) = explode(':', $query["host"]);
             $reply = execOprCmd($ip, $port, $opr_exec->exec_id);
             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.";
         }
     } else {
         $retContent["result"] = "数据库操作失败!";
     }
     echo json_encode($retContent);
     exit;
 }
 /**
  * Finds the DcmdOprCmdExec model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DcmdOprCmdExec the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdOprCmdExec::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }