Add all_visits plugin
This commit is contained in:
		
							
								
								
									
										41
									
								
								plugins/display/all_visits.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								plugins/display/all_visits.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| import time | ||||
|  | ||||
| from iwla import IWLA | ||||
| from iplugin import IPlugin | ||||
| from display import * | ||||
|  | ||||
| class IWLADisplayAllVisits(IPlugin): | ||||
|     def __init__(self, iwla): | ||||
|         super(IWLADisplayAllVisits, self).__init__(iwla) | ||||
|         self.API_VERSION = 1 | ||||
|  | ||||
|     def hook(self, iwla): | ||||
|         hits = iwla.getValidVisitors() | ||||
|         last_access = sorted(hits.values(), key=lambda t: t['last_access'], reverse=True) | ||||
|  | ||||
|         cur_time = self.iwla.getCurTime() | ||||
|         title = time.strftime('All visits %B %Y', cur_time) | ||||
|  | ||||
|         filename = 'all_visits_%d.html' % (cur_time.tm_mon) | ||||
|         path = '%d/%s' % (cur_time.tm_year, filename) | ||||
|  | ||||
|         page = DisplayHTMLPage(title, path) | ||||
|         table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) | ||||
|         for super_hit in last_access: | ||||
|             row = [ | ||||
|                 super_hit['remote_addr'], | ||||
|                 super_hit['viewed_pages'], | ||||
|                 super_hit['viewed_hits'], | ||||
|                 bytesToStr(super_hit['bandwidth']), | ||||
|                 time.asctime(super_hit['last_access']) | ||||
|                 ] | ||||
|             table.appendRow(row) | ||||
|         page.appendBlock(table) | ||||
|  | ||||
|         display = self.iwla.getDisplay() | ||||
|         display.addPage(page) | ||||
|  | ||||
|         index = iwla.getDisplayIndex() | ||||
|         block = DisplayHTMLRawBlock() | ||||
|         block.setRawHTML('<a href=\'%s\'>All visits</a>' % (filename)) | ||||
|         index.appendBlock(block) | ||||
		Reference in New Issue
	
	Block a user