Permalink
Browse files

Add the ability to scan the network for hosts with SSH availability (…

…port 22) to the Configuration UI. If it works, I will add the same thing to the LPWizard.
  • Loading branch information...
Ken Moore
Ken Moore committed Oct 23, 2013
1 parent b62e8c4 commit b22b3a551cf9bd6365f870db2f0c7a1907a72a78
@@ -12,6 +12,7 @@ LPConfig::LPConfig(QWidget *parent) : QDialog(parent), ui(new Ui::LPConfig){
//now connect the buttons
connect(ui->tool_apply,SIGNAL(clicked()), this,SLOT(slotApplyChanges()) );
connect(ui->tool_cancel,SIGNAL(clicked()), this, SLOT(slotCancelConfig()) );
+ connect(ui->push_scanNetwork, SIGNAL(clicked()), this, SLOT(autoDetectReplicationTargets()) );
}
LPConfig::~LPConfig(){
@@ -169,3 +170,27 @@ void LPConfig::on_combo_local_schedule_currentIndexChanged(int index){
//Adjust whether the daily time box is visible
ui->time_local_daily->setVisible( (index == 0) );
}
+
+void LPConfig::autoDetectReplicationTargets(){
+ QStringList targs = LPGUtils::scanNetworkSSH(); // <name>:::<address>:::<port>
+ if(targs.isEmpty()){
+ QMessageBox::warning(this,tr("No Network Targets"), tr("We could not find any systems on the local network with SSH availability (port 22)") );
+ return;
+ }
+ //Ask the user to select a target
+ QStringList targets;
+ for(int i=0; i<targs.length(); i++){
+ targets << targs[i].section(":::",0,0);
+ }
+ bool ok;
+ QString target = QInputDialog::getItem(this, tr("Select Replication Target"), tr("Hostname:"), targets, 0, false, &ok);
+ if(!ok || target.isEmpty() ){ return; } //cancelled
+ //Now look for that target in the list of info
+ for(int i=0; i<targs.length(); i++){
+ if(targs[i].startsWith(target+":::")){
+ ui->lineHostName->setText(targs[i].section(":::",1,1));
+ ui->spinPort->setValue( targs[i].section(":::",2,2).toInt() );
+ break;
+ }
+ }
+}
@@ -4,8 +4,11 @@
#include <QDialog>
#include <QString>
#include <QDebug>
+#include <QMessageBox>
+#include <QInputDialog>
#include "LPBackend.h"
+#include "LPGUtils.h"
namespace Ui{
class LPConfig;
@@ -34,6 +37,7 @@ private slots:
void slotApplyChanges();
void slotCancelConfig();
void on_combo_local_schedule_currentIndexChanged(int);
+ void autoDetectReplicationTargets();
};
#endif
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>374</width>
- <height>327</height>
+ <width>372</width>
+ <height>353</height>
</rect>
</property>
<property name="windowTitle">
@@ -41,7 +41,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
- <number>0</number>
+ <number>1</number>
</property>
<widget class="QWidget" name="tab_local">
<attribute name="title">
@@ -175,6 +175,47 @@
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_9">
+ <item>
+ <spacer name="horizontalSpacer_5">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QPushButton" name="push_scanNetwork">
+ <property name="text">
+ <string>Scan Network</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/network-wired.png</normaloff>:/images/network-wired.png</iconset>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_4">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ </layout>
+ </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
@@ -252,3 +252,27 @@ QStringList LPGUtils::listAvailableHardDisks(){
devs.removeDuplicates();
return devs;
}
+
+QStringList LPGUtils::scanNetworkSSH(){
+ //Output format: <name>:::<address>::::<port>
+ QStringList out;
+ QStringList netout = LPBackend::getCmdOutput("avahi-browse -art");
+ for(int i=0; i<netout.length(); i++){
+ if(netout[i].startsWith("=") && netout[i].contains("local")){
+ QString name, address, port;
+ for(int j=0; j<3; j++){ //need the next 3 lines
+ i++; //Move to the next line
+ QString var = netout[i].section("=",0,0).replace("\t"," ").simplified();
+ QString val = netout[i].section("[",1,1).section("]",0,0).simplified();
+ if(var == "hostname"){ name = val.section(".local",0,0).simplified(); }
+ else if(var == "address"){ address = val; }
+ else if(var == "port"){ port = val; }
+ }
+ //Check that it is an SSH connection that is open (port 22)
+ if(port == "22"){
+ out << name+":::"+address+":::"+port;
+ }
+ }
+ }
+ return out;
+}
@@ -23,6 +23,8 @@ class LPGUtils{
static bool extractHomeDirPackage(QString packagePath);
//Function to scan the system for available harddisks/devices
static QStringList listAvailableHardDisks();
+ //Function to scan the network for available replication targets (SSH open)
+ static QStringList scanNetworkSSH();
};
#endif

0 comments on commit b22b3a5

Please sign in to comment.