KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.62
System : FreeBSD fbsdweb2.web.rcn.net 14.1-RELEASE FreeBSD 14.1-RELEASE releng/14.1-n267679-10e31f0946d8 GENERIC amd64
User : www ( 80)
PHP Version : 8.3.8
Disable Function : NONE
Directory :  /domains/highlandlabs/cqi-bin/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /domains/highlandlabs/cqi-bin/HL_mailform.cgi
#!/usr/bin/perl

$lockfile="/tmp/bnbform.lck";

$mail_program="/usr/sbin/sendmail -t";
#
   &decode_vars;
   &valid_page;
   if ($fields{'countfile'} ne "")
      { &get_number; }
   &valid_data;
   &rev_dns;
   &write_data;
   if ($fields{'autorespond'} eq "yes")
    { &answer_back; }

   if ($fields{'ok_url'} ne "")
    { print "Location: $fields{'ok_url'}\n\n"; exit;}
     else { &thank_you; }

##################################################################
sub write_data
{
   if ($fields{'submit_by'} ne "")
     {
       if (&valid_address == 0)   
        {
          &bad_email;
          exit;
        }
     }
   
   if ($fields{'submit_by'} ne "" && $fields{'emailfile'} ne "")
    {
      open (EMF,">>$fields{'emailfile'}");
      print EMF "$fields{'submit_by'}\n";
      close (EMF);
    }
   $the_date=localtime();
   if ($fields{'submit_to'} ne "")
    {
     &open_mail;
     print MAIL "To: $fields{'submit_to'}\n";
     print MAIL "From: $fields{'submit_by'}\n";
     print MAIL "Subject: $fields{'form_id'}\n";
    if (($fields{'cc_to'}) ne "" && ($fields{'submit_to'} ne ""))
     {
     print MAIL "Cc: $fields{'cc_to'}\n";
     }
     print MAIL "$the_date\n\n";
     print MAIL "Browser Type: $ENV{'HTTP_USER_AGENT'}\n";
     print MAIL "Mailhost: $ENV{'REMOTE_HOST'}\n";
     print MAIL "Address: $ENV{'REMOTE_ADDR'}\n\n";
    }
   if ($fields{'outputfile'} ne "")
    { 
      &get_the_lock; 
      open(OUT_FILE,">>$fields{'outputfile'}"); 
    }
   foreach $to_print (@sortlist)
    {
      if ($fields{'outputfile'} ne "")
       { print OUT_FILE "$fields{$to_print}\|"; }
      if ($fields{'submit_to'} ne "")
       { print MAIL "$to_print = $fields{$to_print}\n"; }
    }
   if ($fields{'outputfile'} ne "")
    {
     print OUT_FILE "$the_date\|\n";
     close(OUT_FILE);
     &drop_the_lock;
    }
   if ($fields{'submit_to'} ne "")
    {
       &close_mail;                           
    }                                         
}

##################################################################
sub decode_vars
 {
  $i=0;
  read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});
  @pairs=split(/&/,$temp);
  foreach $item(@pairs)
   {
    ($key,$content)=split(/=/,$item,2);
    $content=~tr/+/ /;
    $content=~s/%(..)/pack("c",hex($1))/ge;
    $content=~s/\t/ /g;
    $fields{$key}=$content;
    if ($key eq "data_order")
      {
       $content=~s/ //g;
       @sortlist=split(/,/,$content);
      }
    if ($key eq "required")
      {
       $content=~s/ //g;
       @mandatory=split(/,/,$content);
      }
   }
}

##################################################################
sub valid_data
  {
   if ($fields{'data_order'} eq "")    
    {
      print "Content-type: text/html\n\n"; 
      print <<__W1__;

      <H1>NO data_order list SPECIFIED!</H1>

__W1__
      exit;
    }

   foreach $to_check (@mandatory) #test all required fields, bail on 1st bad
    {                             
      if ($fields{$to_check} eq "")
        {
          if ($fields{'not_ok_url'} ne "")
            { 
              print "Location: $fields{'not_ok_url'}\n\n";
              exit;
            }
             else
              {
                &try_again;
              }
         }
    }

  }

##################################################################
sub thank_you
  {
      print "Content-type: text/html\n\n"; 
      print <<__W2__;

      <H1>Thank you!</H1>
      Your information has been sent and I will be in touch
      with you soon.

__W2__
      exit;
  }

##################################################################
sub try_again
  {
      print "Content-type: text/html\n\n"; 
      print <<__W3__;

      <H1>Missing Data!</H1>
      <B>Please press the back button and fill in
      all required fields!<P></B>

__W3__
      exit;
  }

##################################################################
sub open_mail
 {
       open (MAIL, "|$mail_program")
 }

##################################################################
sub close_mail
 {
  close(MAIL);
 }

##################################################################
sub answer_back
 {
  &open_mail;
  print MAIL "To: $fields{'submit_by'}\n";
  print MAIL "From: $fields{'submit_to'}\n";
  print MAIL "Subject: Thank you\n";
  if ($fields{'automessage'} ne "")
   {
    open (AM,"< $fields{'automessage'}");
    while (<AM>)
     {
      chop $_;
      print MAIL "$_\n";
     } 
    close(AM);
   }
    else
    {
      print <<__W4__;

Thank you for your submission. I will be
getting in touch with you soon.

__W4__
    }
  &close_mail;
 }

##################################################################

sub get_number
 {
   $newnum=0;
   open(COUNTER,"<$fields{'countfile'}");
   while(<COUNTER>)
     {
      $newnum = $_ + 1;
     }
   close(COUNTER);
   open(COUNTER,">$fields{'countfile'}");
   print COUNTER "$newnum";
   close (COUNTER);
   $fields{'counter'}=$newnum
 }

##################################################################
sub valid_address 
 {
  $testmail = $fields{'submit_by'};
  if ($testmail =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/ ||
  $testmail !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
   {
     return 0;
   }
   else 
    {
      return 1;
    }
}

sub bad_email
{
print <<__STOP_OF_BADMAIL__;
Content-type: text/html

<FONT SIZE="+1">
<B>
SORRY! Your request could not be processed because of an
improperly formatted e-mail address. Please use your browser's 
back button to return to the form entry page.
</B>
</FONT>
__STOP_OF_BADMAIL__
}

sub rev_dns
{
if (($ENV{'REMOTE_HOST'} eq $ENV{'REMOTE_ADDR'}) 
     && ($ENV{'REMOTE_ADDR'} =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/))
        {                                                                       
        $Address = pack('C4', $1, $2, $3, $4);                                  
        $DNS_Address = (gethostbyaddr($Address, 2))[0];                         
        $ENV{'REMOTE_HOST'} = $DNS_Address if $DNS_Address;                     
        }                                                                       
}

sub get_the_lock
{
  local ($endtime);                                   
  $endtime = 60;                                      
  $endtime = time + $endtime;                         
  while (-e $lockfile && time < $endtime) 
   {
    # Do Nothing                                    
   }                                                   
   open(LOCK_FILE, ">$lockfile");                     
}

sub drop_the_lock
{
  close($lockfile);
  unlink($lockfile);
}


##################################################################
sub valid_page
 {
  if (@okaydomains == 0)
     {return;}
  $DOMAIN_OK=0;                                         
  $RF=$ENV{'HTTP_REFERER'};                             
  $RF=~tr/A-Z/a-z/;                                     
  foreach $ts (@okaydomains)                            
   {                                                    
     if ($RF =~ /$ts/)                                  
      {                                                 
        $DOMAIN_OK=1;                                   
      }                                                 
   }                                                    
   if ( $DOMAIN_OK == 0)                                
     {                                                  
      print "Content-type: text/html\n\n Sorry....Cant run from here!";    
      exit;                                             
     }                                                  
 }


Anon7 - 2021