Is there any way to delete large blocks of comments? I have litterally thousands of spam comments on my gallery and there is no way to delete them other than clicking on each one at a time, then clicking on the confirm buton. That approach is not an option with thousands of items to delete.
Searching the forum about a way to use SQL to delete the comments were met with calls never to do anything with the g2 tables directly or else it will all get corrupted.
Is there any solution to this big problem?
Thanks,
Jeff Billimek
Posts: 10
Ok I got impatient and came up with some SQL (mysql).
In a previous thread valliant mentioned:
I came up spam subjects that were in the vast majority of my spam and used them in the query below. I'm sure there is a much better way to approach this but it worked for me quickly. Subsitute g2_ with your table prefix and of course only do this if you have a backup and know what you are doing.
It may be necessary to wrap the whole thing in a transaction. If anyone reading this discovers a better approach please post so others can benefit from your knowledge. I only did this because I had thousands of spam comments before I realized that capata was not enabled for commenting. There has got to be a better way to deal with a ton of spam other than ging to SQL though.
Posts: 6
thanx for posting this, total useful.
i extended mine a bit to add a couple more search phrases (for people posting urls)
and it also searches through the comment text rather than just the subjects:
CREATE TEMPORARY TABLE tmptable
SELECT gid
FROM `g2Comment` gc
WHERE
gc.gsubject like '%url%' or
gc.gsubject like '%http%' or
gc.gsubject like '%personals%' or
gc.gsubject like '%poker%' or
gc.gsubject like '%blackjack%' or
gc.gsubject like '%gambling%' or
gc.gsubject like '%viagra%' or
gc.gsubject like '%phentermine%' or
gc.gsubject like '%casino%' or
gc.gsubject like '100%' or
gc.gsubject like '%slots%' or
gc.gsubject like '%Cialis%' or
gc.gsubject like '%url%' or
gc.gcomment like '%http%' or
gc.gcomment like '%personals%' or
gc.gcomment like '%poker%' or
gc.gcomment like '%blackjack%' or
gc.gcomment like '%gambling%' or
gc.gcomment like '%viagra%' or
gc.gcomment like '%phentermine%' or
gc.gcomment like '%casino%' or
gc.gcomment like '100%' or
gc.gcomment like '%slots%' or
gc.gcomment like '%Cialis%';
DELETE g2Entity
FROM g2Entity
INNER JOIN tmptable ON g2Entity.gid = tmptable.gid;
DELETE g2ChildEntity
FROM g2ChildEntity
INNER JOIN tmptable ON g2ChildEntity.gid = tmptable.gid;
DELETE g2Comment
FROM g2Comment
INNER JOIN tmptable ON g2Comment.gid = tmptable.gid;
DROP TEMPORARY TABLE tmptable;
Posts: 4
This is very useful code. I'm surprised something like this isn't built into the commenting system. I had over 100 spam comments in my gallery and this got rid of them all.
--
Tied up in knots
Posts: 10
I had to make changes to most of the field names but was able to successfully delete a couple thousand spam comments with this. Thank you! Below are the changes I had to make. Careful, I really don't know what I'm doing, just got lucky.
CREATE TEMPORARY TABLE tmptable
SELECT g_id
FROM `g2_Comment` gc
WHERE
g_subject like '%url%' or
g_subject like '%http%' or
g_subject like '%personals%' or
g_subject like '%poker%' or
g_subject like '%blackjack%' or
g_subject like '%gambling%' or
g_subject like '%viagra%' or
g_subject like '%phentermine%' or
g_subject like '%casino%' or
g_subject like '100%' or
g_subject like '%slots%' or
g_subject like '%Cialis%' or
g_subject like '%url%' or
g_comment like '%http%' or
g_comment like '%personals%' or
g_comment like '%poker%' or
g_comment like '%blackjack%' or
g_comment like '%gambling%' or
g_comment like '%viagra%' or
g_comment like '%phentermine%' or
g_comment like '%casino%' or
g_comment like '100%' or
g_comment like '%slots%' or
g_comment like '%Cialis%';
DELETE g2_Entity
FROM g2_Entity
INNER JOIN tmptable ON g2_Entity.g_id = tmptable.g_id;
DELETE g2_ChildEntity
FROM g2_ChildEntity
INNER JOIN tmptable ON g2_ChildEntity.g_id = tmptable.g_id;
DELETE g2_Comment
FROM g2_Comment
INNER JOIN tmptable ON g2_Comment.g_id = tmptable.g_id;
DROP TEMPORARY TABLE tmptable;
Posts: 22
For those who might be using Postgresql, here is the version for it:
SELECT g_id INTO TEMPORARY tmptable FROM g2_comment WHERE
g_subject like '%url%' or
g_subject like '%http%' or
g_subject like '%personals%' or
g_subject like '%poker%' or
g_subject like '%blackjack%' or
g_subject like '%gambling%' or
g_subject like '%viagra%' or
g_subject like '%phentermine%' or
g_subject like '%casino%' or
g_subject like '100%' or
g_subject like '%slots%' or
g_subject like '%Cialis%' or
g_subject like '%url%' or
g_comment like '%http%' or
g_comment like '%personals%' or
g_comment like '%poker%' or
g_comment like '%blackjack%' or
g_comment like '%gambling%' or
g_comment like '%viagra%' or
g_comment like '%phentermine%' or
g_comment like '%casino%' or
g_comment like '100%' or
g_comment like '%slots%' or
g_comment like '%mortgage%' or
g_comment like '%testing%';
DELETE FROM g2_entity WHERE g_id IN (SELECT g_id FROM tmptable);
DELETE FROM g2_childentity WHERE g_id IN (SELECT g_id FROM tmptable);
DELETE FROM g2_comment WHERE g_id IN (SELECT g_id FROM tmptable);
DROP TABLE tmptable;
Posts: 10
How ironic!
Posts: 32509
i've deleted the spam that was posted before billimek's comment.
--------------
Doumentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 565
billimek---- ironic is not the word I would
willingly use for these people - sick? - criminal?
valiant---- thank you for taking this stuff
seriously. My analysis appended. Use as
appropriate, I have already on my server;~)
----best wishes, Robert
http://www.hcs.k12.nc.us
206.107.110.4 (apparently RBL clean)
United States - North Carolina - Raeford - Hoke County Schools
US Sprint 206.104.0.0/14
http://www.ussbremerton.org
71.18.54.157 (apparently clean)
United States - Kentucky - Hopkinsville - Ecommerce Corporation
US XO 71.0.0.0/8
http://www.glasshillgolf.com
12.39.78.19 (apparently RBL clean)
United States - New York - Clinton - Total Solutions
unlimitedlifestyleincome.com
US AT&T 12.0.0.0/8
http://www.chikungunya.net
84.40.5.130 (apparently RBL clean)
United Kingdom - Hostway
wsh1008.lon.gb.securedata.net (yes, right, really secure)
UK 84.40.0.0/17
http://www.coralblog.com
203.174.83.43 (apparently RBL clean)
Singapore - Singapore - Singapore - Mizuwork Singapore
Singapore 203.174.83.0/24
http://www.wauknet.com
168.215.63.10 (apparently RBL clean)
United States - Wisconsin - Waukesha - Comstar
sirius.comstarllc.com
US Time Warner Telecom 168.215.0.0/16
http://clearblogs.com
206.222.26.18 (apparently RBL clean)
United States - Enet Inc
server.wiseme.com
US eNet Inc 206.222.0.0/19
http://www.serbisyopilipino.org
65.254.250.104 (apparently RBL clean)
United States - Massachusetts - Burlington - Endurance International Group Inc
65-254-250-104.yourhostingaccount.com
US Endurance 65.254.224.0/19
http://www.brianprucey.com
64.202.163.154 (apparently RBL clean)
United States - Arizona - Scottsdale - Go Daddy Software
linhost125.prod.mesa1.secureserver.net (yes, really, secure... all 2.8million sites)
US Go Daddy 64.202.160.0/19
http://www.goldcoastonlinetutoring.com
64.202.163.9 (apparently RBL clean)
United States - Arizona - Scottsdale - Go Daddy Software
linhost218.prod.mesa1.secureserver.net (yes, really, secure... all 2.8million sites)
US Go Daddy 64.202.160.0/19
http://www.riversideca.gov
192.248.248.34 (apparently RBL clean)
United States - California - Riverside - City Of Riverside
portcullis.riversideca.gov
US 192.248.128.0/17
http://www.sambets.com
64.251.197.195 (apparently RBL clean)
United States - Texas - Dallas - 2 Coolweb Inc
US 64.251.192.0/20
http://www.smaaonline.com
65.114.252.14 (good grief... this is the only one that's on an RBL ...since 2002!)
NOMOREFUNN TXT= "qwest.net - added 2002-04-11; spam support - netblk-q0228-65-125-188-0"
United States - Colorado - Sterling Computer Center
markmcdonaldphysicaltherapy.com
US Qwest 65.112.0.0/12
Posts: 32509
for those who wonder what RBL means:
http://en.wikipedia.org/wiki/DNSBL
--------------
Doumentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage
Posts: 219
MANY thanks - top post. Bookmarked! I just deleted nearly 3,000 spams with this.
Posts: 1
Yes, thank you. 60588 (yes 60k +) spam comments deleted from my site with this method.
Posts: 31
I'll add my thanks as well. I put this query in a php page that I set up to run nightly as a cron job. This keeps my gallery spam free with little intervention. Thank you!
Posts: 14
I have been trying to run this to remove 70k spam messages... and I get the following error :
SQL query:
DELETE g2_Entity FROM g2_Entity INNER JOIN tmptable ON g2_Entity.g_id = tmptable.g_id;
MySQL said: Documentation
#1064 - You have an error in your SQL syntax near 'g2_Entity FROM g2_Entity INNER JOIN tmptable ON g2_Entity.g_id = tmptable.g_id' at line 3
any idea's... I am not a sql expert in the least so I am kinda stuck
thanks
Posts: 219
Make sure you're using kkinderen's correct version of the post, and not the first one.
Posts: 14
I am... I just gave up and am running the commentblaster script and removing all comments... I did not have many real ones anyways... although I would live to get the running
Posts: 219
Ooh, commentblaster sounds interesting. I'll give it a go.
Now I have to work out why CAPTCHA is not working for comments on the vslider3 theme...hmmm.
Posts: 1
I think, It will not help to delete all spam.
Posts: 18
Where is this code supposed to be executed? Myphpadmin?
Thanks,
VB
Posts: 1
cleb - i get the same error. I think I discovered that it is because we are using mysql 3.23. Multiple table deletes as written above only work in mysql 4.0 and up. I spent so long trying to get it running before reading that in the mysql documentation.
I have not been able to work around yet. the syntax with g_id IN (SELECT * from tmptable) does not work either.
Can you confirm that you are also running 3.23? Anyone have some hints for those of us not in control of our mysql version?
Posts: 2
I am running MySQL 3.23 and had the same issues. We worked around it with some PHP code. It works for me, but use are your own risk (built from kkinderen's code). Put this code in a .php file on your web server (replacing "database_username" and "database_password" and "database_name" with your values) and open the file in a web browser:
Posts: 1
I just threw pretty much all my available votes at this project.... I have about 75,000 comments to delete and am not savvy enough to use the code posted in this thread... grrrr @ spammers.
I should add: the subject lines of the spam comments I am getting, are random strings of letters.... so in my understanding, that code won't work for those anyway, right?
Posts: 47
do you guys get spam comments even with captcha set to high for guest comments?
Posts: 2
digitalcyanide: The code above probably would work for you. The reason I think it would work is because of the searching for the strings "url" and "http". The reason (most) spammers are doing this is to provide links to web sites, and those are the 2 most common ways to do that. So chances are very good that most or all of your spam comments have a link in them, and the code posted here (pick the one that works for your database) should take them out.
aharami: I don't get any more spam comments since enabling captcha ... but in the week between the time they started and the time I noticed and shut them down, I had about 30,000 spam comments that I wanted to delete.
If I remember correctly, didn't Gallery v1 have a feature built-in to detect / remove spam comments?
Posts: 27300
Yes.
G2 now has http://akismet.com/ in the comment module to protect against spam as well as an improved captcha.
download a nightly or wait for G2.3
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 15
Pardon the interruption, but WHY is this code not built in G2 ???
I have a thousand spam comments I would like to have deleted, but this thread is now terribly confusing and it's totally unclear what code should be used for what exactly.
This looks like one of the basic simplest mass comment delete options possible, yet it's not there for the user?
Posts: 15
The following content worked better for me.
For me it worked fine and safely on a MySQL 5.0 database, but it did need the ending "?>" php-part.
Here's my How to:
Just copy paste the code below to a /something.php file in your G2 main dir, then change all the xxx_ values in the top of the file to yours (they can be found in /config.php ).
Then open the /something.php from your browser, et voila!
Posts: 27300
Because it has to be written by somebody.
Thanks for the contribution.
I think an improvement might be to do a include() of config.php then the user does not have to edit the file manually. Another step, for security, might be to place the file in /lib/support.
With the akismet addition to the comment module you can 'rescan' for comment spam.
Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team
Posts: 10
I love how stuff like this evolves and grows into what we see today! That's for making it even easier to delete the spam. I'm anxiously awaiting the akimset (however you spell it) functionality of G2 v2.3
By the way, is anyone else still getting spam even with capatcha turned on? I just noticed I had a ton of spam today and the past few days and I just verified last night actually that the capatcha is active and working - have the spammers found a way around it?
Posts: 219
OK, the Akismet is looking good for the spam, only problem is that I'm having the same old issue with Gallery as I've always had, which is that it gives me white pages and times out (even though I set php.ini etc).
When I check "delete all comments" (there were about 1,800) it deletes a third of them, but then says there are none left to delete, then I have to wait 8 minutes for Akismet to run again, then delete more spam, then run Akismet again...I'm just worried that this extra load on Akismet might not make gallery popular with them!!
Anyway, looking much better. I just wish I could find where the timeout was stored, as I already have
memory_limit = 64M
max_execution_time = 60
in the php.ini
But anyway, 2.3 is looking good!
Posts: 46
Deletes 10413 comments at about 30MB mySQL trash with this - thanks a lot! :D
Posts: 23
Can you help with the syntax for including config.php and replacing "xxx_mysqlserveraddress","xxx_username","xxx_password", and "xxx_database_name" accordingly? Thanks.
Posts: 126
What's the best version of this script to use with mysql Ver 12.22 Distrib 4.0.27?
Posts: 8
I've got Gallery 2.2.1, php 4.4.1 and mySQL 4.1.22
I used the code iemand posted in a php-file in my website root directory.
for the lines
$connection
$db
i set the values
"xxx_mysqlserveraddress" = ""
"xxx_username" = $storeConfig['username'] from config.php
"xxx_password" = $storeConfig['password'] from config.php
xxx_database_name" = $storeConfig['database'] from config.php
the script completed successfully and removed 176865 spam comments!
Nice
Posts: 96
I have been trying to implement this PHP file to delete comment spam but to no avail.
Tech info:
http://www.whatsthatpicture.com/?q=gallery&g2_view=comment.ShowAllComments
Gallery version = 2.2-rc-1 core 1.1.26
PHP version = 4.4.7 cgi
Webserver = Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 mod_ssl/2.8.28 OpenSSL/0.9.7e-p1 PHP-CGI/0.1b
Database = mysql 4.1.22, lock.system=flock
My theme has been modified and does not give a box for a subject.
I allow non-registered users to comment (it's the whole point of the site) but have captcha enabled.
I regularly get blocks of spam comments, 20 or 30 at a time, typically with three or four links as the start of the comment.
Right now I have been in to phpMyAdmin and deleted all but one of the comments to clean things up, but at the same time leave one in for testing. As a short-term fix I would like to have this PHP based method working, and then cron it so it is automated. Beyond that I would like to have Akismet or at least a more robust Captcha.
As far as the PHP file goes, I have tried the code given by guru_gary above, but when I call the page in a browser I just get a blank page. I have tried putting an echo right at the beginning and not even that gets written out to teh page. Frustratingly I can't get at my PHP error logs so can't see what might be happening behind the scenes. Can anyone suggest some debugging tips? I'm afraid my PHP is rather basic!
Thanks, James
Posts: 2
Iemand, thank you so much for the script, it worked wonder for me! I must tell I'm totally unfamiliar with php and such... :o)
"xxx_mysqlserveraddress" = $storeConfig['hostname'] from config.php
"xxx_username" = $storeConfig['username'] from config.php
"xxx_password" = $storeConfig['password'] from config.php
"xxx_database_name" = $storeConfig['database'] from config.php
Posts: 238
Awesome, thank you so much for this! I was dreading cleaning up my comments after importing my old messy G1...
http://www.discobug.com
Posts: 16504
Also check out Comment Blaster: http://codex.gallery2.org/Downloads:CommentBlaster
That and other tools are linked to here: http://codex.gallery2.org/Downloads
2.3 is suppose to have better anti-spam features.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 19
Here is a slight mod to get rid of a couple more... just added the '%url%' to the g_comment like section..
CREATE TEMPORARY TABLE tmptable
SELECT g_id
FROM `g2_Comment` gc
WHERE
g_subject like '%url%' or
g_subject like '%http%' or
g_subject like '%personals%' or
g_subject like '%poker%' or
g_subject like '%blackjack%' or
g_subject like '%gambling%' or
g_subject like '%viagra%' or
g_subject like '%phentermine%' or
g_subject like '%casino%' or
g_subject like '100%' or
g_subject like '%slots%' or
g_subject like '%Cialis%' or
g_subject like '%url%' or
g_comment like '%http%' or
g_comment like '%personals%' or
g_comment like '%poker%' or
g_comment like '%blackjack%' or
g_comment like '%gambling%' or
g_comment like '%viagra%' or
g_comment like '%phentermine%' or
g_comment like '%casino%' or
g_comment like '100%' or
g_comment like '%slots%' or
g_comment like '%Cialis%' or
g_comment like '%url%';
DELETE g2_Entity
FROM g2_Entity
INNER JOIN tmptable ON g2_Entity.g_id = tmptable.g_id;
DELETE g2_ChildEntity
FROM g2_ChildEntity
INNER JOIN tmptable ON g2_ChildEntity.g_id = tmptable.g_id;
DELETE g2_Comment
FROM g2_Comment
INNER JOIN tmptable ON g2_Comment.g_id = tmptable.g_id;
DROP TEMPORARY TABLE tmptable;
Posts: 126
i ran this file and got the following return.
Table 'TEMPCOM' already exists
and the spam is still there. What went wrong?
Posts: 4
Hi voice903fm:
Something must have gone wrong during the delete spam part, as the table TEMPCOM is deleted after the succesful completion of the php cleanup script.
To delete the table log into mysql:
# ./mysql -u <username> -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 51536
Server version: 5.1.25-rc-standard Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| gallery2 |
| mysql |
| wp |
+--------------------+
mysql> use gallery2
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------+
| Tables_in_gallery2 |
+--------------------------+
| TEMPCOM |
...
...
mysql> drop table TEMPCOM;
mysql> show tables;
+--------------------------+
| Tables_in_gallery2 |
+--------------------------+
| g2_AccessMap |
...
...
mysql> quit
Bye
I also added some lines to the php script above, to include more spam and which totally cleaned up my albums of spam, just copy and replace this with the subject and comment like from the above script:
g_subject like '%url%' or
g_subject like '%http%' or
g_subject like '%handbags%' or
g_subject like '%poker%' or
g_subject like '%blackjack%' or
g_subject like '%gambling%' or
g_subject like '%viagra%' or
g_subject like '%phentermine%' or
g_subject like '%casino%' or
g_subject like '%order%' or
g_subject like '%slots%' or
g_subject like '%Cialis%' or
g_subject like '%url%' or
g_subject like '%sexo%' or
g_subject like '%mortgage%' or
g_subject like '%teen%' or
g_subject like '%discount%' or
g_subject like '%orgasm%' or
g_comment like '%http%' or
g_comment like '%handbags%' or
g_comment like '%poker%' or
g_comment like '%blackjack%' or
g_comment like '%gambling%' or
g_comment like '%viagra%' or
g_comment like '%phentermine%' or
g_comment like '%casino%' or
g_comment like '%buy%' or
g_comment like '%antibiotic%' or
g_comment like '%sexo%' or
g_comment like '%chicas%' or
g_comment like '%mortgage%' or
g_comment like '%teen%' or
g_comment like '%discount%' or
g_comment like '%orgasm%' or
g_comment like '%order%';";
Posts: 4
OK -- I'm totally confused.
my web manager migrated me from Gallery 1 to 2.2.4 I enabled captcha, and thought it was working. but they eventually found me, the nasty spammers, so I guess captcha didn't work. Now there are hundreds, of course. I just disabled comments (so I can't see them anymore), but evidently their bulk has put me way over my size limit!! I don't want to pay more just to keep spam!
So -- I did download the "comment blaster" and uploaded the entire php file to my gallery directory, which I can see in "files" on my Speedy puppy account. I understand that it is a test run, but won't actually delete comments until the "true" is changed to "false". I know that I need to edit that and upload a new file with that change. However, when I'm in gallery admin mode, I can't see the comment blaster to run in the "test" mode, and I don't know how to make it run just from my browser. I'm running Safari on a g4 mac, if that helps.
As for the other script. I don't know how to run anything like that, and might not be able to do it, since my host administrator might have things set up in a different way? But I'd like some clues so I could try, at least.
Astrid
Posts: 16504
If you just want to get rid of all comments, just uninstall the Comments plugin.
Site Admin > Plugins
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 4
hmmmm--- so more than just disable -- uninstall? I'll try that right now
Astrid
Posts: 16504
Yes, disable just deactivates the plugin, but keeps all the data and settings in the database. Uninstalling should remove all data associated to a plugin from the database.
____________________________________________
Like Gallery? Like the support? Donate now!!! See G2 live here
Posts: 4
wow. it seems to have worked. 19.6 MB worth of spam comments gone in a flash. I had received a notice
that I had 37.35 out of 20 MB, but now "MySQL Quota DB" just shows 17.7!! It seems that the idjuts discovered me in August this year, and went wart-hog-happy, pushing me way over max in less than a month.
I wonder if it has to do with the permanent link on Bing images?
THANKS!!!!!!
Astrid
Posts: 4
exploring the stats of my site more closely, I saw that the last two months' stats included a single IP "host" that was 100 x anything else, and not there in the July stats at all. 94.23.51.115 I reported it to project honeypot, since that coincides with the thousands of spam comments to my images.
Astrid
Posts: 4
This morning I realized had 93 spam comments in my Gallery2, so I started removing them manually. Only later I found out that the actual count was more than 10000, 9693 alone on one photo. Thanks to all who posted the SQL to remove comments. I used a simplified SQL to remove the spam:
CREATE TEMPORARY TABLE tmptable
SELECT g_id
FROM `g2_Comment` gc;
DELETE g2_Entity
FROM g2_Entity
INNER JOIN tmptable ON g2_Entity.g_id = tmptable.g_id;
DELETE g2_ChildEntity
FROM g2_ChildEntity
INNER JOIN tmptable ON g2_ChildEntity.g_id = tmptable.g_id;
DELETE g2_Comment
FROM g2_Comment
INNER JOIN tmptable ON g2_Comment.g_id = tmptable.g_id;
DROP TEMPORARY TABLE tmptable;
Plain and simple, all comments were gone. Final step: uninstalling the Comments plugin.
Thanks!