Re: how to send a page and a file at a download script?

2008-09-23 Thread Wiggins d'Anconia
shnaxe wrote:
 dear readers,
 
 i recently finished a small perl-cgi download script that sends files
 after some checks and logging. i call this script through a link on a
 static html-page and pass the file-id as a parameter.
 
 this all works nice so far, the part where i'm stuck at is that with
 clicking on the link, the page containig the link is replaced by a
 white blank page. i wonder how i could instead get either:
 - the page containig the link stays, link is targeted to a new window
 (minimal version)
 - a new page is displayed containg something like 'thank you for
 downloading... you download should start now...' (deluxe solution)
 
 for the minimal version, i thought putting a simple 'target=_blank'
 into the link should do what i want (only tested with firefox 3.0 so
 far). this indeed works, but the focus changes to the popping up new
 blank tab and further, this tab stays open after the file is
 transferred. i remember having seen this differently on the web.
 
 for the deluxe verson i think i somehow need to send out two headers,
 one of type 'application/x-download' (for the file) and another of
 type 'text/html' (for the page).
 but how would i do this? i'm afraid that the second header (whichever)
 will not get recognized as a second document but be embedded into the
 first. i guess a short sleep between the first and the second header
 won't do it...
 

You shouldn't really need a new window at all if you don't want one, at
least not in some browsers. If you return the proper headers followed by
the content then the user should be able to click the download link and
stay right where they are with the standard browser action occuring. If
you return a proper content-type then the browser should just do what
you want, if you return a Content-Disposition header then you will get
to specify a suggested filename, etc. 'application/octet-stream' can
usually be used as a generic download header if you don't have a
specific content-type in mind. So your headers might be:

Content-Type: application/octet-stream
Content-Disposition: attachment; filename=some download.pdf

or in the above case if you know it will be a PDF,

Content-type: application/pdf

 thanks for help and suggestions in advance,
 regards, shnaxe

HTH,

http://danconia.org

 
 ps: well, i am unsure if this would have been better posted to another
 group (but which) since its maybe not a pure perl-question. i got to
 admit that from my point of knowledge, the solution to the problem i
 described seems to be somewhere on a blurry line between perl/cgi and
 html...
 
 

I'd say it is appropriate.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: parsing a line

2008-08-19 Thread Wiggins d'Anconia

thunder wrote:

Hello all

I have the following small file that i am parsing one line at a time
(each line consists of hex values)

line 1: 0d
line 2: 
line 3: 2000
line 4: 0064
line 5: 76d457ed462df78c7cfde9f9e33724c6
line 6: bded7a7b9f6d763e
line 7: 0059010081bb300597603b6f90ef4421
line 8: 001608427754e957a0d281bb30059760
line 9: a72f731c3be6


For line 5, for example, i want to break it up into chunks of 8 hex
charaters (ie for example 76d457ed, 462df78c etc).
I tried to use the shift operator (ie  or ) but perl gives an
error.

Any help with the above would be appreciated.

Thanks





Check out the pack/unpack functions,

perldoc -f unpack

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Extracting TD's from a Text File (Regex Help).

2008-04-08 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote:
  TEXT FILE ##
 td class=PhorumTableRowAlt thread  style=padding-left: 0px
 
 a href=http://mysite.com/link/here_goes?id=239;LINK/a
 
 nbsp;span class=PhorumNewFlag/span/td
 
  td class=PhorumTableRowAlt nowrap=nowrap width=150
   a href=http://mysite.com/link/here_goes?id=239;LINK/a /td
 td class=PhorumTableRowAlt PhorumSmallFont nowrap=nowrap 
 width=15006/11/2007 12:29AM
  /td
 /tr
 
 
 The text file contains hundreds of tds structure like above. All I need is to 
 extract the td with class PhorumTableRowAlt thread. I have tried every 
 possible option, but finally I am coming to you for any Regex for it? TIA.
 
 HERE IS WHAT I AM DOING:
 
 pen(TXT, links.txt) or die Unable to open file;
 my @links = TXT;
 close (TXT);
 foreach my $link(@links) {
 if ($link =~ m|td class=PhorumTableRow thread style=padding-left: 
 0px(.*?)/td|gsi) {
 print $1;}
 }
 
 
 
 But NOTHING coming up. No results.
 
 Thanks for any help.
 
 Sara.
 

Parsing HTML with regexes is just a bad idea. Try a module from CPAN,
I've had good luck with HTML::TokeParser::Simple,

http://search.cpan.org/perldoc?HTML::TokeParser::Simple

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Adding a comma to format localtime

2007-04-09 Thread Wiggins d'Anconia

Gregg O'Donnell wrote:

All,
  I use this line of code:
  my $datetime = join ' ', (split ' ', localtime)[0,2,1,4,3];


my $localtime = [ split ' ', localtime ];
my $datetime = $localtime-[0] . ', ' . join ' ', @$localtime[2,1,4,3];

TMTOWTDI...

http://danconia.org

   
  To create this result:

  Mon 9 Apr 2007 09:15:05
   
  How can I add a comma to this result to get:

  Mon, 9 Apr 2007 09:15:05
   
  Best and thanks,

  Gregg



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: Tweeking a sendmail routine.

2007-03-25 Thread Wiggins d'Anconia

Greg Schiedler wrote:

I know enough Perl to be dangerous!

I have a form that sends out several different confirmations depending on
who the receipient is.

One particular E-mail I need to be in html format so I can put it into a
specific format.  I added a couple of lines to the sendmail routine I was
using and it fixed my E-mail problem but created a problem with my fax
gateway copy.

#1 gets sent the Joe Enduser plain E-mail(Can be html my tweek forced html)
#2 gets sent to the Office HTML Format.
#3 Fax gateway (Plain E-mail).

Fax gateway is in the US Telephone format ie.  [EMAIL PROTECTED]

I thought about adding an if statment but it looks like if I added an
if/else to my tweeked else statement the receipient info has already been
sent

Greg :-)



Best suggestion would be to switch to using a module. MIME::Lite for 
instance but there a lot that will work. Check CPAN. Mail while it seems 
simple is incredibly complex, re-inventing the wheel, especially with 
such strict requirements is going to be time consuming.


http://danconia.org



file: sendmail.pl
snip
# Give the server the message header

print SMTP DATA$CRLF;
sysread(SMTP, $_, 1024);
if (!/[^0-9]*354/) { $Error_Message = $_; return(6) }
print SMTP To: @to$CRLF;
print SMTP From: $from$CRLF;
print SMTP CC: @cc$CRLF if $cc;
print SMTP Subject: $subject$CRLF;

# If there are mime files to attach, we need special headers.

if ($mime_id) {
print SMTP x-sender: $from$CRLF;
print SMTP x-mailer: CGI/Perl Cookbook$CRLF;
print SMTP Mime-Version: 1.0$CRLF;
print SMTP Content-Type: multipart/mixed;
boundary=\$mime_id\$CRLF$CRLF;
print SMTP --$mime_id$CRLF;
print SMTP Content-Type: text/plain;
charset=\US-ASCII\$CRLF$CRLF;
}
# Greg @ Limo.Net 01/24/2007
# Added two header lines for force HTML output.
# else { print SMTP $CRLF }
#
else {
print SMTP Mime-Version: 1.0$CRLF;
print SMTP Content-Type: text/html;
charset=\ISO-8859-1\$CRLF$CRLF;
}
# End Greg @ Limo.Net 01/24/2007

# Output the message body.

if ($body) {
if (!($body =~ /^[\\\/:]/)  ($body =~ /\s/)) { print SMTP $body }
elsif (-e $body  -T $body) { parse_template($body, *SMTP) }
}
print SMTP $CRLF;

# Attach each file.

for ($i = 0; $i  @ATTACH_FILES; ++$i) {
$attach_file = $ATTACH_FILES[$i];
$encoding = $ENCODING[$i];

# Split the filename by directories.  / for unix, \ for dos, : for
mac
/snip


Scanned for Virus by http://Barracuda.Limo.Net




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: -e question

2006-12-15 Thread Wiggins d'Anconia

Lou Hernsen wrote:

I use the -e to check to see if a file is present

  if (-e $Pics/$Game{Page}.jpg)
  {
   }

Question
I can get it to work looking for .pl and .gif but not .jpg

I have checked all the directorie vars and even did this

  print qq|img border=0 src=$Pics/Camera.gif width=$Game{CameraW}
height=$Game{CameraH}BR|;
  print qq|BR|;
  print qq|a target=$Game{Page} href=$Pics/$Game{Page}.jpg|;
  print qq|img border=0 src=$Pics/Camera.gif width=$Game{CameraW}
height=$Game{CameraH}BR|;
  print qq|/a|;
  print qq|BR|;
  if (-e $Pics/$Game{Page}.jpg)
  {
  print qq|img border=0 src=$Pics/Camera.gif width=$Game{CameraW}


In the above line do you mean to have '.jpg'?


height=$Game{CameraH}BR|;
   }

I get the first two images but not the last one.. so I know i have the dirs
correct
are .jpg's not -e able???



-e cares not and knows not of the type of file.


yeah.. i'm nonprofessional hobbiest  my style suck... can someone answer
the question, please?


Helps?

http://danconia.org


Lou




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: trouble with meta http-equiv

2006-11-30 Thread Wiggins d'Anconia

David Bear wrote:

I'm trying to put a client side redirect with http-equiv refresh. I'm using
the syntax:

my $req  = CGI-new();

print $req-header( text/html );
print $req-start_html( -head=meta({-http-equiv = 'refresh', 


In the above line the call to meta() is a function call, but you have 
started out with the object syntax. So you likely haven't imported any 
of the function lists, so you either need to import the correct list, or 
switch to the object syntax,


$req-meta(...)


-content = '1;URL=' . $req-refere()}));



Note you probably need $req-referer in the above line...

HTH,

http://danconia.org


but I get an error:
Undefined subroutine %main::meta called 


This seems to be what is documented on cpan. I must be missing something
simple. Any ideas?


--
David Bear
College of Public Programs at Arizona State University




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Taking Multiple Values for The Same Form Field.

2005-10-29 Thread Wiggins d'Anconia

Bob O'Neill wrote:

Use list context:

  my @names = $q-param('name');

Cheers,
Ovid



I've found this thread very helpful, and have changed it to use Vars (from  
http://users.easystreet.com/ovid/cgi_course/) as I need a hash.  This has 
replaced the following:


foreach $entry (param()) {
$fieldhash{$entry}=param($entry);

Checkentry(param($entry));
}

with:

my $q=new CGI;
my %fieldhash=$q-Vars;

which is much neater.  My subroutine Checkentry untaints the input.  Is 
there an easier way which will allow the hash values created by Vars to be 
passed to my subroutine without stepping through a foreach loop? 



If I understand correctly then you want a hash reference to pass the 
whole hash around at once.


perldoc CGI

Should help, CVars understands its context, so calling it in scalar 
context will result in it returning a hashref instead of a hash.


my $params_ref = $q-Vars;

http://danconia.org



Bob





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: hardcoded paths

2005-10-28 Thread Wiggins d'Anconia
Dermot Paikkos wrote:
 Hi,
 
 I am moving a site from once host to another. There are lots of 
 hardcoded fully qualified paths to the localhost (EG 
 http://myserver/cgi-bin/someprog.pl?name=val  
 http://myserver/css/mystyle.css).
 
 I am pretty sure this isn't good practise but I am not a bit lost as 
 to what are good alternatives. I don't want to make the same mistake 
 and have to do all this editing again next time the hardware changes.
 
 Should I be trying to create a module with these paths in? Or is 
 there some other way?
 Thanx.
 Dp.
 
 

Relative URLs as David mentioned would be good whereever they can be
used. The other option I use is to create a Setup.pm module that
contains constants for these things.

use constant CONFIG_URL_BASE = 'http://yoursite.com';
use constant CONFIG_URL_CGI_BASE = 'http://yoursite.com/cgi-bin';

Then you need to export those constants into the calling code. The only
bummer about using constants is that they don't interpolate inside
strings, but I have settled on using concatenation and prefer to have
the extra overhead to have the ease of changing all URLs on a site at once.

This also makes module code that generates links reusable across sites.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: CGI Upload() for nonexistent files?

2005-10-28 Thread Wiggins d'Anconia
Joby Jones wrote:
 Hello all,
   I have a question about the CGI upload()
 function.
 
   Why does it return a valid file handle to a file
 that does not exist on the client (web browser)
 machine, and what's the best way to handle this?
 

Presumably because this is really a client side error. It is not an
error to upload a zero length file, a file could need to be created but
empty, and you could want to have a program do that. So it is not
unreasonable to think that a file upload could be empty, which means CGI
has to handle the case where a file is uploaded but empty.  Chances are
good the browser is creating the proper HTTP request despite the local
file not existing, but to me that is a browser fault.  CGI just sees the
header that says there is a file coming, then no data so it creates the
file, puts nothing in it, and happily crunches along.

 
 Details:
 
 
 1. A user enters a nonexistent file name in an upload
 field in a form handled by my cgi script. (E.g. on
 windows c:\uplaodthis.txt -- note typo). 

 2. My cgi script does something like this:
 
 my $q = new CGI;
 if(defined($q-param('Upload'))){
 my $upload_file_handle = 
$q-upload('upload_file');
 if(defined($upload_file_handle)){
print Valid file handle to empty file is:\n .
 
   Dumper($upload_file);
 }
 }
 
 
 3. It outputs: 
 Valid file handle ... 
  $VAR1 = bless( \*{FH::uplaodthis.txt ...}, 'Fh' );
 
 
 
 What to do?
 ---
 
 Currently, I write out all valid file handles (checked
 for basic security problems as described in perlsec). 
 If the file is zero length, I delete it and report an
 error.  Which just isn't very satisfying.
 

Why is it not satisfying? It is a requirement of yours that the file not
be empty NOT the CGI world at large, so this is an error you should be
handling. Sounds like you are doing a fine job.

 What am I missing?
 Is there a better way?

Doubtful. You could write a web server module to handle the case at the
front end of the request but the only thing that really saves is a
little processing time, you still have a server side error to throw.

 
 
 
 All advice and documentation pointers (beyond 'CGI'
 :-) appreciated.


I say move on and work on bigger problems. Faulty user input, is well
the fault of the user. Let them deal with the consequences of having to
resubmit the form, assuming your error message is clear.

http://danconia.org


 Thanks,
 joby
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: $CGI::DISABLE_UPLOADS

2005-10-18 Thread Wiggins d'Anconia
Bill Stephenson wrote:
 I've been testing the $CGI::DISABLE_UPLOADS and $CGI::POST_MAX
 variables and I don't think I've got it feature working as it should.
 The docs say this:
 
 CGI.pm also has some simple built-in protections against denial of
 service attacks, but you must activate them before you can use them.
 
 snip
 
 $CGI::POST_MAX
 If set to a non-negative integer, this variable puts a ceiling on
 the size of POSTings, in bytes. If CGI.pm detects a POST that is
 greater than the ceiling, it will immediately exit with an error
 message.
 
 It seems to me that my script will not exit until uploading the entire
 POST has been completed. So, here are my questions about this:


Right, but the script exits immediately. I *suspect* the complete
request must be sent to the web server regardless of whether the script
is going to fail. Exiting immediately just means that CGI will not allow
execution of anything beyond its initial preparations, rather than
meaning it will truncate the request.

At least that would be my interpretation... But I didn't have a look at
the modules source, you might want to check there for confirmation.

http://danconia.org


 Do I misunderstand the above? (ie. the script should upload the entire
 POST before exiting with an error)
 
 Is there something wrong with my test script (I suspect this must be the
 case, please see it below)
 
 Or... is there something wrong with CGI.pm? (this seems to be a longshot)
 
 I'd really appreciate any help you all can give me with this.
 
 Kindest Regards,
 
 -- 
 Bill Stephenson
 
 
 code
 
 #!/usr/bin/perl
 
 # deny_upload.cgi
 
 use CGI;
 use File::Basename;
 use strict;
 
 $CGI::POST_MAX=1024 * 5;  # max 100K posts
 $CGI::DISABLE_UPLOADS = 1;  # no uploads
 
 my $Q = new CGI;
 my $message;
 
 # trap error with this...
 if (!$Q-param('file')  $Q-cgi_error()) {
 $message = $Q-cgi_error();
 error_trap( $message);
 }
 
 # or this...
 # if ($Q-cgi_error()) {
 # $message = $Q-cgi_error();
 # error_trap( $message);
 # }
 
 if (!$Q-param) {
 print $Q-header;
 print qq ~!DOCTYPE HTML PUBLIC -//W3C//DTD HTML 4.01
 Transitional//EN
 http://www.w3.org/TR/html4/loose.dtd;
 html
 head
 titleUpload Test/title
 /head
 body
 form id=upload_logo_form method=post
 action=/cgi-bin/test/deny_upload.cgi enctype=multipart/form-data
 input type=file name=file size=30
 ptextarea name=text rows=4 cols=40put too much text in
 here/textarea/p
 input type=submit name=upload value=Upload Stuff
 /form
 /body
 /html~;
 exit 0;
 }
 
 # get on to uploading the file...
 
 if ($Q-param('file')) {
 my $data;
 my $filePath;
 my $file = $Q-param('file');
 
 fileparse_set_fstype(MSDOS);
 $file = basename($file);
 $filePath = /test/$file;
 
 open (SAVE,$filePath) or error_trap($message=  Error:: $! ::
 Can Not Upload $file: \n);
 while (read($Q-param('file'),$data,1024)) {print SAVE $data;}
 close SAVE;
 
 print $Q-header;
 print $Q-start_html(-title = Uploaded it anyway);
 print Uploaded it anyway;
 print $Q-end_html;
 exit 0;
 }
 
 if ($Q-param('test')) {
 print $Q-header;
 print $Q-start_html(-title = Lotsa Text);
 print $Q-param('test');
 print $Q-end_html;
 exit 0;
 }
 
 sub error_trap  {
 print $Q-header;
 print  $Q-start_html(-title = MyApp Error Screen);
 print $message;
 print  $Q-end_html;
 exit 0;
 }
 
 /code
 
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Query on sendmail problem

2005-10-05 Thread Wiggins d'Anconia
Dale wrote:
 Hi,
 
 I'm hoping someone can help me with an issue I've got with, I assume,
 sendmail.
 
 I've copied part of a script below.  If I use the first To: line (which
 takes the e-mail address from a file - and this works) then a mail
 doesn't arrive.  If, however, I used the second To: line (which is
 currently commented out - the xx is to stop spammers picking the
 address up from this mail) then a mail is received.
 
 I added a page after the sendmail just to make sure it was reading the
 e-mail address from the file (which it was) but it still doesn't seem to
 send. $manageremail is the correct variable name.
 
 In the datafile, I've had the e-mail addresses formatted properly (e.g.
 [EMAIL PROTECTED]) but also tried with \'s at appropriate places (e.g.
 [EMAIL PROTECTED]).  I just can't get anything to work.
 
 Anyone have any ideas what I could be doing wrong.


You're not using a module... Don't think that is what you meant though.

 Thanks in advance!
 
 -
 -
   open(MAIL, |/usr/local/bin/sendmail -t);
 
 print MAIL To: $manageremail\n;

Are you chomp'ing $manageremail?  If it has a newline on it in the file
and you have added an additional new line above then you have stopped
the header, surprisingly it should still be sending but below should be
in the body. You should probably have a look at the mail logs generated
by sendmail to see if it is complaining, and more specifically about what.

http://danconia.org

 #   print MAIL To: [EMAIL PROTECTED];
 print MAIL From: [EMAIL PROTECTED];
 print MAIL Subject: Escalation logged\n;
 
 print MAIL Hi $manager\.\n\n;
 print MAIL The following escalation has been logged from your
 team.\n\n;
 print MAIL Agent's Manager   : $manager\n;
 print MAIL Agent's Name  : $agentname\n;
 print MAIL Date Logged   : $day\-$month\-$year\n;
 print MAIL Escalation Reason : $reason\n;
 print MAIL Short Description : $short\n;
 print MAIL Long  Description : $long\n;
 print MAIL Justified?: $justified\n;
 print MAIL Name of Logger: $logger\n;
 
   close (MAIL);
 -
 -
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: html file with form and onSubmit=return check_form(this)

2005-09-23 Thread Wiggins d'Anconia
Edgardo Lust wrote:
 Hi.
 
 I have a html file (created with Dreamweaver) with one form and submit
 button with 
 
 form method=POST action=/cgi-bin/contact.pl onSubmit=return
 check_form(this)
   input type=hidden name=success
 value=/contacto/message.htm
input type=hidden name=required-to
 value=[EMAIL PROTECTED]
 input type=hidden name=subject value=-- NEW
 CONTACT --
 
 I need my perl script to return a valid value then the user can see
 message.htm page
 
 
 How can I do?
 
 Thanks
 
 Edgardo
 
 

What do you mean by return a valid value? You can either redirect to
message.htm or read it in and return the contents.

As a side note the above is basically an open relay, depending on your
other form fields a specially crafted message can probably be used to
send an e-mail to anyone.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Forcing a save as' dialogue box to come up on left click

2005-09-19 Thread Wiggins d'Anconia
Tony Frasketi wrote:
 Wiggins d'Anconia wrote:
 
 Most browsers will provide this functionality if the return header is
 application/octet-stream rather than text/html or the like.  In
 the case of IE you may have to fool the browser into thinking it is
 getting something different than it is based on the URL, because it 
 likes to look there for a file extension to determine the file type too.
 HTH,
 http://danconia.org

 Hi Wiggins
 Thanks... I just tried putting these three lines in a .htaccess file in
 a particular directory...
 
   AddType application/octet-stream .cgi
   AddType application/octet-stream .txt
   AddType application/octet-stream .htm
 
 Alternatively, I also triedAddType application/octet-stream .cgi
 .txt .htm


Interesting way to do it, not what I intended. Have you 100% confirmed
that the header is being passed back correctly? I am not sure how Apache
(or whatever web server you are using) handles setting the type, it
might be finding it from somewhere else that is overriding it. There is
a module for Firefox/Mozilla called Live HTTP Headers that will help
you confirm what is being sent.

What I was intending was to call the cgi script and rather than it
printing the normal text/html header it would print the header directly,
that way you are guaranteed to be operating the way you intended.

 Using the Mozilla 5.0 Suite browser, I get the following results
 
 And then trried clicked on links to a .cgi file, a .txt file, and a .htm
 file in that directory Only  the .htm file automaticaly brought up a
 'Save as...' diaglogue box as I left clicked on the link to the .htm file
 
 when I clicked on the link to the .txt file, the contents of the .txt
 file appeared in a Wordpad window.

This is windows picking up the association based on the extension
(probably), didn't you know it was smarter than you? ;-)

 
 When I clicked on the link to the .cgi file, the .cgi file was executed
 and the results displayed in the browser window.
 
 One out of three right!
 
 
 Using the Microsoft IE 6.0 browser, I get the following results
 
 .htm file - Displays the .htm file in browser window
 .txt file -  Displays the .txt file in browser window
 .cgi file - Executes the .cgi script and displays results in browser
 window
 
 zero out of three right!

Yeh I suspect that is IE picking up on the URL extension.

 
 
 Using Firefox 1.0 browser, I get the following results...
 .htm file - brings up the 'Save as...' dialogue box
 .txt file - brings up the 'Save as...' dialogue box
 .cgi file - Executes the .cgi script and displays results in browser
 window


The .cgi problem is probably because you have a handler setup for .cgi
files that trumps the AddType call. What is the header printed by the
.cgi file? It should be able to print its own header of
application/octet-stream followed by the contents of a file and it
should work correctly.

 SO... Filefox wins by getting two out of the three
 right!
 
 This method doesn't look very hopeful at this point!

I know I have used this method before, and I have done so recently from
within the context of a different web framework (specifically Interchange).

As to your question about Content-Disposition it can be used to preset
the filename that the user sees in the Save as... dialogue, but is
again not standard, it is just convention and will depend on the browser
supporting it, to my knowledge the major browsers[1] do support it.

 Thanks again
 Tony Frasketi

Keep at it, I suspect you will get it to work...

http://danconia.org

[1] When I say major browsers I mean Mozilla (and variants, Firefox,
etc.), IE (some recent version, probably newer than 4.x), Safari. I know
there are others but I don't have a copy so can't say specifically how
they act, they may work as well.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Forcing a save as' dialogue box to come up on left click

2005-09-19 Thread Wiggins d'Anconia
Tony Frasketi wrote:
 
 What I was intending was to call the cgi script and rather than it
 printing the normal text/html header it would print the header directly,
 that way you are guaranteed to be operating the way you intended.
 
 Hi Wiggins
 Thanks for this suggestion... I've tried the following bit of CGI script
 with three different file types (.txt, .cgi, .dat) and in each case *DO*
 get the 'Save as...' dialogue box to come up and when I select 'Save to
 disk' and click ok, It appears as if a transfer occurs but only a
 zero-length file is saved to my local hard disk directory.  The code is
 as follows...

Ok, so almost there let's back up a step and understand the whole
thing. The HTTProtocol is very similar to other common net protocols
where there is a header section and a data (or payload) section. The two
are separated by a blank line. So right now you are providing the header
(apparently correctly). The client reads that information and based on
what it knows how to handle it decides on a way to use the payload. In
this case we are giving the browser less than optimal descriptors of the
payload. Basically we are telling it that there is something coming and
that neither I nor you know what it is. So it does the only thing it
can, Save as The only hint you are providing it a suggestion about
what to call that thing. So right now you are providing a header, but
not a payload, let's add it

 
 
 #!/usr/local/bin/perl -w
 
 # testoctetstream_1.cgi
 
 # My base directory and base directory URL
 my($basedir) = base directory;
 my($baseurl) = base URL;
 
 # Location of the file to be downloaded
 $fileloc = $basedir/cgi-bin/test/xxx.txt;
 #$fileloc = $basedir/cgi-bin/test/testdu1.cgi;
 #$fileloc = $baseurl/cgi-bin/test/testdu.dat;
 
 # Name of file to be downloaded
 $filename = xxx.txt;
 #$filename = testdu1.cgi;
 #$filename = testdu.dat;
 
 # NOTE: Uncomment the desired $filename and $fileloc above
 
 # Set The headers
 print Content-Type: application/octet-stream;\n;
 print Content-Disposition: attachment; filename=\$filename\\n;
 
 # ---
 # Note: Can't figure out what to put in here to actually download
 # the darn file!!!
 # ---
 

This is the simple part, and probably looks a little like.

open file...
read in file...
print file back to browser...
close file

There are simpler ways to do this, but what I have come to use looks like:

my $READHANDLE;
unless (open $READHANDLE, $file) {
# error handling...
}
binmode $READHANDLE;

$| = 1;

while ( my $length = sysread $READHANDLE, my $buffer, $block_size ) {
next unless defined $length;

my $offset = 0;
while ( $length ) {
my $written  = syswrite STDOUT, $buffer, $length, $offset;
$length -= $written;
$offset += $written;
}
}

close $READHANDLE;

 print \n;

You will want to remove this as it will be an addition to the actual
data which can break some formats.

 exit;
 
 
 The above cod was tested in both Mozilla and IE browers with the same
 results.
 
 
 It appears I'm missing some statement that should follow the
 Content-Disposition
 statement.
 

Does this hit the mark?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Forcing a save as' dialogue box to come up on left click

2005-09-18 Thread Wiggins d'Anconia

Tony Frasketi wrote:

Hello Listers
I'm trying to find a way to force a download dialogue box to come up 
when the user clicks on a link on a web page (the link will primarily be 
for htm, .txt files on the server).  Normally when the user left clikcs 
on the link the .htm or .txt file appears in the browser. And also 
normally when the user right clicks on the link, he is given the choice 
to 'Save Link Target as' in order to download the file.


What I'm looking for is to avoid right clicking and choosing to save the 
file  Is there a way to implement left clicking the link and 
automatically bringing up a Save As dialogue box?


I've googled for such things as mime type download save as etc but 
came up with dead ends


TIA
Tony Frasketi



Most browsers will provide this functionality if the return header is 
application/octet-stream rather than text/html or the like.  In the 
case of IE you may have to fool the browser into thinking it is getting 
something different than it is based on the URL, because it  likes to 
look there for a file extension to determine the file type too.


HTH,

http://danconia.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: problems with CGI.pm upload feature

2005-09-17 Thread Wiggins d'Anconia
Bill Stephenson wrote:
 On Sep 16, 2005, at 7:51 PM, Scott R. Godin wrote:
 
 Wiggins d'Anconia wrote:

 Scott R. Godin wrote:

 script is at http://phpfi.com/78748

 I followed the instructions in CGI.pm as best I could, and from what I
 read the upload() function is supposed to return a filehandle ? (it
 doesn't say whether this is a direct FH to the tempfile or not)

 I had dome some preliminary testing with one-liners and was pretty sure
 this would work, but what I wind up with in the attachment is a file
 containing the name of the file, not its actual contents.

 what did I do wrong? I can't figure it out. :/
 
 
 Possibly used the wrong web browser to upload the file. Not all of them
 support this feature. Firefox does not. It will however provide the CGI
 script with the file name.
 
 Kindest Regards,
 
 -- 
 Bill Stephenson
 
 

Firefox doesn't support file uploads?  I use it all the time to test
scripts that accept uploads.

Huh?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: problems with CGI.pm upload feature

2005-09-16 Thread Wiggins d'Anconia
Scott R. Godin wrote:
 script is at http://phpfi.com/78748
 
 I followed the instructions in CGI.pm as best I could, and from what I
 read the upload() function is supposed to return a filehandle ? (it
 doesn't say whether this is a direct FH to the tempfile or not)
 
 I had dome some preliminary testing with one-liners and was pretty sure
 this would work, but what I wind up with in the attachment is a file
 containing the name of the file, not its actual contents.
 
 what did I do wrong? I can't figure it out. :/
 

Just because it is easy to overlook and fairly common, did you include
the 'enctype' in the form tag?  For instance,

[form enctype=multipart/form-data action=/cgi-bin/request method=POST]

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: File Modification Date

2005-09-14 Thread Wiggins d'Anconia
Vance M. Allen wrote:
 I'm trying to find out how to determine the date and/or time that a file was 
 created in a simple procedure.  I have heard about a few different libraries 
 but the examples I have found haven't been very useful.
 
 The basic purpose I want to do is a simple footer provided by a package 
 module through CGI to inform users of the latest update to the code based on 
 the URL.  Something simple saying Version x.xx, Last Modified MM/DD/. 
 which would automatically get the file modified timestamp.
 
 I'd prefer to have, if possible, a simple scalar variable to store the 
 date...for example:
 
 $modtime = filemoddate_func(filename.cgi);
 
 If anyone can help me with the libraries I need to use for this (if any 
 special), and a code snippet if possible, I'd really appreciate it.
 
 Thanks!
 
 Vance
 
 
 

Generally this type of information is provided by Cstat, see,

perldoc -f stat

For the details.

To get the modification time for example you could use something like,

my $mod_time = (stat 'filename.cgi')[9];

File creation time is rarely if ever available. Obviously you could wrap
the above in a sub, but I suspect there isn't a lot of reason to since
it is so short anyways.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Exact matching using GREP.

2005-09-08 Thread Wiggins d'Anconia
Please bottom post

Sara wrote:
 No, it's not working, probably you didnt' get my question.

How is it not working now?  What Ovid sent is exactly what I would have
answered so you probably need to provide more information. You mention
man pages and switches to grep, there are two greps here, 1) the command
line program used for searching files which is where your -x, etc. come
in and 2) 'grep' the function which is a Perl built-in. For the docs for
it, you need to check:

perldoc -f grep

They are very different things.

http://danconia.org

 
 Anyways, thanks for a prompt reply.
 
 Sara.
 
 - Original Message - From: Ovid
 [EMAIL PROTECTED]
 To: beginners-cgi@perl.org
 Sent: Friday, September 09, 2005 12:01 AM
 Subject: Re: Exact matching using GREP.
 
 
 --- Sara [EMAIL PROTECTED] wrote:

 while (my $row = $sth-fetchrow_hashref)
 {
   if (grep /$row-{CAT_TITLE}/, @present) {
   #matching title with @present elements
   print $row-{CAT_TITLE};
 }

 Question is how to do EXACT matching using GREP? because the above
 code prints every element from array for 'php' if the
 $row-{CAT_TITLE} is 'php' it prints php/counters, php/forums and
 every element containing php.


 Assuming I understood your question correctly:

  if (grep { $_ eq $row-{CAT_TITLE} } @present) {
# do something
  }

 Cheers,
 Ovid

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Force a file download for link

2005-08-30 Thread Wiggins d'Anconia
Denzil Kruse wrote:
 
 --- Bob Showalter [EMAIL PROTECTED]
 wrote:
 
 snip
 
   use CGI qw(:standard);

   open FILE, ...blah blah...
   print header('application/octet-stream');
   print while FILE;

 
 
 Thanks for the help Bob! Is there another way besides
 the content-disposition to specify an attachment or
 filename?  I was trying to find a way to get a file
 download box to come up to ask where to save the file
 on their local computer.  With just the above, it will
 display it in the browser, and my users will just
 go...huh?
 
 Denzil

The 'header' function can take a key/value list of arguments to include
additional header lines. So you can pass your content-disposition header
as you had it before. The key here is that the content type be set to
'application/octet-stream' and that the disposition header will only
work if the client understands it, but in most cases it is worth a shot.

In one my libraries I use,

my %header_options = ( -Content_Type   = 'application/octet-stream',
   -Content_Length = $content_length,
 );

if (defined $self-{'filename'} and $self-{'filename'} ne '') {
$header_options{-Content_Disposition} = attachment;
filename=\$self-{'filename'}\;
}

It seems to have worked for me. Obviously you need to replace
$self-{'filename'} with your variable, and preferably set
$content_length with the file size.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: $ENV{'HTTP_REFERER'}

2005-08-24 Thread Wiggins d'Anconia
Denzil Kruse wrote:
 Hi,
 
 I want to know the web site that someone came from,
 and so I was planning on reading $ENV{'HTTP_REFERER'}
 to figure it out.  How reliable is that?  Do browsers
 or other situations block it or obfuscate it?  Is
 there another way to do it or any other issues
 involved?  I'm using apache on red hat.
 
 Thanks,
 Denzil
 

Depends on your definition of reliable. From experience it would seem
most browsers set it pretty reliably.

Having said that, it is just a value passed as part of the HTTP request
so anyone can spoof it at anytime, so relying on it from a security
stand point, well, isn't secure.

I imagine if you are doing something where someone can benefit from
obfuscating it, they will.  If you want to use it for ease of UI
handling (aka redirects, prepopulating fields, marketing metrics) I
think you are safe.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regex Problem.

2005-08-18 Thread Wiggins d'Anconia
Sara wrote:
 I am at a loss here to generate REGEX for my problem.
 
 I have an input query coming to my cgi script, containg a word (with or 
 without spaces e.g. blood Globin Test etc).
 What I am trying to do is to split this word (maximum of 3 characters) and 
 find the BEST possible matching words within mySQL database. For example if 
 the word is blood
 
 I want to get results using regex: 
 
 for blood: check(blo) then check(loo)  check(ood)
 for Globin Test: check(Glo) then check(lob)  check(obi) check(bin) 
 check(Tes) check(est)
 
 TIA.


Sounds like you need a split then a substr rather than a regex,
though I suppose it would work if you really wanted one, I wouldn't.

perldoc -f split
perldoc -f substr

It will also be faster to combine everything into one select rather than
for each possible token, but at the least if you are going to do
multiple selects use 'prepare' with placeholders and only prepare the
query once.

So,

-- UNTESTED --

my @tokens = split ' ', $entry;
my @words;
foreach my $token (@tokens) {
  push @words, substr $token, 0, 3;
  push @words, substr $token, -3, 3;
}

(or you can put the following into the above foreach however you would like)

my $where = '';
my @bind;
foreach my $word (@words) {
  $where .= ' OR ' if $where ne '';
  $where .= (def LIKE ?);
  push @bind, %$word%;
}

my $sth = $dbh-prepare(SELECT * FROM medical WHERE $where);
$sth-execute(@bind);

while (my @row = $sth-fetchrow_array) {
  print join ' ', @row;
  print \n;
}

This also prevents SQL injection by quoting the query words properly.

 Sara.


http://danconia.org

 sub check {
 my $check = $dbh - prepare(SELECT * FROM medical WHERE def LIKE '%$query%' 
 );
 $check-execute();
 while (my @row = $check - fetchrow_array()) {
 print blah blah blah\n;
 }
 }
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Clearing cookies

2005-08-16 Thread Wiggins d'Anconia
Denzil Kruse wrote:
 Hi all,
 
 I'm trying to clear a cookie using CGI::Cookies, and
 can't seem to do it :(
 
 if ($clear_cookie eq 'yes') {
 
  my %cookies = fetch CGI::Cookie;
 
  print getting cookiebr;
 
  if ($cookies{'id'}) {
 
   print clearing cookiebr;
   $cookies{'id'}-expires('-1s');
   print cleared cookiebr;
  }
 }
 
 I'm getting the cleard cookie message, but it is
 still there.
 
 Denzil
 

To clear the cookie in the user's client (browser) you have to set the
cookie again by printing it in the response headers. You are only
setting the local expiration, to have that maintained across the rest of
the session you have to tell the browser about it, which is done by
passing it back as if you were setting it initially.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Insecure setuid?

2005-08-09 Thread Wiggins d'Anconia
Tantalo, Christopher G wrote:
 Can anyone shed some light on what this error means?
   Insecure $ENV{PATH} while running setuid at
 /var/appl/sls/bin/driver.pl line 1104.
 Line 1104 is
 print `date`;
 

You shouldn't shell out to date anyways, especially in the above manner
with no error checking, etc. Perl has builtin functions for collecting
date information.

 If I comment this out, then the following error message appears:
   Insecure dependency in open while running setuid at
 /var/appl/sls/bin/driver.pl line 1249.
 Line 1249 is
 my $err_file = $ENV{SLS_LOG_PATH} . /drivererror . $rt_id ..
 .err;
 actually 1249 ---  open(ERR_FILE,$err_file) ||die cannot open
 $err_file for reading:$!;
 
 Not sure what insecure warnings mean in terms of setuid.  Any answer
 would be much appreciated.
 Thanks
 Chris

Because you are running setuid the taint mechanism is on. See,

perldoc perlsec

For more info. Whenever you have an error/warning you don't understand
that was thrown by Perl you can find more info in:

perldoc perldiag

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How do I make two different web pages come up from one CGI?

2005-08-04 Thread Wiggins d'Anconia
David Dorward wrote:
 On Wed, Aug 03, 2005 at 10:45:35PM -0700, Luinrandir wrote:
 
I want to create two web pages in two different windows
from one CGI.
 
 
 Each request gives one file, that's how HTTP works. You will need at
 least two requests, with the script running twice (or two scripts
 running once each).
 
 You can use JavaScript to spawn a second window, although it might be
 blocked by popup blockers (the specifics of such a solution are rather
 off topic for this list though, so I'll suggest you look elsewhere if
 you want to go down that path).
 

Just to be thorough, not specifically because I like them, I will
mention frames. Frames are an easy way to give the appearance of two
requests (because there are actually three) without many client side
limitations. Most *graphical* browsers support frames these days.

And though I don't yet have experience with it I suppose you could look
into Ajax.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Problem with https post using LWP

2005-08-01 Thread Wiggins d'Anconia
Denzil Kruse wrote:
 Hi all,
 
 I'm trying send an https post:
 
 my $url = https://some.secure.server/secure.dll;;
 
 my $ua = LWP::UserAgent-new;
 
 # assemble the request
 #
 my $request = HTTP::Request-new(POST = $url);
 $request-content_type('application/x-www-form-urlencoded');
 $request-content($content);
 
 # send the request and get the result
 #
 my $result = $ua-request($request);
 
 print $result-as_string;
 
 But I'm getting this error:
 
 501 (Not Implemented) Protocol scheme 'https' is not
 supported
 
 Looking on cpan, it looks like you do an https post
 the same way as a http post, but I must be missing
 something.
 
 Can anyone help?
 
 Thanks,
 Denzil
 

Have you read:

http://search.cpan.org/src/GAAS/libwww-perl-5.803/README.SSL

And do you have an appropriate SSL interface installed?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: SetEnv Variable from Apache

2005-07-20 Thread Wiggins d'Anconia
Robert wrote:
 How do I use a variable that is set with 'SetEnv' in the Apache config file?
 
 Robert
 
 
 

Have you checked the %ENV hash?

print $ENV{'VAR_NAME'};

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: MIME::Lite attachments

2005-07-17 Thread Wiggins d'Anconia
Mike Blezien wrote:
 Hello,
 
 we're setting up a script to attach mainly PDF files. And was wondering
 when setting up the code to attach the file, what TYPE attribute is used:
 
 snip
 $msg-attach(Type ='', # WHAT TYPE HERE TO USE ??
  Path ='/path/to/somefile.pdf',
  Filename ='Document.pdf',
  Disposition = 'attachment'
  );
 /snip
 
 is the specific what to code MIME Lite to send a TEXT/HTML message with
 a PDF file attached ??
 
 TIA

I'm assuming you want the MIME/Type,  application/pdf.

Not sure what this has to do with CGI though.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: quote problem and mysql

2005-07-15 Thread Wiggins d'Anconia
Bob Showalter wrote:
 Andrew Kennard wrote:
 

[snip]

 
 No, you shouldn't have to do that. Your first approach is correct, so we
 need to find out what's going wrong there...
 

Can you show us GenMainRecData?  Are you sure it isn't the culprit here,
possibly it is already doing data munging that it shouldn't.

As a side note generally you should leave the '' off the call to the
subroutine, no need for it anymore, unless you know specifically why to
include it.

my @TheRecord = GenMainRecData();

Should do.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need a perl module

2005-06-07 Thread Wiggins d'Anconia
Tantalo, Christopher G wrote:
  I use Mail::Box::Manager 2.00.  Works pretty well for me.
 
 +1

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Perl Newbee

2005-06-03 Thread Wiggins d'Anconia
Yuga Chodagam wrote:
 Hi all,
   I am newbee to Perl. Could anybody please give me head start
 with Perl programming? I am interested in playing with some CGI stuff
 and want to sese the Perl's data manipulation power.
 
 
 Thanks all. I appreciate any help.
 
 Yuga.
 

Though he lurks here I doubt he would plug it himself, so I will suggest
that several people have been pleased with Ovid's CGI Course:

http://users.easystreet.com/ovid/cgi_course/

By the time I found it/he wrote it, I was already fairly experienced so
can't say I started with it. Of course when I started I wished it had
already been written.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Help wanted

2005-05-31 Thread Wiggins d'Anconia
Yuanxin wrote:
 Hi,
 I had a lot of data, which are all x-y values. I stored these data in MySQL 
 database. Now I wanna use Perl to get these data from database to build a 
 figure(2-dimensional) and people can use internet to see the figure. In 
 addition, when people see the figure via internet, the x-y value of a point 
 need be shown when mouse is dragged on one point of the figure. In my system, 
 I already install Perl, Perl::DBD::Mysql, CGI, Perl:DBI. So I just wanna know 
 any other Perl:Module should be installed for my case. Thank you very much!
 
 Terence
 

Doing the mouse over part may prove difficult, it is client side. You
might want to look into the GD::Graph module to help you with generating
the figures.  There are other modules available to do graphing with as well.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Undefined subroutine Error

2005-05-09 Thread Wiggins d'Anconia
Mike Blezien wrote:
 Hello,
 
 occasionally we get this error, due to a mis coding error or type-O
 error, but was wondering is there away to check, with a perl code, to
 make sure the sub routine exists before displaying this system 500
 internal error message. the error I'm referring too is this:
 
 Undefined subroutine main::some_routine_name called at script_name line
 XXX
 
 TIA

If they are miscodings then not really, mostly because Perl allows you
to choose subroutines/methods at runtime. So the interpreter can't know
a pri ori what subs need to exist. If you need to check for a sub to see
whether or not you should be calling it, for instance to see if an
object has a particular method you can use the UNIVERSAL::can function,
see perldoc UNIVERSAL for more info.

Of couse having said all that, aren't you testing ;-) 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Alternative Modules

2005-04-27 Thread Wiggins d'Anconia
Mike Blezien wrote:
 Hello,
 
 we are currently using the Mail::Audit module to resend piped incoming
 emails to a particular domain then sends it to various aliases emails
 from a database. I'm trying locate a similar module but doesn't put alot
 of the header garbage into the body of the email. Then Mail::Audit
 doesn't really remove certain headers from the actual body of the email.
 
 Is there a module that works similar as the Mail::Audit, but extracts
 the actual body content of the email without some of the headers
 included in it??
 
 TIA

This is a rather confusing description of what you are doing, if you can
 clean it up a bit we might be able to give you a better solution.

Although it has a very steep learning curve, there isn't a lot that the
Mail::Box suite can't do.  If I wanted to do anything remotely complex
with mail (and I have) I would use it hands down.  It has incredible
documentation, though that too has a little bit of a learning curve :-).

http://perl.overmeer.net/mailbox/

There is also a mailing list...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: About unoffical HTTP headers

2005-04-26 Thread Wiggins d'Anconia
Shu Cao wrote:
 Hi,
 
 Sorry, my last email has some errors. The unofficial HTTP header should
 look like x: y not x=y. 
 
 I am new to Perl CGI programming. And I encounter a difficult problem 
 wish you guys can help me. Thank you! Here is the problem, how can Perl
 CGI program get the unofficial HTTP header value like x: y. I examine
 the %ENV hash, and found nothing but some standard HTTP headers like
 Accept, User-Agent, etc..
 
 And I check the CGI.pm module too, seems there is no method to get the
 unofficial HTTP headers.
 

This is going to depend on the web server, as it is the software parsing
the HTTP request, it just passes execution to the CGI and sets up the
environment before hand. So it is up to the web server software to set
in the environment the extra headers, you should check the documentation
for it. It appears that Apache, if you use it, should be passing through
the additional headers with an 'HTTP_' prepended but there is no
guarantee.  Docs:

http://hoohoo.ncsa.uiuc.edu/cgi/env.html

In addition to these, the header lines received from the client, if
any, are placed into the environment with the prefix HTTP_ followed by
the header name. Any - characters in the header name are changed to _
characters. The server may exclude any headers which it has already
processed, such as Authorization, Content-type, and Content-length. If
necessary, the server may choose to exclude any or all of these headers
if including them would exceed any system environment limits.

Which is linked from:

http://httpd.apache.org/docs/howto/cgi.html#environmentvariables

Which is (obviously) specifically for Apache.

 If you guys know the HOWTO, pls help me. Thank you!
 
 BTW, English is not my native language, if I have any syntax or grammar
 error, pls forgive me:P


Thought it was fine.

 Best Regards,
 Shu Cao
 
 

Good luck,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: PATH problem

2005-04-25 Thread Wiggins d'Anconia
TapasranjanMohapatra wrote:
 All,
 My script goes like this...
 --
 #!/usr/bin/perl
 print Content-type: text/html\n\n;
 $cmd = cat file_one;
 $content = qx!$cmd!;
 print $content;
 --

You should not shell out to read a file, Perl is a full programming
language, you should use the builtin functions whenever possible.
Especially when they are common and simple ones. It is faster, safer,
and less bug/error prone.

#!/usr/bin/perl
use strict; # always
use warnings; # pretty much always

print Content-type: text/html\n\n;

open my $HANDLE, 'file_one' or die Can't open file for reading: $!;
while (my $line = $HANDLE) {
  print $line;
}
close $HANDLE;

The same thing only faster, much safer, and it will give you diagnostic
output in the error log of the web server to find out why it can't read
a particular file.  See the other poster's comments too.

http://danconia.org

 I have a case where file_one is not in the same directory. So I give the 
 absolute path of file_one
 in place of file_one. 
 When run it using perl on command line I get the contents of file printed 
 correctly.
 
 But when accessed through browser (cgi-bin), I get nothing printed.
 
 I thought it might be path problem , but it is not. Because when the file is 
 in same directory,
 it prints the content of the file.
 
 Can anybody let me know where I am going wrong?
 TIA
 tapas
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Variables in Modules

2005-04-13 Thread Wiggins d'Anconia
Ovid wrote:
--- Sergio Pires de Albuquerque [EMAIL PROTECTED] wrote:
I tried with our, importing that var and fully qualified it, but
always 
it get the previous value. My question is: Which method is common to 

share data among apps? What Am I doing wrong? Also, I always use 
strict and warnings.

You're talking about global variables and, in general, using them is a
bad thing as it makes code more difficult to maintain.  I won't go into
that, though, as there's plenty of info elsewhere about that.
In your case, don't give access to the variables.  If you're not going
to go OO, give access to subroutines which can read and alter those
variables.
  package Foo;
  use strict;
  use warningsl
  my $var = 7;
  sub var { $var }
  sub set_var {
my $new_var = shift;
unless (defined $new_var and $new_var =~ /^\d+$/) {
  require Carp;
  Carp::croak(Argument to set_var() can only be digits: ($var));
}
$var = $new_var;
  }
  1;
With techniques like that, you can at least ensure that there is one
canonical place where the data is being fetched and altered.  This
gives you some measure of protection to ensure that naughty code isn't
doing things it should not be doing and, if it ever gets set to a bad
value, you have only one place to put your debugging code.
Cheers,
Ovid
I agree with what Ovid said, but in the case where the data won't need 
or shouldn't be changed, you might consider using constants, which have 
a global nature but are considered less messy than global variables.

perldoc constant
Though I would still drop them into their own module that can be 'use'd. 
This works well for DB DSNs, base URLs, etc.

http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Calling subroutines

2005-03-21 Thread Wiggins d'Anconia

Denzil Kruse wrote:
Hi,
I have a script for a cgi form that covers about 20
pages, and want to name a subroutine to handle each
page like this: page1, page2, page3, etc.
Once the script figures out which page it should go
to, I dont want to have to do this:
if ($page == 1) { page1() }
if ($page == 2) { page2() }
if ($page == 3) { page3() }
.
.
.
I would like to call the subroutine with one
statement, something like this:
$page = $in-param('page');
page$page()
but the compiler doesn't seem to substitute the
variable $page before figuring out the name of the
subroutine and it gives me an error.  I thought about
loading the subroutine referencees into an array, but
run into the same problem.
Is there a way to do this?  Or is there a better way
for the beginning part of the script to play traffic
cop and direct it to the right page?
Have you considered the CGI::Application module? It works essentially as 
you describe but has a good following, is likely better tested, and may 
provide a little more support structure.

http://search.cpan.org/~markstos/CGI-Application-3.31/lib/CGI/Application.pm
In any case the array method you describe should work, can you show us 
the code you have tried?  You may just not be dereferencing your sub 
correctly.  You might also consider a hash and drop the numeric (and 
confusing names) unless there really is an order to the pages.

http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: cgi scripts as root or similar - best method

2005-02-25 Thread Wiggins d'Anconia
Chris Devers wrote:
On Fri, 25 Feb 2005, Gavin Henry wrote:

[...] the problem is [...] cdrecord needs to be run as root.

I assume cdrecord is being invoked from a system command, right?
Have you considered prefixing that command with `sudo`, and going into 
the sudoers file to allow the www user that privilige?

Of course, it would be a bit more complicated than that, as sudo will 
prompt for a password that you have to pass back to it somehow, but 
after hurdle that I suspect that it should work fine...

[snip]
You can use the 'NOPASSWD' flag in the sudoers file for a particular 
command/alias, etc. so that the user does not have to enter a password.

man sudoers
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



sorting and printing text files (was: hello all)

2005-02-17 Thread Wiggins d'Anconia
Don Doucette wrote:
hello everyone.
my name is don doucette and I am 38 years old and have been involved 
with computers since the Timex Sinclair.

Ok. Please use a more informative subject line.
I have recently set up a server and am hosting a web site and forum for 
my community association.

I am running the YaBB forum (http://www.yabbforum.com/) and I would like 
to do the following...

I would like to use perl to look in a directory of numerical named .txt 
files (as in 0123456789.txt), find the file name with the largest number 
(as in 1234567890.txt is greater numerically than 0123456789.txt) then 
open the file and extract data from that file so it can be posted into a 
web page?

For instance...
I have a directory named Messages, in this directory there are the 
following files...

1108577587.txt
1108519222.txt
1108490078.txt
1108489912.txt
Obviously 1108577587.txt is greater numerically than the rest, this also 
happens to signify that this is the newest message. In this file is the 
following information...

Title of Post|Author|[EMAIL PROTECTED]|02/16/05 at 
12:13:07|Group|xx|0|192.168.1.1|Message||

As you can see this file is delimited by | and ends with ||
I would like to parse out the Message field first then the Author field 
and assign their value to a variable then insert the variable into html 
on a page.

Something like...
html
head
titleUntitled Document/title
/head
body
pHere is the newest post to the forumBRBR
$Message BRbr
Posted by $author /p
/body
/html
The idea is when the main web page loads it always shows the newest post 
to the forum and who posted it.

My question REALLY is do you think this can be easily done or is this a 
huge programming effort for someone just trying to figure out perl... I 
have been thumbing through my Perl book (The Complete Reference Perl 
Second Edition) but it hasn't really been helpful so far.

Thanks for your advice.

Clearly you have a good spec which is about the best start. In general 
this is a forum for specific questions about CGI, which sort of fits, 
but you might be better off with just the beginners@perl.org for non-cgi 
related questions, as yours are more general. Though they are also 
forums for learning, rather than getting free code so we usually like to 
see what you have tried first. Having said that

To get to your actual question, what you are talking about doing is 
pretty simple in Perl. I am not familar with that particular book, if 
you are interested in learning Perl you should check out the Llama from 
O'Reilly, aka Learning Perl. Having read that you should be able to 
solve the above problem. If you don't want more books and can read tech 
docs, then you should start with,

perldoc perlopentut
perldoc -f opendir
perldoc -f readdir
perldoc -f open
perldoc -f sort
perldoc -f split
perldoc -f print
perldoc CGI
Very little is a HUGE programming effort in Perl, that is why it is so 
loved by its users...

Good luck,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Favorite Perl CGI Framework for Web Site Development?

2005-02-11 Thread Wiggins d'Anconia
Chris Devers wrote:
On Fri, 11 Feb 2005, Siegfried Heintze wrote:

I notice there are a lot of frameworks out there for .NET (eg, .NETNUK),
PHP, and Java (eg AppFuse) programmers. These are sets of files that form a
typical starter site (or skeleton) that have the basic common features for a
web site: (1) cookie/password authentication authorization, send email for
forgotten password, (2) file upload, (3) calendar etc...
Are there any such frameworks for perl cgi? I googled for perl cgi framework
but could not find any matches.

Does Bricolage count? Or Slashcode?
I would count them. There is also TypePad/Moveable Type by Six Apart.
Perl mainly offers sets of tools for plugging such things together, 
using components like CGI.pm /or template libraries (Template Toolkit, 
Mason, HTML::Template, etc) to build sites.

We don't, however, really have any prominent web application frameworks 
to compare with, say, Zope (Python's main offering) or the many suites 
that are now available with PHP.

I'd be delighted to be corrected about this, but it seems like most of 
the people that are working on such frameworks are using other languages 
these days. 


I have one in development and have been intending to release it under a 
GPL like license but haven't gotten quite that far. Of course it has no 
documentation or testing, why would it need it there are no bugs ;-).

I agree with the other posters about MayPole, and WebGUI.
I will also throw out InterChange since I just started working for a 
company that uses it, but it appears to have a very steep learning curve 
and probably isn't as elegant as the others. It is really geared towards 
e-commerce.

http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How to use sub directories in IIS and Apache HTTPD

2005-02-07 Thread Wiggins d'Anconia
Siegfried Heintze wrote:
When I try to employ subdirectories my perl cgi programs stop working. This
is because the use statements cannot find their files.
I could convert the use evidence_db; statements to require
'../evidence_db.pm'; and that works. But this is painful.
Surely there is an easier way. I thought of going into the IIS setup and put
a -I switch for the perl statement IIS uses to invoke perl for CGI.
However, that could mess up other applications in other sites if I am not
the only site on the machine.
I don't know where I would change the setting in Apache HTTPD for just the
current site either.
Can someone tell me?
Thanks,
Siegfried

perldoc lib
You can add directories to the @INC array at compile time.  You may also 
be interested in

perldoc FindBin
For instance in the top of my CGI handler I have,
use FindBin;
use lib $FindBin::Bin/../../lib;
use lib $FindBin::Bin/../lib;
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: embedding dynamic images in html output

2005-01-21 Thread Wiggins d Anconia
 11:03am, Chad Gard wrote:
 
 
  On Jan 21, 2005, at 10:22 AM, Sean Davis wrote:
 
  You could also have your main script generate the images all at
once (at 
  the same time as you are generating the HTML), put the graphics in
temp 
  files, and then put the appropriate URLs in the img tags.  This will 
  eliminate the overhead of calling a helper script 9-25 times for a
single 
  page.  If you are on an intranet, serving 25 small images should be
almost 
  instantaneous.
 
  Yeah, though then I have to worry about cleaning up the temp
directory, and 
  I'd like to avoid unnecessary writes to the hard drive (to avoid
directory 
  damage possibilities, energy use, fragmentation, etc).  It logically
makes 
  sense to just send these things out as they're generated.
 
 Just a thought here: why do you have a hard drive if you're not going
to use 
 it? And energy use? You're not serious, are you? If the hard drive is 
 spinning, the extra energy used to move the heads is very, very little.
 

If we are talking about energy use then surely the amount of energy
sucked in by the CPU to generate any kind of complex graphed graphic
will be higher than to move the heads on the disk. Out of curiousity do
you not use a web log?  So isn't there a disk write for every request
anyways?  How about a log on the database queries, running the query for
every HTML page hit is going to cause another write, never mind the
potential for errors to be written. Most likely the database also has
tuning to limit requests, what if you hit that limit while generating
your results, blocking someone needing to do something for real, when
all you had to do was serve up a static graphic generated 2 months ago.
And with the 8MB *cache* on some hard drives today there is a good
chance your popular 30kb graphic doesn't even have to come from the
platter...

Seems odd to question caching technology given that cpus (and even the
cache has a cache these days), gpus, harddrives, web servers, browsers,
etc, etc, etc. all use them...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: What exactly does $| = 1; do?

2004-11-30 Thread Wiggins d Anconia
 I have seen in a few scripts now, including some of the articles that Mr. 
 Schwartz has written. I have read it does something with the buffers
but on 
 a more technical level what is that?
 
 Robert 
 

Since this is a general Perl question not related to CGI it is better
asked to [EMAIL PROTECTED]

perldoc perlvar

Will give probably the least friendly and most technical version.
Specifically under OUTPUT_AUTOFLUSH.  The tricky parts being that it is
specifically the currently selected output, see,

perldoc -f select (first form)

For more on that, and that buffering may or may not be implemented for a
given type of handle (though most are).

Helps?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: reading in a CVS file

2004-11-02 Thread Wiggins d Anconia
 Hello,
 
 I am trying to do an import of a Tab De-limited file and then 
 extract certain fields.
 

This has what to do with CGI?  Your question is better asked to
[EMAIL PROTECTED]

 I am looking to general comments and or a better more concise way of
doing this,
 Thanks in advance...
 
 Dave Gilden -- Ft. Worth-less Texass
 
 Here is what I have so far (and it is not tested and my be incorrect!)
 
 
 ###Perl Code###
 

use strict;
use warnings;

 open (FH, $fileIn) || die Problem reading $fileIn $!\n;
 

I suspect the above ought to have Cdie either outside the string, or
in addition to the string.  Have you tested this code?

 while(FH){
 push(@musicians, $_); 
 } 
 close FH;
 
   
 foreach (@musicians){
 chomp;
 
 @tmpArray  = split(/\t/,$_); 
 
 $ssNum = $tmpArray[0];
 $fName = $tmpArray[3];
 $lName = $tmpArray[4];
 $zip = $tmpArray[8];
 $city = $tmpArray[9];
 $state = $tmpArray[10];
 $memberStatus = $tmpArray[12];
 $phone = $tmpArray[19];
 $instrument = $tmpArray[21];
 $email  = $tmpArray[33];
 

Why bother transferring the individual array values into named variables
if you don't intend on using the names anywhere.  What happens when the
columns are in a different order?

 
  INSERT Into Data in to mySql Database ###
 
 # using place holders
 $sql = insert into $table_name values (null, ?, ?, ?, ?,?,?,?, ?, ?,
?);;
 $sth = $dbh-prepare($sql);

$sth-execute($ssNum,$fName,$lName,$zip,$city,$state,$memberStatus,$phone,$instrument,$email);
 
 ## more  code.
 }
 

MySQL comes with an import utility that I believe will take CSV/TSV
files. Alternatively you may want to check out the Text::CSV module, or
one of the other offshoots.  WHat happens when one of the fields
contains a tab, aka it is quoted?

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Files -read write - an epiphany and question

2004-10-18 Thread Wiggins d Anconia
This doesn't have anything to do with CGI so would be better directed to
[EMAIL PROTECTED] instead

 
 I have been studying W/R to files...
 W/R to a string and to an array.
 and I must say I think I have it.
 
 I can read a file into an array IF i wrote the file using \n between
vars, yes

Yes and know. You don't have to have any newlines in the file to read it
into an array, but all of the content will appear in the first element
of the array in that case.  Reading/writing a file is lower level than
that and doesn't specifically care about the contents having said
that, if the file is read/write in a manner that will allow buffering
you might have to have flushing turned on.

 
 and I can read the entire file into a string (to later be split) by
using delimiters like ,yes???

Again delimiters don't affect the reading. However by using delimiters
you can allow any string to be split.


 
 I have some data files that hold lists (like cities) that I want in an
array.
 and some files that hold a collection of vars (name, city, color,
cartype, etc) that I want to delimit and later read as a string ($Slurp)
and then ($name, $city, $color, $cartype, $etc)=split (,,$Slurp)
 
 my question is if I write a file using delimiters like ,  can I
later read the entire file into a string and then
 @Cities = split (,,$Slurp) ??

Assuming they were all on one line.  In this case I would suggest
putting each city on its own line and reading the file at once into an
array, no split would be needed.


 
 but how do I read a file that used the \n and then split it later???
 right now i wold have to
 open file...
 @Array=read entire file into @Array
 close file
 
 and then...
 
 $name=$Array[1];
 $city=$Array[2];
 $color=$Array[3];
 $cartype=$Array[4];
 $etc=$Array[5];
 
 there must be a better way like ?
 $name, $city, $color, $cartype, $etc)[EMAIL PROTECTED];
 

The above will work, you can also store it directly from the HANDLE
since it is list context, but in that case you need to be sure the file
has the right number of lines.

 of can I split using the special var $\ or \n as a delimiter
 

I believe you mean $/ which is the input record separator. For more
information on it see the INPUT_RECORD_SEPARATOR section in,

perldoc perlvar

Essentially it sets the delimiter used when Perl reads the file to
automagically delimit it.

 ?? am I making the example clear?
 or am i trying to do the impossible?
 

Nothing is impossible ;-). Not sure about the clarity though, some
sample code and an example file would be helpful.

 Comment WITH example correction welcome..
 the above syntax may not be completely correct
 but it gives you the idea...so please dont crusify me for it...
 
 Lou
 
 

I would suggest some further reading on the subject first, 

perldoc perlopentut
perldoc -f open
perldoc -f split
perldoc -f readline

Also check out the I/O Operators section of,

perldoc perlop

HTH,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need a little help with a sub.

2004-10-14 Thread Wiggins d Anconia
 I am calling a sub with:
 
 Navigate(%modules, %settings);


Drop the C until you know what it is for. 
 
 And reading it like:
 
 sub Navigate {
 (%modules, %settings) = @_;
 

Perl flattens lists automagically, so when it sees your C%modules,
%settings it flattens it to one list of key value pairs, or actually
just an ordered list of values. Conveniently when you are assigning a
list to a hash Perl is smart enough to switch the ordered list back into
key/value pairs, however the problem and the reason the above won't
work, is that Perl keeps gobbling until the end. So your two lists, get
flattened into 1, and remain flattened with all of the values going into
%modules.  This is most commonly avoided by passing references to the
two lists into the sub, then you can dereference them back into
lists/hashes if you like. So,

Navigate(\%modules, \%settings);

sub Navigate {
  my ($modules, $settings) = @_;
  my %modules = %$modules;
  my %settings = %$settings;
  ...
}

Though you should consider just leaving them references and working on
them directly with the C -  operator.

 Only the first sub gets passed...
 
 Been a while and I cant figure out what I am doing wrong.  To tired to 
 screw arround with it so I would love if some kind soul could point out 
 what I am forgetting.  Thanks!
 
 aNc


For much more on references check out,

perldoc perlreftut
perldoc perlref
perldoc perllol
perldoc perldsc

And/or the Learning PORM book from ORA, 

http://www.oreilly.com/catalog/lrnperlorm/

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Authenticate users

2004-09-29 Thread Wiggins d Anconia
 Does anyone know if there is any easy way to authenticate users and
 securely maintain a session? Or is it up to me to create a database, and
 a session cookie?
 
 Thanks in advance,
 
 Paul

This is a very FAQ, check the archives of this list. You might also want
to look at the popular CGI::Session module on CPAN. There are others but
I haven't used them.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: HTML::Template still choking

2004-09-29 Thread Wiggins d Anconia
 HTML::Template is still choking, giving the error...
 
 HTML::Template-new() : Syntax error in TMPL_* tag at /XXX[here I'm
 ommiting the path]/data/templates/student_info.tmpl : 13. at
 /usr/local/lib/perl5/site_perl/5.005/HTML/Template.pm line 2243.
 
 I now think the fault is in my Perl code which handles the %datahash
 that is tied to a file. I'm new to this and this script is the most 
 complicated
 I've ever tried. Sorry to post so much code, but my blunders the the 
 light
 of day and some sound criticism. Many thanks in advance!
 

I am not so sure about that. Can you post the *actual* template,
especially line 13?  Your previous message said that that was a typical
line from the template, was that the actual line that was causing the
problem?  Can you verify that the data hash is not the problem, by
pulling the code to read the template (aka the constructor) into its own
script and see if it still dies?  Have you tried enabling some of the
debugging options that H::T provides? It appears that it will give very
verbose indication of what it is doing which might help narrow down the
problem. It would help to narrow down to the exact line what part of
your script is failing, from the error it still seems like it is during
template construction.

http://danconia.org


 #!/usr/bin/perl -w
 use strict;
 use CGI;
   $CGI::DISABLE_UPLOADS = 1;
   $CGI::POST_MAX = 102_400; # 100 KB
 use DB_File; # module for Berkeley DBM w/ DB_HASH file type
 use Fcntl qw/ :DEFAULT :flock /; # to help with file handling
 use HTML::Template;
 # This script is called by a post from student_info_viewer.html
 # or a post from the HTML page generated by this script
 
 # Array all the parameters we will use
 my @info_prams = qw(
   student_info
   name_full   enroll_type
   name_nick   account_number
   name_last   password
   date_birth  student_email
   sex mentor_email
   date_enteredsuspended
   date_withdrawn  
 );
 
 # ID the student and change to student's directory
 my $q = new CGI;
 my $student_id = $q-param ( student_id );
 chdir //data/students/$student_id/;
 my $file_to_view = student_info.db;
 
 # Declare the 'working' datahash, then tie it to file
 my %datahash;
 my $db = tie %datahash, 'DB_File', $file_to_view, O_RDWR | O_CREAT, 0644
   or die Can't initialize database: $!\n;
 my $fd = $db-fd(); # get a file descriptor
 open DATAFILE, +=$fd or die Can't safely open file: $!\n;
 flock ( DATAFILE, LOCK_EX )
   or die Unable to acquire exclusive lock: $!. Aborting;
 undef $db; # Avoid untie problems
 
 # Update the hash with the posted parameters
 foreach (@info_prams) {
   chomp;
   $datahash{$_} = $q-param ( $_ );
 }
 # Generate a page using the template and latest data
 use constant TMPL_FILE = 
 /big/dom/xlibertylearning/data/templates/student_info.tmpl;
 my $tmpl = new HTML::Template( filename = TMPL_FILE );
 # Assign template parameters
 foreach (@info_prams) {
   $tmpl-param( $_  = $datahash{$_} );
 }
 print Content-type: text/html\n\n,
 $tmpl-output;
 untie %datahash;
 close DATAFILE;
 exit;
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: template re HTML::Template choking

2004-09-29 Thread Wiggins d Anconia
 Here is the template:
 

   student_id = TMPL_VAR VALUE=student_id

The above line does not have a NAME attribute which I think is
required. And should the VALUE be DEFAULT??

HTH,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: moving files

2004-09-29 Thread Wiggins d Anconia
Make sure to group reply so that others can help and be helped (and to
avoid getting accidentally ignored)...please bottom post...

 OK, here is what I have so far
 
 use CGI;
 use LWP::Simple;
 $URL = http://www.jeffherbeck.com/arch.doc;;
 $remote_user = $ENV{REMOTE_USER};
 
 getstore($URL, /var/www/html/$remote_user);
 
 
 and I keep getting 
 
 Server error!
 The server encountered an internal error and was unable to complete
 your request.
 
 Error message: 
 Premature end of script headers: test.cgi 
 
 If you think this is a server error, please contact the webmaster. 
 
 Error 500
 
 
 
 
 Could you lead me futher?
 

The above does not have a header printed, which is the most common
reason why you would get a 500 error.  Following that, unless you print
some response you will also get the Document Contains No Data error on
the client side. In general when you have a 500 error you triple check
that a proper header is being printed, that nothing is printed before
the header, and from there use the web server log to diagnose further
causes, such as syntax errors, etc. or use the fatalsToBrowser switch to
have errors go to the client (not necessarily advisable in production
facing systems).

 
 Thanks
 
 Jeff

http://danconia.org

snip

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Problem with flock

2004-09-27 Thread Wiggins d Anconia
 Variations on the following code snippet have run successfully before, 
 but now the compiler halts with the complaint
  Bareword LOCK_EX not allowed while strict subs in use at 
 student_info_viewer.cgi line 47
 Can someone help me see what I am overlooking?


You haven't shown us your 'use' statements, I suspect you didn't import
the LOCK_ constants,

perldoc -f flock

Adding:

use Fcntl ':flock'; # import LOCK_* constants

Should help. If it doesn't post the new errors,

http://danconia.org
 
 # Declare the 'working' datahash, then tie it to file
 my %datahash;
 my $db = tie %datahash, 'DB_File', $file_to_view, O_RDWR | O_CREAT, 0644
   or die Can't initialize database: $!\n;
 my $fd = $db-fd(); # get a file descriptor
 open DATAFILE, +=$fd or die Can't safely open file: $!\n;
 flock ( DATAFILE, LOCK_EX )
   or die Unable to acquire exclusive lock: $!. Aborting;
 undef $db; # Avoid untie problems
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: moving files

2004-09-25 Thread Wiggins d'Anconia
Jeff Herbeck wrote:
Hello,
I am trying to start a transloading and webhosting company.  This
will allow users to login via apache .htaccess type authentication and
then be able to put a url of a file into a form and the script  will
go get that file, download it to the webserver into their html
directory and then be available for world access. I have the security
setup (apache athentication) and I can get their username with
env(REMOTE_USER) but I dont' know what to do from here.  I know I want
to use wget to get the file, but i can't seem to get it to work in a
script.  I am a linux admin, but don't know perl.  How can I log in
the http user into linux and go get that file with wget so it will go
in their home directory, which will be their html directory.  Can
someone please get me started?
Thanks in advance
Jeff
I would avoid using 'wget' and instead opt for the LWP suite of modules. 
They should make retrieving a remote file simple (at least over http). 
Take a look at the documentation and examples and give it a shot, when 
you get stuck ask some more specific questions.

http://search.cpan.org/~gaas/libwww-perl-5.800/lib/LWP.pm
LWP is available from CPAN.
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: session ids?

2004-09-22 Thread Wiggins d Anconia
 
 
 I'm still very much a beginner, but I'm starting to see how establishing a
 concept of sessions could be quite handy for my website.  So I was
thinking
 of coming up with session ids, which could be some encoded combination of
 their ip address, user name, and the date/time of that session's
start.  The
 server would embed the session id into hidden fields or cookies, and
use it
 to determine which areas of the site are available to that user.
 
 Is this a common thing to do?  Am I on the right track with this?  And if
 so, does perl offer an easy way to encode those three things into a string
 of apparent gobbledygook and back?
 
 TIA.
 
 - Bryan

This is discussed frequently on this list and is mostly a matter of
preference and/or user demands on how you implement it, aka cookie/url
munging, session ids/user authentication, etc. You should check the
archives for past discussion.

Apache::Session in particular is highly regarded, though there are other
modules available on CPAN.

Questions, yes it is a very common thing to do, yes you are on the right
track, and if you want to mess with the lower level yourself, doing
SHA1/MD5 hashes are probably the easiest (to me), aka encode the data
give it to the client, then during the next request re-encode the data
and compare the two.

I would suggest avoiding doing anything with IP addresses completely as
they are not consistent from user request to request because of things
such as proxies.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need some help using lib to add custom directories to @INC

2004-09-16 Thread Wiggins d Anconia
Please only post to one group, if that group does not yield a good
answer, then try a different one. Especially since this has nothing to
do with CGI.


 Can anyone tell me why this code fails when trying to load
 Some_Module_In_lib_Dir-
 ==
 my $file_path =
 substr($ENV{SCRIPT_FILENAME},0,index($ENV{SCRIPT_FILENAME},'/test.cgi'));

The above happens at runtime, 

 use lib $file_path/../lib;

The above happens at compile time, so $file_path is empty (at least I
suspect).

 use Some_Module_In_lib_Dir;
 
 ==
 And this code does not -
 ==
 use FindBin qw($Bin);

This is loaded at compile time and I suspect it sets $Bin at compile time,

 use lib $Bin/../lib;

This is then loaded at compile time with $Bin already having been set.

 use Some_Module_In_lib_Dir;
 
 ==
 And this code does not -
 ==
 use lib '/home/user/domain-www/cgi-bin/some_dir/test/../lib'

Obviously this is hardcoded and loaded at compile time. Since it is just
a string it works.

 use Some_Module_In_lib_Dir;
 
 ==
 And this code does not -
 ==
 use lib
 substr($ENV{SCRIPT_FILENAME},0,index($ENV{SCRIPT_FILENAME},'/test.cgi')) .
 /../lib;

This is impressive, but I suspect Perl is loading the whole statement at
compile time, and since the %ENV is already established it works. I am
impressed (but not terribly surprised, Perl is so cool) that it knows to
compile and execute the whole line.

 use Some_Module_In_lib_Dir;
 
 
 If $Bin and $file_path are printed to screen, they show values
identical to
 the path used in the third example and that one derived in the fourth
 example. So, why does $Bin get added to @INC before the program tries to
 load Some_Module_In_lib_Dir, and $file_path does not?

Printing happens at runtime, but the 'use' happens at compile time, as
do the setting of variables, *unless* they specifically happened at
compile time for some reason.

You can use CBEGIN blocks to when items are executed, aka if you want
them to be run during compile time.

HTH,

http://danconia.org



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Need some help using lib to add custom directories to @INC

2004-09-16 Thread Wiggins d Anconia
 
  -Original Message-
  From: Wiggins d Anconia [mailto:[EMAIL PROTECTED]
  Sent: Thursday, September 16, 2004 9:03 AM
  To: Ron Goral; Perl Beginners; [EMAIL PROTECTED]
  Subject: Re: Need some help using lib to add custom directories to @INC
 
 
  Please only post to one group, if that group does not yield a good
  answer, then try a different one. Especially since this has nothing to
  do with CGI.
 
 
 Actually, for me this has quite a lot to do with cgi as I am using
this bit
 of code to load various custom modules to process choices submitted via
 forms on a web site.  This is especially necessary when the website
does not
 have it's own secure server certificate and is using a generic one
owned by
 the hosting company.  In such a case, when the script is called via SSL,
 FindBin fails to produce a relative path to the lib directory and loading
 the custom module fails miserably.  The use lib substr() concoction
works.
 I just need to know why for future use.


Right I understood that, but to us it doesn't and in this context it is
*us* that matters since you are requesting the use of the mailing list
resources, and the CGI list is specifically for questions related to CGI
programming, not general Perl how tos. There is nothing specific in your
question about CGI, only that you happen to be running it in a CGI
environment, which doesn't make it relevant for this list *especially*
if you are going to post to the regular beginners list without waiting
to even see if you get a response.
 
 
   Can anyone tell me why this code fails when trying to load
   Some_Module_In_lib_Dir-
   ==
   my $file_path =
  
 
substr($ENV{SCRIPT_FILENAME},0,index($ENV{SCRIPT_FILENAME},'/test.cgi'));
 
  The above happens at runtime,
 
   use lib $file_path/../lib;
 
  The above happens at compile time, so $file_path is empty (at least I
  suspect).
 
   use Some_Module_In_lib_Dir;
  
   ==
   And this code does not -
   ==
   use FindBin qw($Bin);
 
  This is loaded at compile time and I suspect it sets $Bin at compile
time,
 
   use lib $Bin/../lib;
 
  This is then loaded at compile time with $Bin already having been set.
 
   use Some_Module_In_lib_Dir;
  
   ==
   And this code does not -
   ==
   use lib '/home/user/domain-www/cgi-bin/some_dir/test/../lib'
 
  Obviously this is hardcoded and loaded at compile time. Since it is just
  a string it works.
 
   use Some_Module_In_lib_Dir;
  
   ==
   And this code does not -
   ==
   use lib
  
 
substr($ENV{SCRIPT_FILENAME},0,index($ENV{SCRIPT_FILENAME},'/test.cgi')) .
   /../lib;
 
  This is impressive, but I suspect Perl is loading the whole statement at
  compile time, and since the %ENV is already established it works. I am
  impressed (but not terribly surprised, Perl is so cool) that it knows to
  compile and execute the whole line.
 
   use Some_Module_In_lib_Dir;
  
  
   If $Bin and $file_path are printed to screen, they show values
  identical to
   the path used in the third example and that one derived in the fourth
   example. So, why does $Bin get added to @INC before the program
tries to
   load Some_Module_In_lib_Dir, and $file_path does not?
 
  Printing happens at runtime, but the 'use' happens at compile time, as
  do the setting of variables, *unless* they specifically happened at
  compile time for some reason.
 
  You can use CBEGIN blocks to when items are executed, aka if you want
  them to be run during compile time.
 
  HTH,
 
  http://danconia.org
 
 
 
 This helps quite a bit.  THANKS!! =)  I did not know, though I suspected,
 that $Bin would be set at compile time.  I had noticed as I printed
out the
 elements of @INC the path was listed using FindBin even if I printed
 before I did the FindBin stuff in code.  It makes sense that FindBin
does
 it's stuff before run time.  I am curious though why substr() executes at
 compile time and not at runtime.  Is it because it is a builtin perl
 function?
 
 Thanks again.
 
 

Csubstr doesn't normally run during compile time, I think (don't know
for sure, maybe an internals guru will chime in) that it is the special
nature of following the Cuse lib that makes it happen at compile time
in this case, aka the whole part after the 'lib' is essentially taken
inside of a BEGIN{} to allow for this very case, which is what is so
neat about Perl, aka that it allows you to do this kind of thing. 
Essentially the same is tru about the FindBin usage where $Bin is used,
aka it has to interpolate the string, which would normally happen at
runtime too, but in this case it *has* to happen at compile time (so it
knows what to 'use'), and it just so happens that variables like $Bin
have already been set at compile time.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail

Re: CGI Book Advice sought ...

2004-09-15 Thread Wiggins d'Anconia
hcohen2 wrote:
Recently I jumped in to the list and gave a correct answer, but 
unfortunately not really appropriate answer to the question asked.  I 
took the 'Beginners' adjective for this list too seriously.

Hence, to keep myself out of trouble, I think it is time to get 
another book on CGI for perl to study this topic in greater depth.  I 
have been spending time in a book store and researching further using 
Google and I have run across a title that may be appropriate.  The 
title is: CGI Programming 101: Programming Perl for the WWW and is a 
2004 publication.  The first 6 chapters are on line, so I can get some 
idea of the book's value by going through those chapters.  However, 
there is a reader's review of the first edition that seems to ring 
true and, moreover, is not complimentary.  That reader maintains the 
first 40 pages are good, but due to the choice of using the CGI 
package only modestly devalues the contents.  The other four reviewers 
were much more taken with this book.

I wonder has anyone here read this title and would they be willing to 
give an evaluation, having  someone in mind that has only had a brief 
introduction to perl's cgi scripting?

TIA
I would echo Chris' remarks about mod_perl, and the book not being worth 
its oats if it shys away from using CGI.pm.  Personally I would skip 
*all* of the CGI books, and get a good book on Perl itself. Learn the 
language not how to use it for a specific task. This will serve you in 
everything you do much better in the long run, then once you have 
learned Perl basics, it should be trivial to read any module's 
documentation to absorb the API and apply it.  CGI.pm has excellent 
docs, as do some of the other CGI helping tools, such as the various 
template systems, and modules like CGI::Application.  This path will 
also serve you well when it comes time to learn DBI for your database 
access, or any other module you need for core logic.  There are also 
excellent free online tutorials to teach you basic CGI programming, 
Ovid's comes highly endorsed (google).  CGI just isn't that difficult, 
- print a header, maybe include a cookie or two, do a redirect, that's 
about it, the rest is just time and experience.

The two books I would suggest are Learning Perl and its sequence 
Learning Perl Objects, References, and Modules.  I give comments about 
them as well as other Perl books on my site.

Good luck,
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: perl moudules for Primer Design

2004-09-13 Thread Wiggins d Anconia
 Dear all;
Could anybody give me some directions or suggestions that are there
any perl Modules for primer design developed and povided?
  
 Thanks in advance
 Jian
 

Not sure what this has to do with CGI, and I don't really know if you
are speaking of the bio related primer design but a guess is that you
should check out:

http://bio.perl.org/

Or,

http://search.cpan.org/search?query=primer+designmode=all

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: ODBC

2004-09-01 Thread Wiggins d Anconia
 
 
 
 I have a CGI program in which I am trying to access a database. When I
run the code in active state feeding it the input from the form it runs
fine. When I try to run it as a cgi from IE using Apache web server the
data from the form comes in fine but it can not seem to attach to the
database.
 
 Is there anyway to see the errors that the DBI:ODBC is generating when
the application is being run from the server? Any ideas why the ODBC
connect is failing?


You can use CGI::Carp and 'fatalsToBrowser' to have fatal messages
thrown to the browser, alternatively error messages are generally sent
to the Apache error log.  Check there for what they have to say. You
could also turn off DBI's automatic exceptions and catch them yourself,
but this is a fair amount more work (at least while prototyping).
 
 $dbh = DBI-connect(DBI:ODBC:$SERVER, $USER, $PASSWORD);
 
 

Sorry can't help with the connect issue, I suspect if you can find the
error output it will.  If not you might try the dbi-users group or maybe
someone else with ODBC experience will chime in.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Loading an array

2004-09-01 Thread Wiggins d Anconia
Your question may be better asked on [EMAIL PROTECTED] since it isn't
really CGI related.

 
 I need some help, I am running this code to load values into the
 $ArrayofCompareHex [$g] array.  Currently it is not working.  The
 $comparevalue gets the correct value but the value is not past into the
 array.  Here is a portion of my code.  Any ideas
 

Do you have strict/warnings enabled?  Where did $mps come from and what
does it contain?

http://danconia.org

  
 
 230 my $g =0;
 
 231 for ($g = 0; $g  $mps; ++$g)
 
  
 
 {
 
 239 $value = hex($ArrayofInput [$g]);
 
 240 $ArrayofInputHex [$g] = $value;
 
 241 $comparevalue = hex($ArrayofCompare [$g]);
 
 242 $ArrayofCompareHex [$g] =$comparevalue;
 
 }
 
  
 
 thanks in advance
 
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Cookies v. Hiddent Fields

2004-09-01 Thread Wiggins d Anconia
 
 What is the difference (as far as security goes) between using a
cookie and
 a hidden field? Are hidden fields cached if we are using SSL? I think
not. 
 


None. Both are wide open. SSL simply encrypts the pipe between your
server and the client (browser). Everything passing over it, including
cookies and hidden fields, is encrypted, or not if SSL is not employed.
  I like the pipe analogy, think of everything that goes from the
browser to the server (and since both cookies and hidden fields are
client side until the client calls to the server) as traveling over a
clear pipe. So if you can see into the pipe, then you can see
everything. Then picture SSL as a wrapper around the pipe, it prevents
you seeing *everything* traveling over the pipe, so then it is up to you
to make sure the connections at either end work (aka browser supports
SSL, server does too, and they have decided to use the covered pipe
instead of the clear one).
  
 
 If I use a GUID as a session ID in my database and store the GUID in a
 hidden field and the user sees the GUID in some GET parameters, is this of
 any consequence? 
 

Depends on what the GUID is made of.  Did my other write up of the
authentication idiom not help? work? or the modules suggested by the
other poster?

  
 
 Someone recommend that I don't persist cookies. How do I not persist
 cookies?
 

They shouldn't persist by default, it is usually a question of how do I
make them persist, whic his covered very clearly here:

http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm#HTTP_COOKIES

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Cookie Security

2004-08-31 Thread Wiggins d Anconia
 On Tue, Aug 31, 2004 at 08:30:35AM -0600, Siegfried Heintze wrote:
  My client has had me implement some very proprietary algorithms.  He
wants
  to charge his clients money every time someone requests these
calculations
  be preformed on their very sensitive.
  
   
  
  In addition my client anticipates storing this extremely sensitive data
  using Microsoft Access on his site which is largely implemented in
Perl CGI.
  
  
 Microsoft Access does not scale.  Consider using SQL Server if it must
 be MS, or investigate the open source databases like PostgreSQL and
 MySQL if cost is an issue.  Stray away from using Access for anything
 production as its meant to be a simple DB.  It will burn them.  Most of
 my current job is converting all the Access DB's floating around to our
 Oracle DB, while the MIS department is figuring out ways to make sure
 Access will not run on anyone's computers :)


I second this, *please* use something other than Access.

snip
 
 
   
  
  Finally, what about using cookies for authentication and authorization?
  Assuming his clients are amenable to turning cookies on, I believe the
  favorite algorithm is to generate a random number when we prompt for a
  password and (assuming the user enters a valid username and
password) store
  this number both in the cookie on the browser and in the database. The
  browser always presents this number to the Perl CGI code and we look
up the
  number in the database to find the username and bump a counter in our
  database everytime the user requests an evaluation.
  
 
 More than just a random number in most cases.  Usually double md5sum of
 the epoch bitwise or'd or appended with the process id number, ip
 address, or user id or a combination of thereof might work.
 

I don't understand how you are using this info?  The process id number
would change between requests, as might the IP address (think proxies).
 I wrote up a fairly common idiom in a previous message to this list, it
goes like such:

Generally the idiom goes something like, create a private key (aka a
passphrase or something that no one else knows), take the key and some
reproducible non-private information (such as the user name/id) and hash
the two together. Provide the hash, and the information used to create
it (NOT the private key!) in the cookie. Then during the requests check
to see if the information provided back by the user from the cookie can
be used to reproduce the same hash using the same private key as before.
 If the hash is reproduced then the user is authenticated. Assuming no
one else has the private key, then the hash should be unique for the
user and the private key should be non-guessable from the hash,
generally if this holds an attacker can't produce a string that will
authenticate correctly. In general using the IP address in this is not a
good idea unless you know precisely what IP a particular user is going
to come from.  The complexity of your hash inputs can vary what you can
do, aka adding expirations, etc. 

I don't take credit for this, the idiom is yanked from the Writing
Apache Modules with Perl and C book from ORA, it provides an excellent
discussion as well as code samples of how to implement this.

Also not sure about the double MD5, are you positive that doesn't
introduce a vulnerability, by MD5ing a hash you seemingly have reduced
its power since it is a hash of a relatively short string which could
definitely be brute forced very quickly?  I would skip MD5 completely
and go with SHA-1 (although there are recent concerns about it), and
would definitely double check hashing a hash with an encryption expert
before doing it.

   
  
  Is this approach secure? I am suspicious because in the Microsoft .NET
  literature they suggest that cookie (or forms) security is only medium
  security appropriate for storing things like frequent flyer miles or
email
  and is not appropriate for credit cards. What would be a more secure
  approach to authentication and authorization?
  
   
 
 I believe they mean don't store the credit card information in the
 cookie.  Storing some sort of decent hash of some data that identifies a
 user on your site is pretty good.  Cookies are stored on the client's
 machine and kept in a place where the browser can send them a malicious
 site if there exists a bug in the browser.  So yeah, don't store social
 security numbers or credit card numbers in the cookie, but some sort of
 identifier is fine.  In theory, the attacker could take control of the
 host machine, use that cookie to log in and then extract the credit card
 information through your interface, but at that point, there's not much
 you could do anyways.
 

Agreed.

  
Thanks,
  
   Siegfried
  
 -- 
 Brad Lhotsky [EMAIL PROTECTED]
 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Storing Larges Chunks of Text or graphics in web applications

2004-08-25 Thread Wiggins d Anconia
 
 I inherited a perl CGI application that uses the integer primary key
in the
 Microsoft Access database fabricate as the file name of  flat text file to
 hold arbitrary amounts of text. It just dawned on me that this is a bad
 idea! If we compress the database, all those unique integer keys will
 change!
 


Good questions, but they all hinge on the fact that the unique primary
key will change.  I am more concerned about why THAT would change?? 
Yikes. What do you mean by compress???  Other than the fact that I
would avoid M$ access completely, storing the text/images to flat files
with their name based on the unique id is a very common way to handle
this (I do it all the time). But once a unique key is set it should
never change.  And if it must for some reason, you are better off
writing a wrapper that checks for files associated with the old key and
moves them to the new key before doing the update (also something I do,
well for revisions not for primary keys). Storing the data file itself
or large amounts of text in the database will slow down most DBs,
assuming you are searching on the contents of those fields, and/or some
DBs might even implement their blob as a local file (not sure specifically).
  
 
 What is a way to fix this?
 

Don't change the primary key.  This is basic RDBMS, what if you had
other related records based on the primary key. not really any
different.

  
 
 Should we have actually store the text in the Microsoft database
instead of
 storing the file name of the text file in the Access database? Many
database
 vendors, including Microsoft Access have a feature like memo or blob for
 hold large amounts of data.
 
  
 
 But what about jpg or png or gif files? Let us suppose we have a web
 application that stores data on persons. One data enters then, their name,
 address, email address, phone etc. and then uploads a gif or jpg
photograph.
 If we use the blob feature in the database, how do we use the img tag to
 point to a database record? If you are going to store gifs, it seems you
 would have to store them in a flat file and store the file name in the
 database. OK, how do you generate unique file names if you don't use the
 integer primary key?
 
  
 
 Thanks,
 
   siegfried
 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Finding date when a file was created

2004-08-20 Thread Wiggins d Anconia
 On Aug 19, 2004, at 1:58 PM, Randal L. Schwartz wrote:
 
  The founding fathers of Unix deliberately left out creation time
  because the concept is ambiguous at best.  There's some discussion on
  it in the classic materials about the early years of Unix.
 
  And I agree with the logic, and the conclusion.
 
 I'd like to read up on that. I'm sure the logic is solid, but I as I 
 said, I fail to figure it out on my own.
 
  Unix *does* track the most recent time anything happens to a file or
  its metadata via ctime.  That's probably close to creation as you
  would probably mean it or need it.
 
 This is what I'm mostly unclear on. What exactly does ctime represent? 
 I think the only descriptions I found said something like ctime is not 
 the creation date of a file, it is the epoch seconds from the time the 
 script was started.
 

Nope not script started (I believe there is a variable for this, check
perlvar). It is an inode change time and is non-portable, see:

perldoc -f stat

and the 'stat' section of,

perldoc perlport


 When is a file's ctime modified? A few quick tests on my Mac OS X lead 
 me to conclude that this is not an accurate measure of when a file was 
 created but I may have missed something obvious.
 

The file's ctime is modified presumably whenever the inode changes,
which is certainly when the file is created, *but* not *only* when the
file was created, aka it can happen afterwards.  Best example would be a
disk defragger, repartitioning, etc. where a file's starting inode may
get moved/changed (IIRC).  From the perlport page Mac OS X doesn't even
seem to be supported, even though it is just a *nix, though with UFS.

Quoting perlport:

mtime and atime are the same thing, and ctime is creation time instead
of inode change time. (Mac OS).

ctime not supported on UFS (Mac OS X).

Basically you can't and shouldn't rely on it.

HTH,

http://danconia.org



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Upload file not working

2004-08-17 Thread Wiggins d Anconia
 Hi all,
 
 Hoping you guys can provide me some place to start troubleshooting.
Here's the situation. I have created a file upload form which then just
prints the contents of the file out. Basically just copied the CPAN
instructions for testing purposes.


 I am able to do this successfully on my test server (local machine),
but when I tried to use the same script on the production server, all I
get is a blank page. Param works to retrieve the file name and print
that out, but no contents. I tried using upload, but that produces an
error. Any suggestions to test why the script is failing on one server
and not the other?
 

How do the servers differ? OS? Web server? Perl version? Module
installations? What error does upload produce, that seems very relevant?
Check all the versions, confirm the module installations, show us some
code, and tell us what the error is.  What does the error log for the
web server report?

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: stuck at TRUE/FALSE, pls help

2004-08-16 Thread Wiggins d Anconia
 
 Hi
 
 I am very very new to perl. And after lots of work I did script a perl
 file to handle a online form (products order form). However, I am
 stuck at a point. I tried my best but could not get thru.
 
 The form is located at: http://www.kevincoffey.com/order.htm
 
 When I select a different shipping adrress, it DOESNOT work!
 
 I gave a RADIO button for : 
 
 Shipping_Address: TRUE=SAME AS ABOVE (i.e. send to adove address)
 Shipping ADdress: FALSE = send to Floowing address
 
 And in the followings cript I gave it with a -- if .. else --
 statement.. but no use..
 
 Can someone pls help me?
 
 Regards
 
 Babul
 

In the future only post the relevant portions of your script until
someone asks for more. I almost skipped your post because it was so long.


 And the first perl file is:
 ===form1.pl===
 
 #!/usr/bin/perl
 
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use strict;
 

Good start, you should include 'use warnings'...

 my ($query, @params, $param, $paramVal);
 my ($csTravel);
 my (@allProductQuantities);
 my (@productIDs, $ID);
 my (@contactNameFields, @contactAddressFields, @contactOtherFields,
 $field, $value);
 my (@shippingNameFields, @shippingAddressFields, @shippingOtherFields);
 my ($productQuantity, $dollarValue);
 

You should declare your variables when you first use them rather than at
the top, it will help you avoid headaches and allow strictures and
scoping to be most affective.



 
 $csTravel = [EMAIL PROTECTED],[EMAIL PROTECTED];
 open (MAIL, |/bin/mail -s 'CTS Order' $csTravel);

You should always check that 'open' succeeded and you should use a
module that handles sending of email from CPAN rather than doing your
mail handling manually like this. Trust me.

snip

 if ($query - param (Shipping_Preference) == TRUE){

You are using the '==' operator which is specifically for number
operations, you should use the 'eq' operator for string comparisons.

if ($query-param(Shipping_Preference) eq 'TRUE') {

Should fix the problem.

snip

 
 =end of form1.pl===
 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: GD.pm and GD::Graph

2004-08-04 Thread Wiggins d Anconia
 
 
 Hello.
 
 Could someone could shed some light what I should do.  Please point me if 
 I should send to a different list.
 
 Although my script ran fine on the command line.  I've got the following 
 errors when running my script on apache
 
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Premature end 
 of script headers: graph
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Uncaught 
 exception from user code:
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] \tCan't load 
 '/dssweb/local-perl/lib/site_perl/5.8.\
 3/sun4-solaris/auto/GD/GD.so' for module GD: ld.so.1: 
 /dssweb/local-perl/bin/perl: fatal: libgcc_s.so.1: open \
 failed: No such file or directory at 
 /dssweb/local-perl/lib/5.8.3/sun4-solaris/DynaLoader.pm line 229.
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146]  at 
 /dssweb/local-perl/lib/site_perl/5.8.3/GD/Graph\
 /pie.pm line 20
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Compilation 
 failed in require at /dssweb/local-perl\
 /lib/site_perl/5.8.3/GD/Graph/pie.pm line 20.
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] BEGIN 
 failed--compilation aborted at /dssweb/local-\
 perl/lib/site_perl/5.8.3/GD/Graph/pie.pm line 20.
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Compilation 
 failed in require at /dssweb/apache2/cg\
 i-bin/tst/graph line 6.
 [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] BEGIN 
 failed--compilation aborted at /dssweb/apache\
 2/cgi-bin/tst/graph line 6.
 
 Thanks,
 Isarin
 

To avoid the internal server error you could use fatalsToBrowser. But
your error is because GD can't be loaded, specifically because it may
not have been installed correctly, or libgd is either not found or not
installed.  Did you install GD through CPAN or using the standard 4 step
build process? Did 'make test' succeed?  Is libgd installed and in a
normal location? You may need to provide an LD_LIBRARY_PATH or similar
in your web environment.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: GD.pm and GD::Graph

2004-08-04 Thread Wiggins d Anconia
Please bottom post...

 
 is libgcc.so.1 same as libgd? I think my libgd is good. and the
 error message refers to libgcc.so.1.
 

No (at least I don't think) libgcc is I suspect something provided by
gcc, which is presumably your compiler. I wonder if the issue is that
your Perl is compiled with a different compiler?  I am not an expert to
know whether that is libgcc complaining that it can't load GD.so, or if
that is Perl complaining that it can't load libgcc.

 I installed GD through the four steps. It passed the make test.
 I added the path to libgcc.so.1 to LD_LIBRARY_PATH but not to the
 libgd? Should I add it?

Certainly can't hurt right?  Is the Perl used to install GD the same as
that you are calling in your scripts? Better to double check.

 
 Thanks.

Since the script works command line then it is almost certainly
something about the web environment that is different, the linker path
is really the only thing I could see as having this particular affect. 
If this doesn't get it you might redirect your query to
[EMAIL PROTECTED] as there may be others more experienced with
internals specifics that can help there that don't peruse the CGI group.

 
 And here are the paths to the modules:
 
 
 /dssweb/local-perl/lib/site_perl/5.8.3/sun4-solaris: 
 drwxr-xr-x   2 dssweb   dssdev96 Aug  3 15:37 GD
 -r--r--r--   1 dssweb   dssdev 60054 Jul 22 16:11 GD.pm
 
 /dssweb/local-perl/lib/site_perl/5.8.3/GD:
 total 130
 drwxr-xr-x   4 dssweb   dssdev96 Jul 30 10:30 .
 drwxr-xr-x  45 dssweb   dssdev  2048 Aug  3 10:56 ..
 drwxr-xr-x   2 dssweb   dssdev  1024 Jul 30 10:30 Graph
 -r--r--r--   1 dssweb   dssdev 45395 Jul  1  2003 Graph.pm
 drwxr-xr-x   2 dssweb   dssdev96 Jul 30 10:29 Text
 -r--r--r--   1 dssweb   dssdev 16996 Jun 18  2003 Text.pm
 
 /dssweb/lib: 
 -rw-r--r--   1 dssweb   dssdev708028 Jul 30 11:21 libgd.a
 -rwxr-xr-x   1 dssweb   dssdev   717 Jul 30 11:21 libgd.la
 - libgd.so.2.0.0
 lrwxrwxrwx   1 dssweb   dssdev14 Jul 30 11:21 libgd.so.2 - 
 libgd.so.2.0.0
 -rwxr-xr-x   1 dssweb   dssdev484989 Jul 30 11:21 libgd.so.2.0.0
 lrwxrwxrwx   1 dssweb   dssdev10 Jul 28 16:18 libpng.a - 
 libpng12.a
 lrwxrwxrwx   1 dssweb   dssdev11 Jul 28 16:18 libpng.so - 
 libpng.so.3
 lrwxrwxrwx   1 dssweb   dssdev17 Jul 28 16:18 libpng.so.3 - 
 libpng.so.3.1.2.5
 -rwxr-xr-x   1 dssweb   dssdev170112 Jul 28 16:18 libpng.so.3.1.2.5
 -rw-r--r--   1 dssweb   dssdev192464 Jul 28 16:18 libpng12.a
 lrwxrwxrwx   1 dssweb   dssdev19 Jul 28 16:18 libpng12.so - 
 libpng12.so.0.1.2.5
 lrwxrwxrwx   1 dssweb   dssdev19 Jul 28 16:18 libpng12.so.0 - 
 libpng12.so.0.1.2.5
 -rwxr-xr-x   1 dssweb   dssdev170116 Jul 28 16:18 
 libpng12.so.0.1.2.5
 
 
 
 On Wed, 4 Aug 2004, Wiggins d Anconia wrote:
 
  Date: Wed, 4 Aug 2004 08:30:31 -0600
  From: Wiggins d Anconia [EMAIL PROTECTED]
  To: Isarin Sathitruangsak [EMAIL PROTECTED],
[EMAIL PROTECTED]
  Subject: Re: GD.pm and GD::Graph
  
 
 
  Hello.
 
  Could someone could shed some light what I should do.  Please point
me if
  I should send to a different list.
 
  Although my script ran fine on the command line.  I've got the
following
  errors when running my script on apache
 
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146]
Premature end
  of script headers: graph
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Uncaught
  exception from user code:
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] \tCan't load
  '/dssweb/local-perl/lib/site_perl/5.8.\
  3/sun4-solaris/auto/GD/GD.so' for module GD: ld.so.1:
  /dssweb/local-perl/bin/perl: fatal: libgcc_s.so.1: open \
  failed: No such file or directory at
  /dssweb/local-perl/lib/5.8.3/sun4-solaris/DynaLoader.pm line 229.
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146]  at
  /dssweb/local-perl/lib/site_perl/5.8.3/GD/Graph\
  /pie.pm line 20
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Compilation
  failed in require at /dssweb/local-perl\
  /lib/site_perl/5.8.3/GD/Graph/pie.pm line 20.
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] BEGIN
  failed--compilation aborted at /dssweb/local-\
  perl/lib/site_perl/5.8.3/GD/Graph/pie.pm line 20.
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] Compilation
  failed in require at /dssweb/apache2/cg\
  i-bin/tst/graph line 6.
  [Tue Aug 03 15:54:14 2004] [error] [client 172.16.140.146] BEGIN
  failed--compilation aborted at /dssweb/apache\
  2/cgi-bin/tst/graph line 6.
 
  Thanks,
  Isarin
 
 
  To avoid the internal server error you could use fatalsToBrowser. But
  your error is because GD can't be loaded, specifically because it may
  not have been installed correctly, or libgd is either not found or not
  installed.  Did you install GD through CPAN or using the standard 4 step
  build process? Did 'make test' succeed?  Is libgd installed and in a
  normal location? You may need to provide

Re: File upload question

2004-07-27 Thread Wiggins d Anconia
 On Tue, Jul 27, 2004 at 12:37:11PM -0400, Sean Davis wrote:
  if ($q-param('upload_file'))  {
my $fh=$q-upload('upload_file');
^^
 
 Perhaps that should be param, not upload. I'm not familiar with an
 upload method in the CGI module.
 
 

Please check the docs, the 'upload' method is new as of version 2.47,

http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm#CREATING_A_FILE_UPLOAD_FIELD

But very much there. I use it. Didn't see anything in my first glance at
the code though.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: A question on Radio buttons in the CGI::Form package

2004-07-27 Thread Wiggins d Anconia
 Hi,
 
I am trying to generate radio buttons using the CGI::Form package.
 My radio buttons need to be vertically aligned with some other HTML
 elements in between them. For e.g.
 
Radio 1
 some HTML elements
Radio 2
 
This obviously precludes me from using the 'radio_group' method as
 that does not allow me to insert other elements in between. 
 
I tried using 'radio' but that seems an unrecognized method.
 
So my question is, how do I construct independent radio buttons
 using the CGI::Form module?
 
 Thanks,
 Sharad
 

Not sure what the CGI::Form package is. If you mean using CGI.pm it
appears you can call radio_group in list context to receive an array of
button elements see the very last part of the docs at,

http://search.cpan.org/~lds/CGI.pm-3.05/CGI.pm#CREATING_A_RADIO_BUTTON_GROUP

If this won't work, theoretically you could create multiple single
element radio_groups with the same name... though I make no guarantees,
check the HTML source.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: CPU load/server resources.

2004-07-14 Thread Wiggins d Anconia
 On Tue, 13 Jul 2004 15:30:36 -0600
 Wiggins d Anconia [EMAIL PROTECTED] wrote:
 
   
   I had a script for which my previous host cancelled my account
   saying
  it's a resource hog and using more than 50% resources of the server
  (shared hosting).
   
   Yep, there were some faults in the script. I modified it and they
  restored the account.
   
   But now I am looking for some script/subroutine within the script
   that
  can give me the CPU/resource usage when the script runs?
   
   I have NO idea about it.
   
   Can anyone help me with it?
  
  This tends to be a very system dependent thing.   I find it odd that
  you would need to run a script in such an environment, isn't that what
  the hoster does?  Or are you talking about the resource usage of the
  script specifically?
  
  In any case, give us more information about your platform.  If it is
  Unix can you read from /proc?
 
 yes, use:
 
 **
 open (F, /proc/$$/stat) || die error opening /proc/$$/stat: $!\n
 # $$ is current PID
 @content = split /\s+/, F;
 close F;
 print join(\n,@content), \n;
 **

That's going to be pretty ineffective on Windows I suspect, or on a
system either without /proc or where /proc has not been mounted.

 
 all YOU need to find out now is what what each element means... and
 share your wisdom with us. well, I'd like to know. ;)
 

man proc

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: CPU load/server resources.

2004-07-13 Thread Wiggins d Anconia
 
 I had a script for which my previous host cancelled my account saying
it's a resource hog and using more than 50% resources of the server
(shared hosting).
 
 Yep, there were some faults in the script. I modified it and they
restored the account.
 
 But now I am looking for some script/subroutine within the script that
can give me the CPU/resource usage when the script runs?
 
 I have NO idea about it.
 
 Can anyone help me with it?

This tends to be a very system dependent thing.   I find it odd that you
would need to run a script in such an environment, isn't that what the
hoster does?  Or are you talking about the resource usage of the script
specifically?

In any case, give us more information about your platform.  If it is
Unix can you read from /proc?

How were you doing this previously?  You state that you fixed the script
and the account was reactivated, are you looking for further
improvements?  If so, post the script

Help us to help you...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Fwd: Re: how to call an application in cgi and let it run in web browser

2004-07-12 Thread Wiggins d Anconia
 Xiangli Zhang wrote:

snip

 
 Aha, are you trying to open the vi editor? Then I don't think I'm able
 to help you; not sure if it's even possible to do that from a CGI script.
 
  main pagetest.pl [readonly] 6L,
  95C#!/usr/bin/perl -w print Content-Type: text/html\n\n;
  print this is phrap testing file; ~ ~ ~
  ~ ~ ~ ~ ~ ~ ~
  ~ ~ ~ ~ ~ ~ ~ 
  Vim: Error reading input, exiting... Vim:
  Finished.  Software error:
  
  'vi test.pl' failed: 256 at /var/www/cgi-bin/jun06_uploadFile.cgi
  line 78.
 
 Among all the funny characters, I notice [readonly]. Can it possibly
 be that you need to change the permissions for the file to make it
 editable by CGI?
 
 But, to be honest, I don't think that's enough. Hopefully somebody
 else is willing to jump in and advise.


'vi' is a terminal based application, which is generally expecting to do
I/O on a terminal, or in a console/x window (in the case of gvim). 
Presumably you could manage a vi session with something like expect or
something, but that sounds like a nightmare.  Since 'vi' is just a file
editing app, and you are running over a stateless CGI session the normal
method would be to load a page with a form, drop the contents of the
file into a textarea and have that form submit back to a script that
stores the file.  Granted, then you can't use all the shortcuts and key
combos of Vi, but then you are doing this over a stateless connection
which has its benefits.  

What are you really trying to do...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: please help to solve the problem: Error message: Premature end of script headers

2004-07-09 Thread Wiggins d Anconia
 Hi all,
 
 I have received the respond from the Apache stated that:
 
 The server encountered an internal error and was unable to complete
your request. 
 
 Error message: 
 Premature end of script headers: testing.cgi 
 
 If you think this is a server error, please contact the webmaster. 
 
 Please help me to solve this problem.
 
 PS. the path of the perl is correctly pointed.
 

Please use a real return address.

This is an FAQ, 

perldoc -q 'Server Error'

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Mailing Script

2004-07-08 Thread Wiggins d Anconia
 Gunnar Hjalmarsson wrote:
 
  Werner Otto wrote:
 
  Gunnar Hjalmarsson wrote:
 
 
  Add this line at the top of the script:
 
  use CGI::Carp 'fatalsToBrowser';
 
 
  The permissions on running.pdf was not correct. It helps if you
  know how to debug!
 
 
  Talking about debugging... You should get the habit of including:
 
  use strict;
  use warnings;
 
  in the beginning of every Perl program you write. (They would not have
  made a difference to solve this particular problem, but they may do so
  next time.)
 
 Yes, I tend not to do that Makes my code look beter when it 
 runs. Just fooling myself  I guess.
 

You are, and beauty is in the eye of the beholder, your code may look
better to you, but to the computer it definitely doesn't.  Perfect
example, given,

open(test123, /home/staff/wot/public_html/perl/test.csv) or die
(File test.csv could not be opened for writing);

What do you think the following three lines do?

flock(test, 2);
seek(test, 0, 2);

close(test);

Or how about your error conditions,

 or die Error adding $file_gif: $!\n;
 or die Error adding $file_zip: $!\n;

So much for including the filename.

'strict' and 'warnings' will save you hours of headache.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Mailing Script

2004-07-08 Thread Wiggins d Anconia
 Wiggins d Anconia wrote:
 

snip

   
 
 When I include warnings and strict is give me allot of warnings. What do 
 they mean?
 
 h1Software error:/h1
 preGlobal symbol quot;$surnamequot; requires explicit package name 
 at ola.cgi line 15.

snip

 ola.cgi had compilation errors.
 /pre
 p
 For help, please send mail to this site's webmaster, giving this error 
 message
 and the time and date of the error.
 
 /p

snip

 [Thu Jul  8 15:05:23 2004] ola.cgi: Global symbol $msg requires 
 explicit package name at ola.cgi line 90.
 [Thu Jul  8 15:05:23 2004] ola.cgi: ola.cgi had compilation errors.
 
 

Whenever you come across an error/warning/diagnostic message you don't
recognize or understand you can find its meaning in,

perldoc perldiag

Global symbol %s requires explicit package name
(F) Youâve said use strict vars, which indicates that all variables
must either be lexically scoped (using my), declared beforehand using
our, or explicitly qualified to say which package the global variable
is in (using ::).

In this case you are not declaring your variables, adding a 'my' before
them will fix the issue in most cases.

perldoc -f my
perldoc strict
http://perl.plover.com/FAQs/Namespaces.html

For more, especially that last.

If you start out in the habit of including 'my' before your variables,
then when you screw up the name of one of them, then strict will yell at
you.  This is only one very small example of how it can help you and
save you time, no more hunting for misspelled variables.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: popup_menu

2004-06-25 Thread Wiggins d Anconia
 Hi have the following code:
 
 print popup_menu(-name='hosts',-values=['1','2','3'],-default=['2']);
 
 the default value doen not seem to appear, any reason why?
 
 Regards
 Otto
 

Does not appear or is not selected?  I couldn't reproduce the former,
the latter is because you are providing -default with an array
reference, but it should be a single scalar value (remove the [] from
around '2').

Does this help?

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: popup_menu

2004-06-24 Thread Wiggins d Anconia
 Hi All,
 
 Any idea how to disable a popup_menu?
 

This is client side, javascript or XForms.  See the 'disabled'
attribute, but this will be highly browser dependent.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Unexpected CGI and HTML

2004-06-24 Thread Wiggins d Anconia
 I have an odd result (at least to me) that I can't explain.  I am using
 CGI::Application and have the following subroutine that returns
$output, the
 html for the page (only a toy example, but illustrates the point, I
think):
 
 sub return_probe_details {
   # Get OligoMap object (actually, just inherited from CGI::Application)
   my $self = shift;
   
   # Get CGI Query Object
   my $q = $self-query();
 
   my $output = '';
   $output .= $q-start_html(-title   = 'Query Human Oligo Probe',
 -BGCOLOR = 'aquamarine');
   $output .= $q-startform();
   $output .= 'hello';
   $output .= 'p';
   $output .= $q-end_form;

The call to 'end_form' is adding the div tags.  Apparently CGI likes to
wrap forms in a div.  Normally you would manipulate the form by adding
fields, etc. using the CGI methods, those fields would then show up
within the form, within the div.  It is this kind of over control that
prevents me from using the HTML building components of the CGI module.

HTH,

http://danconia.org


   $output .= $q-end_html();
 
   return $output;
 }
 
 The HTML output is:
 
 ?xml version=1.0 encoding=iso-8859-1?
 !DOCTYPE html
 PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
  http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd;
 html xmlns=http://www.w3.org/1999/xhtml; lang=en-US
 xml:lang=en-USheadtitleQuery Human Oligo Probe/title
 /headbody bgcolor=aquamarineform method=post
 action=/cgi-bin/oligo.pl enctype=application/x-www-form-urlencoded
 hellopdiv/div
 /form/body/html
 
 From where is the tagset div/div coming?  It isn't a problem here, of
 course, but if I try to use this with HTML::template, it is causing
 problems.  Any ideas?
 
 Thanks,
 Sean
 
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Can't coerce array into hash at - error

2004-06-17 Thread Wiggins d Anconia
 Hi All,
 
 I am trying to fill a popup_menu with values retrieved from my database 
 and get the following error. Can't coerce array into hash at. As this is 
 the first time I'm doing this, could someone please assist in telling me 
 where I'm going wrong.

'at' what?  That would help.  Perl should be giving you a line number
that would help track down where the problem is. I couldn't see anything
on a quick glance but then usually I don't have to try and see where the
problem is, when Perl tells me.

 
 $db=wotdb;
 $host=test;
 $port=436;
 $userid=wot;
 $passwd=wot;
 $connectionInfo=DBI:mysql:database=$db;$host:$port;
 $dbh = DBI-connect($connectionInfo,$userid,$passwd) || die(Could not
get 
 connected!);
 
 my @ids = ();
 my %hostname = ();
 
 $query = SELECT * FROM hosts, ping_test where 
 hosts.hostname=ping_test.ping_hostname;

Why select * when you could just select what you need?

 $sth = $dbh-prepare($query);
 $sth-execute();
 my($hostname,$hostip,$hostport);
 
Are the other variables already declared?

$sth-bind_columns(\$hostname,\$hostip,\$hostport,\$ping_date,\$ping_time,\$ping_hostname,

\$ping_hostip,\$ping_bytes,\$ping_icmp_seq,\$ping_timems,\$ping_tot_pack_trans,

\$ping_tot_pack_rec,\$ping_perc_pack_loss,\$ping_conn_status);
 

Why are you binding the columns like this and then calling fetchrow_array?

 while(my($id,$hostname)=$sth-fetchrow_array)
 {

Personally to me it is easier to call fetchrow_hashref, then you don't
need to bind the columns or worry about a whole bunch of separate
variable names.  Which ends up looking something like,

while (my $row = $sth-fetchrow_hashref) {

$hostname{ $row-{'id'} } = $row-{'hostname'};

push(@ids,$id);
$hostname{$id} = $hostname;

Why the two variables? You can use 'keys' with the hash to reproduce the
same list below.

perldoc -f keys

 }
 
 print start_form,;
 print br;
 print centertable border=0 cellpadding=3 cellspacing=1;
 print tr;
 print popup_menu('name'='hostname', 
 'values'=[EMAIL PROTECTED],'default'=$hostname,'labels'=\%hostname);
 print /tr;
 print /table/center;
 

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Writable dirs

2004-06-15 Thread Wiggins d Anconia
 Hi,
 
 a friend of mine uses a certain directory to upload files to. This
directory has write permissions for all, since his cgi script has to
store the files in it.


This is a common myth. The directory only has to have the permissions it
needs, how much control you have over the directory and the box is going
to determine that, as well as what other users need access to the same
files.  In general the directory will have to be writable by the user
the web server is running as.  In many cases this will be an 'apache'
user, an 'httpd' user, sometimes 'nobody', etc. but depends on the
system, the installation, and configuration of the web server software.
In the case that other users on the system need write access to the
directory as well, a good approach would be to create a new group, add
the web server as well as the other users to the group and then provide
group writable permissions to the directory.  Regardless you are leaving
the web server open to writing to a directory, which really isn't as big
a deal as people make it out to be.  No server is secure, period. Having
said that, you can limit your exposure, for instance make sure the
directory where the files are stored is not script aliased so that
anything uploaded can be executed, additionally move the directory out
of the document root so that anything uploaded can't even be served
directly. Make sure that the archaic 'PUT' and 'DELETE' methods aren't
accepted by the web server.  
 
 He does not believe that this could be a security issue. Is there a
simple method to delete something from this directory (or write
something to it without using his script) to prove him wrong?
 

Try the 'PUT' or 'DELETE' request methods.  It *is* a security issue,
*but* is it the biggest one? Is it worth the effort versus the risk? 
Only he (and you) can decide...

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: joining form input in parser

2004-06-11 Thread Wiggins d Anconia
 HI
 
 Any help will be greatly appreciated.
 
 The below statement is my parsing statement. It may be antiquated but it
 works.

If it does then you wouldn't need to ask right?  It is antiquated, very,
and shouldn't be used when there are much better ways to do this,
specifically the CGI module.

 
 I want to process input from a select form that has two names and two name
 values
 name=group1 , value1=
 name=group2 , value2=
 
 
 IN the below statement, how do I process this information so that:
 
 a]  if a user selects both group1 and group2 from the drop lists, then it
 will join them together and parse both groups as one.
 
 b] if a user selects either group1 or group2 the it parses either group.
 
 I have tried to use . for joining strings (concatenate)
 
 

snip

Switch to the CGI module

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: joining form input in parser

2004-06-11 Thread Wiggins d Anconia
Only re-inforced what you already stated, yep the truth hurts, doesn't
mean it isn't the truth.  Don't worry, I won't, and good chance others
won't either.

http://www.catb.org/~esr/faqs/smart-questions.html

http://danconia.org


 Having viewed your website, I can understand your reply.
 Next time. don't bother.
 
 ##
 - Original Message - 
 From: Wiggins D Anconia [EMAIL PROTECTED]
 Newsgroups: perl.beginners.cgi
 To: William Kolln [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Saturday, June 12, 2004 1:58 AM
 Subject: Re: joining form input in parser
 
 
   HI
  
   Any help will be greatly appreciated.
  
   The below statement is my parsing statement. It may be antiquated
but it
   works.
 
  If it does then you wouldn't need to ask right?  It is antiquated, very,
  and shouldn't be used when there are much better ways to do this,
  specifically the CGI module.
 
  
   I want to process input from a select form that has two names and two
 name
   values
   name=group1 , value1=
   name=group2 , value2=
  
  
   IN the below statement, how do I process this information so that:
  
   a]  if a user selects both group1 and group2 from the drop lists, then
 it
   will join them together and parse both groups as one.
  
   b] if a user selects either group1 or group2 the it parses either
group.
  
   I have tried to use . for joining strings (concatenate)
  
  
 
  snip
 
  Switch to the CGI module
 
  http://danconia.org
 
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Current Value

2004-06-10 Thread Wiggins d Anconia
 Hi,
 
 When Im looping through as cgi that loops through records in a table,
I do 
 a print statement of a variable.
 Example
 
 if($condition eq G)
 {
print $field1;
 }
 
 why does it print all the occurances of the fields in the table, as only 
 one of them fits the criteria of equaling G. Is there some sort of way 
 to only print the value that is true for that instance?
 

Show us some more code. 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Printing a multipart HTML output

2004-06-09 Thread Wiggins d Anconia
I suppose it is possible that it could, but remember Outlook is a mail
client, specifically a MIME compliant one (well as much as Lookout is
compliant with anything), which means it has to be able to deal with
multiple attachments in a single request.  But in the case of the
browsers most often they don't deal with multiple responses for a single
request, rather they render a single request assuming that they will
need to make further requests in a live type of session.  

I still don't understand why the HTML file can't request back to a
server for the images? You still only need to provide one file, granted,
and a remote host...

http://danconia.org

 Hi,
 
 Thanks for responding.
 I need to create that multipart page because I am trying to create a
single html file with a financial analysis which includes pictures and I
don't want to be necessary to send more files to the clients.
 But I was sure that if Outlook Express can read such a page, Internet
Explorer and other browsers will be able to read it for sure.
 
 Thanks.
 
 Teddy
 
 - Original Message - 
 From: Wiggins d Anconia [EMAIL PROTECTED]
 To: Octavian Rasnita [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Tuesday, June 08, 2004 6:18 PM
 Subject: Re: Printing a multipart HTML output
 
 
   Hi all,
   
   Please tell me how can I create a multipart html file that
includes html
   text and images.
   I know that Mime::Lite can create such a thing for sending an
email with
   attachments, but I don't know if it is possible to use it for creating
   common HTML pages with multipart content.
   
  
  I was not aware that this was even possible. It does appear that some
  browsers, specifically in the Netscape class could handle this at least
  once upon a time.  I found a link through google to chapter 13 of the
  definitive HTML book from ORA (illegal copyright violation so I will not
  provide it), that talks about how to do this, specifically in an HTTP
  push application (like streaming media, etc.) so apparently it can
be done.
  
 
 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Printing a multipart HTML output

2004-06-08 Thread Wiggins d Anconia
 Hi all,
 
 Please tell me how can I create a multipart html file that includes html
 text and images.
 I know that Mime::Lite can create such a thing for sending an email with
 attachments, but I don't know if it is possible to use it for creating
 common HTML pages with multipart content.
 

I was not aware that this was even possible. It does appear that some
browsers, specifically in the Netscape class could handle this at least
once upon a time.  I found a link through google to chapter 13 of the
definitive HTML book from ORA (illegal copyright violation so I will not
provide it), that talks about how to do this, specifically in an HTTP
push application (like streaming media, etc.) so apparently it can be done.

This is going to be very, very browser implementation specific I
imagine, because the browser has to know how to deal with multipart data
transmissions, etc. but assuming your target app can handle it then it
appears to work almost exactly as MIME does in e-mail. Aka you specify a
content-type of multipart/*, with a boundary string, then just print
your multiple parts separated by the boundary. Having said that you
might be able to coerce MIME::Lite into doing this, though it might be
overkill, since you may not have to deal with encoding, etc. since it
isn't mail going through an intermediary.  Either way you should look
into some of the server-push applications available and see what they do.

Of course, not sure why you would want to do this with text and images
anyways, why not just serve up a normal img tag?

HTH,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: POST and GET and CGI.pm

2004-06-08 Thread Wiggins d Anconia
 Greetings,
 
 While reading some of the Perl newsgroups, I've seen a few examples of
 people getting CGI parameters by either parsing the query-string (for
GETs)
 or reading in some of the content (for POSTs). I've been working with CGI
 (using Perl) for a little while now and I've always used the param()
method
 in
 CGI.pm and it is working for both GETs and POSTs. I'm wondering if I'm
 missing something and if there are times when using the CGI.pm param()
 method is not advised. Thanks.
 

You're not the one missing out.  'param' specifically isn't always the
best way, for instance sometimes I like to pull them all at once with
the 'Vars' method.  Or in the case of file uploads I generally use the
newer upload interface methods.  Point being, you should rarely if ever
need to parse the query string/post yourself.  To me, using the CGI
module would never be the wrong way to do it, whereas the other would
be.  mod_perl not in consideration at this point, aka there is the
Apache::Request (I think?) for that, etc.

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: How do I document my perl code?

2004-06-07 Thread Wiggins d Anconia
 Is there any standard for documenting functions?
 For example, in Javadoc, there is a specific format
 that uses the @ for identifying and formating the
 function argruments. It looks like POD much more
 freeform and is not nearly so detailed. Is that true?
 Siegfried
 
 P.S. Sorry Charles, I accidently replied to you personally.
 

Could be, I haven't used Javadoc. You might find Mark Overmeer's OODoc
interesting,

http://perl.overmeer.net/oodoc/
http://search.cpan.org/~markov/OODoc-0.10/lib/OODoc.pod

Or take a look at the Docs category to see some of the things that can
be done with Pod:

http://search.cpan.org/modlist/Documentation

This is sort of off topic for a CGI list, might be better posted to the
[EMAIL PROTECTED] list instead.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: POST method with perl module

2004-06-04 Thread Wiggins d Anconia
 Good morning,
 
 im trying to set up a tools module for my modperl environment.
 My function get_vars should get all passed variables with the following
 snipplet:
 
  if($ENV{'REQUEST_METHOD'} eq GET){
   $my_data = $ENV{'QUERY_STRING'};
  }
  else {
   $data_length = $ENV{'CONTENT_LENGTH'};
   $bytes_read = read(STDIN, $my_data, $data_length); (*)
  }
 
 This works great in a function of a script.
 If i put the code into a seperate module (which i use in my script), only
 the GET method works, so i think there is a problem in the (*) line.
 
 So, my question: How do i capture the POST variables from within a module.
 

Um, use the CGI module or a more mod_perl friendly (if such a thing
exists) module that will already do this?

Are you exporting $my_data?  You would need to show us more of your
module, and how you are accessing into it.  Are you using 'strict' and
'warnings'?  

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




OT: mysql vs. postgresql (was: Re: CGI and mySQL book, any recommendation.)

2004-06-01 Thread Wiggins d Anconia
  Wiggins == Wiggins D'Anconia [EMAIL PROTECTED] writes:
 
 Wiggins Agreed. I have requested this from him before, but didn't get
much.
 
 I haven't responded because I've been using the net at 40 cents per
 minute from a satellite link on a ship this past week, and right now
 I'm using a 10 cents per minute cellphone modem.  When I get back to a
 free link, I'll post more.


That is a very good reason, actually I was referring to back in
December, apparently that was the beginners list not the beginners-cgi, see:

http://groups.google.com/groups?hl=enlr=ie=UTF-8selm=3FD34DFD.7080207%40danconia.org

 
 But in short, MySQL was great when it was the only game in town.
 But PostgreSQL has leapfrogged MySQL now in every area including
 features, performance, *and* license.  There's no point in starting
 a new project with MySQL, *except* for legacy.

Ok, license is a good cause.  When you state features and performance,
are there specifics, etc?  I am wanting to believe you, and you state
ignorance as a reason, and that is probably the biggest, so enlighten me
so that I am compelled to switch.  

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: CGI and mySQL book, any recommendation.

2004-05-31 Thread Wiggins d'Anconia
Paul Archer wrote:
Yesterday, Randal L. Schwartz wrote:

By the way... it's consensus amongst experts that MySQL has hit
nearly end-of-life.  If you're starting a new project, use PostgreSQL
instead.  A real Database... not a database wannabe.
The only reason to use MySQL these days is ignorance or legacy.
I've done a quick search on Google (mysql vs postresql) and all the hits
I've seen, including a very detailed comparison of the two by Sourceforge
principal Tim Perdue give both high marks. I haven't read anything so far
supporting your position (MySQL is a wannabe and nearly end-of-life).
While I am not refuting your claims, I would appreciate a little evidence in
support of these claims so that I can better judge for myself.
Agreed. I have requested this from him before, but didn't get much.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: String Variable

2004-05-20 Thread Wiggins d Anconia
 hi there,
 
 I've got the following example:
 
 system (ping -a $hostname | cut -c20-30);
 
 how do I get the following result which is (is alive) into a string 
 variable as I keep on getting 0
 
 Please help.
 

Seems like you might want to post these types of things to
[EMAIL PROTECTED] as they don't have a lot to do with CGI.

'system' returns a combination of exit values from the command. The 0
indicates that the command was successful.

perldoc -f system

For more on parsing return values.

Since you are looking for the output from the command you should
consider using backticks also known as the qx operator,

perldoc perlop (search for qx)

Additionally you may want to read through,

perldoc perlipc
perldoc IPC::Open3

If you are still stuck as it introduces Open3/Open2, etc.

Point your additional questions to the beginners group, lots of people
there ready to help.

HTH,

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: writing to a file

2004-05-20 Thread Wiggins d Anconia
 Hi
 
 I have a very simple cgi script that I have put onto a webserver. I want
 to write to a log file when it is run. My problem is that the open file
 command always fails (and I get the openFailed message in my browser).
 (even if i try opening for input it fails). I have created the file called
 log.dat in the same folder as the script (cgi-bin) and set attributes to
 read/write using chmod.
 
 Is there any easy way I can find out why the file cant be opened (is it
 permissions?). 

You can get further help on what you need to know by using the $!
variable in your exit code. $! is a special variable (perldoc perlvar)
that tells you the reason why a particular action fails. See below.

Do I need to fully qualify the filepath? if so how do I do
 that? Is it because I'm not allowed to have log files in the cgi-bin
 folder?
 

Shouldn't, depends, possibly but not necessarily.

 Any help for an absolute beginner appreciated.
 steve
   
 
 #!/usr/local/bin/perl
 

use strict; #always
use warnings; #usually

 $Msg = ;

my $Msg = '';

 
 if( ! open (LOGFILE,  log.dat) ){
$Msg = OpenFailed;

$Msg = Open failed: $!;

$Msg will now include the human readable version of why the open fails.

 }
 else {
   $Msg = OpenWorked;
   #print LOGFILE $Msg;
   close (LOGFILE) ;
 }
 
 print Content-type: text/html\n\n;
 
 print EOF;
 HTML
 
 HEAD
 TITLEResult/TITLE
 /HEAD
 BODY
 TABLE DIR=LTR BORDER
 CAPTION$Msg/CAPTION
 TR
 TD$Msg/TD
 /BODY
 /HTML
 EOF
 

Give it a shot and see if that helps, if not post again...

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: writing to a file

2004-05-20 Thread Wiggins d Anconia
Please bottom post...

 Also, the first line,
 
  #!/usr/local/bin/perl
 
 What if the server isn't a UNIX server, but an IIS server? Doesn't
this line
 have to change?
 

Careful, Unix is an OS type, IIS is an application software group.

It is my understanding (which could be very wrong) that IIS/Perl will
just ignore the line, IIS will have a pre-registered handler for the
script call, then Perl should recognize the line for what it is and skip
it, (with the small exception that flags provided on the line may be
included, such as -T).

Please test this before taking my word for it though :-)...

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: replacing characters in a string

2004-05-19 Thread Wiggins d Anconia
 I cant find a simple perl function to replace characters in a string. Im
 trying to inserts strings like bob's into a database and need to convert
 that to bob''s so that sql doesnt whine when i do an insert.
 
 Any suggestions?
 

There are regex's and the tr/y functions/operators? But in this case you
shouldn't use either and instead use binding (assuming you are using
DBI, are you?).  Binding allows DBI/DBD which is very smart decide how
the data needs to be quoted rather than attempting to do this manually
which usually just leads to problems.

http://search.cpan.org/~timb/DBI-1.42/DBI.pm#Placeholders_and_Bind_Values

Alternatively if binding can't be used, there is the 'quote' method for
handling this specific task (on same page as above).

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how-to log in proceedure

2004-05-19 Thread Wiggins d Anconia
 
 
 I working on a rather complex database cgi program and i've never done
much work with user logins. Ideally I woudl love to set up a secure
login which will verify passwords aggaints data stored in an SQL table.
The modle I wish to use ie below. The area I need help with is the
proper way to set and retrieve secure cookies.
 
 retrieve pw:login from form.
 compare to stored password.
 if match encrypt a string which is stored in the database then set the
same string as a cookie with date and IP.
 use this cookie to authenticate each subsiquent page until logout.
  can someone point me to a good how to ?
 

Security is always relative.  Cookies are only secure (in one sense of
the word) when passed over an https (like) connection, as your password
should be too, otherwise anyone can sniff the password and be able to
retrieve their own authenticated cookie. 

It sounds like you have a decent start, step 1 is easily handled with
the CGI module.  Comparing the password is easily handled with DBI to
connect to your database. (Minor point, be sure to store the password in
an encrypted/hashed way rather than directly.)  Step 3 is a little odd,
why are you storing the string in the database? Generally I don't think
this is going to provide security, aka all I have to do is guess the
string you stored and set a cookie manually, then I have an
authenticated session.  Generally the idiom goes something like, create
a private key (aka a passphrase or something that no one else knows),
take the key and some reproducible non-private information (such as the
user name/id) and hash the two together. Provide the hash, and the
information used to create it (NOT the private key!) in the cookie. Then
during the requests check to see if the information provided back by the
user from the cookie can be used to reproduce the same hash using the
same private key as before.  If the hash is reproduced then the user is
authenticated. Assuming no one else has the private key, then the hash
should be unique for the user and the private key should be
non-guessable from the hash, generally if this holds an attacker can't
produce a string that will authenticate correctly. In general using the
IP address in this is not a good idea unless you know precisely what IP
a particular user is going to come from.  The complexity of your hash
inputs can vary what you can do, aka adding expirations, etc.

I don't take credit for this, the idiom is yanked from the Writing
Apache Modules with Perl and C book from ORA, it provides an excellent
discussion as well as code samples of how to implement this.

I imagine there are also a number of modules available from CPAN that
provide this functionality, Apache::Session rings a bell.

http://search.cpan.org/~jbaker/Apache-Session-1.6/Session.pm#Tracking_users_with_cookies

My recent implementation looks like this, the following is untested and
I am not a security professional,

Thoughts?

http://danconia.org


use constant CONFIG_AUTH_KEY = 'Secret passphrase goes here';
use Digest::SHA1;

#
# generate an authentication string that can be used to verify if
# a user is who they say they are without a database lookup
#
sub authentication_string {
my $self = shift;

my $uid = $self-id;
my $time = time;
my $expires = 2592000;

my $data = join(':', CONFIG_AUTH_KEY, $time, $expires, $uid);
my $hash = Digest::SHA1::sha1_hex($data);

return uid=$uid time=$time expires=$expires hash=$hash;
}

#
# class method to verify an authentication string, returns
# an exception on failure or the user id of the string on
# success
#
sub check_auth_string {
my $class = shift;
my ($auth) = @_;

unless (defined $auth) {
die Missing arg: auth string;
}

# deparse auth string then check user cache
my @auth = split(' ', $auth);
my %auth;
foreach my $element (@auth) {
if ($element =~ /^(.+)=(.+)$/) {
$auth{$1} = $2;
}
}
foreach my $key ('uid', 'time', 'expires', 'hash') {
unless ((defined $auth{$key})  ($auth{$key} ne '')) {
die Cookie corrupt: $key;
}
}
my $testdata = join(':', CONFIG_AUTH_KEY, $auth{'time'},
$auth{'expires'}, $auth{'uid'});
my $testhash = Digest::SHA1::sha1_hex($testdata);

unless ($testhash eq $auth{'hash'}) {
die Auth string corrupt;
}

return $auth{'uid'};
}


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




OT: Re: Browsers?

2004-05-14 Thread Wiggins d Anconia
 
 On 14 May 2004, at 15:58, Werner Otto wrote:
 
  Is there any way in which I can make my site appear the same in all 
  available browsers?
 
 No.
 
 (I'd be very impressed if you could even make it appear similar in 
 Emacspeak, JAWS, Firefox, and Lynx).
 
 Work to public standards, then tweak for bugs in popular browsers.
 
 http://www.allmyfaqs.com/faq.pl?AnySizeDesign
 
 And this doesn't really have much to do with CGI does it?
 

An excellent link!  Tried for 3 years at an interactive agency to get
their designers to understand these points, failed miserably.  

Now I work maintaining a system daemon, no one much cares what he looks
like, only whether he is grumpy ;-)...

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Print statement

2004-05-13 Thread Wiggins d Anconia
 Hi,
 
 Is there any way in which I can tell perl where to print my data. i.e.
 
 Here is my .html

That doesn't look like HTML to me?  I am thoroughly confused, can you
provide better information about the issue?

As a hunch you might want to check out one of the various template kits,
Template-Toolkit is a well respected one it seems,

http://search.cpan.org/~abw/Template-Toolkit-2.13/

 ---
 
 Header
 ---
 Body header in orig. place
 
 
 ---
 
 if ($var == 1)
 {
   bod_head = New Header - Override current body header;
 }
 else
 {
   bod_head = Body header in orig. place;
 }
 

bod_head needs a sigil.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Escaping quotes in variable content

2004-05-11 Thread Wiggins d Anconia
Please bottom post...

 This is better, replace the quotes with nothing and then build your input
 tag.
 

Better?  You have destroyed the data.  Stay away from my information
with your substituitions.

[snip code that should not be used in production]

 
 I hope this helps 

Anyone reading the archive, please don't do this.  escapeHTML or
HTML::Entities should do very well.

http://danconia.org

 
 
 -Original Message-
 From: Jan Eden [mailto:[EMAIL PROTECTED] 
 Sent: 11 May 2004 04:21 PM
 To: David Dorward; Perl Lists
 Subject: Re: Escaping quotes in variable content
 
 Hi David,
 
 David Dorward wrote on 11.05.2004:
 
 On 11 May 2004, at 14:58, Jan Eden wrote:
 how can I escape quotes within a variable's content? I use the
 following directive to fill an HTML form: input type=text
 name=frage_text size=100 value=$frage_text / Unfortunately,
 if $frage_text contains a double quote, the browser will stop
 displaying the string at that point. I tried to escape the quotes
 in a Perl way $frage_text =~ s//\\/g;
 
 In HTML characters are 'escaped' by converting them to entities.
 entityName; Quote marks are quot;
 
 You probably want to use escapeHTML() from the CGI module.
 
 Doh. I have been working on the script for several hours now and
forgot the
 most simple things about HTML.
 
 Thanks,
 
 Jan



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




  1   2   3   4   >