From nobody Sat Jul 20 19:36:36 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Make files?
References: <245D3383FB8F0C469218514273488A27892709@hh-nts01.databuilt.com>
Date: 20 Jul 2002 19:36:14 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 48

barry.jones@databuilt.com (Barry Jones) writes:

> I don't have access to the shell on my web server, but I can FTP
> stuff over to my web space.  I need to install the DBI locally and I
> was wondering if it was possible to run a make file THROUGH a CGI?

Sure.  You can put any command you want in a CGI.  I had to do this
once to view the httpd log on a machine where the ISP didn't provide
any decent way to read it.  First I uploaded this script and viewed it
through my browser:

  #!/bin/sh
  echo Content-type: text/plain
  echo
  locate httpd.conf

Once I located it, I replaced the locate line with:

  cat httpd.conf

Then I was able to look through that and find where the httpd log was,
and replace the 'cat' line with:

  tail -50 /path/to/httpd.log

So you could do the same kind of thing with your make process.  Make
sure you send the output to files, so you can download them and see
how it went.  You could send the output to your browser, but it might
be quite long, so sending it to a file is better.  I like to do:

  make >make.log 2>make.err

to keep errors separate from normal output.

One issue you might have is timeouts.  If your process takes too long,
the server might timeout and kill it.  If your 'make' takes long
enough for this to be a problem, you'll need to get around that
somehow.  Either detach the make process from your script process so
it doesn't get killed, or try creating an 'at' or cron job to do it.
Whatever works. :-)

My first recommendation, though, would be to get your admin to install
DBI, or move to a server that offers it.


-- 
Aaron

From nobody Sat Jul 20 19:52:16 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Gettin a 1 after an HTML field
References: <C7A3CC2962D2494EB1962BE45E5214FD043C6C@mail.taylorjohnson.com> <3D388505.FF03D743@san.rr.com>
Date: 20 Jul 2002 19:52:14 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 30

mfischer@san.rr.com (Maureen E Fischer) writes:

> #my ($enh_prior)        =   $q->param("enhpriority") =~ /^[1-3]+$/;

This says, "Do the following regex check on the return value of the
param() call, and assign the number of matches to $enh_prior.  Since
your regex can only match once, it equals '1'.  The Camel book says:

  "If the match succeeds, but there were no parantheses, a list value
  of (1) is returned."

That's probably not what you want here.

You could do this:

  my( $enh_prior ) = $q->param("enhpriority") =~ /^([1-3]+)$/;

But that wouldn't be very good either, since if the regex fails, it
returns a null list, and $enh_prior will never be initialized.  I'd do
something like this:

  my( $enh_prior ) = $q->param("enhpriority") || '';
  
And then do whatever checking I wanted to do on the value after
getting it into the variable.


-- 
Aaron

From nobody Sat Jul 20 23:05:28 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Zipping a file for download
References: <002801c23059$533303b0$6c67e9d5@microsoft.com>
Date: 20 Jul 2002 23:05:26 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 35

orasnita@home.ro (Octavian Rasnita) writes:

> I have made a script that let the web page visitor to choose the
> files she wants to download using checkboxes, then the script
> creates a zip archive with those files, and put it in a directory
> accessible for web page visitors.

> Are there any Perl modules that can help me for creating zip (or
> tar, or gzip) files?

Yes, Archive::Zip and Archive::Tar, available at CPAN.  Probably
others too.

> Is it possible to send the result of zip command directly for
> printing in the browser, so the download take place without a
> temporary file?

Sure.  This would be the easiest solution, as it eliminates the whole
issue of temporary files and cleaning up.  Say you gather the list of
files to zip into @files:

  my $fl = join ' ', @files;
  open ZIP, "zip - $fl |";
  print "Content-type: application/octet-stream\n\n";
  print <ZIP>;
  close ZIP;

You can do something similar with a tar|gzip| pipe, or use the modules
above.  You might want to throw a Content-length header in there too,
and of course you should add error correction.


-- 
Aaron

From nobody Wed Jul 31 13:02:52 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Multiple Selects to Perl Script
References: <006301c23895$e87ec5a0$400d19c4@saix.net>
Date: 31 Jul 2002 13:02:52 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 18

margaret@saix.net (Margaret) writes:

> I am having a most frustrating problem. I created a from with
> multiple selects using a perl script and passed the multiple
> selections to an array ie.

> @array1 = $q->param('type').

> The array only contains the first selection and none of the
> others. How do I fix this? I have read a lot of documentation and it
> is supposed to work.  What am I doing wrong?

What does your form HTML look like, especially the <select> sections?


-- 
Aaron

From nobody Thu Aug  1 07:32:38 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Checking Form data
References: <20020730202252.5043.qmail@web9101.mail.yahoo.com> <007801c238aa$b4c377a0$3310a8c0@home> <3D487ACF.6030805@danconia.org>
Date: 01 Aug 2002 07:32:36 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 17

wiggins@danconia.org (Wiggins D'Anconia) writes:

> This is correct, with the exception of date validation is still
> required in this instance as even with a set of pull downs the user
> can pick a date that *does not exist* (unless you want them to be
> able to)...such as 02/31/xxxx, this is always an invalidate but
> would pass regex check, etc.

Also, even with pull-downs, there's nothing to stop a malicious user
from manually sending incorrect dates.  If your CGI is just doing info
lookups or something like that, this may not be harmful; but if you're
storing the dates or doing calculations with them, it could be.


-- 
Aaron

From nobody Sun Aug  4 12:15:06 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Tk in Windows?
References: <002501c23bc2$ff0a3b30$0761640a@microsoft.com>
Date: 04 Aug 2002 12:15:06 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 23

orasnita@home.ro (Octavian Rasnita) writes:

> Can the Tk module be used in Windows?
> I've installed using ppm and if I put "use Tk;" it give me the
> following error in the log:

> Can't locate loadable object for module Tk::Event in @INC (@INC
> contains: C:/Perl/lib C:/Perl/site/lib .) at C:/Perl/site/lib/Tk.pm
> line 13

Looks like Tk isn't installed correctly.  You'll probably have better
luck finding out why if you ask in comp.lang.perl.tk.  Tk has nothing
to do with CGI.

> This Event module is installed and it is where it should be.  Can
> Perl create applications with graphical interfaces for Windows?

I haven't done it myself, but I believe so.


-- 
Aaron

From nobody Mon Aug  5 18:06:00 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Combination of "while" and "for" delivers wrong result from array
References: <000401c23bc3$5bafbae0$3310a8c0@home> <20020805062655.1936.qmail@onion.perl.org>
Date: 05 Aug 2002 18:05:58 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 54

krause@id.ethz.ch (Richard Krause) writes:

> I moved the close-command to the end of this script now but the
> output I'm getting is a list that shows every row of the array three
> times [snip]

> Ther must be wrong something else also.

Well, let's take the code line by line and see why.

> while (<ADDRESSLIST>) {

This reads in one line for each loop, putting it in $_.  In our case,
$_ will equal "wayne;john;huston\n" the first time through (where \n
might be some other end-of-line character(s)).

>      my @rows= split (/;/);

This splits the line on ;, putting the results into @rows, such that:

@rows = ( 'wayne', 'john', "huston\n" );

>      for my $i (0 ..$#rows)

This does a loop, assigning integers to $i from 0 to the index of the
last value in @rows.  The last value in rows would be $rows[2], so
this will assign 0, 1, and 2 to $i, looping once for each.

>          print $q->a({href=> "/cgi-bin/details.cgi?nr=$i"},
>          escapeHTML($rows[0]))."<br>\n";

This prints your link, plugging $rows[0] in there each time.  $i
changes, but $rows[0] doesn't.  So you'll get a link with nr=0, one
with nr=1, and one with nr=2, but all will have the same value for
$rows[0].

Since you just want one print statement for each line, there's no
reason to be looping through the values in each line.  Although your
data is two-dimensional, you're only interested in one dimension of
it, so two loops are one too many.  Just split out the value(s) that
you want, and use them.  Like this:

  my $i = 0;        
  while(<ADDRESSLIST>){
    my @rows = split /\;/;
    print $q->a({href=> "/cgi-bin/details.cgi?nr=$i"},
          escapeHTML($rows[0]))."<br>\n";
        $i++;
  }


-- 
Aaron

From nobody Wed Aug  7 17:27:03 2002
Newsgroups: perl.beginners.cgi
Subject: Re: CGI encryption???
References: <5.1.0.14.0.20020806155811.00b48178@mail.froggy.com.au>
Date: 07 Aug 2002 17:27:02 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 17

voigt@froggy.com.au (Richard Voigt) writes:

> I want to write a script that would enable customers to fill out a
> form with important data which would have to be sent to the server
> and then back to me through email or other mean but it would have to
> be encrypted. Any knowledge on how to encrypt my data on the server
> before sending them back to my PC???

Create a set of PGP or GPG (whichever your email program will handle)
keys for yourself.  Have your script encrypt the data with your public
key, and send it to you with one of the many perl email modules
that'll do attachments, like MIME::Lite.  


-- 
Aaron

From nobody Wed Aug  7 17:44:22 2002
Newsgroups: perl.beginners.cgi
Subject: Re: DBI connection failure in CGI context
References: <1028666767.14609.36.camel@localhost.localdomain> <Pine.SOL.4.20.0208061716030.15162-100000@csa.bu.edu>
Date: 07 Aug 2002 17:44:22 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 21

dwalu@cs.bu.edu (Dwalu Z. Khasu) writes:

> Thanx for the efforts to help me.  After your earlier email, I
> thought it couldn't hurt to try it so I did.  I created a user,
> test, with a password and verified this using 'mysql -u test -p
> miavia_dev'.  I tried selects and even inserted a dummy record.
> Then I made the changes to my cgi script and verified that as well.
> Alas, it failed the browser test AGAIN.  I sincerely appreciate your
> efforts and would appreciate any other thoughts in this matter...any
> takers?

Could you have mysql installed in two different locations?  In that
case, depending on PATH values, your CGI user and normal user could be
trying to access it differently.  The message about not being able to
access the socket /tmp/mysql.sock definitely sounds like mysql isn't
running -- at least the copy of it that your CGI is trying to access.


-- 
Aaron

From nobody Sat Aug 10 07:58:01 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Reformatting a file
References: <3D54FD20.14DAEA87@bellsouth.net>
Date: 10 Aug 2002 07:57:56 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 29

mickalo@bellsouth.net (Mikeblezien) writes:

> I'm trying to correct some shopping cart files that got messed up
> and need to be reformatted, so we can rebuild the database from
> these text order files. This is a sample of some of the data:

> Now each of these "order_items" lines, I need to grab the lines from
> the file,

> order_items::PF110::1::::::::::::89.95::0.00::89.95::::::::::
> ^^GG111::1::::::::::::49.95::0.00::49.95::::::::::

> then put it all on one line, IE:
> order_items::PF110::1::::::::::::89.95::0.00::89.95::::::::::^^GG11[snip]

Well, if the breaks always occur before two carets, as in your example,
this very simple perl script will do it:

$in = `cat filename`;
$in =~ s/\n(\^\^)/\1/sg;
print $in;

That simply strips out every newline that precedes '^^'.  If your file
is coming from a DOS system, you may need to add \r in there somehwere.


-- 
Aaron

From nobody Mon Aug 12 15:12:22 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Creating a shopping cart
References: <000e01c2421d$c6592150$3961640a@microsoft.com>
Date: 12 Aug 2002 15:12:20 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 35

orasnita@home.ro (Octavian Rasnita) writes:

> I have a question, not about Perl, but about CGI.  Can you give me
> some hints where should I go to learn how to create a shopping cart?

> I don't think I have a problem with the Perl code, but I don't know
> how to validate a credit card, how do the transactions work, etc, to
> be able to write a code for that.

First of all, you'll need to have an account with a payment processor
like CyberCash (now Verisign's PayFlow) or AuthorizeNet.  This account
works in conjunction with your bank, to do the actual CC withdrawals
and deposit them in your account.

Then you just have your script post the transactions.  AuthorizeNet is
the easiest that I have used; with it you just put your transaction
info in a hash and post it to their server with the LWP module.
Cybercash is a bit more complicated, as they provide a separate
set of perl modules for you to use, but it's not terribly difficult
either.

The most complicated part isn't actually making the transactions; it's
keeping track of them and handling credits and voids and other issues
that come up.

> Are there any books or online tutorials, free shopping carts, etc?

There are free shopping carts, which you can find easily with a web
search.  Commerce.cgi comes to mind, although I wouldn't recommend it
as a sample of easy-to-follow code for learning purposes.


-- 
Aaron

From nobody Wed Aug 21 06:23:57 2002
Newsgroups: perl.beginners.cgi
Subject: Re: bad interpreter
References: <20020821085109.GA22598@genestate.com>
Date: 21 Aug 2002 06:23:49 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 18

mat.harris@genestate.com (Mat Harris) writes:

> why, when i try to run one of my cgi scripts do i get a "bad
> interpreter, file not found" error? my shebang line is correct and
> works for every other perl script i run on that server. btw the
> script in question is the ikonboard forum solution from
> www.ikonboard.com. does anyone know of any bugs with it or another
> reason why i get this apparently incorrect error.

Could either be the shebang line or non-execute permissions on the
CGI.  Make sure the shebang line doesn't have any trailing ^M's, which
sometimes will happen with downloaded packages that were developed on
Windows.


-- 
Aaron

From nobody Fri Aug 30 13:39:12 2002
Newsgroups: perl.beginners.cgi
Subject: Re: database connection problem
References: <DAV21c0D543TuylJc0x00003e54@hotmail.com>
Date: 30 Aug 2002 13:39:12 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 22

amancgiperl@hotmail.com (Aman Cgiperl) writes:

>     12  my $dth = DBI->connect("DBI:mysql:db_name","user","pass");
>     26  my $sth_check = dth->prepare("SELECT * FROM mytab WHERE s='$s'");

> ---------------------------------------
> I am getting the following output. What could be wrong ???
> --------------------------------------

> Can't locate object method "prepare" via package "dth" (perhaps you
> forgot to load "dth"?) at /home/somesite/cgi-bin/script line 26.

Should be:
  $dth->prepare(...

By leaving the $ off your reference, perl thinks "dth" is a package
name, instead of the DBI connection object you just created.


-- 
Aaron

From nobody Mon Sep  2 07:39:25 2002
Newsgroups: perl.beginners.cgi
Subject: Re: How to make a hyperlink an argument for a CGI script
References: <E9B3905226DDD411BC0F0090276D21C20A669736@fmsmsx30.fm.intel.com>
Date: 02 Sep 2002 07:39:24 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 26

david.nazary@intel.com (David Nazary) writes:

> In the following web page how can I make "foo" to become an argument
> to "cgi-bin\script.pl" script when I click on "foo"?

Like this:

  href="/cgi-bin/script.pl?arg=foo"

or this:

  href="/cgi-bin/script.pl?foo"

or this:

  href="/cgi-bin/script.pl/foo"

Each of those will pass 'foo' along to your script, but in different
ways.  If you're using perl, see 'perldoc CGI' to find out how to get
at the arguments.  CGI scripts get their arguments through
environment variables, not from @ARGV.


-- 
Aaron

From nobody Mon Sep  2 16:35:50 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Analyzing a form
References: <014501c25221$cd06f9a0$3761640a@microsoft.com> <JGEPKJHDAHAGGDLNIEDEGEHMCPAB.soheil@jhanna.com>
Date: 02 Sep 2002 16:35:48 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 29

soheil@jhanna.com (Soheil Shaghaghi) writes:

> I have a form with 7 fields, each having it's own dropdown menu.

> The user passes in the following conditions:
> There are 2 simple requirements:
> One of the fields (options1, option2, option3,option4A) are equal to 1
> and (option5=Yes or option6>2)

Lets assume you've already copied your CGI parameter values into a
hash called %f, with the same hash keys as your form names.  Then do:

  if( ( $f{option1} == 1 or     # any one of these can be true
        $f{option2} == 1 or
        $f{option3} == 1 or
        $f{option4A} == 1 ) 
      and
      ( $f{option5} eq 'Yes' or   # and one of these
        $f{option6} > 2 )
    ){
        # Do your Passed stuff
  } else {
        # Do your failure stuff
  }


-- 
Aaron

From nobody Mon Sep  2 16:41:29 2002
Newsgroups: perl.beginners.cgi
Subject: Re: How to protect Perl code
References: <NBBBKHPKLKEJAGCDBKIPAEAADMAA.alex@fam-agerholm.dk>
Date: 02 Sep 2002 16:41:28 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 23

alex@fam-agerholm.dk (Alex Agerholm) writes:

> Can anyone give me a good way to protect my Perl code.

> I am writing a CGI application in Perl that I am going to sell -
> therefore I would like to protect my code in such a way that it is
> not that easy to copy the code and reuse/resell/distribute it.

> Does anyone have a good sugestion howto do this ?

It can't be done.  You can obfuscate your code, but you can't prevent
someone from reading it.  Perl is a scripting language.  At some
point, your script has to be read by the perl interpreter, and if a
user's perl can read it, so can he if he really wants to.

There are compilers which turn a perl script into some sort of binary
code, which would make it somewhat more difficult (but not impossible)
to read, but that does nothing at all to prevent copying.


-- 
Aaron

From nobody Tue Sep 17 18:59:35 2002
Newsgroups: perl.beginners.cgi
Subject: Re: Rounding a number
References: <001001c25a72$4c5e3850$1d61640a@microsoft.com>
Date: 17 Sep 2002 18:59:33 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 27

orasnita@home.ro (Octavian Rasnita) writes:

> I would like to round a number but to the next integer not like the
> int function does.

> From your code, it looks like you want to round up decimals >= .5, and
round down smaller ones.  That translates pretty easily into code:

sub round {
  my $num = shift;
  my $rem = $num - int($num);   # get decimal portion
  return $num unless $rem;      # if it's already an integer, return it
  if( $rem < .5 ){              # if decimal is < .5, 
        return int($num);       #     return int
  } else {
    return int($num) + 1;       # else return int of number + 1
  }
}

for ( .9, 3.499999, 4.5, 5.0, 6.789 ){    # then test it
  print "$_  ", round($_), "\n";
}


-- 
Aaron

From nobody Tue Sep 17 19:03:52 2002
Newsgroups: perl.beginners.cgi
Subject: Re: checkpassword function ??
References: <001a01c25b8c$f7020910$a101a8c0@mydomain.net>
Date: 17 Sep 2002 19:03:52 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 21

bien@www.veia.org.vn (Nguyen Thanh Bien) writes:

> i'm going to write a CGI script to change user's password on Linux
> system.  but i don't know how to check old password of user can i
> use perl functions or system command (Linux RedHat 7.3) ?

No.  The actual password is not stored on the system anywhere (unless
you stored it somewhere yourself when you created the account).  A
one-way hash of the password is stored, and authentication attempts
are tried against that hash.  

If the user is changing his own password, simply have him supply the
old password through the HTML form.  If it's not possible to get the
old password, you'll have to run the passwd utility as root -- in
which case on most systems it won't ask for the old password -- with
all the security implications that brings.


-- 
Aaron

From nobody Thu Sep 19 07:00:43 2002
Newsgroups: perl.beginners.cgi
Subject: Re: sort
References: <1032364836.10963.ezmlm@perl.org> <000a01c25f7d$ece86880$26b518c8@home>
Date: 19 Sep 2002 07:00:40 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 29

danielhb@perubookstore.com (Daniel Hurtado Brenner) writes:

> For example:
> If i have a flat data base myfile.txt with this info:

> 1|name|address|
> 2|name two|address two|
> 3|name three|address three|
> 4|name four|address four|
> ..... (etc, etc)

> OK. BUT HOW I CAN DO FOR THIS RESULTS BE:
> 4|name four|address four|
> 3|name three|address three|
> 2|name two|address two|
> 1|name|address|

Since you don't appear to want to change the contents of the lines,
there's no need to be splitting them and putting them back together.
Since your numbers to sort on are at the beginning of the lines, just
pass the data through a numerical sort:

  open M, "myfile.txt" or die $!;
  print sort { $b <=> $a } <M>;


-- 
Aaron

From nobody Tue Oct  1 07:00:59 2002
Newsgroups: perl.beginners.cgi
Subject: Re: How to run a process in background?
References: <005701c26831$29151950$e067e9d5@microsoft.com> <emjgpu4kdh0go42egqugd1dbhvi4h9kt5c@4ax.com>
Date: 01 Oct 2002 07:00:59 -0500
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Lines: 34

zentara@highstream.net (Zentara) writes:

> >Can you give me some hints about how I should use the fork, to run
> >the process in background?

> Your biggest problem is to close the pipes to apache from the forked
> children, else your clients will see their browser's hang.

There's another option, that I usually use.  Have the CGI store the
job to be done in a temporary file, and then have a separate job
running as a daemon or cron, which picks up the stored job files,
executes them, and deletes them.

In this case, your temporary files could look something like this:

---------------------------------------------------
address@from.com
address@to.net
My subject line
Body of message......
second line of body....
etc....
---------------------------------------------------

Then a simple cron could pick up that file, do some error checking
on the contents, and send the message based on that info.  

If you use this method, you need to make sure that no other
process/user can read/write/create these temporary files.


-- 
Aaron

