[solved] Manually Add a User to the Blacklist

Solutions for other advanced phplisters

Postby prodos » 11:11pm, Tue 24 Mar, 2009

Thanks crSteve,

I wonder if you (or anyone else) could provide the code of the whole page of the massunconfirm.php file as it should be after it's been modified?

i.e. after that extra script has been added?

I'm a bit confused about where and how exactly to make the script changes you've suggested, and I'd really like to test out this blacklisting function.

Thanks! 8)

[I'm using phplist v2.10.9]
prodos
PL Nut
 
Posts: 20
Joined: 1:22pm, Sun 08 Mar, 2009

Postby prodos » 10:50am, Thu 26 Mar, 2009

Good evening.

I am using phplist v2.10.9

Below is the complete code of the file:

/admin/massunconfirm.php

Could anyone post the code to include the changes suggested by crSteve ?

Code: Select all
<php>get('Sorry, this page can only be used by super admins');
  return;
}

if ($_POST['unsubscribe']) {
  $emails = explode("\n",$_POST['unsubscribe']);
  $count = 0;
  $unsubbed = 0;
  foreach ($emails as $email) {
    $email = trim($email);
    $count++;
    Sql_Query(sprintf('update %s set confirmed = 0 where email = "%s"',$GLOBALS['tables']['user'],$email));
    $unsubbed += Sql_Affected_Rows();
  }
  printf($GLOBALS['I18N']->get('All done, %d emails processed, %d emails marked unconfirmed<br>'),$count,$unsubbed);
  return;
}
?>

<form>
<h1><php>get('Mass unconfirm email addresses')?></h1>
<p><php>get('Paste the emails to mark unconfirmed in this box, and click continue')?></p>
<input><br>
<textarea></textarea>
</form>



Thanks.
Last edited by prodos on 1:02pm, Thu 26 Mar, 2009, edited 1 time in total.
prodos
PL Nut
 
Posts: 20
Joined: 1:22pm, Sun 08 Mar, 2009

Postby Dragonrider » 11:03am, Thu 26 Mar, 2009

Nice and easy, works too!

Code: Select all
<?php
require_once dirname(__FILE__).'/accesscheck.php';

//userlib for blacklist function
include_once dirname(__FILE__).'/commonlib/lib/userlib.php';

if (!$_SESSION['logindetails']['superuser']) {
  print $GLOBALS['I18N']->get('Sorry, this page can only be used by super admins');
  return;
}

if ($_POST['unsubscribe']) {
  $emails = explode("\n",$_POST['unsubscribe']);
  $count = 0;
  $unsubbed = 0;
  foreach ($emails as $email) {
    $email = trim($email);
    $count++;
    Sql_Query(sprintf('update %s set confirmed = 0 where email = "%s"',$GLOBALS['tables']['user'],$email));
    $unsubbed += Sql_Affected_Rows();

  //added user to the blacklist
addUserToBlackList($email, 'Admin Blacklisted');

}
  printf($GLOBALS['I18N']->get('All done, %d emails processed, %d emails marked unconfirmed<br/>'),$count,$unsubbed);
  return;
}
?>

<form method=post action="">
<h1><?php echo $GLOBALS['I18N']->get('Mass unconfirm email addresses')?></h1>
<p><?php echo $GLOBALS['I18N']->get('Paste the emails to mark unconfirmed in this box, and click continue')?></p>
<input type=submit name="go" value="<?php echo $GLOBALS['I18N']->get('Continue')?>"><br/>
<textarea name="unsubscribe" rows=30 cols=40></textarea>
</form>
My sites:- http://wharfedalefestival.co.uk, http://ilkleygardeners.org.uk, http://emergencyaid.net, http://dragonrider.co.uk
Latest phpList version is now 3.0.12 (3 February 2015) and requires a minimum of MySQL 5.0 and PHP 5.3.x
Dragonrider
Moderator
 
Posts: 3460
Joined: 6:58am, Sun 02 Jul, 2006
Location: Ilkley, West Yorkshire, United Kingdom

Postby prodos » 12:03pm, Thu 26 Mar, 2009

Thanks a lot Dragonrider.

That's darned good of you to oblige.

I'll give it a whirl! :)
prodos
PL Nut
 
Posts: 20
Joined: 1:22pm, Sun 08 Mar, 2009

Postby Dragonrider » 1:01pm, Thu 26 Mar, 2009

prodos wrote:Thanks a lot Dragonrider.

That's darned good of you to oblige.

I'll give it a whirl! :)

No prob! :)
My sites:- http://wharfedalefestival.co.uk, http://ilkleygardeners.org.uk, http://emergencyaid.net, http://dragonrider.co.uk
Latest phpList version is now 3.0.12 (3 February 2015) and requires a minimum of MySQL 5.0 and PHP 5.3.x
Dragonrider
Moderator
 
Posts: 3460
Joined: 6:58am, Sun 02 Jul, 2006
Location: Ilkley, West Yorkshire, United Kingdom

Postby prodos » 1:37pm, Thu 26 Mar, 2009

Reporting that this alteration to massunconfirm.php works perfectly!

I just tested it on one of my v2.10.9 test sites.

Mass unconfirm now acts as mass blacklist!

As noted earlier by crSteve, yes, the newly blacklisted users do seem to be effectively blacklisted immediately.

However they don't immediately look blacklisted when their details are checked. This is nothing to worry about.

I waited probably half an hour, checked again, and their "bl l" (blacklist) column was now "1" (one).

Reality and appearance matched. There's a moral in there somewhere. :roll:
prodos
PL Nut
 
Posts: 20
Joined: 1:22pm, Sun 08 Mar, 2009

Re: Simple mass blacklist for the Admin

Postby ThorstenAlbrecht » 4:48pm, Thu 06 Aug, 2009

crSteve wrote: However, when you do a search for the user it shows an X under bl l instead of the check mark. I guess it has to do with the browser cache, cause eventually it sorts out and displays the appropriate check under bl l.

No, that's no browser cache problem.
Just set in config.php
Code: Select all
$blacklist_gracetime = 1;

and wait a minute...

Thorsten
ThorstenAlbrecht
PL Nut
 
Posts: 44
Joined: 4:08pm, Thu 06 Aug, 2009

Re: [solved] Manually Add a User to the Blacklist

Postby prodos » 8:17pm, Thu 06 Aug, 2009

Code: Select all
$blacklist_gracetime = 1;


Hey, that´s a nifty feature! :)

Perhaps ¨gracetime¨ is about allowing notifications of the blacklisting to be sent through to the user?

i.e. Without specifying a grace time, users might not receive such notifications.

If it´s not a cache issue, but is an actual grace period before the blacklisting kicks in then the user would presumably be treated as active until the grace time expires.

Thanks to ThorstenAlbrecht for drawing attention to this bit of code.
prodos
PL Nut
 
Posts: 20
Joined: 1:22pm, Sun 08 Mar, 2009

Re: [solved] Manually Add a User to the Blacklist

Postby kaon » 6:25am, Tue 08 Dec, 2009

If I try to mass-unconfirm+blacklist a bunch of addresses, some of which do not yet exist in the database, will it work?

The desired behavior is:
- if the address exists, the blacklist state is set.
- if the address does not exist, it is added to the database, and blacklist state is set.
kaon
PL Nut
 
Posts: 36
Joined: 7:18am, Fri 23 Dec, 2005

Re: [solved] Manually Add a User to the Blacklist

Postby kennethml224 » 11:10pm, Thu 11 Feb, 2010

Thank you Dragonrider and Thorsten! I was trying to configure PHPlist for my company and this helped a lot! -Kenneth
kennethml224
phpList newbie
 
Posts: 1
Joined: 11:04pm, Thu 11 Feb, 2010

Re: Simple mass blacklist for the Admin

Postby ThorstenAlbrecht » 6:53pm, Mon 15 Feb, 2010

ThorstenAlbrecht wrote:
crSteve wrote: However, when you do a search for the user it shows an X under bl l instead of the check mark. I guess it has to do with the browser cache, cause eventually it sorts out and displays the appropriate check under bl l.

No, that's no browser cache problem.
Just set in config.php
Code: Select all
$blacklist_gracetime = 1;

and wait a minute...


With the following modification of userlib.php (in/admin/commonlib/lib) it is possible to change the waiting time unit from minutes to seconds:

filename: admin/commonlib/lib/userlib.php
original code: (phpList 2.10.10)
(line 302)
Code: Select all
  $req = Sql_Query(sprintf('select * from %s where email = "%s" and date_add(added,interval %d minute) < now()',
    $GLOBALS["tables"]["user_blacklist"],sql_escape($email),$gracetime));


modified code:
Code: Select all
  $req = Sql_Query(sprintf('select * from %s where email = "%s" and date_add(added,interval %d second) < now()',
    $GLOBALS["tables"]["user_blacklist"],sql_escape($email),$gracetime));


I have set the variable $blacklist_gracetime in config.php to 1 but now you can leave it on the default value of 5 (seconds - not minutes).

I would appreciate if someone could explain me the sense of this code (with unit minutes). I don't understand the explanation of the programmer:
# allow 5 minutes to send the last message acknowledging unsubscription

What does that mean? Why cannot the function isBlackListed() list everybody who requested to be blacklisted immediately?

BTW This is just one of my, say, 15 questions to phpList which will never be answered by anybody, because nobody seems to be responsible for this peace of software. Well ok, it works... But never again.

Thorsten
ThorstenAlbrecht
PL Nut
 
Posts: 44
Joined: 4:08pm, Thu 06 Aug, 2009

Re: [solved] Manually Add a User to the Blacklist

Postby samuelcrash » 9:26pm, Wed 26 May, 2010

Having users both unconfirmed and blacklisted can cause a problem if one ever wants to clear out unconfirmed users but retain their blacklisted users. So, I took the previously posted code and added a simple check box that allows you to choose whether the emails are blacklisted or unconfirmed.

This is the entire lists/admin/massunconfirmed.php file:
Code: Select all
<?php
require_once dirname(__FILE__).'/accesscheck.php';

//userlib for blacklist function
include_once dirname(__FILE__).'/commonlib/lib/userlib.php';
$massblacklist = $_POST["massblacklist"];

if (!$_SESSION['logindetails']['superuser']) {
  print $GLOBALS['I18N']->get('Sorry, this page can only be used by super admins');
  return;
}

if ($_POST['unsubscribe']) {
  $emails = explode("\n",$_POST['unsubscribe']);
  $count = 0;
  $unsubbed = 0;
  $blacklisted = 0;   
  foreach ($emails as $email) {
    $email = trim($email);
    $count++;

   if ($massblacklist = true) {
       //added user to the blacklist if massblacklist checkbox is true;
       addUserToBlackList($email, 'Admin Blacklisted');
       $blacklisted++;      
   }
   
   else {
      Sql_Query(sprintf('update %s set confirmed = 0 where email =                  "%s"',$GLOBALS['tables']['user'],$email));
    $unsubbed += Sql_Affected_Rows();
   }

  }
  printf($GLOBALS['I18N']->get('All done, %d emails processed, %d emails marked unconfirmed, %d emails blacklisted<br/>'),$count,$unsubbed,$blacklisted);
  return;
}
?>

<form method=post action="">
<h1><?php echo $GLOBALS['I18N']->get('Mass unconfirm email addresses')?></h1>
<p><?php echo $GLOBALS['I18N']->get('Paste the emails to mark unconfirmed in this box, and click continue')?></p>
<p><?php echo $GLOBALS['I18N']->get('MassBlacklist:')?>
<input type="checkbox" value="massblacklist" name="massblacklist[]"></p>
<input type=submit name="go" value="<?php echo $GLOBALS['I18N']->get('Continue')?>"><br/>
<textarea name="unsubscribe" rows=30 cols=40></textarea>
</form>
samuelcrash
phpList newbie
 
Posts: 2
Joined: 9:19pm, Wed 26 May, 2010

Re: [solved] Manually Add a User to the Blacklist

Postby ThorstenAlbrecht » 10:53am, Thu 27 May, 2010

Hi,

you have a typo in your code (= instead of ==):

if ($massblacklist == true)

After correcting that it works as expected.

However, because there exist no function in phpList admin to delete all blacklisted user I prefer to delete the unconfirmed user from time to time. Therefore: If I would put some user on the blacklist manually I would prefer to unconfirm him in the same step.

Thorsten
ThorstenAlbrecht
PL Nut
 
Posts: 44
Joined: 4:08pm, Thu 06 Aug, 2009

Re: [solved] Manually Add a User to the Blacklist

Postby tlhonda2010 » 9:50am, Tue 08 Jun, 2010

thanks so much for this.
tlhonda2010
phpList newbie
 
Posts: 1
Joined: 9:48am, Tue 08 Jun, 2010

Re: [solved] Manually Add a User to the Blacklist

Postby trickleup » 6:55am, Wed 15 Jun, 2011

This is the script I use:

Code: Select all
UPDATE  `user` SET  `blacklisted` =  '1' WHERE  `user`.`email` = 'test@example.com';

INSERT INTO `phplist_user_blacklist` (`email`, `added`) VALUES ('test@example.com', now() );

INSERT INTO `phplist_user_blacklist_data` (
`email` ,
`name` ,
`data`
)
VALUES (
'test@example.com', 'reason', NULL
);


Table names may vary due to what prefixes you have set. Even after running these script, some cache somewhere still shows an X and not a checkmark when searching for a user (as noted above). But if you check the box "show only blacklisted users" when searching for the email, and then uncheck that and search for the email again, it should clear and show the right image. Annoying.
trickleup
phpList newbie
 
Posts: 2
Joined: 6:05am, Fri 26 Feb, 2010

PreviousNext

Return to Advanced Answers, Howtos, Tips & Tricks

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot] and 1 guest

cron