#!/perl/bin/perl print "Content-type:text/html\n\n"; use CGI qw(:standard); use strict; use warnings; use XML::Simple; use XML::XSLT; use Data::Dumper; use Data::FormValidator; use Data::FormValidator::Constraints qw(email); use Net::SMTP; my $tech = { 'Linux' => 'linux@domain.com', 'Unix' => 'unix@domain.com', 'Windows XP' => 'windows@domain.com', }; # ----------------- Sub routines ----------------- sub showfun1 { my $xml->{items} = { item => [ sort keys %{$tech} ] }; $xml->{rootname} = 'data'; $xml->{nextpage} = 'frmform'; return $xml; } sub write_xml { my ($ref, $fn) = @_; my $root_name = $ref->{rootname}; my $xmld = new XML::Simple( rootname => $root_name, noattr => 1 ); my $data = $xmld->XMLout( $ref ); open(OUT , ">$fn") or die $!; print OUT "$data"; close (OUT); } sub showfun2 { my ($name) = @_; my $xml = showfun1(); $xml->{name} = param("$name"); $xml->{mail} = $tech->{$xml->{name}}; $xml->{nextpage} = 'frmconfirm'; return $xml; } sub showfun3 { my $xml = showfun2("tt"); # Input my $input; $input->{"$_"} = param("$_") foreach ( param() ); # Profile my $profile = { required=> [qw(sendermail mob username designation)], constraint_methods => { sendermail => email(), username => qr/^([A-Z|a-z]{6,15})$/, mob => qr/^([0-9]{10})$/, }, }; # Validation my ($valids, $missings, $invalids, $unknowns) = Data::FormValidator->validate($input, $profile); print "Missing :", scalar(@$missings)."
"; print "Invalid :", scalar(@$invalids)."
"; if ( (scalar(@$missings)) ) { $xml->{missing} = $missings; } if ( (scalar(@$invalids)) ) { $xml->{invalid} = $invalids; } if ( (scalar(@$missings)) ==0 && (scalar(@$invalids)) == 0){ my $server='IP'; my ($mailfrom, my $mailto ) = @_; my $subject = 'Test mail from perl program'; my $message = 'Hi this is a test mail which is generated by perl program'; my $smtp = Net::SMTP->new($server, Timeout => 15, Debug => 1); $smtp->mail ( $mailfrom ); $smtp->to ( $mailto ); $smtp->data(); # Start the mail # headers $smtp->datasend ("From: $mailfrom\n"); $smtp->datasend ("To: $mailto\n"); $smtp->datasend ("Subject: $subject\n"); $smtp->datasend ("\n"); # body. $smtp->datasend ("$message\n\n"); my $ss=$smtp->dataend(); # Send the termination string # Construct final XML if($ss != 0) { $xml->{uname} = param('username'); } if($ss == 0) { $xml->{errorcode} = '530 5.7.1 Client was not authenticated'; } $xml->{rootname} = 'confirm'; } return $xml; } # ----------------- Main Programme ----------------- # Var Declarations my $fname = param('nextpage'); my $ret; my $xml_file = "abc.xml"; my $xsl_file = "abc.xsl"; # Validation if ( $fname eq 'frmform' ) { $ret = showfun2("selopt"); } elsif ( $fname eq 'frmconfirm' ) { $ret = showfun3(); }else { $ret = showfun1(); } # Writing into XML write_xml($ret,"$xml_file"); # Convertion from XML to HTML my $p = XML::XSLT->new ($xsl_file, "FILE"); $p->transform_document ($xml_file, "FILE"); $p->print_result();