/**
  * Creates a new DcmdOprCmdExec model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 private function actionCreate()
 {
     $model = new DcmdOprCmdExec();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->exec_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 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;
 }