/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DcmdGroupCmd::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'gid' => $this->gid, 'opr_cmd_id' => $this->opr_cmd_id, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); return $dataProvider; }
/** * 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; }
public function actionRun($opr_cmd_id, $ips = "") { ///判断用户权限 if (Yii::$app->user->getIdentity()->admin != 1) { $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all(); $gstr = " opr_cmd_id = " . $opr_cmd_id . " and gid in (0"; foreach ($query as $item) { $gstr .= "," . $item['gid']; } $gstr .= ")"; $query = DcmdGroupCmd::find()->where($gstr)->asArray()->all(); if (count($query) == 0) { Yii::$app->getSession()->setFlash('error', '对不起, 你没有权限!'); return $this->redirect(['dcmd-opr-cmd/index']); } } $opr = $this->findModel($opr_cmd_id); $arg = $this->showTaskArg($opr_cmd_id); return $this->render('run', ['opr' => $opr, 'arg' => $arg, 'ips' => $ips]); }
/** * Creates a new DcmdGroupCmd model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate($gid, $gname) { if (Yii::$app->user->getIdentity()->admin != 1 || Yii::$app->user->getIdentity()->sa != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(array('dcmd-group/index')); } $query = DcmdGroupCmd::find()->andWhere(['gid' => $gid])->asArray()->all(); $opr_cmd = " opr_cmd_id not in(0"; foreach ($query as $item) { $opr_cmd .= "," . $item['opr_cmd_id']; } $opr_cmd .= ")"; $searchModel = new DcmdOprCmdSearch(); $dataProvider = $searchModel->search(array(), $opr_cmd); return $this->render('create', ['gid' => Yii::$app->request->queryParams['gid'], 'gname' => Yii::$app->request->queryParams['gname'], 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]); /*$model = new DcmdGroupCmd(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); }*/ }