Jump to content

Hoping Someone Can Take A Look At My Script :|


darnell
 Share

Recommended Posts

Hello, I am trying to put together a form that allows people to pretty much make their webpage themselves.... the coding will then be emailed to us and we can basically cut and past. My problem is I know didly squat about perl... and had someone put something together for me.

 

So, below is the script. I also have a questions 1) Do I need to upload this via ftp with certain settings (777..).

 

Any help would be appreciated. Thanks in advance.

 

#!/usr/local/bin/perl

 

# setup prefix for replacement in template...

# case sensitive

$tprefix = "VFITEMPLATE-";

 

# form variable name prefix...

# case sensitive

$fprefix = "vfi-";

 

#filepath for the template file...

$templatefile = "template.html";

 

# return URL from name (put a HIDDEN value in the submission

# form called the value of this with the return URL)

$ returl = "returl";

 

# email to send the completed HTML to

$sendto = "support@voiceforinmates.com";

 

# email address it will come from...

$sendfrom = "support@voiceforinmates.com"

 

# subject for the email

$esubject = "Completed VFI Template";

 

 

###### CODE BELOW ######

 

# get form post data...

parse_formdata( );

 

# load template into memory...

open (X, "<$templatefile");

$tdata = "";

while(<X>) {

# read every line ($_is the value of the last <X>)

$tdata .= $_;

}

close(X);

 

 

# ok... go through our form variables that start with $fprefix

# and swap out every $tprefix-varname with the value from the form

# submission...

 

foreach $fvar (@formvars) {

 

if (substr($fvar ,0, length ($fprefix)) eq "$fprefix") {

# matches our prefix...

$fname = substr($fvar, length ($prefix), lenght($fvar));

 

$value = $Form{$fvar};

# find all of them in $tdata (the copy of the template)

$tname = "$tprefix$fname";

 

(@vx) = split (/$tname/, $tdata);

$ntdata = "";

foreach $vx (@vx) {

$ntdata .= $vx;

$ntdata .= $value;

}

# we append an extra>>> wipe it out...

$tdata = substr ($ntdata,0, length ($ntdata)-length ($value));

}

 

}

 

 

# ok... send the email

open (X, "|/usr/sbin/sendmail -t");

print X "To: $sendto\n";

print X "From: $sendfrom\n";

print X "Subject: $esubject\n\n";

print X "$tdata";

print X "\n\n";

close(X);

 

# we're done!

 

# send them to $returl

print "Location: $Form{$returl}\n\n";

exit

 

# my subroutine for parsing form post in perl

sub parse_formdata {

if (uc($ENV{'REQUEST METHOD'}) eq 'POST') {

read (STDIN,$inbuf , $ENV{'CONTENT LENGTH'});

$clen = $ENV{'CONTENT LENGTH'};

} else {

#assume its GET

$inbuf = $ENV{QUERY STRING'};

$clen = length ($inbuf);

 

}

 

# split it up...

my @fsets = split(/\&/, $inbuf);

 

# clean them up...

foreach $f (@fsets) {

my ($var ,$marg) = split(/\=/,$f);

$marg =~ tr/+/ /;

$var =~ s/%(..)/ chr(hex($1)) /eg;

$marg =~ s/%(..)/ chr(hex($1)) /eg;

$Form{$var} = $marg;

push(@formvars,$var);

}

}

Link to comment
Share on other sites

THANK YOU! :) It is a step in the right direction.

 

 

For it to execute you should set the permissions to 755. As for helping debug your script, it's been a long time since I've used perl so I'd be of no help. Maybe someone else is willing.
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...