1

I have tried to add a proxy server to the following perl script:

#!/usr/bin/perl

TO='list of email adresses here';

require "/usr/local/SCRIPTS/www-tools/service-name/jcode.pl";
use LWP::UserAgent;
$sendmail = '/usr/lib/sendmail -t -oi';
######################
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$mon  = $mon+1;

$MMDD = sprintf("%02d/%02d",$mon,$mday);
$HHMM = sprintf("%02d:%02d",$hour,$min);

$err = 0;

#Ph.1 WebAccess-1stServer(VIP)
@ret = &SiteAccess( 'http://IP:PORT/hostname/' , 
                    'http://IP:PORT/hostname/Login.do' );

if( $ret[0] != 200 || $ret[2] != 200 ){
  $err = 1;
}
$body  = &jcode::euc($ret[1]);
if( $body !~ m#<title>ServiceName<\/title># ){
  $err = 2;
}

$title = &jcode::euc('<title>web$BO"7H(J</title>');
$body  = &jcode::euc($ret[3]);
if( $body !~ m#$title# ){
    $err = 3;
}
&MailSend('Web')  if( $err > 0 );
$err=0;

#Ph.2 WebAccess-2ndServer(Direct)
@ret = &SiteAccess( 'http://2ndServerIP:PORT/hostname/' , 
                    'http://2ndServerIP:PORT/hostname/Login.do' );


if( $ret[0] != 200 || $ret[2] != 200 ){
    $err = 4;
}
$body  = &jcode::euc($ret[1]);
if( $body !~ m#<title>ServiceName<\/title># ){
    $err = 5;
}

$title = &jcode::euc('<title>web$BO"7H(J</title>');
$body  = &jcode::euc($ret[3]);
if( $body !~ m#$title# ){
    $err = 6;
}
&MailSend('Web2nd')  if( $err > 0);
$err=0;

#Ph.3 POP
@ret = &SiteAccess( 'http://IP:PORT/hostname/' ,
                    'http://IP:PORT/hostname/Login.do' );

if( $ret[0] != 200 || $ret[2] != 200 ){
    $err = 7;
}
$body  = &jcode::euc($ret[1]);
if( $body !~ m#<title>ServiceName</title># ){
    $err = 8;
}

$title = &jcode::euc('<title>TitleJapanese<(J</title>');
$body  = &jcode::euc($ret[3]);
if( $body !~ m#$title# ){
    $err = 9;
}

&MailSend('POP')  if( $err > 0);
$err=0;


#Ph.4 Exchange(EWS)
@ret = &SiteAccess( 'http://IP:PORT/hostname/' ,
                    'http://IP:PORT/hostname/Login.do' );

if( $ret[0] != 200 || $ret[2] != 200 ){
    $err = 10;
}
$body  = &jcode::euc($ret[1]);
if( $body !~ m#<title>ServiceName</title># ){
    $err = 11;
}

$title = &jcode::euc('<title>TitleJapanese<(J</title>');
$body  = &jcode::euc($ret[3]);
if( $body !~ m#$title# ){
    $err = 12;
}

&MailSend('Exchange-EWS')  if( $err > 0);
$err=0;



sub SiteAccess{
    my $url1 = shift;
    my $url2 = shift;
    # $ua,$req,$res;i
    my @r;

    if($url1 ne ''){
        $ua = LWP::UserAgent->new;

        $req = HTTP::Request->new(GET => $url1);
        $res = $ua->request($req);

        $r[0] = $res->code;
    $r[1] = $res->content;
    }
    if($url2 ne ''){
        $ua = LWP::UserAgent->new;

        $res = $ua->post( $url2,
            {
                    "c" => "don't knwo what that is",
                    "u" => "users ldap",
                    "p" => "password"
                    }, 
                    "Content-Type" => "application/x-www-form-urlencoded",
              "User-Agent"   => "DoCoMo/2.0 N901iS(c100;TB;W24H12;ser123445654654645;icc898114564645667716666f)");

        $r[2] = $res->code;
        $r[3] = $res->content;
     }
    return @r;
}

sub MailSend{
    my $title = shift;
    my $body;
    my $from;
    my @message;

#the following lines need another file name jcode to display properly.    It     just means error code or auth error.

    $message[1] = &jcode::jis('[Web]$B%(%i!<%3!<%I(J');
    $message[4] = &jcode::jis('[Web2nd]$B%(%i!<%3!<%I(J');
    $message[7] = &jcode::jis('[POP]$B%(%i!<%3!<%I(J');
    $message[10] = &jcode::jis('[EWS]$B%(%i!<%3!<%I(J');

    $message[2] = &jcode::jis('[Web]$B%m%0%$%s2hLL(J');
    $message[5] = &jcode::jis('[Web2nd]$B%m%0%$%s2hLL(J');
    $message[8] = &jcode::jis('[POP]$B%m%0%$%s2hLL(J');
    $message[11] = &jcode::jis('[EWS]$B%m%0%$%s2hLL(J');

    $message[3] = &jcode::jis('[Web]auth$B%(%i!<(J');
    $message[6] = &jcode::jis('[Web2nd]auth$B%(%i!<(J');
    $message[9] = &jcode::jis('[POP]auth$B%(%i!<(J');
    $message[12] = &jcode::jis('[EWS]auth$B%(%i!<(J');

    $from = 'mail@abc.com';

    $title = '['.$title.']cnct1 err';

#    $title = $title.'['.$MMDD.$HHMM.']';

    $body =<<END_OF_BODY;
To: $TO
Subject: $title
From: $from

ConnectOneCheck Error
Date       : $MMDD $HHMM
ErrorStatus: $err 
ErrorMsg   : $message[$err] 
END_OF_BODY

open(ML,"| $sendmail") || &error("Can't execute sendmail : $sendmail\n");
    print ML $body;
    close(ML);
}

So now here's the part where I tried to add the usage of a proxy. Most parts are commented out, except for the last function:

!/usr/bin/perl

TO='list of email adresses here';

require "/usr/local/SCRIPTS/www-tools/service-name/jcode.pl";
use LWP::UserAgent;
$sendmail = '/usr/lib/sendmail -t -oi';
######################
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year = $year+1900;
$mon  = $mon+1;

$MMDD = sprintf("%02d/%02d",$mon,$mday);
$HHMM = sprintf("%02d:%02d",$hour,$min);

$err = 0;

The next part is commented out because it is not in use.

@ret = &SiteAccess( 'http://IP:PORT/hostname/' ,
                    'http://IP:PORT/hostname/Login.do' );

if( $ret[0] != 200 || $ret[2] != 200 ){
    $err = 10;
}
$body  = &jcode::euc($ret[1]);
if( $body !‾ m#<title>ConnectONE</title># ){
    $err = 11;
}

$title = &jcode::euc('<title>TitleJapanese</title>');
$body  = &jcode::euc($ret[3]);
if( $body !‾ m#$title# ){
    $err = 12;
}

&MailSend('Exchange-EWS')  if( $err > 0);
$err=0;



sub SiteAccess{
    my $url1 = shift;
    my $url2 = shift;
    # $ua,$req,$res;i
    my @r;

    if($url1 ne ''){
        $ua = LWP::UserAgent->new;
        $ENV{HTTP_proxy} = "proxy fqdn here";                     
        $ua->env_proxy                                                      

        $req = HTTP::Request->new(GET => $url1);
        $res = $ua->request($req);

        $r[0] = $res->code;
    $r[1] = $res->content;
    }
    if($url2 ne ''){
        $ua = LWP::UserAgent->new;
        $ENV{HTTP_proxy} = "proxy fqdn here";                     
        $ua->env_proxy                                                      
           $res = $ua->post( $url2,
            {
                    "c" => "don't knwo what that is",
                    "u" => "users ldap",
                    "p" => "password"
                    }, 
                    "Content-Type" => "application/x-www-form-urlencoded",
              "User-Agent"   => "DoCoMo/2.0 N901iS(c100;TB;W24H12;ser123445654654645;icc898114564645667716666f)");

        $r[2] = $res->code;
        $r[3] = $res->content;
     }
    return @r;
}

sub MailSend{
    my $title = shift;
    my $body;
    my $from;
    my @message;

#the following lines need another file name jcode to display properly.    It     just means error code or auth error.

    #$message[1] = &jcode::jis('[Web]$B%(%i!<%3!<%I(J');
    #$message[4] = &jcode::jis('[Web2nd]$B%(%i!<%3!<%I(J');
    #$message[7] = &jcode::jis('[POP]$B%(%i!<%3!<%I(J');
    $message[10] = &jcode::jis('[EWS]$B%(%i!<%3!<%I(J');

    #$message[2] = &jcode::jis('[Web]$B%m%0%$%s2hLL(J');
    #$message[5] = &jcode::jis('[Web2nd]$B%m%0%$%s2hLL(J');
    #$message[8] = &jcode::jis('[POP]$B%m%0%$%s2hLL(J');
    $message[11] = &jcode::jis('[EWS]$B%m%0%$%s2hLL(J');

    #$message[3] = &jcode::jis('[Web]auth$B%(%i!<(J');
    #$message[6] = &jcode::jis('[Web2nd]auth$B%(%i!<(J');
    #$message[9] = &jcode::jis('[POP]auth$B%(%i!<(J');
    $message[12] = &jcode::jis('[EWS]auth$B%(%i!<(J');

    $from = 'mail@abc.com';

    $title = '['.$title.']cnct1 err';

#    $title = $title.'['.$MMDD.$HHMM.']';

    $body =<<END_OF_BODY;
To: $TO
Subject: $title
From: $from

ConnectOneCheck Error
Date       : $MMDD $HHMM
ErrorStatus: $err 
ErrorMsg   : $message[$err] 
END_OF_BODY

open(ML,"| $sendmail") || &error("Can't execute sendmail : $sendmail\n");
    print ML $body;
    close(ML);
}

OK so I have added a proxy using this function

$ua = LWP::UserAgent->new;
$ENV{HTTP_proxy} = "here is the FQDN of the proxy";                     
$ua->env_proxy    

But it doesn't compile well. It gives me this error:

syntax error at /usr/local/SCRIPTS/www-tools/connectone/ConnectOneCheck.pl line 93, near "$body !" Unrecognized character \xE2; marked by <-- HERE after f( $body !<-- HERE near column 12 at /usr/local/SCRIPTS/www-tools/connectone/ConnectOneCheck.pl line 93.

Is here someone who can get this script running?

i716
  • 67
  • 1
  • 11
  • You're more likely to get good help if you make it easy for us to help you. Ideally, that means posting a _small_, self-contained example which demonstrates the problem in the least amount of code possible. (This also has the nice side-effect that, in the process of creating such an example, you're very likely to find the solution yourself.) Failing that, post the actual code you're running (not a history of "this is the original code, and this is commented out, and then I added this..." which we need to try to piece together) and clearly mark the line with the error (which line is line 93?). – Dave Sherohman Apr 25 '18 at 07:09
  • @Dave Sherohman: Fair advice. I will review my post as soon as I get the time to do it. – i716 Apr 25 '18 at 07:23

2 Answers2

0

Your script does not compile as it is presented here. In Line 3 where it says

TO='list of

it needs to be changed to

$TO='list of

...and then it compiles for me. Without the error you are getting in line 93.

From my limited viewpoint this means there may actually be some misprint in your code line 93 that did not make it to the code on this side.

If you erase your line 93 in your script and copy the line 93 back into your code, you might be settled.

Halperly
  • 1
  • 2
0

You have a non-ASCII character OVERLINE (U+203E) () in your source code, and that is the cause of the error you have shown.

The first code point of Unicode characters in the U+2000–206F "General Punctuation" block is \xE2. That was the first clue. The overline is 0xE2 0x80 0xBE in hex.

Perhaps there was some encoding problem that translated the tildes (~) in those few places in your original source into these overlines.

You may also see errors like this when “curly” quotes, en (–) and em (—) dashes, and the like have crept into your source code. Sometimes it's due to well-meaning software such as WordPress or MS Word automatically substituting, for example, straight for curly quotes, which you in turn copy-pasted into your source code.

It's difficult to spot these visually (I didn't notice the overline at first), but this shell one-liner strips characters in the non-ASCII range and then compares side-by-side with the original file on the left:

# assumes Bash shell
sdiff --suppress-common-lines script.pl <(tr -cd '\11\12\15\40-\176' <script.pl)

A similar encoding problem in a Python context, with an error message about \xE2, is described in this SO question. This gave me the idea to look for non-ASCII characters in your source code.

TheDudeAbides
  • 1,821
  • 1
  • 21
  • 29