mirror of
https://github.com/fwbuilder/fwbuilder
synced 2026-03-21 18:57:14 +01:00
fixes #202 implemented library merge function in fwbedit
This commit is contained in:
parent
98ddfcffb9
commit
e97f326f7b
@ -1,3 +1,10 @@
|
||||
2009-12-08 vadim <vadim@vk.crocodile.org>
|
||||
|
||||
* ../src/fwbedit/merge.cpp: fixed bug #2794851 (fwbuilder bug
|
||||
#202): "Ability to import Library using fwbedit". User can now
|
||||
merge objects from two files together using fwbedit just like the
|
||||
"Import library" function in the GUI.
|
||||
|
||||
2009-12-07 vadim <vadim@vk.crocodile.org>
|
||||
|
||||
* instDialog_ui_ops.cpp (instDialog::getInstOptions): fixed bug
|
||||
|
||||
@ -155,6 +155,14 @@ data file and repairs it if necessary.
|
||||
-f file.fwb: data file
|
||||
|
||||
|
||||
.B merge -f file1.fwb -i file2.fwb
|
||||
|
||||
Objects from the file2.fwb are merged with objects in file1 and
|
||||
combined object tree saved in file1.fwb
|
||||
|
||||
-f file.fwb: data file #1
|
||||
-i file.fwb: data file #2
|
||||
|
||||
|
||||
.SH ATTRIBUTES FOR THE NEW OBJECTS, BY TYPE
|
||||
.PP
|
||||
|
||||
@ -98,6 +98,7 @@ extern int errno;
|
||||
#include "../common/init.cpp"
|
||||
|
||||
#include "fwbedit.h"
|
||||
#include "upgradePredicate.h"
|
||||
|
||||
using namespace libfwbuilder;
|
||||
using namespace std;
|
||||
@ -107,6 +108,8 @@ command cmd = NONE;
|
||||
|
||||
bool autoupgrade_flag = false;
|
||||
string filename = "";
|
||||
string filemerge = "";
|
||||
int conflict_res = 1;
|
||||
|
||||
vector<string> platforms;
|
||||
|
||||
@ -114,28 +117,6 @@ FWObjectDatabase *objdb = NULL;
|
||||
|
||||
int fwbdebug = 0;
|
||||
|
||||
class UpgradePredicate: public XMLTools::UpgradePredicate
|
||||
{
|
||||
public:
|
||||
virtual bool operator()(const string&) const
|
||||
{
|
||||
bool res=false;
|
||||
cout << "Data file has been created in the old version of Firewall Builder." << endl << flush;
|
||||
if (autoupgrade_flag)
|
||||
{
|
||||
cout << "Do you want to convert it? (Y/n)" << endl;
|
||||
int a = getchar();
|
||||
if (a=='y' || a=='Y' || a=='\n' ) res= true;
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Use option '-u' to upgrade the file. Alternatively,\nfwbuilder GUI can convert it." << endl;
|
||||
}
|
||||
if (res) cout << "Upgrading the file now ..." << endl;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
void usage()
|
||||
{
|
||||
cout << "Firewall Builder: general purpose object tree editing tool"
|
||||
@ -153,8 +134,8 @@ void usage()
|
||||
cout << " add add object to a group" << endl;
|
||||
cout << " remove remove object from a group" << endl;
|
||||
cout << " upgrade upgrade data file" << endl;
|
||||
cout << " checktree check object tree and repair if necessary"
|
||||
<< endl;
|
||||
cout << " checktree check object tree and repair if necessary" << endl;
|
||||
cout << " merge merge one data file into another" << endl;
|
||||
cout << endl;
|
||||
|
||||
cout << "Options:" << endl;
|
||||
@ -221,17 +202,30 @@ void usage()
|
||||
cout << endl;
|
||||
|
||||
cout <<
|
||||
" upgrade -f file.fwb\n"
|
||||
" upgrade -f file.fwb\n"
|
||||
"\n"
|
||||
" -f file.fwb: data file\n";
|
||||
cout << endl;
|
||||
|
||||
cout <<
|
||||
"checktree -f file.fwb\n"
|
||||
" checktree -f file.fwb\n"
|
||||
"\n"
|
||||
" -f file.fwb: data file\n";
|
||||
cout << endl;
|
||||
|
||||
cout <<
|
||||
" merge -f file1.fwb -i file2.fwb -c[1|2]\n"
|
||||
"\n"
|
||||
" -f file1.fwb: data file #1\n"
|
||||
" -i file2.fwb: data file #2\n"
|
||||
" -cN in case of conflict (the same object is found in both files),\n"
|
||||
" keep the object from the file N (can be '1' or '2').\n"
|
||||
" Default is '1'.\n"
|
||||
" Objects from the file2.fwb are merged with objects in file1\n"
|
||||
" and combined object tree saved in file1.fwb\n";
|
||||
|
||||
cout << endl;
|
||||
|
||||
cout << "Attributes for the new objects, by type:" << endl;
|
||||
cout << endl;
|
||||
cout << " "
|
||||
@ -410,6 +404,7 @@ int main(int argc, char * const *argv)
|
||||
if (cmd_str=="list") cmd = LIST;
|
||||
if (cmd_str=="upgrade") cmd = UPGRADE;
|
||||
if (cmd_str=="checktree") cmd = STRUCT;
|
||||
if (cmd_str=="merge") cmd = MERGE;
|
||||
|
||||
char * const *args = argv;
|
||||
args++;
|
||||
@ -536,6 +531,19 @@ int main(int argc, char * const *argv)
|
||||
}
|
||||
break;
|
||||
|
||||
case MERGE:
|
||||
// -f file1.fwb -i file2.fwb
|
||||
while( (opt=getopt(argc, args, "f:i:c:")) != EOF )
|
||||
{
|
||||
switch(opt)
|
||||
{
|
||||
case 'f': filename = optarg; break;
|
||||
case 'i': filemerge = optarg; break;
|
||||
case 'c': conflict_res = atoi(optarg); break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NONE:
|
||||
break;
|
||||
}
|
||||
@ -558,11 +566,20 @@ int main(int argc, char * const *argv)
|
||||
objdb = new FWObjectDatabase();
|
||||
|
||||
/* load the data file */
|
||||
UpgradePredicate upgrade_predicate;
|
||||
UpgradePredicate upgrade_predicate(autoupgrade_flag);
|
||||
|
||||
objdb->load(filename, &upgrade_predicate, librespath);
|
||||
|
||||
if (cmd == STRUCT)
|
||||
if (cmd == MERGE)
|
||||
{
|
||||
if (filemerge.empty())
|
||||
{
|
||||
usage();
|
||||
exit(1);
|
||||
}
|
||||
mergeTree(objdb, filemerge, conflict_res);
|
||||
}
|
||||
else if (cmd == STRUCT)
|
||||
{
|
||||
checkAndRepairTree(objdb);
|
||||
}
|
||||
@ -649,16 +666,16 @@ int main(int argc, char * const *argv)
|
||||
}
|
||||
|
||||
} catch(FWException &ex) {
|
||||
cerr << ex.toString() << endl;
|
||||
cerr << ex.toString() << endl;
|
||||
exit(1);
|
||||
} catch (std::string s) {
|
||||
cerr << s;
|
||||
cerr << s;
|
||||
exit(1);
|
||||
} catch (std::exception ex) {
|
||||
cerr << ex.what();
|
||||
cerr << ex.what();
|
||||
exit(1);
|
||||
} catch (...) {
|
||||
cerr << "Unsupported exception";
|
||||
cerr << "Unsupported exception";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
|
||||
// can't use 'DELETE' in this enum because it is degined somewhere on windows
|
||||
typedef enum { NONE, ADDGRP, REMGRP, DELOBJECT, NEWOBJECT, MODOBJECT,
|
||||
LIST, STRUCT, UPGRADE} command;
|
||||
LIST, STRUCT, UPGRADE, MERGE} command;
|
||||
|
||||
class OperandsError : public std::exception {};
|
||||
|
||||
@ -69,6 +69,9 @@ extern void modObject(libfwbuilder::FWObjectDatabase *objdb,
|
||||
|
||||
extern void checkAndRepairTree(libfwbuilder::FWObjectDatabase *objdb);
|
||||
|
||||
extern void mergeTree(libfwbuilder::FWObjectDatabase *objdb,
|
||||
const std::string &mergefile, int conflict_res);
|
||||
|
||||
extern int splitStr(char ch,std::string s, operands * ops);
|
||||
extern std::string getNextOpt(operands &ops);
|
||||
extern std::string fixPath(const std::string &obj_path);
|
||||
@ -80,4 +83,5 @@ extern void findObjects(const std::string &obj_path,
|
||||
extern bool getBool(std::string s);
|
||||
extern void usage();
|
||||
|
||||
extern std::string librespath;
|
||||
|
||||
|
||||
@ -6,8 +6,8 @@ include(../../qmake.inc)
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
SOURCES = fwbedit.cpp new_object.cpp repair_tree.cpp list_object.cpp
|
||||
HEADERS = ../../config.h fwbedit.h
|
||||
SOURCES = fwbedit.cpp new_object.cpp repair_tree.cpp list_object.cpp merge.cpp
|
||||
HEADERS = ../../config.h fwbedit.h upgradePredicate.h
|
||||
|
||||
TARGET = fwbedit
|
||||
|
||||
|
||||
78
src/fwbedit/merge.cpp
Normal file
78
src/fwbedit/merge.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2003 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
$Id$
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "../../config.h"
|
||||
#include "fwbuilder/libfwbuilder-config.h"
|
||||
#include "fwbuilder/Constants.h"
|
||||
#include "fwbuilder/ObjectGroup.h"
|
||||
#include "fwbuilder/ServiceGroup.h"
|
||||
#include "fwbuilder/IntervalGroup.h"
|
||||
|
||||
#include "fwbedit.h"
|
||||
#include "upgradePredicate.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace libfwbuilder;
|
||||
using namespace std;
|
||||
|
||||
|
||||
class MergeConflictRes :
|
||||
public libfwbuilder::FWObjectDatabase::ConflictResolutionPredicate
|
||||
{
|
||||
int conflict_res;
|
||||
public:
|
||||
MergeConflictRes(int cr) { conflict_res = cr; }
|
||||
virtual bool askUser(libfwbuilder::FWObject*, libfwbuilder::FWObject*)
|
||||
{
|
||||
return (conflict_res == 1);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void mergeTree(FWObjectDatabase *objdb, const string &mergefile, int conflict_res)
|
||||
{
|
||||
cout << "Merge objects from file " << mergefile << endl;
|
||||
|
||||
UpgradePredicate upgrade_predicate(false);
|
||||
|
||||
try
|
||||
{
|
||||
FWObjectDatabase *ndb = new FWObjectDatabase();
|
||||
ndb->load(mergefile, &upgrade_predicate, librespath);
|
||||
|
||||
FWObject *dobj = ndb->findInIndex(FWObjectDatabase::DELETED_OBJECTS_ID);
|
||||
if (dobj) ndb->remove(dobj, false);
|
||||
|
||||
MergeConflictRes mcr(conflict_res);
|
||||
objdb->merge(ndb, &mcr);
|
||||
delete ndb;
|
||||
|
||||
} catch(FWException &ex)
|
||||
{
|
||||
cerr << ex.toString() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
54
src/fwbedit/upgradePredicate.h
Normal file
54
src/fwbedit/upgradePredicate.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
|
||||
Firewall Builder
|
||||
|
||||
Copyright (C) 2003-2009 NetCitadel, LLC
|
||||
|
||||
Author: Vadim Kurland vadim@fwbuilder.org
|
||||
|
||||
$Id$
|
||||
|
||||
This program is free software which we release under the GNU General Public
|
||||
License. You may redistribute and/or modify this program under the terms
|
||||
of that license as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
To get a copy of the GNU General Public License, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
*/
|
||||
|
||||
#include "fwbuilder/XMLTools.h"
|
||||
|
||||
class UpgradePredicate: public libfwbuilder::XMLTools::UpgradePredicate
|
||||
{
|
||||
bool autoupgrade_flag;
|
||||
|
||||
public:
|
||||
UpgradePredicate(bool autoupgrade) { autoupgrade_flag = autoupgrade; }
|
||||
virtual bool operator()(const std::string&) const
|
||||
{
|
||||
bool res=false;
|
||||
std::cout << "Data file has been created in the old version of Firewall Builder."
|
||||
<< std::endl << std::flush;
|
||||
if (autoupgrade_flag)
|
||||
{
|
||||
std::cout << "Do you want to convert it? (Y/n)" << std::endl;
|
||||
int a = getchar();
|
||||
if (a=='y' || a=='Y' || a=='\n' ) res= true;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Use option '-u' to upgrade the file in fwbedit."
|
||||
" Alternatively, fwbuilder GUI can convert it." << std::endl;
|
||||
}
|
||||
if (res) std::cout << "Upgrading the file now ..." << std::endl;
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
@ -490,3 +490,13 @@ rule sets of this object rather than in the actual firewalls.
|
||||
<p>
|
||||
Added support for option "--random" in SNAT rules
|
||||
</p>
|
||||
|
||||
|
||||
<a name="fwbedit"></a>
|
||||
<h2>Changes in the command linbe tool fwbedit</h2>
|
||||
|
||||
<p>
|
||||
User can now <b>merge objects from two data files</b> together using
|
||||
command line tool <b>fwbedit</b> just like the "Import library"
|
||||
function in the GUI.
|
||||
</p>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user