## ------------------ Here we keep global settings package Utils::spd; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(checksize checkemail start_html end_html html_header redirect_url printmsg printerr sendmail writelog); # symbols to export on request use strict; my $mail_prog = '/usr/sbin/sendmail'; #sendmail path #----------------------------------------------------------------------------------- sub html_header{ return "Content-Type: text/html\n\n"; } #----------------------------------------------------------------------------------- sub start_html{ my ($title)=@_; my $html="\n"; $html .= "\n"; $html .= "$title\n"; $html .= "\n"; $html .= "\n"; returm $html; } #----------------------------------------------------------------------------------- sub end_html{ return ""; } #----------------------------------------------------------------------------------- sub redirect_url{ my ($title,$url,$time)=@_; my $html="\n"; $html .= "\n"; $html .= ""; $html .= "$title\n"; $html .= "\n"; $html .= "\n"; return $html; } #----------------------------------------------------------------------------------- sub printmsg{ my ($msg,$url,$time)=@_; print html_header, redirect_url("Message",$url,$time), "
", "

",$msg,"", "
", end_html; } #----------------------------------------------------------------------------------- sub printerr{ my ($msg,$url,$time)=@_; print html_header, redirect_url("Eroare",$url,$time), "
", "

Eroare
", ($msg), "
", end_html; } #----------------------------------------------------------------------------------- sub sendmail{ #Trimite email folosindu-se de pogramul sendmail ($mail_prog) my ($to,$from,$subject,$message)=@_; open (MAIL, "|$mail_prog -t"); print MAIL "To: $to\n"; print MAIL "Reply-to: $from\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n" ; print MAIL "\n\n"; print MAIL "$message\n" ; print MAIL "\n\n"; close (MAIL); } #----------------------------------------------------------------------------------- sub writelog { my ($flog,$msg)=@_; my $proxyaddr = $ENV{'REMOTE_ADDR'}; my $ipaddr = $ENV{'HTTP_X_FORWARDED_FOR'}; open (LOGFILE, ">> $flog") ; flock(LOGFILE, 2) ; #LOCK - comment for locking on a non-Unix server. seek(LOGFILE, 0, 2) ; #LOCK - comment for locking on a non-Unix server. my $datetime = localtime ; if ($ipaddr eq "") {print LOGFILE "$datetime\t$proxyaddr\t$msg\n";} else {print LOGFILE "$datetime\t$ipaddr<--$proxyaddr\t$msg\n";} flock(LOGFILE, 8) ; #UNLOCK - comment for locking on a non-Unix server. close (LOGFILE) ; } #----------------------------------------------------------------------------------- sub checksize{ # my ($var,$min,$max)=@_; return ( ($max>=$var) and ($var>=$min) ); } #----------------------------------------------------------------------------------- sub checkemail{ my ($addr)=@_; return ( ($addr =~ /.+\@.+\..+/ ) and !($addr =~ s/[^a-zA-Z0-9@._-]//g) ) } #---------------------------------------------------------------------------------- sub jredirect{ #javascript redirect my ($url)=@_; my $html.="\n"; return $html; } #----------------------------------------------------------------------------------- 1;