/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = DcmdGroupRepeatCmd::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'gid' => $this->gid, 'repeat_cmd_id' => $this->repeat_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 = DcmdGroupRepeatCmd::find()->where($gstr)->asArray()->all(); if ($qstr == NULL) { $qstr = " repeat_cmd_id in (0"; } else { $qstr .= " and repeat_cmd_id in (0"; } foreach ($query as $item) { $qstr .= "," . $item['repeat_cmd_id']; } $qstr .= ")"; } if ($qstr) { $query = DcmdOprCmdRepeatExec::find()->andWhere($qstr)->orderBy('repeat_cmd_name'); } else { $query = DcmdOprCmdRepeatExec::find()->orderBy('repeat_cmd_name'); } $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pagesize' => 20]]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['repeat_cmd_id' => $this->repeat_cmd_id, 'timeout' => $this->timeout, 'repeat' => $this->repeat, 'cache_time' => $this->cache_time, 'ip_mutable' => $this->ip_mutable, 'arg_mutable' => $this->arg_mutable, 'utime' => $this->utime, 'ctime' => $this->ctime, 'opr_uid' => $this->opr_uid]); $query->andFilterWhere(['like', 'repeat_cmd_name', $this->repeat_cmd_name])->andFilterWhere(['like', 'opr_cmd', $this->opr_cmd])->andFilterWhere(['like', 'run_user', $this->run_user])->andFilterWhere(['like', 'ip', $this->ip])->andFilterWhere(['like', 'arg', $this->arg]); return $dataProvider; }
public function actionRun($id, $ips = "") { ///判断用户权限 if (Yii::$app->user->getIdentity()->admin != 1) { $gstr = " gid in (0"; $query = DcmdUserGroup::find()->andWhere(['uid' => Yii::$app->user->getId()])->asArray()->all(); foreach ($query as $item) { $gstr .= "," . $item['gid']; } $gstr .= ")"; $query = DcmdGroupRepeatCmd::find()->where($gstr)->asArray()->all(); if (count($query) == 0) { Yii::$app->getSession()->setFlash('error', '对不起, 你没有权限!'); return $this->redirect(['dcmd-opr-cmd-repeat-exec/index']); } } $opr = $this->findModel($id); $change = true; if ($opr->arg_mutable == "0") { $change = false; } $arg = $this->getArg($opr->arg, $change, $opr->opr_cmd); if ($opr->ip_mutable == "1" && $ips != "") { $opr->ip = $ips; } return $this->render('run', ['opr' => $opr, 'arg' => $arg]); }
public function actionAddGroup($repeat_cmd_id = 0) { 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')); } $model = new DcmdGroupRepeatCmd(); if (Yii::$app->request->post()) { ///var_dump(Yii::$app->request->post());exit; $date = date('Y-m-d H:i:s'); if (is_array(Yii::$app->request->post()['DcmdGroupRepeatCmd']['gid'])) { foreach (Yii::$app->request->post()['DcmdGroupRepeatCmd']['gid'] as $gid) { $dcmd_group_cmd = new DcmdGroupRepeatCmd(); $dcmd_group_cmd->gid = $gid; $dcmd_group_cmd->repeat_cmd_id = $repeat_cmd_id; $dcmd_group_cmd->utime = $date; $dcmd_group_cmd->ctime = $date; $dcmd_group_cmd->opr_uid = Yii::$app->user->getId(); $dcmd_group_cmd->save(); Yii::$app->getSession()->setFlash('success', '添加成功!'); } } else { Yii::$app->getSession()->setFlash('error', "没有选择用户组!"); } return $this->redirect(['dcmd-opr-cmd-repeat-exec/view', 'id' => $repeat_cmd_id]); } else { $exist_group = array(); $query = DcmdGroupRepeatCmd::find()->andWhere(['repeat_cmd_id' => $repeat_cmd_id])->asArray()->all(); foreach ($query as $item) { $exist_group[$item['gid']] = $item['gid']; } $query = DcmdGroup::find()->andWhere(['gtype' => 2])->asArray()->all(); $group = array(); foreach ($query as $item) { if (!array_key_exists($item['gid'], $exist_group)) { $group[$item['gid']] = $item['gname']; } } $repeat_cmd = DcmdOprCmdRepeatExec::findOne($repeat_cmd_id); return $this->render('add_group', ['model' => $model, 'repeat_cmd' => $repeat_cmd, 'group' => $group]); } }