Forum Moderators: coopster

Message Too Old, No Replies

Help! Our upload script can't send mail notifications anymore

Need help to fix code to be compatible with suPHP

         

Lisaweb

11:47 pm on Apr 20, 2017 (gmt 0)

10+ Year Member



In order to speed up our WP site, our host recently changed us to suPHP. Unfortunately, we have an upload script that we can't live without, that is no longer sending us email notifications. Here's the error:


$* is no longer supported at /***/***/upload.cgi line 1022.
sendmail: sendmail cannot be called directly from a shell with the current user id

So it looks like we'll need to use smtp auth to send mail from the script. However, the original developer has abandoned support for this script, and my knowledge of PHP is limited.

Is there a PHP Guru who can help me edit this portion of the script so it can send mail notifications again?

Below is the portion of the script that sends mail. Any help greatly appreciated!

sub send_mail_NT {
my ( %VAR, @atts );

$VAR{sndrEml} = shift;
$VAR{sndrNme} = shift;
$VAR{rcvrEml} = shift;
$VAR{rcvrNme} = shift;
$VAR{subject} = shift;
$VAR{message} = shift;
$VAR{ccrcEml} = shift;
$VAR{ccrcNme} = shift;

use Socket;

$VAR{CRLF} = "\015\012";
$VAR{debug} = 0;

if($VAR{debug}){
#BEGIN {
#$| = 1;
#open (STDERR, ">&STDOUT");
#print qq~Content-type: text/html\n\n<pre>~;
#}
}

$VAR{message} =~ s/\r+//ig;
$VAR{message} =~ s/\n{3,300}/$VAR{CRLF}$VAR{CRLF}/ig;
$VAR{message} =~ s/\n/$VAR{CRLF}/ig;
$VAR{attPths} =~ s/\s+//ig;

$VAR{HTMLmess} = $VAR{message};
$VAR{TEXTmess} = $VAR{message};
if($CONFIG{mail_format} == 2){
$VAR{TEXTmess} =~ s/\&quot;/\"/g;
$VAR{TEXTmess} =~ s/\&lt;/\</ig;
}
$VAR{files} = qq~~;
$VAR{hasAtts} = 0;

$VAR{bound1} = qq~----=_NextPart_P_115Dream~; # printable
$VAR{bound2} = qq~----=_NextPart_A_SubHB~; # attachments
$VAR{bound3} = qq~----=_NextPart_E_SlowTrain~; # embded

$VAR{fm} = $VAR{sndrNme} =~ /\w+/ ? qq~$VAR{sndrEml} ($VAR{sndrNme})~ : $VAR{sndrEml};
$VAR{to} = $VAR{rcvrNme} =~ /\w+/ ? qq~$VAR{rcvrEml} ($VAR{rcvrNme})~ : $VAR{rcvrEml};
$VAR{cc} = $VAR{ccrcNme} =~ /\w+/ ? qq~$VAR{ccrcEml} ($VAR{ccrcNme})~ : $VAR{ccrcEml};

$* = 1; # Set regex to handle multiple line strings
$VAR{SMTPserver} = $CONFIG{mailprogram};
$VAR{SMTPport} = 25;
$VAR{Stream} = $] > 5 ? SOCK_STREAM : 1;
$VAR{AFinet} = $] > 5 ? AF_INET : 2;

$VAR{protocol} = (getprotobyname('tcp'))[2];
$VAR{hostName} = (gethostbyname($VAR{SMTPserver}))[4];

$VAR{bindSock} = pack('S n a4 x8', $VAR{AFinet}, 0, $VAR{hostName});
$VAR{connSock} = pack('S n a4 x8', $VAR{AFinet}, $VAR{SMTPport}, $VAR{hostName});

unless(socket(M, $VAR{AFinet}, $VAR{Stream}, $VAR{protocol})){
if($VAR{debug}){ print qq~No socket established\n\n~; } return;
}

bind(M, $VAR{bindSock});

unless(connect(M, $VAR{connSock})){
if($VAR{debug}){ print qq~No connection established\n\n~; } return;
}

$VAR{selected} = select(M); $| = 1; select($VAR{selected});

select(undef, undef, undef, 1);
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~Connection accepted:$_ \n\n~; }

print M qq~HELO $VAR{SMTPserver}$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~HELO:$_ \n\n~; }
if(!/^\s*250/){ if($VAR{debug}){ print qq~HELO failed\n\n~;} return; }

# authenticate ourselves?
if($CONFIG{mailuser} =~ /\w+/ && $CONFIG{mailpass} =~ /\w+/){
$VAR{SMTPuser} = $CONFIG{mailuser};
$VAR{SMTPpass} = $CONFIG{mailpass};

$VAR{length} = $VAR{SMTPuser};
$VAR{encoded} = substr(pack('u57', $VAR{SMTPuser}), 1); chop($VAR{encoded});
$VAR{encoded} =~ tr| -_`|A-Za-z0-9+/A|;
$VAR{buff} = (3 - ($VAR{length} % 3)) % 3;
substr($VAR{encoded}, -$VAR{buff}, $VAR{buff}) = '=' x $VAR{buff};
$VAR{SMTPuser} = $VAR{encoded};

$VAR{length} = $VAR{SMTPpass};
$VAR{encoded} = substr(pack('u57', $VAR{SMTPpass}), 1); chop($VAR{encoded});
$VAR{encoded} =~ tr| -_`|A-Za-z0-9+/A|;
$VAR{buff} = (3 - ($VAR{length} % 3)) % 3;
substr($VAR{encoded}, -$VAR{buff}, $VAR{buff}) = '=' x $VAR{buff};
$VAR{SMTPpass} = $VAR{encoded};

print M qq~AUTH LOGIN$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~AUTH LOGIN: $_\n\n~; }

print M qq~$VAR{SMTPuser}$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~Auth Username: $_\n\n~; }

print M qq~$VAR{SMTPpass}$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~Auth Password: $_\n\n~; }
}

print M qq~MAIL FROM:$VAR{sndrEml}$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~MAIL FROM:$_\n\n~; }
if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Denied.\n\n~; } return; }

print M qq~RCPT TO:$VAR{rcvrEml}$VAR{CRLF}~;
sysread(M, $_, 1024); /[^0-9]*(\d\d\d)/;
if($VAR{debug}){ print qq~RCPT TO:$_\n\n~; }
if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Denied. Auth required?\n\n~; } return; }

if($VAR{ccrcEml}){
print M qq~RCPT TO:$VAR{ccrcEml}$VAR{CRLF}~;
sysread(SMTP, $_, 1024); /[^0-9]*(\d\d\d)/;
if($VAR{debug}){ print qq~RCPT TO CC:$_\n\n~; }
if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Denied. Auth required?\n\n~; } return; }
}

print M qq~DATA$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~Ready to send DATA:$_\n\n~; }
if(!/[^0-9]*354/){ if($VAR{debug}){ print qq~Denied.\n\n~; } return; }

print M qq~From: $VAR{fm}$VAR{CRLF}~;
print M qq~To: $VAR{to}$VAR{CRLF}~;
print M qq~CC: $VAR{cc}$VAR{CRLF}~ if $VAR{ccrcEml};
print M qq~Subject: $VAR{subject}$VAR{CRLF}~;
print M qq~MIME-Version: 1.0$VAR{CRLF}~;

if($CONFIG{mail_format} == 1){
print M qq~$VAR{fileHeaders}~;
print M qq~$VAR{embedHeaders}~;

print M qq~Content-Type: multipart/alternative;$VAR{CRLF}~;
print M qq~\tboundary="$VAR{bound1}"$VAR{CRLF}$VAR{CRLF}$VAR{CRLF}~;
print M qq~--$VAR{bound1}$VAR{CRLF}~;
print M qq~Content-Type: text/plain;$VAR{CRLF}~;
print M qq~Content-Transfer-Encoding: 7bit$VAR{CRLF}$VAR{CRLF}~;
print M qq~$VAR{TEXTmess}$VAR{CRLF}$VAR{CRLF}~;

print M qq~--$VAR{bound1}$VAR{CRLF}~;
print M qq~Content-Type: text/html; $VAR{charset2}$VAR{CRLF}$VAR{CRLF}~;

print M qq~$VAR{HTMLmess}$VAR{CRLF}~;

print M qq~$VAR{CRLF}$VAR{CRLF}--$VAR{bound1}--$VAR{files}~;
} else {
print M qq~$VAR{fileHeaders}~;
print M qq~Content-Type: text/plain;$VAR{CRLF}~;
print M qq~Content-Transfer-Encoding: 7bit$VAR{CRLF}$VAR{CRLF}~;
print M qq~$VAR{TEXTmess}$VAR{CRLF}$VAR{CRLF}$VAR{files}~;
}

print M qq~$VAR{CRLF}.$VAR{CRLF}~;
sysread(M, $_, 1024);
if($VAR{debug}){ print qq~Message ended:$_\n\n~; }
if(!/[^0-9]*250/){ if($VAR{debug}){ print qq~Message failed.\n\n~; } return; }

if(!shutdown(M, 2)){
if($VAR{debug}){ print qq~Shutdown failed:$_\n\n~; } return;
} else { return 1; }
}

martinibuster

3:08 am on Apr 21, 2017 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Sounds like it MIGHT be an issue with permissions. It could be the script can still run but that the script is conflicting with the security needs of suPHP.

When debugging a problem I take a look at the line an error message cites. In your case it's citing an issue at line 1022. So maybe that's a place to begin the diagnosis.

Peter_S

9:50 am on Apr 21, 2017 (gmt 0)

5+ Year Member Top Contributors Of The Month



It doesn't look like PHP code.

But in PHP you can simply use the "mail" function : [php.net...]

Lisaweb

8:07 pm on Apr 24, 2017 (gmt 0)

10+ Year Member



I'm sorry- I had my head buried in php and so called this the same - but of course you guys know it was written in Perl. I will try permissions and see where it gets me. Thanks.