use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class SshHandler method logCommands.
/**
* 记录终端执行记录
*
* @param session 回话
* @param command 命令行
* @param refuse 是否拒绝
*/
private void logCommands(WebSocketSession session, String command, boolean refuse) {
List<String> split = StrUtil.splitTrim(command, StrUtil.CR);
// 最后一个是否为回车, 最后一个不是回车表示还未提交,还在缓存去待确认
boolean all = StrUtil.endWith(command, StrUtil.CR);
int size = split.size();
split = CollUtil.sub(split, 0, all ? size : size - 1);
if (CollUtil.isEmpty(split)) {
return;
}
// 获取基础信息
Map<String, Object> attributes = session.getAttributes();
UserModel userInfo = (UserModel) attributes.get("userInfo");
String ip = (String) attributes.get("ip");
String userAgent = (String) attributes.get(HttpHeaders.USER_AGENT);
SshModel sshItem = (SshModel) attributes.get("dataItem");
//
sshTerminalExecuteLogService.batch(userInfo, sshItem, ip, userAgent, refuse, split);
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class SshHandler method handleTextMessage.
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
HandlerItem handlerItem = HANDLER_ITEM_CONCURRENT_HASH_MAP.get(session.getId());
if (handlerItem == null) {
sendBinary(session, "已经离线啦");
IoUtil.close(session);
return;
}
String payload = message.getPayload();
if (JSONValidator.from(payload).getType() == JSONValidator.Type.Object) {
JSONObject jsonObject = JSONObject.parseObject(payload);
String data = jsonObject.getString("data");
if (StrUtil.equals(data, "jpom-heart")) {
// 心跳消息不转发
return;
}
if (StrUtil.equals(data, "resize")) {
// 缓存区大小
handlerItem.resize(jsonObject);
return;
}
}
init();
Map<String, Object> attributes = session.getAttributes();
UserModel userInfo = (UserModel) attributes.get("userInfo");
// 判断是没有任何限制
String workspaceId = handlerItem.sshItem.getWorkspaceId();
boolean sshCommandNotLimited = userBindWorkspaceService.exists(userInfo.getId(), workspaceId + UserBindWorkspaceService.SSH_COMMAND_NOT_LIMITED);
try {
this.sendCommand(handlerItem, payload, userInfo, sshCommandNotLimited);
} catch (Exception e) {
sendBinary(session, "Failure:" + e.getMessage());
DefaultSystemLog.getLog().error("执行命令异常", e);
}
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class OperateLogController method afterReturning.
@Override
public void afterReturning(Object value) {
try {
CacheInfo cacheInfo = CACHE_INFO_THREAD_LOCAL.get();
if (cacheInfo == null || cacheInfo.methodFeature == MethodFeature.LIST) {
return;
}
if (cacheInfo.classFeature == null || cacheInfo.methodFeature == null) {
new RuntimeException("权限功能没有配置正确").printStackTrace();
return;
}
UserModel userModel = BaseServerController.getUserByThreadLocal();
userModel = userModel == null ? BaseServerController.getUserModel() : userModel;
// 没有对应的用户
if (userModel == null) {
return;
}
this.log(userModel, value, cacheInfo);
} finally {
CACHE_INFO_THREAD_LOCAL.remove();
}
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class ServerScriptHandler method createLog.
/**
* 创建执行日志
*
* @param attributes 参数属性
* @return 执行ID
*/
private String createLog(Map<String, Object> attributes, ScriptModel scriptModel) {
UserModel userModel = (UserModel) attributes.get("userInfo");
//
try {
BaseServerController.resetInfo(userModel);
//
ScriptModel scriptCacheModel = new ScriptModel();
scriptCacheModel.setId(scriptModel.getId());
scriptCacheModel.setLastRunUser(userModel.getId());
nodeScriptServer.update(scriptCacheModel);
//
ScriptExecuteLogModel scriptExecuteLogCacheModel = logServer.create(scriptModel, 0);
return scriptExecuteLogCacheModel.getId();
} finally {
BaseServerController.removeAll();
}
}
use of io.jpom.model.data.UserModel in project Jpom by dromara.
the class BaseHandler method showHelloMsg.
protected void showHelloMsg(Map<String, Object> attributes, WebSocketSession session) {
UserModel userInfo = (UserModel) attributes.get("userInfo");
String payload = StrUtil.format("欢迎加入:{} 会话id:{} ", userInfo.getName(), session.getId() + StrUtil.CRLF);
this.sendMsg(session, payload);
}
Aggregations