[17848] in Perl-Users-Digest
Perl-Users Digest, Issue: 8 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 6 18:05:36 2001
Date: Sat, 6 Jan 2001 15:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <978822308-v10-i8@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 6 Jan 2001 Volume: 10 Number: 8
Today's topics:
Re: Beginner cgi question.. <s2mdalle@titan.vcu.edu>
Re: Beginner cgi question.. <wavetable@birdmail.com>
Re: Could I remotely zip a file before I get it by FTP (Monte Phillips)
Re: Could I remotely zip a file before I get it by FTP <tony_curtis32@yahoo.com>
Re: Could I remotely zip a file before I get it by FTP (Chris Fedde)
Re: distributing perl.dll with commercial sw (Chris Fedde)
FA: 6 O'Reilly Perl Books on CD <username@invalid.com>
Re: files in directory <snef@soneramail.nl>
Re: files in directory <snef@soneramail.nl>
Re: files in directory <snef@soneramail.nl>
flock with dbm file <jhiller@online-testing.net>
Re: flock with dbm file (Garry Williams)
Re: Has anyone used Net::ICQ already? <replynews@bigfoot.com>
Re: JAPH critique (Abigail)
Mac pathnames <you.will.always.find.him.in.the.kitchen@parties>
Re: multiple setCookies <founder@pege.org>
Re: multiple setCookies <sarbayo@telis.org>
Re: Newbie but serious - Problems reading file from mul <joe+usenet@sunstarsys.com>
Re: Newbie but serious - Problems reading file from mul (Ilya Zakharevich)
Re: Newbie but serious - Problems reading file from mul (Garry Williams)
Re: Newbie but serious - Problems reading file from mul (Mark Jason Dominus)
Re: Newbie but serious - Problems reading file from mul <joe+usenet@sunstarsys.com>
Re: Newbie but serious - Problems reading file from mul <joe+usenet@sunstarsys.com>
Q: multiple setCookies <sarbayo@telis.org>
Re: still having problems with cookies <sarbayo@telis.org>
Re: The best way? <s2mdalle@titan.vcu.edu>
Re: Trouble with Interpolation <xzrgpnys@yvtugubhfrovm.pbz>
Re: Trouble with Interpolation (Tad McClellan)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 06 Jan 2001 19:49:06 GMT
From: "David Allen" <s2mdalle@titan.vcu.edu>
Subject: Re: Beginner cgi question..
Message-Id: <SEK56.2709$8O3.725372@typhoon2.ba-dsg.net>
In article <9378gc$dqs$1@news.kolumbus.fi>, "Wavetable"
<wavetable@birdmail.com> wrote:
> This is a really simple question but as I haven't found the answer
> anywhere I'll try it here. I don't know really anything about
> perl/cgi... How do you read parameters in cgi programs? I have tried the
> $QUERY_STRING method with #!/usr/local/bin/perl but it doesn't work, yet
> it works with
> #!/bin/sh. Thanks..
Like this:
Say your script is at http://foo.com/cgi-bin/foo.pl
And the user goes to:
http://foo.com/cgi-bin/foo.pl?x=5&y=2&z=3
Then what you do is this:
#!/usr/bin/perl -w
use strict;
use CGI;
my $c = new CGI;
if($c->param()) {
print $c->header();
print $c->start_html(-title=>"Foo!!!");
print $c->p, "X is ", $c->param('x');
print $c->p, "Y is ", $c->param('y');
print $c->p, "Z is ", $c->param('z');
print $c->end_html;
}
So basically the answer you're looking for is,
create a CGI object, then use the param() method
to get different parameters. IIRC, if you call
param() without an argument, you get a list of
parameters provided. I.e.
foreach $p ($c->param()) {
print $c->p, $p, " is ", $c->param($p);
}
should do the same thing. (IIRC)
--
David Allen
http://opop.nols.com/
----------------------------------------
"A raccoon tangled with a 23,000 volt line today. The results blacked
out 1400 homes and, of course, one raccoon."
- Steel City News
------------------------------
Date: Sun, 7 Jan 2001 00:19:56 +0200
From: "Wavetable" <wavetable@birdmail.com>
Subject: Re: Beginner cgi question..
Message-Id: <9385gu$f0t$1@news.kolumbus.fi>
Thanks alot! :)
"David Allen" <s2mdalle@titan.vcu.edu> wrote in message
news:SEK56.2709$8O3.725372@typhoon2.ba-dsg.net...
> In article <9378gc$dqs$1@news.kolumbus.fi>, "Wavetable"
> <wavetable@birdmail.com> wrote:
>
> > This is a really simple question but as I haven't found the answer
> > anywhere I'll try it here. I don't know really anything about
> > perl/cgi... How do you read parameters in cgi programs? I have tried the
> > $QUERY_STRING method with #!/usr/local/bin/perl but it doesn't work, yet
> > it works with
> > #!/bin/sh. Thanks..
>
> Like this:
>
> Say your script is at http://foo.com/cgi-bin/foo.pl
>
> And the user goes to:
> http://foo.com/cgi-bin/foo.pl?x=5&y=2&z=3
>
> Then what you do is this:
>
> #!/usr/bin/perl -w
> use strict;
> use CGI;
>
> my $c = new CGI;
>
> if($c->param()) {
> print $c->header();
> print $c->start_html(-title=>"Foo!!!");
> print $c->p, "X is ", $c->param('x');
> print $c->p, "Y is ", $c->param('y');
> print $c->p, "Z is ", $c->param('z');
> print $c->end_html;
> }
>
> So basically the answer you're looking for is,
> create a CGI object, then use the param() method
> to get different parameters. IIRC, if you call
> param() without an argument, you get a list of
> parameters provided. I.e.
>
> foreach $p ($c->param()) {
> print $c->p, $p, " is ", $c->param($p);
> }
>
> should do the same thing. (IIRC)
>
> --
> David Allen
> http://opop.nols.com/
> ----------------------------------------
> "A raccoon tangled with a 23,000 volt line today. The results blacked
> out 1400 homes and, of course, one raccoon."
> - Steel City News
------------------------------
Date: Sat, 06 Jan 2001 19:55:59 GMT
From: montep@hal-pc.org (Monte Phillips)
Subject: Re: Could I remotely zip a file before I get it by FTP
Message-Id: <3a57781a.20805036@news.hal-pc.org>
On 6 Jan 2001 18:54:07 GMT, abigail@foad.org (Abigail) wrote:
>Regent Linus (wstsoi@netvigator.com) wrote on MMDCLXXXV September
>MCMXCIII in <URL:news:937egf$kpg3@imsp212.netvigator.com>:
>^^ How could perl do this?
>
>There are various ways. You could use UUCP to give a remote command.
>Or you could NSF mount the drive the file is on, then zip it. Or
>install (write?) an FTP server that zips on the fly. Perl doesn't
>really play much of a role in all of this though.
>Abigail
I beg your pardon? why not system() and zip or tarball the thing?
------------------------------
Date: 06 Jan 2001 16:00:09 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Could I remotely zip a file before I get it by FTP
Message-Id: <87lmsoe3yu.fsf@limey.hpcc.uh.edu>
>> On Sat, 06 Jan 2001 19:55:59 GMT,
>> montep@hal-pc.org (Monte Phillips) said:
> On 6 Jan 2001 18:54:07 GMT, abigail@foad.org (Abigail)
> wrote:
>> Regent Linus (wstsoi@netvigator.com) wrote on MMDCLXXXV
>> September MCMXCIII in
>> <URL:news:937egf$kpg3@imsp212.netvigator.com>: ^^ How
>> could perl do this?
>>
>> There are various ways. You could use UUCP to give a
>> remote command. Or you could NSF [sic, NFS] mount the
>> drive the file is on, then zip it. Or install (write?)
>> an FTP server that zips on the fly. Perl doesn't really
>> play much of a role in all of this though. Abigail
> I beg your pardon? why not system() and zip or tarball
> the thing?
Because the file is located on a remote FTP server (see
sujbect line). I suppose you could get the file via FTP
into a named pipe (man mkfifo, perldoc perlipc) and then
zip/gzip the incoming data, but again this isn't really
much to do with perl.
hth
t
--
Eih bennek, eih blavek.
------------------------------
Date: Sat, 06 Jan 2001 22:38:45 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Could I remotely zip a file before I get it by FTP
Message-Id: <V7N56.723$B9.170956800@news.frii.net>
In article <87lmsoe3yu.fsf@limey.hpcc.uh.edu>,
Tony Curtis <tony_curtis32@yahoo.com> wrote:
>>> On Sat, 06 Jan 2001 19:55:59 GMT,
>>> montep@hal-pc.org (Monte Phillips) said:
>
>> On 6 Jan 2001 18:54:07 GMT, abigail@foad.org (Abigail)
>> wrote:
>>> Regent Linus (wstsoi@netvigator.com) wrote on MMDCLXXXV
>>> September MCMXCIII in
>>> <URL:news:937egf$kpg3@imsp212.netvigator.com>: ^^ How
>>> could perl do this?
>>>
>>> Perl doesn't really play much of a role in all of this though.
>>> Abigail
>
>> I beg your pardon? why not system() and zip or tarball
>> the thing?
>
>I suppose you could get the file via FTP
>into a named pipe (man mkfifo, perldoc perlipc) and then
>zip/gzip the incoming data, but again this isn't really
>much to do with perl.
>
The main reason to compress the file is to save time in transit.
so compressing it on the fly at the local end does not buy anything.
As Abigail pointed out, the OP needs to take advantage of features on the
remote FTP server. Some FTP servers can do things like tar and zip on the
fiy. If the OP is lucky the remote is using one of these.
--
This space intentionally left blank
------------------------------
Date: Sat, 06 Jan 2001 22:55:30 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: distributing perl.dll with commercial sw
Message-Id: <CnN56.724$B9.190628352@news.frii.net>
In article <937etn$ojc$1@nnrp1.deja.com>, <nmaddix@bb2w.com> wrote:
>Hope someone can help... I've written a piece of commercial software in
>c++ that embeds small amounts of perl code and links with perl56.dll.
>All I need to do is distribute the dll with the application and I'm good
>to go.
>
>The problem is... is it legal to distribute perl56.dll with a commercial
>application? The perl artistic license seems to say this is OK, but
>doesn't address the dll directly. Can anyone point me to a more
>closely-related source of information on this specific situation?
>
Did you read the licence for the distribution of Perl that you are
using? What did it say about this issue?
Good Luck
chris
--
This space intentionally left blank
------------------------------
Date: Sat, 06 Jan 2001 22:40:10 GMT
From: lbecker <username@invalid.com>
Subject: FA: 6 O'Reilly Perl Books on CD
Message-Id: <rd7f5tkl82frs02fqjohe730rshbnes97t@4ax.com>
For auction, well below half price. The Perl CD Bookshelf on CD.
Also comes with the paperback "Perl in a Nutshell."
This is the book with the original CD. (not a CD-R copy).
If interested take a look at
http://cgi.ebay.com/aw-cgi/eBayISAPI.dll?ViewItem&item=1402729410
Amazon reviews and info at :
http://www.amazon.com/exec/obidos/ASIN/1565924622/o/qid=978808310/sr=8-1/ref=aps_sr_b_1_1/002-5984827-3955204
Great resource if you are learning or using Perl.
The six books are :
Perl In a Nutshell
Programming Perl, 2nd Edition (the Camel book)
Perl Cookbook
Advanced Perl Programming
Learning Perl. 2nd Edition (the Llama book)
Learning Perl on Win32 Systems
------------------------------
Date: Sat, 6 Jan 2001 21:56:02 +0100
From: snef <snef@soneramail.nl>
Subject: Re: files in directory
Message-Id: <MPG.14c1a4ca82b75fc2989700@news.soneraplaza.nl>
In article <3a5763f4.1df$4f@news.op.net>, mjd@plover.com says...
> In article <MPG.14c1449a326489f19896fd@news.soneraplaza.nl>,
> snef <snef@soneramail.nl> wrote:
> >I want a script to get files out a directory (if there are any), read
> >them and delete them. (and later; when something goes wrong in the
> >script, I want to save the file in another directory.) I think it
> >can be done more efficient (?) or in a different manner. Can somebody
> >give my some tips/hints?
>
> The way you did it is fine, and is aprobably about as efficient as any
> other method people will come up with. I saw two small but serious
> problems that I saw were that you changed the value of $/ and did not
> put the old value back when you were done. It is a good practice to
> use 'local' when you change the value of $/:
>
>
> foreach $file (@files) {
> local $/;
> undef ($/);
> ...
> }
>
> The 'local' expression tells Perl to save the old value of $/ and to
> arrange to restore the old value automatically when control leaves
> trhe 'foreach' loop. That way you can't forget to put the old value
> back, because it happens automatically.
>
> The other problem is that
>
> unlink <./dirname/$file>;
>
> does not do what you mean. You want to use
>
> unlink "./dirname/$file";
>
> instead. <...> does a pattern-matching operation and produces a list
> of all the matching files. This could cause problems if $file
> happened to contain a '*' or '?' character.
>
> If you wanted to use less code, you should follow Tad's suggestions.
> But here is a tricky alternative that may amuse you:
>
> { my @files = grep m{/\w[^/]*$}, glob("./dirname/*");
> local $/ = undef;
> local @ARGV = @files;
> my @file_data = <>;
> # use @file_data here
> unlink @files;
> }
>
> glob("./dirname/*") constructs a list of all the files in the
Thanx also!
------------------------------
Date: Sat, 6 Jan 2001 21:55:42 +0100
From: snef <snef@soneramail.nl>
Subject: Re: files in directory
Message-Id: <MPG.14c1a4bc332bdf079896ff@news.soneraplaza.nl>
In article <slrn95ebcp.sgh.tadmc@magna.metronet.com>, tadmc@metronet.com
says...
> snef <snef@soneramail.nl> wrote:
> >
> >I want a script to get files out a directory (if there are any), read
> >them and delete them. (and later; when something goes wrong in the
> >script, I want to save the file in another directory.)
> >
> >#!/usr/bin/perl -w
>
> use strict;
>
>
> ># get filenames out directory
> >open (DIR,"./dirname");
>
>
> You need to call opendir() for directories. open() is for files.
>
> You should check the return value too:
>
> opendir(DIR, './dirname') or die "could not open './dirname' directory $!";
>
>
> >while ($name = readdir(DIR));
> > next if $name !~ /^\w/;
> > push(@files, $name);
> >}
>
>
> You can replace that whole loop with one statement:
>
> my @files = grep /^\w/, readdir(DIR);
>
>
> >foreach $file (@files) {
>
>
> You don't need the temp @files array at all:
>
> foreach $file ( grep /^\w/, readdir(DIR) ) {
>
>
>
> > unlink <./dirname/$file>;
>
> Globbing is dangerous there (what if $file = 'foo*.bar'?), you
> should use a string instead, else you may be deleting more than
> a single file:
>
> unlink "./dirname/$file";
>
Thanx!
(i already had opendir in my file....just mistyped here...)
------------------------------
Date: Sat, 6 Jan 2001 22:10:35 +0100
From: snef <snef@soneramail.nl>
Subject: Re: files in directory
Message-Id: <MPG.14c1a83a49993d41989701@news.soneraplaza.nl>
In article <slrn95ebcp.sgh.tadmc@magna.metronet.com>, tadmc@metronet.com
says...
> snef <snef@soneramail.nl> wrote:
> >
> >I want a script to get files out a directory (if there are any), read
> >them and delete them. (and later; when something goes wrong in the
> >script, I want to save the file in another directory.)
> >
> >#!/usr/bin/perl -w
>
> use strict;
>
>
> ># get filenames out directory
> >open (DIR,"./dirname");
>
>
> You need to call opendir() for directories. open() is for files.
>
> You should check the return value too:
>
> opendir(DIR, './dirname') or die "could not open './dirname' directory $!";
>
>
> >while ($name = readdir(DIR));
> > next if $name !~ /^\w/;
> > push(@files, $name);
> >}
>
>
> You can replace that whole loop with one statement:
>
> my @files = grep /^\w/, readdir(DIR);
>
>
> >foreach $file (@files) {
>
>
> You don't need the temp @files array at all:
>
> foreach $file ( grep /^\w/, readdir(DIR) ) {
>
>
>
> > unlink <./dirname/$file>;
>
> Globbing is dangerous there (what if $file = 'foo*.bar'?), you
> should use a string instead, else you may be deleting more than
> a single file:
>
> unlink "./dirname/$file";
>
Only one problem here.....
How do I let directories out of the foreach loop? I only want to select
files.
Snef
------------------------------
Date: Sat, 06 Jan 2001 20:12:09 GMT
From: Jordan Hiller <jhiller@online-testing.net>
Subject: flock with dbm file
Message-Id: <3A577CCC.C7EB1222@online-testing.net>
When I do a dbmopen(), will flock() work the same way as with a normal
open()? Is there anything different I need to do?
Thanks,
Jordan Hiller
http://www.Online-Testing.Net
Online Quiz and Testing Solutions
------------------------------
Date: Sat, 06 Jan 2001 21:46:19 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: flock with dbm file
Message-Id: <LmM56.72$UQ5.3737@eagle.america.net>
On Sat, 06 Jan 2001 20:12:09 GMT, Jordan Hiller
<jhiller@online-testing.net> wrote:
>When I do a dbmopen(), will flock() work the same way as with a
>normal open()?
Hmm. From perlfunc manual page:
Functions obsoleted in perl5
`dbmclose', `dbmopen'
...
dbmopen HASH,DBNAME,MASK
[This function has been largely superseded by the
`tie' function.]
So, you seem to be starting with the wrong question.
The NDBM_File manual page and perlfunc manual page (tie) don't mention
how to lock a `dbm' file. So, I would use a semaphore file to
_represent_ the dbm file and lock it *before* tie'ing it and untie the
dbm file *before* unlocking the semaphore.
If you are tie'ing using DB_File, that manual page has a whole section
discussing how to safely lock the file.
>Is there anything different I need to do?
Probably. See above.
--
Garry Williams
------------------------------
Date: Sat, 6 Jan 2001 22:30:03 +0100
From: "Ralf Siedow" <replynews@bigfoot.com>
Subject: Re: Has anyone used Net::ICQ already?
Message-Id: <9382on$3ns$03$2@news.t-online.com>
Uuh, ouch, how could I post such a dump text?
Ok, trying to de-dump it:
The module's test script don't work because it seems that they don't get any
ack after sending the login command to the icq server. As far as I
understood the protocol specs (I got them from:
http://www.algonet.se/~henisak/icq/icqv5.html) the module does everything
correct.
Did AOL/Mirabilis change the protocol again to keep competition running like
ants?
Any hints on how to change the test.pl and test2.pl scripts included in the
Net::ICQ-Package so they will work?
cu Ralf
------------------------------
Date: 6 Jan 2001 19:10:03 GMT
From: abigail@foad.org (Abigail)
Subject: Re: JAPH critique
Message-Id: <slrn95ercb.94m.abigail@tsathoggua.rlyeh.net>
Robert M. Starkweather (cm142@freenet.buffalo.edu) wrote on MMDCLXXXIV
September MCMXCIII in <URL:news:G6pMGq.BB0@freenet.buffalo.edu>:
() hello, all. i am a relative novice to perl (i use it , at my place of
() employment for simple database manipulation/reporting), and have fallen
() for its inherent style. i've been lurking here for quite a while, and am
() mightily impressed by some of the JAPHs posted here (particularly
() abigail's). i was hoping some of you would take a moment to critique my
() first JAPH creations (all only tested on my unix box at work...hey, it's
() been a slow week :) ....with perl version 5.004_04, built for
() sun4-solaris).
()
() i know they're kind of ugly, but i'm working on it...i am especially proud
() of #3 (an example of extreme laziness).
()
() but will 2 and 3 (which rely on perldoc) work on all systems?
() i.e., is the format of perldoc a set standard across systems/versions
() of perl?
() let me know if they don't work...
()
() perl -e 'split //, "IF A BOY DECIDES TO PLAY WITH PERL, HE BECOMES....";
() $a=(join q//, 0, $_[9], $_[10], ord($_[11]), $_[11], 4, 1, $_[10],
() $_[10], "010", $_[5], ord("#"), $_[9], ord(","), $_[1],
() $_[3], 1, $_[10], $_[5], ord($_[3]), 7, $_[3], 2, $_[10], $=/4,
() $_[1], ord(7), 5**2, $_[3], ord(5), $_[10], $_[3]);
() while(length $a) {$b=hex(substr $a, 0, 7); substr ($a, 0, 7)="";
() split //, $b; @_=("$_[0]$_[1]", "$_[2]$_[3]", "$_[4]$_[5]",
() "$_[6]$_[7]"); print (map { (($_==32)&&chr($_))||chr($_+$=) }
() @_);} print ",\n";'
This one is just too long. JAPHs should preferably fit in 4 lines, each
at most 80 characters long. (Yeah, I know, a few of mine are too long too).
() perl -e '$_=`perldoc -f split`; @_=split //; $_=join q//, chr((ord
() $_[1416])-32), $_[157], $_[2799], $_[4255], $_[4377], $_[4300],
() $_[4166], $_[4200], $_[4255], $_[4199], $_[4250], $_[4249],
() $_[4377], $_[4356], $_[4250], $_[4249], $_[4243], $_[4377],
() $_[4199], $_[4300], $_[4204], $_[3646], $_[4250], $_[4249],
() $_[4202], "\n"; print'
This one is sensitive to which version of the documentation is installed.
My 5.6.0 Perl shows gibberish. It's also too long, but that can be fixed:
perl -le '@_ = split //, `perldoc -f split`;print chr((ord $_[1416])-32),
@_[ 157,2799,4255,4377,4300,4166,4200,4255,4199,4250,4249,4377,
4356,4250,4249,4243,4377,4199,4300,4204,3646,4250,4249,4202]'
() perl -e '$_=`perldoc -q JAPH`;($_=substr $_,(index $_,"?")+29,24)=~y/jp/JP/;
() print $_,",\n"'
Something like this has been seen in this group before.
Abigail
--
perl -wlne '}print$.;{' file # Count the number of lines.
------------------------------
Date: Sun, 7 Jan 2001 11:16:56 +1300
From: "Tintin" <you.will.always.find.him.in.the.kitchen@parties>
Subject: Mac pathnames
Message-Id: <978819565.41200@shelley.paradise.net.nz>
I've looked in the Perl FAQ, the deja archives and the MacPerl mailing list,
but I couldn't find a definitive resource or reference that explains how to
handle Mac pathnames and more importantly, how to write portable scripts to
cater for the differences.
Maybe I just missed a reference, but I would certainly appreciate any
pointers.
I did see a few MacPerl scripts which had a section with
sub GetDirSeperatorChar
{
my ($tOSString) = @_;
my ($tDirSepChar);
if ($tOSString eq 'MacOS') { #it's a Macintosh!
$tDirSepChar = ':';
}
elsif ($tOSString =~ /nix/i) { #it's probably some flavor of Unix
$tDirSepChar = '/';
}
else { #it could be other things, but assume a Wintel PC
$tDirSepChar = '/'; #!?! -- same as unix, not '\' as expected!
}
return ($tDirSepChar);
}
so I'm assuming that you have to use a : as the Mac directory separator.
Is converting Unix pathnames to Mac as simple as converting / to :'s? I
suspect not.
------------------------------
Date: Sat, 6 Jan 2001 23:23:29 +0100
From: "Mösl Roland" <founder@pege.org>
Subject: Re: multiple setCookies
Message-Id: <3a579c36$0$17558@SSP1NO25.highway.telekom.at>
"steve a" <sarbayo@telis.org> wrote in message
news:3a57977c.9653618@news.inreach.com...
> Q:
> using Perl, is there a way to set multiple cookies during a single cgi
> process ??
> but not this:
> print header(-cookie=>[$cookie1,$cookie2]);
For what?
The Cookie should only be the key
to access a database on the server
--
Mösl Roland founder@pege.org
http://www.pege.org clear targets for a confused civilization
http://www.BeingFound.com web design starts at the search engine
------------------------------
Date: Sat, 06 Jan 2001 23:02:00 GMT
From: steve a <sarbayo@telis.org>
Subject: Re: multiple setCookies
Message-Id: <3a57a1f6.12336155@news.inreach.com>
On Sat, 6 Jan 2001 23:23:29 +0100, "Mösl Roland" <founder@pege.org>
wrote:
:"steve a" <sarbayo@telis.org> wrote in message
:news:3a57977c.9653618@news.inreach.com...
:> Q:
:> using Perl, is there a way to set multiple cookies during a single cgi
:> process ??
:> but not this:
:> print header(-cookie=>[$cookie1,$cookie2]);
:
:For what?
1) to determine if cookies are enables on the browser, by sending
a "dummy" cookie and then reading it,
2) If cookies are enabled, set a real cookie.
As I stated:
#pseudo code:
#set a dummy cookie
print header(-cookie=>[$cookie1]);
#next, test if cookies are "on" by fetching the dummy
%cookies = fetch CGI::Cookie;
if(! %cookies) {
#do plan "B"
#indicate cookies are "off"
} else {
#do plan "A"
#set a valid cookie
}
:
:The Cookie should only be the key
:to access a database on the server
I don't recall there being any rules on cookies,,,,
Steve
------------------------------
Date: 06 Jan 2001 14:45:38 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <m37l4831nh.fsf@mumonkan.sunstarsys.com>
mjd@plover.com (Mark Jason Dominus) writes:
> In article <m3d7e03ah0.fsf@mumonkan.sunstarsys.com>,
> Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
> >> > if ($file ne "") {
> >> > my $fileName = $file;
> >> > $fileName =~ s!^.*(\\|\/)!!;
> >
> >I've seen this bad idiom in cgi scripts before;
>
> What's bad about it? I don't know much about windows systems, but on
> Unix it would be safe.
No it would not. In the context that OP is using it,
it's very bad. Here's his open call:
> >> > open (OUTFILE, ">F:/www/mysite/$user/$fileName") || print "<br><b>$0
> >> > ERROR: $!</b><br>";
% cat try.pl
#!/usr/bin/perl -wT
use strict;
use CGI qw(-debug);
my $q = new CGI;
my $fileName = $q->param('f');
$fileName =~ s!^.*(\\|\/)!!; # merely strips directory from $fileName
open OUTFILE, ">/www/mysite/me/$fileName" or die $!;
close OUTFILE;
__END__
% try.pl f=.htaccess
Insecure dependency in open while running with -T switch
at /tmp/try.pl line 7.
% try.pl f=ssi.shtml
Insecure dependency in open while running with -T switch
at /tmp/try.pl line 7.
% try.pl f=sh.cgi
Insecure dependency in open while running with -T switch
at /tmp/try.pl line 7.
Note that looking for correct file extensions in an effort
to detaint the filename can also be very difficult.
% try.pl f=archive.tar.gz
Insecure dependency in open while running with -T switch
at /tmp/try.pl line 7.
%try.pl f=ssi.shtml%00.gif
Insecure dependency in open while running with -T switch
at /tmp/try.pl line 7.
--
Joe Schaefer
------------------------------
Date: 6 Jan 2001 19:46:34 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <937smq$pgl$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was sent to Mark Jason Dominus
<mjd@plover.com>],
who wrote in article <3a575dac.133$2b3@news.op.net>:
> >I don't see where you are untainting the filename.
>
> That would be this line here:
>
> >> $fileName =~ s!^.*(\\|\/)!!;
>
> It's not designed to work specifically with the tainting mechanism,
> but it serves the same purpose.
Really? Is not it a bug then? I thought only $<n> were untainted,
and only because they may be accessed in a different statement.
(Tainting taints a whole statement at once.)
Ilya
------------------------------
Date: Sat, 06 Jan 2001 21:30:32 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <Y7M56.71$UQ5.3737@eagle.america.net>
On 06 Jan 2001 14:45:38 -0500, Joe Schaefer
<joe+usenet@sunstarsys.com> wrote:
>mjd@plover.com (Mark Jason Dominus) writes:
>
>> In article <m3d7e03ah0.fsf@mumonkan.sunstarsys.com>,
>> Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
>> >> > if ($file ne "") {
>> >> > my $fileName = $file;
>> >> > $fileName =~ s!^.*(\\|\/)!!;
>> >
>> >I've seen this bad idiom in cgi scripts before;
>>
>> What's bad about it? I don't know much about windows systems, but on
>> Unix it would be safe.
>
>No it would not. In the context that OP is using it,
>it's very bad. Here's his open call:
>
>> >> > open (OUTFILE, ">F:/www/mysite/$user/$fileName") || print "<br><b>$0
>> >> > ERROR: $!</b><br>";
>
>% cat try.pl
>#!/usr/bin/perl -wT
>use strict;
>use CGI qw(-debug);
>my $q = new CGI;
>my $fileName = $q->param('f');
>$fileName =~ s!^.*(\\|\/)!!; # merely strips directory from $fileName
>open OUTFILE, ">/www/mysite/me/$fileName" or die $!;
>close OUTFILE;
>__END__
>
>% try.pl f=.htaccess
>Insecure dependency in open while running with -T switch
>at /tmp/try.pl line 7.
I don't know what you expected to happen. $fileName is tainted. You
didn't untaint it. The code above will fail because of that, a
priori. See perlsec, "Laundering and Detecting Tainted Data".
--
Garry Williams
------------------------------
Date: Sat, 06 Jan 2001 22:38:39 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <3a579e6e.84a$8c@news.op.net>
In article <m37l4831nh.fsf@mumonkan.sunstarsys.com>,
Joe Schaefer <joe+usenet@sunstarsys.com> wrote:
>> What's bad about it? I don't know much about windows systems, but on
>> Unix it would be safe.
>
>No it would not. In the context that OP is using it,
>it's very bad.
>% try.pl f=.htaccess
In that case, the sercurity problem is in putting .htaccess, which is
a security contrtol file, into the directory that is is supposed to be
controlling. That is like putting the keys to the jail incide the
cell, instead of outside.
If the directory is asupposed to be writable---which it is---then the
.htaccess file should be elsewhere. Good security practice is that
user upload directories should not be in the server's HTML tree at
all, for precisely this kind of reason.
>Note that looking for correct file extensions in an effort
>to detaint the filename can also be very difficult.
Yes, and that is why you should avoid the whole problem, by assigning
one meaning ('uploads') to the directory, rather than two
('downloads') or three ('security controls').
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f|ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 06 Jan 2001 17:46:27 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <m33dew2ta4.fsf@mumonkan.sunstarsys.com>
Patrick Holthuizen <pholthuizen@celwood.com> writes:
> Hi all,
>
> I've asked this before, but I didn't receive any reactions. Here it is
> again, please help me out.
>
> As you all have I'm writing a script to upload files from a web browser
> to a web site. Yes, I've stumble across all the common problems
> (binmode) but I'm still having corrupt binary file uploads. The problem
> seems to be in the file reading system, when I read the file supplied by
> the user the script seems to read more bytes than the number
> actually available in the file. These bytes seem to be occuring
> at random places within the file. Seems like a binmode problem,
> but it isn't.
Try running this test CGI script on the server:
#!/usr/bin/perl -wl
use strict;
use CGI;
use Config;
print "Content-Type: text/plain\n";
print "CGI version: $CGI::VERSION";
print '$^O = ' . $^O;
print "OS type: $Config::Config{osname}";
print '$needs_binmode = ' . $CGI::needs_binmode;
print "SERVER_SOFTWARE = $ENV{SERVER_SOFTWARE}";
print "GATEWAY_INTERFACE = $ENV{GATEWAY_INTERFACE}";
__END__
If the output of that script indicates a problem,
you can check the file attributes of the temp file
that CGI uses to spool the upload in your script.
Add this (or something similar like $q->tmpFileName...)
right below your close line (untested code):
...
close(OUTFILE);
my $spool = $req->{'.tmpfiles'}->{fileno("$file")}->{name}->as_string;
print "Used $spool as spool: size is " . -s $spool . " bytes\n";
print "File no. $onnum ($fileName) has been transfered. ($teller
bytes)<p>\n";
...
The output of these may help you determine the cause
(I'm thinking that CGI is guessing wrong about your
platform's binmode setting for the spool file).
If CGI is working OK, it's time to check whether the
browser is broken.
HTH
--
Joe Schaefer
------------------------------
Date: 06 Jan 2001 18:00:01 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Newbie but serious - Problems reading file from multipart forms (no binmode!) (repost)
Message-Id: <m3y9wo1e32.fsf@mumonkan.sunstarsys.com>
garry@zvolve.com (Garry Williams) writes:
> On 06 Jan 2001 14:45:38 -0500, Joe Schaefer
> <joe+usenet@sunstarsys.com> wrote:
>
> >% cat try.pl
> >#!/usr/bin/perl -wT
> >use strict;
> >use CGI qw(-debug);
> >my $q = new CGI;
> >my $fileName = $q->param('f');
> >$fileName =~ s!^.*(\\|\/)!!; # merely strips directory from $fileName
> >open OUTFILE, ">/www/mysite/me/$fileName" or die $!;
> >close OUTFILE;
> >__END__
> >
> >% try.pl f=.htaccess
> >Insecure dependency in open while running with -T switch
> >at /tmp/try.pl line 7.
>
> I don't know what you expected to happen. $fileName is tainted. You
> didn't untaint it.
*That* is the point - had OP enabled taint checks, his code
never would have run. If you allow a random goofball to name
files on your server- .htaccess is the first one they'll try
to upload. Setting the appropriate content in this file, say
Options ExecCGI Includes
and the next few files uploaded to that directory can be lethal.
(Note that this usually isn't necessary, given the settings many
web hosting companies use to configure their servers. You can
usually skip right to SSI).
--
Joe Schaefer
------------------------------
Date: Sat, 06 Jan 2001 22:09:28 GMT
From: steve a <sarbayo@telis.org>
Subject: Q: multiple setCookies
Message-Id: <3a57977c.9653618@news.inreach.com>
Q:
using Perl, is there a way to set multiple cookies during a single cgi
process ??
but not this:
print header(-cookie=>[$cookie1,$cookie2]);
need the following:
#pseudo code:
print header(-cookie=>[$cookie1]);
#next, test if cookies are "on"
%cookies = fetch CGI::Cookie;
if(! %cookies) {
#indicate cookies are "off"
#do plan "B"
} else {
#set a valid cookie
#do plan "A"
}
I can't seem to find a way of doing this,
once the *header* has been sent.
Steve
------------------------------
Date: Sat, 06 Jan 2001 22:37:47 GMT
From: steve a <sarbayo@telis.org>
Subject: Re: still having problems with cookies
Message-Id: <3a579cd8.11026083@news.inreach.com>
I don't see a "fetch" anywhere.
Like:
%cookies = fetch CGI::Cookie;
See below:
On Sat, 6 Jan 2001 12:17:29 -0000, "Sian Baldwin" <Sian@Baldwin.net>
wrote:
:I posted this question a couple of days agao and got a resonse from
:Rafael...unfortunately, this didn't resolve the problem...so I am still in
:need of help, here was my original posting:
:
:I have written some code that takes user details and enters them in a
:database and then sets a cookie with the users name. I then use this cookie
:to welcome the user back on the main home page when they return to the
:site...my problem is that I cannot retrieve the cookie???
:
:Here is the code I am trying to retrieve the cookie with:
:
:#!/local/bin/perl
:
:use CGI qw(:standard :html3);
:use CGI::Carp ('fatalsToBrowser');
:
:%stored_cookie = cookie('ID');
%cookie = fetch CGI::Cookie;
$stored_cookie = $cookies{'name'}->value;
:
:$personalised = $stored_cookie{name} ?
: "Welcome back, $stored_cookie{name}!" : "Customizable Page";
:
:print header();
:print start_html('Home Page');
:print h1($personalised);
:
:print end_html;
:
:I always get the "customizable page" bit, rather than the "welcome back
:whoever" bit....I have checked my cookies folder and a cookie has clearly
:been lodged by the other script....I cannot figure this one out??
:
:Help would be greatly appreciated!!!
:Sian
:
:
:
:
------------------------------
Date: Sat, 06 Jan 2001 19:53:34 GMT
From: "David Allen" <s2mdalle@titan.vcu.edu>
Subject: Re: The best way?
Message-Id: <2JK56.2712$8O3.726868@typhoon2.ba-dsg.net>
In article <3a56f600$0$17822@SSP1NO25.highway.telekom.at>, "Mösl Roland"
<founder@pege.org> wrote:
Use the source, Luke! What you're looking for is
CPAN.
> 1.) ZIP a folder
>
> I need to zip a whole folder. On all computer is WinZip 8 installed
> There is a command line extension of WinZip 8
>
> Should I use this WinZip8 command line extension or is there a more
> elegant way in Perl to ZIP files
Archive::Zip on CPAN
http://search.cpan.org/doc/NEDKONZ/Archive-Zip-0.10/lib/Archive/Zip.pm
> 2.) FTP to the server
>
> Transfer files from the local harddisk per FTP to the web server
Net::FTP on CPAN
http://search.cpan.org/doc/GBARR/libnet-1.0703/Net/FTP.pm
> 3.) Manipulate and store pictures
>
> All clients have now PSP 7 on their computers. The common task is to
> store a picture from a
> 3.3 M Pixel digital camera in 3 different resolutions.
> name_print.jpg in original size name.jpg 600 width
> or 540 height name_dir.jpg 80 height I want to make this
> automatic.
>
> Perfect picture resize and interlaced JPG store are necessary. Maybe to
> test and to decide to store the small pic in JPG or PNG.
I am not immediately familiar with a module that
does this, but I'd bet that it exists.
Go to http://search.cpan.org/ and look for modules
related to Jpeg files, RTFM, and see if they meet
your needs.
In general, get to know CPAN. It will make your
life much easier.
--
David Allen
http://opop.nols.com/
----------------------------------------
"A raccoon tangled with a 23,000 volt line today. The results blacked
out 1400 homes and, of course, one raccoon."
- Steel City News
------------------------------
Date: 06 Jan 2001 19:11:36 GMT
From: kevin metcalf <xzrgpnys@yvtugubhfrovm.pbz>
Subject: Re: Trouble with Interpolation
Message-Id: <3A576E80.51982BE2@yvtugubhfrovm.pbz>
> > Here's the part of the code that matters:
> > *******
> > $option_line = "<option ";
> > unless ($contents{print_option} == 0) { $option_line .=
> > 'value="$i"';}
> $option_line = "value=\"$i\"";
> or a bit cleaner:
> $option_line = qq{value="$i"};
You were sorta right. I tried this already, and it didn't fix it. The
problem is that the response you gave me will evaluate the variable $i
BEFORE the program gets to the loop. Ex:
#!/usr/bin/perl
$counter=123;
$my_var = qq/Count=$counter/;
for ($counter=0; $counter<3; $counter++) {
print $my_var;
}
Gives me:
Count=123Count=123Count=123
When I want it to give me:
Count=0Count=1Count=2
For those of you just joining us, the acctual code like this:
$option_line = "<option ";
unless ($contents{print_option} == 0) {
$option_line .= qq/value="$i"/;
}
unless ($contents{extra} eq "") {
$option_line .= " $contents{extra}";
}
$option_line .= qq/>$i/;
if ($contents{newlinechar} eq "ret") {
$option_line .= "\n";
}
else { $option_line .= "$newlinechar"; }
$countfrom=$contents{countfrom};
$countto=$contents{countto};
$countto++;
for ($i=$countfrom; $i<$countto; $i++){
print $option_line;
}
TIA
--
Kevin Metcalf
(Carbon Ocelot)
email: xzrgpnys@yvtugubhfrovm.pbz
Huh? http://www.flactem.com/utils/rot13.html
------------------------------
Date: Sat, 6 Jan 2001 12:44:43 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Trouble with Interpolation
Message-Id: <slrn95emcb.std.tadmc@magna.metronet.com>
kevin metcalf <xzrgpnys@yvtugubhfrovm.pbz> wrote:
>> > Here's the part of the code that matters:
>> > *******
>> > $option_line = "<option ";
>> > unless ($contents{print_option} == 0) { $option_line .=
>> > 'value="$i"';}
>> $option_line = "value=\"$i\"";
>> or a bit cleaner:
>> $option_line = qq{value="$i"};
>
>You were sorta right.
^^^
You who?
Please provide an attribution when you quote someone.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8
************************************