RE: Little code fragment request (Is this code ok?)

2002-05-07 Thread Bob Showalter

> -Original Message-
> From: Rafael Cotta [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 07, 2002 2:15 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Little code fragment request (Is this code ok?)
> 
> 
> Well, after searching I come to this:
> 
> #---
> sub WriteLog
> {
>  open(OUTF,">>$filenamedate.dat") or die("Couldn't open 
> $filenamedate.dat
> for writing: $!");
> 
>  # This locks the file so no other CGI can write to it at the
>  # same time...
>  flock(OUTF,2);
 ^^^
You should import the constants from Fcntl instead
of using magic numbers:

   use Fcntl qw(:flock);

> 
>  # Reset the file pointer to the end of the file, in case
>  # someone wrote to it while we waited for the lock...
>  seek(OUTF,0,2);
   ^^
This is unecessary. When a file is opened in append mode,
writes always and only go to the end.

> 
>  print OUTF "$linha\n";
>  close(OUTF);
> }
> #---
> 
> Where $filenamedate will have something like "2002-05-06" and 
> $linha will
> contain the information I need to append to the file.
> 
> Will this code run fine on a website with several 
> simultaneous accesses?

Additional considerations:

1. Where is $filename coming from? If it's from outside the
script, you should run with -T and properly untaint it.

2. You shouldn't assume any particular current working directory
in the CGI environment. You need to specify a path name in your
open() or use chdir() to set a specific directory.

3. Perl 5.6 allows you to use the following form for open:

   open(my $fh, ">>$filename.dat") or die ...

This makes your code more modular as it avoids use of a global
filehandle.

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




(OT) RE: Matching string (here I am again)

2002-05-07 Thread John Brooking

Okay, what's the [2] doing? It appears to be saying to
match \d exactly two times, but I thought that would
be {2} instead. But changing your [] to {} leads to
the same problem as the original expression.

You probably know, Camilo, but since you didn't say,
let me guess at why Rafael's original RE did not work.
The problem seemed to be the use of "*" (zero or more)
when "+" (one or more) was probably meant. So the
original RE was asking if there are any ocurrences of
*ZERO OR MORE* characters followed by two digits and
the string ".html". The answer is yes, the substring
"01.html" of "djavan001.html" fits that criteria, as
it is ZERO characters followed by two digits, etc.
Changing the "*" to a "+" makes his original RE work
as intended, so there has to be at least one
character. This also prevents something like "99.html"
from matching, which I'm assuming from his description
is also desired.

--- Camilo Gonzalez <[EMAIL PROTECTED]>
wrote:
> Try /[a-z]*\d[2]/
> 
> -Original Message-
> From: Rafael Cotta [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 07, 2002 12:16 PM
> To: [EMAIL PROTECTED]
> Subject: Matching string (here I am again)
> 
> 
> First of all, special thanks to Drieux.
> 
> I need to check if a string with the following
> patern:
> 
> .html
> 
> Like "cae01.html" or "djavan10.html" (without
> quotes).
> 
> I tryied
> 
> $musica =~ /([a-z]*)[0-9][0-9]\.html/
> 
> but this matches "djavan001.html", when this should
> not.
> 
> Wich regexpr can I use? This time a link to a howto
> will be very welcome,
> once this is not the unique regexpr I'll need to
> build myself.
> 
> Rafael


__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




RE: Matching string (here I am again)

2002-05-07 Thread Camilo Gonzalez

Try /[a-z]*\d[2]/

-Original Message-
From: Rafael Cotta [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 07, 2002 12:16 PM
To: [EMAIL PROTECTED]
Subject: Matching string (here I am again)


First of all, special thanks to Drieux.

I need to check if a string with the following patern:

.html

Like "cae01.html" or "djavan10.html" (without quotes).

I tryied

$musica =~ /([a-z]*)[0-9][0-9]\.html/

but this matches "djavan001.html", when this should not.

Wich regexpr can I use? This time a link to a howto will be very welcome,
once this is not the unique regexpr I'll need to build myself.

Rafael





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

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




Matching string (here I am again)

2002-05-07 Thread Rafael Cotta

First of all, special thanks to Drieux.

I need to check if a string with the following patern:

.html

Like "cae01.html" or "djavan10.html" (without quotes).

I tryied

$musica =~ /([a-z]*)[0-9][0-9]\.html/

but this matches "djavan001.html", when this should not.

Wich regexpr can I use? This time a link to a howto will be very welcome,
once this is not the unique regexpr I'll need to build myself.

Rafael





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




Re: Accessing form elements before submit..

2002-05-07 Thread MARCOS LABORDE

You can do client processing in javascript but you can also put your values in hidden 
fields as you change your array of values, use one button for the final submit and 
other submit buttons disguised as preprocessing buttons.

>>> onkar sangoram <[EMAIL PROTECTED]> 05/07/02 06:58AM >>>
Hi ,
 I badly need ur help regarding to the CGI scripts.
 i have written one perl script to design a tree ,with
recursive function in it. I am accepting parameters
from the user () and then splicing the
array.The things are fine.
 But when i want to put it in the web page,there will
be a text-box fot input. But how can i access the
values entered by the user in the same script before
submit. Because after each input the array is
reforming.
 So is it possible to access the values of form
element before pressing submit button ??
 I really want this problem to be solved,
 please do help me.
Onkar

__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com 

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



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




(OT) Re: Accessing form elements before submit..

2002-05-07 Thread John Brooking

To expand a bit from a more general persective:

The important distinction here is what is client-side
and what is server-side. HTTP is a request/response
protocol. So the interaction looks like this:

  1) User (Client) requests page where your form is
  2) Server delivers that page
  3) User fills out the form
  4) User submits the form, resulting in another
request
  5) Server processes that request and delivers
another response

What it sounds like you are looking for is something
to allow the client browser to make some decisions
during step 3, while the user is filling out the form.
Since the last server response has completed (the page
was successfully delivered), and the next won't start
until the user submits, the client is on its own, and
no server-side technology (Perl or whatever) can help
at that point. You need a client-side technology.
That's JavaScript. (Not to be confused with Java,
which is an entirely separate language and is on the
server side.)

By the way, if you happen to look at Microsoft's
support side, you'll see references to JScript, which
is IE's implementation of JavaScript (although
JavaScript works in IE too). IE also supports VBScript
(similar syntax to Visual Basic) on the client. But of
course browser-dependent technology is a big no-no
unless you are programming for internal people only
whom you can assume have a company-standard browser.

A short JavaScript intro: If you have a form named
"myForm" with a text input called "myInput", inside an
HTML script tag you can refer to the value in this
form as "document.myForm.myInput.value". You can use
this value to assign to JavaScript variables or to
other fields on the form, possibly hidden ones. That
sounds like the sort of thing you're wanting to do.
There are many good JavaScript references on-line to
help you learn.

- John

--- David vd Geer Inhuur tbv IPlib
<[EMAIL PROTECTED]> wrote:
> 
> Hi Onkar,
> 
> Yes there is a solution, Javascript :)
> 
> Maybe you'dd take a look at :
> http://codepunk.hardwar.org.uk/bjs.htm
> Believe me, it's easier than you think.
> 
> Good luck. David


__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




Re: Accessing form elements before submit..

2002-05-07 Thread David vd Geer Inhuur tbv IPlib


Hi Onkar,

Yes there is a solution, Javascript :)

Maybe you'dd take a look at : http://codepunk.hardwar.org.uk/bjs.htm
Believe me, it's easier than you think.

Good luck. David

> 
> Hi ,
>  I badly need ur help regarding to the CGI scripts.
>  i have written one perl script to design a tree ,with
> recursive function in it. I am accepting parameters
> from the user () and then splicing the
> array.The things are fine.
>  But when i want to put it in the web page,there will
> be a text-box fot input. But how can i access the
> values entered by the user in the same script before
> submit. Because after each input the array is
> reforming.
>  So is it possible to access the values of form
> element before pressing submit button ??
>  I really want this problem to be solved,
>  please do help me.
> Onkar
> 
> __
> Do You Yahoo!?
> Yahoo! Health - your guide to health and wellness
> http://health.yahoo.com
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

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




Re: Mod Perl / CGI problem

2002-05-07 Thread Elwyn Chow

Hi,

I forgot to ask this...

In the other parts of my modPerl script, are there any other
glaring errors in my programming style that I've programmed for modPerl
besides the problem with that particular variable and what's the easiest
way to fix them without changing my lovely style. :-)

My script should work okay in non-modPerl, if it works for the 8
or so times that it does work right before it starts reusing old variable
values, right?

Bye
Elwyn


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




Mod Perl / CGI problem

2002-05-07 Thread Elwyn Chow

Hi,

Is there a good web site where I can get tips of potential modPerl
problems, particularly relating to CGI?

Also, I'm getting a modPerl problem with my script:
I keep finding that $param{form}{type} has the wrong value in it.

Any help would be greatly appreciated.

Bye
Elwyn

#!/usr/bin/perl

use strict;
use CGI;
use DBI;
use lib '.';

my $HOST = 'localhost';
my $DATABASE = 'shopping';
my $DEBUG = 1;
my $MAINTAINER_EMAIL = '[EMAIL PROTECTED]';

my @EQUIPMENT_LIST = 
('cpu','memory','modem','storage_disk','mainboard','graphics_card','monitor','IDE_controller','firewire','hard_disk','CD_ROM','DVD_ROM','CD_writer','keyboard','mouse','networking','case','zip','floppy_drive','sound_card','speakers','printer','scanner');

my @PARAM_TO_EXTRACT = ("id", "type", "brand", "description", "price");

my $cgi;
$cgi  = new CGI;

my $Sdb = DBI->connect("DBI:mysql:database=$DATABASE;host=$HOST", 'root', 'password') 
|| &error("Database couldn't connect: $DBI::errstr", {});

my %p = ();

#---

&main();
exit 1;
#---

sub main {
my %param;
%param = &get_param();

my $body;
$body = "";

$body .= $cgi->header;
$body .= $cgi->start_html(-title=>"Equipment Editor",
  -style=>{-src=>"../style/stylesheet.css"});
print "Type: " . $param{form}{type} ."";

if ($cgi->param('style') eq 'add_save') {
   $body .=&save_add_item(\%param);
} elsif ($cgi->param('style') eq 'add_item') {
   $body .= &add_item(\%param);
} elsif ($cgi->param('style') eq 'show_items') {
   $body .= "\n";
   $body .= &show_items(\%param);
} elsif ($cgi->param('style') eq 'Edit Selected Items') {
  $body .= &edit_items(\%param);
} elsif ($cgi->param('style') eq 'Delete Selected Items') {
  $body .= &delete_items(\%param);
} elsif ($cgi->param('style') eq 'Return to Menu') {
  $body .= &show_menu(\%param);
} else {
  $body .= &show_menu(\%param);
}

$body .= $cgi->end_html;

print $body;
}
#---
sub get_param {
   my %param;
   %param = undef;

   my $to_ex;
   foreach $to_ex (@PARAM_TO_EXTRACT) {
  $param{form}{$to_ex} = "";
   }

   foreach $to_ex (@PARAM_TO_EXTRACT) {
  $param{form}{$to_ex} = $cgi->param("$to_ex");
   }

print "Here it is: " .$param{form}{type} ."";
   return %param;
}

#---
# Print an 'I'm sorry' message, mail an error report to the maintainer
# and quit (using exit, not die; die was making mod_perl lock up
# sometimes, I don't know why.)  Pass it the message and a ref to the
# parameters hash

sub error {
my (  $message, $p ) = @_;
my $body = <>

Its environment was:
EOMAIL
  foreach ( sort keys %ENV ) {
 print SENDMAIL "$_: $ENV{$_}\n";
  }

  close SENDMAIL;
   }
   warn($message);

   &display_html($body, \%p);
   exit;
}
#---
# Wrapper function for simple DBI queries (ie ones without
# placeholders).  Returns a results handle.
#
sub db_query {
my $sql = shift;
#print "SQL: $sql";
my $sth = $Sdb->prepare($sql) || &error($Sdb->errstr . " [$sql]", {});
$sth->execute || &error($Sdb->errstr  . " [$sql]", {});
$sth;
}

#---

sub display_html {
  my ($body, $temp) = @_;

  my %p = %{$temp};
  print "An error occurred$body";
}

#---
sub some_upcase {
   my $str = shift;

   my @bits = split(/_/, $str);

   my $output = "";
   foreach my $bit (@bits) {
  $bit =~ /^(.)(.+)$/;
  $output .= uc($1) . $2;
   }

   return $output;
}

#---

sub adjust_decimal_price {
   my $price = shift;
   $price = sprintf("%.2f", $price) if ($price != int($price));
   return $price;
}
#---

sub add_item {
   my $tmp = shift;
   my %param = %{$tmp};

   my $body = "";
   $body .= $cgi->start_form(-method=>"get", -action=>$ENV{SCRIPT_NAME});

   my %labels = map{ $_ => some_upcase($_) } @EQUIPMENT_LIST;
   my $type_popup_menu = $cgi->popup_menu(-name=>"type", -values=>\@EQUIPMENT_LIST, 
-labels=>\%labels);

   $body .=<


   Equipment Type:
   $param{errors}{type} $type_popup_menu



   Brand:
   $param{errors}{brand}



   Description:
   $param{errors}{description} 



   Price:
   $param{errors}{price} 



   
  
  
   

EO_HTML

   $body .= $cgi->end_form;
}
#---
sub save_add_item {
   my $tmp = shift;
   my %param = %{$tmp};

   %param = &check_add_item_type(\%param);
   %param 

Accessing form elements before submit..

2002-05-07 Thread onkar sangoram

Hi ,
 I badly need ur help regarding to the CGI scripts.
 i have written one perl script to design a tree ,with
recursive function in it. I am accepting parameters
from the user () and then splicing the
array.The things are fine.
 But when i want to put it in the web page,there will
be a text-box fot input. But how can i access the
values entered by the user in the same script before
submit. Because after each input the array is
reforming.
 So is it possible to access the values of form
element before pressing submit button ??
 I really want this problem to be solved,
 please do help me.
Onkar

__
Do You Yahoo!?
Yahoo! Health - your guide to health and wellness
http://health.yahoo.com

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




Re: trouble setting up (solution?)

2002-05-07 Thread Jake

Several people have responded so I thought I'd post my solution...

In commonhttpd.conf (someone keeps changing the configuration file) there were 
the following lines...


AllowOverride All
Options ExecCGI


and I inserted a couple of lines so it now reads...


AllowOverride All
Options ExecCGI
Order allow,deny
Allow from all


I dont know if this is good or bad, but it's workin for me :)

Thanks all
J

On Sunday 05 May 2002 05:37 am, [EMAIL PROTECTED] wrote:
> On Sat, 4 May 2002, Webster wrote:
> > > I just installed Mandrake 8.2 with Apache and I'm trying to get
> >>
> >> some of my  scripts to run on it.   I put them into the www/cgi-bin
> >> directory and chmoded them to 755  I also set their owner and
> >> group to "apache" But I'm still getting "Forbidden...You dont
> >> have permission" errors  What am I forgetting to do?  it's an
> >> install directly from the rpms, so I havent fiddled with any of the
> >> conf files.
>
> Probably need to edit httpd.conf to enable the file extensions,
> grep cgi httpd.conf and you'll see.


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