View Full Version : running Perl from webbrowser locally
golfcents
03-20-2006, 06:31 PM
Hello I am new here and new to PERL...:eek:
I am trying to run perl programs from my PC(Not a server).
using Windows XP and Activestate's Perl
I have been using the command prompt to succesfully run them thus far...
example
C:\Perl> perl myprog.pl
I now want to test input from a html form to a cgi file and find that when a browser comes across the cgi or pl extensions it opens the file like an editor or prompts for downloading the file , rather than actually running it...
Is there a simple trick for running .cgi or .pl files from your local compter, from a web browser???
thank you in advance
gc
andi182
03-20-2006, 06:47 PM
personally i use a programme called abyss webserver
it's free and really easy to use
its available on download.com or just search google for it =]
once installed just set it up to run cgi scripts
hope this helps
=]
andi
golfcents
03-20-2006, 09:00 PM
Hi and thank you for your response. :thumbsup:
So is there a simpler way to do this , other than loading Server software ?
I guess that is the next question.
FishMonger
03-20-2006, 10:28 PM
If you're asking if it can be done without a web server, the answer is NO.
nkrgupta
03-21-2006, 05:55 AM
.......
Is there a simple trick for running .cgi or .pl files from your local compter, from a web browser???
thank you in advance
gc
The simplest trick that comes to my mind is to put a small web server like Small HTTP ( http://smallsrv.com/ ) - about 100 kb, or many others and test out all your cgi apps.
Naveen
golfcents
03-23-2006, 12:40 AM
So it cant be done locally. Thats OK. :rolleyes:
I can always copy files over to a nearby server and test them there.
It just would have been more convenient locally...
thanks everyone...
My next question
On our win2003 server (with activeperl) the sendmail feature isnt there, Ive tried a few things like mail::sendmail module and sent a simple email out . (sendmail.pm)
Can anyone demostrate a very simple perl program to accept a user's html form input with the results of the form emailed to a set email address, using the sendmail.pm or Mail::Send mail ?
by simple
from email & subject fields
radio button
text box.
I just want the form submission with the data to go to an email.
The old unix sendmail worked for this, but the windows server is finicky.
my perl path #!D:/perl/bin/perl.exe
please keep it simple as I am a rookie at this stuff :thumbsup:
thanks to all of you
here is the cgi for the form that I want to run on win2003 server
#!D:/perl/bin/perl.exe
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# The following sends the email
open (MESSAGE,"| ###need this part too###"); #I know this is wrong
print MESSAGE "To: $FORM{submitaddress}\n";
print MESSAGE "From: $FORM{email}\n";
print MESSAGE "Reply-To: $FORM{email}\n";
print MESSAGE "Subject: Equipment Pool Request from: $ENV{'REMOTE_USER'}at $ENV{'REMOTE_HOST'}\n\n";
print MESSAGE "____________Equipment Request_______________ \n";
print MESSAGE " \n";
print MESSAGE "__________Customer Information________________________ \n";
print MESSAGE "Customer Name :"; print MESSAGE "$FORM{name}\n";
print MESSAGE "Customer Email :"; print MESSAGE "$FORM{email}\n";
print MESSAGE "Customer Dept :"; print MESSAGE "$FORM{dept}\n";
print MESSAGE "Customer Bldg-Fl :"; print MESSAGE "$FORM{bldg}\n";
print MESSAGE "Customer Phone :"; print MESSAGE "$FORM{phone}\n";
print MESSAGE " \n";
print MESSAGE "__________Equipment Information______________________ \n";
print MESSAGE "Serial Number :"; print MESSAGE "$FORM{serial}\n";
print MESSAGE "Manufacturer :"; print MESSAGE "$FORM{mfg}\n";
print MESSAGE "Model :"; print MESSAGE "$FORM{model}\n";
print MESSAGE "Description :"; print MESSAGE "$FORM{description}\n";
print MESSAGE "Bin Loc :"; print MESSAGE "$FORM{bin}\n";
print MESSAGE "IBM Site :"; print MESSAGE "$FORM{site}\n";
print MESSAGE "Work Requirement :"; print MESSAGE "$FORM{required}\n";
print MESSAGE "Comments :"; print MESSAGE "$FORM{comments}\n";
print MESSAGE "_____________________________________________________ \n";
}
This works on the unix server with the proper paths (left out in this example)
I want to use a similar format with win2003 server using sendmail.pm or Mail::Sendmail or whatever
else you think will work....
thanks again
FishMonger
03-23-2006, 02:16 AM
So it cant be done locally.No, that's not what we said. It can be done locally...you just need to install a web server such as apache, IIS, abyss, or any one of a number of other web servers.
I haven't used Mail::Sendmail; I normally use MIME::Lite or Net::SMTP but I'll work up an example and post it a little later. The method that you're using to read/parse the form submission should be dropped. That approach has been depreciated for 10+ years. Use this instead.
#!D:/perl/bin/perl.exe
use strict;
use CGI ':cgi-lib';
my %form = Vars;
golfcents
03-23-2006, 02:30 AM
Thank you Fishmonger,
ps on the last post
I meant to say" So it cant be done locally, without loading server software? " Sorry for the confusion....:D
pps I will gladly use your form cgi code. I will await your post....
ppps Now as to the outdated read/parse version example I sent, its does work fine on the unix-server as is, but are you saying because its 10 years old, it will miss data or do something improper or what?
What would be the actual reason for not using it, besides old age?
I'm just trying to learn.
thank you again in advance
FishMonger
03-23-2006, 04:55 AM
It's more than just the fact that it's 10yr old. Just because it works, doesn't mean that you should use it. You need to consider the improvements in implementation over the last 10 years. The methods applied in the CGI module have lots of checks and error handling that the older method doesn't have. That 1 line of code that I showed (my %form = Vars;) will read/parse both POST and GET requests. It's also a lot cleaner, and easier to read and maintain.
Another major issue with your approach is that you're allowing the user to supply the recipient and sender address. That opens a big security hole and allows spammers to hijack your form to use it as a spam relay.
Here's the simple example that you asked, but doesn't include the level of error handling that I'd use in a production script. It also doesn't give any output to the user...you'd probably want to rediect them to another page after the email gets sent.
#!D:/perl/bin/perl.exe
use strict;
use CGI ':cgi-lib';
use CGI::Carp qw(fatalsToBrowser);
use Mail::Sendmail;
my %form = Vars;
my $msg = <<MSG;
____________Equipment Request_______________
__________Customer Information________________________
Customer Name :$form{'name'}
Customer Email :$form{'email'}
Customer Dept :$form{'dept'}
Customer Bldg-Fl :$form{'bldg'}
Customer Phone :$form{'phone'}
__________Equipment Information______________________
Serial Number :$form{'serial'}
Manufacturer :$form{'mfg'}
Model :$form{'model'}
Description :$form{'description'}
Bin Loc :$form{'bin'}
IBM Site :$form{'site'}
Work Requirement :$form{'required'}
Comments :$form{'comments'}
_____________________________________________________
MSG
my %mail = (smtp => 'your.smtp.server.com',
To => 'me@mydomain.com',
From => 'me@mydomain.com',
Subject => "Equipment Pool Request from: $ENV{'REMOTE_USER'}at $ENV{'REMOTE_HOST'}",
Message => $msg
);
sendmail(%mail) or die $Mail::Sendmail::error;
golfcents
03-24-2006, 12:44 AM
Thanks
I will try this out tonight....
I see your points about keeping up with technology..
and I didnt show the subroutine "thankyou"
That thanks & acknowledges form submission then redirects them to a home page in 5 seconds....
I'll bet you would propbably tell me that sub is outdated .:eek:
thanks again
golfcents
03-24-2006, 01:38 AM
Hello Fishmonger,
saved your code into a file form.cgi to test om my system.....
My attempt gives me the error (below) .maybe you have seen this one???:thumbsup:
Software error:
Can't locate Mail/Sendmail.pm in @INC (@INC contains: C:/perl/lib C:/perl/site/lib .) at d:\Internet\Webpage\p\form.cgi line 6.
BEGIN failed--compilation aborted at d:\Internet\Webpage\p\form.cgi line 6.
A file search found sendmail here
D:\perl\site\lib\mail\sendmail.pm
and here
D:\perl\site\lib\sendmail.pm
Is there something that I need to edit path-wise?
FishMonger
03-24-2006, 01:58 AM
That message is telling you that it can't find or you don't have the Mail::Sendmail module installed on your system. On my system, I have 3 different versions of sendmail.pm from 3 different authors.
Case is important, Perl will see these as 2 distinct separate modules that could and probably does use different syntax.
D:\perl\site\lib\mail\sendmail.pm
D:\perl\site\lib\Mail\Sendmail.pm # this is the one you need.
You could change the syntax to match the module version that you have installed, or you can use ppm to install the other module.
ppm install Mail::Sendmail
If you want to use one of the ones already installed, you'd need to change the use statement to either of these:
use sendmail;
use mail::sendmail;
You'd also need to change the other portion of the script to use the required syntax of the module you choose to use.
golfcents
03-25-2006, 03:12 AM
Hi again,
I think this beast wants to find Sendmail only from the C: disk, I have to get the Server admin to access the C drive...
We loaded activeperl there then copied it to the D: partition where the webpages run and I am allowed to use....could this be the problem???
ps I ran perl -V the Sendmail.pm module mentioned to run it to see results.
(Please note P:\ is my virtual drive it represents D:\perl )
P:\>perl -V
Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
Platform:
osname=MSWin32, osvers=5.0, archname=MSWin32-x86-multi-thread
uname=''
config_args='undef'
hint=recommended, useposix=true, d_sigaction=undef
usethreads=define use5005threads=undef useithreads=define usemultiplicity=de
fine
useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
use64bitint=undef use64bitall=undef uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cl', ccflags ='-nologo -GF -W3 -MD -Zi -DNDEBUG -O1 -DWIN32 -D_CONSOLE -
DNO_STRICT -DHAVE_DES_FCRYPT -DNO_HASH_SEED -DUSE_SITECUSTOMIZE -DPERL_IMPLICIT_
CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -DPERL_MSVCRT_READFIX',
optimize='-MD -Zi -DNDEBUG -O1',
cppflags='-DWIN32'
ccversion='12.00.8804', gccversion='', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64', lseeksi
ze=8
alignbytes=8, prototype=define
Linker and Libraries:
ld='link', ldflags ='-nologo -nodefaultlib -debug -opt:ref,icf -libpath:"c:
\Perl\lib\CORE" -machine:x86'
libpth=\lib
libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32
.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib ws2_
32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib comd
lg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib netapi32.lib uuid.lib
ws2_32.lib mpr.lib winmm.lib version.lib odbc32.lib odbccp32.lib msvcrt.lib
libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -debug -opt:ref,icf -
libpath:"c:\Perl\lib\CORE" -machine:x86'
Characteristics of this binary (from libperl):
Compile-time options: MULTIPLICITY PERL_IMPLICIT_CONTEXT
PERL_IMPLICIT_SYS PERL_MALLOC_WRAP
PL_OP_SLAB_ALLOC USE_ITHREADS USE_LARGE_FILES
USE_PERLIO USE_SITECUSTOMIZE
Locally applied patches:
ActivePerl Build 816 [255195]
Iin_load_module moved for compatibility with build 806
PerlEx support in CGI::Carp
Less verbose ExtUtils::Install and Pod::Find
Patch for CAN-2005-0448 from Debian with modifications
27359 Fix -d:Foo=bar syntax
27210 Fix quote typo in c2ph
27203 Allow compiling swigged C++ code
27200 Make stat() on Windows handle trailing slashes correctly
27194 Get perl_fini() running on HP-UX again
27133 Initialise lastparen in the regexp structure
27034 Avoid "Prototype mismatch" warnings with autouse
26970 Make Passive mode the default for Net::FTP
26921 Avoid getprotobyname/number calls in IO::Socket::INET
26897,26903 Make common IPPROTO_* constants always available
26670 Make '-s' on the shebang line parse -foo=bar switches
26379 Fix alarm() for Windows 2003
26087 Storable 0.1 compatibility
25861 IO::File performace issue
25084 long groups entry could cause memory exhaustion
24699 ICMP_UNREACHABLE handling in Net::Ping
Built under MSWin32
Compiled at Mar 1 2006 18:00:52
@INC:
c:/Perl/lib
c:/Perl/site/lib
.
P:\>
FishMonger
03-25-2006, 03:25 AM
Yep, that's going to be a problem. If you need to run Perl from the D: drive, then that's where you should install it. Simply coping the perl directories isn't enough. You could add a use lib statement to every script, but that would be a very poor approach.
golfcents
03-27-2006, 11:26 PM
2morrow ,
I will have the server guy load Sendmail.pm in both places
c:/Perl/lib
c:/Perl/site/lib
then test it tomorrow....
I will let yo uknow how it goes....
thanks for all your help FM
GC
FishMonger
03-27-2006, 11:48 PM
You don't need to have it in both locations. If you use ppm to install the module, it will be put in its proper location, which is c:\perl\site\lib.
golfcents
03-28-2006, 08:50 PM
Ok ...Sendmail was installed on C: in the appropriate directory
The form output sends the email out OK, but when submitted the submitter gets the error below
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.
I'm searching the internet for possible reasons for this, but if you happen to know that would be great.
thank you
golfcents
03-29-2006, 03:48 AM
Hello again,
I have installed the Mail::Sendmail module successfully in C:
Sendmail.pm has my smtp server address inside, and from email address....
The form nows sends out the email successfully:thumbsup: ,
I havent redirected the form to display a confirmation page yet.
:eek: Only 1 problem after the form is submitted this occurs
CGI error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.
I have also tried to reference the splat line to look for perl in C: as a test,
no luck still get the HTTP header error....
any ideas are welcome
we are so close FM thank you
ps I found this post on the web , do you agree with the way it solved this person's error?
I'm home so I cant try it until 2morrow.
=============================================================
Re: CGI application misbehaved by not returned complete set of HTTP headers
I had this problem and solved by adding the following around my code:
#!perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
print header;
print start_html("Environment");
(Code here)
print end_html;
FishMonger
03-29-2006, 05:19 AM
The error message you're receiving usually means that your script tried to send output to the browser without sending the html headers.
The solution you found would be my first suggestion, but it needs one additional line.
#!perl -w
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
print header();
warningsToBrowser(1);
print start_html("Environment");
(Code here)
print end_html;
If you post the current version of your script, we might be able to make other recommendations.
golfcents
04-06-2006, 06:52 PM
:thumbsup: All is working fine but I wanted to add a graphic above the email info
I tried html <img src code> NG
any ideas????
#!C:/perl/bin/perl.exe
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
use CGI ':cgi-lib';
use Mail::Sendmail;
print header();
warningsToBrowser(1);
print start_html("Environment");
my %form = Vars;
my $msg = <<MSG;
Can a graphic banner be placed here so its above the email that is sent
____________LCD Work/Information Request______________
__________Customer Information________________________
Customer Name: $form{'name'}
Customer Email: $form{'email'}
Customer Dept: $form{'dept'}
Customer Bldg-Fl:$form{'bldg'}
Customer Phone: $form{'phone'}
__________Equipment Information______________________
Serial Number: $form{'serial'}
Manufacturer: $form{'mfg'}
Model: $form{'model'}
Description: $form{'description'}
Conference Room: $form{'cr'}
Comments: $form{'comments'}
_____________________________________________________
MSG
my %mail = (smtp => 'us.xyz.com',
To => 'mynamel@xyz.com ',
From => $form{'email'},
Subject => "LCD Work-Information Request from: $ENV{'REMOTE_USER'}at $ENV{'REMOTE_HOST'}",
Message => $msg
);
sendmail(%mail) or die $Mail::Sendmail::error;
&thank_you;
sub thank_you {
prints an HTML thank you page then redirects to a home page....
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.