source: src-qt4/pc-installgui/wizardRestore.cpp @ 93572be

9.2-releasereleng/10.0releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 93572be was 93572be, checked in by Kris Moore <kris@…>, 13 months ago

Welcome the new Life-Preserver restore ability to the Installer GUI

Now you can restore your entire system from a replicated life-preserver backup on a
remote machine

  • Property mode set to 100644
File size: 7.3 KB
Line 
1/****************************************************************************
2** ui.h extension file, included from the uic-generated form implementation.
3**
4** If you want to add, delete, or rename functions or slots, use
5** Qt Designer to update this file, preserving your code.
6**
7** You should not define a constructor or destructor in this file.
8** Instead, write your code in functions called init() and destroy().
9** These will automatically be called by the form's constructor and
10** destructor.
11*****************************************************************************/
12#include "wizardRestore.h"
13#include "ui_wizardRestore.h"
14#include "backend.h"
15#include <QMessageBox>
16#include <QInputDialog>
17
18#define SCRIPTDIR QString("/usr/local/share/pcbsd/pc-installgui")
19
20void wizardRestore::programInit()
21{
22   connect(this,SIGNAL(currentIdChanged(int)),this,SLOT(slotCheckComplete()));
23   connect(lineHostName,SIGNAL(textChanged(const QString)),this,SLOT(slotCheckComplete()));
24   connect(lineUserName,SIGNAL(textChanged(const QString)),this,SLOT(slotCheckComplete()));
25   connect(spinPort,SIGNAL(valueChanged(int)),this,SLOT(slotCheckComplete()));
26}
27
28void wizardRestore::slotClose()
29{
30  close();
31}
32
33void wizardRestore::accept()
34{
35  QString targetSys;
36  targetSys = sysList.at(comboBoxRestoreSystem->currentIndex());
37
38  QStringList rset;
39  rset << lineHostName->text();
40  rset << lineUserName->text();
41  rset << QString::number(spinPort->value());
42  rset << authKey;
43  rset << targetSys;
44  emit saved(rset);
45  close();
46}
47
48// Logic checks to see if we are ready to move onto next page
49bool wizardRestore::validatePage()
50{
51  switch (currentId()) {
52     case Page_Intro:
53         button(QWizard::NextButton)->setEnabled(true);
54         return true;
55     case Page_Host:
56         if ( lineHostName->text().isEmpty() ) {
57           button(QWizard::NextButton)->setEnabled(false);
58           return false;
59         }
60         if ( lineUserName->text().isEmpty() ) {
61           button(QWizard::NextButton)->setEnabled(false);
62           return false;
63         }
64         // if we get this far, all the fields are filled in
65         button(QWizard::NextButton)->setEnabled(true);
66         return true;
67     case Page_Auth:
68         button(QWizard::NextButton)->setEnabled(true);
69         return true;
70     case Page_System:
71         if ( comboBoxRestoreSystem->currentText().isEmpty() ) {
72           button(QWizard::NextButton)->setEnabled(false);
73           return false;
74         }
75         button(QWizard::NextButton)->setEnabled(true);
76         return true;
77     case Page_Finish:
78         button(QWizard::FinishButton)->setEnabled(true);
79         return true;
80     default:
81         button(QWizard::NextButton)->setEnabled(true);
82         return true;
83  }
84
85  return true;
86}
87
88void wizardRestore::slotCheckComplete()
89{
90   // Validate this page
91   validatePage();
92}
93
94void wizardRestore::initializePage(int page)
95{
96  switch (page) {
97     case Page_System:
98       comboBoxRestoreSystem->clear();
99
100       // Lets start the auth process
101       if ( radioUSBAuth->isChecked() ) {
102          if ( ! getUSBAuth() ) {
103             QMessageBox::critical(this, tr("No keys found!"),
104                                tr("No Auth keys could be found on that memory stick!\n"
105                                   "Please try another USB stick or use password authentication."),
106                                QMessageBox::Ok,
107                                QMessageBox::Ok);       
108              return;
109          }
110       } else {
111          if ( ! startPWAuth() ) {
112             QMessageBox::critical(this, tr("Connection failed!"),
113                                tr("Could not connect to the backup server!\n"
114                                   "Please check that the server is reachable and verify your user/password."),
115                                QMessageBox::Ok,
116                                QMessageBox::Ok);       
117             button(QWizard::NextButton)->setEnabled(false);
118             return;
119          }
120        }
121
122        if ( ! getSysList() ) {
123           QMessageBox::critical(this, tr("Connection failed!"),
124                               tr("Could not connect to the backup server!\n"
125                                  "Please check your hostname and that the backup server is reachable."),
126                                QMessageBox::Ok,
127                                QMessageBox::Ok);       
128            button(QWizard::NextButton)->setEnabled(false);
129            return;
130        }
131
132       break;
133     case Page_Finish:
134       plainTextEditSummary->clear();
135       plainTextEditSummary->appendPlainText(tr("Will restore from:"));
136       plainTextEditSummary->appendPlainText("Host: " + lineHostName->text());
137       plainTextEditSummary->appendPlainText("User: " + lineUserName->text());
138       plainTextEditSummary->appendPlainText("Target System: " + comboBoxRestoreSystem->currentText());
139       break;
140   }
141}
142
143bool wizardRestore::getUSBAuth()
144{
145  QStringList keys, dispKeys;
146
147  QProcess p;
148  p.start(SCRIPTDIR + "/load-usb-key.sh", QStringList());
149  while(p.state() == QProcess::Starting || p.state() == QProcess::Running) {
150      p.waitForFinished(200);
151      QCoreApplication::processEvents();
152  }
153  while (p.canReadLine())
154      keys << p.readLine().simplified();
155
156  // Did we find any key files?
157  if ( keys.isEmpty() )
158     return false;
159
160  // Only a single key? Lets use that
161  if ( keys.size() == 1 ) {
162     authKey = keys.at(0);
163     return true;
164  }
165
166  // More than one? Lets ask the user which one they want to use
167  ////////////////////
168
169  // Lets start by showing only the file-names
170  for (int i = 0; i < keys.size(); ++i)
171     dispKeys << keys.at(i).section("/", -1);
172
173  bool ok;
174  QString item = QInputDialog::getItem(this, tr("Select the SSH key to use"),
175                                          tr("Key File:"), dispKeys, 0, false, &ok);
176
177  if ( !ok || item.isEmpty() )
178     return false;
179
180  for (int i = 0; i < keys.size(); ++i)
181     if ( item == keys.at(i).section("/", -1) )
182     {
183        authKey = keys.at(i);
184        return true;
185     }
186 
187
188  // We shouldn't get here
189  qDebug() << "Invalid end of getUSBAuth()";
190  return false;
191}
192
193bool wizardRestore::startPWAuth()
194{
195  QString cmd = "xterm -e \""+SCRIPTDIR+"/setup-ssh-keys.sh " + \
196                lineUserName->text() + \
197                " " + lineHostName->text() + \
198                " " +QString::number(spinPort->value()) + "\"";
199  system(cmd.toUtf8());
200 
201  if ( QFile::exists("/tmp/.ssh-auth-failed") )
202     return false;
203
204  // Looks like auth worked!
205  return true;
206}
207
208bool wizardRestore::getSysList()
209{
210  sysList.clear();
211  comboBoxRestoreSystem->clear();
212
213  qDebug() << lineUserName->text() << lineHostName->text() << authKey;
214
215  QStringList propList;
216  QProcess p;
217  p.start(SCRIPTDIR + "/get-zfs-restore-list.sh", QStringList() << lineUserName->text() << lineHostName->text() << QString::number(spinPort->value()) << authKey );
218  while(p.state() == QProcess::Starting || p.state() == QProcess::Running) {
219      p.waitForFinished(200);
220      QCoreApplication::processEvents();
221  }
222  while (p.canReadLine())
223      propList << p.readLine().simplified();
224
225  if ( p.exitStatus() == QProcess::CrashExit || p.exitCode() != 0 )
226     return false;
227
228  // Lets start by showing only the systemNames
229  for (int i = 0; i < propList.size(); ++i) {
230     if ( ! propList.at(i).startsWith(".lp-props-" ) )
231        continue;
232     comboBoxRestoreSystem->addItem(propList.at(i).section("#", -1));
233     sysList << propList.at(i);
234  }
235
236  return true;
237}
238
Note: See TracBrowser for help on using the repository browser.