Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Help to modify a perl-script

Posted on 2005-03-14
12
Medium Priority
?
218 Views
Last Modified: 2011-10-03
I like to use smtpwrap :

http://www.network-theory.co.uk/articles/smtpwrap.html

But I want to change one thing that I can't figure out how.

I have 5 ip-addresses that I always want to be allowed.


How can i change the script to allow that?

0
Comment
Question by:wqclatre
  • 5
  • 5
  • 2
12 Comments
 
LVL 6

Expert Comment

by:Talmash
ID: 13535072
hi,

this script do:
force "IDLE" of 1 hour before connection from unknown IPies.

to bypass the 1 hour delay for each of the 5 IPies (reduce delay=0 seconds)

@ip = ( "200.145.205.1" "200.145.205.2" "200.145.205.13" "224.145.205.1" "200.145.199.1");
# put all bypassed IPies above

..
my $WAIT_TIME = 3600;

openlog("smtpwrap", "pid", "mail");

my $mysockaddr = getpeername(STDIN) or die;
my ($port, $myaddr) = sockaddr_in($mysockaddr) or die;
my $ip = inet_ntoa($myaddr) or die;
my $net = $ip ; $net =~ s/\.\d+$//;

# NEW SECTION #
while (@allowed_ip) {
  if ($_ == $ip) {
    $WAIT_TIME = 0;
  }
}

tal
0
 
LVL 2

Author Comment

by:wqclatre
ID: 13535476
Thanks. I will test it later to night.

One question thogu.

Shouldn't

@ip = ( "200.145.205.1" "200.145.205.2" "200.145.205.13" "224.145.205.1" "200.145.199.1");

be

@allowed_ip = ( "200.145.205.1" "200.145.205.2" "200.145.205.13" "224.145.205.1" "200.145.199.1");



0
 
LVL 6

Expert Comment

by:Talmash
ID: 13535601
u r correct!
@ip will collide with $ip
correct also the while loop

tal
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 85

Expert Comment

by:ozo
ID: 13535894
Also
    $_ == $ip
should be
    $_ eq $ip
0
 
LVL 85

Expert Comment

by:ozo
ID: 13535957
You could also say

my %allowed_ip;
@allowed_ip{qw(200.145.205.1 200.145.205.2 200.145.205.13 224.145.205.1 200.145.199.1)} = ();

$WAIT_TIME = exists($allowed_ip{$ip})?0:3600;
0
 
LVL 2

Author Comment

by:wqclatre
ID: 13537058
Ok thanks. I will test this now.

Would it be hard to also modify it so all connections from *.microsoft.com would be accepted directly?
0
 
LVL 2

Author Comment

by:wqclatre
ID: 13537202
Have some more problems.

Ut seems like  it don't like the row:

@allowed_ip = ("192.168.1.1" "127.0.0.1");

use strict;
use Socket;
use GDBM_File;
use Sys::Syslog;
use Fcntl qw(:DEFAULT :flock);

my $FILE = "/tmp/greylist.gdbm";



@allowed_ip = ("192.168.1.1" "127.0.0.1");


my $WAIT_TIME = 180;


openlog("smtpwrap", "pid", "mail");

my $mysockaddr = getpeername(STDIN) or die;
my ($port, $myaddr) = sockaddr_in($mysockaddr) or die;
my $ip = inet_ntoa($myaddr) or die;
my $net = $ip ; $net =~ s/\.\d+$//;



while (@allowed_ip) {
    if ($_ eq $ip) {
        $WAIT_TIME = 0;

 }
}

Gives me:

[root@mail root]# telnet localhost 2525
Trying 127.0.0.1...
Connected to localhost.localdomain.
Escape character is '^]'.
String found where operator expected at /usr/sbin/smtpwrap line 29, near ""192.168.1.1" "127.0.0.1""
        (Missing operator before  "127.0.0.1"?)
Global symbol "@allowed_ip" requires explicit package name at /usr/sbin/smtpwrap line 29.
syntax error at /usr/sbin/smtpwrap line 29, near ""192.168.1.1" "127.0.0.1""
Global symbol "@allowed_ip" requires explicit package name at /usr/sbin/smtpwrap line 47.
Execution of /usr/sbin/smtpwrap aborted due to compilation errors.
Connection closed by foreign host.
[root@mail root]#

0
 
LVL 2

Author Comment

by:wqclatre
ID: 13537241
if I add a ',' between the ip's

@allowed_ip = ("192.168.1.1","127.0.0.1");

I get
Global symbol "@allowed_ip" requires explicit package name at /usr/sbin/smtpwrap line 29.

And if I change to:

my @allowed_ip = ("192.168.1.1","127.0.0.1");

IT got stuck in:



while (@allowed_ip) {
    if ($_ eq $ip) {
        $WAIT_TIME = 0;

 }
}
0
 
LVL 85

Expert Comment

by:ozo
ID: 13537243
$WAIT_TIME = 0 if gethostbyaddr($myaddr, AF_INET) =~ /\.microsoft\.com$/;
0
 
LVL 85

Accepted Solution

by:
ozo earned 1000 total points
ID: 13537252
while( @allowed_ip ){
should be
for( @allowed_ip ){
0
 
LVL 2

Author Comment

by:wqclatre
ID: 13543389
I have one question ozo:

WAIT_TIME = 0 if gethostbyaddr($ip, AF_INET) =~ /\.microsoft\.com$/;

Don't seems to work

$WAIT_TIME = 0 if gethostbyaddr(inet_aton($ip), AF_INET) =~ /\.microsoft\.com$/;


Semms to work.

What are inet_aton doing? And why don't the first row work?
0
 
LVL 85

Expert Comment

by:ozo
ID: 13550445
$ip = inet_ntoa($myaddr);
$myaddr = inet_aton($ip);
$ip is in dotted "127.0.0.1" form.  $myaddr is the equivalent 32 bit quantity
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question