Ignore:
Timestamp:
08/20/13 14:21:00 (12 months ago)
Author:
Ken Moore <ken@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
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/LPBackend.cpp

    r2a5e337 r96c5e841  
    2020  } 
    2121  list.removeDuplicates(); 
     22    
    2223  return list;   
    2324} 
     
    3839    if(!ds.isEmpty()){ list << ds; } 
    3940  } 
     41    
    4042  return list; 
    4143} 
     
    6163  } 
    6264  list.removeDuplicates();       
     65    
    6366  return list; 
    6467} 
     
    9194    } 
    9295  } 
     96    
    9397  return list;   
    9498} 
     
    111115    } 
    112116  } 
     117    
    113118  return list;           
    114119} 
     
    127132  for(int i=2; i<out.length(); i++){ //first 2 lines are headers 
    128133    //Format: <dataset>:::<lastsnapshot | NONE>:::<lastreplication | NONE> 
     134    if(out[i].isEmpty()){ continue; } 
    129135    QString ds  = out[i].section(" - ",0,0).simplified(); 
    130136    QString snap = out[i].section(" - ",1,1).simplified(); 
     
    134140    list << ds +":::"+ snap+":::"+rep; 
    135141  } 
     142    
    136143  return list; 
    137144} 
     
    152159  QString cmd = "lpreserver cronsnap "+dataset+" start "+freq+" "+QString::number(numToKeep); 
    153160  int ret = system(cmd.toUtf8()); 
     161    
    154162  return (ret == 0); 
    155163} 
     
    158166  QString cmd = "lpreserver cronsnap "+dataset+" stop"; 
    159167  int ret = system(cmd.toUtf8());        
     168    
    160169  return (ret == 0); 
    161170} 
     
    188197  } 
    189198  //qDebug() << "lpreserver cronsnap:\n" << out << QString::number(time) << QString::number(numToKeep); 
     199    
    190200  return ok; 
    191201} 
     
    197207  QString cmd = "lpreserver mksnap "+dataset; 
    198208  int ret = system(cmd.toUtf8()); 
     209    
    199210  return (ret == 0); 
    200211} 
     
    203214  QString cmd = "lpreserver rmsnap "+dataset +" "+snapshot; 
    204215  int ret = system(cmd.toUtf8());        
     216    
    205217  return (ret == 0); 
    206218} 
     
    209221  QString cmd = "lpreserver revertsnap "+dataset +" "+snapshot; 
    210222  int ret  = system(cmd.toUtf8()); 
     223    
    211224  return (ret == 0); 
    212225} 
     
    268281  QString cmd = "lpreserver replicate add "+remotehost+" "+user+" "+ QString::number(port)+" "+dataset+" "+remotedataset+" "+stime; 
    269282  int ret = system(cmd.toUtf8()); 
     283   
    270284  return (ret == 0); 
    271285} 
     
    274288  QString cmd = "lpreserver replicate remove "+dataset; 
    275289  int ret = system(cmd.toUtf8());        
     290    
    276291  return (ret == 0); 
    277292} 
     
    302317    } 
    303318  }        
     319    
    304320  return ok; 
    305321} 
     322 
     323// ====================== 
     324//          SSH Key Management 
     325// ====================== 
     326bool LPBackend::setupSSHKey(QString remoteHost, QString remoteUser, int remotePort){ 
     327  QString LPPATH = "/usr/local/share/lifePreserver"; 
     328  QString cmd = "xterm -e \""+LPPATH+"/scripts/setup-ssh-keys.sh "+remoteUser+" "+remoteHost+" "+QString::number(remotePort)+"\""; 
     329  int ret = system(cmd.toUtf8()); 
     330  return (ret == 0); 
     331} 
     332 
     333QStringList LPBackend::findValidUSBDevices(){ 
     334  //Return format: "<mountpoint> (<device node>") 
     335  QString cmd = "mount"; 
     336  //Need output, so run this in a QProcess 
     337  QProcess *proc = new QProcess; 
     338  proc->setProcessChannelMode(QProcess::MergedChannels); 
     339  proc->start(cmd); 
     340  proc->waitForFinished(); 
     341  QStringList out = QString(proc->readAllStandardOutput()).split("\n");  
     342  delete proc; 
     343  //Now process the output 
     344  QStringList list; 
     345  for(int i=0; i<out.length(); i++){ 
     346    if(out[i].startsWith("/dev/da") && out[i].contains("(msdosfs,local)")){ 
     347      QString mountpoint = out[i].section(" on ",1,1).section("(",0,0).simplified(); 
     348      QString devnode = out[i].section(" on ",0,0).section("/",-1).simplified(); 
     349      list << mountpoint +" ("+devnode+")"; 
     350    } 
     351  } 
     352  return list; 
     353} 
     354 
     355bool LPBackend::copySSHKey(QString mountPath, QString localHost){ 
     356  QString publicKey = "/root/.ssh/id_rsa.pub"; 
     357  //copy the file onto the designated USB stick 
     358  if(!mountPath.endsWith("/")){ mountPath.append("/"); } 
     359  mountPath.append("root/.ssh/"+localHost+"-id_rsa.pub"); 
     360  bool ok = QFile::copy(publicKey, mountPath); 
     361  return ok; 
     362} 
Note: See TracChangeset for help on using the changeset viewer.