/** * 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]); }
/** * Finds the DcmdGroupCmd model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return DcmdGroupCmd the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = DcmdGroupCmd::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Deletes an existing DcmdGroup model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { /*$node = DcmdUserGroup::find()->where(['gid' => $id])->one(); if($node) { Yii::$app->getSession()->setFlash('error', '用户组内有用户,不可删除!'); }else { $this->findModel($id)->delete(); Yii::$app->getSession()->setFlash('success', '删除成功!'); }*/ if (Yii::$app->user->getIdentity()->admin != 1 || Yii::$app->user->getIdentity()->sa != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "Sorry, You don't have priority!"); return $this->redirect(array('index')); } DcmdUserGroup::deleteAll("gid=" . $id); DcmdGroupCmd::deleteAll('gid=' . $id); DcmdGroupRepeatCmd::deleteAll('gid=' . $id); $model = $this->findModel($id); $this->oprlog(3, "delete group:" . $model->gname); $model->delete(); Yii::$app->getSession()->setFlash('success', '删除成功!'); return $this->redirect(['index']); }