public boolean isEnabled() throws KuraException { try { // Check if named is running int pid = LinuxProcessUtil.getPid(s_procString); return (pid > -1); } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } }
public boolean disable() throws KuraException { try { int result = -1; // If so, stop it. if (OS_VERSION.equals( KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion())) { result = LinuxProcessUtil.start("/etc/init.d/bind stop"); } else if (OS_VERSION.equals(KuraConstants.Raspberry_Pi.getImageName()) || OS_VERSION.equals(KuraConstants.BeagleBone.getImageName())) { result = LinuxProcessUtil.start("/etc/init.d/bind9 stop"); } else if (OS_VERSION.equals( KuraConstants.Intel_Edison.getImageName() + "_" + KuraConstants.Intel_Edison.getImageVersion() + "_" + KuraConstants.Intel_Edison.getTargetName())) { result = LinuxProcessUtil.start("/etc/init.d/bind stop"); } else if (OS_VERSION.equals( KuraConstants.ReliaGATE_50_21_Ubuntu.getImageName() + "_" + KuraConstants.ReliaGATE_50_21_Ubuntu.getImageVersion())) { result = LinuxProcessUtil.start("/etc/init.d/bind9 stop"); } else { result = LinuxProcessUtil.start("/etc/init.d/named stop"); } if (result == 0) { s_logger.debug("DNS server stopped."); s_logger.trace(m_dnsServerConfigIP4.toString()); return true; } else { s_logger.debug("tried to kill DNS server for interface but it is not running"); } } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } return true; }
public boolean restart() throws KuraException { try { if (LinuxProcessUtil.start("/etc/init.d/named restart") == 0) { s_logger.debug("DNS server restarted."); } else { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "error restarting"); } } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } return true; }
public boolean enable() throws KuraException { // write config happened during 'set config' step try { // Check if named is running int pid = LinuxProcessUtil.getPid(s_procString); if (pid > -1) { // If so, disable it s_logger.error("DNS server is already running, bringing it down..."); disable(); } // Start named int result = -1; if (OS_VERSION.equals( KuraConstants.Mini_Gateway.getImageName() + "_" + KuraConstants.Mini_Gateway.getImageVersion())) { result = LinuxProcessUtil.start("/etc/init.d/bind start"); } else if (OS_VERSION.equals( KuraConstants.ReliaGATE_10_05.getImageName() + "_" + KuraConstants.ReliaGATE_10_05.getImageVersion())) { result = LinuxProcessUtil.start("/etc/init.d/bind start"); } else if (OS_VERSION.equals(KuraConstants.Raspberry_Pi.getImageName()) || OS_VERSION.equals(KuraConstants.BeagleBone.getImageName())) { result = LinuxProcessUtil.start("/etc/init.d/bind9 start"); } else if (OS_VERSION.equals( KuraConstants.Intel_Edison.getImageName() + "_" + KuraConstants.Intel_Edison.getImageVersion() + "_" + KuraConstants.Intel_Edison.getTargetName())) { result = LinuxProcessUtil.start("/etc/init.d/bind start"); } else if (OS_VERSION.equals( KuraConstants.ReliaGATE_50_21_Ubuntu.getImageName() + "_" + KuraConstants.ReliaGATE_50_21_Ubuntu.getImageVersion())) { result = LinuxProcessUtil.start("/etc/init.d/bind9 start"); } else { s_logger.info("Linux named enable fallback"); result = LinuxProcessUtil.start("/etc/init.d/named start"); } if (result == 0) { s_logger.debug("DNS server started."); s_logger.trace(m_dnsServerConfigIP4.toString()); return true; } } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } return false; }
public void scan() throws KuraException { String line = null; ProcessStats processStats = null; BufferedReader br = null; String sScanCommand = formSupplicantScanCommand(m_iface); // scan for wireless networks try { processStats = LinuxProcessUtil.startWithStats(sScanCommand); } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } try { br = new BufferedReader(new InputStreamReader(processStats.getInputStream())); line = br.readLine(); if ((line == null) || !line.equals("OK")) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, sScanCommand + " command failed"); } } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } finally { try { br.close(); } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } } // get scan results String sScanResultsCommand = formSupplicantScanResultsCommand(m_iface); try { processStats = LinuxProcessUtil.startWithStats(sScanResultsCommand); } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } try { br = new BufferedReader(new InputStreamReader(processStats.getInputStream())); String[] aScanInfo = null; while ((line = br.readLine()) != null) { aScanInfo = line.split("\\s+"); if (aScanInfo.length > 0) { String macAddress = aScanInfo[0]; int frequency = Integer.parseInt(aScanInfo[1]); int signalLevel = Integer.parseInt(aScanInfo[2]); int securityCode = 0; String sSecurity = aScanInfo[3].substring(aScanInfo[3].indexOf("[") + 1, aScanInfo[3].lastIndexOf(']')); StringTokenizer st = new StringTokenizer(sSecurity, "]["); while (st.hasMoreTokens()) { String token = st.nextToken(); if (token.startsWith("WEP")) { securityCode |= 1; } else if (token.startsWith("WPA2")) { securityCode |= 4; } else if (token.startsWith("WPA")) { securityCode |= 2; } } WifiSecurity wifiSecurity = null; switch (securityCode) { case 1: wifiSecurity = WifiSecurity.SECURITY_WEP; break; case 2: wifiSecurity = WifiSecurity.SECURITY_WPA; break; case 4: wifiSecurity = WifiSecurity.SECURITY_WPA2; break; case 6: wifiSecurity = WifiSecurity.SECURITY_WPA_WPA2; break; default: wifiSecurity = WifiSecurity.NONE; } String ssid = aScanInfo[4]; WifiHotspotInfo wifiHotspotInfo = new WifiHotspotInfo( ssid, macAddress, signalLevel, frequencyMhz2Channel(frequency), frequency, wifiSecurity); m_listWifiHotspotInfo.add(wifiHotspotInfo); } } } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } finally { try { br.close(); } catch (Exception e) { throw new KuraException(KuraErrorCode.INTERNAL_ERROR, e); } } }