Add subdomains plugin
This commit is contained in:
		
							
								
								
									
										72
									
								
								plugins/display/subdomains.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								plugins/display/subdomains.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,72 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| # | ||||
| # Copyright Grégory Soutadé 2023 | ||||
|  | ||||
| # This file is part of iwla | ||||
|  | ||||
| # iwla is free software: you can redistribute it and/or modify | ||||
| # it under the terms of the GNU General Public License as published by | ||||
| # the Free Software Foundation, either version 3 of the License, or | ||||
| # (at your option) any later version. | ||||
| # | ||||
| # iwla is distributed in the hope that it will be useful, | ||||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| # GNU General Public License for more details. | ||||
| # | ||||
| # You should have received a copy of the GNU General Public License | ||||
| # along with iwla.  If not, see <http://www.gnu.org/licenses/>. | ||||
| # | ||||
|  | ||||
| from iwla import IWLA | ||||
| from iplugin import IPlugin | ||||
| from display import * | ||||
|  | ||||
| import awstats_data | ||||
|  | ||||
| """ | ||||
| Display hook | ||||
|  | ||||
| Add subdomains statistics | ||||
|  | ||||
| Plugin requirements : | ||||
|     post_analysis/subdomains | ||||
|  | ||||
| Conf values needed : | ||||
|     None | ||||
|  | ||||
| Output files : | ||||
|     OUTPUT_ROOT/year/month/index.html | ||||
|  | ||||
| Statistics creation : | ||||
|     None | ||||
|  | ||||
| Statistics update : | ||||
|     None | ||||
|  | ||||
| Statistics deletion : | ||||
|     None | ||||
| """ | ||||
|  | ||||
| class IWLADisplaySubDomains(IPlugin): | ||||
|     def __init__(self, iwla): | ||||
|         super(IWLADisplaySubDomains, self).__init__(iwla) | ||||
|         self.requires = ['IWLAPostAnalysisSubDomains'] | ||||
|  | ||||
|  | ||||
|     def hook(self): | ||||
|         display = self.iwla.getDisplay() | ||||
|         subdomains = self.iwla.getMonthStats()['subdomains'] | ||||
|  | ||||
|         # Subdomains in index | ||||
|         title = self.iwla._(u'Subdomains') | ||||
|  | ||||
|         index = self.iwla.getDisplayIndex() | ||||
|          | ||||
|         table = display.createBlock(DisplayHTMLBlockTable, title, [self.iwla._('URI'), self.iwla._(u'Entrance')]) | ||||
|         table.setColsCSSClass(['', 'iwla_hit']) | ||||
|         subdomains = sorted(subdomains.items(), key=lambda t: t[1], reverse=True) | ||||
|         for (uri, count) in subdomains: | ||||
|             table.appendRow([uri, count]) | ||||
|         table.computeRatio(1) | ||||
|         index.appendBlock(table) | ||||
							
								
								
									
										73
									
								
								plugins/post_analysis/subdomains.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								plugins/post_analysis/subdomains.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,73 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| # | ||||
| # Copyright Grégory Soutadé 2023 | ||||
|  | ||||
| # This file is part of iwla | ||||
|  | ||||
| # iwla is free software: you can redistribute it and/or modify | ||||
| # it under the terms of the GNU General Public License as published by | ||||
| # the Free Software Foundation, either version 3 of the License, or | ||||
| # (at your option) any later version. | ||||
| # | ||||
| # iwla is distributed in the hope that it will be useful, | ||||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| # GNU General Public License for more details. | ||||
| # | ||||
| # You should have received a copy of the GNU General Public License | ||||
| # along with iwla.  If not, see <http://www.gnu.org/licenses/>. | ||||
| # | ||||
|  | ||||
| import re | ||||
|  | ||||
| from iwla import IWLA | ||||
| from iplugin import IPlugin | ||||
|  | ||||
| """ | ||||
| Post analysis hook | ||||
|  | ||||
| Group top pages by subdomains | ||||
|  | ||||
| Plugin requirements : | ||||
|     post_analysis/top_pages | ||||
|  | ||||
| Conf values needed : | ||||
|     None | ||||
|  | ||||
| Output files : | ||||
|     None | ||||
|  | ||||
| Statistics creation : | ||||
| month_stats: | ||||
|    subdomains => | ||||
|        domain => count | ||||
|  | ||||
| Statistics update : | ||||
|     None | ||||
|  | ||||
| Statistics deletion : | ||||
|     None | ||||
| """ | ||||
|  | ||||
| class IWLAPostAnalysisSubDomains(IPlugin): | ||||
|     def __init__(self, iwla): | ||||
|         super(IWLAPostAnalysisSubDomains, self).__init__(iwla) | ||||
|         self.requires = ['IWLAPostAnalysisTopPages'] | ||||
|  | ||||
|     def load(self): | ||||
|         self.domain_re = re.compile(r'([^/]*)/.*') | ||||
|         return True | ||||
|          | ||||
|     def hook(self): | ||||
|         month_stats = self.iwla.getMonthStats() | ||||
|         top_pages = month_stats['top_pages'] | ||||
|          | ||||
|         subdomains = {} | ||||
|  | ||||
|         for (uri, count) in top_pages.items(): | ||||
|             domain = self.domain_re.match(uri) | ||||
|             if not domain: continue | ||||
|             domain = domain.group(1) | ||||
|             subdomains[domain] = subdomains.get(domain, 0) + count | ||||
|  | ||||
|         month_stats['subdomains'] = subdomains | ||||
		Reference in New Issue
	
	Block a user