1 /*
2 
3                           Firewall Builder
4 
5                  Copyright (C) 2004 NetCitadel, LLC
6 
7   Author:  Vadim Kurland     vadim@fwbuilder.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 #include "global.h"
28 #include "platforms.h"
29 
30 #include "linux24AdvancedDialog.h"
31 #include "FWCmdChange.h"
32 
33 #include "fwbuilder/Firewall.h"
34 #include "fwbuilder/Management.h"
35 #include "fwbuilder/Resources.h"
36 
37 #include <memory>
38 
39 #include <qcheckbox.h>
40 #include <qspinbox.h>
41 #include <qcombobox.h>
42 #include <qradiobutton.h>
43 #include <qlineedit.h>
44 #include <qstackedwidget.h>
45 #include <qregexp.h>
46 #include <QUndoStack>
47 
48 #include "FWWindow.h"
49 #include "Help.h"
50 
51 using namespace std;
52 using namespace libfwbuilder;
53 
~linux24AdvancedDialog()54 linux24AdvancedDialog::~linux24AdvancedDialog()
55 {
56     delete m_dialog;
57 }
58 
linux24AdvancedDialog(QWidget * parent,FWObject * o)59 linux24AdvancedDialog::linux24AdvancedDialog(QWidget *parent,FWObject *o)
60     : QDialog(parent)
61 {
62     m_dialog = new Ui::linux24AdvancedDialog_q;
63     m_dialog->setupUi(this);
64     obj=o;
65 
66     string host_os = obj->getStr("host_OS");
67     string description = Resources::os_res[host_os]->
68         getResourceStr("/FWBuilderResources/Target/description");
69     setWindowTitle(QObject::tr("%1 advanced settings").arg(description.c_str()));
70 
71     FWOptions *fwopt=(Firewall::cast(obj))->getOptionsObject();
72     assert(fwopt!=NULL);
73 
74     Management *mgmt=(Firewall::cast(obj))->getManagementObject();
75     assert(mgmt!=NULL);
76 
77     QStringList threeStateMapping;
78 
79     threeStateMapping.push_back(QObject::tr("No change"));
80     threeStateMapping.push_back("");
81 
82     threeStateMapping.push_back(QObject::tr("On"));
83     threeStateMapping.push_back("1");
84 
85     threeStateMapping.push_back(QObject::tr("Off"));
86     threeStateMapping.push_back("0");
87 
88     data.registerOption( m_dialog->linux24_log_martians,
89                          fwopt,
90                          "linux24_log_martians", threeStateMapping);
91     data.registerOption( m_dialog->linux24_accept_redirects,
92                          fwopt,
93                          "linux24_accept_redirects", threeStateMapping);
94     data.registerOption( m_dialog->linux24_icmp_echo_ignore_all,
95                          fwopt,
96                          "linux24_icmp_echo_ignore_all", threeStateMapping);
97     data.registerOption( m_dialog->linux24_icmp_echo_ignore_broadcasts,
98                          fwopt,
99                          "linux24_icmp_echo_ignore_broadcasts",
100                          threeStateMapping);
101     data.registerOption( m_dialog->linux24_icmp_ignore_bogus_error_responses,
102                          fwopt,
103                          "linux24_icmp_ignore_bogus_error_responses",
104                          threeStateMapping);
105     data.registerOption( m_dialog->linux24_ip_dynaddr,
106                          fwopt,
107                          "linux24_ip_dynaddr", threeStateMapping);
108     data.registerOption( m_dialog->linux24_rp_filter,
109                          fwopt,
110                          "linux24_rp_filter", threeStateMapping);
111     data.registerOption( m_dialog->linux24_accept_source_route,
112                          fwopt,
113                          "linux24_accept_source_route", threeStateMapping);
114     data.registerOption( m_dialog->linux24_ip_forward,
115                          fwopt,
116                          "linux24_ip_forward", threeStateMapping);
117     data.registerOption( m_dialog->linux24_ipv6_forward,
118                          fwopt,
119                          "linux24_ipv6_forward", threeStateMapping);
120     data.registerOption( m_dialog->linux24_tcp_fin_timeout,
121                          fwopt,
122                          "linux24_tcp_fin_timeout" );
123     data.registerOption( m_dialog->linux24_tcp_keepalive_interval,
124                          fwopt,
125                          "linux24_tcp_keepalive_interval");
126     data.registerOption( m_dialog->linux24_tcp_window_scaling,
127                          fwopt,
128                          "linux24_tcp_window_scaling", threeStateMapping);
129     data.registerOption( m_dialog->linux24_tcp_sack,
130                          fwopt,
131                          "linux24_tcp_sack", threeStateMapping);
132     data.registerOption( m_dialog->linux24_tcp_fack,
133                          fwopt,
134                          "linux24_tcp_fack", threeStateMapping);
135     data.registerOption( m_dialog->linux24_tcp_ecn,
136                          fwopt,
137                          "linux24_tcp_ecn", threeStateMapping);
138     data.registerOption( m_dialog->linux24_tcp_syncookies,
139                          fwopt,
140                          "linux24_tcp_syncookies", threeStateMapping);
141     data.registerOption( m_dialog->linux24_tcp_timestamps,
142                          fwopt,
143                          "linux24_tcp_timestamps", threeStateMapping);
144     data.registerOption( m_dialog->linux24_path_iptables,
145                          fwopt,
146                          "linux24_path_iptables" );
147     data.registerOption( m_dialog->linux24_path_ip6tables,
148                          fwopt,
149                          "linux24_path_ip6tables" );
150     data.registerOption( m_dialog->linux24_path_ip,
151                          fwopt,
152                          "linux24_path_ip");
153     data.registerOption( m_dialog->linux24_path_lsmod,
154                          fwopt,
155                          "linux24_path_lsmod");
156     data.registerOption( m_dialog->linux24_path_logger,
157                          fwopt,
158                          "linux24_path_logger");
159     data.registerOption( m_dialog->linux24_path_vconfig,
160                          fwopt,
161                          "linux24_path_vconfig");
162     data.registerOption( m_dialog->linux24_path_brctl,
163                          fwopt,
164                          "linux24_path_brctl");
165     data.registerOption( m_dialog->linux24_path_ifenslave,
166                          fwopt,
167                          "linux24_path_ifenslave");
168     data.registerOption( m_dialog->linux24_path_modprobe,
169                          fwopt,
170                          "linux24_path_modprobe");
171     data.registerOption( m_dialog->linux24_path_ipset,
172                          fwopt,
173                          "linux24_path_ipset");
174     data.registerOption( m_dialog->linux24_path_iptables_restore,
175                          fwopt,
176                          "linux24_path_iptables_restore");
177     data.registerOption( m_dialog->linux24_path_ip6tables_restore,
178                          fwopt,
179                          "linux24_path_ip6tables_restore");
180 
181     data.registerOption(m_dialog->conntrack_max,
182                         fwopt,
183                         "linux24_conntrack_max");
184     data.registerOption(m_dialog->conntrack_hashsize,
185                         fwopt,
186                         "linux24_conntrack_hashsize");
187     data.registerOption(m_dialog->conntrack_tcp_be_liberal,
188                         fwopt,
189                         "linux24_conntrack_tcp_be_liberal", threeStateMapping);
190 
191     data.registerOption(m_dialog->linux24_data_dir, fwopt, "data_dir");
192 
193     data.loadAll();
194 
195     m_dialog->tabWidget->setCurrentIndex(0);
196 }
197 
198 /*
199  * store all data in the object
200  */
accept()201 void linux24AdvancedDialog::accept()
202 {
203     ProjectPanel *project = mw->activeProject();
204     std::auto_ptr<FWCmdChange> cmd( new FWCmdChange(project, obj));
205 
206     // new_state  is a copy of the fw object
207     FWObject* new_state = cmd->getNewState();
208     FWOptions* fwoptions = Firewall::cast(new_state)->getOptionsObject();
209     assert(fwoptions!=NULL);
210 
211     Management *mgmt = (Firewall::cast(new_state))->getManagementObject();
212     assert(mgmt!=NULL);
213 
214     data.saveAll(fwoptions);
215 
216     if (!Firewall::cast(cmd->getOldState())->getOptionsObject()->cmp(fwoptions, true))
217         project->undoStack->push(cmd.release());
218 
219     QDialog::accept();
220 }
221 
reject()222 void linux24AdvancedDialog::reject()
223 {
224     QDialog::reject();
225 }
226 
help()227 void linux24AdvancedDialog::help()
228 {
229     QString tab_title = m_dialog->tabWidget->tabText(
230         m_dialog->tabWidget->currentIndex());
231     QString anchor = tab_title.replace('/', '-').replace(' ', '-').toLower();
232     Help *h = Help::getHelpWindow(this);
233     h->setName("Host type Linux 2.4/2.6");
234     h->setSource(QUrl("linux24AdvancedDialog.html#" + anchor));
235     h->raise();
236     h->show();
237 }
238 
239 
240 
241