Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: modules/statsmaster/templates/anonymize_ips_item.erb

Issue 6293281981857792: Issue 239 - Move AWStats processing to the stats server (Closed)
Patch Set: Added IP address anonymization and addressed review comments Created April 25, 2014, 7:38 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « modules/statsmaster/templates/anonymize_ips_head.erb ('k') | modules/statsmaster/templates/awstats.conf » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: modules/statsmaster/templates/anonymize_ips_item.erb
===================================================================
new file mode 100644
--- /dev/null
+++ b/modules/statsmaster/templates/anonymize_ips_item.erb
@@ -0,0 +1,27 @@
+file = os.path.join('/var/www/awstatsdata', '<%= title %>',
+ 'awstats%s%s.%s.txt' % (month, year, '<%= title %>'))
+if os.path.exists(file):
+ with open(file, 'rb+') as f:
+ mapstarted = False
+ seekpos = None
+ for line in f:
+ if not mapstarted:
+ if line.startswith('BEGIN_MAP '):
+ mapstarted = True
+ else:
+ match = re.search(r'^POS_VISITOR (\d+)', line)
+ if match:
+ seekpos = int(match.group(1))
+ break
+
+ f.seek(seekpos)
+ data = f.readline() # BEGIN_VISITOR line
+ for line in f:
+ if line.startswith("END_VISITOR"):
+ break
+ parts = line.split(' ')
+ parts[0] = re.sub(r'\w', 'x', parts[0])
+ data += ' '.join(parts)
+
+ f.seek(seekpos)
+ f.write(data)
« no previous file with comments | « modules/statsmaster/templates/anonymize_ips_head.erb ('k') | modules/statsmaster/templates/awstats.conf » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld