[PC-BSD Commits] r17664 - pcbsd/current/src-qt4/warden-gui

svn at pcbsd.org svn at pcbsd.org
Fri Jul 6 07:32:08 PDT 2012


Author: kris
Date: 2012-07-06 14:32:07 +0000 (Fri, 06 Jul 2012)
New Revision: 17664

Modified:
   pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp
   pcbsd/current/src-qt4/warden-gui/wizardNewJail.cpp
   pcbsd/current/src-qt4/warden-gui/wizardNewJail.h
   pcbsd/current/src-qt4/warden-gui/wizardNewJail.ui
Log:

Add some validation to IP / Hostname during creation of new jails in warden
GUI



Modified: pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp
===================================================================
--- pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp	2012-07-06 13:33:52 UTC (rev 17663)
+++ pcbsd/current/src-qt4/warden-gui/dialogwarden.cpp	2012-07-06 14:32:07 UTC (rev 17664)
@@ -841,10 +841,21 @@
 
 void dialogWarden::slotClickedNewJail()
 {
+      QStringList uH, uI;
+
        // Launch our working dialog to prevent further action until we are finished
       newJailWizard = new wizardNewJail();
       newJailWizard->setModal(true);
       newJailWizard->programInit();
+
+      // Build list of used jail IP / Hosts
+      QTreeWidgetItemIterator it( listJails );
+      while (*it) {
+         uI << (*it)->text(0);
+         uH << (*it)->text(2);
+         ++it;
+      }
+      newJailWizard->setHostIPUsed(uH, uI);
       
       connect( newJailWizard, SIGNAL(create(const QString &, const QString &, bool, const QString &, bool, bool, bool, bool, const QString &)), this, SLOT(slotCreateNewJail(const QString &, const QString &, bool, const QString &, bool, bool, bool, bool, const QString &) ) );
       newJailWizard->show();

Modified: pcbsd/current/src-qt4/warden-gui/wizardNewJail.cpp
===================================================================
--- pcbsd/current/src-qt4/warden-gui/wizardNewJail.cpp	2012-07-06 13:33:52 UTC (rev 17663)
+++ pcbsd/current/src-qt4/warden-gui/wizardNewJail.cpp	2012-07-06 14:32:07 UTC (rev 17664)
@@ -27,6 +27,11 @@
     connect(this, SIGNAL(currentIdChanged(int)), this, SLOT(slotCheckComplete()) );
 }
 
+void wizardNewJail::setHostIPUsed(QStringList uH, QStringList uIP)
+{
+   usedHosts = uH;
+   usedIP = uIP;
+}
 
 void wizardNewJail::accept()
 {
@@ -46,16 +51,58 @@
 // Logic checks to see if we are ready to move onto next page
 bool wizardNewJail::validatePage()
 {
+  QColor red = QColor(255, 78, 78);
+  QColor white = QColor(255, 255, 255);
+  QPalette badPal(red);
+  badPal.setColor(QPalette::Window,red);
+  badPal.setColor(QPalette::WindowText,red);
+  QPalette goodPal(white);
+  goodPal.setColor(QPalette::Window,white);
+  goodPal.setColor(QPalette::WindowText,white);
+  labelMessage->setText(QString());
+
+
   switch (currentId()) {
      case Page_IP:
+         // Make sure items are not empty
+         if ( lineIP->text().isEmpty() ) {
+            button(QWizard::NextButton)->setEnabled(false);
+            return false;
+	 }
+         if ( lineHost->text().isEmpty() ) {
+            button(QWizard::NextButton)->setEnabled(false);
+            return false;
+	 }
+
+	 // Check if this IP / Host is already used
+         for (int i = 0; i < usedHosts.size(); ++i)
+            if ( usedHosts.at(i) == lineHost->text() ) {
+               button(QWizard::NextButton)->setEnabled(false);
+               lineHost->setPalette(badPal);
+               labelMessage->setText(tr("Hostname already used!"));
+               return false;
+	    }
+         for (int i = 0; i < usedIP.size(); ++i)
+            if ( usedIP.at(i) == lineIP->text() ) {
+               button(QWizard::NextButton)->setEnabled(false);
+               lineIP->setPalette(badPal);
+               labelMessage->setText(tr("IP already used!"));
+               return false;
+	    }
+
          // Check if we have a good IPV4 or IPV6 address
-	 if ( Utils::validateIPV4(lineIP->text()) || Utils::validateIPV6(lineIP->text()) ) {
-           button(QWizard::NextButton)->setEnabled(true);
-           return true;
-         } else {
+	 if ( ! Utils::validateIPV4(lineIP->text()) && ! Utils::validateIPV6(lineIP->text()) ) {
            button(QWizard::NextButton)->setEnabled(false);
+           lineIP->setPalette(badPal);
+           labelMessage->setText(tr("Invalid IP address!"));
            return false;
          }
+
+         // Got to the end, must be good!
+         lineIP->setPalette(goodPal);
+         lineHost->setPalette(goodPal);
+         button(QWizard::NextButton)->setEnabled(true);
+         return true;
      case Page_Root:
 	 if ( lineRoot->text().isEmpty() || lineRoot->text() != lineRoot2->text() ) {
            button(QWizard::NextButton)->setEnabled(false);

Modified: pcbsd/current/src-qt4/warden-gui/wizardNewJail.h
===================================================================
--- pcbsd/current/src-qt4/warden-gui/wizardNewJail.h	2012-07-06 13:33:52 UTC (rev 17663)
+++ pcbsd/current/src-qt4/warden-gui/wizardNewJail.h	2012-07-06 14:32:07 UTC (rev 17664)
@@ -15,6 +15,7 @@
         }
 
      void programInit();
+     void setHostIPUsed(QStringList, QStringList);
      virtual int nextId() const;
 
 public slots:
@@ -27,6 +28,7 @@
 
 private:
     bool validatePage();
+    QStringList usedHosts, usedIP;
     enum { Page_IP, Page_Type, Page_Root, Page_Linux, Page_Opts };
 
 signals:

Modified: pcbsd/current/src-qt4/warden-gui/wizardNewJail.ui
===================================================================
(Binary files differ)



More information about the Commits mailing list