Import list of e-mail addresses to blacklist

Discussion in 'Feature Requests' started by Quaxth, Feb 2, 2014.

  1. Quaxth

    Quaxth Member

    As the title say's!

    I was looking for to import, let say an CSV file to the E-Mail Blacklist and didn't find something! Maybe I'm blind?!

    If not, if it could be done, How To.......?

    Or could such feature added to ISPConfig? Same would be for export an already existing Blacklist in ISPConfig to an CSV File!

    It's a lot of trouble to add address by address to the list!

    Please advice.

    Thanks.
     
  2. sjau

    sjau Local Meanie Moderator

    I made myself a little php script that I can run locally and that I use to create aliases and add stuff to the blacklist. It uses Curl to do the stuff. If you know some PHP you could alter it to go through the list...
     
  3. Quaxth

    Quaxth Member

    I wasn't think for my own only, even there'll a lot other looking for such feature of an high profile Control Panel! In reality. it's a pain in the ass for to key in the blacklist's entries one by one and that not once only, it need to done multiple times, for each Mail Domain! Most of the normal users as well as many system administrators didn't have the knowledge for to create such needed scripts. It would need a quite good knowledge of some program language for to to build those script's.
     
  4. sjau

    sjau Local Meanie Moderator

    Well, I did alter my script but didn't test it yet:

    That should add entries to the global blacklist.

    Code:
    <?php
    
    # Define File containing Blacklist Entries
    define('BLACKLIST_',             'blacklist.txt');
    
    # Define Blacklist Settings
    define('ACTIVE_',		'y');
    define('BLACKLIST_TYPE_1_',	'sender');
    define('BLACKLIST_TYPE_2_',	'client');
    define('SERVER_ID_',		'1');
    define('ACCESS_',		'REJECT');
    
    
    # ISPConfig Login and URLs
    define('USER_',			'admin');
    define('PASSWD_',		'xxxx');
    define('DOMAIN_',		'https://ispc.domain.com');
    define('PORT_',                 '8080');
    define('START_PAGE_',		DOMAIN_ . '/index.php');
    define('LOGIN_PAGE_',		DOMAIN_ . '/content.php');
    define('MAIL_BLACKLIST_EDIT_',	DOMAIN_ . '/mail/mail_blacklist_edit.php');
    
    
    # Other Stuff
    define('USERAGENT_', 		'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0');
    define('COOKIE_', 		'/tmp/ispc_user_cookie.txt');
    
    
    
    /**************************************************************************************************************
    *                                                                                                             *
    *                                         HERE BE DRAGONS                                                     *
    *                                                                                                             *
    **************************************************************************************************************/
    
    
    # Run the script to add sender and client blocklist entries
    addBlock('1');
    addBlock('2');
    
    
    function addBlock ($type) {
    
            # Make Login
    	$ch = ISPConfigLogin ();
        
            # Get the mail_alias_edit form to create necessary sessions vars
            curl_setopt($ch, CURLOPT_URL,                   MAIL_BLACKLIST_EDIT_);
            curl_setopt($ch, CURLOPT_PORT ,                     PORT_);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,    false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,    false);
            curl_setopt($ch, CURLOPT_USERAGENT,             USERAGENT_);
            curl_setopt($ch, CURLOPT_COOKIEFILE,            COOKIE_);
            curl_setopt($ch, CURLOPT_POST,                  false);
            curl_setopt($ch, CURLOPT_REFERER,               START_PAGE_);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,        true);
            curl_setopt($ch, CURLOPT_HEADER,                true);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION,        true);
            curl_setopt($ch, CURLOPT_NOBODY,                false);
            $r = curl_exec($ch);
    
            # Read Blacklist file and loop through entries
    	$entries = file(BLACKLIST_);
    	foreach ($entries as $entry)
    	{
                # Get entry and sanitize it
                trim($entry);
    
                # Build data array
                unset($data);
                if($type == 1) { $type_data = BLACKLIST_TYPE_1_; } else { $type_data = BLACKLIST_TYPE_2_; }
                $data = array(
                        'server_id'			=> SERVER_ID_,
                        'source'			=> $entry,
                        'type'			=> $type_data,
                        'active'			=> ACTIVE_,
                        'id'			=> '',
                        'access'			=> ACCESS_,
                        'next_tab'			=> '',
                        'phpsessid'			=> PHPSESSID_
                );
    
                # Transfer post data into url string
                unset($qstring);
                foreach ($data as $key => $val) {
                        $tmp = urlencode($key) . '=' . urlencode($val) . '&';
                        $qstring .= $tmp;
                }
    
                # Make Query
                curl_setopt($ch, CURLOPT_URL,		MAIL_BLACKLIST_EDIT_);
                curl_setopt($ch, CURLOPT_USERAGENT,		USERAGENT_);
                curl_setopt($ch, CURLOPT_COOKIEFILE,	COOKIE_);
                curl_setopt($ch, CURLOPT_POST,		true);
                curl_setopt($ch, CURLOPT_POSTFIELDS,	$qstring);
                curl_setopt($ch, CURLOPT_REFERER,		START_PAGE_);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,	true);
                curl_setopt($ch, CURLOPT_HEADER,		true);
                curl_setopt($ch, CURLOPT_FOLLOWLOCATION,	true);
                curl_setopt($ch, CURLOPT_NOBODY,		false);
                $r = curl_exec($ch);
            }
    
    }
    
    
    
    
    
    function ISPConfigLogin () {
    
    
    	# Start Session Prefetching
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,                   START_PAGE_);
    	curl_setopt($ch, CURLOPT_PORT ,			PORT_);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,	false);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 	false);
    	curl_setopt($ch, CURLOPT_USERAGENT,             USERAGENT_);
    	curl_setopt($ch, CURLOPT_COOKIEJAR,             COOKIE_);
    	curl_setopt($ch, CURLOPT_HEADER,                true);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER,        true);
    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,        true);
    	curl_setopt($ch, CURLOPT_NOBODY,                false);
    	$r = curl_exec($ch);
    
    
    	# Build post data
    	$data = array(
    		'username'		=>	USER_,
    		'passwort'		=>	PASSWD_,
    		's_mod'			=>	'login',
    		's_pg'			=>	'index'
    	);
    
    
    	# Transfer post data into url string
    	foreach ($data as $key => $val) {
    		$tmp = urlencode($key) . '=' . urlencode($val) . '&';
    		$qstring .= $tmp;
    	}
    
    	# Make login
    	curl_setopt($ch, CURLOPT_URL,                   LOGIN_PAGE_);
    	curl_setopt($ch, CURLOPT_PORT ,			PORT_);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,	false);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 	false);
    	curl_setopt($ch, CURLOPT_USERAGENT,             USERAGENT_);
    	curl_setopt($ch, CURLOPT_COOKIEFILE,            COOKIE_);
    	curl_setopt($ch, CURLOPT_POST,                  true);
    	curl_setopt($ch, CURLOPT_POSTFIELDS,            $qstring);
    	curl_setopt($ch, CURLOPT_REFERER,               START_PAGE_);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER,        true);
    	curl_setopt($ch, CURLOPT_HEADER,                true);
    	curl_setopt($ch, CURLOPT_FOLLOWLOCATION,        true);
    	curl_setopt($ch, CURLOPT_NOBODY,                false);
    	$r = curl_exec($ch);
    
    	# Get the PHPSESSID from the cookie
    	$filename = COOKIE_;
    	$handle = fopen($filename, "r");
    	$contents = fread($handle, filesize($filename));
    	fclose($handle);
    	$phpsessid = explode( 'PHPSESSID', $contents);
    	define('PHPSESSID_',		trim($phpsessid[1]));
    
    	return($ch);
    
    }
    
    
    
    ?>
    
     
  5. till

    till Super Moderator Staff Member ISPConfig Developer

    Hi Sjau, instead of using curl, you could have used the ispconfig remote api. Its easier to use :)
     
  6. sjau

    sjau Local Meanie Moderator

    That's true... however mastering curl lets you automate just about every website - even those that don't have APIs :)

    Also, in my script I do a bit more like adding entries to /etc/postfix/header_checks and testing those with:
    Code:
    header_checks = regexp:/etc/postfix/header_checks
    
    in the main.cf
     
    Last edited: Feb 4, 2014
  7. Quaxth

    Quaxth Member

    Auto Bounce-Back

    Just a question: Is there any way to do some Auto Bounce-Back of e-mails classified as Spam?

    Thanks.
     
  8. till

    till Super Moderator Staff Member ISPConfig Developer

    Do you realy want to do that? You will get blacklistes by all major email providers for sending backscatter then.
     
  9. sjau

    sjau Local Meanie Moderator

    depends on what you really mean.
     
  10. Quaxth

    Quaxth Member

    The last 2 week I was getting a lot e-mails from bogus accounts of Yahoo!! That were around 1500!! Luckly only 2 mail addresses of mine were involved and I could easy just delete those e-mail's! I'm only afraid what'll happen if the other mails accounts get altered by that Spam mails too!

    So, what do you thing would be the best solution for such "attacks"?

    Thanks.
     
  11. till

    till Super Moderator Staff Member ISPConfig Developer

    I receive about spams 800 daily, allmost all filtered out automatically to the spam folder. Maybe 2-3 go into my inbox. I filter the emails automatically into the junk folder and have set that folder in my mailclient to delete email that were older then 30 days. So in case I miss a email that went accidently to junk, I can look it up within 30 days.
     
  12. Quaxth

    Quaxth Member

    Normally I just get up to 10 spam mails a day because of the settings in smoothwall.
    On the other hand, I had used Mail Washer Pro for some years on my desktop. And I may start to use them again. Question would be: could I use the data from Mail Washer for to automatically add to the Mail Blacklist's of ISPConfig? Also, if I use the normal Blacklist function in ISPC, I've to create several Blacklist's, one for each e-mail domain, at least! If I could use the global Blacklist from Postfix, could that be used as general blacklist for all e-mail domains and accounts?

    Thanks.
     
  13. sjau

    sjau Local Meanie Moderator

    if you login as administrator into ISPC you can add entries to the global blacklist in the Email tab.
     
  14. Quaxth

    Quaxth Member

    I know that and it didn't answers my question: Would those list be used in ALL Mail Domains and their Mail Accounts?
     
  15. Quaxth

    Quaxth Member

    There's also the possibility to bounce (reject) messages in Content Filtert:

    [​IMG]

    What's about that for to use, will that send back the messages to sender?

    Thanks.
     
  16. Quaxth

    Quaxth Member

    Where are the Blacklist's located for either Spamfilter and Global Filter for Postfix?

    Is it possible for to add the data directly?

    Thanks.
     

Share This Page