Ignore:
Timestamp:
Aug 20, 2013 2:21:00 PM (8 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1
Children:
bf5b6c3
Parents:
0de3f5a
Message:

Add the ability to create an SSH Key file, and copy that key file to a msdosfs/FAT32 formatted USB stick (still needs testing)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src-qt4/life-preserver/mainUI.cpp

    r2a5e337 r96c5e841  
    1515  connect(brMenu,SIGNAL(triggered(QAction*)),this,SLOT(slotBrowseSnapshot(QAction*)) ); 
    1616  connect(addMenu, SIGNAL(triggered(QAction*)),this,SLOT(slotAddDataset(QAction*)) ); 
     17  //Setup the Key menu items (static items, never changed) 
     18  keyMenu = new QMenu(); 
     19    keyMenu->addAction(ui->actionKeyNew); //action from designer 
     20    keyMenu->addAction(ui->actionKeyCopy); //action from designer 
     21  ui->tool_keys->setMenu(keyMenu); 
     22  //Setup the update frequency limiter 
     23  freqTimer = new QTimer(); 
     24        freqTimer->setSingleShot(true); 
     25        freqTimer->setInterval(15000); 
     26        connect(freqTimer, SIGNAL(timeout()), this, SLOT(setupUI()) ); 
    1727} 
    1828 
     
    2232 
    2333void mainUI::setupUI(){ 
    24   qDebug() << "Setting up Life Preserver UI..."; 
    25   //Initialize the Hash 
    26   updateHash(); 
     34  //Initialize the Hash (make sure it is not run too frequently - causes kernel panics) 
     35  if(lastUpdate.isNull() || lastUpdate.addSecs(15) < QTime::currentTime() ){ 
     36    lastUpdate = QTime::currentTime();     
     37    qDebug() << "Updating the database"; 
     38    updateHash(); 
     39  }else{ 
     40    freqTimer->start(); 
     41  } 
    2742  //Update the display 
    28   updateUI(); 
    29   updateMenus(); 
    30 } 
    31  
    32 void mainUI::updateDisplay(){ 
    33   //Public function for the tray to be able to request that the UI update  
    34   // (In case there is a status message that goes by which changes things) 
    35   updateHash(); 
    3643  updateUI(); 
    3744  updateMenus(); 
     
    6572  } 
    6673  if(CLIST.isEmpty()){ ci = -1; } //catch for empty list 
    67    
    68   if(subsets.isEmpty()){ 
     74  if(DSC.subsetHash.size() < 1){ 
    6975    DSC.numberOfSnapshots = "0"; 
    7076    DSC.latestSnapshot= ""; 
     
    7379    DSC.numberOfSnapshots = QString::number(fSnap.length()); 
    7480    if(fSnap.isEmpty()){ DSC.latestSnapshot=""; } 
    75     else if(ci > -1){  
     81    else if(ci > -1 && ci < CLIST.length()){  
    7682      QString sna = CLIST[ci].section(":::",1,1); 
    7783      if(sna != "-"){ DSC.latestSnapshot= sna; } 
     
    95101// ================= 
    96102void mainUI::updateHash(QString ds){ 
     103  //qDebug() << "Get replication targets"; 
    97104  RLIST = LPBackend::listReplicationTargets(); //update list of replication datasets 
     105  //qDebug() << "Get possible datasets"; 
    98106  SLIST = LPBackend::listPossibleDatasets(); 
     107  //qDebug() << "List current status"; 
    99108  CLIST = LPBackend::listCurrentStatus(); 
     109  //qDebug() << "Check hash"; 
    100110  if(HLIST.contains(ds) && !ds.isEmpty()){ 
    101111    //only update the entry for the given dataset 
     
    103113  }else{ 
    104114    //Clear and fill the hash 
     115    //qDebug() << "Clear hash"; 
    105116    HLIST.clear(); 
     117    //qDebug() << "List datasets"; 
    106118    QStringList dsList = LPBackend::listDatasets(); 
    107119    for(int i=0; i<dsList.length(); i++){ 
     
    109121    } 
    110122  } 
    111  
     123  //qDebug() << "Done with Hash Update"; 
    112124} 
    113125 
     
    146158    ui->tool_remove->setVisible(false); 
    147159    ui->tool_config->setVisible(false); 
     160 
    148161  }else{ 
    149162    ui->tool_remove->setVisible(true); 
    150163    ui->tool_config->setVisible(true);     
     164  } 
     165  //Enabled/disable the SSH key management 
     166  if(RLIST.contains(ds) && !ds.isEmpty()){ 
     167    ui->tool_keys->setVisible(true); 
     168  }else{ 
     169    ui->tool_keys->setVisible(false); 
    151170  } 
    152171  //check for a valid ds/snapshot combination 
     
    225244  //Now update the UI if appropriate 
    226245  if(change){ 
    227     updateHash(ds); 
    228     updateUI(); 
    229     updateMenus(); 
     246    setupUI(); 
    230247  } 
    231248} 
     
    251268    } 
    252269  } 
    253   updateHash(); 
    254   updateUI(); 
    255   updateMenus(); 
     270  setupUI(); 
    256271} 
    257272 
     
    331346  } 
    332347  //Now update the UI/Hash 
    333   updateHash(); 
    334   updateUI(); 
    335   updateMenus(); 
     348  setupUI(); 
    336349} 
    337350 
     
    339352  this->close(); 
    340353} 
     354 
     355void mainUI::on_actionKeyNew_triggered(){ 
     356  QString ds = getSelectedDS(); 
     357  qDebug() << "New SSH Key triggered for DS:" << ds; 
     358  //Get the remote values for this dataset 
     359  QString remoteHost, user, remotedataset; 
     360  int port, time; 
     361  bool ok = LPBackend::replicationInfo(ds, remoteHost, user, port, remotedataset,  time); 
     362  if(ok){ 
     363    if( !LPBackend::setupSSHKey(remoteHost, user, port) ){ 
     364      QMessageBox::warning(this,tr("Failure"), tr("There was an error while creating the SSH key.")); 
     365    }else{ 
     366      QMessageBox::information(this,tr("Success"), tr("The SSH key was successfully generated.")); 
     367    } 
     368  }else{ 
     369    QMessageBox::warning(this,tr("Failure"), tr("There was an error in retrieving the remote replication information for this dataset. Please ensure that replication is enabled and try agin.") ); 
     370  } 
     371} 
     372 
     373void mainUI::on_actionKeyCopy_triggered(){ 
     374  QString ds = getSelectedDS();  
     375  qDebug() << "Copy SSH Key triggered for DS:" << ds; 
     376  //Get the local hostname 
     377  char host[1023] = "\0"; 
     378  gethostname(host,1023); 
     379  QString localHost = QString(host).simplified(); 
     380  qDebug() << " - hostname:" << localHost; 
     381  //Scan for mounted USB devices 
     382  QStringList devs = LPBackend::findValidUSBDevices(); 
     383  qDebug() << " - devs:" << devs; 
     384  if(devs.isEmpty()){ 
     385    QMessageBox::warning(this,tr("No Valid USB Devices"), tr("No valid USB devices could be found. Please mount a FAT32 formatted USB stick and try again.")); 
     386    return; 
     387  } 
     388  //Ask the user which one to save the file to 
     389  bool ok; 
     390  QString dev = QInputDialog::getItem(this, tr("Select USB Device"), tr("Available USB Devices:"), devs,0,false,&ok);    
     391  if(!ok or dev.isEmpty()){ return; } //cancelled 
     392  QString devPath = dev.section("(",0,0).simplified(); 
     393  //Now copy the file over 
     394  ok = LPBackend::copySSHKey(devPath, localHost); 
     395  if(ok){ 
     396    QMessageBox::information(this,tr("Success"), tr("The public SSH key file was successfully copied onto the USB device.")); 
     397  }else{ 
     398    QMessageBox::information(this,tr("Failure"), tr("The public SSH key file could not be copied onto the USB device.")); 
     399  } 
     400} 
     401 
    341402 
    342403// ============= 
Note: See TracChangeset for help on using the changeset viewer.