1
# Gufw 10.04.2 - http://gufw.tuxfamily.org
2
# Copyright (C) 2008-2010 Marcos Alvarez Costales <marcos@softastur.org>
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.
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.
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
23
"""Record and return Gufw Log"""
25
self.logging = self.get_ufw_logging()
27
def get_ufw_logging(self):
28
cmd = commands.getstatusoutput("grep log=enable /etc/gufw/gufw.cfg")
29
if cmd[1].find("enable") != -1:
34
def add_log(self, command):
35
"""Add a command to Gufw Log"""
36
if self.logging == "enable":
37
# Add log to Gufw log file
38
msg = "[" + time.strftime('%x %X') + "] " + command
39
cmd = "echo '&' >> /var/log/gufw_log.txt".replace("&", msg)
40
commands.getstatusoutput(cmd)
41
# Add log to Gufw server script log
42
cmd = "echo '&' >> /var/log/gufw_log_server.txt".replace("&", command)
43
commands.getstatusoutput(cmd)
46
"""Return complete Gufw Log for local & server script"""
47
cmd_local = commands.getstatusoutput("cat /var/log/gufw_log.txt")
50
cmd_server = commands.getstatusoutput("cat /var/log/gufw_log_server.txt")
51
return cmd_local[1], cmd_server[1]
54
"""Remove complete Gufw Log"""
55
commands.getstatusoutput("rm /var/log/gufw_log.txt && rm /var/log/gufw_log_server.txt")
57
def get_logging(self):
58
"""Return the actual Gufw Log Status [enable|disable]"""
61
def set_logging(self, logging):
62
"""Set the actual Gufw Log Status [enable|disable]"""
63
if logging == "disable":
64
commands.getstatusoutput("sed -i 's/log=enable/log=disable/' /etc/gufw/gufw.cfg")
65
self.logging = "disable"
67
commands.getstatusoutput("sed -i 's/log=disable/log=enable/' /etc/gufw/gufw.cfg")
68
self.logging = "enable"