Thread: IP banning

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NY
    Posts
    51
    Rep Power
    15

    IP banning


    I am trying to ban ip's that are automatically recorded into a file ipban.txt

    ipban.txt looks like

    11.12.3.12
    124.121.1.1
    1.1.1.1
    2.2.3.1


    just a bunch of ip's....


    here is my code in mailing script the converts the text file into an array


    $file = "ipban.txt";
    open(INFO, $file);
    @lines = <INFO>;
    close(INFO);
    print @lines;
    if $ip_bans (@lines) eq $ip
    {
    print "sorry, only send once....";
    }
    else {
    here is the code to send mail
    }


    Is there anything wrong with the code?

    Also, is the right code $ip_bans (@lines) to read all in the array?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NY
    Posts
    51
    Rep Power
    15
    $ip = $ENV{'REMOTE_ADDR'};

    open (IPBAN, "ipban.txt");
    my $file = join("",<IPBAN> );

    my @levels = (0);
    my @data = split(/<(\/*level) *([0-9]*)>/i, $file);


    if $ip == $file {
    print "Mail cannot be sent due to use of profane language.";
    }

    else $ip ne $file {

    The code to send mail

    }



    I tryed to recode the my first post.... failed again

    Any comments or help would be appreciated

    Thanks!
    Last edited by daza1; April 5th, 2003 at 03:56 PM.
  4. #3
  5. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Boston MA
    Posts
    100
    Rep Power
    0
    Code:
    $ip = $ENV{'REMOTE_ADDR'};
    
    $file = "ipban.txt";
            open(INFO, $file);
                    @lines = <INFO>;
            close(INFO);
    
    print "@lines\n";
    
    foreach $ip_bans(@lines) {
    
            chomp $ip_bans;
    
            if ($ip_bans eq $ip)  {
                    print "sorry, only send once....\n";
                    }
            else {
                    The code to send email
                    }
    
    }  # End foreach loop
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NY
    Posts
    51
    Rep Power
    15
    I tryed to place
    }

    } # End foreach loop

    under all script I wanted to execute....

    I get an internal server error...
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NY
    Posts
    51
    Rep Power
    15

    here


    got it thanx
    Last edited by daza1; April 5th, 2003 at 04:46 PM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NY
    Posts
    51
    Rep Power
    15
    problems....

    ok i have no idea where to put

    }

    } # End foreach loop


    I thought it should execute my mail so i put it under
    ###################
    print mail(....)
    ...
    mail stuff

    }

    } # End foreach loop
    ####################

    But now it doesn't send the mail...

    I then put it under the confirmation page


    print mail(....)
    ...
    mail stuff

    print "content type blah....."
    print" your mail has been sent

    }

    } # End foreach loop
    #######################

    I get another internal server error?

    where do you suggest i place it?
    ############################3
    #!/usr/bin/perl




    $file = "ipban.txt";
    open(INFO, $file) || die("Unable to open file!\n");
    @lines = <INFO>;
    close(INFO);

    print "@lines\n";

    foreach $ip_bans(@lines) {

    chomp $ip_bans;

    if ($ip_bans eq $ip) {
    print "sorry, only send once....\n";
    }
    else {



    open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n";
    print MAIL "To: $FORM{'email'}\n";
    print MAIL "From: $FORM{'from'}\n";
    print MAIL "Subject: $FORM{'subject'}\n\n";
    print MAIL "$FORM{'message'}\n";
    #print MAIL "---------\n";
    #print MAIL "Sent by IP: $ip\n";
    close (MAIL);

    ###SHOULD I PUT I HERE (a)

    if ($logmail == 1) {
    open(IPKILL, ">>ipban.txt") ||
    flock(IPKILL, 2);
    print IPKILL "$ip\n";
    flock(IPKILL, 8);
    close(IPKILL);

    }

    ###SHOULD I PUT I HERE (N)
    print "content type blah.....";
    print" your mail has been sent";

    ###SHOULD I PUT I HERE (C)
    sub incomplete {
    print "Content-type: text/html\n\n";
    print "<html><head><title>ERROR: Incomplete E-mail!</title></head>\n";
    print "<body bgcolor=#FFFFFF text=#000000><p>\n";
    print "<center>You haven't completely filled out your e-mail.<br>\n";
    print "Go back and try it again please.<p>\n";
    print "</body></html>\n";

    exit;
    }


    ###SHOULD I PUT I HERE (D)
    &get_date;

    if ($logmail == 1) {
    open(LOG, ">>email_log.txt") ||
    flock(LOG, 2);
    print LOG "---------------------------------- \n";
    print LOG "Date: $date \n";
    print LOG "IP: $ip \n";
    print LOG "Referrer: $ref \n";
    print LOG "Browser: $browser \n";
    print LOG "User: $user \n";
    print LOG "To: $FORM{'email'}\n";
    print LOG "From: $FORM{'from'}\n";
    print LOG "Subject: $FORM{'subject'}\n";
    print LOG "Message: $FORM{'message'}\n";
    flock(LOG, 8);
    close(LOG);

    }
    ###SHOULD I PUT I HERE (F)

    sub incomplete2 {
    print "Content-type: text/html\n\n";
    print "<html><head><title>ERROR: Incomplete E-mail!</title></head>\n";
    print "<body bgcolor=#FFFFFF text=#000000><p>\n";
    print "<center>You Must agree to our terms of service...<br>\n";
    print "Go back and try it again please.<p>\n";
    print "</body></html>\n";

    exit;
    }
    ###SHOULD I PUT I HERE (G)
    sub error {
    local($error) = @_;

    print "Content-type: text/html\n\n";
    print "<html><head><title>ERROR:</title></head>\n";
    print "<body bgcolor=#FFFFFF text=#000000><center><h1>Error</h1></center>\n";
    print "<center>$error</center>\n";
    print "<center><a href=\"http://negativepulse.net\">Anonymous E-mailer V1.0</center></a>";
    print "</body></html>\n";

    exit;
    }
    ###SHOULD I PUT I HERE (H)
    sub get_date {

    # Define arrays for the day of the week and month of the year. #
    @days = ('Sunday','Monday','Tuesday','Wednesday',
    'Thursday','Friday','Saturday');
    @months = ('January','February','March','April','May','June','July',
    'August','September','October','November','December');

    # Get the current time and format the hour, minutes and seconds. Add #
    # 1900 to the year to get the full 4 digit year. #
    ($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
    $time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
    $year += 1900;

    # Format the date. #
    $date = "$days[$wday], $months[$mon] $mday, $year at $time";
    }

    ###SHOULD I PUT I HERE (I)

    ###################
    Please note... everything worked before i added the ip ban, so all variables are set... I even had it work once, then error, error, error, error and the mails would not get sent either
    Last edited by daza1; April 5th, 2003 at 05:48 PM.
  12. #7
  13. No Profile Picture
    Senior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2002
    Location
    Boston MA
    Posts
    100
    Rep Power
    0
    Put it after "your mail has been sent"; (C)
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2003
    Location
    NY
    Posts
    51
    Rep Power
    15
    I have just sent you the link to the script source...

    It would be awesome if you could look over it.

    Thanks a lot for all your support so far.

    My e-mail is daza1/at/paintingmart/dot/com (don't want bots getting my e-mail address)

    Thank you!

IMN logo majestic logo threadwatch logo seochat tools logo