Search in sources :

Example 1 with AgentAutoUser

use of io.jpom.model.system.AgentAutoUser in project Jpom by dromara.

the class AgentAuthorize method checkPwd.

/**
 * 检查是否配置密码
 */
private void checkPwd() {
    String path = ConfigBean.getInstance().getAgentAutoAuthorizeFile(ConfigBean.getInstance().getDataPath());
    if (StrUtil.isNotEmpty(agentPwd)) {
        // 有指定密码 清除旧密码信息
        FileUtil.del(path);
        Console.log("Authorization information has been customized,account:{}", this.agentName);
        return;
    }
    if (FileUtil.exist(path)) {
        // 读取旧密码
        try {
            String json = FileUtil.readString(path, CharsetUtil.CHARSET_UTF_8);
            AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
            if (!StrUtil.equals(autoUser.getAgentName(), this.agentName)) {
                throw new JpomRuntimeException("The existing login name is inconsistent with the configured login name");
            }
            String oldAgentPwd = autoUser.getAgentPwd();
            if (StrUtil.isNotEmpty(oldAgentPwd)) {
                this.agentPwd = oldAgentPwd;
                Console.log("Already authorized account:{}  password:{}  Authorization information storage location:{}", this.agentName, this.agentPwd, FileUtil.getAbsolutePath(path));
                return;
            }
        } catch (JpomRuntimeException e) {
            throw e;
        } catch (Exception ignored) {
        }
    }
    this.agentPwd = RandomUtil.randomString(10);
    AgentAutoUser autoUser = new AgentAutoUser();
    autoUser.setAgentName(this.agentName);
    autoUser.setAgentPwd(this.agentPwd);
    // 写入文件中
    JsonFileUtil.saveJson(path, autoUser.toJson());
    Console.log("Automatically generate authorized account:{}  password:{}  Authorization information storage location:{}", this.agentName, this.agentPwd, FileUtil.getAbsolutePath(path));
}
Also used : AgentAutoUser(io.jpom.model.system.AgentAutoUser)

Example 2 with AgentAutoUser

use of io.jpom.model.system.AgentAutoUser in project Jpom by dromara.

the class AutoImportLocalNode method findPid.

private static void findPid(String pid) {
    File file = ConfigBean.getInstance().getApplicationJpomInfo(Type.Agent);
    if (!file.exists() || file.isDirectory()) {
        return;
    }
    // 比较进程id
    String json = FileUtil.readString(file, CharsetUtil.CHARSET_UTF_8);
    JpomManifest jpomManifest = JSONObject.parseObject(json, JpomManifest.class);
    if (!pid.equals(String.valueOf(jpomManifest.getPid()))) {
        return;
    }
    // 判断自动授权文件是否存在
    String path = ConfigBean.getInstance().getAgentAutoAuthorizeFile(jpomManifest.getDataPath());
    if (!FileUtil.exist(path)) {
        return;
    }
    json = FileUtil.readString(path, CharsetUtil.CHARSET_UTF_8);
    AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
    // 判断授权信息
    // 
    NodeModel nodeModel = new NodeModel();
    nodeModel.setUrl(StrUtil.format("127.0.0.1:{}", jpomManifest.getPort()));
    nodeModel.setName("本机");
    // nodeModel.setProtocol("http");
    // 
    nodeModel.setLoginPwd(autoUser.getAgentPwd());
    nodeModel.setLoginName(autoUser.getAgentName());
    // 
    nodeModel.setOpenStatus(1);
    nodeService.insertNotFill(nodeModel);
    Console.log("Automatically add native node successfully:" + nodeModel.getId());
}
Also used : NodeModel(io.jpom.model.data.NodeModel) JpomManifest(io.jpom.common.JpomManifest) AgentAutoUser(io.jpom.model.system.AgentAutoUser) File(java.io.File)

Example 3 with AgentAutoUser

use of io.jpom.model.system.AgentAutoUser in project Jpom by dromara.

the class SshInstallAgentController method getAuthorize.

private String getAuthorize(SshModel sshModel, NodeModel nodeModel, String path) {
    File saveFile = null;
    try {
        String tempFilePath = ServerConfigBean.getInstance().getUserTempPath().getAbsolutePath();
        // 获取远程的授权信息
        String normalize = FileUtil.normalize(StrUtil.format("{}/{}/{}", path, ConfigBean.DATA, ConfigBean.AUTHORIZE));
        saveFile = FileUtil.file(tempFilePath, IdUtil.fastSimpleUUID() + ConfigBean.AUTHORIZE);
        sshService.download(sshModel, normalize, saveFile);
        // 
        String json = FileUtil.readString(saveFile, CharsetUtil.CHARSET_UTF_8);
        AgentAutoUser autoUser = JSONObject.parseObject(json, AgentAutoUser.class);
        nodeModel.setLoginPwd(autoUser.getAgentPwd());
        nodeModel.setLoginName(autoUser.getAgentName());
    } catch (Exception e) {
        DefaultSystemLog.getLog().error("拉取授权信息失败:{}", e.getMessage());
        return "获取授权信息失败,请检查对应的插件端运行状态" + e.getMessage();
    } finally {
        FileUtil.del(saveFile);
    }
    return null;
}
Also used : AgentAutoUser(io.jpom.model.system.AgentAutoUser) ZipFile(java.util.zip.ZipFile) File(java.io.File) IOException(java.io.IOException)

Aggregations

AgentAutoUser (io.jpom.model.system.AgentAutoUser)3 File (java.io.File)2 JpomManifest (io.jpom.common.JpomManifest)1 NodeModel (io.jpom.model.data.NodeModel)1 IOException (java.io.IOException)1 ZipFile (java.util.zip.ZipFile)1