Search in sources :

Example 1 with GwtNetInterfaceConfig

use of org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig in project kura by eclipse.

the class GwtNetworkServiceImpl method privateFindNetInterfaceConfigurations.

@SuppressWarnings({ "unchecked", "rawtypes" })
private List<GwtNetInterfaceConfig> privateFindNetInterfaceConfigurations() throws GwtKuraException {
    s_logger.debug("Starting");
    List<GwtNetInterfaceConfig> gwtNetConfigs = new ArrayList<GwtNetInterfaceConfig>();
    NetworkAdminService nas = null;
    try {
        nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
    } catch (Throwable t) {
        s_logger.warn("Exception", t);
        return gwtNetConfigs;
    }
    ModemManagerService modemManagerService = null;
    try {
        modemManagerService = ServiceLocator.getInstance().getService(ModemManagerService.class);
    } catch (Throwable t) {
        s_logger.warn("{ModemManagerService} Exception", t);
    }
    WifiClientMonitorService wifiClientMonitorService = null;
    try {
        wifiClientMonitorService = ServiceLocator.getInstance().getService(WifiClientMonitorService.class);
    } catch (Throwable t) {
        s_logger.warn("{WifiClientMonitorService} Exception", t);
    }
    try {
        GwtNetInterfaceConfig gwtNetConfig = null;
        for (NetInterfaceConfig<? extends NetInterfaceAddressConfig> netIfConfig : nas.getNetworkInterfaceConfigs()) {
            s_logger.debug("Getting config for {} with type {}", netIfConfig.getName(), netIfConfig.getType());
            s_logger.debug("Interface State: {}", netIfConfig.getState());
            if (netIfConfig.getType() == NetInterfaceType.WIFI) {
                gwtNetConfig = new GwtWifiNetInterfaceConfig();
            } else if (netIfConfig.getType() == NetInterfaceType.MODEM) {
                gwtNetConfig = new GwtModemInterfaceConfig();
                ((GwtModemInterfaceConfig) gwtNetConfig).setModemId(((ModemInterface) netIfConfig).getModemIdentifier());
                ((GwtModemInterfaceConfig) gwtNetConfig).setManufacturer(((ModemInterface) netIfConfig).getManufacturer());
                ((GwtModemInterfaceConfig) gwtNetConfig).setModel(((ModemInterface) netIfConfig).getModel());
                List<String> technologyList = new ArrayList<String>();
                List<ModemTechnologyType> technologyTypes = ((ModemInterface) netIfConfig).getTechnologyTypes();
                if (technologyTypes != null) {
                    for (ModemTechnologyType techType : technologyTypes) {
                        technologyList.add(techType.name());
                    }
                }
                ((GwtModemInterfaceConfig) gwtNetConfig).setNetworkTechnology(technologyList);
            } else {
                gwtNetConfig = new GwtNetInterfaceConfig();
                gwtNetConfig.setHwRssi("N/A");
            }
            gwtNetConfig.setName(netIfConfig.getName());
            gwtNetConfig.setHwName(netIfConfig.getName());
            if (netIfConfig.getType() != null) {
                gwtNetConfig.setHwType(netIfConfig.getType().name());
            }
            if (netIfConfig.getState() != null) {
                gwtNetConfig.setHwState(netIfConfig.getState().name());
            }
            s_logger.debug("MAC: {}", NetUtil.hardwareAddressToString(netIfConfig.getHardwareAddress()));
            gwtNetConfig.setHwAddress(NetUtil.hardwareAddressToString(netIfConfig.getHardwareAddress()));
            gwtNetConfig.setHwDriver(netIfConfig.getDriver());
            gwtNetConfig.setHwDriverVersion(netIfConfig.getDriverVersion());
            gwtNetConfig.setHwFirmware(netIfConfig.getFirmwareVersion());
            gwtNetConfig.setHwMTU(netIfConfig.getMTU());
            if (netIfConfig.getUsbDevice() != null) {
                gwtNetConfig.setHwUsbDevice(netIfConfig.getUsbDevice().getUsbDevicePath());
            } else {
                gwtNetConfig.setHwUsbDevice("N/A");
            }
            List<? extends NetInterfaceAddressConfig> addressConfigs = netIfConfig.getNetInterfaceAddresses();
            if (addressConfigs != null && !addressConfigs.isEmpty()) {
                for (NetInterfaceAddressConfig addressConfig : addressConfigs) {
                    // current status - not configuration!
                    if (addressConfig.getAddress() != null) {
                        s_logger.debug("current address: {}", addressConfig.getAddress().getHostAddress());
                    }
                    if (addressConfig.getNetworkPrefixLength() >= 0 && addressConfig.getNetworkPrefixLength() <= 32) {
                        s_logger.debug("current prefix length: {}", addressConfig.getNetworkPrefixLength());
                    }
                    if (addressConfig.getNetmask() != null) {
                        s_logger.debug("current netmask: {}", addressConfig.getNetmask().getHostAddress());
                    }
                    List<NetConfig> netConfigs = addressConfig.getConfigs();
                    if (netConfigs != null && !netConfigs.isEmpty()) {
                        boolean isNatEnabled = false;
                        boolean isDhcpServerEnabled = false;
                        for (NetConfig netConfig : netConfigs) {
                            if (netConfig instanceof NetConfigIP4) {
                                s_logger.debug("Setting up NetConfigIP4 with status {}", ((NetConfigIP4) netConfig).getStatus().toString());
                                // we are enabled - for LAN or WAN?
                                if (((NetConfigIP4) netConfig).getStatus() == NetInterfaceStatus.netIPv4StatusEnabledLAN) {
                                    gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusEnabledLAN.name());
                                } else if (((NetConfigIP4) netConfig).getStatus() == NetInterfaceStatus.netIPv4StatusEnabledWAN) {
                                    gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusEnabledWAN.name());
                                } else {
                                    gwtNetConfig.setStatus(GwtNetIfStatus.netIPv4StatusDisabled.name());
                                }
                                if (((NetConfigIP4) netConfig).isDhcp()) {
                                    gwtNetConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
                                    // since DHCP - populate current data
                                    if (addressConfig.getAddress() != null) {
                                        gwtNetConfig.setIpAddress(addressConfig.getAddress().getHostAddress());
                                    } else {
                                        gwtNetConfig.setIpAddress("");
                                    }
                                    if (addressConfig.getNetworkPrefixLength() >= 0 && addressConfig.getNetworkPrefixLength() <= 32) {
                                        gwtNetConfig.setSubnetMask(NetworkUtil.getNetmaskStringForm(addressConfig.getNetworkPrefixLength()));
                                    } else {
                                        if (addressConfig.getNetmask() != null) {
                                            gwtNetConfig.setSubnetMask(addressConfig.getNetmask().getHostAddress());
                                        } else {
                                            gwtNetConfig.setSubnetMask("");
                                        }
                                    }
                                    if (addressConfig.getGateway() != null) {
                                        gwtNetConfig.setGateway(addressConfig.getGateway().getHostAddress());
                                    } else {
                                        gwtNetConfig.setGateway("");
                                    }
                                    // DHCP supplied DNS servers
                                    StringBuffer sb = new StringBuffer();
                                    List<? extends IPAddress> dnsServers = addressConfig.getDnsServers();
                                    if (dnsServers != null && !dnsServers.isEmpty()) {
                                        String sep = "";
                                        for (IPAddress dnsServer : dnsServers) {
                                            sb.append(sep).append(dnsServer.getHostAddress());
                                            sep = "\n";
                                        }
                                        s_logger.debug("DNS Servers: {}", sb);
                                        gwtNetConfig.setReadOnlyDnsServers(sb.toString());
                                    } else {
                                        s_logger.debug("DNS Servers: [empty String]");
                                        gwtNetConfig.setReadOnlyDnsServers("");
                                    }
                                } else {
                                    gwtNetConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeManual.name());
                                    // TODO - should we throw an error if current state doesn't match configuration?
                                    if (((NetConfigIP4) netConfig).getAddress() != null) {
                                        gwtNetConfig.setIpAddress(((NetConfigIP4) netConfig).getAddress().getHostAddress());
                                    } else {
                                        gwtNetConfig.setIpAddress("");
                                    }
                                    if (((NetConfigIP4) netConfig).getSubnetMask() != null) {
                                        gwtNetConfig.setSubnetMask(((NetConfigIP4) netConfig).getSubnetMask().getHostAddress());
                                    } else {
                                        gwtNetConfig.setSubnetMask("");
                                    }
                                    if (((NetConfigIP4) netConfig).getGateway() != null) {
                                        s_logger.debug("Gateway for {} is: {}", netIfConfig.getName(), ((NetConfigIP4) netConfig).getGateway().getHostAddress());
                                        gwtNetConfig.setGateway(((NetConfigIP4) netConfig).getGateway().getHostAddress());
                                    } else {
                                        gwtNetConfig.setGateway("");
                                    }
                                }
                                // Custom DNS servers
                                StringBuffer sb = new StringBuffer();
                                List<IP4Address> dnsServers = ((NetConfigIP4) netConfig).getDnsServers();
                                if (dnsServers != null && !dnsServers.isEmpty()) {
                                    for (IP4Address dnsServer : dnsServers) {
                                        if (!dnsServer.getHostAddress().equals("127.0.0.1")) {
                                            sb.append(' ').append(dnsServer.getHostAddress());
                                        }
                                    }
                                    s_logger.debug("DNS Servers: {}", sb);
                                    gwtNetConfig.setDnsServers(sb.toString().trim());
                                } else {
                                    s_logger.debug("DNS Servers: [empty String]");
                                    gwtNetConfig.setDnsServers("");
                                }
                                // Search domains
                                sb = new StringBuffer();
                                List<IP4Address> winsServers = ((NetConfigIP4) netConfig).getWinsServers();
                                if (winsServers != null && !winsServers.isEmpty()) {
                                    for (IP4Address winServer : winsServers) {
                                        sb.append(winServer.getHostAddress());
                                        sb.append("\n");
                                    }
                                    s_logger.debug("Search Domains: {}", sb);
                                    gwtNetConfig.setSearchDomains(sb.toString());
                                } else {
                                    s_logger.debug("Search Domains: [empty String]");
                                    gwtNetConfig.setSearchDomains("");
                                }
                            }
                            // config
                            if (netConfig instanceof WifiConfig) {
                                s_logger.debug("Setting up WifiConfigIP4");
                                WifiConfig wifiConfig = (WifiConfig) netConfig;
                                GwtWifiConfig gwtWifiConfig = new GwtWifiConfig();
                                // mode
                                if (wifiConfig.getMode() == WifiMode.MASTER) {
                                    gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name());
                                    // set as the access point config for this interface
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setAccessPointWifiConfig(gwtWifiConfig);
                                } else if (wifiConfig.getMode() == WifiMode.INFRA) {
                                    gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeStation.name());
                                    // set as the station config for this interface
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setStationWifiConfig(gwtWifiConfig);
                                } else if (wifiConfig.getMode() == WifiMode.ADHOC) {
                                    gwtWifiConfig.setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name());
                                    // set as the adhoc config for this interface
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setAdhocWifiConfig(gwtWifiConfig);
                                }
                                // ssid
                                gwtWifiConfig.setWirelessSsid(wifiConfig.getSSID());
                                // driver
                                gwtWifiConfig.setDriver(wifiConfig.getDriver());
                                // security
                                if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA.name());
                                } else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA2) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA2.name());
                                } else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WPA_WPA2) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWPA_WPA2.name());
                                } else if (wifiConfig.getSecurity() == WifiSecurity.SECURITY_WEP) {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityWEP.name());
                                } else {
                                    gwtWifiConfig.setSecurity(GwtWifiSecurity.netWifiSecurityNONE.name());
                                }
                                if (wifiConfig.getPairwiseCiphers() == WifiCiphers.CCMP_TKIP) {
                                    gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name());
                                } else if (wifiConfig.getPairwiseCiphers() == WifiCiphers.TKIP) {
                                    gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_TKIP.name());
                                } else if (wifiConfig.getPairwiseCiphers() == WifiCiphers.CCMP) {
                                    gwtWifiConfig.setPairwiseCiphers(GwtWifiCiphers.netWifiCiphers_CCMP.name());
                                }
                                if (wifiConfig.getGroupCiphers() == WifiCiphers.CCMP_TKIP) {
                                    gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP_TKIP.name());
                                } else if (wifiConfig.getGroupCiphers() == WifiCiphers.TKIP) {
                                    gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_TKIP.name());
                                } else if (wifiConfig.getGroupCiphers() == WifiCiphers.CCMP) {
                                    gwtWifiConfig.setGroupCiphers(GwtWifiCiphers.netWifiCiphers_CCMP.name());
                                }
                                // bgscan
                                WifiBgscan wifiBgscan = wifiConfig.getBgscan();
                                if (wifiBgscan != null) {
                                    if (wifiBgscan.getModule() == WifiBgscanModule.NONE) {
                                        gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_NONE.name());
                                    } else if (wifiBgscan.getModule() == WifiBgscanModule.SIMPLE) {
                                        gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_SIMPLE.name());
                                    } else if (wifiBgscan.getModule() == WifiBgscanModule.LEARN) {
                                        gwtWifiConfig.setBgscanModule(GwtWifiBgscanModule.netWifiBgscanMode_LEARN.name());
                                    }
                                    gwtWifiConfig.setBgscanRssiThreshold(wifiBgscan.getRssiThreshold());
                                    gwtWifiConfig.setBgscanShortInterval(wifiBgscan.getShortInterval());
                                    gwtWifiConfig.setBgscanLongInterval(wifiBgscan.getLongInterval());
                                }
                                // ping access point?
                                gwtWifiConfig.setPingAccessPoint(wifiConfig.pingAccessPoint());
                                // ignore SSID?
                                gwtWifiConfig.setIgnoreSSID(wifiConfig.ignoreSSID());
                                // passkey
                                Password psswd = wifiConfig.getPasskey();
                                if (psswd != null) {
                                    String password = new String(psswd.getPassword());
                                    gwtWifiConfig.setPassword(password);
                                }
                                // channel
                                int[] channels = wifiConfig.getChannels();
                                if (channels != null) {
                                    ArrayList<Integer> alChannels = new ArrayList<Integer>();
                                    for (int channel : channels) {
                                        alChannels.add(new Integer(channel));
                                    }
                                    gwtWifiConfig.setChannels(alChannels);
                                }
                                // radio mode
                                GwtWifiRadioMode gwtWifiRadioMode = null;
                                if (wifiConfig.getRadioMode() != null) {
                                    switch(wifiConfig.getRadioMode()) {
                                        case RADIO_MODE_80211a:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeA;
                                            break;
                                        case RADIO_MODE_80211b:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeB;
                                            break;
                                        case RADIO_MODE_80211g:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeBG;
                                            break;
                                        case RADIO_MODE_80211nHT20:
                                        case RADIO_MODE_80211nHT40above:
                                        case RADIO_MODE_80211nHT40below:
                                            gwtWifiRadioMode = GwtWifiRadioMode.netWifiRadioModeBGN;
                                            break;
                                        default:
                                            break;
                                    }
                                }
                                if (gwtWifiRadioMode != null) {
                                    gwtWifiConfig.setRadioMode(gwtWifiRadioMode.name());
                                }
                                // set the currently active mode based on the address config
                                WifiMode activeWirelessMode = ((WifiInterfaceAddressConfig) addressConfig).getMode();
                                if (activeWirelessMode == WifiMode.MASTER) {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name());
                                    gwtNetConfig.setHwRssi("N/A");
                                } else if (activeWirelessMode == WifiMode.INFRA) {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeStation.name());
                                    if (wifiClientMonitorService != null) {
                                        if (wifiConfig.getMode().equals(WifiMode.INFRA)) {
                                            if (gwtNetConfig.getStatus().equals(GwtNetIfStatus.netIPv4StatusDisabled.name())) {
                                                gwtNetConfig.setHwRssi("N/A");
                                            } else {
                                                try {
                                                    int rssi = wifiClientMonitorService.getSignalLevel(netIfConfig.getName(), wifiConfig.getSSID());
                                                    s_logger.debug("Setting Received Signal Strength to {}", rssi);
                                                    gwtNetConfig.setHwRssi(Integer.toString(rssi));
                                                } catch (KuraException e) {
                                                    s_logger.warn("Failed", e);
                                                }
                                            }
                                        }
                                    }
                                } else if (activeWirelessMode == WifiMode.ADHOC) {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeAdHoc.name());
                                    gwtNetConfig.setHwRssi("N/A");
                                } else {
                                    ((GwtWifiNetInterfaceConfig) gwtNetConfig).setWirelessMode(GwtWifiWirelessMode.netWifiWirelessModeDisabled.name());
                                    gwtNetConfig.setHwRssi("N/A");
                                }
                            }
                            if (netConfig instanceof ModemConfig) {
                                s_logger.debug("Setting up ModemConfig");
                                ModemConfig modemConfig = (ModemConfig) netConfig;
                                GwtModemInterfaceConfig gwtModemConfig = (GwtModemInterfaceConfig) gwtNetConfig;
                                if (modemManagerService != null) {
                                    UsbDevice usbDevice = netIfConfig.getUsbDevice();
                                    String modemServiceId = null;
                                    if (usbDevice != null) {
                                        modemServiceId = netIfConfig.getUsbDevice().getUsbPort();
                                    } else {
                                        Collection<CellularModem> modemServices = modemManagerService.getAllModemServices();
                                        for (CellularModem modemService : modemServices) {
                                            ModemDevice modemDevice = modemService.getModemDevice();
                                            if (modemDevice instanceof SerialModemDevice) {
                                                modemServiceId = modemDevice.getProductName();
                                                break;
                                            }
                                        }
                                    }
                                    if (modemServiceId != null) {
                                        CellularModem cellModemService = modemManagerService.getModemService(modemServiceId);
                                        if (cellModemService != null) {
                                            try {
                                                String imei = cellModemService.getSerialNumber();
                                                s_logger.debug("Setting IMEI/MEID to {}", imei);
                                                gwtModemConfig.setHwSerial(imei);
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get IMEI from modem", e);
                                            }
                                            try {
                                                int rssi = cellModemService.getSignalStrength();
                                                s_logger.debug("Setting Received Signal Strength to {}", rssi);
                                                gwtModemConfig.setHwRssi(Integer.toString(rssi));
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get Received Signal Strength from modem", e);
                                            }
                                            try {
                                                String sModel = cellModemService.getModel();
                                                ((GwtModemInterfaceConfig) gwtNetConfig).setModel(sModel);
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get model information from modem", e);
                                            }
                                            try {
                                                boolean gpsSupported = cellModemService.isGpsSupported();
                                                s_logger.debug("Setting GPS supported to {}", gpsSupported);
                                                ((GwtModemInterfaceConfig) gwtNetConfig).setGpsSupported(gpsSupported);
                                            } catch (KuraException e) {
                                                s_logger.warn("Failed to get GPS supported from modem", e);
                                            }
                                        }
                                    }
                                }
                                // set as DHCP - populate current address
                                gwtModemConfig.setConfigMode(GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name());
                                if (addressConfig.getAddress() != null) {
                                    gwtModemConfig.setIpAddress(addressConfig.getAddress().getHostAddress());
                                }
                                if (addressConfig.getNetmask() != null) {
                                    gwtModemConfig.setSubnetMask(addressConfig.getNetmask().getHostAddress());
                                }
                                gwtModemConfig.setDialString(modemConfig.getDialString());
                                AuthType authType = modemConfig.getAuthType();
                                if (authType == AuthType.AUTO) {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthAUTO);
                                } else if (authType == AuthType.CHAP) {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthCHAP);
                                } else if (authType == AuthType.PAP) {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthPAP);
                                } else {
                                    gwtModemConfig.setAuthType(GwtModemAuthType.netModemAuthNONE);
                                }
                                gwtModemConfig.setUsername(modemConfig.getUsername());
                                gwtModemConfig.setPassword(modemConfig.getPassword());
                                gwtModemConfig.setPppNum(modemConfig.getPppNumber());
                                gwtModemConfig.setResetTimeout(modemConfig.getResetTimeout());
                                gwtModemConfig.setPersist(modemConfig.isPersist());
                                gwtModemConfig.setMaxFail(modemConfig.getMaxFail());
                                gwtModemConfig.setIdle(modemConfig.getIdle());
                                gwtModemConfig.setActiveFilter(modemConfig.getActiveFilter());
                                gwtModemConfig.setLcpEchoInterval(modemConfig.getLcpEchoInterval());
                                gwtModemConfig.setLcpEchoFailure(modemConfig.getLcpEchoFailure());
                                gwtModemConfig.setGpsEnabled(modemConfig.isGpsEnabled());
                                gwtModemConfig.setProfileID(modemConfig.getProfileID());
                                PdpType pdpType = modemConfig.getPdpType();
                                if (pdpType == PdpType.IP) {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpIP);
                                } else if (pdpType == PdpType.PPP) {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpPPP);
                                } else if (pdpType == PdpType.IPv6) {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpIPv6);
                                } else {
                                    gwtModemConfig.setPdpType(GwtModemPdpType.netModemPdpUnknown);
                                }
                                gwtModemConfig.setApn(modemConfig.getApn());
                                gwtModemConfig.setDataCompression(modemConfig.getDataCompression());
                                gwtModemConfig.setHeaderCompression(modemConfig.getHeaderCompression());
                                ModemConnectionStatus connectionStatus = ((ModemInterfaceAddressConfig) addressConfig).getConnectionStatus();
                                if (connectionStatus == ModemConnectionStatus.DISCONNECTED) {
                                    gwtModemConfig.setHwState(NetInterfaceState.DISCONNECTED.name());
                                } else if (connectionStatus == ModemConnectionStatus.CONNECTING) {
                                    gwtModemConfig.setHwState(NetInterfaceState.IP_CONFIG.name());
                                } else if (connectionStatus == ModemConnectionStatus.CONNECTED) {
                                    gwtModemConfig.setHwState(NetInterfaceState.ACTIVATED.name());
                                } else {
                                    gwtModemConfig.setHwState(NetInterfaceState.UNKNOWN.name());
                                }
                                gwtModemConfig.setConnectionType(((ModemInterfaceAddressConfig) addressConfig).getConnectionType().name());
                            }
                            if (netConfig instanceof DhcpServerConfigIP4) {
                                s_logger.debug("Setting up DhcpServerConfigIP4: {} to {}", ((DhcpServerConfigIP4) netConfig).getRangeStart().getHostAddress(), ((DhcpServerConfigIP4) netConfig).getRangeEnd().getHostAddress());
                                s_logger.debug("Setting up DhcpServerConfigIP4: {}", ((DhcpServerConfigIP4) netConfig).toString());
                                isDhcpServerEnabled = ((DhcpServerConfigIP4) netConfig).isEnabled();
                                gwtNetConfig.setRouterDhcpBeginAddress(((DhcpServerConfigIP4) netConfig).getRangeStart().getHostAddress());
                                gwtNetConfig.setRouterDhcpEndAddress(((DhcpServerConfigIP4) netConfig).getRangeEnd().getHostAddress());
                                gwtNetConfig.setRouterDhcpSubnetMask(((DhcpServerConfigIP4) netConfig).getSubnetMask().getHostAddress());
                                gwtNetConfig.setRouterDhcpDefaultLease(((DhcpServerConfigIP4) netConfig).getDefaultLeaseTime());
                                gwtNetConfig.setRouterDhcpMaxLease(((DhcpServerConfigIP4) netConfig).getMaximumLeaseTime());
                                gwtNetConfig.setRouterDnsPass(((DhcpServerConfigIP4) netConfig).isPassDns());
                            }
                            if (netConfig instanceof FirewallAutoNatConfig) {
                                s_logger.debug("Setting up FirewallAutoNatConfig");
                                isNatEnabled = true;
                            }
                        // TODO - only dealing with IPv4 right now
                        }
                        // set up the DHCP and NAT config
                        if (isDhcpServerEnabled && isNatEnabled) {
                            s_logger.debug("setting router mode to DHCP and NAT");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterDchpNat.name());
                        } else if (isDhcpServerEnabled && !isNatEnabled) {
                            s_logger.debug("setting router mode to DHCP only");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterDchp.name());
                        } else if (!isDhcpServerEnabled && isNatEnabled) {
                            s_logger.debug("setting router mode to NAT only");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterNat.name());
                        } else {
                            s_logger.debug("setting router mode to disabled");
                            gwtNetConfig.setRouterMode(GwtNetRouterMode.netRouterOff.name());
                        }
                    }
                }
            }
            gwtNetConfigs.add(gwtNetConfig);
        }
    } catch (Throwable t) {
        KuraExceptionHandler.handle(t);
    }
    s_logger.debug("Returning");
    return gwtNetConfigs;
}
Also used : SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) FirewallAutoNatConfig(org.eclipse.kura.net.firewall.FirewallAutoNatConfig) WifiConfig(org.eclipse.kura.net.wifi.WifiConfig) GwtWifiConfig(org.eclipse.kura.web.shared.model.GwtWifiConfig) ArrayList(java.util.ArrayList) ModemManagerService(org.eclipse.kura.net.modem.ModemManagerService) UsbDevice(org.eclipse.kura.usb.UsbDevice) WifiClientMonitorService(org.eclipse.kura.net.wifi.WifiClientMonitorService) WifiInterfaceAddressConfig(org.eclipse.kura.net.wifi.WifiInterfaceAddressConfig) GwtWifiRadioMode(org.eclipse.kura.web.shared.model.GwtWifiRadioMode) ModemDevice(org.eclipse.kura.net.modem.ModemDevice) SerialModemDevice(org.eclipse.kura.net.modem.SerialModemDevice) CellularModem(org.eclipse.kura.net.modem.CellularModem) KuraException(org.eclipse.kura.KuraException) GwtKuraException(org.eclipse.kura.web.shared.GwtKuraException) WifiMode(org.eclipse.kura.net.wifi.WifiMode) ModemInterfaceAddressConfig(org.eclipse.kura.net.modem.ModemInterfaceAddressConfig) ModemTechnologyType(org.eclipse.kura.net.modem.ModemTechnologyType) List(java.util.List) ArrayList(java.util.ArrayList) GwtModemInterfaceConfig(org.eclipse.kura.web.shared.model.GwtModemInterfaceConfig) AuthType(org.eclipse.kura.net.modem.ModemConfig.AuthType) GwtModemAuthType(org.eclipse.kura.web.shared.model.GwtModemAuthType) NetInterfaceAddressConfig(org.eclipse.kura.net.NetInterfaceAddressConfig) ModemInterface(org.eclipse.kura.net.modem.ModemInterface) IP4Address(org.eclipse.kura.net.IP4Address) ModemConnectionStatus(org.eclipse.kura.net.modem.ModemConnectionStatus) ModemConfig(org.eclipse.kura.net.modem.ModemConfig) NetConfig(org.eclipse.kura.net.NetConfig) DhcpServerConfigIP4(org.eclipse.kura.net.dhcp.DhcpServerConfigIP4) NetConfigIP4(org.eclipse.kura.net.NetConfigIP4) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig) Password(org.eclipse.kura.configuration.Password) PdpType(org.eclipse.kura.net.modem.ModemConfig.PdpType) GwtModemPdpType(org.eclipse.kura.web.shared.model.GwtModemPdpType) GwtWifiConfig(org.eclipse.kura.web.shared.model.GwtWifiConfig) GwtWifiNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtWifiNetInterfaceConfig) WifiBgscan(org.eclipse.kura.net.wifi.WifiBgscan) NetworkAdminService(org.eclipse.kura.net.NetworkAdminService) IPAddress(org.eclipse.kura.net.IPAddress)

Example 2 with GwtNetInterfaceConfig

use of org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig in project kura by eclipse.

the class TabTcpIpUi method initForm.

// ---------------Private Methods------------
private void initForm() {
    // Labels
    this.labelStatus.setText(MSGS.netIPv4Status());
    this.labelConfigure.setText(MSGS.netIPv4Configure());
    this.labelIp.setText(MSGS.netIPv4Address());
    this.labelSubnet.setText(MSGS.netIPv4SubnetMask());
    this.labelGateway.setText(MSGS.netIPv4Gateway());
    this.labelDns.setText(MSGS.netIPv4DNSServers());
    this.labelSearch.setText(MSGS.netIPv4SearchDomains());
    for (GwtNetIfConfigMode mode : GwtNetIfConfigMode.values()) {
        this.configure.addItem(MessageUtils.get(mode.name()));
    }
    // Populate status list
    if (this.selectedNetIfConfig != null && this.selectedNetIfConfig.getHwTypeEnum() == GwtNetIfType.MODEM) {
        if (this.status != null) {
            this.status.clear();
            this.status.addItem(MessageUtils.get("netIPv4StatusDisabled"));
            this.status.addItem(MessageUtils.get("netIPv4StatusEnabledWAN"));
        }
    } else {
        if (this.status != null) {
            this.status.clear();
            this.status.addItem(MessageUtils.get("netIPv4StatusDisabled"));
            this.status.addItem(MessageUtils.get("netIPv4StatusEnabledLAN"));
            this.status.addItem(MessageUtils.get("netIPv4StatusEnabledWAN"));
        }
    }
    // SetTooltips
    // Status
    this.status.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.status.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ModemToolTipStatus()));
            }
        }
    });
    this.status.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
    this.status.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            setDirty(true);
            TabTcpIpUi.this.tabs.adjustInterfaceTabs();
            refreshForm();
            resetValidations();
            // changed to WAN
            if (isWanEnabled()) {
                EntryClassUi.showWaitModal();
                TabTcpIpUi.this.gwtNetworkService.findNetInterfaceConfigurations(new AsyncCallback<List<GwtNetInterfaceConfig>>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        EntryClassUi.hideWaitModal();
                        FailureHandler.handle(caught);
                    }

                    @Override
                    public void onSuccess(List<GwtNetInterfaceConfig> result) {
                        EntryClassUi.hideWaitModal();
                        for (GwtNetInterfaceConfig config : result) {
                            if (config.getStatusEnum().equals(GwtNetIfStatus.netIPv4StatusEnabledWAN) && !config.getName().equals(TabTcpIpUi.this.selectedNetIfConfig.getName())) {
                                logger.log(Level.SEVERE, "Error: Status Invalid");
                                TabTcpIpUi.this.wanModal.show();
                                break;
                            }
                        }
                    }
                });
            }
        }
    });
    // Configure
    this.configure.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.configure.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipConfigure()));
            }
        }
    });
    this.configure.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
    this.configure.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            setDirty(true);
            TabTcpIpUi.this.tabs.adjustInterfaceTabs();
            refreshForm();
            resetValidations();
        }
    });
    // Initial view of configure
    if (this.configure.getSelectedItemText().equalsIgnoreCase(VMSGS.netIPv4ConfigModeDHCP())) {
        // Using DHCP selected
        this.ip.setEnabled(false);
        this.subnet.setEnabled(false);
        this.gateway.setEnabled(false);
        this.renew.setEnabled(true);
    } else if (this.configure.getSelectedItemText().equalsIgnoreCase(VMSGS.netIPv4ConfigModeManual())) {
        // Manually selected
        this.ip.setEnabled(true);
        this.subnet.setEnabled(true);
        this.gateway.setEnabled(true);
        this.renew.setEnabled(false);
    }
    // IP Address
    this.ip.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.ip.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipAddress()));
            }
        }
    });
    this.ip.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
    this.ip.addBlurHandler(new BlurHandler() {

        @Override
        public void onBlur(BlurEvent event) {
            setDirty(true);
            if (!TabTcpIpUi.this.ip.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex()) || !(TabTcpIpUi.this.ip.getText().trim().length() > 0)) {
                TabTcpIpUi.this.groupIp.setValidationState(ValidationState.ERROR);
                TabTcpIpUi.this.helpIp.setText(MSGS.netIPv4InvalidAddress());
            } else {
                TabTcpIpUi.this.groupIp.setValidationState(ValidationState.NONE);
                TabTcpIpUi.this.helpIp.setText("");
            }
        }
    });
    // Subnet Mask
    this.subnet.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.subnet.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipSubnetMask()));
            }
        }
    });
    this.subnet.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
    this.subnet.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            setDirty(true);
            if (!TabTcpIpUi.this.subnet.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex()) && TabTcpIpUi.this.subnet.getText().trim().length() > 0) {
                TabTcpIpUi.this.groupSubnet.setValidationState(ValidationState.ERROR);
                TabTcpIpUi.this.helpSubnet.setText(MSGS.netIPv4InvalidAddress());
            } else {
                TabTcpIpUi.this.groupSubnet.setValidationState(ValidationState.NONE);
                TabTcpIpUi.this.helpSubnet.setText("");
            }
        }
    });
    // Gateway
    this.gateway.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.gateway.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipGateway()));
            }
        }
    });
    this.gateway.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
    this.gateway.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            setDirty(true);
            if (!TabTcpIpUi.this.gateway.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex()) && TabTcpIpUi.this.gateway.getText().trim().length() > 0) {
                TabTcpIpUi.this.groupGateway.setValidationState(ValidationState.ERROR);
                TabTcpIpUi.this.helpGateway.setText(MSGS.netIPv4InvalidAddress());
            } else {
                TabTcpIpUi.this.groupGateway.setValidationState(ValidationState.NONE);
                TabTcpIpUi.this.helpGateway.setText("");
            }
        }
    });
    // DNS Servers
    this.dns.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.dns.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipDns()));
            }
        }
    });
    this.dns.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
    this.dns.addChangeHandler(new ChangeHandler() {

        @Override
        public void onChange(ChangeEvent event) {
            setDirty(true);
            if (TabTcpIpUi.this.dns.getText().trim().length() == 0) {
                TabTcpIpUi.this.groupDns.setValidationState(ValidationState.NONE);
                TabTcpIpUi.this.helpDns.setText("");
                return;
            }
            String regex = "[\\s,;\\n\\t]+";
            String[] aDnsServers = TabTcpIpUi.this.dns.getText().trim().split(regex);
            boolean validDnsList = true;
            for (String dnsEntry : aDnsServers) {
                if ((dnsEntry.length() > 0) && !dnsEntry.matches(FieldType.IPv4_ADDRESS.getRegex())) {
                    validDnsList = false;
                    break;
                }
            }
            if (!validDnsList) {
                TabTcpIpUi.this.groupDns.setValidationState(ValidationState.ERROR);
                TabTcpIpUi.this.helpDns.setText(MSGS.netIPv4InvalidAddress());
            } else {
                TabTcpIpUi.this.groupDns.setValidationState(ValidationState.NONE);
                TabTcpIpUi.this.helpDns.setText("");
            }
        /*
                if (!TabTcpIpUi.this.dns.getText().trim().matches(FieldType.IPv4_ADDRESS.getRegex())
                        && TabTcpIpUi.this.dns.getText().trim().length() > 0) {
                    TabTcpIpUi.this.groupDns.setValidationState(ValidationState.ERROR);
                    TabTcpIpUi.this.helpDns.setText(MSGS.netIPv4InvalidAddress());
                } else {
                    TabTcpIpUi.this.groupDns.setValidationState(ValidationState.NONE);
                    TabTcpIpUi.this.helpDns.setText("");
                }
                */
        }
    });
    // Renew DHCP Lease
    this.renew.setText(MSGS.netIPv4RenewDHCPLease());
    this.renew.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            EntryClassUi.showWaitModal();
            TabTcpIpUi.this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                @Override
                public void onFailure(Throwable ex) {
                    EntryClassUi.hideWaitModal();
                    FailureHandler.handle(ex);
                }

                @Override
                public void onSuccess(GwtXSRFToken token) {
                    TabTcpIpUi.this.gwtNetworkService.renewDhcpLease(token, TabTcpIpUi.this.selectedNetIfConfig.getName(), new AsyncCallback<Void>() {

                        @Override
                        public void onFailure(Throwable ex) {
                            EntryClassUi.hideWaitModal();
                            FailureHandler.handle(ex);
                        }

                        @Override
                        public void onSuccess(Void result) {
                            refresh();
                            EntryClassUi.hideWaitModal();
                        }
                    });
                }
            });
        }
    });
    this.renew.addMouseOverHandler(new MouseOverHandler() {

        @Override
        public void onMouseOver(MouseOverEvent event) {
            if (TabTcpIpUi.this.renew.isEnabled()) {
                TabTcpIpUi.this.helpText.clear();
                TabTcpIpUi.this.helpText.add(new Span(MSGS.netIPv4ToolTipRenew()));
            }
        }
    });
    this.renew.addMouseOutHandler(new MouseOutHandler() {

        @Override
        public void onMouseOut(MouseOutEvent event) {
            resetHelp();
        }
    });
}
Also used : BlurHandler(com.google.gwt.event.dom.client.BlurHandler) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Span(org.gwtbootstrap3.client.ui.html.Span) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) MouseOutEvent(com.google.gwt.event.dom.client.MouseOutEvent) MouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ChangeEvent(com.google.gwt.event.dom.client.ChangeEvent) ChangeHandler(com.google.gwt.event.dom.client.ChangeHandler) MouseOverEvent(com.google.gwt.event.dom.client.MouseOverEvent) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig) MouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler) List(java.util.List) BlurEvent(com.google.gwt.event.dom.client.BlurEvent) GwtNetIfConfigMode(org.eclipse.kura.web.shared.model.GwtNetIfConfigMode)

Example 3 with GwtNetInterfaceConfig

use of org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig in project kura by eclipse.

the class NetworkButtonBarUi method initButtons.

private void initButtons() {
    // Apply Button
    this.apply.setText(MSGS.apply());
    this.apply.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            if (!NetworkButtonBarUi.this.tabs.visibleTabs.isEmpty() && NetworkButtonBarUi.this.tabs.isValid()) {
                GwtNetInterfaceConfig prevNetIf = NetworkButtonBarUi.this.table.selectionModel.getSelectedObject();
                final GwtNetInterfaceConfig updatedNetIf = NetworkButtonBarUi.this.tabs.getUpdatedInterface();
                // submit updated netInterfaceConfig and priorities
                if (prevNetIf != null && prevNetIf.equals(updatedNetIf)) {
                    NetworkButtonBarUi.this.table.refresh();
                    NetworkButtonBarUi.this.apply.setEnabled(false);
                } else {
                    String newNetwork = null;
                    String prevNetwork = null;
                    try {
                        newNetwork = calculateNetwork(updatedNetIf.getIpAddress(), updatedNetIf.getSubnetMask());
                        // prevNetwork = Window.Location.getHost();
                        prevNetwork = calculateNetwork(Window.Location.getHost(), updatedNetIf.getSubnetMask());
                    } catch (Exception e) {
                    }
                    if (newNetwork != null) {
                        // location
                        if (updatedNetIf.getConfigMode().equals(IPV4_MODE_MANUAL_NAME) && newNetwork.equals(prevNetwork) && Window.Location.getHost().equals(prevNetIf.getIpAddress())) {
                            Timer t = new Timer() {

                                @Override
                                public void run() {
                                    Window.Location.replace("http://" + updatedNetIf.getIpAddress());
                                }
                            };
                            t.schedule(500);
                        }
                    }
                    EntryClassUi.showWaitModal();
                    NetworkButtonBarUi.this.gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {

                        @Override
                        public void onFailure(Throwable ex) {
                            EntryClassUi.hideWaitModal();
                            FailureHandler.handle(ex, NetworkButtonBarUi.class.getSimpleName());
                        }

                        @Override
                        public void onSuccess(GwtXSRFToken token) {
                            NetworkButtonBarUi.this.gwtNetworkService.updateNetInterfaceConfigurations(token, updatedNetIf, new AsyncCallback<Void>() {

                                @Override
                                public void onFailure(Throwable ex) {
                                    EntryClassUi.hideWaitModal();
                                    FailureHandler.handle(ex, NetworkButtonBarUi.class.getSimpleName());
                                }

                                @Override
                                public void onSuccess(Void result) {
                                    EntryClassUi.hideWaitModal();
                                    NetworkButtonBarUi.this.tabs.setDirty(false);
                                    NetworkButtonBarUi.this.table.refresh();
                                    NetworkButtonBarUi.this.tabs.refresh();
                                    NetworkButtonBarUi.this.apply.setEnabled(false);
                                }
                            });
                        }
                    });
                }
            } else {
                logger.log(Level.FINER, MSGS.information() + ": " + MSGS.deviceConfigError());
                NetworkButtonBarUi.this.incompleteFieldsModal.show();
            }
        }
    });
    // Refresh Button
    this.refresh.setText(MSGS.refresh());
    this.refresh.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            NetworkButtonBarUi.this.table.refresh();
            NetworkButtonBarUi.this.tabs.setDirty(false);
            NetworkButtonBarUi.this.tabs.refresh();
            NetworkButtonBarUi.this.tabs.adjustInterfaceTabs();
        }
    });
    this.table.interfacesGrid.getSelectionModel().addSelectionChangeHandler(new SelectionChangeEvent.Handler() {

        @Override
        public void onSelectionChange(SelectionChangeEvent event) {
            NetworkButtonBarUi.this.apply.setEnabled(true);
        }
    });
// TODO ?? how to detect changes
}
Also used : ClickEvent(com.google.gwt.event.dom.client.ClickEvent) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) GwtXSRFToken(org.eclipse.kura.web.shared.model.GwtXSRFToken) SelectionChangeEvent(com.google.gwt.view.client.SelectionChangeEvent) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) Timer(com.google.gwt.user.client.Timer) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig)

Example 4 with GwtNetInterfaceConfig

use of org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig in project kura by eclipse.

the class NetInterfaceConfigTabs method getUpdatedNetInterface.

public GwtNetInterfaceConfig getUpdatedNetInterface() {
    Log.debug("getting updatedNetInterface");
    GwtNetInterfaceConfig updatedNetIf = null;
    if (m_netIfConfig instanceof GwtWifiNetInterfaceConfig) {
        Log.debug("Creating GwtWifiNetInterfaceConfig");
        updatedNetIf = new GwtWifiNetInterfaceConfig();
    } else if (m_netIfConfig instanceof GwtModemInterfaceConfig) {
        Log.debug("Creating GwtModemInterfaceConfig");
        updatedNetIf = new GwtModemInterfaceConfig();
    } else {
        Log.debug("Creating GwtNetInterfaceConfig");
        updatedNetIf = new GwtNetInterfaceConfig();
    }
    // Copy the previous values
    updatedNetIf.setProperties(m_netIfConfig.getProperties());
    // Get updated values from visible tabs
    Log.debug("Setting updated values");
    List<TabItem> tabItems = new ArrayList<TabItem>(m_tabsPanel.getItems());
    if (tabItems.contains(m_tabIPv4Config)) {
        m_tcpIpConfigTab.getUpdatedNetInterface(updatedNetIf);
    }
    if (tabItems.contains(m_tabWirelessConfig)) {
        m_wirelessConfigTab.getUpdatedNetInterface(updatedNetIf);
    }
    if (tabItems.contains(m_tabModemConfig)) {
        m_modemConfigTab.getUpdatedNetInterface(updatedNetIf);
    }
    if (tabItems.contains(m_tabModemGpsConfig)) {
        m_modemGpsConfigTab.getUpdatedNetInterface(updatedNetIf);
    }
    if (tabItems.contains(m_tabDhcpNatConfig)) {
        m_dhcpNatConfigTab.getUpdatedNetInterface(updatedNetIf);
    }
    if (tabItems.contains(m_tabHardwareConfig)) {
        m_hwConfigTab.getUpdatedNetInterface(updatedNetIf);
    }
    return updatedNetIf;
}
Also used : TabItem(com.extjs.gxt.ui.client.widget.TabItem) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig) ArrayList(java.util.ArrayList) GwtWifiNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtWifiNetInterfaceConfig) GwtModemInterfaceConfig(org.eclipse.kura.web.shared.model.GwtModemInterfaceConfig)

Example 5 with GwtNetInterfaceConfig

use of org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig in project kura by eclipse.

the class NetworkInterfacesTable method initGrid.

private void initGrid() {
    // 
    // Column Configuration
    List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
    ColumnConfig column = new ColumnConfig("name", MSGS.netInterfaceName(), 125);
    column.setAlignment(HorizontalAlignment.LEFT);
    column.setSortable(false);
    configs.add(column);
    // loader and store
    RpcProxy<ListLoadResult<GwtNetInterfaceConfig>> proxy = new RpcProxy<ListLoadResult<GwtNetInterfaceConfig>>() {

        @Override
        public void load(Object loadConfig, AsyncCallback<ListLoadResult<GwtNetInterfaceConfig>> callback) {
            gwtNetworkService.findNetInterfaceConfigurations(callback);
        }
    };
    m_loader = new BaseListLoader<ListLoadResult<GwtNetInterfaceConfig>>(proxy);
    m_loader.setRemoteSort(false);
    m_loader.setSortDir(SortDir.ASC);
    m_loader.setSortField("name");
    m_store = new ListStore<GwtNetInterfaceConfig>(m_loader);
    m_store.setStoreSorter(new StoreSorter<GwtNetInterfaceConfig>(new Comparator<Object>() {

        public int compare(Object o1, Object o2) {
            if (o1 == null) {
                o1 = new Integer(-1);
            } else {
                o1 = getIntFromName((String) o1);
            }
            if (o2 == null) {
                o2 = new Integer(-1);
            } else {
                o2 = getIntFromName((String) o2);
            }
            return (Integer) o1 - (Integer) o2;
        }

        private Integer getIntFromName(String name) {
            if ("lo".equals(name))
                return new Integer(1);
            else if ("eth0".equals(name))
                return new Integer(2);
            else if ("eth1".equals(name))
                return new Integer(3);
            else if (name.contains("eth"))
                return new Integer(4);
            else if ("wlan0".equals(name))
                return new Integer(10);
            else if ("ppp0".equals(name))
                return new Integer(20);
            else if (name.contains("ppp"))
                return new Integer(21);
            else
                return new Integer(100);
        }
    }));
    m_grid = new Grid<GwtNetInterfaceConfig>(m_store, new ColumnModel(configs));
    m_grid.setBorders(false);
    m_grid.setStateful(false);
    m_grid.setLoadMask(true);
    m_grid.setStripeRows(true);
    m_grid.setAutoExpandColumn("name");
    m_grid.getView().setAutoFill(true);
    m_grid.getView().setEmptyText(MSGS.netTableNoInterfaces());
    GridSelectionModel<GwtNetInterfaceConfig> selectionModel = new GridSelectionModel<GwtNetInterfaceConfig>();
    selectionModel.setSelectionMode(SelectionMode.SINGLE);
    m_grid.setSelectionModel(selectionModel);
    // 
    // on selection, complete the switch
    m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtNetInterfaceConfig>() {

        @Override
        public void selectionChanged(SelectionChangedEvent<GwtNetInterfaceConfig> se) {
            GwtNetInterfaceConfig gwtNetIfConfig = se.getSelectedItem();
            if (gwtNetIfConfig != null) {
                m_selectedIfConfig = gwtNetIfConfig;
                m_netConfigTabs.setNetInterface(gwtNetIfConfig);
            }
        }
    });
    m_loader.addLoadListener(new DataLoadListener(m_netConfigTabs, m_grid));
}
Also used : ColumnConfig(com.extjs.gxt.ui.client.widget.grid.ColumnConfig) AsyncCallback(com.google.gwt.user.client.rpc.AsyncCallback) ArrayList(java.util.ArrayList) GridSelectionModel(com.extjs.gxt.ui.client.widget.grid.GridSelectionModel) RpcProxy(com.extjs.gxt.ui.client.data.RpcProxy) Comparator(java.util.Comparator) ListLoadResult(com.extjs.gxt.ui.client.data.ListLoadResult) GwtNetInterfaceConfig(org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig) ColumnModel(com.extjs.gxt.ui.client.widget.grid.ColumnModel)

Aggregations

GwtNetInterfaceConfig (org.eclipse.kura.web.shared.model.GwtNetInterfaceConfig)11 GwtModemInterfaceConfig (org.eclipse.kura.web.shared.model.GwtModemInterfaceConfig)6 AsyncCallback (com.google.gwt.user.client.rpc.AsyncCallback)5 ArrayList (java.util.ArrayList)5 GwtWifiNetInterfaceConfig (org.eclipse.kura.web.shared.model.GwtWifiNetInterfaceConfig)5 GwtXSRFToken (org.eclipse.kura.web.shared.model.GwtXSRFToken)4 List (java.util.List)3 GwtWifiConfig (org.eclipse.kura.web.shared.model.GwtWifiConfig)3 ListLoadResult (com.extjs.gxt.ui.client.data.ListLoadResult)2 ButtonEvent (com.extjs.gxt.ui.client.event.ButtonEvent)2 Button (com.extjs.gxt.ui.client.widget.button.Button)2 FitLayout (com.extjs.gxt.ui.client.widget.layout.FitLayout)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 Timer (com.google.gwt.user.client.Timer)2 KuraException (org.eclipse.kura.KuraException)2 IP4Address (org.eclipse.kura.net.IP4Address)2 NetConfig (org.eclipse.kura.net.NetConfig)2 NetConfigIP4 (org.eclipse.kura.net.NetConfigIP4)2 NetworkAdminService (org.eclipse.kura.net.NetworkAdminService)2