public function actionMonitorTask($task_id)
 {
     $task = DcmdTask::findOne($task_id);
     ///非系统管理员只能操作同一产品组的该任务
     if (Yii::$app->user->getIdentity()->admin != 1) {
         if ($task->opr_uid != Yii::$app->user->getId()) {
             ///判断是否为同一产品组
             $app = DcmdApp::findOne($task->app_id);
             $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['svr_gid']]);
             if ($query == NULL) {
                 Yii::$app->getSession()->setFlash('success', NULL);
                 Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
                 return $this->redirect(array('dcmd-task/index'));
             }
         }
     } else {
         ///系统管理员产品所属同一系统组
         $app = DcmdApp::findOne($task->app_id);
         $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['sa_gid']]);
         if ($query == NULL) {
             Yii::$app->getSession()->setFlash('success', NULL);
             Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
             return $this->redirect(array('dcmd-task/index'));
         }
     }
     if (Yii::$app->request->post()) {
         $timeout = Yii::$app->request->post()['timeout'];
         $auto = Yii::$app->request->post()['auto'];
         $concurrent_rate = Yii::$app->request->post()['concurrent_rate'];
         $this->updateTask($task_id, $timeout, $auto, $concurrent_rate);
         ////var_dump(Yii::$app->request->post());exit;
     }
     ///获取产品名称
     ///$query = DcmdService::findOne($task->svr_id);
     $app_id = $task->app_id;
     /// $query->app_id;
     ///$query = DcmdApp::findOne($app_id);
     $app_name = $task->app_name;
     $ret = xml_to_array($task->task_arg);
     $args = "";
     if (is_array($ret['env'])) {
         foreach ($ret['env'] as $k => $v) {
             $args .= $k . '=' . $v . " ; ";
         }
     }
     return $this->render('monitor', ['task_id' => $task_id, 'task' => $task, 'args' => $args, 'app_name' => $app_name, 'app_id' => $app_id]);
 }
 /**
  * Updates an existing DcmdServicePoolAttr model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id, $svr_pool_id)
 {
     $svr_pool = DcmdServicePool::findOne($svr_pool_id);
     ///仅仅用户与该应用在同一个系统组才可以操作
     $temp = DcmdApp::findOne($svr_pool->app_id);
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['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-attr'));
     }
     if ($id == 0) {
         ///需要新建
         $attr_id = Yii::$app->request->queryParams['attr_id'];
         $def_attr = DcmdServicePoolAttrDef::findOne($attr_id);
         $query = DcmdServicePoolAttr::findOne(['svr_pool_id' => $svr_pool_id, 'attr_name' => $def_attr->attr_name]);
         if (count($query) > 0) {
             $id = $query['id'];
         } else {
             $model = new DcmdServicePoolAttr();
             $model->app_id = $svr_pool->app_id;
             $model->svr_id = $svr_pool->svr_id;
             $model->svr_pool_id = $svr_pool_id;
             $model->attr_name = $def_attr->attr_name;
             $model->attr_value = $def_attr->def_value;
             $model->comment = $def_attr->comment;
             $model->utime = date('Y-m-d H:i:s');
             $model->ctime = $model->utime;
             $model->opr_uid = Yii::$app->user->getId();
             $model->save();
             $id = $model->id;
         }
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', '修改成功!');
         return $this->redirect(['/dcmd-service-pool/view', 'id' => $model->svr_pool_id, 'show_div' => 'dcmd-service-pool-attr']);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
Example #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     ///应用足用户只可查看所在组的应用
     $app_con = "";
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $app_con = "svr_gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $app_con .= "," . $item['gid'];
             }
         }
         $app_con .= ")";
     }
     $query = DcmdApp::find()->where($app_con)->orderBy('app_name');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['app_id' => $this->app_id, 'sa_gid' => $this->sa_gid, 'svr_gid' => $this->svr_gid, 'depart_id' => $this->depart_id, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]);
     $query->andFilterWhere(['like', 'app_name', $this->app_name])->andFilterWhere(['like', 'app_alias', $this->app_alias])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 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 actionDeleteAll()
 {
     if (!array_key_exists('selection', Yii::$app->request->post())) {
         Yii::$app->getSession()->setFlash('error', '未选择服务!');
         return $this->redirect(['index']);
     }
     $select = Yii::$app->request->post()['selection'];
     $ret_msg = "";
     foreach ($select as $k => $id) {
         $model = $this->findModel($id);
         ///仅仅用户与该应用在同一个系统组才可以操作
         $temp = DcmdApp::findOne($model['app_id']);
         $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['sa_gid']]);
         if ($query == NULL) {
             $ret_msg .= "没有权限删除:" . $model->ip . " ";
             continue;
         }
         $model->delete();
         $ret_msg .= '删除成功:' . $model->ip . " ";
     }
     Yii::$app->getSession()->setFlash('success', $ret_msg);
     return $this->redirect(['index']);
 }
 /**
  * Updates an existing DcmdTaskTemplate model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     ///只有管理员可以操作
     if (Yii::$app->user->getIdentity()->admin != 1) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
         return $this->redirect(array('dcmd-task-template/view', 'id' => $id));
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->load(Yii::$app->request->post());
         $query = DcmdService::findOne($model->svr_id);
         $model->svr_name = $query['svr_name'];
         $query = DcmdTaskCmd::findOne($model->task_cmd_id);
         ////Yii::$app->request->post()['task_cmd_id']);
         $model->task_cmd = $query['task_cmd'];
         $model->utime = date('Y-m-d H:i:s');
         $model->ctime = $model->utime;
         $model->opr_uid = Yii::$app->user->getId();
         $arg = array();
         foreach (Yii::$app->request->post() as $k => $v) {
             if (substr($k, 0, 3) == "Arg") {
                 $arg[substr($k, 3)] = $v;
             }
         }
         $model->task_arg = arrToXml($arg);
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', "修改成功");
             $this->oprlog(2, "update task template:" . $model->task_tmpt_name);
             return $this->redirect(['view', 'id' => $model->task_tmpt_id]);
         }
     }
     ///获取产品信息
     $query = DcmdApp::find()->asArray()->all();
     $app = array("" => "");
     if ($query) {
         foreach ($query as $item) {
             $app[$item['app_id']] = $item['app_name'];
         }
     }
     ///获取任务脚本
     $query = DcmdTaskCmd::find()->asArray()->all();
     $task_cmd = array("" => "");
     if ($query) {
         foreach ($query as $item) {
             $task_cmd[$item['task_cmd_id']] = $item['task_cmd'];
         }
     }
     $arg_content = $this->actionGetTaskTypeArg($model->task_cmd_id, xmltoarray($model->task_arg));
     return $this->render('update', ['model' => $model, 'app' => $app, 'task_cmd' => $task_cmd, 'svr' => array($model->svr_id => $model->svr_name), 'arg_content' => $arg_content]);
 }
 /**
  * Finds the DcmdApp model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return DcmdApp the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = DcmdApp::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionDeleteAll()
 {
     if (!array_key_exists('selection', Yii::$app->request->post())) {
         Yii::$app->getSession()->setFlash('error', '未选择服务池!');
         return $this->redirect(['index']);
     }
     $select = Yii::$app->request->post()['selection'];
     $err_msg = "";
     $suc_msg = "";
     foreach ($select as $k => $id) {
         $model = $this->findModel($id);
         ///仅仅用户与该应用在同一个系统组才可以操作
         $temp = DcmdApp::findOne($model['app_id']);
         $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['sa_gid']]);
         if ($query == NULL) {
             $err_msg .= $model->svr_pool . ":没有权限删除<br>";
             continue;
         }
         $node = DcmdServicePoolNode::find()->where(['svr_pool_id' => $id])->one();
         if ($node) {
             $err_msg .= $model->svr_pool . ':服务池子设备不为空,不可删除<br>';
             continue;
         } else {
             ///删除服务池属性
             DcmdServicePoolAttr::deleteAll(['svr_pool_id' => $id]);
             $model->delete();
             $suc_msg .= $model->svr_pool . ':删除成功<br>';
         }
     }
     if ($suc_msg != "") {
         Yii::$app->getSession()->setFlash('success', $suc_msg);
     }
     if ($err_msg != "") {
         Yii::$app->getSession()->setFlash('error', $err_msg);
     }
     return $this->redirect(['index']);
 }
 /**
  * Deletes an existing DcmdAppArchDiagram model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     $app_query = DcmdApp::findOne($model->app_id);
     ///判断用户所属的系统组是否和该应用相同
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app_query['sa_gid']]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!");
         return $this->redirect(array('dcmd-app/view', 'id' => $model->app_id));
     }
     $app_id = $model->app_id;
     $arch_name = $model->arch_name;
     $model->delete();
     Yii::$app->getSession()->setFlash('success', '删除成功!');
     ///删除文件
     $base_path = dirname(__DIR__) . "/web/app_image/app_";
     $img_path = $base_path . $arch_name . '_' . $app_id . '.jpg';
     if (file_exists($img_path)) {
         unlink($img_path);
     }
     $opr_log = new DcmdOprLog();
     $opr_log->log_table = "dcmd_app_arch_diagram";
     $opr_log->opr_type = 3;
     $opr_log->sql_statement = "delete arch_name:{$arch_name}";
     $opr_log->ctime = date('Y-m-d H:i:s');
     $opr_log->opr_uid = Yii::$app->user->getId();
     $opr_log->save();
     return $this->redirect(['dcmd-app/view', 'id' => $app_id]);
 }
 function actionFinishTask()
 {
     $suc_msg = "";
     $err_msg = "";
     if (array_key_exists('selection', Yii::$app->request->post())) {
         $task_ids = Yii::$app->request->post()['selection'];
         foreach ($task_ids as $id) {
             $task = $this->findModel($id);
             if (Yii::$app->user->getIdentity()->admin != 1 && $task->opr_uid != Yii::$app->user->getId()) {
                 ///判断是否为同一产品组
                 $app = DcmdApp::findOne($task->app_id);
                 $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $app['svr_gid']]);
                 if ($query == NULL) {
                     $err_msg .= $task->task_name . ": 没有权限<br>";
                     continue;
                 }
             }
             ///删除dcmd_task_service_pool_history
             DcmdTaskServicePoolHistory::deleteAll(['task_id' => $id]);
             ///dcmd_task_node_history
             DcmdTaskNodeHistory::deleteAll(['task_id' => $id]);
             ///dcmd_command_history
             DcmdCommandHistory::deleteAll(['task_id' => $id]);
             ///dcmd_task_service_pool_attr_history
             DcmdTaskServicePoolAttrHistory::deleteAll(['task_id' => $id]);
             $task->delete();
             $this->oprlog(3, "delete history task:" . $task->task_name);
             $suc_msg .= $task->task_name . ": 删除成功<br>";
         }
     }
     if ($suc_msg != "") {
         Yii::$app->getSession()->setFlash('success', $suc_msg);
     }
     if ($err_msg != "") {
         Yii::$app->getSession()->setFlash('error', $err_msg);
     }
     $this->redirect(array('index'));
 }
 /**
  * Deletes an existing DcmdServiceArchDiagram model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $model = $this->findModel($id);
     ///仅仅用户与该应用在同一个系统组才可以操作
     $temp = DcmdApp::findOne($model->app_id);
     $query = DcmdUserGroup::findOne(['uid' => Yii::$app->user->getId(), 'gid' => $temp['sa_gid']]);
     if ($query == NULL) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起, 你没有权限!");
         return $this->redirect(array('dcmd-service/view', 'id' => $model->svr_id));
     }
     $app_id = $model->app_id;
     $svr_id = $model->svr_id;
     $arch_name = $model->arch_name;
     $this->oprlog(3, "delete arch:" . $arch_name);
     $model->delete();
     Yii::$app->getSession()->setFlash('success', '删除成功!');
     ///删除文件
     $base_path = dirname(__DIR__) . "/web/app_image/svr_";
     $img_path = $base_path . $arch_name . '_' . $svr_id . '.jpg';
     if (file_exists($img_path)) {
         unlink($img_path);
     }
     return $this->redirect(['dcmd-service/view', 'id' => $svr_id]);
 }