1 /*
2 
3                           Firewall Builder
4 
5                  Copyright (C) 2003 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 "definitions.h"
28 #include "global.h"
29 #include "utils_no_qt.h"
30 #include "utils.h"
31 
32 #include <qobject.h>
33 #include <qtextstream.h>
34 #include <qdatetime.h>
35 #include <qregexp.h>
36 #include <QtDebug>
37 
38 #include "FWObjectPropertiesFactory.h"
39 #include "platforms.h"
40 #include "DialogFactory.h"
41 #include "FWBTree.h"
42 
43 #include "fwbuilder/AddressRange.h"
44 #include "fwbuilder/AddressTable.h"
45 #include "fwbuilder/CustomService.h"
46 #include "fwbuilder/DNSName.h"
47 #include "fwbuilder/DynamicGroup.h"
48 #include "fwbuilder/FWException.h"
49 #include "fwbuilder/FWObjectDatabase.h"
50 #include "fwbuilder/FWReference.h"
51 #include "fwbuilder/Firewall.h"
52 #include "fwbuilder/Group.h"
53 #include "fwbuilder/Host.h"
54 #include "fwbuilder/ICMP6Service.h"
55 #include "fwbuilder/ICMPService.h"
56 #include "fwbuilder/IPService.h"
57 #include "fwbuilder/IPv4.h"
58 #include "fwbuilder/IPv6.h"
59 #include "fwbuilder/Interface.h"
60 #include "fwbuilder/Interval.h"
61 #include "fwbuilder/Library.h"
62 #include "fwbuilder/Network.h"
63 #include "fwbuilder/NetworkIPv6.h"
64 #include "fwbuilder/ObjectGroup.h"
65 #include "fwbuilder/Policy.h"
66 #include "fwbuilder/Resources.h"
67 #include "fwbuilder/Rule.h"
68 #include "fwbuilder/RuleSet.h"
69 #include "fwbuilder/TCPService.h"
70 #include "fwbuilder/TagService.h"
71 #include "fwbuilder/UDPService.h"
72 #include "fwbuilder/UserService.h"
73 #include "fwbuilder/physAddress.h"
74 #include "fwbuilder/StateSyncClusterGroup.h"
75 #include "fwbuilder/FailoverClusterGroup.h"
76 #include "fwbuilder/Cluster.h"
77 
78 #include <sstream>
79 #include <iostream>
80 #include <time.h>
81 
82 
83 using namespace std;
84 using namespace libfwbuilder;
85 
86 /*
87  * This method returns brief summary of properties, guaranteed to be 1
88  * line of text
89  */
getObjectPropertiesBrief(FWObject * obj)90 QString FWObjectPropertiesFactory::getObjectPropertiesBrief(FWObject *obj)
91 {
92     QString res;
93     QTextStream str(&res, QIODevice::WriteOnly);
94     FWObject *parent_obj = obj->getParent();
95 
96     try
97     {
98         if (Library::isA(obj))
99         {
100             if (obj->isReadOnly()) str << "(read only)";
101 
102         } else if (IPv4::isA(obj))
103         {
104             str <<  IPv4::cast(obj)->getAddressPtr()->toString().c_str();
105             if (parent_obj && Interface::isA(parent_obj))
106             {
107                 str << "/";
108                 str << IPv4::cast(obj)->getNetmaskPtr()->toString().c_str();
109             }
110         } else if (IPv6::isA(obj))
111         {
112             str <<  IPv6::cast(obj)->getAddressPtr()->toString().c_str();
113             if (parent_obj && Interface::isA(parent_obj))
114             {
115                 str << "/";
116                 str << QString("%1").arg(IPv6::cast(obj)->getNetmaskPtr()->getLength());
117             }
118         } else if (physAddress::isA(obj))
119         {
120             str <<  physAddress::cast(obj)->getPhysAddress().c_str();
121         } else if (DNSName::isA(obj))
122         {
123             str << DNSName::cast(obj)->getSourceName().c_str();
124         } else if (AddressTable::isA(obj))
125         {
126             str << AddressTable::cast(obj)->getSourceName().c_str();
127         } else if (AddressRange::isA(obj))
128         {
129             AddressRange *ar=AddressRange::cast(obj);
130             str << ar->getRangeStart().toString().c_str();
131             str << " - ";
132             str << ar->getRangeEnd().toString().c_str();
133         } else if (Firewall::cast(obj))
134         {
135             if (Firewall::cast(obj)->needsCompile()) str << " * ";
136             QString platform = obj->getStr("platform").c_str();
137             QString version  = obj->getStr("version").c_str();
138             QString readableVersion = getVersionString(platform,version);
139             QString hostOS = obj->getStr("host_OS").c_str();
140             str <<  platform << "(" << readableVersion << ") / " << hostOS;
141 
142         } else if (Host::isA(obj))
143         {
144             const InetAddr *addr = Address::cast(obj)->getAddressPtr();
145             if (addr)
146                 str <<  addr->toString().c_str();
147             else
148                 str << "(no ip address)";
149         } else if (Network::isA(obj))
150         {
151             Network *n=Network::cast(obj);
152             str << n->getAddressPtr()->toString().c_str();
153             str << "/";
154             str << n->getNetmaskPtr()->toString().c_str();
155 
156         } else if (NetworkIPv6::isA(obj))
157         {
158             NetworkIPv6 *n=NetworkIPv6::cast(obj);
159             str << n->getAddressPtr()->toString().c_str();
160             str << "/";
161             str << QString("%1").arg(n->getNetmaskPtr()->getLength());
162 
163         } else if (ClusterGroup::cast(obj)!=NULL)
164         {
165             ClusterGroup *g = ClusterGroup::cast(obj);
166             str << QObject::tr("type: ") << g->getStr("type").c_str();
167         } else if (Group::cast(obj)!=NULL)   // just any group
168         {
169             Group *g=Group::cast(obj);
170             str << g->size() << " " << QObject::tr(" objects");
171 
172         } else if (Interface::isA(obj))
173         {
174             Interface *intf = Interface::cast(obj);
175             // trigger late initialization of options object
176             // if its read-only or part of the read-only tree, I can't help it.
177             if (!obj->isReadOnly()) intf->getOptionsObject();
178             str << intf->getLabel().c_str() << " ";
179 
180             QStringList q;
181 
182             FWObject *parent = Host::getParentHost(intf);
183             //FWObject *parent = intf->getParentHost();
184             if (parent)
185             {
186                 bool supports_security_levels = false;
187                 bool supports_network_zones   = false;
188                 try
189                 {
190                     supports_security_levels =
191                         (!parent->getStr("platform").empty() &&
192                          Resources::getTargetCapabilityBool(
193                              parent->getStr("platform"), "security_levels"));
194                     supports_network_zones =
195                         (!parent->getStr("platform").empty() &&
196                          Resources::getTargetCapabilityBool(
197                              parent->getStr("platform"), "network_zones"));
198                 } catch (FWException &ex)  { }
199 
200                 if (supports_security_levels)
201                 {
202                     QString str;
203                     str.setNum(intf->getSecurityLevel());
204                     q.push_back(QString("sec level: %1").arg(str));
205                 }
206                 if (supports_network_zones)
207                 {
208                     int id = FWObjectDatabase::getIntId(intf->getStr("network_zone"));
209                     if (id > 0)
210                     {
211                         FWObject *nz_obj = obj->getRoot()->findInIndex(id);
212                         if (nz_obj)
213                             q.push_back(
214                                 QString("network zone: %1")
215                                 .arg(nz_obj->getName().c_str()));
216                         else
217                             q.push_back(QString("network zone: not configured"));
218 
219                     }
220                 }
221             }
222 
223             if (intf->isDyn())         q.push_back("dyn");
224             if (intf->isUnnumbered())  q.push_back("unnum");
225             if (intf->isDedicatedFailover())  q.push_back("failover");
226             if (intf->isBridgePort())  q.push_back("bridge port");
227             if (intf->isSlave())       q.push_back("slave");
228             if (intf->isUnprotected()) q.push_back("unp");
229             if (!q.empty()) str << q.join(",");
230 
231         } else if (IPService::isA(obj))
232         {
233             str << QObject::tr("protocol: %1").arg(obj->getStr("protocol_num").c_str());
234 
235         } else if (ICMPService::isA(obj) || ICMP6Service::isA(obj))
236         {
237             str << QObject::tr("type: %1").arg(obj->getStr("type").c_str())
238                 << "  "
239                 << QObject::tr("code: %1").arg(obj->getStr("code").c_str());
240 
241         } else if (TCPService::isA(obj) || UDPService::isA(obj))
242         {
243             int sps,spe,dps,dpe;
244 
245             sps=TCPUDPService::cast(obj)->getSrcRangeStart();
246             spe=TCPUDPService::cast(obj)->getSrcRangeEnd();
247             dps=TCPUDPService::cast(obj)->getDstRangeStart();
248             dpe=TCPUDPService::cast(obj)->getDstRangeEnd();
249 
250             str << sps << ":" << spe << " / ";
251             str << dps << ":" << dpe;
252         } else if (TagService::isA(obj))
253         {
254             str << "Pattern: \"" << obj->getStr("tagcode").c_str() << "\"" ;
255         } else if (UserService::isA(obj))
256         {
257             const UserService* user_srv = UserService::constcast(obj);
258             str << "User id: \"" << user_srv->getUserId().c_str() << "\"" ;
259         } else if (RuleSet::cast(obj) != NULL)
260         {
261             QStringList attrs;
262             RuleSet *rs = RuleSet::cast(obj);
263             if (rs->isTop()) attrs.push_back("top ruleset");
264             if (rs->isDual()) attrs.push_back("ipv4/ipv6");
265             else
266             {
267                 if (rs->isV4()) attrs.push_back("ipv4");
268                 if (rs->isV6()) attrs.push_back("ipv6");
269             }
270             attrs.push_back(QString("%1 rules").arg(rs->getRuleSetSize()));
271             str << attrs.join(" ");
272         } else if (Interval::isA(obj))
273         {
274 
275         }
276     } catch (FWException &ex)
277     {
278         cerr << ex.toString() << endl;
279     }
280 
281     return QString::fromUtf8(res.toStdString().c_str());
282 }
283 
284 /*
285  * More detailed list of properties, still one line, no fancy
286  * formatting and no HTML. This is used in object group list view and
287  * for printing.
288  */
getObjectProperties(FWObject * obj)289 QString FWObjectPropertiesFactory::getObjectProperties(FWObject *obj)
290 {
291     QString res;
292     QTextStream str(&res, QIODevice::WriteOnly);
293     FWObject *parent_obj = obj->getParent();
294 
295     try
296     {
297         if (IPv4::isA(obj))
298         {
299             str <<  IPv4::cast(obj)->getAddressPtr()->toString().c_str();
300             if (parent_obj && Interface::isA(parent_obj))
301             {
302                 str << "/";
303                 str << IPv4::cast(obj)->getNetmaskPtr()->toString().c_str();
304             }
305         } else if (IPv6::isA(obj))
306         {
307             str <<  IPv6::cast(obj)->getAddressPtr()->toString().c_str();
308             if (parent_obj && Interface::isA(parent_obj))
309             {
310                 str << "/";
311                 str << QString("%1").arg(IPv6::cast(obj)->getNetmaskPtr()->getLength());
312             }
313         } else if (physAddress::isA(obj))
314         {
315             str <<  physAddress::cast(obj)->getPhysAddress().c_str();
316         } else if (DNSName::isA(obj))
317         {
318             str << QObject::tr("DNS record: ")
319                 << DNSName::cast(obj)->getSourceName().c_str();
320         } else if (AddressTable::isA(obj))
321         {
322             str << QObject::tr("Address Table: ")
323                 << AddressTable::cast(obj)->getSourceName().c_str();
324         } else if (AddressRange::isA(obj))
325         {
326             AddressRange *ar=AddressRange::cast(obj);
327             str << ar->getRangeStart().toString().c_str();
328             str << " - ";
329             str << ar->getRangeEnd().toString().c_str();
330         } else if (Firewall::cast(obj))
331         {
332             QString platform = obj->getStr("platform").c_str();
333             QString version  = obj->getStr("version").c_str();
334             QString readableVersion = getVersionString(platform,version);
335             QString hostOS = obj->getStr("host_OS").c_str();
336 
337             QDateTime dt;
338             time_t t;
339 
340             t = obj->getInt("lastModified");dt.setTime_t(t);
341             QString t_modified  = (t)? dt.toString():"-";
342 
343             t = obj->getInt("lastCompiled");dt.setTime_t(t);
344             QString t_compiled  = (t)? dt.toString():"-";
345 
346             t = obj->getInt("lastInstalled");dt.setTime_t(t);
347             QString t_installed = (t)? dt.toString():"-";
348 
349             str <<  platform << "(" << readableVersion << ") / " << hostOS;
350 
351         } else if (Host::isA(obj))
352         {
353             const InetAddr *addr = Address::cast(obj)->getAddressPtr();
354             if (addr)
355                 str <<  addr->toString().c_str();
356             else
357                 str << "(no ip address)";
358 
359             FWObject *co=obj->getFirstByType("Interface");
360             if (co!=NULL)
361             {
362                 physAddress *paddr=(Interface::cast(co))->getPhysicalAddress();
363                 if (paddr!=NULL)
364                     str << "    " <<  paddr->getPhysAddress().c_str();
365             }
366 
367         } else if (Network::isA(obj))
368         {
369             Network *n=Network::cast(obj);
370             str << QString("%1/%2")
371                 .arg(n->getAddressPtr()->toString().c_str())
372                 .arg(n->getNetmaskPtr()->toString().c_str());
373 
374         } else if (NetworkIPv6::isA(obj))
375         {
376             NetworkIPv6 *n=NetworkIPv6::cast(obj);
377             str << QString("%1/%2")
378                 .arg(n->getAddressPtr()->toString().c_str())
379                 .arg(n->getNetmaskPtr()->getLength());
380 
381         } else if (ClusterGroup::cast(obj)!=NULL)
382         {
383             ClusterGroup *g = ClusterGroup::cast(obj);
384             str << QObject::tr("Type: ") << g->getStr("type").c_str() << " ";
385             QStringList members;
386             FWObjectTypedChildIterator j = obj->findByType(FWObjectReference::TYPENAME);
387             for ( ; j!=j.end(); ++j)
388             {
389                 FWObject *obj = FWReference::getObject(*j);
390                 if (Interface::cast(obj))
391                 {
392                     FWObject *fw = obj->getParent();
393                     members.push_back(
394                         QString("%1:%2")
395                         .arg(fw->getName().c_str()).arg(obj->getName().c_str()));
396                 }
397             }
398             if (members.size() != 0)
399             {
400                 members.push_front(QObject::tr("Members:"));
401                 str << members.join(" ");
402             }
403         } else if (DynamicGroup::cast(obj) != 0) {
404             DynamicGroup *objGroup = DynamicGroup::cast(obj);
405             str << QObject::tr("%1 filters").arg(objGroup->getFilter().size());
406         } else if (Group::cast(obj)!=NULL)   // just any group
407         {
408             Group *g=Group::cast(obj);
409             str << QObject::tr("%1 objects").arg(g->size());
410         } else if (Firewall::cast(obj))
411         {
412 
413         } else if (Interface::isA(obj))
414         {
415             Interface *intf = Interface::cast(obj);
416             QString label = QString::fromUtf8(intf->getLabel().c_str());
417             if (label != "")
418                 str << QObject::tr("Label: %1").arg(label) << " ";
419 
420             QString intf_type = intf->getOptionsObject()->getStr("type").c_str();
421             if (intf_type != "" && intf_type.toLower() != "ethernet")
422                 str << QObject::tr("Type: ") << intf_type << " ";
423 
424             QStringList addr;
425             FWObjectTypedChildIterator j = obj->findByType(IPv4::TYPENAME);
426             for ( ; j!=j.end(); ++j)
427             {
428                 addr << getObjectProperties(*j);
429             }
430             if (addr.size() != 0)
431             {
432                 if (addr.size() > 1)
433                     addr.push_front(QObject::tr("Addresses:"));
434                 else
435                     addr.push_front(QObject::tr("Address:"));
436                 str << addr.join(" ");
437             }
438         } else if (IPService::isA(obj))
439         {
440             str << QObject::tr("protocol: %1").arg(obj->getStr("protocol_num").c_str());
441 
442         } else if (ICMPService::isA(obj) || ICMP6Service::isA(obj))
443         {
444             str << QObject::tr("type: %1").arg(obj->getStr("type").c_str())
445                 << "  "
446                 << QObject::tr("code: %1").arg(obj->getStr("code").c_str());
447 
448         } else if (TCPService::isA(obj) || UDPService::isA(obj))
449         {
450             int sps,spe,dps,dpe;
451 
452             sps=TCPUDPService::cast(obj)->getSrcRangeStart();
453             spe=TCPUDPService::cast(obj)->getSrcRangeEnd();
454             dps=TCPUDPService::cast(obj)->getDstRangeStart();
455             dpe=TCPUDPService::cast(obj)->getDstRangeEnd();
456 
457             str << sps << ":" << spe << " / ";
458             str << dps << ":" << dpe;
459         } else if (TagService::isA(obj))
460         {
461             str << QObject::tr("Pattern: \"%1\"").arg(obj->getStr("tagcode").c_str());
462         } else if (UserService::isA(obj))
463         {
464             const UserService* user_srv = UserService::constcast(obj);
465             str << QObject::tr("User id: \"%1\"").arg(user_srv->getUserId().c_str());
466         } else if (Interval::isA(obj))
467         {
468 
469         }
470     } catch (FWException &ex)
471     {
472         cerr << ex.toString() << endl;
473     }
474 
475     return res;
476 }
477 
478 
stripHTML(const QString & str)479 QString FWObjectPropertiesFactory::stripHTML(const QString &str)
480 {
481     // note that str may contain multiple lines
482     // separated by <br> and/or '\n'
483 
484     QRegExp htmltag1 = QRegExp("<[^>]+>");
485     QRegExp htmltag2 = QRegExp("</[^>]+>");
486     QRegExp htmltd   = QRegExp("</td><td>");
487 
488     QString res = str;
489     res = res.replace(htmltd,": ");
490     res = res.remove(htmltag1);
491     res = res.remove(htmltag2);
492     return res;
493 }
494 
495 /*
496  * Nicely formatted list of properties, HTML. This one is used for the
497  * tree tooltips.
498  */
getObjectPropertiesDetailed(FWObject * obj,bool showPath,bool tooltip,bool accentName,bool richText)499 QString FWObjectPropertiesFactory::getObjectPropertiesDetailed(FWObject *obj,
500                                                                bool showPath,
501                                                                bool tooltip,
502                                                                bool accentName,
503                                                                bool richText)
504 {
505     QString str;
506     FWObject *parent_obj = obj->getParent();
507 
508     QString path = obj->getPath().c_str();
509     path = path.section('/',2,-1);
510 
511     if (obj->getId() == FWObjectDatabase::ANY_ADDRESS_ID ||
512         obj->getId() == FWObjectDatabase::ANY_SERVICE_ID ||
513         obj->getId() == FWObjectDatabase::ANY_INTERVAL_ID)
514     {
515         return "to modify this field drag and \ndrop an object from the tree here";
516     }
517 
518     if (showPath)
519     {
520         str += QObject::tr("<b>Library:</b> ");
521         str += QString::fromUtf8(obj->getLibrary()->getName().c_str()) + "<br>\n";
522 
523         if (!tooltip)
524         {
525             str += QObject::tr("<b>Object Id:</b> ");
526             str += QString(FWObjectDatabase::getStringId(obj->getId()).c_str()) + "<br>\n";
527         }
528     }
529 
530     if (FWBTree().isSystem(obj))
531     {
532         QString object_path = obj->getPath(true).c_str();
533 
534         if (object_path == "Objects")
535             return QObject::tr("This system folder holds objects that represent <b>IPv4</b> and <b>IPv6</b> addresses and networks");
536 
537         if (object_path == "Objects/Addresses")
538             return QObject::tr("This system folder holds objects that represent <b>IPv4</b> and <b>IPv6</b> addresses");
539 
540         if (object_path == "Objects/DNS Names")
541             return QObject::tr("This system folder holds objects that represent <b>DNS A</b> records");
542 
543         if (object_path == "Objects/Address Tables")
544             return QObject::tr("This system folder holds objects that read <b>IP addresses</b> from external files");
545 
546         if (object_path == "Objects/Address Ranges")
547             return QObject::tr("This system folder holds objects that represent <b>IPv4</b> and <b>IPv6</b> address ranges");
548 
549         if (object_path == "Objects/Groups")
550             return QObject::tr("This system folder holds objects that represent groups of <b>IPv4</b> and <b>IPv6</b> addresses, networks and other groups");
551 
552         if (object_path == "Objects/Hosts")
553             return QObject::tr("This system folder holds objects that represent <b>hosts</b> or <b>servers</b> that have one or more interfaces");
554 
555         if (object_path == "Objects/Networks")
556             return QObject::tr("This system folder holds objects that represent <b>IPv4</b> and <b>IPv6</b> networks");
557 
558         if (object_path == "Services")
559             return QObject::tr("This system folder holds objects that represent <b>IP, ICMP, TCP and UDP</b> services");
560 
561         if (object_path == "Services/Groups")
562             return QObject::tr("This system folder holds objects that represent groups of <b>IP, ICMP, TCP and UDP</b> services");
563 
564         if (object_path == "Services/Custom")
565             return QObject::tr("This system folder holds objects that represent <b>custom (user-defined)</b> services");
566 
567         if (object_path == "Services/IP")
568             return QObject::tr("This system folder holds objects that represent <b>IP</b> services");
569 
570         if (object_path == "Services/ICMP")
571             return QObject::tr("This system folder holds objects that represent <b>ICMP</b> and <b>ICMPv6</b> services");
572 
573         if (object_path == "Services/TCP")
574             return QObject::tr("This system folder holds objects that represent <b>TCP</b> services");
575 
576         if (object_path == "Services/UDP")
577             return QObject::tr("This system folder holds objects that represent <b>UDP</b> services");
578 
579         if (object_path == "Services/Users")
580             return QObject::tr("This system folder holds objects that represent <b>user names</b>");
581 
582         if (object_path == "Services/TagServices")
583             return QObject::tr("This system folder holds objects that represent <b>tags</b>");
584 
585         if (object_path == "Firewalls")
586             return QObject::tr("This system folder holds objects that represent <b>firewalls</b>");
587 
588         if (object_path ==  "Clusters")
589             return QObject::tr("This system folder holds objects that represent firewall <b>clusters</b>");
590 
591         if (object_path ==  "Time")
592             return QObject::tr("This system folder holds objects that represent <b>time intervals</b>");
593 
594     }
595 
596 
597     if (Library::isA(obj))
598     {
599         switch (obj->getId())
600         {
601         case FWObjectDatabase::STANDARD_LIB_ID:
602             return QObject::tr("<html>A library of predefined read-only address and service objects that come with the program</html>");
603             ;
604 
605         case FWObjectDatabase::DELETED_OBJECTS_ID:
606             return QObject::tr("<html>This library holds objects that have been deleted. You can undelete them by clicking right mouse button and using menu item 'Move to ...' to move them back to another library</html>");
607             ;
608 
609         default:
610             return QObject::tr("<html>A library of user-defined objects; this is where you create your objects</html>");
611         }
612 
613     }
614 
615     str += QObject::tr("<b>Object Type:</b> ");
616     string d = Resources::global_res->getObjResourceStr(obj,"description");
617     str += QString(d.c_str()) + "<br>\n";
618 
619     str += QObject::tr("<b>Object Name:</b> ");
620     if (accentName) str += "<font color=\"red\">";
621     str += QString::fromUtf8(obj->getName().c_str());
622     if (accentName) str += "</font>";
623     str += "<br>\n";
624 
625     try
626     {
627         if (IPv4::isA(obj))
628         {
629             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
630             str +=  IPv4::cast(obj)->getAddressPtr()->toString().c_str();
631             if (parent_obj && Interface::isA(parent_obj))
632             {
633                 str += "/";
634                 str += IPv4::cast(obj)->getNetmaskPtr()->toString().c_str();
635             }
636         } else if (IPv6::isA(obj))
637         {
638             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
639             str +=  IPv6::cast(obj)->getAddressPtr()->toString().c_str();
640             if (parent_obj && Interface::isA(parent_obj))
641             {
642                 str += "/";
643                 str += QString("%1").arg(IPv6::cast(obj)->getNetmaskPtr()->getLength());
644             }
645         } else if (physAddress::isA(obj))
646         {
647             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
648             str += physAddress::cast(obj)->getPhysAddress().c_str();
649         } else if (DNSName::isA(obj))
650         {
651             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
652             str += QObject::tr("<b>DNS record:</b>");
653             str += MultiAddress::cast(obj)->getSourceName().c_str();
654             str += "<br>\n";
655             str += (MultiAddress::cast(obj)->isRunTime())?QObject::tr("Run-time"):QObject::tr("Compile-time");
656 
657         } else if (AddressTable::isA(obj))
658         {
659             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
660             str += QObject::tr("<b>Table file:</b>");
661             str += MultiAddress::cast(obj)->getSourceName().c_str();
662             str += "<br>\n";
663             str += (MultiAddress::cast(obj)->isRunTime())?QObject::tr("Run-time"):QObject::tr("Compile-time");
664 
665         } else if (AddressRange::isA(obj))
666         {
667             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
668             AddressRange *ar=AddressRange::cast(obj);
669             str += ar->getRangeStart().toString().c_str();
670             str += " - ";
671             str += ar->getRangeEnd().toString().c_str();
672         } else if (Host::isA(obj))
673         {
674             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
675 
676             FWObjectTypedChildIterator j = obj->findByType(
677                 Interface::TYPENAME);
678             for ( ; j!=j.end(); ++j)
679             {
680                 str += (*j)->getName().c_str();
681                 str += ": ";
682                 str += getObjectProperties(*j);
683                 str += "<br>";
684             }
685         } else if (Network::isA(obj))
686         {
687             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
688             Network *n=Network::cast(obj);
689             str += n->getAddressPtr()->toString().c_str();
690             str += "/";
691             str += n->getNetmaskPtr()->toString().c_str();
692 
693         } else if (NetworkIPv6::isA(obj))
694         {
695             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
696             NetworkIPv6 *n=NetworkIPv6::cast(obj);
697             str += n->getAddressPtr()->toString().c_str();
698             str += "/";
699             str += QString("%1").arg(n->getNetmaskPtr()->getLength());
700         } else if (ClusterGroup::cast(obj)!=NULL)
701         {
702             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
703             ClusterGroup *g = ClusterGroup::cast(obj);
704             str += QObject::tr("type: %1<br>").arg(g->getStr("type").c_str());
705             FWObjectTypedChildIterator j = obj->findByType(FWObjectReference::TYPENAME);
706             for ( ; j!=j.end(); ++j)
707             {
708                 FWObject *obj = FWReference::getObject(*j);
709                 if (Interface::cast(obj))
710                 {
711                     FWObject *fw = obj->getParent();
712                     str += QObject::tr("Group member %1:%2<br>").
713                         arg(fw->getName().c_str()).arg(obj->getName().c_str());
714                 }
715             }
716         } else if (DynamicGroup::cast(obj) != 0) {
717             DynamicGroup *objGroup = DynamicGroup::cast(obj);
718             str += QObject::tr("%1 filters<br>\n").arg(objGroup->getFilter().size());
719         } else if (Group::cast(obj)!=NULL)   // just any group
720         {
721             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
722             Group *g = Group::cast(obj);
723             str += QObject::tr("%1 objects<br>\n").arg(g->size());
724             int n = 0;
725             list<FWObject*> ll = *g;
726             ll.sort(FWObjectNameCmpPredicate());
727 
728             for (FWObject::iterator i=ll.begin(); i!=ll.end(); ++i,++n)
729             {
730                 if (n>20)  // arbitrary number
731                 {
732                     str += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.&nbsp;.&nbsp;.&nbsp;";
733                     break;
734                 } else
735                 {
736                     FWObject *o1=*i;
737                     if (FWReference::cast(o1)!=NULL)
738                         o1=FWReference::cast(o1)->getPointer();
739                     str += QString(o1->getTypeName().c_str())
740                         + "  <b>" + QString::fromUtf8(o1->getName().c_str()) + "</b><br>\n";
741                 }
742             }
743         } else if (Firewall::cast(obj))
744         {
745             // Note: Firewall::cast(obj) matched Firewall and Cluster
746             QString platform = obj->getStr("platform").c_str();
747             QString version  = obj->getStr("version").c_str();
748             QString readableVersion = getVersionString(platform,version);
749             QString hostOS = obj->getStr("host_OS").c_str();
750 
751             QDateTime dt;
752             time_t lm=obj->getInt("lastModified");
753             time_t lc=obj->getInt("lastCompiled");
754             time_t li=obj->getInt("lastInstalled");
755 
756             dt.setTime_t(lm);
757             QString t_modified  = (lm)? dt.toString():"-";
758             if (lm>lc && lm>li) t_modified=QString("<b>")+t_modified+"</b>";
759 
760             dt.setTime_t(lc);
761             QString t_compiled  = (lc)? dt.toString():"-";
762             if (lc>lm && lc>li) t_compiled=QString("<b>")+t_compiled+"</b>";
763 
764             dt.setTime_t(li);
765             QString t_installed = (li)? dt.toString():"-";
766             if (li>lc && li>lm) t_installed=QString("<b>")+t_installed+"</b>";
767 
768 
769 
770             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
771             str += "<table cellspacing=\"0\" cellpadding=\"0\">";
772             str += QString("<tr><td>Platform:</td><td>") +
773                 platform + "</td></tr>\n";
774             str += QString("<tr><td>Version:</td><td>")  +
775                 readableVersion + "</td></tr>\n";
776             str += QString("<tr><td>Host OS:</td><td>")  +
777                 hostOS + "</td></tr>\n";
778 
779             str += QString("<tr><td>Modified:</td><td>")  +
780                 t_modified + "</td></tr>\n";
781             str += QString("<tr><td>Compiled:</td><td>")  +
782                 t_compiled + "</td></tr>\n";
783             str += QString("<tr><td>Installed:</td><td>")  +
784                 t_installed + "</td></tr>\n";
785 
786             str += "</table>";
787         } else if (Interface::isA(obj))
788         {
789             FWObject *parent_host = obj;
790             QStringList short_path;
791             //short_path.push_front(QString::fromUtf8(obj->getName().c_str()));
792             do
793             {
794                 parent_host = parent_host->getParent();
795                 if (parent_host == NULL) break;
796                 short_path.push_front(QString::fromUtf8(parent_host->getName().c_str()));
797             }
798             while (Host::cast(parent_host) == NULL);
799 
800             str += QString("<b>Parent: </b>%1<br>\n").arg(short_path.join("/"));
801 
802             Interface *intf = Interface::cast(obj);
803             str += "<b>Label: </b>";
804             str += QString::fromUtf8(intf->getLabel().c_str());
805             str += "<br>";
806 
807             FWObjectTypedChildIterator j = obj->findByType(IPv4::TYPENAME);
808             for ( ; j!=j.end(); ++j)
809             {
810                 str += getObjectProperties(*j);
811                 str += "<br>";
812             }
813 
814             string intf_type = intf->getOptionsObject()->getStr("type");
815             if (!intf_type.empty())
816             {
817                 str += "<b>Interface Type: </b>";
818                 str += intf_type.c_str();
819                 if (intf_type == "8021q")
820                 {
821                     int vlan_id = intf->getOptionsObject()->getInt("vlan_id");
822                     str += QString(" VLAN ID=%1").arg(vlan_id);
823                 }
824                 str += "<br>";
825             }
826 
827             physAddress *paddr = intf->getPhysicalAddress();
828             if (paddr!=NULL)
829             {
830                 str += "MAC: ";
831                 str +=  paddr->getPhysAddress().c_str() ;
832                 str += "<br>";
833             }
834 
835             QString q;
836             if (intf->isDyn())        q=" dyn";
837             if (intf->isUnnumbered()) q=" unnum";
838             if (intf->isBridgePort()) q=" bridge port";
839 
840             FWObject *p=obj;
841             while (p!=NULL && !Firewall::cast(p)) p=p->getParent();
842             if (p!=NULL && (p->getStr("platform")=="pix" || p->getStr("platform")=="fwsm"))
843             {
844                 int sl = intf->getSecurityLevel();
845                 q=q+QString("sec.level %1").arg(sl);
846             }
847 
848             if (intf->isUnprotected())    q=q+" unp";
849 
850             if (q!="") str += " (" + q + ")";
851             str += "<br>\n";
852             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
853 
854         } else if (CustomService::isA(obj))
855         {
856 
857             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
858 
859             CustomService *s = dynamic_cast<CustomService*>(obj);
860             bool first=true;
861 
862             map<string,string> platforms = Resources::getPlatforms();
863             for (map<string,string>::iterator i=platforms.begin(); i!=platforms.end(); i++)
864             {
865                 string c=s->getCodeForPlatform( (*i).first );
866                 if ( c!="" )
867                 {
868                     if (first)
869                     {
870                         str += "<table cellspacing=\"0\" cellpadding=\"0\">";
871                         first=false;
872                     }
873                     str += QString("<tr><td>%1</td><td>%2</td></tr>\n")
874                         .arg((*i).second.c_str()).arg(c.c_str());
875                 }
876             }
877             if (!first) str += "</table>";
878 
879         } else if (IPService::isA(obj))
880         {
881             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
882             str += QObject::tr("protocol ") + obj->getStr("protocol_num").c_str();
883 
884         } else if (ICMPService::isA(obj) || ICMP6Service::isA(obj))
885         {
886             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
887             str += QObject::tr("type: ") + obj->getStr("type").c_str()
888                 + "  "
889                 + QObject::tr("code: ") + obj->getStr("code").c_str();
890 
891         } else if (TCPService::isA(obj) || UDPService::isA(obj))
892         {
893             int sps,spe,dps,dpe;
894 
895             sps=TCPUDPService::cast(obj)->getSrcRangeStart();
896             spe=TCPUDPService::cast(obj)->getSrcRangeEnd();
897             dps=TCPUDPService::cast(obj)->getDstRangeStart();
898             dpe=TCPUDPService::cast(obj)->getDstRangeEnd();
899 
900             if (showPath && !tooltip) str += "<b>Path: </b>" + path + "<br>\n";
901             str += "<table cellspacing=\"0\" cellpadding=\"0\">";
902             str += QString("<tr><td>source port range</td><td>%1:%2</td></tr>\n")
903                 .arg(sps).arg(spe);
904             str += QString("<tr><td>destination port range</td><td>%1:%2</td></tr>\n")
905                 .arg(dps).arg(dpe);
906             str += "</table>";
907         } else if (TagService::isA(obj))
908         {
909             str += QObject::tr("Pattern: \"%1\"").arg(obj->getStr("tagcode").c_str());
910         } else if (UserService::isA(obj))
911         {
912             const UserService* user_srv = UserService::constcast(obj);
913             str += QObject::tr("User id: \"%1\"").arg(user_srv->getUserId().c_str());
914         } else if (Interval::isA(obj))
915         {
916 
917         }
918     } catch (FWException &ex)
919     {
920         cerr << ex.toString() << endl;
921     }
922 
923     if (richText) return str;
924 
925     return FWObjectPropertiesFactory::stripHTML(str);
926 }
927 
928 /*
929  * Do not translate literals 'pipe', 'queue', 'divert' below, these refer
930  * to actual ipfw parameters and should not be localized.
931  */
getRuleActionProperties(Rule * rule)932 QString FWObjectPropertiesFactory::getRuleActionProperties(Rule *rule)
933 {
934     QString par = "";
935 
936     if (rule!=NULL)
937     {
938         QString act = getRuleAction(rule);
939 
940         FWObject *o = rule;
941         while (o!=NULL && Firewall::cast(o)==NULL) o=o->getParent();
942         if (o==NULL) return "";
943 
944         Firewall *f=Firewall::cast(o);
945         string platform=f->getStr("platform");
946 
947         FWOptions *ropt = rule->getOptionsObject();
948         string editor = DialogFactory::getActionDialogPageName(f, rule);
949 
950         if (editor == "None") return "";
951 
952         if (PolicyRule::isA(rule))
953         {
954             switch (PolicyRule::cast(rule)->getAction())
955             {
956             case PolicyRule::Reject:
957                 par = ropt->getStr("action_on_reject").c_str();
958                 break;
959             case PolicyRule::Accounting :
960                 par = ropt->getStr("rule_name_accounting").c_str();
961                 break;
962             case PolicyRule::Custom:
963                 par = ropt->getStr("custom_str").c_str();
964                 break;
965             case PolicyRule::Branch:
966             {
967                 FWObject *branch_ruleset = rule->getBranch();
968                 if (branch_ruleset)
969                     par = branch_ruleset->getName().c_str();
970                 // ropt->getStr("branch_name").c_str();
971                 break;
972             }
973             case PolicyRule::Pipe :
974                 if (platform=="ipfw")
975                 {
976                     par = QString("divert ") +
977                         ropt->getStr("ipfw_pipe_port_num").c_str();
978                 }
979                 break;
980 
981             default : {}
982             }
983         }
984 
985         if (NATRule::isA(rule))
986         {
987             switch (NATRule::cast(rule)->getAction())
988             {
989             case NATRule::Translate:
990                 break;
991 
992             case NATRule::Branch:
993                 FWObject *branch_ruleset = rule->getBranch();
994                 if (branch_ruleset)
995                     par = branch_ruleset->getName().c_str();
996                 break;
997             }
998         }
999     }
1000 
1001     return par;
1002 }
1003 
getRuleActionPropertiesRich(Rule * rule)1004 QString FWObjectPropertiesFactory::getRuleActionPropertiesRich(Rule *rule)
1005 {
1006     FWObject *p=rule;
1007     while (p!=NULL && !Firewall::cast(p)) p=p->getParent();
1008     if (p==NULL)
1009     {
1010         qDebug() << "FWObjectPropertiesFactory::getRuleActionPropertiesRich(): "
1011                  << "Can not locate parent firewall for the rule:";
1012         rule->dump(false, true);
1013         return "";
1014     }
1015 
1016     string platform=p->getStr("platform");
1017     QString act = getActionNameForPlatform(Firewall::cast(p), rule);
1018     QString par = getRuleActionProperties(rule);
1019     QString res = QObject::tr("<b>Action   :</b> %1<br>").arg(act);
1020     if (!par.isEmpty())
1021     {
1022         res += QObject::tr("<b>Parameter:</b> %1").arg(par);
1023     }
1024     return res;
1025 }
1026 
getPolicyRuleOptions(Rule * rule)1027 QString FWObjectPropertiesFactory::getPolicyRuleOptions(Rule *rule)
1028 {
1029     if (rule == NULL) return "";
1030 
1031     QList<QPair<QString,QString> > options;
1032 
1033     PolicyRule *prule = PolicyRule::cast(rule);
1034     FWObject *o = rule;
1035     while (o!=NULL && Firewall::cast(o)==NULL) o = o->getParent();
1036     assert(o!=NULL);
1037     Firewall *f = Firewall::cast(o);
1038     string platform = f->getStr("platform");
1039     FWOptions *ropt = rule->getOptionsObject();
1040 
1041     if (platform!="iosacl" && platform!="procurve_acl")
1042     {
1043         if (ropt->getBool("stateless"))
1044         {
1045             options << qMakePair(QObject::tr("Stateless"), QString(""));
1046         } else
1047         {
1048             options << qMakePair(QObject::tr("Stateful"), QString(""));
1049         }
1050     }
1051 
1052     if (platform=="iptables")
1053     {
1054         if (prule)
1055         {
1056             if (prule->getTagging())
1057             {
1058                 options << qMakePair(QObject::tr("tag:"),
1059                                      QString(prule->getTagValue().c_str()));
1060             }
1061 
1062             if (prule->getClassification())
1063             {
1064                 options << qMakePair(QObject::tr("class:"),
1065                                      QString(ropt->getStr("classify_str").c_str()));
1066             }
1067         }
1068 
1069         if (!ropt->getStr("log_prefix").empty())
1070         {
1071             options << qMakePair(QObject::tr("Log prefix:"),
1072                                  QString(ropt->getStr("log_prefix").c_str()));
1073         }
1074 
1075         if (!ropt->getStr("log_level").empty())
1076         {
1077             options << qMakePair(
1078                 QObject::tr("Log Level:"),
1079                 QString(getScreenName(ropt->getStr("log_level").c_str(),
1080                                       getLogLevels(platform.c_str()))));
1081         }
1082 
1083         if (ropt->getInt("ulog_nlgroup")>1)
1084         {
1085             options << qMakePair(
1086                 QObject::tr("Netlink group:"),
1087                 QString(ropt->getStr("ulog_nlgroup").c_str()));
1088         }
1089 
1090         if (ropt->getInt("limit_value")>0)
1091         {
1092             QString arg;
1093             if (ropt->getBool("limit_value_not")) arg = " ! ";
1094             arg += QString(ropt->getStr("limit_value").c_str());
1095             if (!ropt->getStr("limit_suffix").empty())
1096             {
1097                 arg += getScreenName(ropt->getStr("limit_suffix").c_str(),
1098                                      getLimitSuffixes(platform.c_str()));
1099             }
1100             options << qMakePair(QString("Limit value:"), arg);
1101         }
1102 
1103         if (ropt->getInt("limit_burst")>0)
1104         {
1105             options << qMakePair(QString("Limit burst:"),
1106                                  QString(ropt->getStr("limit_burst").c_str()));
1107         }
1108 
1109         if (ropt->getInt("connlimit_value")>0)
1110         {
1111             QString arg;
1112 
1113             if (ropt->getBool("connlimit_above_not")) arg = " ! ";
1114             arg += QString(ropt->getStr("connlimit_value").c_str());
1115 
1116             options << qMakePair(QObject::tr("connlimit value:"), arg);
1117         }
1118 
1119         if (ropt->getInt("hashlimit_value")>0)
1120         {
1121             QString arg;
1122             if (ropt->getBool("hashlimit_value_not")) arg = " ! ";
1123             arg += QString(ropt->getStr("hashlimit_value").c_str());
1124             if (!ropt->getStr("hashlimit_suffix").empty())
1125             {
1126                 arg += getScreenName(ropt->getStr("limit_suffix").c_str(),
1127                                      getLimitSuffixes(platform.c_str()));
1128             }
1129 
1130             options << qMakePair(
1131                 QString("hashlimit name:"),
1132                 QString(ropt->getStr("hashlimit_name").c_str()));
1133             options << qMakePair(QString("hashlimit value:"), arg);
1134 
1135             if (ropt->getInt("hashlimit_burst")>0)
1136             {
1137                 options << qMakePair(
1138                     QString("haslimit burst:"),
1139                     QString(ropt->getStr("hashlimit_burst").c_str()));
1140             }
1141         }
1142 
1143         if (ropt->getBool("firewall_is_part_of_any_and_networks"))
1144         {
1145             options << qMakePair(QObject::tr("Part of Any"), QString(""));
1146         }
1147 
1148 
1149     } else if (platform=="ipf")
1150     {
1151         if (!ropt->getStr("ipf_log_facility").empty())
1152         {
1153             options << qMakePair(
1154                 QObject::tr("Log facility:"),
1155                 QString(getScreenName(ropt->getStr("ipf_log_facility").c_str(),
1156                                       getLogFacilities(platform.c_str()))));
1157         }
1158 
1159         if (!ropt->getStr("log_level").empty())
1160         {
1161             options << qMakePair(
1162                 QObject::tr("Log level:"),
1163                 QString(getScreenName(ropt->getStr("log_level").c_str(),
1164                                       getLogLevels(platform.c_str()))));
1165         }
1166 
1167         if (ropt->getBool("ipf_return_icmp_as_dest"))
1168         {
1169             options << qMakePair(
1170                 QObject::tr("Send 'unreachable'"), QString(""));
1171         }
1172 
1173         if (ropt->getBool("ipf_keep_frags"))
1174         {
1175             options << qMakePair(
1176                 QObject::tr("Keep information on fragmented packets"),
1177                 QString(""));
1178         }
1179 
1180     }else if (platform=="pf")
1181     {
1182 
1183         if (prule)
1184         {
1185             if (prule->getTagging())
1186             {
1187                 options << qMakePair(QObject::tr("tag:"),
1188                                      QString(prule->getTagValue().c_str()));
1189             }
1190 
1191             if (prule->getClassification())
1192             {
1193                 options << qMakePair(QObject::tr("queue:"),
1194                                      QString(ropt->getStr("pf_classify_str").c_str()));
1195             }
1196         }
1197 
1198         if (!ropt->getStr("log_prefix").empty())
1199         {
1200             options << qMakePair(QObject::tr("Log prefix:"),
1201                                  QString(ropt->getStr("log_prefix").c_str()));
1202         }
1203 
1204         if (ropt->getInt("pf_rule_max_state")>0)
1205         {
1206             options << qMakePair(
1207                 QObject::tr("Max state:"),
1208                 QString(ropt->getStr("pf_rule_max_state").c_str()));
1209         }
1210 
1211         if (ropt->getBool("pf_keep_state"))
1212         {
1213             options << qMakePair(
1214                 QObject::tr("Force 'keep-state'"), QString(""));
1215         }
1216         if (ropt->getBool("pf_no_sync"))
1217         {
1218             options << qMakePair(QString("no-sync"), QString(""));
1219         }
1220         if (ropt->getBool("pf_pflow"))
1221         {
1222             options << qMakePair(QString("pflow"), QString(""));
1223         }
1224         if (ropt->getBool("pf_sloppy_tracker"))
1225         {
1226             options << qMakePair(QString("sloppy-tracker"), QString(""));
1227         }
1228 
1229         if (ropt->getBool("pf_source_tracking"))
1230         {
1231             options << qMakePair(
1232                 QObject::tr("Source tracking"), QString(""));
1233 
1234             options << qMakePair(
1235                 QObject::tr("Max src nodes:"),
1236                 QString(ropt->getStr("pf_max_src_nodes").c_str()));
1237 
1238             options << qMakePair(
1239                 QObject::tr("Max src states:"),
1240                 QString(ropt->getStr("pf_max_src_states").c_str()));
1241         }
1242 
1243         if (ropt->getBool("pf_synproxy"))
1244         {
1245             options << qMakePair(QString("synproxy"), QString(""));
1246         }
1247 
1248         if (ropt->getBool("pf_modulate_state"))
1249         {
1250             options << qMakePair(QString("modulate_state"), QString(""));
1251         }
1252 
1253     }else if (platform=="ipfw")
1254     {
1255         ;
1256     }else if (platform == "iosacl" || platform == "procurve_acl")
1257     {
1258         if (ropt->getBool("iosacl_add_mirror_rule"))
1259         {
1260             options << qMakePair(
1261                 QObject::tr("Add mirrored rule"), QString(""));
1262         }
1263 
1264     }else if (platform=="pix" || platform=="fwsm")
1265     {
1266         string vers = "version_"+f->getStr("version");
1267 
1268         options << qMakePair(QObject::tr("Version:"), QString(vers.c_str()));
1269 
1270         if ( Resources::platform_res[platform]->getResourceBool(
1271                  "/FWBuilderResources/Target/options/"+vers+"/pix_rule_syslog_settings"))
1272         {
1273 
1274             if (!ropt->getStr("log_level").empty())
1275             {
1276                 options << qMakePair(
1277                     QObject::tr("Log level:"),
1278                     QString(getScreenName(ropt->getStr("log_level").c_str(),
1279                                           getLogLevels(platform.c_str()))));
1280             }
1281             if (ropt->getInt("log_interval")>0)
1282             {
1283                 options << qMakePair(
1284                     QObject::tr("Log interval:"),
1285                     QString(ropt->getStr("log_interval").c_str()));
1286             }
1287 
1288             if (ropt->getBool("disable_logging_for_this_rule"))
1289             {
1290                 options << qMakePair(
1291                     QObject::tr("Disable logging for this rule"), QString(""));
1292             }
1293 
1294         }
1295     }
1296 
1297     if (prule)
1298         options << qMakePair(
1299             QObject::tr("Logging: "),
1300             (prule->getLogging()) ? QObject::tr("on") : QObject::tr("off"));
1301 
1302     QStringList res;
1303     res << "<table>";
1304     QList<QPair<QString,QString> >::iterator it;
1305     for (it=options.begin(); it!=options.end(); ++it)
1306     {
1307         QPair<QString,QString> p = *it;
1308         res << "<tr><th align='left'>" + p.first + "</th><td>" + p.second + "</td></tr>";
1309     }
1310     res << "</table>";
1311     QString html = res.join("\n");
1312     if (fwbdebug)
1313         qDebug() << html;
1314     return html;
1315 }
1316 
getNATRuleOptions(Rule * rule)1317 QString FWObjectPropertiesFactory::getNATRuleOptions(Rule *rule)
1318 {
1319     QString res;
1320 
1321     if (rule!=NULL)
1322     {
1323         res="";
1324         FWObject *o = rule;
1325         while (o!=NULL && Firewall::cast(o)==NULL) o=o->getParent();
1326         assert(o!=NULL);
1327         Firewall *f=Firewall::cast(o);
1328         string platform=f->getStr("platform");
1329         FWOptions *ropt = rule->getOptionsObject();
1330 
1331         if (fwbdebug)
1332             qDebug() << "getNATRuleOptions: platform: " << platform.c_str();
1333 
1334         if (platform=="iptables")
1335         {
1336             if (ropt->getBool("ipt_use_snat_instead_of_masq"))
1337                 res += QObject::tr("use SNAT instead of MASQ<br>");
1338             if (ropt->getBool("ipt_nat_random"))      res += QObject::tr("random<br>");
1339             if (ropt->getBool("ipt_nat_persistent"))  res += QObject::tr("persistent<br>");
1340         }
1341 
1342         if (platform=="pf")
1343         {
1344             if (ropt->getBool("pf_bitmask"))      res+=QObject::tr("bitmask<br>");
1345             if (ropt->getBool("pf_random"))       res+=QObject::tr("random<br>");
1346             if (ropt->getBool("pf_source_hash"))  res+=QObject::tr("source-hash<br>");
1347             if (ropt->getBool("pf_round_robin"))  res+=QObject::tr("round-robin<br>");
1348             if (!res.isEmpty()) res += ",";
1349             if (ropt->getBool("pf_static_port"))  res+=QObject::tr("static-port<br>");
1350         }
1351     }
1352 
1353     return res;
1354 }
1355 
getInterfaceNameExamplesForHostOS(const QString & host_os)1356 QString FWObjectPropertiesFactory::getInterfaceNameExamplesForHostOS(const QString &host_os)
1357 {
1358     Resources *os_resources = Resources::os_res[host_os.toStdString()];
1359     if (os_resources == NULL) return "";
1360     string os_family = os_resources-> getResourceStr("/FWBuilderResources/Target/family");
1361 
1362     if (os_family == "linux24" ||
1363         os_family == "ipcop"   ||
1364         os_family == "openwrt" ||
1365         os_family == "dd-wrt-nvram" ||
1366         os_family == "dd-wrt-jffs" ||
1367         os_family == "sveasoft") return "eth0, eth0.100, vlan100, br0, etc";
1368 
1369     if (os_family == "openbsd" ||
1370         os_family == "freebsd" ||
1371         os_family == "macosx") return "en0, fxp0, vlan100, etc";
1372 
1373     if (os_family == "ios" ||
1374         os_family == "pix_os") return "FastEthernet0/0, etc";
1375 
1376     if (os_family == "procurve") return "vlan 10, a1, b1, etc";
1377 
1378     return "";
1379 }
1380 
1381