public function getOprcmd($repeat_cmd_id) { $query = DcmdOprCmdRepeatExec::findOne($repeat_cmd_id); if ($query) { return $query['opr_cmd']; } return ""; }
/** * 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 actionShellRun() { $repeat_cmd_name = Yii::$app->request->post()['repeat_cmd_name']; $repeat_cmd = DcmdOprCmdRepeatExec::findOne(['repeat_cmd_name' => $repeat_cmd_name]); $ips = array(); if ($repeat_cmd->ip_mutable) { $t = Yii::$app->request->post()['ips']; $ips = explode(";", $t); } $args = array(); if ($repeat_cmd->arg_mutable) { $temp = explode(";", Yii::$app->request->post()['args']); foreach ($temp as $ag) { $i = explode("=", $ag); if (sizeof($i) != 2) { continue; } $args[$i[0]] = $i[1]; } } $retcontent = array(); $query = DcmdCenter::findOne(['master' => 1]); if ($query) { list($ip, $port) = explode(':', $query["host"]); $reply = execRepeatOprCmd($ip, $port, $repeat_cmd_name, $args, $ips); if ($reply->getState() == 0) { $ret_msg = "State:success<br>Detail:<br>"; foreach ($reply->getResult() as $agent) { $ret_msg .= "-------------------------------------------------------<br>"; $ret_msg .= "Ip:" . $agent->getIp() . "<br>"; if ($agent->getState() == 0) { $ret_msg .= "State:success<br>"; $ret_msg .= "Status:" . $agent->getStatus() . "<br>"; $ret_msg .= "Result:<br>" . str_replace("\n", "<br/>", $agent->getResult()) . "<br>"; } else { $ret_msg .= "State:error<br>"; $ret_msg .= "Detail:<br>" . str_replace("\n", "<br/>", $agent->getErr()) . "<br>"; } $retContent["result"] = $ret_msg; } } else { $retContent["result"] = "State:error<br>detail:" . str_replace("\n", "<br/>", $reply->getErr()) . "<br>"; } } else { $retContent["result"] = "无法获取Center."; } echo json_encode($retContent); exit; }
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]); } }