Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View nuke.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
require 'rubygems'
require 'mechanize'
require 'httparty'
 
# Ugly code, for an ugly hack.
 
# Hey, if Lighthouse didn't suck then none of this would happen.
 
# It's been lotsa fun coding it though, so I suppose I should be thankful for the "opportunity"
 
def locate_form_by_button(page, value)
page.forms.detect { |f| f.buttons.detect { |b| b.value == value } }
end
 
class String
def underscore
self.downcase.gsub(" ", "_")
end
end
 
 
# The IDs of all the known bastards
bastards = [119236]
 
# Setup mechanize
agent = Mechanize.new
 
# Load configuration
config = YAML.load_file(File.join(ENV["HOME"] + "/.lighthouse.yml"))
# Logging in
page = agent.get('https://rails.lighthouseapp.com/login')
 
# There's two forms, use the login form not the open id form
login_form = page.forms[1]
login_form.email = config["email"]
login_form.password = config["password"]
 
page = agent.submit(login_form, login_form.buttons.first)
 
bastards.each do |bastard|
page = agent.get("http://rails.lighthouseapp.com/users/#{bastard}")
pp page.title
# Get all their ticket comments
links = page.links.select { |l| l.href =~ /tickets\/\d+/ }.map(&:href).uniq
 
 
links.each do |link|
begin
page = agent.get(link)
# Detect if the spammer has changed the title
id, version = /#ticket-(\d+)-(\d+)/.match(link).to_a
comment = page.search(id)
# Get the changes for this ticket and revert them.
# Because Lighthouse is too fucking stupid to revert (all) the changes of a ticket when you delete it.
changes = comment.search(".ticket-changes li")
update_ticket_form = locate_form_by_button(page, "Update ticket")
update_ticket_action = "http://rails.lighthouseapp.com#{update_ticket_form.action}"
p "Updating: #{update_ticket_action}"
authenticity_token = update_ticket_form.fields.detect { |f| f.name == "authenticity_token" }.value
params = {}
changes.map do |change|
matches = /(.*?) changed from (.*?) to (.*?)$/.match(change)
field = matches[1].split(" ")[1..-1].join(" ").underscore
original_value = matches[2].gsub("\u0093", "").gsub("\u0094", "").gsub("\302\223", "").gsub("\302\224", "")
new_value = matches[3]
params[field] = original_value
end
# If assigned user has changed, switch it back
user_select_box = update_ticket_form.fields.detect { |f| f.name == "ticket[assigned_user_id]" }
assigned_user = params.delete("assigned_user")
if !assigned_user.blank?
params["assigned_user_id"] = user_select_box.options.detect { |o| o.text == assigned_user }.select
end
# If tags changed, switch them back
tag = update_ticket_form.fields.detect { |f| f.name == "ticket[tag]"}
tag.value = params["tag"] if params["tag"]
# If title changed, switch it back
title = update_ticket_form.fields.detect { |f| f.name == "ticket[title]"}
title.value = params["title"] if params["title"]
comment = update_ticket_form.fields.detect { |f| f.name == "ticket[body]" }
comment.value = "Automatic cleanup of spam."
update_ticket_form.submit(update_ticket_form.buttons.first)
# Now we delete the motherfucker.
numbers = /#ticket-(\d+)-(\d+)/.match(link)
version_to_delete_url = "https://rails.lighthouseapp.com#{update_ticket_form.action}/versions/#{numbers[2]}"
page = agent.get(version_to_delete_url)
# begin
delete_form = locate_form_by_button(page, "Yes, delete this ticket comment.")
agent.submit(delete_form, delete_form.buttons.first)
# rescue
# next
# end
rescue Exception => e
p e.message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.