Search in sources :

Example 1 with MachineProxyDO

use of com.orion.ops.entity.domain.MachineProxyDO in project orion-ops by lijiahangmax.

the class MachineInfoServiceImpl method connectSessionStore.

/**
 * 打开sessionStore
 *
 * @param machine machine
 * @return SessionStore
 */
private SessionStore connectSessionStore(MachineInfoDO machine) {
    Valid.notNull(machine, MessageConst.INVALID_MACHINE);
    Long proxyId = machine.getProxyId();
    SessionStore session;
    try {
        session = SessionHolder.getSession(machine.getMachineHost(), machine.getSshPort(), machine.getUsername());
        String password = machine.getPassword();
        if (Strings.isNotBlank(password)) {
            session.setPassword(ValueMix.decrypt(password));
        }
        MachineProxyDO proxy = null;
        if (proxyId != null) {
            proxy = machineProxyDAO.selectById(proxyId);
        }
        if (proxy != null) {
            ProxyType proxyType = ProxyType.of(proxy.getProxyType());
            String proxyPassword = proxy.getProxyPassword();
            if (!Strings.isBlank(proxyPassword)) {
                proxyPassword = ValueMix.decrypt(proxyPassword);
            }
            if (ProxyType.HTTP.equals(proxyType)) {
                session.setHttpProxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
            } else if (ProxyType.SOCKET4.equals(proxyType)) {
                session.setSocket4Proxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
            } else if (ProxyType.SOCKET5.equals(proxyType)) {
                session.setSocket5Proxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
            }
            session.setHttpProxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
        }
        session.connect(MachineConst.CONNECT_TIMEOUT);
        log.info("远程机器建立连接-成功 {}@{}:{}", machine.getUsername(), machine.getMachineHost(), machine.getSshPort());
        return session;
    } catch (Exception e) {
        log.error("远程机器建立连接-失败 {}@{}:{} {}", machine.getUsername(), machine.getMachineHost(), machine.getSshPort(), e);
        throw e;
    }
}
Also used : SessionStore(com.orion.remote.channel.SessionStore) MachineProxyDO(com.orion.ops.entity.domain.MachineProxyDO) ProxyType(com.orion.ops.consts.machine.ProxyType) AuthenticationException(com.orion.exception.AuthenticationException) ConnectionRuntimeException(com.orion.exception.ConnectionRuntimeException) IOException(java.io.IOException)

Example 2 with MachineProxyDO

use of com.orion.ops.entity.domain.MachineProxyDO in project orion-ops by lijiahangmax.

the class MachineProxyServiceImpl method addProxy.

@Override
public Long addProxy(MachineProxyRequest request) {
    MachineProxyDO proxy = new MachineProxyDO();
    proxy.setProxyHost(request.getHost());
    proxy.setProxyPort(request.getPort());
    proxy.setProxyType(request.getType());
    proxy.setProxyUsername(request.getUsername());
    String password = request.getPassword();
    if (!Strings.isBlank(password)) {
        proxy.setProxyPassword(ValueMix.encrypt(password));
    }
    proxy.setDescription(request.getDescription());
    // 插入
    machineProxyDAO.insert(proxy);
    // 设置日志参数
    EventParamsHolder.addParams(proxy);
    return proxy.getId();
}
Also used : MachineProxyDO(com.orion.ops.entity.domain.MachineProxyDO)

Example 3 with MachineProxyDO

use of com.orion.ops.entity.domain.MachineProxyDO in project orion-ops by lijiahangmax.

the class MachineProxyServiceImpl method updateProxy.

@Override
public Integer updateProxy(MachineProxyRequest request) {
    // 查询
    Long id = request.getId();
    MachineProxyDO beforeProxy = machineProxyDAO.selectById(id);
    Valid.notNull(beforeProxy, MessageConst.UNKNOWN_DATA);
    MachineProxyDO proxy = new MachineProxyDO();
    proxy.setId(id);
    proxy.setProxyHost(request.getHost());
    proxy.setProxyPort(request.getPort());
    proxy.setProxyUsername(request.getUsername());
    proxy.setProxyType(request.getType());
    String password = request.getPassword();
    if (!Strings.isBlank(password)) {
        proxy.setProxyPassword(ValueMix.encrypt(password));
    }
    proxy.setDescription(request.getDescription());
    // 修改
    int effect = machineProxyDAO.updateById(proxy);
    // 设置日志参数
    EventParamsHolder.addParams(proxy);
    EventParamsHolder.addParam(EventKeys.HOST, beforeProxy.getProxyHost());
    return effect;
}
Also used : MachineProxyDO(com.orion.ops.entity.domain.MachineProxyDO)

Example 4 with MachineProxyDO

use of com.orion.ops.entity.domain.MachineProxyDO in project orion-ops by lijiahangmax.

the class MachineProxyServiceImpl method getProxyDetail.

@Override
public MachineProxyVO getProxyDetail(Long id) {
    MachineProxyDO proxy = machineProxyDAO.selectById(id);
    Valid.notNull(proxy, MessageConst.UNKNOWN_DATA);
    return Converts.to(proxy, MachineProxyVO.class);
}
Also used : MachineProxyDO(com.orion.ops.entity.domain.MachineProxyDO)

Example 5 with MachineProxyDO

use of com.orion.ops.entity.domain.MachineProxyDO in project orion-ops by lijiahangmax.

the class MachineInfoServiceImpl method checkProxy.

/**
 * 检查代理
 */
private void checkProxy(Long proxyId) {
    if (proxyId == null) {
        return;
    }
    MachineProxyDO proxy = machineProxyDAO.selectById(proxyId);
    Valid.notNull(proxy, MessageConst.INVALID_PROXY);
}
Also used : MachineProxyDO(com.orion.ops.entity.domain.MachineProxyDO)

Aggregations

MachineProxyDO (com.orion.ops.entity.domain.MachineProxyDO)5 AuthenticationException (com.orion.exception.AuthenticationException)1 ConnectionRuntimeException (com.orion.exception.ConnectionRuntimeException)1 ProxyType (com.orion.ops.consts.machine.ProxyType)1 SessionStore (com.orion.remote.channel.SessionStore)1 IOException (java.io.IOException)1