Search in sources :

Example 1 with ProxyType

use of com.orion.ops.consts.machine.ProxyType 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)

Aggregations

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