-
Notifications
You must be signed in to change notification settings - Fork 0
/
fw_compat.py
75 lines (70 loc) · 2.46 KB
/
fw_compat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#
# Copyright (C) 2007, 2008 Red Hat, Inc.
# Authors:
# Thomas Woerner <twoerner@redhat.com>
#
# This program is free software; you can redistribute it and/or modify
# it under 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.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from fw_functions import getPortID, getServiceName
import fw_services
def convertToServices(config):
if len(config.services) > 0:
return
print _("Converting %s") % config.filename
services = config.services
ports = [ ]
matched = [ ]
for svc in fw_services.service_list:
_matched = [ ]
if config.ports:
all_matched = True
for (port, proto) in svc.ports:
id = getPortID(port)
name = getServiceName(port, proto)
if ((id,), proto) in config.ports:
_matched.append(((id,), proto))
elif ((port,), proto) in config.ports:
_matched.append(((port,), proto))
elif ((name,), proto) in config.ports:
_matched.append(((name,), proto))
else:
all_matched = False
else:
all_matched = False
if all_matched:
services.append(svc.key)
matched.extend(_matched)
del _matched
if config.ports:
for entry in config.ports:
if entry in matched:
continue
ports.append(entry)
del matched
if not hasattr(config, "no_ipsec") or not config.no_ipsec:
if not "ipsec" in services:
services.append("ipsec")
else:
delattr(config, "no_ipsec")
if not hasattr(config, "no_mdns") or not config.no_mdns:
if not "mdns" in services:
services.append("mdns")
else:
delattr(config, "no_mdns")
if not hasattr(config, "no_ipp") or not config.no_ipp:
if not "ipp" in services:
services.append("ipp")
else:
delattr(config, "no_ipp")
config.ports = ports