forked from adydas/WPPharmaHackFix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
amp.rb
32 lines (29 loc) · 986 Bytes
/
amp.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
#!/usr/bin/ruby -w
require "rubygems"
require "dbd/Mysql"
require "dbi"
begin
# connect to the MySQL server
dbh = DBI.connect("DBI:Mysql:AMP:localhost","root", "")
# get server version string and display it
sth = dbh.execute ("select post_content, ID FROM wp_posts where post_content like '%display: none%'")
while row = sth.fetch do
#puts "Server version: " + row[0]
new_str = row[0].gsub(/<(\s*)div(.*)display:(\s*)none(.*)<\/div>/, '')
#new_str = new_str.gsub(/<(\s*)a(.*)>(.*)viagra(.*)<\/a>/,'')
puts "Filtered string " + new_str
uth = dbh.prepare ("update wp_posts set post_content = ? where ID = ?")
uth.execute(new_str, row[1])
uth.finish
end
dbh.commit
sth.finish
rescue DBI::DatabaseError => e
puts "An error occurred"
puts "Error code: #{e.err}"
puts "Error message: #{e.errstr}"
dbh.rollback
ensure
# disconnect from server
dbh.disconnect if dbh
end