예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params, $qstr = NULL)
 {
     ///非系统用户只能查看授权的操作
     if (Yii::$app->user->getIdentity()->admin != 1) {
         $gstr = " gid in (0";
         $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all();
         if ($query) {
             foreach ($query as $item) {
                 $gstr .= "," . $item['gid'];
             }
         }
         $gstr .= ")";
         $query = DcmdGroupCmd::find()->where($gstr)->asArray()->all();
         if ($qstr == NULL) {
             $qstr = " opr_cmd_id in (0";
         } else {
             $qstr .= " and opr_cmd_id in (0";
         }
         foreach ($query as $item) {
             $qstr .= "," . $item['opr_cmd_id'];
         }
         $qstr .= ")";
     }
     if ($qstr) {
         $query = DcmdOprCmd::find()->andWhere($qstr)->orderBy('opr_cmd');
     } else {
         $query = DcmdOprCmd::find();
     }
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['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', 'ui_name', $this->ui_name])->andFilterWhere(['like', 'run_user', $this->run_user])->andFilterWhere(['like', 'script_md5', $this->script_md5])->andFilterWhere(['like', 'comment', $this->comment]);
     return $dataProvider;
 }
 /**
  * Creates a new DcmdOprCmdRepeatExec model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->getIdentity()->admin != 1) {
         Yii::$app->getSession()->setFlash('success', NULL);
         Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!");
         return $this->redirect(array('dcmd-opr-cmd-repeat-exec/index'));
     }
     if (Yii::$app->request->post()) {
         $params = Yii::$app->request->post()['DcmdOprCmdRepeatExec'];
         $query = DcmdOprCmd::findOne(['opr_cmd' => $params['opr_cmd']]);
         $opr_cmd_repeat = new DcmdOprCmdRepeatExec();
         $opr_cmd_repeat->repeat_cmd_name = $params['repeat_cmd_name'];
         $opr_cmd_repeat->opr_cmd = $params['opr_cmd'];
         $opr_cmd_repeat->run_user = $query['run_user'];
         $opr_cmd_repeat->timeout = $params['timeout'];
         $opr_cmd_repeat->cache_time = $params['cache_time'];
         $opr_cmd_repeat->ip = $params['ip'];
         $opr_cmd_repeat->repeat = $params['repeat'];
         $opr_cmd_repeat->ip_mutable = $params['ip_mutable'];
         $opr_cmd_repeat->arg_mutable = $params['arg_mutable'];
         $opr_cmd_repeat->utime = date('Y-m-d H:i:s');
         $opr_cmd_repeat->ctime = $opr_cmd_repeat->utime;
         $opr_cmd_repeat->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;
             }
         }
         $opr_cmd_repeat->arg = arrToXml($arg);
         if ($opr_cmd_repeat->save()) {
             $this->oprlog(1, "insert repeat exec cmd:" . $opr_cmd_repeat->repeat_cmd_name);
             Yii::$app->getSession()->setFlash('success', "添加成功");
             return $this->redirect(['view', 'id' => $opr_cmd_repeat->repeat_cmd_id]);
         }
         $err_str = "";
         foreach ($model->getErrors() as $k => $v) {
             $err_str .= $k . ":" . $v[0] . "<br>";
         }
         Yii::$app->getSession()->setFlash('error', "添加失败:" . $err_str);
     }
     $model = new DcmdOprCmdRepeatExec();
     $query = DcmdOprCmd::find()->asArray()->all();
     $opr_cmd = array("" => "");
     foreach ($query as $item) {
         $opr_cmd[$item['opr_cmd']] = $item['opr_cmd'];
     }
     return $this->render('create', ['model' => $model, 'opr_cmd' => $opr_cmd]);
 }