unsubscribe, blacklist, disable... is this method ok?

Solutions for other advanced phplisters

unsubscribe, blacklist, disable... is this method ok?

Postby amoswright » 8:30pm, Wed 14 May, 2008

I am moving masses of emails to a new phplist install. I have a need to blacklist bunches of emails too, since our import/update file of emails may contain emails that have been unsubscribed by methods outside of phplist.

After learning that disabling an account does not work:

viewtopic.php?t=17764&highlight=disable

and being overwhelmed by a solution that might have worked but seemed too technical for my feeble mind:

viewtopic.php?t=5009

and trying another that seemed simple but didn't work for me:

viewtopic.php?p=45860#45860

I decided to mash-up some code and hack my own solution.

It seems to work, but I can imagine that there would be any number of reasons why it's a bad solution, and was curious to hear them... or if it's acceptable, to let others use it as well.

by-the-by, this seems to be a recurring request, so I'd ad my voice to those that would love a built-in solution to this in phplist. It'd make transition to phplist much easier for me!


Here is what I did:

1) put each email to blacklist on it's own line in a file called "blacklist.txt" and saved it into the root install directory of phplist

2) copied the code below into a file (i called it "massblacklist.php"), also in the root install directory of phplist

3) brought up massblacklist.php in a browser.

4) Check to see if it worked... that's it.

NOTE: for some reason, it seems to take a bit of time for the info to update in the phplist admin interface? shows up ok in phpmyadmin. not tested extensively, but I think it works.. here is the code:

Code: Select all
<?php
//here is the file with the blacklist emails
$emailfile="blacklist.txt";
//here is a bunch of stuff from the index file
//I know you need some of it, but perhaps not all...
ob_start();
$er = error_reporting(0);
require_once dirname(__FILE__) .'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__).'/admin/init.php';
## none of our parameters can contain html for now
$_GET = removeXss($_GET);
$_POST = removeXss($_POST);
$_REQUEST = removeXss($_REQUEST);

if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
#  print '<using>'."\n";
  include $_SERVER["ConfigFile"];
} elseif (isset($_ENV["CONFIG"]) && is_file($_ENV["CONFIG"])) {
#  print '<using>'."\n";
  include $_ENV["CONFIG"];
} elseif (is_file("config/config.php")) {
#  print '<using>'."\n";
  include "config/config.php";
} else {
  print "Error, cannot find config file\n";
  exit;
}
if (0) {#isset($GLOBALS["developer_email"]) && $GLOBALS['show_dev_errors']) {
  error_reporting(E_ALL);
} else {
  if (isset($error_level)) {
    error_reporting($error_level);
  } else {
    error_reporting($er);
  }
}

require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
require_once dirname(__FILE__)."/texts/english.inc";
include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
require_once dirname(__FILE__)."/admin/defaultconfig.inc";
require_once dirname(__FILE__).'/admin/connect.php';
include_once dirname(__FILE__)."/admin/languages.php";
include_once dirname(__FILE__)."/admin/lib.php";
$I18N= new phplist_I18N();

if ($require_login || ASKFORPASSWORD) {
  # we need session info if an admin subscribes a user
  if (!empty($GLOBALS["SessionTableName"])) {
    require_once dirname(__FILE__).'/admin/sessionlib.php';
  }
  @session_start(); # it may have been started already in languages
}

if (!isset($_POST) && isset($HTTP_POST_VARS)) {
    require "admin/commonlib/lib/oldphp_vars.php";
}

/*
  We request you retain the inclusion of pagetop below. This will add invisible
  additional information to your public pages.
  This not only gives respect to the large amount of time given freely
  by the developers  but also helps build interest, traffic and use of
  PHPlist, which is beneficial to it's future development.

  Michiel Dethmers, Tincan Ltd 2000,2006
*/
include "admin/pagetop.php";
if (isset($_GET['id'])) {
  $id = sprintf('%d',$_GET['id']);
} else {
  $id = 0;
}

//here is the hacked stuff for blacklisting
//it is mostly taken from the links listed in my post
echo '<html>';
echo 'phplistadd running <br><br>';


require_once dirname(__FILE__) .'/admin/commonlib/lib/userlib.php';


//init
$emails= array();
$attributes=NULL;
$rownum=0;


// open file and loop, processing each line in turn
$fh = fopen($emailfile, 'r');
echo "file opened";
if ($fh)
   {
   while (!feof($fh))
      {
      $theline = fgets($fh);
      $emails[$rownum] = trim($theline);
      echo $emails[$rownum];
      addUserToBlackList($emails[$rownum], 'Admin Blacklisted');
      echo " yep - blacklisted: ".$emails[$rownum]."<br>";
      ++$rownum;
      }
      $count = 0;


  return;
   }
else
   {
   echo 'Failed to open file "' . $emailfile . '".<br>';
   }
   

// done








?>
amoswright
phpLister
 
Posts: 8
Joined: 4:22pm, Tue 25 Mar, 2008

Postby J_S » 2:06pm, Thu 15 May, 2008

mm..
seems to be ok
even more so if it works for you
J_S
Admin
 
Posts: 674
Joined: 10:18pm, Fri 11 Apr, 2003

code update, makes changes show up in phplist interface

Postby amoswright » 5:42pm, Thu 15 May, 2008

ok then... forging ahead, (foolishly, i'm sure) I added some functionality to make it so that the user_user table is updated. That way, your blacklisted users will show up under admin interface --> users --> show only blacklisted users. the use is exactly as outlined above. here is the modified code:

Code: Select all
<?php
//Here is your file with the list of emails with one email on each line, and nothing else..
$emailfile="blacklist.txt";

//here is a modified version of the addUserToBlackList function, so that the user_user table is also changed
function addUserToBlackListUpdate($email) {
   $id= getUniqid();
  Sql_Query(sprintf('insert ignore into %s (email, blacklisted, uniqid) values (\'%s\', 1, \'%s\') on duplicate key update blacklisted = 1, uniqid =\'%s\'',
    $GLOBALS["tables"]["user"],addslashes($email), $id, $id));
    }

//this code section is copied from the root index file, not sure how much of it you need, but doesn't seem to hurt..
ob_start();
$er = error_reporting(0);
require_once dirname(__FILE__) .'/admin/commonlib/lib/magic_quotes.php';
require_once dirname(__FILE__).'/admin/init.php';
## none of our parameters can contain html for now
$_GET = removeXss($_GET);
$_POST = removeXss($_POST);
$_REQUEST = removeXss($_REQUEST);

if (isset($_SERVER["ConfigFile"]) && is_file($_SERVER["ConfigFile"])) {
#  print '<using>'."\n";
  include $_SERVER["ConfigFile"];
} elseif (isset($_ENV["CONFIG"]) && is_file($_ENV["CONFIG"])) {
#  print '<using>'."\n";
  include $_ENV["CONFIG"];
} elseif (is_file("config/config.php")) {
#  print '<using>'."\n";
  include "config/config.php";
} else {
  print "Error, cannot find config file\n";
  exit;
}
if (0) {#isset($GLOBALS["developer_email"]) && $GLOBALS['show_dev_errors']) {
  error_reporting(E_ALL);
} else {
  if (isset($error_level)) {
    error_reporting($error_level);
  } else {
    error_reporting($er);
  }
}

require_once dirname(__FILE__).'/admin/'.$GLOBALS["database_module"];
require_once dirname(__FILE__)."/texts/english.inc";
include_once dirname(__FILE__)."/texts/".$GLOBALS["language_module"];
require_once dirname(__FILE__)."/admin/defaultconfig.inc";
require_once dirname(__FILE__).'/admin/connect.php';
include_once dirname(__FILE__)."/admin/languages.php";
include_once dirname(__FILE__)."/admin/lib.php";
$I18N= new phplist_I18N();

if ($require_login || ASKFORPASSWORD) {
  # we need session info if an admin subscribes a user
  if (!empty($GLOBALS["SessionTableName"])) {
    require_once dirname(__FILE__).'/admin/sessionlib.php';
  }
  @session_start(); # it may have been started already in languages
}

if (!isset($_POST) && isset($HTTP_POST_VARS)) {
    require "admin/commonlib/lib/oldphp_vars.php";
}

/*
  We request you retain the inclusion of pagetop below. This will add invisible
  additional information to your public pages.
  This not only gives respect to the large amount of time given freely
  by the developers  but also helps build interest, traffic and use of
  PHPlist, which is beneficial to it's future development.

  Michiel Dethmers, Tincan Ltd 2000,2006
*/
include "admin/pagetop.php";
if (isset($_GET['id'])) {
  $id = sprintf('%d',$_GET['id']);
} else {
  $id = 0;
}


//here is the section that processes and displays the (hopefully) changed or added emails
//this code is sorta modified from some of the links in my original post
echo '<html>';
echo 'phplistadd running <br><br>';


require_once dirname(__FILE__) .'/admin/commonlib/lib/userlib.php';


//init
$emails= array();
$attributes=NULL;
$rownum=0;


// open file and loop, processing each line in turn
$fh = fopen($emailfile, 'r');
echo "file opened";
if ($fh)
   {
   while (!feof($fh))
      {
      $theline = fgets($fh);
      $emails[$rownum] = trim($theline);
      addUserToBlackList($emails[$rownum], 'Admin Blacklisted');
      addUserToBlackListUpdate($emails[$rownum]);
      echo " yep - blacklisted: ".$emails[$rownum]."<br>";
      ++$rownum;
      }
      $count = 0;


  return;
   }
else
   {
   echo 'Failed to open file "' . $emailfile . '".<br>';
   }
   
// done

?>
amoswright
phpLister
 
Posts: 8
Joined: 4:22pm, Tue 25 Mar, 2008

Postby albert0346 » 9:17am, Fri 19 Sep, 2008

@amoswright

Does your solution work for version 2.10.5?

Thanks.

Albert
albert0346
PL Geek
 
Posts: 53
Joined: 9:53am, Sat 18 Aug, 2007

Re: unsubscribe, blacklist, disable... is this method ok?

Postby dotzilla » 12:47pm, Mon 05 Jul, 2010

Hey guys,

thanks for that useful script.
There are some issues with the script on newer phplist versions.

Is anybody out there who is interested and able to modify the script to work with the current phplist version?

Thanks a lot!
dotzilla
phpLister
 
Posts: 7
Joined: 2:43pm, Wed 08 Jul, 2009

Re: unsubscribe, blacklist, disable... is this method ok?

Postby marcovolpe » 3:13pm, Tue 21 Dec, 2010

I've tryed now and looks like it's working on 2.10.12...
What the issues of the newer versions that need to be updated?
marcovolpe
phpList newbie
 
Posts: 1
Joined: 3:12pm, Tue 21 Dec, 2010

Re: unsubscribe, blacklist, disable... is this method ok?

Postby Kruge » 4:01pm, Mon 31 Oct, 2011

version 2.10.17

- Works like a charm. (after I thought of looking into the htaccess file to see why I didn't get Permissions to run it) :)
Kruge
PL Nut
 
Posts: 22
Joined: 2:15pm, Wed 01 Jun, 2011

Re: unsubscribe, blacklist, disable... is this method ok?

Postby alba90 » 5:49am, Tue 11 Dec, 2012

This is the script I was looking for, just wanted to say thank you so much for this post, despite being 1 year ago... :P.
alba90
phpList newbie
 
Posts: 1
Joined: 5:42am, Tue 11 Dec, 2012


Return to Advanced Answers, Howtos, Tips & Tricks

Who is online

Users browsing this forum: No registered users and 1 guest