Attachment 'WikiLog.py'

Download

   1 #!/usr/bin/env python
   2 # -*- coding: cp1251 -*-
   3 """
   4     Browse Wiki event-log for page requests.
   5     
   6     The macro also tries to resolve host names, if not found then host IP is given
   7 
   8     Usage:
   9         [[WikiLog(yyyy-mm-dd)]]
  10         where yyyy-mm-dd - day from which to start showing logs
  11         if no arguments given then showing for the last month
  12 
  13     @copyright: 2007 by Alexander "Loki" Agibalov
  14 """
  15 
  16 import os, sys, socket
  17 from MoinMoin.Page import Page
  18 from MoinMoin.logfile import eventlog, logfile
  19 from MoinMoin import wikiutil
  20 from datetime import datetime
  21 
  22 def execute(macro, args):
  23     request=macro.request
  24     _=macro.request.getText
  25     if not request.user.isSuperUser():
  26         return macro.formatter.text('Only a SuperUser can view this page!')
  27     if args is None:
  28         dNow0=datetime.now()
  29         if dNow0.month > 1:
  30             sargs=(dNow0.year, dNow0.month-1, dNow0.day)
  31         else:
  32             sargs=(dNow0.year-1, 12, dNow0.day)
  33         retTxt="<p><b>Page visits for the last month</b></p>"
  34     else:
  35         retTxt="<p><b>Page visits since %s</b></p>" % args
  36         sargs=args.split("-")
  37     event_log = eventlog.EventLog(request)
  38     try:
  39         logDate = event_log.date()
  40     except logfile.LogMissing:
  41         return macro.formatter.text('event log not found')
  42     event_log.set_filter(['VIEWPAGE'])
  43     sRet=retTxt
  44     sRet+="<table><tr><td>Date</td><td>Page</td><td>Host or IP</td><tr>"
  45     dHosts={}
  46     for event in event_log.reverse():
  47         date_tup=request.user.getTime(wikiutil.version2timestamp(event[0]))
  48         if int(date_tup[0]) < int(sargs[0]):
  49             break
  50         if (int(date_tup[0]) == int(sargs[0])) and (int(date_tup[1]) < int(sargs[1])):
  51             break
  52         if (int(date_tup[0]) == int(sargs[0])) and (int(date_tup[1]) == int(sargs[1])) and (int(date_tup[2]) <= int(sargs[2])):
  53             break
  54         sHost=str(event[2].get('REMOTE_ADDR', None))
  55         if not dHosts.has_key(sHost):
  56             try:
  57                 lHost=socket.gethostbyaddr(sHost)
  58                 dHosts[sHost]=lHost[0]
  59             except:
  60                 dHosts[sHost]=sHost
  61         sHost=dHosts[sHost]
  62         tmpSt="<tr><td>%s</td><td>%s</td><td>%s</td></tr>" % (request.user.getFormattedDateTime(wikiutil.version2timestamp(event[0])), event[2].get('pagename', None), sHost)
  63         sRet+=tmpSt
  64     sRet+="</table>"
  65     return macro.formatter.rawHTML(sRet)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2007-07-11 12:43:54, 1.1 KB) [[attachment:AllPagesWithACL.py]]
  • [get | view] (2007-07-11 12:45:09, 1.8 KB) [[attachment:LostSoulsInGroups.py]]
  • [get | view] (2007-04-13 10:05:04, 1.1 KB) [[attachment:MacroMarket-AllPagesWithACL.py]]
  • [get | view] (2007-04-24 07:25:22, 3.6 KB) [[attachment:MacroMarket-ManageUsers.py]]
  • [get | view] (2007-05-03 10:22:47, 2.4 KB) [[attachment:MacroMarket-WikiLog.py]]
  • [get | view] (2007-07-11 12:44:58, 3.6 KB) [[attachment:ManageUsers.py]]
  • [get | view] (2007-07-11 12:44:50, 2.4 KB) [[attachment:WikiLog.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.