mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-19 17:57:22 +01:00
see #2477 removed transfer agent classes and functions
This commit is contained in:
parent
db233ee8e8
commit
f5e22c040b
@ -1,5 +1,8 @@
|
||||
2011-06-20 Vadim Kurland <vadim@netcitadel.com>
|
||||
|
||||
* src.pro (SUBDIRS): see #2477 removed transfer agent
|
||||
code.
|
||||
|
||||
* gui.pro: see #2506 Removed obsolete localization files (Russian
|
||||
and Japanese). These were incomplete and have never been updated for
|
||||
v4.
|
||||
|
||||
@ -1,393 +0,0 @@
|
||||
/*
|
||||
* TransferDevice.cpp - fwtransfer library implementation
|
||||
*
|
||||
* Copyright (c) 2008 secunet Security Networks AG
|
||||
* Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch>
|
||||
* Copyright (c) 2008 Reto Buerki <buerki@swiss-it.ch>
|
||||
*
|
||||
* This work is dual-licensed under:
|
||||
*
|
||||
* o The terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* o The terms of NetCitadel End User License Agreement
|
||||
*/
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#include <sys/types.h>
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <QDebug>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
|
||||
#include "TransferDevice.h"
|
||||
|
||||
using namespace fwtransfer;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
#ifdef HAVE_QTDBUS
|
||||
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QtDBus/QDBusConnection>
|
||||
|
||||
QVariant getProperty(QDBusInterface &interface, QString prop)
|
||||
throw(FWException)
|
||||
{
|
||||
QDBusMessage msg = interface.call("GetProperty", prop);
|
||||
if (msg.type() == QDBusMessage::ErrorMessage)
|
||||
{
|
||||
throw FWException(interface.path().toStdString() +
|
||||
": could not get property => " + prop.toStdString());
|
||||
}
|
||||
QVariant ret = msg.arguments()[0];
|
||||
return ret;
|
||||
}
|
||||
|
||||
QString TransferDevice::getVolumeSizeStr() const
|
||||
{
|
||||
// get size in bytes
|
||||
qlonglong size = getVolumeSize();
|
||||
QString size_str;
|
||||
QString unit = "KB";
|
||||
QVariant size_v;
|
||||
|
||||
if (size != 0)
|
||||
{
|
||||
// smallest unit is kb
|
||||
size = size / 1024;
|
||||
size_v = size;
|
||||
if (size > 1024)
|
||||
{
|
||||
size = size / 1024;
|
||||
size_v = size;
|
||||
unit = "MB";
|
||||
}
|
||||
if (size > 1024)
|
||||
{
|
||||
float f_size = float(size) / 1024;
|
||||
size_v = floor(f_size * 100.0 + 0.5) / 100;
|
||||
unit = "GB";
|
||||
}
|
||||
size_str = size_v.toString() + " " + unit;
|
||||
}
|
||||
else
|
||||
{
|
||||
size_str = "0";
|
||||
}
|
||||
return size_str;
|
||||
}
|
||||
|
||||
void TransferDevice::dump() const
|
||||
{
|
||||
// header
|
||||
qDebug() << "( dump of transfer device " << getDeviceName() << " )";
|
||||
|
||||
// actual dump
|
||||
QString mounted = is_mounted ? "yes" : "no";
|
||||
QString removable = is_removable ? "yes" : "no";
|
||||
QString hotpluggable = is_hotpluggable ? "yes" : "no";
|
||||
|
||||
qDebug() << "volume UDI\t:\t" + getVolumeUDI();
|
||||
qDebug() << "fstype\t\t:\t" + getVolumeFS();
|
||||
qDebug() << "size (MB)\t:\t" + getVolumeSizeStr();
|
||||
qDebug() << "device UDI\t:\t" + getDeviceUDI();
|
||||
qDebug() << "device\t\t:\t" + getDeviceName();
|
||||
qDebug() << "bus\t\t:\t" + getDeviceBus();
|
||||
qDebug() << "type\t\t:\t" + getDeviceType();
|
||||
qDebug() << "mountpoint\t:\t" + getMountpoint();
|
||||
qDebug() << "mounted\t:\t" + mounted;
|
||||
qDebug() << "removable\t:\t" + removable;
|
||||
qDebug() << "hotpluggable\t:\t" + hotpluggable;
|
||||
qDebug();
|
||||
}
|
||||
|
||||
void TransferDevice::mount() throw(FWException)
|
||||
{
|
||||
// ignore request if already mounted
|
||||
if (is_mounted)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection conn = QDBusConnection::systemBus();
|
||||
|
||||
QDBusInterface mountiface("org.freedesktop.Hal", getVolumeUDI(),
|
||||
"org.freedesktop.Hal.Device.Volume", conn);
|
||||
|
||||
QStringList options;
|
||||
|
||||
#ifndef WIN32
|
||||
// special mount options for vfat filesystems
|
||||
if (getVolumeFS() == "vfat")
|
||||
{
|
||||
QVariant user_v = getuid();
|
||||
QString user = "uid=" + user_v.toString();
|
||||
|
||||
options << "quiet" << "shortname=mixed" << user << "umask=077";
|
||||
}
|
||||
#endif
|
||||
|
||||
// send mount DBus message
|
||||
QDBusMessage replyMsg = mountiface.call("Mount", "", "", options);
|
||||
if (replyMsg.type() == QDBusMessage::ErrorMessage)
|
||||
{
|
||||
qDebug() << "Could not mount : " <<
|
||||
replyMsg.errorMessage() << ", " <<
|
||||
replyMsg.errorName();
|
||||
throw FWException(replyMsg.errorName().toStdString() + " : " +
|
||||
replyMsg.errorMessage().toStdString());
|
||||
}
|
||||
else
|
||||
{
|
||||
// re-read mountpoint
|
||||
QDBusInterface volumeiface("org.freedesktop.Hal", getVolumeUDI(),
|
||||
"org.freedesktop.Hal.Device", conn);
|
||||
setMountpoint(getProperty(volumeiface, "volume.mount_point").toString());
|
||||
}
|
||||
}
|
||||
|
||||
void TransferDeviceList::init() throw(FWException)
|
||||
{
|
||||
if (!checkDBus())
|
||||
{
|
||||
throw FWException("Cannot connect to the D-BUS system bus.");
|
||||
}
|
||||
|
||||
QDBusInterface hal("org.freedesktop.Hal",
|
||||
"/org/freedesktop/Hal/Manager",
|
||||
"org.freedesktop.Hal.Manager",
|
||||
QDBusConnection::systemBus());
|
||||
|
||||
// clear 'old' devices
|
||||
clear();
|
||||
|
||||
// get all volumes from HAL
|
||||
QDBusMessage msg = hal.call("FindDeviceByCapability", "volume");
|
||||
|
||||
QList<QVariant> volumes = msg.arguments();
|
||||
|
||||
foreach (QVariant name, volumes)
|
||||
{
|
||||
QStringList volume_list = name.toStringList();
|
||||
foreach (QString vol, volume_list)
|
||||
{
|
||||
addNewVolume(vol);
|
||||
}
|
||||
}
|
||||
|
||||
bool success;
|
||||
// connect HAL signals to our observer slots
|
||||
success = hal.connection().connect("org.freedesktop.Hal",
|
||||
"/org/freedesktop/Hal/Manager",
|
||||
"org.freedesktop.Hal.Manager",
|
||||
"DeviceAdded", this,
|
||||
SLOT(newDeviceDetected(const QString &)));
|
||||
|
||||
if (!success)
|
||||
{
|
||||
throw FWException("Cannot subscribe to HAL 'DeviceAdded' signal.");
|
||||
}
|
||||
|
||||
success = hal.connection().connect("org.freedesktop.Hal",
|
||||
"/org/freedesktop/Hal/Manager",
|
||||
"org.freedesktop.Hal.Manager",
|
||||
"DeviceRemoved", this,
|
||||
SLOT(deviceRemovedDetected(const QString &)));
|
||||
|
||||
if (!success)
|
||||
{
|
||||
throw FWException("Cannot subscribe to HAL 'DeviceRemoved' signal.");
|
||||
}
|
||||
}
|
||||
|
||||
void TransferDeviceList::dump() const
|
||||
{
|
||||
TransferDeviceList::const_iterator it;
|
||||
for (it = this->begin(); it != this->end(); it++)
|
||||
{
|
||||
(*it).dump();
|
||||
}
|
||||
}
|
||||
|
||||
bool TransferDeviceList::checkDBus() const
|
||||
{
|
||||
if (!QDBusConnection::systemBus().isConnected())
|
||||
{
|
||||
fprintf(stderr, "Cannot connect to the D-BUS system bus.\n");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransferDeviceList::addNewVolume(const QString &udi)
|
||||
{
|
||||
QDBusConnection conn = QDBusConnection::systemBus();
|
||||
QDBusInterface volume("org.freedesktop.Hal", udi,
|
||||
"org.freedesktop.Hal.Device", conn);
|
||||
|
||||
// only consider volumes for addition
|
||||
QVariant is_volume;
|
||||
try
|
||||
{
|
||||
// getProperty throws an exception if property is not there
|
||||
is_volume = getProperty(volume, "block.is_volume");
|
||||
}
|
||||
catch (FWException &ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// property is there, but still it is not a volume
|
||||
if (!is_volume.toBool())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// read in new volume/device
|
||||
TransferDevice new_device;
|
||||
new_device.setVolumeUDI(udi);
|
||||
|
||||
|
||||
// get physical device UDI and path for volume
|
||||
new_device.setDeviceUDI(getProperty(volume,
|
||||
"block.storage_device").toString());
|
||||
new_device.setDeviceName(getProperty(volume,
|
||||
"block.device").toString());
|
||||
|
||||
// check if its already mounted
|
||||
new_device.setMounted(getProperty(volume,
|
||||
"volume.is_mounted").toBool());
|
||||
// if mounted, read mountpoint
|
||||
if (new_device.isMounted())
|
||||
{
|
||||
new_device.setMountpoint(getProperty(volume,
|
||||
"volume.mount_point").toString());
|
||||
}
|
||||
|
||||
// volume filesystem type
|
||||
new_device.setVolumeFS(getProperty(volume,
|
||||
"volume.fstype").toString());
|
||||
|
||||
// volume size
|
||||
new_device.setVolumeSize(getProperty(volume,
|
||||
"volume.size").toLongLong());
|
||||
|
||||
// get properties for storage device
|
||||
QDBusInterface device("org.freedesktop.Hal",
|
||||
new_device.getDeviceUDI(),
|
||||
"org.freedesktop.Hal.Device", conn);
|
||||
|
||||
new_device.setDeviceBus(getProperty(device,
|
||||
"storage.bus").toString());
|
||||
new_device.setRemovable(getProperty(device,
|
||||
"storage.removable").toBool());
|
||||
new_device.setDeviceType(getProperty(device,
|
||||
"storage.drive_type").toString());
|
||||
new_device.setHotpluggable(getProperty(device,
|
||||
"storage.hotpluggable").toBool());
|
||||
|
||||
// only store portable usb based volumes
|
||||
if (new_device.isHotpluggable() &&
|
||||
new_device.isRemovable() &&
|
||||
new_device.getDeviceBus() == "usb" &&
|
||||
new_device.getDeviceType() == "disk")
|
||||
{
|
||||
push_back(new_device);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TransferDeviceList::removeVolume(const QString &udi)
|
||||
{
|
||||
TransferDeviceList::iterator it;
|
||||
PredFindVolumeUDI pred;
|
||||
pred.setSearchString(udi);
|
||||
it = find_if(begin(), end(), pred);
|
||||
|
||||
// not found
|
||||
if (it == end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// remove volume
|
||||
erase(it);
|
||||
return true;
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator
|
||||
TransferDeviceList::getDeviceByName(const QString &name) const
|
||||
{
|
||||
TransferDeviceList::const_iterator it;
|
||||
PredFindName pred;
|
||||
pred.setSearchString(name);
|
||||
it = find_if(begin(), end(), pred);
|
||||
return it;
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator
|
||||
TransferDeviceList::getDeviceByName(const std::string &name) const
|
||||
{
|
||||
return getDeviceByName(QString(name.c_str()));
|
||||
}
|
||||
|
||||
void TransferDeviceList::newDeviceDetected(const QString &udi)
|
||||
{
|
||||
// add this volume/device to the list
|
||||
if (addNewVolume(udi))
|
||||
{
|
||||
// qDebug() << "TransferDeviceList : DeviceAdded : " << udi;
|
||||
emit devicesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void TransferDeviceList::deviceRemovedDetected(const QString &udi)
|
||||
{
|
||||
if (removeVolume(udi))
|
||||
{
|
||||
// qDebug() << "TransferDeviceList : DeviceRemoved : " << udi;
|
||||
emit devicesChanged();
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#ifndef _WIN32
|
||||
#warning "QT D-BUS support not available!"
|
||||
#endif
|
||||
|
||||
QString TransferDevice::getVolumeSizeStr() const { return ""; }
|
||||
|
||||
void TransferDevice::dump() const {}
|
||||
|
||||
void TransferDevice::mount() throw(FWException)
|
||||
{
|
||||
throw FWException("Cannot connect to the D-BUS system bus.");
|
||||
}
|
||||
|
||||
void TransferDeviceList::init() throw(FWException)
|
||||
{
|
||||
throw FWException("Cannot connect to the D-BUS system bus.");
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator
|
||||
TransferDeviceList::getDeviceByName(const QString&) const
|
||||
{
|
||||
return end();
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator
|
||||
TransferDeviceList::getDeviceByName(const std::string&) const
|
||||
{
|
||||
return end();
|
||||
}
|
||||
|
||||
void TransferDeviceList::dump() const
|
||||
{}
|
||||
|
||||
#endif
|
||||
@ -1,395 +0,0 @@
|
||||
/*
|
||||
* TransferDevice.cpp - QDBus based config transfer library
|
||||
*
|
||||
* Copyright (c) 2008 secunet Security Networks AG
|
||||
* Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch>
|
||||
* Copyright (c) 2008 Reto Buerki <buerki@swiss-it.ch>
|
||||
*
|
||||
* This work is dual-licensed under:
|
||||
*
|
||||
* o The terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* o The terms of NetCitadel End User License Agreement
|
||||
*/
|
||||
|
||||
#ifndef __TRANSFER_DEVICE_HH__
|
||||
#define __TRANSFER_DEVICE_HH__
|
||||
|
||||
#include <string>
|
||||
#include <QString>
|
||||
#include <QObject>
|
||||
|
||||
#include "../../config.h"
|
||||
#include "fwbuilder/FWException.h"
|
||||
|
||||
namespace fwtransfer
|
||||
{
|
||||
|
||||
class DeviceObserver;
|
||||
|
||||
/**
|
||||
* @class TransferDevice
|
||||
*
|
||||
* @brief This class represents a device for firewall config transfer.
|
||||
*
|
||||
* The TransferDevice class can be used to store information about transfer
|
||||
* volumes/devices. TransferDevices provide different setter/getter functions
|
||||
* to set/get information about devices and volumes. TransferDevice objects
|
||||
* provides a dump() function to dump the currently stored info and also a
|
||||
* mount() function to actually mount the volume.
|
||||
*/
|
||||
class TransferDevice
|
||||
{
|
||||
public:
|
||||
TransferDevice() :
|
||||
volume_udi(QString()),
|
||||
volume_fs(QString()),
|
||||
volume_size(0),
|
||||
device_udi(QString()),
|
||||
device_name(QString()),
|
||||
device_bus(QString()),
|
||||
device_type(QString()),
|
||||
mountpoint(QString()),
|
||||
is_mounted(false),
|
||||
is_removable(false),
|
||||
is_hotpluggable(false) {};
|
||||
|
||||
/**
|
||||
* set volume UDI for transfer device.
|
||||
*
|
||||
* @param udi volume UDI
|
||||
*/
|
||||
void setVolumeUDI(QString udi) { volume_udi = udi; };
|
||||
|
||||
/**
|
||||
* get volume UDI for transfer device.
|
||||
*
|
||||
* @return volume UDI
|
||||
*/
|
||||
QString getVolumeUDI() const { return volume_udi; };
|
||||
|
||||
/**
|
||||
* set filesystem type for transfer device (e.g. "ext3").
|
||||
*
|
||||
* @param fs filesystem type
|
||||
*/
|
||||
void setVolumeFS(QString fs) { volume_fs = fs; };
|
||||
|
||||
/**
|
||||
* get filesystem type of transfer device.
|
||||
*
|
||||
* @return filesystem type
|
||||
*/
|
||||
QString getVolumeFS() const { return volume_fs; };
|
||||
|
||||
/**
|
||||
* set volume size for transfer device.
|
||||
*
|
||||
* @param fs filesystem type
|
||||
*/
|
||||
void setVolumeSize(qlonglong size) { volume_size = size; };
|
||||
|
||||
/**
|
||||
* get volume size for volume of transfer device as qlonglong.
|
||||
*
|
||||
* @return filesystem size in bytes
|
||||
*/
|
||||
qlonglong getVolumeSize() const { return volume_size; };
|
||||
|
||||
/**
|
||||
* get volume size for volume of transfer device as QString.
|
||||
*
|
||||
* @return filesystem size in human readable string format
|
||||
*/
|
||||
QString getVolumeSizeStr() const;
|
||||
|
||||
/**
|
||||
* set device UDI for transfer device.
|
||||
*
|
||||
* @param udi device UDI
|
||||
*/
|
||||
void setDeviceUDI(QString udi) { device_udi = udi; };
|
||||
|
||||
/**
|
||||
* get device UDI for transfer device.
|
||||
*
|
||||
* @return device UDI
|
||||
*/
|
||||
QString getDeviceUDI() const { return device_udi; };
|
||||
|
||||
/**
|
||||
* set device name for transfer device (e.g. /dev/sdc1).
|
||||
*
|
||||
* @param name device name
|
||||
*/
|
||||
void setDeviceName(QString name) { device_name = name; };
|
||||
|
||||
/**
|
||||
* get device name of transfer device.
|
||||
*
|
||||
* @return device name
|
||||
*/
|
||||
QString getDeviceName() const { return device_name; };
|
||||
|
||||
/**
|
||||
* set bus type used by transfer device (e.g. "usb").
|
||||
*
|
||||
* @param bus type of bus device is attached to (pci, usb, ...)
|
||||
*/
|
||||
void setDeviceBus(QString bus) { device_bus = bus; };
|
||||
|
||||
/**
|
||||
* get bus type of transfer device.
|
||||
*
|
||||
* @return bus type
|
||||
*/
|
||||
QString getDeviceBus() const { return device_bus; };
|
||||
|
||||
/**
|
||||
* set transfer device type (e.g. "disk").
|
||||
*
|
||||
* @param type transfer device storage type
|
||||
*/
|
||||
void setDeviceType(QString type) { device_type = type; };
|
||||
|
||||
/**
|
||||
* get storage type of this transfer device.
|
||||
*
|
||||
* @return storage device type
|
||||
*/
|
||||
QString getDeviceType() const { return device_type; };
|
||||
|
||||
/**
|
||||
* set mount point for transfer device (e.g. "/media/disk").
|
||||
*
|
||||
* @param path mount point of transfer device
|
||||
*/
|
||||
void setMountpoint(QString path) { mountpoint = path; };
|
||||
|
||||
/**
|
||||
* get mount point path of transfer device.
|
||||
*
|
||||
* @return mount point path
|
||||
*/
|
||||
QString getMountpoint() const { return mountpoint; };
|
||||
|
||||
/**
|
||||
* set mounted flag to true or false depending on whether transfer
|
||||
* device volume is mounted or not.
|
||||
*
|
||||
* @param flag mounted status of volume
|
||||
*/
|
||||
void setMounted(bool flag) { is_mounted = flag; };
|
||||
|
||||
/**
|
||||
* determines whether transfer device volume is already mounted or not.
|
||||
*
|
||||
* @return true if mounted, false if not
|
||||
*/
|
||||
bool isMounted() const { return is_mounted; };
|
||||
|
||||
/**
|
||||
* set removable flag to true or false depending on whether device can
|
||||
* be removed or not.
|
||||
*
|
||||
* @param flag removable status flag of device
|
||||
*/
|
||||
void setRemovable(bool flag) { is_removable = flag; };
|
||||
|
||||
/**
|
||||
* determines whether device can be removed or not.
|
||||
*
|
||||
* @return true if portable, false if not
|
||||
*/
|
||||
bool isRemovable() const { return is_removable; };
|
||||
|
||||
/**
|
||||
* set hotpluggable flag to true or false depending on whether device is
|
||||
* hotpluggable.
|
||||
*
|
||||
* @param flag hotpluggable status flag of device
|
||||
*/
|
||||
void setHotpluggable(bool flag) { is_hotpluggable = flag; };
|
||||
|
||||
/**
|
||||
* determines whether device is hotpluggable.
|
||||
*
|
||||
* @return true if yes, false if not
|
||||
*/
|
||||
bool isHotpluggable() const { return is_hotpluggable; };
|
||||
|
||||
/**
|
||||
* debug function to dump transfer device settings.
|
||||
*/
|
||||
void dump() const;
|
||||
|
||||
/**
|
||||
* mount transfer device
|
||||
*
|
||||
* @throw libfwbuilder::FWException could not mount exception
|
||||
*/
|
||||
void mount() throw(libfwbuilder::FWException);
|
||||
|
||||
private:
|
||||
QString volume_udi;
|
||||
QString volume_fs;
|
||||
qlonglong volume_size;
|
||||
QString device_udi;
|
||||
QString device_name;
|
||||
QString device_bus;
|
||||
QString device_type;
|
||||
QString mountpoint;
|
||||
bool is_mounted;
|
||||
bool is_removable;
|
||||
bool is_hotpluggable;
|
||||
};
|
||||
|
||||
/**
|
||||
* @class TransferDeviceList
|
||||
*
|
||||
* @brief An TransferDeviceList is used to manage transfer devices of a system.
|
||||
*
|
||||
* An TransferDeviceList stores all available transfer volumes. It also
|
||||
* provides a devicesChanged signal which can be used to track list changes.
|
||||
* This signal is emitted when HAL detects a new device (DeviceAdded) or
|
||||
* a device has vanished (DeviceRemoved). Users of an TransferDeviceList
|
||||
* object can connect a slot to this signal to react to this event.
|
||||
*/
|
||||
class TransferDeviceList : public QObject, public std::list<TransferDevice>
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
/** TransferDeviceList ctor */
|
||||
TransferDeviceList(QObject * parent = 0) : QObject(parent) {};
|
||||
|
||||
/** TransferDeviceList dtor */
|
||||
virtual ~TransferDeviceList() {};
|
||||
|
||||
/**
|
||||
* init list of volumes/devices. only usb based, portable volumes
|
||||
* are added to the list. Previously added transfer devices will be
|
||||
* cleared from the list before adding new ones.
|
||||
*
|
||||
* @throw libfwbuilder::FWException DBus not available exception
|
||||
*/
|
||||
void init() throw(libfwbuilder::FWException);
|
||||
|
||||
/**
|
||||
* return specific TransferDevice identified by volume name.
|
||||
*
|
||||
* @param volumeid id of volume as QString (e.g. /dev/sdc1)
|
||||
* @return iterator pointing to requested TransferDevice
|
||||
*
|
||||
*/
|
||||
TransferDeviceList::const_iterator
|
||||
getDeviceByName(const QString &name) const;
|
||||
|
||||
/**
|
||||
* return specific TransferDevice identified by volume name.
|
||||
*
|
||||
* @param volumeid id of volume as string (e.g. /dev/sdc1)
|
||||
* @return iterator pointing to requested TransferDevice
|
||||
*
|
||||
*/
|
||||
TransferDeviceList::const_iterator
|
||||
getDeviceByName(const std::string &name) const;
|
||||
|
||||
/**
|
||||
* dump data of all managed transfer devices.
|
||||
*/
|
||||
void dump() const;
|
||||
|
||||
private:
|
||||
|
||||
#ifdef HAVE_QTDBUS
|
||||
/**
|
||||
* check DBus availability.
|
||||
*/
|
||||
bool checkDBus() const;
|
||||
|
||||
/**
|
||||
* add a new transfer volume with given volume UDI.
|
||||
*
|
||||
* @param udi UDI of the volume to add.
|
||||
* @return true if successfully added, false if not
|
||||
*/
|
||||
bool addNewVolume(const QString &udi);
|
||||
|
||||
/**
|
||||
* remove an existing volume identified by UDI from the list.
|
||||
*
|
||||
* @param udi UDI of the volume to add.
|
||||
* @return true if successfully removed, false if not found
|
||||
*/
|
||||
bool removeVolume(const QString &udi);
|
||||
|
||||
private slots:
|
||||
void newDeviceDetected(const QString &udi);
|
||||
void deviceRemovedDetected(const QString &udi);
|
||||
|
||||
signals:
|
||||
void devicesChanged();
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
/**
|
||||
* @class PredFindName
|
||||
*
|
||||
* @brief Predicate class to find device name in TransferDevice.
|
||||
*
|
||||
* PredFindName can be used e.g. as parameter in find_if() function to
|
||||
* compare TransferDevices in TransferDeviceList with a given device name
|
||||
* specified by setSearchString().
|
||||
*/
|
||||
class PredFindName
|
||||
{
|
||||
protected:
|
||||
QString search_string;
|
||||
public:
|
||||
PredFindName() {};
|
||||
|
||||
bool operator()(const TransferDevice dev) const
|
||||
{
|
||||
return (dev.getDeviceName() == search_string);
|
||||
}
|
||||
|
||||
void setSearchString(const QString &string)
|
||||
{
|
||||
search_string = string;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @class PredFindVolumeUDI
|
||||
*
|
||||
* @brief Predicate class to find volume UDI in TransferDevice.
|
||||
*
|
||||
* PredFindVolumeUDI can be used e.g. as parameter in find_if() function to
|
||||
* compare TransferDevices in TransferDeviceList with a given volume UDI
|
||||
* specified by setSearchString().
|
||||
*/
|
||||
class PredFindVolumeUDI
|
||||
{
|
||||
protected:
|
||||
QString search_string;
|
||||
public:
|
||||
PredFindVolumeUDI() {};
|
||||
|
||||
bool operator()(const TransferDevice dev) const
|
||||
{
|
||||
return (dev.getVolumeUDI() == search_string);
|
||||
}
|
||||
|
||||
void setSearchString(const QString &string)
|
||||
{
|
||||
search_string = string;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#endif /* __TRANSFER_DEVICE_HH__ */
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
#-*- mode: makefile; tab-width: 4; -*-
|
||||
#
|
||||
include(../../qmake.inc)
|
||||
#
|
||||
TEMPLATE = lib
|
||||
#
|
||||
INCLUDEPATH += ../libfwbuilder/src
|
||||
DEPENDPATH += ../libfwbuilder/src
|
||||
|
||||
SOURCES = TransferDevice.cpp
|
||||
|
||||
HEADERS = TransferDevice.h
|
||||
|
||||
CONFIG += staticlib
|
||||
|
||||
TARGET = fwtransfer
|
||||
|
||||
INSTALLS -= target
|
||||
@ -14,7 +14,7 @@ SOURCES += main.cpp
|
||||
|
||||
IMPORT_LIB = ../import/$$BINARY_SUBDIR/libimport.a
|
||||
FWBPARSER_LIB = ../parsers/$$BINARY_SUBDIR/libfwbparser.a
|
||||
FWTRANSFER_LIB = ../fwtransfer/$$BINARY_SUBDIR/libfwtransfer.a
|
||||
# FWTRANSFER_LIB = ../fwtransfer/$$BINARY_SUBDIR/libfwtransfer.a
|
||||
|
||||
INCLUDEPATH += $$ANTLR_INCLUDEPATH
|
||||
DEFINES += $$ANTLR_DEFINES
|
||||
@ -23,13 +23,14 @@ STATIC_LIBS += ../libgui/$$BINARY_SUBDIR/libgui.a \
|
||||
$$IMPORT_LIB $$FWBPARSER_LIB $$ANTLR_LIBS
|
||||
|
||||
# fwtransfer lib. Add this before adding -lQtDBus to LIBS below
|
||||
STATIC_LIBS += $$FWTRANSFER_LIB
|
||||
contains( HAVE_QTDBUS, 1 ):unix {
|
||||
!macx:QT += network \
|
||||
dbus
|
||||
macx:STATIC_LIBS += -framework \
|
||||
QtDBus
|
||||
}
|
||||
# STATIC_LIBS += $$FWTRANSFER_LIB
|
||||
|
||||
# contains( HAVE_QTDBUS, 1 ):unix {
|
||||
# !macx:QT += network \
|
||||
# dbus
|
||||
# macx:STATIC_LIBS += -framework \
|
||||
# QtDBus
|
||||
# }
|
||||
|
||||
# !macx:STATIC_LIBS += -lQtDBus # workaround for QT += dbus not working with Qt < 4.4.0
|
||||
|
||||
|
||||
@ -69,8 +69,6 @@
|
||||
#include "HttpGet.h"
|
||||
#include "StartTipDialog.h"
|
||||
|
||||
#include "transferDialog.h"
|
||||
|
||||
#include "events.h"
|
||||
|
||||
#include "importAddressListWizard/ImportAddressListWizard.h"
|
||||
@ -1780,19 +1778,6 @@ void FWWindow::inspect()
|
||||
}
|
||||
}
|
||||
|
||||
void FWWindow::transferfw(set<Firewall*> vf)
|
||||
{
|
||||
transferDialog *ed = new transferDialog(NULL, vf);
|
||||
ed->show();
|
||||
}
|
||||
|
||||
void FWWindow::transferfw()
|
||||
{
|
||||
std::set<Firewall*> emp;
|
||||
transferDialog *ed = new transferDialog(NULL, emp);
|
||||
ed->show();
|
||||
}
|
||||
|
||||
void FWWindow::addNewObjectMenu(QMenu *m)
|
||||
{
|
||||
QMenu *old_menu = m_mainWindow->newObjectAction->menu();
|
||||
|
||||
@ -204,8 +204,6 @@ public slots:
|
||||
virtual void install(std::set<libfwbuilder::Firewall * > vf);
|
||||
virtual void install();
|
||||
virtual void inspect();
|
||||
virtual void transferfw(std::set<libfwbuilder::Firewall * > vf);
|
||||
virtual void transferfw();
|
||||
|
||||
virtual void insertRule();
|
||||
virtual void addRuleAfterCurrent();
|
||||
|
||||
@ -820,38 +820,6 @@ void ObjectManipulator::contextMenuRequested(const QPoint &pos)
|
||||
popup_menu->addAction( tr("Compile"), this, SLOT( compile()));
|
||||
popup_menu->addAction( tr("Install"), this, SLOT( install()));
|
||||
popup_menu->addAction( tr("Inspect"), this, SLOT( inspect()));
|
||||
|
||||
if (Firewall::cast(currentObj)!=NULL)
|
||||
{
|
||||
Resources* os_res = Resources::os_res[currentObj->getStr("host_OS")];
|
||||
if (os_res)
|
||||
{
|
||||
string transfer = os_res->getTransferAgent();
|
||||
if (!transfer.empty())
|
||||
popup_menu->addAction( tr("Transfer"), this, SLOT(transferfw()));
|
||||
}
|
||||
}
|
||||
|
||||
if (ObjectGroup::cast(currentObj)!=NULL &&
|
||||
currentObj->getName()=="Firewalls")
|
||||
{
|
||||
// Config transfer is currently only supported for Secuwall.
|
||||
// Check if we have any
|
||||
bool have_transfer_support = false;
|
||||
for (FWObject::iterator it=currentObj->begin();
|
||||
it!=currentObj->end(); ++it)
|
||||
{
|
||||
FWObject *fw = *it;
|
||||
Resources* os_res = Resources::os_res[fw->getStr("host_OS")];
|
||||
if (os_res)
|
||||
{
|
||||
string transfer = os_res->getTransferAgent();
|
||||
have_transfer_support = have_transfer_support || (!transfer.empty());
|
||||
}
|
||||
}
|
||||
if (have_transfer_support)
|
||||
popup_menu->addAction( tr("Transfer"), this, SLOT(transferfw()));
|
||||
}
|
||||
}
|
||||
|
||||
popup_menu->addSeparator();
|
||||
|
||||
@ -251,7 +251,6 @@ public slots:
|
||||
void compile();
|
||||
void install();
|
||||
void inspect();
|
||||
void transferfw();
|
||||
|
||||
void duplicateObj(QAction*);
|
||||
void moveObj(QAction*);
|
||||
|
||||
@ -412,17 +412,6 @@ void ObjectManipulator::inspect()
|
||||
m_project->inspect(fwset);
|
||||
}
|
||||
|
||||
void ObjectManipulator::transferfw()
|
||||
{
|
||||
if (getCurrentObjectTree()->getNumSelected()==0) return;
|
||||
|
||||
vector<FWObject*> so = getCurrentObjectTree()->getSimplifiedSelection();
|
||||
set<Firewall*> fo;
|
||||
filterFirewallsFromSelection(so, fo);
|
||||
|
||||
m_project->transferfw(fo);
|
||||
}
|
||||
|
||||
void ObjectManipulator::find()
|
||||
{
|
||||
if (getCurrentObjectTree()->getNumSelected()==0) return;
|
||||
|
||||
@ -991,16 +991,6 @@ void ProjectPanel::inspect(set<Firewall *> fws)
|
||||
viewer->show();
|
||||
}
|
||||
|
||||
void ProjectPanel::transferfw(set<Firewall*> vf)
|
||||
{
|
||||
mainW->transferfw(vf);
|
||||
}
|
||||
|
||||
void ProjectPanel::transferfw()
|
||||
{
|
||||
mainW->transferfw();
|
||||
}
|
||||
|
||||
QString ProjectPanel::printHeader()
|
||||
{
|
||||
QString headerText = rcs->getFileName().section("/",-1,-1);
|
||||
|
||||
@ -277,8 +277,6 @@ public:
|
||||
virtual void install(std::set<libfwbuilder::Firewall*> vf);
|
||||
virtual void install();
|
||||
virtual void inspect(std::set<libfwbuilder::Firewall*> vf);
|
||||
virtual void transferfw(std::set<libfwbuilder::Firewall*> vf);
|
||||
virtual void transferfw();
|
||||
|
||||
void splitterMoved ( int pos, int index );
|
||||
|
||||
|
||||
@ -578,9 +578,9 @@ FORMS = FWBMainWindow_q.ui \
|
||||
|
||||
|
||||
# fwtransfer stuff.
|
||||
HEADERS += transferDialog.h
|
||||
SOURCES += transferDialog.cpp
|
||||
FORMS += transferdialog_q.ui
|
||||
# HEADERS += transferDialog.h
|
||||
# SOURCES += transferDialog.cpp
|
||||
# FORMS += transferdialog_q.ui
|
||||
|
||||
# !macx:LIBS += -lQtDBus # workaround for QT += dbus not working with Qt < 4.4.0
|
||||
|
||||
@ -590,8 +590,8 @@ INCLUDEPATH += \
|
||||
../pflib \
|
||||
../cisco_lib \
|
||||
../compiler_lib \
|
||||
../fwtransfer \
|
||||
../libfwbuilder/src
|
||||
|
||||
DEPENDPATH += \
|
||||
../import \
|
||||
../iptlib \
|
||||
|
||||
@ -1,482 +0,0 @@
|
||||
/*
|
||||
* transferDialog.cpp - config transfer dialog implementation
|
||||
*
|
||||
* Copyright (c) 2008 secunet Security Networks AG
|
||||
* Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch>
|
||||
* Copyright (c) 2008 Reto Buerki <buerki@swiss-it.ch>
|
||||
*
|
||||
* This work is dual-licensed under:
|
||||
*
|
||||
* o The terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* o The terms of NetCitadel End User License Agreement
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "transferDialog.h"
|
||||
#include "utils.h"
|
||||
#include "utils_no_qt.h"
|
||||
#include "global.h"
|
||||
|
||||
#include "fwbuilder/FWObjectDatabase.h"
|
||||
#include "fwbuilder/FWException.h"
|
||||
#include "fwbuilder/Resources.h"
|
||||
#include "fwbuilder/Cluster.h"
|
||||
|
||||
#include "TransferDevice.h"
|
||||
|
||||
#include "FWWindow.h"
|
||||
#include "FWBSettings.h"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <qmessagebox.h>
|
||||
#include <qfiledialog.h>
|
||||
|
||||
#define SEARCHSTRING "Transfer firewall "
|
||||
|
||||
using namespace std;
|
||||
using namespace fwtransfer;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
transferDialog::transferDialog(QWidget *parent, set<libfwbuilder::Firewall*> fws)
|
||||
: QDialog(parent), transferDevices(NULL)
|
||||
{
|
||||
// setup ui
|
||||
m_dialog = new Ui::transferDialog_q;
|
||||
m_dialog->setupUi(this);
|
||||
|
||||
// init external process handling
|
||||
connect(&proc, SIGNAL(readyReadStandardOutput()),
|
||||
this, SLOT(readFromStdout()));
|
||||
connect(&proc, SIGNAL(finished(int, QProcess::ExitStatus)),
|
||||
this, SLOT(processExited(int)));
|
||||
proc.setProcessChannelMode(QProcess::MergedChannels);
|
||||
|
||||
// disable transfer button until a volume is selected
|
||||
m_dialog->transferButton->setEnabled(false);
|
||||
|
||||
// handle cluster selections
|
||||
foreach(Firewall* fw, fws)
|
||||
{
|
||||
if (Cluster::isA(fw))
|
||||
{
|
||||
list<Firewall*> members;
|
||||
Cluster::cast(fw)->getMembersList(members);
|
||||
firewalls.insert(firewalls.begin(), members.begin(), members.end());
|
||||
|
||||
} else
|
||||
{
|
||||
firewalls.push_back(fw);
|
||||
}
|
||||
}
|
||||
|
||||
if (firewalls.empty())
|
||||
{
|
||||
QMessageBox::critical(this, "Firewall Config Transfer",
|
||||
tr("No firewalls selected for transfer"),
|
||||
tr("&Continue"), QString::null, QString::null,
|
||||
0, 1);
|
||||
return;
|
||||
}
|
||||
firewalls.sort(FWObjectNameCmpPredicate());
|
||||
|
||||
// init volume list
|
||||
transferDevices = new TransferDeviceList;
|
||||
try
|
||||
{
|
||||
transferDevices->init();
|
||||
}
|
||||
catch (FWException &ex)
|
||||
{
|
||||
QMessageBox::critical(this, "Firewall Config Transfer",
|
||||
tr("Transfer error: %1").arg(ex.toString().c_str()),
|
||||
tr("&Continue"), QString::null, QString::null,
|
||||
0, 1);
|
||||
return;
|
||||
}
|
||||
// display available volumes (if any)
|
||||
updateVolumeView();
|
||||
|
||||
// connect transferDevices signals to our slots
|
||||
connect(transferDevices, SIGNAL(devicesChanged()),
|
||||
this, SLOT(updateDeviceList()));
|
||||
|
||||
// display selected firewalls
|
||||
displayFirewalls();
|
||||
}
|
||||
|
||||
transferDialog::~transferDialog()
|
||||
{
|
||||
if (transferDevices != NULL)
|
||||
{
|
||||
delete transferDevices;
|
||||
transferDevices = NULL;
|
||||
}
|
||||
delete m_dialog;
|
||||
}
|
||||
|
||||
void transferDialog::displayFirewalls()
|
||||
{
|
||||
m_dialog->fwWorkList->clear();
|
||||
|
||||
QTreeWidgetItem *titem;
|
||||
list<Firewall*>::const_iterator i;
|
||||
for (i = firewalls.begin(); i != firewalls.end(); ++i)
|
||||
{
|
||||
titem = new QTreeWidgetItem;
|
||||
titem->setText(0, (*i)->getName().c_str());
|
||||
|
||||
// initial state is 'Waiting'
|
||||
titem->setText(1, tr("Waiting"));
|
||||
m_dialog->fwWorkList->insertTopLevelItem(0, titem);
|
||||
|
||||
// store mapping
|
||||
opListMapping[(*i)] = titem;
|
||||
}
|
||||
m_dialog->fwWorkList->resizeColumnToContents(0);
|
||||
m_dialog->fwWorkList->sortByColumn(0, Qt::AscendingOrder);
|
||||
}
|
||||
|
||||
void transferDialog::updateVolumeView()
|
||||
{
|
||||
// set row count to fit transferDevices size
|
||||
m_dialog->transferTable->setRowCount(transferDevices->size());
|
||||
|
||||
// display appropriate label, if no volumes -> return
|
||||
if (transferDevices->empty())
|
||||
{
|
||||
m_dialog->volumeLabel->setText("<b>No volumes found! Please connect"
|
||||
" any usbdisk to update the volume list.</b>");
|
||||
m_dialog->transferTable->setEnabled(false);
|
||||
m_dialog->transferButton->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_dialog->volumeLabel->setText("Select usbstick volume to start "
|
||||
"firewall config transfer:");
|
||||
m_dialog->transferTable->setEnabled(true);
|
||||
}
|
||||
|
||||
// fill in available sticks, disable auto-sort first
|
||||
m_dialog->transferTable->setSortingEnabled(false);
|
||||
QTableWidgetItem *citem;
|
||||
int row = 0;
|
||||
TransferDeviceList::const_iterator it;
|
||||
for (it = transferDevices->begin(); it != transferDevices->end(); it++)
|
||||
{
|
||||
// name
|
||||
citem = new QTableWidgetItem;
|
||||
citem->setText((*it).getDeviceName());
|
||||
m_dialog->transferTable->setItem(row, 0, citem);
|
||||
|
||||
// size (in MB)
|
||||
citem = new QTableWidgetItem;
|
||||
citem->setText((*it).getVolumeSizeStr());
|
||||
m_dialog->transferTable->setItem(row, 1, citem);
|
||||
|
||||
// mounted?
|
||||
QString mounted = (*it).isMounted() ? "Yes" : "No";
|
||||
citem = new QTableWidgetItem;
|
||||
citem->setText(mounted);
|
||||
m_dialog->transferTable->setItem(row, 2, citem);
|
||||
|
||||
// mountpoint, if any
|
||||
citem = new QTableWidgetItem;
|
||||
citem->setText((*it).getMountpoint());
|
||||
m_dialog->transferTable->setItem(row, 3, citem);
|
||||
|
||||
// filesystem
|
||||
citem = new QTableWidgetItem;
|
||||
citem->setText((*it).getVolumeFS());
|
||||
m_dialog->transferTable->setItem(row, 4, citem);
|
||||
row++;
|
||||
}
|
||||
m_dialog->transferTable->setSortingEnabled(true);
|
||||
m_dialog->transferTable->sortByColumn(0, Qt::AscendingOrder);
|
||||
m_dialog->transferTable->resizeColumnToContents(0);
|
||||
}
|
||||
|
||||
bool transferDialog::runTransfer(Firewall *fw, const QString &volume)
|
||||
{
|
||||
// process events to update display first
|
||||
// important when transfering multiple firewalls
|
||||
qApp->processEvents();
|
||||
|
||||
// prepare args for transfer agent call
|
||||
QStringList args;
|
||||
if (!prepareArgs(args, fw, volume))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
log(QObject::tr("Executing:"));
|
||||
log(args.join(" "));
|
||||
|
||||
// execute binary
|
||||
QString path = args.at(0);
|
||||
args.pop_front();
|
||||
proc.start(path, args);
|
||||
|
||||
if (!proc.waitForStarted())
|
||||
{
|
||||
log(tr("Error: Failed to start program"));
|
||||
setTreeStatus(fw, "Failure");
|
||||
return false;
|
||||
}
|
||||
args.push_front(path);
|
||||
|
||||
if (!proc.waitForFinished())
|
||||
{
|
||||
log(tr("Error: Waiting for program termination"));
|
||||
setTreeStatus(fw, "Failure");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (proc.exitCode())
|
||||
{
|
||||
log(tr("Error: Program returned failure status"));
|
||||
setTreeStatus(fw, "Failure");
|
||||
return false;
|
||||
}
|
||||
|
||||
setTreeStatus(fw, "Success");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool transferDialog::prepareArgs(QStringList &args, libfwbuilder::Firewall *fw,
|
||||
const QString &volume)
|
||||
{
|
||||
|
||||
FWOptions *fwopt = fw->getOptionsObject();
|
||||
|
||||
// try to find suitable config transfer agent
|
||||
string agent = fwopt->getStr("agent");
|
||||
if (agent.empty())
|
||||
{
|
||||
agent = Resources::os_res[fw->getStr("host_OS")]->getTransferAgent();
|
||||
}
|
||||
|
||||
if (agent.empty())
|
||||
{
|
||||
// no transfer agent for this host_OS found
|
||||
log("Cannot find suitable transfer agent");
|
||||
setTreeStatus(fw, "Failure");
|
||||
return false;
|
||||
}
|
||||
log(QObject::tr("Using transfer agent '%1'").arg(agent.c_str()));
|
||||
|
||||
QString wdir = getFileDir(mw->getRCS()->getFileName());
|
||||
|
||||
// fill argument list
|
||||
args.push_back(agent.c_str());
|
||||
QString qs = fwopt->getStr("cmdline").c_str();
|
||||
args += qs.split(" ", QString::SkipEmptyParts);
|
||||
args.push_back("-f");
|
||||
args.push_back(fw->getRoot()->getFileName().c_str());
|
||||
if (!wdir.isEmpty())
|
||||
{
|
||||
args.push_back("-d");
|
||||
args.push_back(wdir);
|
||||
}
|
||||
args.push_back("-v");
|
||||
args.push_back(volume);
|
||||
|
||||
// append fw object name to tarball when writing multiple configs
|
||||
// to a volume
|
||||
if (firewalls.size() > 1)
|
||||
{
|
||||
log(QObject::tr("Appending fw object name to tarball"));
|
||||
args.push_back("-n");
|
||||
}
|
||||
|
||||
// append template directory content to transfer tarball
|
||||
if (fwopt->getBool("secuwall_add_files"))
|
||||
{
|
||||
QString tmpldir = fwopt->getStr("secuwall_add_files_dir").c_str();
|
||||
args.push_back("-a");
|
||||
args.push_back(tmpldir);
|
||||
}
|
||||
|
||||
args.push_back(QString::fromUtf8(fw->getName().c_str()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void transferDialog::log(const QString message)
|
||||
{
|
||||
if (message.isEmpty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
QString txt = message;
|
||||
if (!txt.endsWith("\n"))
|
||||
{
|
||||
txt += "<br>";
|
||||
}
|
||||
else
|
||||
{
|
||||
txt.replace('\n', "<br>");
|
||||
}
|
||||
m_dialog->procLogDisplay->insertHtml(txt);
|
||||
m_dialog->procLogDisplay->ensureCursorVisible();
|
||||
}
|
||||
|
||||
void transferDialog::setTreeStatus(Firewall *fw, const QString &status)
|
||||
{
|
||||
QTreeWidgetItem* item = opListMapping[fw];
|
||||
if (item == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
item->setText(1, status);
|
||||
}
|
||||
|
||||
QString transferDialog::getVolumeName() const
|
||||
{
|
||||
QList<QTableWidgetItem *> itemlist;
|
||||
itemlist = m_dialog->transferTable->selectedItems();
|
||||
|
||||
return itemlist[0]->text();
|
||||
}
|
||||
|
||||
void transferDialog::accept()
|
||||
{
|
||||
int current = m_dialog->transferTable->currentRow();
|
||||
if (current == -1)
|
||||
{
|
||||
QMessageBox::information(this, "Transfer",
|
||||
"Please select volume or press 'Cancel' button.");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
// start the transfer
|
||||
|
||||
// move cursor to the end of log widget
|
||||
m_dialog->procLogDisplay->moveCursor(QTextCursor::End);
|
||||
|
||||
QString volume = getVolumeName();
|
||||
log("<b>Using volume : <i>" + volume + "</i></b></br>");
|
||||
|
||||
Firewall *fw;
|
||||
list<Firewall*>::const_iterator i;
|
||||
for (i = firewalls.begin(); i != firewalls.end(); ++i)
|
||||
{
|
||||
fw = *i;
|
||||
QString fwname = fw->getName().c_str();
|
||||
|
||||
log("<br><b>" + QString(SEARCHSTRING) + fwname + ":</b>");
|
||||
setTreeStatus(fw, "Transfering ...");
|
||||
if (!runTransfer(fw, volume))
|
||||
{
|
||||
log(QObject::tr("Could not transfer %1 config to '%2'").
|
||||
arg(fwname).arg(volume));
|
||||
}
|
||||
}
|
||||
|
||||
// enable save log button after first run
|
||||
if (!m_dialog->saveLogButton->isEnabled())
|
||||
{
|
||||
m_dialog->saveLogButton->setEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void transferDialog::saveLog()
|
||||
{
|
||||
QString dir;
|
||||
dir = st->getWDir();
|
||||
|
||||
if (dir.isEmpty())
|
||||
{
|
||||
dir = st->getOpenFileDir();
|
||||
}
|
||||
if (dir.isEmpty())
|
||||
{
|
||||
dir = "~";
|
||||
}
|
||||
|
||||
QString logText;
|
||||
logText = m_dialog->procLogDisplay->toPlainText();
|
||||
|
||||
QString s = QFileDialog::getSaveFileName(this, "Choose a file",
|
||||
dir, "Text file (*.txt)");
|
||||
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("Saving log to file %s", s.toAscii().constData());
|
||||
}
|
||||
|
||||
if (!s.isEmpty())
|
||||
{
|
||||
if (!s.endsWith(".txt"))
|
||||
{
|
||||
s += ".txt";
|
||||
}
|
||||
|
||||
QFile f(s);
|
||||
if (f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
QTextStream str(&f);
|
||||
str << logText;
|
||||
f.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void transferDialog::selected()
|
||||
{
|
||||
m_dialog->transferButton->setEnabled(true);
|
||||
}
|
||||
|
||||
void transferDialog::readFromStdout()
|
||||
{
|
||||
QString buf = proc.readAllStandardOutput();
|
||||
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("transferDialog::readFromStdout: %s",
|
||||
buf.toAscii().constData());
|
||||
}
|
||||
|
||||
log(buf);
|
||||
}
|
||||
|
||||
void transferDialog::processExited(int res)
|
||||
{
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("transferDialog::processExited, exit code = %d", res);
|
||||
}
|
||||
|
||||
readFromStdout();
|
||||
}
|
||||
|
||||
void transferDialog::findFirewallInLog(QTreeWidgetItem* item)
|
||||
{
|
||||
if (fwbdebug)
|
||||
{
|
||||
qDebug("transferDialog::findFirewallInLog");
|
||||
}
|
||||
|
||||
qApp->processEvents();
|
||||
m_dialog->procLogDisplay->moveCursor(QTextCursor::End);
|
||||
m_dialog->procLogDisplay->find(QString(SEARCHSTRING) + item->text(0) + ":",
|
||||
QTextDocument::FindWholeWords |
|
||||
QTextDocument::FindCaseSensitively |
|
||||
QTextDocument::FindBackward);
|
||||
}
|
||||
|
||||
void transferDialog::updateDeviceList()
|
||||
{
|
||||
updateVolumeView();
|
||||
}
|
||||
|
||||
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* transferDialog.h - firewall config transfer dialog
|
||||
*
|
||||
* Copyright (c) 2008 secunet Security Networks AG
|
||||
* Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch>
|
||||
* Copyright (c) 2008 Reto Buerki <buerki@swiss-it.ch>
|
||||
*
|
||||
* This work is dual-licensed under:
|
||||
*
|
||||
* o The terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* o The terms of NetCitadel End User License Agreement
|
||||
*/
|
||||
|
||||
#ifndef __TRANSFERDIALOG_H_
|
||||
#define __TRANSFERDIALOG_H_
|
||||
|
||||
#include "../../config.h"
|
||||
#include <ui_transferdialog_q.h>
|
||||
|
||||
#include "fwbuilder/Firewall.h"
|
||||
|
||||
#include <qprocess.h>
|
||||
|
||||
namespace fwtransfer
|
||||
{
|
||||
class TransferDeviceList;
|
||||
};
|
||||
|
||||
typedef std::map<libfwbuilder::Firewall*, QTreeWidgetItem*> t_listMap;
|
||||
|
||||
/**
|
||||
* @class transferDialog
|
||||
*
|
||||
* @brief This class is the users view to config transfer operations.
|
||||
*
|
||||
* The transferDialog class/UI is used to display transfer information to the user.
|
||||
* The user can select an usb-storage volume to transfer specific firewall
|
||||
* configs. Progress about running transfer operations is displayed in a status
|
||||
* log.
|
||||
*/
|
||||
class transferDialog : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private:
|
||||
/**
|
||||
* display all selected firewalls in tree widget.
|
||||
*/
|
||||
void displayFirewalls();
|
||||
|
||||
/**
|
||||
* display all available usb-storage based volumes. This function is
|
||||
* also called when a devicesChanged signal is received from the
|
||||
* transferDevices list to update the volumes view.
|
||||
*/
|
||||
void updateVolumeView();
|
||||
|
||||
/**
|
||||
* perform an transfer of a specific firewall.
|
||||
*
|
||||
* @param fw firewall to transfer
|
||||
* @param volume volume name to transfer config to
|
||||
* @return true if transfer was successful, false if not
|
||||
*/
|
||||
bool runTransfer(libfwbuilder::Firewall *fw, const QString &volume);
|
||||
|
||||
/**
|
||||
* prepare argument list for transfer agent call.
|
||||
*
|
||||
* @param args argument list as QStringList to prepare
|
||||
* @param fw firewall to build transfer agent argument list for
|
||||
* @param volume volume name used for transfer
|
||||
* @return true if suitable transfer agent found, false if not
|
||||
*/
|
||||
bool prepareArgs(QStringList &args, libfwbuilder::Firewall *fw,
|
||||
const QString &volume);
|
||||
|
||||
/**
|
||||
* write a message to the log widget.
|
||||
*
|
||||
* @param message log message to write
|
||||
*/
|
||||
void log(const QString message);
|
||||
|
||||
/**
|
||||
* set status of a firewall given by fw to status 'status', this status
|
||||
* is displayed in the firewall tree widget.
|
||||
*
|
||||
* @param fw firewall to change status
|
||||
* @param status free-text status message
|
||||
*/
|
||||
void setTreeStatus(libfwbuilder::Firewall *fw, const QString &status);
|
||||
|
||||
/** selected volume id */
|
||||
QString volume_name;
|
||||
|
||||
/** firewalls to transfer */
|
||||
std::list<libfwbuilder::Firewall*> firewalls;
|
||||
|
||||
/** Available transfer devices are stored here */
|
||||
fwtransfer::TransferDeviceList *transferDevices;
|
||||
|
||||
/** external process handler */
|
||||
QProcess proc;
|
||||
|
||||
/** mapping between tree items and firewalls */
|
||||
t_listMap opListMapping;
|
||||
|
||||
/** transferDialog UI */
|
||||
Ui::transferDialog_q *m_dialog;
|
||||
|
||||
public:
|
||||
/** transferDialog ctor */
|
||||
transferDialog(QWidget *parent, std::set<libfwbuilder::Firewall*> fws);
|
||||
|
||||
/** transferDialog dtor */
|
||||
~transferDialog();
|
||||
|
||||
/**
|
||||
* return chosen volume name to caller.
|
||||
*
|
||||
* @return selected volume name (e.g. /dev/sdc1)
|
||||
*/
|
||||
QString getVolumeName() const;
|
||||
|
||||
protected slots:
|
||||
virtual void accept();
|
||||
virtual void saveLog();
|
||||
void selected();
|
||||
void readFromStdout();
|
||||
void processExited(int code);
|
||||
void findFirewallInLog(QTreeWidgetItem*);
|
||||
void updateDeviceList();
|
||||
};
|
||||
|
||||
#endif /* __TRANSFERDIALOG_H_ */
|
||||
|
||||
@ -1,393 +0,0 @@
|
||||
<ui version="4.0" >
|
||||
<class>transferDialog_q</class>
|
||||
<widget class="QDialog" name="transferDialog_q" >
|
||||
<property name="geometry" >
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>547</width>
|
||||
<height>627</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Preferred" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>32767</width>
|
||||
<height>32767</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="focusPolicy" >
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</property>
|
||||
<property name="windowTitle" >
|
||||
<string>Config transfer options</string>
|
||||
</property>
|
||||
<property name="sizeGripEnabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" >
|
||||
<widget class="QFrame" name="titleFrame" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>32767</width>
|
||||
<height>32767</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<property name="lineWidth" >
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="midLineWidth" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" >
|
||||
<item>
|
||||
<widget class="QLabel" name="dialogTitleLine" >
|
||||
<property name="text" >
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal;">
|
||||
<p align="center" style=" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:x-large; font-weight:600;">Export firewall configs to transfer device</span></p></body></html></string>
|
||||
</property>
|
||||
<property name="wordWrap" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" >
|
||||
<widget class="QFrame" name="mainBox" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Minimum" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::Box</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="0" colspan="2" >
|
||||
<widget class="QLabel" name="volumeLabel" >
|
||||
<property name="text" >
|
||||
<string>Select usbstick volume to start firewall config transfer:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2" >
|
||||
<widget class="QTableWidget" name="transferTable" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip" >
|
||||
<string>Select a portable disk volume to transfer firewall configs</string>
|
||||
</property>
|
||||
<property name="editTriggers" >
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
<property name="tabKeyNavigation" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="showDropIndicator" stdset="0" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="alternatingRowColors" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="selectionMode" >
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior" >
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<property name="textElideMode" >
|
||||
<enum>Qt::ElideMiddle</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="wordWrap" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Device</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Size</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Mounted</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Mountpoint</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Filesystem</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QTreeWidget" name="fwWorkList" >
|
||||
<property name="toolTip" >
|
||||
<string>Double click on a firewall in this tree to jump to the corresponding process log entry</string>
|
||||
</property>
|
||||
<property name="itemsExpandable" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Firewall</string>
|
||||
</property>
|
||||
</column>
|
||||
<column>
|
||||
<property name="text" >
|
||||
<string>Progress</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" >
|
||||
<layout class="QHBoxLayout" >
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="detailMCframe_2" >
|
||||
<property name="title" >
|
||||
<string>Process log</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<property name="margin" >
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="spacing" >
|
||||
<number>6</number>
|
||||
</property>
|
||||
<item row="0" column="0" >
|
||||
<spacer>
|
||||
<property name="orientation" >
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeType" >
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0" >
|
||||
<size>
|
||||
<width>176</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="1" >
|
||||
<widget class="QPushButton" name="saveLogButton" >
|
||||
<property name="enabled" >
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Save log to file</string>
|
||||
</property>
|
||||
<property name="icon" >
|
||||
<iconset resource="MainRes.qrc" >
|
||||
<normaloff>:/Icons/save_25.png</normaloff>:/Icons/save_25.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="2" >
|
||||
<widget class="QTextEdit" name="procLogDisplay" >
|
||||
<property name="readOnly" >
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" >
|
||||
<widget class="QFrame" name="buttonsFrame" >
|
||||
<property name="sizePolicy" >
|
||||
<sizepolicy vsizetype="Fixed" hsizetype="Preferred" >
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximumSize" >
|
||||
<size>
|
||||
<width>32767</width>
|
||||
<height>32767</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="frameShape" >
|
||||
<enum>QFrame::Panel</enum>
|
||||
</property>
|
||||
<property name="frameShadow" >
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QGridLayout" >
|
||||
<item row="0" column="1" >
|
||||
<widget class="QPushButton" name="transferButton" >
|
||||
<property name="toolTip" >
|
||||
<string>Start the export!</string>
|
||||
</property>
|
||||
<property name="text" >
|
||||
<string>Transfer</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2" >
|
||||
<widget class="QPushButton" name="closeButton" >
|
||||
<property name="text" >
|
||||
<string>Close</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0" >
|
||||
<spacer>
|
||||
<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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11" />
|
||||
<tabstops>
|
||||
<tabstop>transferButton</tabstop>
|
||||
<tabstop>closeButton</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="MainRes.qrc" />
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>transferButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>transferDialog_q</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>407</x>
|
||||
<y>601</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>closeButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>transferDialog_q</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>493</x>
|
||||
<y>601</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>20</x>
|
||||
<y>20</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>transferTable</sender>
|
||||
<signal>cellClicked(int,int)</signal>
|
||||
<receiver>transferDialog_q</receiver>
|
||||
<slot>selected()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>277</x>
|
||||
<y>185</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>277</x>
|
||||
<y>301</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>saveLogButton</sender>
|
||||
<signal>clicked()</signal>
|
||||
<receiver>transferDialog_q</receiver>
|
||||
<slot>saveLog()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>540</x>
|
||||
<y>362</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>277</x>
|
||||
<y>301</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>fwWorkList</sender>
|
||||
<signal>itemActivated(QTreeWidgetItem*,int)</signal>
|
||||
<receiver>transferDialog_q</receiver>
|
||||
<slot>findFirewallInLog(QTreeWidgetItem*)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel" >
|
||||
<x>143</x>
|
||||
<y>411</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel" >
|
||||
<x>277</x>
|
||||
<y>301</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@ -16,7 +16,6 @@ SUBDIRS = libfwbuilder \
|
||||
import \
|
||||
common \
|
||||
compiler_lib \
|
||||
fwtransfer \
|
||||
iptlib \
|
||||
ipt \
|
||||
pflib \
|
||||
@ -27,7 +26,6 @@ SUBDIRS = libfwbuilder \
|
||||
iosacl \
|
||||
pix \
|
||||
procurve_acl \
|
||||
transfer_agents \
|
||||
libgui \
|
||||
fwbedit \
|
||||
gui \
|
||||
|
||||
@ -1,35 +0,0 @@
|
||||
#-*- mode: makefile; tab-width: 4; -*-
|
||||
#
|
||||
#
|
||||
include(../../../qmake.inc)
|
||||
|
||||
SOURCES = transfer_secuwall.cpp
|
||||
|
||||
HEADERS = ../../../config.h
|
||||
|
||||
INCLUDEPATH += ../../libfwbuilder/src
|
||||
DEPENDPATH += ../../libfwbuilder/src
|
||||
|
||||
contains( HAVE_QTDBUS, 1 ):unix {
|
||||
!macx: QT += network dbus
|
||||
macx: LIBS += -framework QtDBus
|
||||
#!macx:LIBS += -lQtDBus # workaround for QT += dbus not working with Qt < 4.4.0
|
||||
}
|
||||
|
||||
!win32 {
|
||||
QMAKE_COPY = ../../../install.sh -m 0755 -s
|
||||
LIBS = ../../fwtransfer/libfwtransfer.a \ # -lQtDBus
|
||||
../../libfwbuilder/src/fwcompiler/libfwcompiler.a \
|
||||
../../libfwbuilder/src/fwbuilder/libfwbuilder.a \
|
||||
$$LIBS
|
||||
}
|
||||
|
||||
win32 {
|
||||
CONFIG += console
|
||||
LIBS += ../../fwtransfer/release/libfwtransfer.a \ # -lQtDBus
|
||||
../../libfwbuilder/src/fwcompiler/release/libfwcompiler.a \
|
||||
../../libfwbuilder/src/fwbuilder/release/libfwbuilder.a
|
||||
}
|
||||
|
||||
TARGET = transfer_secuwall
|
||||
|
||||
@ -1,383 +0,0 @@
|
||||
/*
|
||||
* transfer_secuwall.cpp - secunet wall config transfer agent
|
||||
*
|
||||
* Copyright (c) 2008 secunet Security Networks AG
|
||||
* Copyright (c) 2008 Adrian-Ken Rueegsegger <rueegsegger@swiss-it.ch>
|
||||
* Copyright (c) 2008 Reto Buerki <buerki@swiss-it.ch>
|
||||
*
|
||||
* This work is dual-licensed under:
|
||||
*
|
||||
* o The terms of the GNU General Public License as published by the Free
|
||||
* Software Foundation, either version 2 of the License, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* o The terms of NetCitadel End User License Agreement
|
||||
*/
|
||||
|
||||
#include "../../../config.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sys/stat.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#include <direct.h>
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_GETOPT_H
|
||||
#include <getopt.h>
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
#include <getopt.h>
|
||||
#else
|
||||
//#include <stdlib.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include "fwbuilder/FWException.h"
|
||||
|
||||
#include "fwtransfer/TransferDevice.h"
|
||||
|
||||
// tarball base name and suffix (e.g. config.tar.gz)
|
||||
#define BASENAME "config"
|
||||
#define SUFFIX "tar"
|
||||
|
||||
using namespace std;
|
||||
using namespace fwtransfer;
|
||||
using namespace libfwbuilder;
|
||||
|
||||
int fwbdebug = 0;
|
||||
|
||||
// object database filename: not used at the moment
|
||||
static string filename = "";
|
||||
// workdir of firewall to export
|
||||
static string workdir = "";
|
||||
// templates dir to use
|
||||
static string tmpldir = "";
|
||||
// volumeid (e.g. /dev/sdc1) to use as transfer partition
|
||||
static string volumeid = "";
|
||||
// object name of firewall to export (e.g. fw1)
|
||||
static string fwobjectname = "";
|
||||
|
||||
// append fwobjectname to transfer tarball
|
||||
static bool appendname = false;
|
||||
|
||||
/**
|
||||
* init portable usb device list.
|
||||
*
|
||||
* @param devices device list to init, only portable devices are valid.
|
||||
* @return true if successful, false if not
|
||||
*/
|
||||
bool init_usbdisks(TransferDeviceList &devices)
|
||||
{
|
||||
try
|
||||
{
|
||||
devices.init();
|
||||
}
|
||||
catch (FWException &ex)
|
||||
{
|
||||
cout << "Could not init list of usbdisks!" << endl;
|
||||
cout << "Error: " << ex.toString() << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator it;
|
||||
it = devices.begin();
|
||||
if (it == devices.end())
|
||||
{
|
||||
cout << "No usable transfer volumes found! " << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* display transfer_secuwall usage.
|
||||
*/
|
||||
void usage(const char *name)
|
||||
{
|
||||
cout << "Firewall Builder: config transfer agent for "
|
||||
"secunet wall host OS" << endl;
|
||||
cout << ("Version : ") << VERSION << endl;
|
||||
cout << ("Usage : ") << name <<
|
||||
" [-l] [-h] [-n] -v volumeid [-f filename.xml] [-d workdir] "
|
||||
"[-a templatedir] firewall_object_name" << endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* list all available transfer volumes.
|
||||
*/
|
||||
void list_volumes()
|
||||
{
|
||||
TransferDeviceList devices;
|
||||
|
||||
if (!init_usbdisks(devices))
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator it;
|
||||
it = devices.begin();
|
||||
cout << endl;
|
||||
for (; it != devices.end(); it++)
|
||||
{
|
||||
TransferDevice dev = *it;
|
||||
dev.dump();
|
||||
}
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
* copy file specified by src to dst
|
||||
*
|
||||
* @param src source filepath
|
||||
* @param dst destination filepath
|
||||
* @return true if successfully copied, false if not
|
||||
*/
|
||||
bool copy_file(const string &src, const string &dst)
|
||||
{
|
||||
std::ifstream infile(src.c_str(), std::ios_base::binary);
|
||||
std::ofstream outfile(dst.c_str(), std::ios_base::binary);
|
||||
|
||||
if (!infile)
|
||||
{
|
||||
cout << "File not found: " << src << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!outfile)
|
||||
{
|
||||
cout << "Could not create: " << dst << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
outfile << infile.rdbuf();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cout << "Error while writing to: " << dst << endl;
|
||||
infile.close();
|
||||
outfile.close();
|
||||
return false;
|
||||
}
|
||||
infile.close();
|
||||
outfile.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* secunet wall config transfer agent
|
||||
*
|
||||
* used to export fw config tarball to a portable usb medium.
|
||||
*/
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc <= 1)
|
||||
{
|
||||
usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
int opt;
|
||||
|
||||
while ((opt = getopt(argc, argv, "lhnv:f:d:a:")) != EOF)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'd':
|
||||
workdir = string(optarg);
|
||||
break;
|
||||
case 'a':
|
||||
tmpldir = string(optarg);
|
||||
break;
|
||||
case 'f':
|
||||
filename = string(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
volumeid = string(optarg);
|
||||
break;
|
||||
case 'l':
|
||||
list_volumes();
|
||||
break;
|
||||
case 'h':
|
||||
usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
case 'n':
|
||||
appendname = true;
|
||||
break;
|
||||
default:
|
||||
usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
if ((argc - 1) != optind)
|
||||
{
|
||||
usage(argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
fwobjectname = string(argv[optind++]);
|
||||
|
||||
if (workdir.empty())
|
||||
{
|
||||
workdir = "./";
|
||||
}
|
||||
|
||||
if (filename.empty())
|
||||
{
|
||||
filename = workdir + fwobjectname + ".fwb";
|
||||
}
|
||||
|
||||
if (fwbdebug)
|
||||
{
|
||||
cout << "Volume\t: " << volumeid << endl;
|
||||
cout << "Object\t: " << fwobjectname << endl;
|
||||
cout << "Workdir\t: " << workdir << endl;
|
||||
cout << "DB\t: " << filename << endl;
|
||||
}
|
||||
|
||||
if (
|
||||
#ifdef _WIN32
|
||||
_chdir(workdir.c_str())
|
||||
#else
|
||||
chdir(workdir.c_str())
|
||||
#endif
|
||||
)
|
||||
{
|
||||
cout << "Can't change directory to: " << workdir << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// check for existence of fwobjectname subdir
|
||||
struct stat buffer;
|
||||
if (stat(fwobjectname.c_str(), &buffer))
|
||||
{
|
||||
cout << "Config subdir not found for " << fwobjectname << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// check templates directory (with -a flag only)
|
||||
if (!tmpldir.empty())
|
||||
{
|
||||
if (stat(tmpldir.c_str(), &buffer))
|
||||
{
|
||||
cout << "Templates directory '" << tmpldir << "' not found" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// try to mount volume
|
||||
TransferDeviceList devices;
|
||||
if (!init_usbdisks(devices))
|
||||
{
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
TransferDeviceList::const_iterator it;
|
||||
it = devices.getDeviceByName(volumeid);
|
||||
if (it == devices.end())
|
||||
{
|
||||
cout << "Could not find volume " << volumeid << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
TransferDevice dev = *it;
|
||||
|
||||
if (!dev.isMounted())
|
||||
{
|
||||
try
|
||||
{
|
||||
dev.mount();
|
||||
}
|
||||
catch (FWException &ex)
|
||||
{
|
||||
cout << "Could not mount volume " << volumeid << endl;
|
||||
cout << "Error: " << ex.toString() << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
string mountpoint = dev.getMountpoint().toStdString();
|
||||
cout << "Device mounted to " << mountpoint << endl;
|
||||
|
||||
// copy firewall script to fwobjectname subdir, we assume the script name
|
||||
// to be: 'fwobjectname + fw suffix'. the file will be copied to 'sysconfig'
|
||||
// subdirectory.
|
||||
string fwscriptname = fwobjectname + ".fw";
|
||||
string fwscriptdst = fwobjectname + "/sysconfig/" + fwscriptname;
|
||||
if (!copy_file(fwscriptname, fwscriptdst))
|
||||
{
|
||||
cout << "Firewall config script file not found for '"
|
||||
<< fwobjectname << "'" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// construct tarball name depending on appendname flag
|
||||
string tarball;
|
||||
if (appendname)
|
||||
{
|
||||
tarball = string(BASENAME) + "-" + fwobjectname + "." + string(SUFFIX);
|
||||
}
|
||||
else
|
||||
{
|
||||
tarball = string(BASENAME) + "." + string(SUFFIX);
|
||||
}
|
||||
|
||||
// tell tar to change into fwobjectname subdir and create tarball
|
||||
// force file ownership to root:root
|
||||
string cmd = "tar cCf " + fwobjectname + " " + tarball + " --owner=0 --group=0 .";
|
||||
if (system(cmd.c_str()) != 0)
|
||||
{
|
||||
cout << "Could not create tarball '" << tarball << "'" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// append templates to tarball
|
||||
if (!tmpldir.empty())
|
||||
{
|
||||
cout << "Adding templates from '" << tmpldir << "'" << endl;
|
||||
cmd = "tar rCf " + tmpldir + " " + tarball + " --owner=0 --group=0 .";
|
||||
if (system(cmd.c_str()) != 0)
|
||||
{
|
||||
cout << "Could not append templates to tarball '" << tarball
|
||||
<< "'" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// compress tarball
|
||||
cmd = "gzip -f " + tarball;
|
||||
if (system(cmd.c_str()) != 0)
|
||||
{
|
||||
cout << "Could not compress tarball '" << tarball << "'" << endl;
|
||||
cout << "Missing gzip binary?" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// copy compressed archive to volume
|
||||
string compressed = tarball + ".gz";
|
||||
string outpath = mountpoint + "/" + compressed;
|
||||
if (!copy_file(compressed, outpath))
|
||||
{
|
||||
cout << "Could not copy '" << compressed << "' to '"
|
||||
<< outpath << "'" << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
sync();
|
||||
#endif
|
||||
|
||||
cout << "Exported '" << fwobjectname << "' config to " << outpath << endl;
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
#-*- mode: makefile; tab-width: 4; -*-
|
||||
#
|
||||
#
|
||||
|
||||
TEMPLATE = subdirs
|
||||
|
||||
CONFIG += ordered
|
||||
|
||||
TARGET = transfer_agents
|
||||
SUBDIRS = secuwall
|
||||
Loading…
x
Reference in New Issue
Block a user