Search in sources :

Example 1 with UserModel

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);
}
Also used : UserModel(io.jpom.model.data.UserModel) SshModel(io.jpom.model.data.SshModel) JSONObject(com.alibaba.fastjson.JSONObject)

Example 2 with UserModel

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);
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) JSONObject(com.alibaba.fastjson.JSONObject) JSONObject(com.alibaba.fastjson.JSONObject) IOException(java.io.IOException) JSchException(com.jcraft.jsch.JSchException)

Example 3 with UserModel

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();
    }
}
Also used : UserModel(io.jpom.model.data.UserModel)

Example 4 with UserModel

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();
    }
}
Also used : UserModel(io.jpom.model.data.UserModel) ScriptModel(io.jpom.model.script.ScriptModel) ScriptExecuteLogModel(io.jpom.model.script.ScriptExecuteLogModel)

Example 5 with UserModel

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);
}
Also used : UserModel(io.jpom.model.data.UserModel)

Aggregations

UserModel (io.jpom.model.data.UserModel)66 JSONObject (com.alibaba.fastjson.JSONObject)17 MethodFeature (io.jpom.permission.MethodFeature)15 ClassFeature (io.jpom.permission.ClassFeature)14 Feature (io.jpom.permission.Feature)14 NodeModel (io.jpom.model.data.NodeModel)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 NotLogin (io.jpom.common.interceptor.NotLogin)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 UserService (io.jpom.service.user.UserService)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 StrUtil (cn.hutool.core.util.StrUtil)4 Entity (cn.hutool.db.Entity)4 JSONArray (com.alibaba.fastjson.JSONArray)4 BuildInfoModel (io.jpom.model.data.BuildInfoModel)4 List (java.util.List)4 JsonMessage (cn.jiangzeyin.common.JsonMessage)3 BaseServerController (io.jpom.common.BaseServerController)3 WorkspaceModel (io.jpom.model.data.WorkspaceModel)3 UserLoginDto (io.jpom.model.dto.UserLoginDto)3