Skip to content

Instantly share code, notes, and snippets.

@jeffkreeftmeijer
Forked from radar/nuke.rb
Created October 12, 2010 07:57
Show Gist options
  • Select an option

  • Save jeffkreeftmeijer/621822 to your computer and use it in GitHub Desktop.

Select an option

Save jeffkreeftmeijer/621822 to your computer and use it in GitHub Desktop.

Revisions

  1. @radar radar revised this gist Oct 9, 2010. 1 changed file with 4 additions and 2 deletions.
    6 changes: 4 additions & 2 deletions nuke.rb
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,10 @@ def underscore
    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 = {}
    @@ -74,8 +77,7 @@ def underscore
    # 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
    if !assigned_user.blank?
    params["assigned_user_id"] = user_select_box.options.detect { |o| o.text == assigned_user }.select
    end

  2. @radar radar revised this gist Oct 9, 2010. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nuke.rb
    Original file line number Diff line number Diff line change
    @@ -41,7 +41,7 @@ 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\/69/ }.map(&:href).uniq
    links = page.links.select { |l| l.href =~ /tickets\/\d+/ }.map(&:href).uniq


    links.each do |link|
  3. @radar radar revised this gist Oct 9, 2010. 1 changed file with 51 additions and 46 deletions.
    97 changes: 51 additions & 46 deletions nuke.rb
    Original file line number Diff line number Diff line change
    @@ -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
  4. @radar radar renamed this gist Oct 9, 2010. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @radar radar created this gist Oct 9, 2010.
    105 changes: 105 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,105 @@
    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 = page.links.select { |l| l.href =~ /tickets\/\d+/ }.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)

    # 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

    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[field] = original_value
    p params[field]

    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 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."

    # 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
    end
    end