~ubuntu-branches/ubuntu/maverick/gui-ufw/maverick

« back to all changes in this revision

Viewing changes to model/Variable.py

  • Committer: Bazaar Package Importer
  • Author(s): Devid Antonio Filoni
  • Date: 2010-03-15 22:19:04 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20100315221904-bsiaax6ayc9j124o
Tags: 10.04.2-0ubuntu1
* New upstream release (LP: #538649).
* Do not install /etc/gufw/*.cfg anymore, only remove /etc/gufw/gufw.cfg if
  needed (remove debian/postinst).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Gufw 10.04.1 - http://gufw.tuxfamily.org
2
 
# Copyright (C) 2009 Marcos Alvarez Costales
3
 
#
4
 
# Gufw is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 3 of the License, or
7
 
# (at your option) any later version.
8
 
9
 
# Gufw is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with Gufw; if not, see http://www.gnu.org/licenses for more
16
 
# information. 
17
 
 
18
 
 
19
 
import locale
20
 
import gettext
21
 
import sys
22
 
import gtk
23
 
 
24
 
 
25
 
class Variable:
26
 
 
27
 
    def __init__(self):
28
 
 
29
 
        # Run in develoment mode? (--dev parameter)
30
 
        self.dev = False
31
 
        for parameter in sys.argv:
32
 
            if parameter == "--dev":
33
 
                self.dev = True
34
 
 
35
 
        if self.dev:
36
 
            DIR = sys.path[0] + "/locale-langpack"
37
 
        else:
38
 
            DIR = "/usr/share/locale-langpack"
39
 
        _ = gettext.gettext
40
 
        gettext.bindtextdomain("gufw", DIR)
41
 
        gettext.textdomain("gufw")
42
 
        gtk.glade.bindtextdomain("gufw", DIR)
43
 
        gtk.glade.textdomain("gufw")
44
 
 
45
 
            
46
 
        # Define Texts
47
 
        self.texts = { "001" : _("To"),
48
 
                       "002" : _("Action"),
49
 
                       "003" : _("From"),
50
 
                       "004" : _("Gufw Log Enabled"),
51
 
                       "005" : _("Gufw Log Disabled"),
52
 
                       "006" : _("Deny all INCOMING traffic"),
53
 
                       "007" : _("Allow all INCOMING traffic"),
54
 
                       "008" : _("Enabled Firewall"),
55
 
                       "009" : _("Disabled Firewall"),
56
 
                       "010" : _("Select rule(s)"),
57
 
                       "011" : _("Reject all INCOMING traffic"),
58
 
                       "012" : _("Error performing operation"),
59
 
                       "013" : _("Rule added"),
60
 
                       "014" : _("Rule removed"),
61
 
                       "015" : _("Error: Insert a port number"),
62
 
                       "016" : _("Error: Fields filled out incorrectly"),
63
 
                       "017" : _("Error: Range ports only with tcp or udp protocol"),
64
 
                       "018" : _("You must run Gufw as root => gksu gufw"),
65
 
                       "019" : _("Rules removed"),
66
 
                       "020" : _("Rules added"),
67
 
                       "021" : _("Deny all OUTGOING traffic"),
68
 
                       "022" : _("Allow all OUTGOING traffic"),
69
 
                       "023" : _("Reject all OUTGOING traffic"),
70
 
                       "024" : _("Removed rules and reset firewall!"),
71
 
                       "025" : _("You will remove all rules and reset the firewall!"),
72
 
                       "026" : _("Do you want to continue?"),
73
 
                       "027" : _("Remove all rules"),
74
 
                       "028" : _("Deny In"),
75
 
                       "029" : _("Allow In"),
76
 
                       "030" : _("Limit In"),
77
 
                       "031" : _("Reject In"),
78
 
                       "032" : _("Deny Out"),
79
 
                       "033" : _("Allow Out"),
80
 
                       "034" : _("Limit Out"),
81
 
                       "035" : _("Reject Out"),
82
 
                       "036" : _("Deny"),
83
 
                       "037" : _("Allow"),
84
 
                       "038" : _("Limit"),
85
 
                       "039" : _("Reject"),
86
 
                       "040" : _("Anywhere"),
87
 
                       "041" : _("log-all"),
88
 
                       "042" : _("log") }
89
 
        
90
 
        # Define constants
91
 
        self.constants = {"disabled"            : "disabled",
92
 
                          "enabled"             : "enabled",
93
 
                          "none"                : "none",
94
 
                          "deny"                : "deny",
95
 
                          "deny_upper"          : "DENY",
96
 
                          "deny_in_upper"       : "DENY IN",
97
 
                          "deny_out_upper"      : "DENY OUT",
98
 
                          "allow"               : "allow",
99
 
                          "allow_upper"         : "ALLOW",
100
 
                          "allow_in_upper"      : "ALLOW IN",
101
 
                          "allow_out_upper"     : "ALLOW OUT",
102
 
                          "limit"               : "limit",
103
 
                          "limit_upper"         : "LIMIT",
104
 
                          "limit_in_upper"      : "LIMIT IN",
105
 
                          "limit_out_upper"     : "LIMIT OUT",
106
 
                          "reject"              : "reject",
107
 
                          "reject_upper"        : "REJECT",
108
 
                          "reject_in_upper"     : "REJECT IN",
109
 
                          "reject_out_upper"    : "REJECT OUT",
110
 
                          "tcp"                 : "tcp",
111
 
                          "udp"                 : "udp",
112
 
                          "both"                : "both",
113
 
                          "ufw_log_low"         : "ufw_log_low",
114
 
                          "ufw_log_medium"      : "ufw_log_medium",
115
 
                          "ufw_log_high"        : "ufw_log_high",
116
 
                          "ufw_log_full"        : "ufw_log_full",
117
 
                          "ufw_log_off"         : "ufw_log_off",
118
 
                          "ufw_log_on"          : "ufw_log_on",
119
 
                          "gufw_log_on"         : "gufw_log_on",
120
 
                          "gufw_log_off"        : "gufw_log_off",
121
 
                          "service_enabled"     : "service_enabled",
122
 
                          "service_disabled"    : "service_disabled",
123
 
                          "font_rules"          : "monospace 10",
124
 
                          "color_gray"          : "#b0b0b0",
125
 
                          "color_green"         : "#28ab2b",
126
 
                          "color_red"           : "#e31818",
127
 
                          "color_orange"        : "#e57f1b",
128
 
                          "color_blue"          : "#19308b",
129
 
                          "window_width"        : 336,
130
 
                          "window_height"       : 404,
131
 
                          "translators_credits" : _("translator-credits"),
132
 
                          "rule_added"          : "Rule added",
133
 
                          "rule_updated"        : "Rule updated",
134
 
                          "rule_deleted"        : "Rule deleted",
135
 
                          "any"                 : "any",
136
 
                          "anywhere"            : "Anywhere",
137
 
                          "service_yes"         : "yes",
138
 
                          "service_no"          : "service_no",
139
 
                          "in"                  : "in",
140
 
                          "out"                 : "out",
141
 
                          "log"                 : "log",
142
 
                          "log-all"             : "log-all",
143
 
                          "log-default"         : "log-default" }
144
 
        
145
 
        # Define paths
146
 
        self.paths = { "glade"    : sys.path[0] + "/glade/gufw.glade",
147
 
                       "pid_file" : "/tmp/gufw.pid",
148
 
        
149
 
                       "shield_allow_allow_dev"   : sys.path[0] + "/pixmaps/allow_allow.png",
150
 
                       "shield_allow_deny_dev"    : sys.path[0] + "/pixmaps/allow_deny.png",
151
 
                       "shield_allow_disable_dev" : sys.path[0] + "/pixmaps/allow_disable.png",
152
 
                       "shield_allow_reject_dev"  : sys.path[0] + "/pixmaps/allow_reject.png",
153
 
                       
154
 
                       "shield_deny_allow_dev"   : sys.path[0] + "/pixmaps/deny_allow.png",
155
 
                       "shield_deny_deny_dev"    : sys.path[0] + "/pixmaps/deny_deny.png",
156
 
                       "shield_deny_disable_dev" : sys.path[0] + "/pixmaps/deny_disable.png",
157
 
                       "shield_deny_reject_dev"  : sys.path[0] + "/pixmaps/deny_reject.png",
158
 
                       
159
 
                       "shield_disable_allow_dev"   : sys.path[0] + "/pixmaps/disable_allow.png",
160
 
                       "shield_disable_deny_dev"    : sys.path[0] + "/pixmaps/disable_deny.png",
161
 
                       "shield_disable_disable_dev" : sys.path[0] + "/pixmaps/disable_disable.png",
162
 
                       "shield_disable_reject_dev"  : sys.path[0] + "/pixmaps/disable_reject.png",
163
 
                       
164
 
                       "shield_reject_allow_dev"   : sys.path[0] + "/pixmaps/reject_allow.png",
165
 
                       "shield_reject_deny_dev"    : sys.path[0] + "/pixmaps/reject_deny.png",
166
 
                       "shield_reject_disable_dev" : sys.path[0] + "/pixmaps/reject_disable.png",
167
 
                       "shield_reject_reject_dev"  : sys.path[0] + "/pixmaps/reject_reject.png",
168
 
                       
169
 
                       "shield_allow_allow"   : "/usr/share/pixmaps/gufw/allow_allow.png",
170
 
                       "shield_allow_deny"    : "/usr/share/pixmaps/gufw/allow_deny.png",
171
 
                       "shield_allow_disable" : "/usr/share/pixmaps/gufw/allow_disable.png",
172
 
                       "shield_allow_reject"  : "/usr/share/pixmaps/gufw/allow_reject.png",
173
 
                       
174
 
                       "shield_deny_allow"   : "/usr/share/pixmaps/gufw/deny_allow.png",
175
 
                       "shield_deny_deny"    : "/usr/share/pixmaps/gufw/deny_deny.png",
176
 
                       "shield_deny_disable" : "/usr/share/pixmaps/gufw/deny_disable.png",
177
 
                       "shield_deny_reject"  : "/usr/share/pixmaps/gufw/deny_reject.png",
178
 
                       
179
 
                       "shield_disable_allow"   : "/usr/share/pixmaps/gufw/disable_allow.png",
180
 
                       "shield_disable_deny"    : "/usr/share/pixmaps/gufw/disable_deny.png",
181
 
                       "shield_disable_disable" : "/usr/share/pixmaps/gufw/disable_disable.png",
182
 
                       "shield_disable_reject"  : "/usr/share/pixmaps/gufw/disable_reject.png",
183
 
                       
184
 
                       "shield_reject_allow"   : "/usr/share/pixmaps/gufw/reject_allow.png",
185
 
                       "shield_reject_deny"    : "/usr/share/pixmaps/gufw/reject_deny.png",
186
 
                       "shield_reject_disable" : "/usr/share/pixmaps/gufw/reject_disable.png",
187
 
                       "shield_reject_reject"  : "/usr/share/pixmaps/gufw/reject_reject.png" }                           
188
 
                                    
189
 
        # Define Commands
190
 
        self.commands = { "enabled"                : "LANGUAGE=C ufw enable",
191
 
                          "disabled"               : "LANGUAGE=C ufw disable",
192
 
                          "status"                 : "LANGUAGE=C ufw status",
193
 
                          "status_verbose"         : "LANGUAGE=C ufw status verbose",
194
 
                          "deny_incoming"          : "LANGUAGE=C ufw default deny incoming",
195
 
                          "allow_incoming"         : "LANGUAGE=C ufw default allow incoming",
196
 
                          "reject_incoming"        : "LANGUAGE=C ufw default reject incoming",
197
 
                          "deny_outgoing"          : "LANGUAGE=C ufw default deny outgoing",
198
 
                          "allow_outgoing"         : "LANGUAGE=C ufw default allow outgoing",
199
 
                          "reject_outgoing"        : "LANGUAGE=C ufw default reject outgoing",
200
 
                          "search_policy_incoming" : "LANGUAGE=C grep DEFAULT_INPUT_POLICY /etc/default/ufw",
201
 
                          "search_policy_outgoing" : "LANGUAGE=C grep DEFAULT_OUTPUT_POLICY /etc/default/ufw",
202
 
                          "ufw_log_off"            : "LANGUAGE=C ufw logging off",
203
 
                          "ufw_log_on"             : "LANGUAGE=C ufw logging on",
204
 
                          "ufw_log_low"            : "LANGUAGE=C ufw logging low",
205
 
                          "ufw_log_medium"         : "LANGUAGE=C ufw logging medium",
206
 
                          "ufw_log_high"           : "LANGUAGE=C ufw logging high",
207
 
                          "ufw_log_full"           : "LANGUAGE=C ufw logging full",
208
 
                          "reset_all_rules"        : "LANGUAGE=C ufw --force reset",
209
 
                          "remove_rule"            : "LANGUAGE=C ufw --force delete &number",
210
 
                          "add_complete_rule"      : "LANGUAGE=C ufw insert &insert &action &direction &log proto &protocol from &fromIP port &fromPort to &toIP port &toPort",
211
 
                          "add_short_rule"         : "LANGUAGE=C ufw insert &insert &action &direction &log &toPort",
212
 
                          
213
 
                          "refresh_log_files"      : "LANGUAGE=C rm /var/log/gufw_log.txt && rm /var/log/gufw_log_server.txt" ,
214
 
                          "append_log_file"        : "LANGUAGE=C echo '&' >> /var/log/gufw_log.txt",
215
 
                          "append_log_file_server" : "LANGUAGE=C echo '&' >> /var/log/gufw_log_server.txt",
216
 
                          "get_log_file"           : "LANGUAGE=C cat /var/log/gufw_log.txt",
217
 
                          "get_log_file_server"    : "LANGUAGE=C cat /var/log/gufw_log_server.txt",
218
 
                          "cfg_gufw_log"           : "LANGUAGE=C grep log=enabled /etc/gufw/gufw.cfg",
219
 
                          "gufw_log_on"            : "LANGUAGE=C sed -i 's/^log=disabled/log=enabled/' /etc/gufw/gufw.cfg",
220
 
                          "gufw_log_off"           : "LANGUAGE=C sed -i 's/^log=enabled/log=disabled/' /etc/gufw/gufw.cfg",
221
 
                          "read_size_win"          : "LANGUAGE=C cat /etc/gufw/size_window.cfg",
222
 
                          "save_size_win"          : 'LANGUAGE=C rm /etc/gufw/size_window.cfg && echo "width=&1;height=&2" > /etc/gufw/size_window.cfg',
223
 
                          
224
 
                          "refresh_log_files_dev"      : "LANGUAGE=C rm cfg_files/gufw_log.txt && rm cfg_files/gufw_log_server.txt" ,
225
 
                          "append_log_file_dev"        : "LANGUAGE=C echo '&' >> cfg_files/gufw_log.txt",
226
 
                          "append_log_file_server_dev" : "LANGUAGE=C echo '&' >> cfg_files/gufw_log_server.txt",
227
 
                          "get_log_file_dev"           : "LANGUAGE=C cat cfg_files/gufw_log.txt",
228
 
                          "get_log_file_server_dev"    : "LANGUAGE=C cat cfg_files/gufw_log_server.txt",
229
 
                          "cfg_gufw_log_dev"           : "LANGUAGE=C grep log=enabled cfg_files/gufw.cfg",
230
 
                          "gufw_log_on_dev"            : "LANGUAGE=C sed -i 's/^log=disabled/log=enabled/' cfg_files/gufw.cfg",
231
 
                          "gufw_log_off_dev"           : "LANGUAGE=C sed -i 's/^log=enabled/log=disabled/' cfg_files/gufw.cfg",
232
 
                          "read_size_win_dev"          : "LANGUAGE=C cat cfg_files/size_window.cfg",
233
 
                          "save_size_win_dev"          : 'LANGUAGE=C rm cfg_files/size_window.cfg && echo "width=&1;height=&2" > cfg_files/size_window.cfg' }
234
 
                          
235
 
        # Define Programs (Split by #)
236
 
        self.programs = { "Amule"        : "4662tcp#4672udp",
237
 
                          "Deluge"       : "6881:6891tcp",
238
 
                          "Nicotine"     : "2234:2239tcp#2242tcp",
239
 
                          "Transmission" : "51413tcp",
240
 
                          "KTorrent"     : "6881tcp#4444udp",
241
 
                          "qBittorrent"  : "6881:6889tcp" }
242
 
 
243
 
        # Define Services 
244
 
        self.services = { "HTTP"        : "http",
245
 
                          "Samba"       : "135,139,445tcp|137,138udp",
246
 
                          "ssh"         : "ssh",
247
 
                          "NFS"         : "nfs",
248
 
                          "VNC"         : "5900tcp",
249
 
                          "FTP"         : "ftp",
250
 
                          "IMAP"        : "imap",
251
 
                          "POP3"        : "pop3",
252
 
                          "SMTP"        : "smtp",
253
 
                          "Telnet"      : "telnet" }
254
 
                          
255
 
    # Return a constant
256
 
    def get_constant(self, name):
257
 
       return self.constants[name]
258
 
       
259
 
       
260
 
    # Return a Path
261
 
    def get_path(self, path):
262
 
        return self.paths[path]
263
 
 
264
 
    # Return a Text
265
 
    def get_text(self, txt_number):
266
 
        return self.texts[txt_number]
267
 
 
268
 
 
269
 
    # Return a Command
270
 
    def get_command(self, cmd):
271
 
        return self.commands[cmd]
272
 
        
273
 
        
274
 
    # Return a Program
275
 
    def get_program(self, prg):
276
 
        return self.programs[prg]
277
 
 
278
 
    # Return a Service
279
 
    def get_service(self, srv):
280
 
        return self.services[srv]
281