[PC-BSD Commits] r4681 - in pcbsd/trunk/lifePreserver: . scripts

svn at pcbsd.org svn at pcbsd.org
Mon Oct 19 13:30:49 PDT 2009


Author: kris
Date: 2009-10-19 13:30:49 -0700 (Mon, 19 Oct 2009)
New Revision: 4681

Added:
   pcbsd/trunk/lifePreserver/externals.h
Modified:
   pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
   pcbsd/trunk/lifePreserver/lifePreserverMain.h
   pcbsd/trunk/lifePreserver/lifePreserverMain.ui
   pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp
   pcbsd/trunk/lifePreserver/lifePreserverWizard.h
   pcbsd/trunk/lifePreserver/lifePreserverWizard.ui
   pcbsd/trunk/lifePreserver/scripts/setup-ssh-keys.sh
Log:

Updated lifePreserver, now its able to add / remove a host, and perform ssh key authorization during
the add phase. Now just need to get the actual backups working, plus add some restore functionality



Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.cpp	2009-10-19 20:30:49 UTC (rev 4681)
@@ -43,18 +43,77 @@
 { 
    qDebug("Application starting...");
    setWindowIcon(QIcon(QString::fromUtf8(":/images/images/lifepreserver.png")));
+   loadPreservers();
 
    connect(pushQuit, SIGNAL( clicked() ), this, SLOT(slotPushQuitClicked() ) );
    connect(pushNewPreserver, SIGNAL( clicked() ), this, SLOT(slotPushNewPreserverClicked() ) );
+   connect(pushRemovePreserver, SIGNAL( clicked() ), this, SLOT(slotPushRemovePreserverClicked() ) );
+   connect(pushEditPreserver, SIGNAL( clicked() ), this, SLOT(slotPushEditPreserverClicked() ) );
    treePreservers->resizeColumnToContents(0);
 }
 
+// Slot which checks which preserver is currently highlighted
+void lifePreserver::slotCurrentTreePreserverChanged(QTreeWidgetItem *curItem)
+{
+   QString host = curItem->text(0);
+   pushEditPreserver->setEnabled(true);
+   pushRemovePreserver->setEnabled(true);
+   pushPreserverStart->setEnabled(true);
+  
+}
+
+// Slot to remove a preserver host
+void lifePreserver::slotPushRemovePreserverClicked()
+{
+   if (treePreservers->currentColumn() == -1)
+   {
+      return;
+   }
+
+   QString removeHost = treePreservers->currentItem()->text(0);
+   QSettings settings("PCBSD");
+   QString savedPreservers[500];
+   int numExisting = 0;
+   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
+   int j = 0;
+   for (int i = 0; i < size; ++i)
+   {
+     settings.setArrayIndex(i);
+     if ( settings.value("connectString").toString() != removeHost) {
+       savedPreservers[j] = settings.value("connectString").toString();
+       j++;
+       numExisting = j;
+     }
+   }
+   settings.endArray();
+
+
+   settings.beginWriteArray("/lifePreserver/savedPreservers");
+   for ( int i = 0; i < numExisting; ++i)
+   {
+     settings.setArrayIndex(i);
+     settings.setValue("connectString", savedPreservers[i] );
+   }
+   settings.endArray();
+   settings.sync();
+
+   // Reload our list
+   loadPreservers();
+}
+
+// Slot to edit a preserver host
+void lifePreserver::slotPushEditPreserverClicked()
+{
+
+}
+
 // Slot to start the creation of a new life preserver
 void lifePreserver::slotPushNewPreserverClicked()
 {
-  lpw = new lifePreserverWizard();
-  lpw->widgetInit();
-  lpw->show();
+   lpw = new lifePreserverWizard();
+   lpw->widgetInit();
+   connect(lpw, SIGNAL( added() ), this, SLOT(loadPreservers() ) );
+   lpw->show();
 
 }
 
@@ -63,3 +122,49 @@
 {
    close();
 }
+
+void lifePreserver::loadPreservers()
+{
+   // Make sure we disconnect our notifier before clearing the list
+   disconnect(treePreservers, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem *) ), 0, 0 );
+   treePreservers->clear();
+
+   pushEditPreserver->setEnabled(false);
+   pushRemovePreserver->setEnabled(false);
+   pushPreserverStart->setEnabled(false);
+
+   QString tmp;
+   QSettings settings("PCBSD");
+   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
+   for (int i = 0; i < size; ++i)
+   {
+     settings.setArrayIndex(i);
+     QStringList itemTexts;
+     tmp = settings.value("connectString").toString();
+     itemTexts << tmp << getPreserverLastBackup(tmp) << getPreserverFrequency(tmp)  << getPreserverStatus(tmp);
+     QTreeWidgetItem *newitem = new QTreeWidgetItem(treePreservers, itemTexts);
+     //treePreservers->addTopLevelItem(newitem);
+     treePreservers->setCurrentItem(newitem);
+     slotCurrentTreePreserverChanged(newitem);
+   }
+   settings.endArray();
+
+   // Connect our slot to determine when the selected item has changed
+   connect(treePreservers, SIGNAL( currentItemChanged ( QTreeWidgetItem *, QTreeWidgetItem *) ), this, SLOT(slotCurrentTreePreserverChanged(QTreeWidgetItem *) ) );
+
+}
+
+QString lifePreserver::getPreserverLastBackup(QString host)
+{
+   return QString("Unknown");
+}
+
+QString lifePreserver::getPreserverFrequency(QString host)
+{
+   return QString("Not scheduled");
+}
+
+QString lifePreserver::getPreserverStatus(QString host)
+{
+   return QString("Not Running");
+}

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.h
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.h	2009-10-19 20:30:49 UTC (rev 4681)
@@ -32,9 +32,16 @@
 private slots:
    void slotPushQuitClicked();
    void slotPushNewPreserverClicked();
+   void slotPushRemovePreserverClicked();
+   void slotPushEditPreserverClicked();
+   void slotCurrentTreePreserverChanged(QTreeWidgetItem *curItem);
+   void loadPreservers();
 
 private:
    lifePreserverWizard *lpw;
+   QString getPreserverLastBackup(QString host);
+   QString getPreserverFrequency(QString host);
+   QString getPreserverStatus(QString host);
 
 signals:
 

Modified: pcbsd/trunk/lifePreserver/lifePreserverMain.ui
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverMain.ui	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/lifePreserverMain.ui	2009-10-19 20:30:49 UTC (rev 4681)
@@ -20,6 +20,12 @@
   <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
     <widget class="QTreeWidget" name="treePreservers">
+     <property name="showDropIndicator" stdset="0">
+      <bool>false</bool>
+     </property>
+     <property name="rootIsDecorated">
+      <bool>false</bool>
+     </property>
      <attribute name="headerDefaultSectionSize">
       <number>120</number>
      </attribute>
@@ -38,7 +44,7 @@
      </column>
      <column>
       <property name="text">
-       <string>Type</string>
+       <string>Frequency</string>
       </property>
      </column>
      <column>

Modified: pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/lifePreserverWizard.cpp	2009-10-19 20:30:49 UTC (rev 4681)
@@ -28,17 +28,21 @@
 #include <QSettings>
 #include <QDateTime>
 #include <QFileDialog>
+#include <QMessageBox>
+#include <QDebug>
+#include <QSettings>
 
 /* Local includes */
 #include "ui_lifePreserverWizard.h"
 #include "lifePreserverWizard.h"
+#include "externals.h"
 
 /* KDE */
 
 
 void lifePreserverWizard::widgetInit()
 { 
-   qDebug("Starting wizard...");
+   qDebug() << "Starting wizard...";
    setWindowModality ( Qt::WindowModal );
 
    // Connect our slots for complete status checking
@@ -54,6 +58,7 @@
 bool lifePreserverWizard::validatePage()
 {
 
+
   switch (currentId()) {
      case Page_Intro:
          button(QWizard::NextButton)->setEnabled(true);
@@ -109,6 +114,89 @@
    }
 }
 
+void lifePreserverWizard::accept()
+{
+  if ( ! doesPreserverExist() )
+  {
+    setEnabled(false);
+    QString program = "xterm";
+    QStringList arguments;
+    arguments << "-e" << LIFEPRESERVERPATH + "/scripts/setup-ssh-keys.sh " \
+    + lineUserName->text() + " " + lineHostName->text();
+
+    qDebug() << program << arguments;
+    QProcess *sshAuthProc = new QProcess(this);
+    connect(sshAuthProc,SIGNAL(finished( int, QProcess::ExitStatus)),this,SLOT(slotSSHProcFinished( int, QProcess::ExitStatus)));
+    sshAuthProc->start(program, arguments);
+  } else {
+    QMessageBox::critical ( this, tr("Duplicate Preserver"), tr("A preserver for this user + host already exists! Please select a different username / host when creating a new lifePreserver."), QMessageBox::Ok);
+  }
+
+}
+
+void lifePreserverWizard::slotSSHProcFinished ( int exitCode, QProcess::ExitStatus exitStatus )
+{
+  if ( exitCode == 0 && exitStatus != QProcess::CrashExit && !QFile::exists("/tmp/.failedPreserver-" + lineUserName->text()))
+  {
+    // Save the new Preserver Job
+    savePreserver(); 
+    emit added();
+    close();
+  } else {
+    if ( QFile::exists("/tmp/.failedPreserver-" + lineUserName->text()))
+    {
+       QFile::remove("/tmp/.failedPreserver-" + lineUserName->text());
+    }
+    QMessageBox::critical ( this, tr("Failed setting up SSH keys"), tr("Failed setting up the SSH keys for this server. Please click Back to check your settings and try again."), QMessageBox::Ok);
+    setEnabled(true);
+  }
+}
+
+
+// Function which saves the Preserver into the registry
+void lifePreserverWizard::savePreserver()
+{
+   QString connectString = lineUserName->text() + "@" + lineHostName->text();
+   QSettings settings("PCBSD");
+   QString savedPreservers[500];
+   int numExisting = 0;
+   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
+   for (int i = 0; i < size; ++i)
+   {
+     settings.setArrayIndex(i);
+     savedPreservers[i] = settings.value("connectString").toString();
+     numExisting = i;
+   }
+   settings.endArray();
+
+   settings.beginWriteArray("/lifePreserver/savedPreservers");
+   for ( int i = 0; i < numExisting; ++i)
+   {
+     settings.setArrayIndex(i);
+     settings.setValue("connectString", savedPreservers[i] );
+   }
+   settings.setArrayIndex(numExisting);
+   settings.setValue("connectString", connectString );
+   settings.endArray();
+
+}
+
+bool lifePreserverWizard::doesPreserverExist()
+{
+   QString tmp;
+   QString searchingName = lineUserName->text() + "@" + lineHostName->text();
+   QSettings settings("PCBSD");
+   int size = settings.beginReadArray("/lifePreserver/savedPreservers");
+   for (int i = 0; i < size; ++i)
+   {
+     settings.setArrayIndex(i);
+     if ( settings.value("connectString").toString() == searchingName ) 
+       return true;
+   }
+
+   return false;
+}
+
 int lifePreserverWizard::nextId() const
 {
    switch (currentId()) {

Modified: pcbsd/trunk/lifePreserver/lifePreserverWizard.h
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverWizard.h	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/lifePreserverWizard.h	2009-10-19 20:30:49 UTC (rev 4681)
@@ -28,13 +28,19 @@
 
 private slots:
    virtual int nextId() const;
+   virtual void accept();
    virtual void slotCheckComplete();
+   void slotSSHProcFinished ( int exitCode, QProcess::ExitStatus exitStatus );
 
 private:
+    void savePreserver();
+    bool doesPreserverExist();
     enum { Page_Intro, Page_RemoteDev, Page_Schedule, Page_Finished };
     bool validatePage();
+    QProcess *sshAuthProc;
 
 signals:
+    void added();
 } ;
 #endif // LIFEPW_H
 

Modified: pcbsd/trunk/lifePreserver/lifePreserverWizard.ui
===================================================================
--- pcbsd/trunk/lifePreserver/lifePreserverWizard.ui	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/lifePreserverWizard.ui	2009-10-19 20:30:49 UTC (rev 4681)
@@ -398,7 +398,7 @@
     <item row="0" column="0">
      <widget class="QLabel" name="label_3">
       <property name="text">
-       <string>You are now ready to setup the connection to your remote backup server. When you click finish, a window will popup to setup your secure backup connection. You will need to enter the password for the server.</string>
+       <string>You are now ready to setup the connection to your remote backup server. When you click finish, a window will popup, and you will need to enter the password for the server.</string>
       </property>
       <property name="wordWrap">
        <bool>true</bool>

Modified: pcbsd/trunk/lifePreserver/scripts/setup-ssh-keys.sh
===================================================================
--- pcbsd/trunk/lifePreserver/scripts/setup-ssh-keys.sh	2009-10-19 16:26:26 UTC (rev 4680)
+++ pcbsd/trunk/lifePreserver/scripts/setup-ssh-keys.sh	2009-10-19 20:30:49 UTC (rev 4681)
@@ -13,6 +13,9 @@
 
 cd ~
 
+echo "Preparing to setup SSH key authorization..."
+echo "When prompted, enter your password for ${SSHUSER}@${SSHHOST}"
+
 if [ ! -e ".ssh/id_rsa.pub" ]
 then
   ssh-keygen -q -t rsa -N '' -f .ssh/id_rsa
@@ -30,4 +33,7 @@
 
 ssh ${SSHUSER}@${SSHHOST} "mkdir .ssh ; echo $PUBKEY >> .ssh/authorized_keys; chmod 600 .ssh/authorized_keys ; echo $PUBKEY >> .ssh/authorized_keys2; chmod 600 .ssh/authorized_keys2"
 
-exit $? 
+if [ "$?" != "0" ]
+then
+  touch /tmp/.failedPreserver-${SSHUSER}
+fi



More information about the Commits mailing list