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

« back to all changes in this revision

Viewing changes to src/model/GufwLog.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.2 - http://gufw.tuxfamily.org
 
2
# Copyright (C) 2008-2010 Marcos Alvarez Costales <marcos@softastur.org>
 
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
import time
 
19
import commands
 
20
 
 
21
 
 
22
class GufwLog:
 
23
    """Record and return Gufw Log"""
 
24
    def __init__(self):
 
25
        self.logging = self.get_ufw_logging()
 
26
    
 
27
    def get_ufw_logging(self):
 
28
        cmd = commands.getstatusoutput("grep log=enable /etc/gufw/gufw.cfg")
 
29
        if cmd[1].find("enable") != -1:
 
30
            return "enable"
 
31
        else:
 
32
            return "disable"
 
33
    
 
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)
 
44
        
 
45
    def get_log(self):
 
46
        """Return complete Gufw Log for local & server script"""
 
47
        cmd_local  = commands.getstatusoutput("cat /var/log/gufw_log.txt")
 
48
        if cmd_local[0] != 0:
 
49
            return "", ""
 
50
        cmd_server = commands.getstatusoutput("cat /var/log/gufw_log_server.txt")
 
51
        return cmd_local[1], cmd_server[1]
 
52
    
 
53
    def remove_log(self):
 
54
        """Remove complete Gufw Log"""
 
55
        commands.getstatusoutput("rm /var/log/gufw_log.txt && rm /var/log/gufw_log_server.txt")
 
56
    
 
57
    def get_logging(self):
 
58
        """Return the actual Gufw Log Status [enable|disable]"""
 
59
        return self.logging
 
60
        
 
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"
 
66
        else:
 
67
            commands.getstatusoutput("sed -i 's/log=disable/log=enable/' /etc/gufw/gufw.cfg")
 
68
            self.logging = "enable"
 
69
 
 
70