[PC-BSD Commits] r17281 - pcbsd/current/src-qt4/pc-servicemanager

svn at pcbsd.org svn at pcbsd.org
Thu Jun 14 09:26:59 PDT 2012


Author: kris
Date: 2012-06-14 16:26:57 +0000 (Thu, 14 Jun 2012)
New Revision: 17281

Modified:
   pcbsd/current/src-qt4/pc-servicemanager/main.cpp
   pcbsd/current/src-qt4/pc-servicemanager/pc-servicemanager.pro
   pcbsd/current/src-qt4/pc-servicemanager/servicemanager.cpp
   pcbsd/current/src-qt4/pc-servicemanager/servicemanager.h
   pcbsd/current/src-qt4/pc-servicemanager/servicemanager.ui
Log:

Enhance the service manager GUI, provide functionality to control services
inside warden-managed jails



Modified: pcbsd/current/src-qt4/pc-servicemanager/main.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-servicemanager/main.cpp	2012-06-14 15:49:13 UTC (rev 17280)
+++ pcbsd/current/src-qt4/pc-servicemanager/main.cpp	2012-06-14 16:26:57 UTC (rev 17281)
@@ -32,12 +32,25 @@
       QFont f( "Dejavu", 12);
       a.setFont( f);
     }
-    
-    QString Tmp = a.argv()[1];
-  
+
+    QString chroot, ip;
+    if ( argc >= 2)
+    {
+       QString chkarg = argv[1];
+       // Running in a warden jail?
+       if ( chkarg == "-warden" )
+         if ( argc == 4 ) {
+           chroot = argv[2];
+           ip = argv[3];
+         } else {
+           qDebug() << "Usage: -warden <directory> <ip>";
+           exit(1);
+         }
+    }
+
     ServiceManager w;
 
-    w.ProgramInit();
+    w.ProgramInit(chroot, ip);
 
     w.show();
     a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );

Modified: pcbsd/current/src-qt4/pc-servicemanager/pc-servicemanager.pro
===================================================================
--- pcbsd/current/src-qt4/pc-servicemanager/pc-servicemanager.pro	2012-06-14 15:49:13 UTC (rev 17280)
+++ pcbsd/current/src-qt4/pc-servicemanager/pc-servicemanager.pro	2012-06-14 16:26:57 UTC (rev 17281)
@@ -1,6 +1,8 @@
 TEMPLATE	= app
 LANGUAGE	= C++
 
+LIBS    += -L/usr/local/lib -lpcbsd
+
 CONFIG	+= qt warn_on release
 
 TRANSLATIONS = 	i18n/ServiceManager_af.ts \

Modified: pcbsd/current/src-qt4/pc-servicemanager/servicemanager.cpp
===================================================================
--- pcbsd/current/src-qt4/pc-servicemanager/servicemanager.cpp	2012-06-14 15:49:13 UTC (rev 17280)
+++ pcbsd/current/src-qt4/pc-servicemanager/servicemanager.cpp	2012-06-14 16:26:57 UTC (rev 17281)
@@ -9,17 +9,21 @@
 ** These will automatically be called by the form's constructor and
 ** destructor.
 *****************************************************************************/
+#include <QDebug>
+#include <QTimer>
+#include <QTreeWidgetItem>
+#include <QTextStream>
+#include <pcbsd-utils.h>
+
 #include "ui_servicemanager.h"
 #include "servicemanager.h"
-#include <QTreeWidgetItem>
-#include <qtextstream.h>
-#include <QDebug>
 
-#define S_DIRS	"/etc/rc.d" << "/usr/local/etc/rc.d"
+void ServiceManager::ProgramInit(QString chroot, QString IP)
+{
+    // Set any warden stuff
+    wDir = chroot;
+    wIP = IP;
 
-
-void ServiceManager::ProgramInit()
-{
     listServices->setColumnHidden(0, true);
     listServices->setColumnHidden(1, true);
     
@@ -49,6 +53,9 @@
     
     // Start checking if services are enabled
     checkEnabled();
+
+    if ( ! wDir.isEmpty() )
+      textTopLabel->setText(tr("Managing services for Warden IP:") + " " +  wIP);
 }
 
 void ServiceManager::setButtonsAllEnabled(bool enabled)
@@ -59,10 +66,6 @@
   pushEnableStartup->setEnabled(enabled); 
   pushDisableStartup->setEnabled(enabled); 
 
-  if ( enabled )
-    textTopLabel->setText("");
-  else
-    textTopLabel->setText(tr("Please Wait..."));
 }
 
 void ServiceManager::startSlot()
@@ -76,11 +79,18 @@
     // Disable the buttons until we are done
     setButtonsAllEnabled(false);
 
-    // Start the detection script
-    QString prog = item->text(0);
+    // Start the process
+    QString prog;
     QStringList args;
-    args << "start";
 
+    if ( wDir.isEmpty() ) {
+      prog = item->text(0);
+      args << "start";
+    } else {
+      prog = "warden";
+      args << "chroot" << wIP << item->text(0) + " start";
+    }
+
     // Show the progress GUI
     progressUI *servAction = new progressUI;
     servAction->startServ(prog, args);
@@ -88,10 +98,6 @@
 
     listSelectionChanged();
 
-    // Start checking the status of these services
-    currentCheckRunningItem = new QTreeWidgetItemIterator(listServices);
-    checkRunning();
-
 }
 
 
@@ -106,11 +112,18 @@
     // Disable the buttons until we are done
     setButtonsAllEnabled(false);
 
-    // Start the detection script
-    QString prog = item->text(0);
+    // Stop the process
+    QString prog;
     QStringList args;
-    args << "stop";
 
+    if ( wDir.isEmpty() ) {
+      prog = item->text(0);
+      args << "start";
+    } else {
+      prog = "warden";
+      args << "chroot" << wIP << item->text(0) + " stop";
+    }
+
     // Show the progress GUI
     progressUI *servAction = new progressUI;
     servAction->startServ(prog, args);
@@ -118,9 +131,6 @@
 
     listSelectionChanged();
 
-    // Start checking the status of these services
-    currentCheckRunningItem = new QTreeWidgetItemIterator(listServices);
-    checkRunning();
 }
 
 
@@ -135,11 +145,19 @@
     // Disable the buttons until we are done
     setButtonsAllEnabled(false);
 
-    // Start the detection script
-    QString prog = item->text(0);
+    // Restart the process
+    QString prog;
     QStringList args;
-    args << "restart";
 
+    if ( wDir.isEmpty() ) {
+      prog = item->text(0);
+      args << "start";
+    } else {
+      prog = "warden";
+      args << "chroot" << wIP << item->text(0) + " restart";
+    }
+
+
     // Show the progress GUI
     progressUI *servAction = new progressUI;
     servAction->startServ(prog, args);
@@ -147,9 +165,6 @@
 
     listSelectionChanged();
 
-    // Start checking the status of these services
-    currentCheckRunningItem = new QTreeWidgetItemIterator(listServices);
-    checkRunning();
 }
 
 
@@ -166,37 +181,11 @@
     // Disable the buttons until we are done
     setButtonsAllEnabled(false);
 
-    // Read in the rc.conf
-    QFile file( "/etc/rc.conf" );
-    if ( file.open( QIODevice::ReadOnly ) ) {
-      QTextStream stream( &file );
-      stream.setCodec("UTF-8");
-      while ( !stream.atEnd() )
-         rcList << stream.readLine();
-      file.close();
-    } else {
-	return;
-    }
+    Utils::setConfFileValue( wDir + "/etc/rc.conf", tag, tag + "=\"YES\"", -1);
 
-    // Remove old tags if any
-    for ( int i=0; i<rcList.size(); i++ )
-      if ( rcList.at(i).indexOf(tag + "=") != -1 )
-	rcList.removeAt(i);
-
-    // Save the fixed rc.conf
-    if ( file.open( QIODevice::WriteOnly ) ) {
-      QTextStream stream( &file );
-      stream.setCodec("UTF-8");
-      for ( int i = 0; i<rcList.size(); i++ ) 
-         stream << rcList.at(i) << "\n";
-
-      stream << tag << "=\"YES\"\n";
-      file.close();
-    }
-
-     // Set the service as enabled
-     item->setText(4, tr("Enabled"));
-     listSelectionChanged();
+    // Set the service as enabled
+    item->setText(4, tr("Enabled"));
+    listSelectionChanged();
 }
 
 
@@ -216,37 +205,11 @@
     // Disable the buttons until we are done
     setButtonsAllEnabled(false);
 
-    // Read in the rc.conf
-    QFile file( "/etc/rc.conf" );
-    if ( file.open( QIODevice::ReadOnly ) ) {
-      QTextStream stream( &file );
-      stream.setCodec("UTF-8");
-      while ( !stream.atEnd() )
-         rcList << stream.readLine();
-      file.close();
-    } else {
-        return;
-    }
+    Utils::setConfFileValue( wDir + "/etc/rc.conf", tag, tag + "=\"NO\"", -1);
 
-    // Remove old tags if any
-    for ( int i=0; i<rcList.size(); i++ )
-      if ( rcList.at(i).indexOf(tag + "=") != -1 )
-        rcList.removeAt(i);
-
-    // Save the fixed rc.conf
-    if ( file.open( QIODevice::WriteOnly ) ) {
-      QTextStream stream( &file );
-      stream.setCodec("UTF-8");
-      for ( int i = 0; i<rcList.size(); i++ )
-         stream << rcList.at(i) << "\n";
-
-      stream << tag << "=\"NO\"\n";
-      file.close();
-    }
-
-     // Set the service as enabled
-     item->setText(4, tr("Disabled"));
-     listSelectionChanged();
+    // Set the service as enabled
+    item->setText(4, tr("Disabled"));
+    listSelectionChanged();
 }
 
 
@@ -257,7 +220,7 @@
 	QString ServiceDir, ServiceTag, ServiceName;
     
 	QStringList sDirs;
-	sDirs << S_DIRS;
+	sDirs << wDir + "/etc/rc.d" << wDir + "/usr/local/etc/rc.d";
 
 	for ( int z = 0; z < sDirs.size(); ++z) {
 
@@ -320,9 +283,12 @@
 	  	    continue;
 
                   QStringList cols;
-                  cols << sDirs.at(z) + "/" + ServiceDir << ServiceTag << ServiceName << tr("Unknown") << tr("Unknown");
+		  QString cDir = sDirs.at(z);
+		  if ( ! wDir.isEmpty() )
+		    cDir.replace(wDir, "");
+                  cols << cDir + "/" + ServiceDir << ServiceTag << ServiceName << tr("Unknown") << tr("Unknown");
 		  (void) new QTreeWidgetItem(listServices, cols );
-		  qDebug() << "Added Service:" << ServiceDir << ServiceName << ServiceTag;
+		  qDebug() << "Added Service:" << cDir << ServiceDir << ServiceName << ServiceTag;
 	      }
           }
  	}   
@@ -337,17 +303,31 @@
     QTreeWidgetItemIterator it(*currentCheckRunningItem);
     if (*it)
     {
-	// Start the detection script
-        QString prog = (*it)->text(0);
-        QStringList args;
-        args << "status";
-
-	CheckServiceRunning= new QProcess( this );
-	connect( CheckServiceRunning, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(checkRunningFinishedSlot()) );
-	CheckServiceRunning->start(prog, args);
+	if ( wDir.isEmpty() ) {
+	  // Start the detection script
+          QString prog = (*it)->text(0);
+          QStringList args;
+          args << "status";
+	  CheckServiceRunning= new QProcess( this );
+	  connect( CheckServiceRunning, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(checkRunningFinishedSlot()) );
+	  CheckServiceRunning->start(prog, args);
+	} else {
+	  // Start the detection script
+          QString prog = "warden";
+          QStringList args;
+          args << "chroot" << wIP << (*it)->text(0) + " status";
+	  CheckServiceRunning= new QProcess( this );
+	  connect( CheckServiceRunning, SIGNAL(finished(int, QProcess::ExitStatus)), this, SLOT(checkRunningFinishedSlot()) );
+	  CheckServiceRunning->start(prog, args);
+        }
+	return;
     }
     
 
+    // At the end! Restart scanning in a few seconds
+    currentCheckRunningItem = new QTreeWidgetItemIterator(listServices);
+    QTimer::singleShot(8000, this, SLOT(checkRunning()));
+
 }
 
 
@@ -357,7 +337,7 @@
     QStringList rcFiles;
     QString tmp, tmp2;
 
-    rcFiles << "/etc/rc.conf" << "/etc/rc.conf.local" << "/etc/defaults/rc.conf";
+    rcFiles << wDir + "/etc/rc.conf" << wDir + "/etc/rc.conf.local" << wDir + "/etc/defaults/rc.conf";
 
     // Read in the rc conf files
     for ( int r = 0; r<rcFiles.size(); r++ ) {

Modified: pcbsd/current/src-qt4/pc-servicemanager/servicemanager.h
===================================================================
--- pcbsd/current/src-qt4/pc-servicemanager/servicemanager.h	2012-06-14 15:49:13 UTC (rev 17280)
+++ pcbsd/current/src-qt4/pc-servicemanager/servicemanager.h	2012-06-14 16:26:57 UTC (rev 17281)
@@ -20,7 +20,7 @@
 
 
 public slots:
-    void ProgramInit();
+    void ProgramInit(QString, QString);
 
 private slots:
     void startSlot();
@@ -30,15 +30,16 @@
     void disableSlot();
     void checkRunningFinishedSlot();
     void listSelectionChanged();
+    void checkRunning();
 
 private:
+    QString wDir, wIP;
     void setButtonsAllEnabled(bool enabled);
     QProcess *ServiceEnable;
     QProcess *ServiceDisable;
     QProcess *CheckServiceRunning;
     QProcess *CheckServiceEnabled;
     void populateList();
-    void checkRunning();
     void checkEnabled();
     QTreeWidgetItem *workingTreeWidgetItem;
     QTreeWidgetItemIterator *currentCheckRunningItem;

Modified: pcbsd/current/src-qt4/pc-servicemanager/servicemanager.ui
===================================================================
--- pcbsd/current/src-qt4/pc-servicemanager/servicemanager.ui	2012-06-14 15:49:13 UTC (rev 17280)
+++ pcbsd/current/src-qt4/pc-servicemanager/servicemanager.ui	2012-06-14 16:26:57 UTC (rev 17281)
@@ -6,8 +6,8 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>578</width>
-    <height>410</height>
+    <width>611</width>
+    <height>405</height>
    </rect>
   </property>
   <property name="windowTitle">
@@ -27,7 +27,7 @@
       <enum>QFrame::Plain</enum>
      </property>
      <property name="text">
-      <string>The following services are setup on this system. You may enable / disable them below.</string>
+      <string>The following services are available on this system</string>
      </property>
      <property name="wordWrap">
       <bool>true</bool>



More information about the Commits mailing list