Skip to content

Instantly share code, notes, and snippets.

@decal
Last active April 27, 2018 07:44
Show Gist options
  • Save decal/f819da1ca457c75100cd91143d58d705 to your computer and use it in GitHub Desktop.
Save decal/f819da1ca457c75100cd91143d58d705 to your computer and use it in GitHub Desktop.
❔ Split the QUERY_STRING variables in URL paths of locally mirrored files seperated by ampersands and starting with a question mark
#!/usr/bin/env ruby
# coding: utf-8
#
# Parse CGI variable names from files stored by tools such as:
# wget, wayback_archive_downloader, etc.
#
# Written By: Derek Callaway [derek.callaway (AT) ioactive {D0T} org]
# Last Updated: Wed Dec 27 04:30:02 PST 2017
# Tested On: Linux 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014
#
require 'find'
names = []
ARGV.each do |a|
begin
Find.find(a) do |x|
if File.file?(x)
anind = x.index('?')
next if !anind
uargs = x[anind .. -1]
next if uargs.empty?
uvars = uargs.split('&')
next if !uvars or uvars.empty?
asize = names.size
uvars.each do |v|
v = v[1 .. -1] if v.size > 1 and v.first.eql?('?')
n = v.split('=')
next if !n or n.empty?
asize = names.size
if !names.include?(n.first)
STDOUT.print("#{n.first} ")
names << n.first
end
STDOUT.puts if names.size != asize
end
end
end
rescue Exception => e
STDERR.puts(e.backtrace.join(' '))
STDERR.puts(e.inspect)
end
end
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment