leonteale

decode_logs.rb

Nov 12th, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.52 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. require 'base64'
  3.  
  4. unless ARGV.length > 0
  5.     puts "USAGE: ./parselogs.rb [apache-access.log]\r\n\r\n"
  6.     exit!
  7. end
  8.  
  9. def clean_line(line)
  10.     if line.include?('id=')
  11.         first = line.split('id=')[0]
  12.         second = line.split('id=')[1]
  13.         junk = second.split(" ")
  14.         junk[0] = Base64.decode64(junk[0])
  15.         second = "id="
  16.         junk.each { |element| second << element.to_s.chomp + " " }
  17.         return first +  second
  18.     else
  19.         return line
  20.     end
  21. end
  22.  
  23. File.open(ARGV[0], 'r').each_line do |line|
  24.     puts clean_line(line)
  25. end
Advertisement
Add Comment
Please, Sign In to add comment