summaryrefslogtreecommitdiffstats
path: root/watcher.py
blob: 665d7792fe85f49373dd2cb6624b03da464e0f60 (plain)
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
# cobbler mod_python handler for observing kickstart activity
# 
# Copyright 2007, Red Hat, Inc
# Michael DeHaan <mdehaan@redhat.com>
# 
# This software may be freely redistributed under the terms of the GNU
# general public license.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import time
from mod_python import apache

def outputfilter(filter):

    # open the logfile (directory be set writeable by installer)
    logfile = open("/var/log/cobbler/cobbler.log","a+")

    # extract important info    
    request = filter.req
    connection = request.connection

    if request.the_request.find("cobbler_track") == -1:
        # skip URL's not related to kickstart tracking
        filter.close()
        return

    # write the timestamp
    t = time.gmtime()
    seconds = str(time.mktime(t))
    logfile.write(seconds)
    logfile.write("\t")
    timestr = str(time.asctime(t))
    logfile.write(timestr)
    logfile.write("\t")

    # write the IP address of the client
    (address,port) = connection.remote_addr
    logfile.write(address)
    logfile.write("\t")

    # write the filename being requested
    logfile.write(request.the_request)
    # logfile.write(request.filename)
    logfile.write("\n")

    # if requesting this file, don't return it
    if request.the_request.find("watcher.py") != -1:
        filter.close()
        return

    # pass-through filter
    s = filter.read()
    while s:
        filter.write(s)
        s = filter.read()
    if s is None:
        filter.close()
    logfile.close()