[PC-BSD Commits] r9751 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Mon Mar 21 14:21:38 PDT 2011


Author: kenmoore
Date: 2011-03-21 14:21:38 -0700 (Mon, 21 Mar 2011)
New Revision: 9751

Modified:
   pcbsd/current/src-qt4/libpcbsd/netif.cpp
   pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h
   pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
   pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:
Added a couple new functions to libpcbsd.
QString Utils::runShellCommandLine(QString) - finished and working
QString NetworkUtilities::getWifiSecurity(QString,QString) - Done but needs testing still


Modified: pcbsd/current/src-qt4/libpcbsd/netif.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/netif.cpp	2011-03-21 20:21:22 UTC (rev 9750)
+++ pcbsd/current/src-qt4/libpcbsd/netif.cpp	2011-03-21 21:21:38 UTC (rev 9751)
@@ -316,7 +316,7 @@
   QString signoise = line.section(" ",3,3,QString::SectionSkipEmpty); //S:G column
   QString inte = line.section(" ",4,4,QString::SectionSkipEmpty); //INT column
   QString caps = line.section(" ",5,5,QString::SectionSkipEmpty); //CAPS column
-  QString etc = line.section(" ",6,50,QString::SectionSkipEmpty); //Everything at the end  
+  QString etc = line.section(" ",6,50,QString::SectionSkipEmpty); //Everything at the end (security info) 
 
     //change signoise into signal strength(%)
     QString sig = signoise.section(":",0,0); //determine signal
@@ -335,3 +335,42 @@
   return out;
 }
 
+QString NetworkInterface::getWifiSecurity( QString SSID, QString deviceName ){
+  //Make sure the SSID is less than 16 long (non verbose to be used)
+  QString smSSID;
+  if(SSID.size() > 16){
+    smSSID = SSID.left(15);
+  }else{
+    smSSID = SSID; 
+  }
+  //Scan the wifi to determine the security type
+  QString command = "ifconfig " + deviceName + " list scan | grep " + smSSID;
+  QString ifconfOut = Utils::runShellCommandLine(command);
+  QStringList parsed = NetworkInterface::parseWifiScanLine(ifconfOut,false);
+  QString caps = parsed[6];
+  QStringList secure = parsed[7].split(" "); //put each security type in a different list element
+  
+  //Examine the CAPS and Security data to determine the wifi encryption type
+  bool isDisabled = !caps.contains("P") && caps.contains("ES") && (secure.size()==-1); //CAPS = "ES" only -> no security
+  bool isWEP = caps.contains("EP") && (secure.size()==-1); //CAPS = "EP" or "EPS" only (could also be RADIUS security type)
+  bool isWPA = secure.contains("WPA"); //both WPA personal and enterprise
+  bool isWPA2 = secure.contains("RSN"); //both WPA2 personal and enterprise
+  
+  //Output the security type
+  QString securityType;
+  if(isDisabled){ 
+    securityType = "None";
+  }else if(isWEP){ 
+    securityType = "WEP";
+  }else if(isWPA){ 
+    securityType = "WPA";
+  }else if(isWPA2){ 
+    securityType = "WPA2";
+  }else{ 
+    securityType = "ERROR";
+  }
+  
+  return securityType;
+  
+}
+

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h	2011-03-21 20:21:22 UTC (rev 9750)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-netif.h	2011-03-21 21:21:38 UTC (rev 9751)
@@ -51,6 +51,7 @@
    
    static QStringList getInterfaces();
    static QStringList parseWifiScanLine(QString linein, bool isverbose);
+   static QString getWifiSecurity(QString SSID,QString deviceName);
 
 private:
    QString name;

Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2011-03-21 20:21:22 UTC (rev 9750)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2011-03-21 21:21:38 UTC (rev 9751)
@@ -54,6 +54,7 @@
    static QString getConfFileValue( QString oFile, QString Key );
    static QString getConfFileValue( QString oFile, QString Key, int occur );
    static QStringList runShellCommand( QString command );
+   static QString runShellCommandLine( QString command );
 };
 
 #endif

Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp	2011-03-21 20:21:22 UTC (rev 9750)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp	2011-03-21 21:21:38 UTC (rev 9751)
@@ -332,6 +332,7 @@
     
 }
 
+//Run a shell command (return a list of lines)
 QStringList Utils::runShellCommand( QString command )
 {
  QProcess p;
@@ -342,3 +343,14 @@
  QStringList out = outstr.split("\n"); //put each line into a different element
  return out;
 }
+
+//Run a shell command (return output in original formatting)
+//This version is useful for a command that return a single line of output
+QString Utils::runShellCommandLine( QString command )
+{
+ QProcess p;
+ p.start(command);
+ p.waitForFinished(-1);
+ QString outstr = p.readAllStandardOutput();
+ return outstr;
+}



More information about the Commits mailing list