1 /*
2 
3                           Firewall Builder
4 
5                  Copyright (C) 2009 NetCitadel, LLC
6 
7   Author:  Vadim Kurland     vadim@vk.crocodile.org
8 
9   $Id$
10 
11   This program is free software which we release under the GNU General Public
12   License. You may redistribute and/or modify this program under the terms
13   of that license as published by the Free Software Foundation; either
14   version 2 of the License, or (at your option) any later version.
15 
16   This program is distributed in the hope that it will be useful,
17   but WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   GNU General Public License for more details.
20 
21   To get a copy of the GNU General Public License, write to the Free Software
22   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23 
24 */
25 
26 #include "../../config.h"
27 
28 #include <fstream>
29 #include <iostream>
30 #include <algorithm>
31 #include <functional>
32 #include <stdexcept>
33 
34 #include <assert.h>
35 #include <string>
36 #include <cstring>
37 #include <iomanip>
38 
39 #include "fwbuilder/FWOptions.h"
40 #include "fwbuilder/Firewall.h"
41 #include "fwbuilder/Interface.h"
42 
43 #include "CompilerDriver_ipf.h"
44 
45 #include <QFileInfo>
46 #include <QDir>
47 
48 
49 using namespace std;
50 using namespace libfwbuilder;
51 using namespace fwcompiler;
52 
53 
CompilerDriver_ipf(FWObjectDatabase * db)54 CompilerDriver_ipf::CompilerDriver_ipf(FWObjectDatabase *db) :
55     CompilerDriver_pf(db)
56 {
57     have_nat = false;
58     have_filter = false;
59 }
60 
61 // create a copy of itself, including objdb
clone()62 CompilerDriver* CompilerDriver_ipf::clone()
63 {
64     CompilerDriver_ipf* new_cd = new CompilerDriver_ipf(objdb);
65     if (inEmbeddedMode()) new_cd->setEmbeddedMode();
66     return new_cd;
67 }
68 
printActivationCommandWithSubstitution(Firewall * fw)69 QString CompilerDriver_ipf::printActivationCommandWithSubstitution(Firewall *fw)
70 {
71     QString script_buffer;
72     QTextStream str(&script_buffer, QIODevice::WriteOnly);
73 
74     FWObjectTypedChildIterator j=fw->findByType(Interface::TYPENAME);
75     for ( ; j!=j.end(); ++j )
76     {
77         Interface *iface=Interface::cast(*j);
78         if ( iface->isDyn() )
79         {
80             str << "sed \"s/ (" << iface->getName() << ") "
81                 << "/ $i_" << iface->getName() << " /\"";
82         }
83     }
84     return script_buffer;
85 }
86 
87