Zubrag.com
August 20, 2019, 01:46:54 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Cpanel Forwarder: redirect to "Failure Message" on X3  (Read 15742 times)
sandheep
Newbie
*
Posts: 3


« on: November 18, 2007, 08:41:11 PM »

Hola,

BTW, this script is fantastic--so many of my e-mail woes are being taken care of by this...many thanks--got a "donate" link somewhere?

Also, can you tell me how to mod the script (on X3) to setup a forward to :fail:?  With X3, it doesn't seem to accept :fail: in the redirect box.

Thanks again!

Sandheep

Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #1 on: November 20, 2007, 06:21:45 AM »

Hi.

I believe this would work. Did not test it though as i do not have access to cPanel now.
Code:
<?php

###############################################################
# cPanel Email Forwarder Creator
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################

////////////////////////////////////////////////////////////////
/////////////////////// SETTINGS START&#160; ////////////////////////
////////////////////////////////////////////////////////////////

// cpanel user (the one you login to cpanel)
define('CPANELUSER','cpanel-username-here');

// cpanel password (the one you login to cpanel)
define('CPANELPASS','cpanel-password-here');

// your cpanel domain (localhost, or domain name)
define('CPANELDOMAIN','localhost');

// cPanel skin (usually "x")
// Check http://www.zubrag.com/articles/determine-cpanel-skin.php to know it for sure
define('CPANEL_SKIN','x');

// Allow multiple forwarders for the same email?
// true - allow, false - disallow
define('ALLOW_MULTIPLE'false);

////////////////////////////////////////////////////////////////
/////////////////////// END OF SETTINGS ////////////////////////
////////////////////////////////////////////////////////////////

function getVar($name$def '') {
&
#160; if (isset($_REQUEST[$name]) && ($_REQUEST[$name] != ''))
&#160; &#160; return $_REQUEST[$name];
&#160; else
&#160; &#160; return $def;
}

$cpuser CPANELUSER;
$cppass CPANELPASS;
$cpdomain CPANELDOMAIN;
$cpskin CPANEL_SKIN;

$euser=getVar('euser');
$edomain=getVar('edomain');
$eforward1 getVar('eforward1');
$eforward2 getVar('eforward2');
$eforward3 getVar('eforward3');
$failmsgs getVar('failmsgs');
$failmsgs urlencode(getVar('failmsgs'));

if (empty(
$euser) || empty($edomain)) {
&
#160; echo "All fields are required to create email forwarding:<br>
<form method='post'>
&
#160; Username:<input name='euser' value='$euser'> (sample: john)<br>
&#160; Domain:<input name='edomain' value='$edomain'> (sample: mysite.com)<br>
&#160; Redirect to email: <input name='eforward1' value='$eforward'> (sample: jimm@site2.com)<br>
&#160; Discard with error to sender: <input name='eforward2'> (sample: jimm@site2.com)<br>
&#160; Failure Message (seen by sender): <input name='failmsgs' type='text' size='40' value='No such person at this address'><br>
&#160; Pipe to a Program: <input name='eforward3'> (sample: jimm@site2.com)<br>
&#160; <input type='submit' value='Create forwarder' style='border:1px solid black'>
</form>";
&#160; die();
}

if (!ALLOW_MULTIPLE) {
&#160; // get list of existing forwarders for this email
&#160; $forwarders = array();
&#160; preg_match_all('/\?email=' . $euser. '@' . $edomain . '=([^"
]*)/', file_get_contents("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/fwds.html"), $forwarders);

&#160; if (count($forwarders[1]) > 0) {
&#160; &#160; die("Email forwarder for this account already exists.");
&#160; }
} // ALLOW_MULTIPLE

if ($eforward1 != '') $fwdopt = "fwd";
else if ($eforward2 != '') { $fwdopt = "fail"; $eforward1 = $eforward2;}
else if ($eforward3 != '') {$fwdopt = "pipe"; $eforward1 = $eforward3;}


// Create email forwarder
$f = fopen
("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddfwd.html?email=$euser&domain=$edomain&fwdemail=$eforward1&failmsgs=$failmsgs&fwdopt=$fwdopt",
 "r");
if (!$f) {
&#160; die('
Cannot create forwardingPossible reasons"fopen" function disallowed on your server, or PHP is running in SAFE mode');
}

$text = "";

// Check result
while (!feof ($f)) {
&#160; $text = $text . fgets ($f, 1024);;
}
fclose($f);

if ( ereg ("failure", $text, $out) || !(strpos($text,"redirected") || strpos($text,"copied")) ) {
&#160; die('
Cannot create email forwarding. . $text);
}

echo 
"Email Forwarder created: $euser@$edomain =&gt; $eforward1";

?>

Donate page is located here http://www.zubrag.com/donate.php
Logged
sandheep
Newbie
*
Posts: 3


« Reply #2 on: November 21, 2007, 01:27:47 AM »

Many thanks--a few corrections:

  • Lines 79 & 80 need semicolons at the end of the lines (but before the closed squiggly bracket)
  • For X3, line 99 needs "forwarded" changed to "copied" (I know you know that, but just for everyone else's reference

Also, since there aren't any radio buttons on the page (as there are in the cpanel interface), its not so intuitive which option (e.g. redirect, fail, pipe) will be executed.

For my purposes, though, this works fantastic!  I can't thank you enough.  Catchalls were once recommended to me for a good way of stopping spam, but after I started getting hit with dictionary attacks, my domain was getting greylisted.  I wrote some scripts to parse my inbox so I could create actual forwards for all the addresses I have given out over the years, but using your script, I can easily create new forwards on the fly (no need to login to cpanel anymore).

Many thanks again,

Sandheep
Logged
zubrag
Administrator
Hero Member
*****
Posts: 788


WWW
« Reply #3 on: November 21, 2007, 03:40:38 AM »

This one includes radio buttons like cPanel 11 has, and added "copied" like you suggested. Did not test though. Thanks.

Code:
<?php

###############################################################
# cPanel Email Forwarder Creator
###############################################################
# Visit http://www.zubrag.com/scripts/ for updates
###############################################################

////////////////////////////////////////////////////////////////
/////////////////////// SETTINGS START  ////////////////////////
////////////////////////////////////////////////////////////////

// cpanel user (the one you login to cpanel)
define('CPANELUSER','cpanel-username-here');

// cpanel password (the one you login to cpanel)
define('CPANELPASS','cpanel-password-here');

// your cpanel domain (localhost, or domain name)
define('CPANELDOMAIN','localhost');

// cPanel skin (usually "x")
// Check http://www.zubrag.com/articles/determine-cpanel-skin.php to know it for sure
define('CPANEL_SKIN','x');

// Allow multiple forwarders for the same email?
// true - allow, false - disallow
define('ALLOW_MULTIPLE'false);

////////////////////////////////////////////////////////////////
/////////////////////// END OF SETTINGS ////////////////////////
////////////////////////////////////////////////////////////////

function getVar($name$def '') {
  if (isset(
$_REQUEST[$name]) && ($_REQUEST[$name] != ''))
    return 
$_REQUEST[$name];
  else
    return 
$def;
}

$cpuser CPANELUSER;
$cppass CPANELPASS;
$cpdomain CPANELDOMAIN;
$cpskin CPANEL_SKIN;

$euser=getVar('euser');
$edomain=getVar('edomain');
$fwdemail getVar('fwdemail');
$pipefwd getVar('pipefwd');
$failmsgs getVar('failmsgs');
$failmsgs urlencode(getVar('failmsgs'));
$fwdopt getVar('fwdopt');

if (empty(
$euser) || empty($edomain)) {
  echo 
"<h1>Add a new Forwarder</h1>
<br />
<form method='post'>
<h2>Address</h2>
  Username:<input name='euser' value='$euser'> (sample: john) @ <input name='edomain' value='$edomain'> (sample: mysite.com)<br>
<h2>Destination</h2>
<p><input name='fwdopt' type='radio' value='fwd' checked /> Forward
to email address: <input name='fwdemail' type='text' size='20' /></p>

<p><input name='fwdopt' type='radio' value='fail' /> Discard with error to sender (at SMTP time)</p>
<blockquote><p>Failure Message (seen by sender):
<input name='failmsgs' type='text' size='40' value='No such person at this address' />
</p></blockquote>

<p><input name='fwdopt' type='radio' value='pipe' /> Pipe to a Program: <input name='pipefwd' type='text' size='20' /><br />
<input type='submit' value='Create forwarder' style='border:1px solid black'>
</p>
</form>
"
;
  die();
}

if (!
ALLOW_MULTIPLE) {
  
// get list of existing forwarders for this email
  
$forwarders = array();
  
preg_match_all('/\?email=' $euser'@' $edomain '=([^"]*)/'file_get_contents("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/fwds.html"), $forwarders);

  if (
count($forwarders[1]) > 0) {
    die(
"Email forwarder for this account already exists.");
  }
// ALLOW_MULTIPLE

// Create email forwarder
$f fopen
("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/doaddfwd.html?email=$euser&domain=$edomain&fwdemail=$fwdemail&failmsgs=$failmsgs&pipefwd=$pipefwd&fwdopt=$fwdopt",
 
"r");
if (!
$f) {
  die(
'Cannot create forwarding. Possible reasons: "fopen" function disallowed on your server, or PHP is running in SAFE mode');
}

$text "";

// Check result
while (!feof ($f)) {
  
$text $text fgets ($f1024);;
}
fclose($f);

if ( 
ereg ("failure"$text$out) || !(strpos($text,"redirected") || strpos($text,"copied")) ) {
  die(
'Cannot create email forwarding.' $text);
}

echo 
"Email Forwarder created: $euser@$edomain =&gt; " . ($fwdopt == 'fail' ':Fail:' $fwdemail.$pipefwd);

?>
Logged
cb
Newbie
*
Posts: 7


« Reply #4 on: June 20, 2008, 11:23:02 AM »

I keep getting a blank page when clicking on "Create Forwarder" for theme x3.  Has anyone got their program running?

This was running great until I was changed over to x3 from x.

I'm also extremely concerned about the possibility of creating a forwarding account that is the same as an existing email account.  As it stands, someone can create the forwarder webmaster@zubrag.com and get a copy of every email received, possibly without the knowledge of the webmaster.  I'd like to see a check of duplication of email accounts as it has been done for duplication of forwarders.
Logged
cb
Newbie
*
Posts: 7


« Reply #5 on: July 08, 2008, 11:57:06 AM »

I cannot get this to work on cPanel 11 and theme x3.
Does anyone have a solution and a working script?
Logged
ozace
Newbie
*
Posts: 3


« Reply #6 on: September 09, 2008, 02:48:28 AM »

Hi,
I am adding default addresses fine for parked domains using:
                // check email to fwd to
      // put in the email catchall
      $fwdopt = "fwd";
      $ffff = fopen("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/dosetdef.html?fwdopt=$fwdopt&fwdemail=$default&domain=$mydomain",
       "r");

when I try to make the default go to fail - as per cpanels no such user here using:

      $fwdopt = "fail";
      $failmsgs = urlencode("No such user here");
      $ffff = fopen
      ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/dosetdef.html?fwdopt =$fwdopt&fwdemail=$default&failmsgs=$failmsgs&domain=$mydomain",
       "r");

cpanel - says nope and doesnt seem to pick up the domain and simply spits the dummy

am I doing something basic wrong ?

(same thing happens if I use:
$ffff = fopen
      ("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/dosetdef.html?fwdopt =$fwdopt&failmsgs=$failmsgs&domain=$mydomain",
       "r");  )
Logged
ozace
Newbie
*
Posts: 3


« Reply #7 on: September 09, 2008, 03:41:14 AM »

Hi,
I found that by using :

      $fwdopt = "fail";
      $failmsgs = urlencode("No such user here");
      $fwdemail=":fail:";
      $ffff = fopen("http://$cpuser:$cppass@$cpdomain:2082/frontend/$cpskin/mail/dosetdef.html?fwdopt=$fwdopt&failmsgs=$failmsgs&fwdemail=$fwdemail&domain=$mydomain",
       "r");

it now works :-)
cheers
Jim
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC