|
|
@@ -41,65 +41,70 @@ def underscore |
|
|
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 = page.links.select { |l| l.href =~ /tickets\/\d+/ }.map(&:href).uniq |
|
|
links = page.links.select { |l| l.href =~ /tickets\/69/ }.map(&:href).uniq |
|
|
|
|
|
|
|
|
links.each do |link| |
|
|
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) |
|
|
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") |
|
|
# 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}" |
|
|
authenticity_token = update_ticket_form.fields.detect { |f| f.name == "authenticity_token" }.value |
|
|
update_ticket_form = locate_form_by_button(page, "Update ticket") |
|
|
update_ticket_action = "http://rails.lighthouseapp.com#{update_ticket_form.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", "") |
|
|
new_value = matches[3] |
|
|
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 |
|
|
p params[field] |
|
|
|
|
|
end |
|
|
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 |
|
|
params["assigned_user_id"] = user_select_box.options.detect { |o| o.text == assigned_user }.select |
|
|
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") |
|
|
p assigned_user |
|
|
if assigned_user |
|
|
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 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 |
|
|
# If title changed, switch it back |
|
|
|
|
|
title = update_ticket_form.fields.detect { |f| f.name == "ticket[title]"} |
|
|
title.value = params["title"] if params["title"] |
|
|
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." |
|
|
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 |
|
|
# 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 |