RE: searching for files using perl

2003-04-01 Thread Peter Kappus
Shawn Sharp wrote:
 I created the following code to search for extention .PBD files in the
 htdocs/PBD folder while using the apache webserver.  However it will only
 search in the cgi-bin folder for these files.  What am I doing wrong?

If you're just searching for files, this is probably a great opportunity to
use the File::Find module.  I reinvented the wheel about four times before I
discovered this one...d'oh!

oh yeah,perldoc Find::File


try this:

#!/usr/bin/perl -w
use File::Find;
use strict;
use warnings;   #HEY!  Do i need this with -w?  somebody tell me...

my $root = C:/temp;   #directory to start from
my $ending = .pbd;#extension to search for 
my @files;  #our list of found files

#go look for it...
#pass our subroutine for processing each file and the root dir
find(\gotIt, $root);  

#print our list all pretty like, with linebreaks
print join(\n,@files);

sub gotIt{
push(@files,$File::Find::name) if (/$ending$/i);
}


-good luck.
pk


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



RE: screen size question

2003-03-27 Thread Peter Kappus
Hi Lou,
Yes, as Jeff pointed out, if you're running it from a console,
system(stty -a) should give you the rows/columns and a bunch of other
usefull stuff.  If, however, you're talking about screen resolution and
you're running your script as a CGI and sending the results to a browser
(which is what this list is all about ;-)  Then you're going to have to do
some fancy JavaScripting to capture the screen resolution, etc.

Basically, you create hidden form fields in a form on your page and then use
javascript to populate them once the page gets rendered on the client's
side.  (Un)fortunately, the only way to get this info is when the client
submits a form.


for example, I might have a form on my login page that looks like this:

form name=LoginForm
input type=hidden value=ScreenWidth/
input type=hidden value=ScreenHeight/
input type=hidden value=ColorDepth/
username: input type=text name=username/
BR/
password: input type=passwd name=pass/
input type=button onClick=doSubmit()/
/form

then in the header I'd need a js function onSubmit like this:

script language='javascript'

function doSubmit(){
var elements = document.forms.LoginForm.elements;
elements.ScreenWidth.value = window.screen.width;
elements.ScreenHeight.value = window.screen.height;
elements.ColorDepth.value = window.screen.colorDepth;

//some other form validation

//submit!
document.forms.LoginForm.submit();
}

/script



In my CGI, I can capture this using the standard CGI params methods...

use GGI qw/:standard/;

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

print screenWidth:  . param(ScreenWidth);
print BRscreenHeight:  . param(ScreenHeight);

etc...

NOTE:  this is untested and yes, I just ripped it off of mailblocks.com 

If this makes no sense, try to learn a little more about hidden form
variables and javascript firstthen figure out how to get it into your
CGI.


good luck,
-Peter


-Original Message-
From: Luinrandir Hernsen [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 27, 2003 11:08 AM

how do I find the current screen size of someone running my perl program?
many thanks
Lou

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



RE: Perl include files

2003-03-25 Thread Peter Kappus
If you're just trying to implement some sort of templating for the
presentation of your site, I'd suggest looking at the HTML::Template module
or maybe HTML::Mason.

If you're talking about code reuse, there are probably more effective OO
ways to create objects that you reuse, etc.  

But a quick and dirty solution that's worked for me is to put my config
variable assignments into an external config file and call it using:

use vars qw($every $variable $in $the @configFile);  #import our
variables
do config.pl;   #set the variables

to include commonly used functions, etc. try putting them in an extneral
file and including them like so:

require myFunctions.pl #or whatever your file is called


What kinds of problems have you had with require() and eval()?

HTH,
Peter



-Original Message-
From: Jason Jolly [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 25, 2003 1:06 PM
To: [EMAIL PROTECTED]
Subject: Perl include files


I'm currently in the process of templating my entire site to provide a
consistent framework...

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



RE: Good Perl cgi book?

2003-03-18 Thread Peter Kappus
Get the mother of all perl books:

Programming Perl (from O'reilly)
by Larry Wall (perl creator), Tom Christainsen, and Jon Orwant.

It moves at a comfortable pace and lets you dig as deep as you want.  It's
also actually a fun read!  Try saying that about most programming books.
(of course, I am a geek, so you may not enjoy it as much as I did)

Good luck.

-P



-Original Message-
From: Bob X [mailto:[EMAIL PROTECTED]
Sent: Monday, March 17, 2003 2:31 PM
To: [EMAIL PROTECTED]
Subject: Good Perl cgi book?

What is the best book for a beginner to get started with on Perl and CGI?

Bob

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



RE: passing page URL to SSI script

2003-03-11 Thread Peter Kappus
If you're using Apache, you can read from the magical environment hash to
see what URL the script was called from.

try this:  $ENV{'REQUEST_URI'};

or print them all like so:
print $_ .   .$ENV{$_} . BR for(keys(%ENV));

I'm not sure how this behaves with other servers such as IIS, but it's
probably worth a look.

good luck,
-Peter K.



-Original Message-
From: javamaster [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 11, 2003 2:35 PM
To: [EMAIL PROTECTED]
Subject: passing page URL to SSI script


I am including the same CGI script as an SSI on several web pages. I 
need to know which page the script was run from (something like the 
javascript window.location variable). I want to be able to know if the 
script was executed from index.html, or contact.html, or products.html, 
etc. I cannot find anything and I was wondering if anyone had any ideas. 
Thanks.

Tim Brom
[EMAIL PROTECTED]



-- 
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: php like behavior for my perl CGI

2003-02-17 Thread Peter Kappus
Thanks to all who have responded to my rather vague request.  Indeed, I
should clarify a bit what I'm looking for.

Because I'm extremely lazy, I'd like to use certain formatting shortcuts in
my HTML.  In a given document, I might have 15 different spacer gifs of
different sizes to aid in precise formatting that would look something like
this:

img src=spacer.gif height=50 width=10/

In PHP, or ASP, for example, I would write a spacer(height,width) function
and call it in my block of HTML like so:

?spacer(50,10)?

which would create and send the image tag for me.
I'd like, in perl, to do the following:

printeob;
table border=0
TR
TD?spacer(10,50)?/TD
/TR
/TABLE
eob

Ideally, I would overload the print function so that it would search for
statements between ?? delimeters and execute them.
Of course, I could also say:

my $spacer1=spacer(10,50);
my $spacer2=spacer(50,100);

printeof;
table
TR
TD$spacer1/TD
TDsome stuff/TD
TD$spacer2/TD
/TR
/TABLE
eof

but it seems like there should be an easier way with fewer keystrokes and
fewer intermediate variables.

Of course, the larger issue here, is that I'd like to learn to temporarily
re-rout STDOUT to a subroutine that will manipulate whatever I send to a
print statement, before actually sending it to my desired output stream.


Perhaps, my dream is completely quixotic, but so far, it seems like the kind
of thing that must be very easy if only I knew the right trick...  Also the
only real benefit I've seen of PHP over perl-cgi is the ease with which one
can mix HTML and code (Naturally, most web architects will jump at the
opportunity to tell you why this is a very bad idea but it often makes life
easier for small projects)

I hope this clarifies things a bit.  If not..I guess I'll just need to do a
few extra keystrokes :)

Many thanks!

-peter


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




DBI question

2003-02-14 Thread Peter Kappus
Hi List,
Sorry if this is a little offtopic but I'm trying to learn DBI for a
CGI I'm writing.  Been reading http://www.perldoc.com/cpan/DBI.html but
seems a little over complex for what I need...just inserts, updates, and
queries really. Portability isn't too important.  Probably going to use
DBD::ODBC on top of it anyway. Also trying to learn about packages and OOP
with perl at the same time...yikes.

Basically, i'm trying to write a little abstraction layer so that I can say
things like:


$dbh = MyPackages::DB-new();  #handles my connection stuff.

#and then
my @values = $dbh-getvalues(username,users);

#or maybe,
my @rowsHashRefs = @{$dbh-query(select username,email from users)};

#and then
foreach my $hashRef (@rowsHashRefs){
my %row = %{$hashRef};
#some html...
print user $row{'username'}'s email is $row{'email'}; 
#or whatever
}



Not sure how much code I'm actually saving by doing this...Does anybody have
experience using DBI or any tricks for keeping things simple and avoiding
excessive prepare, execute, selectall_hashrefs...etc.


Secondly, I thought I had something working (see my package below) but
it's complaining that I'm only passing one argument to selectall_hashref
despite the documentation saying you can use just a simple statement.

here's the error: Usage: $h-selectall_hashref($statement, $keyfield [,
\%attr [, @bind_params ] ]) at Score/DB.pm line 56.


Thanks for any pointers...


-peter





here's the package that I'm trying to write:  (be warned:  It's ugly)



use strict;
use DBI;
use DBD::ODBC;
package MyPackages::DB;


sub new {
#my $class=shift;
my $self={};
bless $self;
#go ahead and connect
$self-connect();
return $self;
}

sub connect{
my $self = shift;
$self-{dbh} =
DBI-connect(dbi:ODBC:myDSN,username,sekretpassword,{
AutoCommit=0,
RaiseError=1}) or die(Can't connect! $!);
}

sub getValue{
my ($self,$field,$table,$condition) = @_;
return if($#_2);

my @rowHashRefs;

if($condition){
@rowHashRefs = @{$self-query(Select $field from $table
where $condition)};
}else{
@rowHashRefs = @{$self-query(select $field from $table)};
}

#get at our hash from our arrayref [0] and pull out the value of
field:$field
#if ($#rowHasheRefs == 0){
#   return ${${$arrayRef}[0]}{$field};
#}

my @fieldValues;
foreach my $rowHashRef (@rowHashRefs){
push(@fieldValues,${$rowHashRef}{$field});
}

#give back the array of values ...or do I want a reference to it?
return @fieldValues;

}

sub query{
my ($self,$qry) = @_;
return unless($qry);
return $self-{dbh}-selectall_hashref($qry);  #why does it complain
here

}

1;



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




php like behavior for my perl CGI...and DBI followup

2003-02-14 Thread Peter Kappus
Thanks to Rob for his Class::DBI suggestion earlier.  Looks like what I
needed was simply:

my %hash;
return $sth-fetchall_arrayref(\%hash);

to return an array of hashes...

As I'm continuing with my latest project, I'm finding myself wishing I could
do some PHP type things...specifically, as I'm formatting the HTML there's
often a need to throw in spacer gifs of various dimensions to make things
look pretty...

In PHP this can be streamlined by creating a function which prints out your
image tag for your and accepts the height and width as parameters. like so:

function spacer($y,$x){
?img src=spacer.gif height=?=$y? width=?=$x??
}


To call it, you would just say:

?spacer(10,50)?  

and it would throw in an image tag with a height of 10 and a width of
50...or whatever.


My question is this:

i'd like to be able to use the  printeof; behavior to send large blocks
of HTML to the browser.  Is there A way that I can reroute that statement to
send my string through a sub that basically does the following:

sub sendit{
my $txt = shift;
$txt =~ s/\?(.+?)\?/(?{eval($1)})/g;  #evaluate what's between my
?? delimeters and print the result
print $txt;
}


I know I could say:

my $vareof;
some HTML with some 
PHP-type function in it?someSub(50)?
haha!
eof

sendit($var);


BUT that seems like a lot to type...I wish I could just say:

senditeof;
somHTML with some 
PHP-type function in it?someSub(50)?
haha!
eof

and have sendit() parse and execute my ?? piece and print the result.
But, alas, that seems to start a never ending perl child...


Thanks once again for any sage wisdom you may have.


-peter


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




RE: Variable passing

2003-02-05 Thread Peter Kappus
Hi Stephen,

In this particular example, you're merely using the onClick event of the
form button to open a window and point it to sample2.pl

For this particular case, I would actually create a series of links on the
first page (instead of  a form) and make those links open a popup and send
data to the script via the query string in the URL (using the GET method)

SO..in my original window I'd say:

HTML
HEAD
script language=javascript
function openResults(year){
window.open(sample2.pl?year= +
year,sample2,status=yes,scrollbars=yes,resizable=yes,height=500,width=800
);
}
/script
/HEAD
BODY
Please select a year to view:
a href=javascript:openResults(2002)2002/A

a href=javascript:openResults(2003)2003/A

a href=javascript:openResults(2004)2004/A

/BODY
/HTML


THEN in sample2.pl I'd use the CGI lib to avoid re-inventing the wheel :)
and say somethign like:

#!/usr/bin/perl -w
use strict;
use CGI qw/:standard/;

my $year = param(year);

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

if($year){
print You've chosen $year;
}else{
print No year selected!;
}


you get the general idea.

if you MUST use a form on the first page, the only way I can think of is to
use javascript to read each element out of your
form and then open your results window and glue the form elements into the
query string (URL encoding everything of course).  There may be an easier
way but I can't think of one.   I'd encourage the link approach if you can
get away with it.  The less form handling you have to do with javascript the
better...  Finally, if you can manage it, your life would be simpler without
using pop-ups for this particular task.

good luck

-Peter





-Original Message-
From: Stephen Spalding [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 05, 2003 2:00 PM
To: CGI
Subject: Variable passing


Hello all,

I've written a cgi page whose form I've set up to open
another window. I'm having problems getting an input
variable to pass from the originating page to the page
that's being opened. I've included some snippits from
my code below. I can't even get it to work in this
simple example.

Can anyone help me out?

Thanks!

-Stephen Spalding

Original CGI page:
#!/usr/bin/perl
print Content-type: text/html\n\n;

print HTML\n;
print BODY BGCOLOR=#F5FFFA\n;

print SCRIPT language=\JavaScript\\n;
print function open_schedule()\n;
print{\n;
printper_seat_var =
window.open(\sample2.pl\,\sample2\,\status=yes,scrollbars=yes,resizable
=yes,height=500,width=800\)\n;
print}\n;
print /SCRIPT\n;

print TABLE width=\600\\n;
print TR\n;
print   TD width=\600\ align=center\n;
print BSelect a year to view:/B\n;
print   /TD\n;
print /TR\n;
print /TABLE\n;

print FORM method=\post\
action=\display_schedule.pl?FULL_SCREEN=true\\n;
print TABLE width=\600\\n;
print TR\n;
print   TD width=\200\ align=right\n;
print BYear: /B\n;
print   /TD\n;
print   TD width=\100\ align=left\n;
print select name=\year\ size=\1\\n;
if ( $year eq '2002' )
{ print option value=\2002\
selected2002\n; }
else
{ print option value=\2002\2002\n; }
if ( $year eq '2003' )
{ print option value=\2003\
selected2003\n; }
else
{ print option value=\2003\2003\n; }
if ( $year eq '2004' )
{ print option value=\2004\
selected2004\n; }
else
{ print option value=\2004\2004\n; }
print /select\n;
print   /TD\n;
print   TD width=\100\ align=left\n;
print INPUT TYPE=\button\
NAME=\submitButton\ VALUE=\Go!\;
print onClick=\open_schedule()\;
print   /TD\n;
print /TR\n;
print /TABLE\n;
print /FORM\n;
print /BODY\n;
print /HTML\n;



Here's the script that's being opened:


#!/usr/bin/perl
print Content-type: text/html\n\n;

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(//, $buffer);
foreach $pair (@pairs)
{
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~
s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;

# full_screen eq true
if ( $name eq 'year' ) { $year = $value; }
}

print HTML\n;
print BODY BGCOLOR=#F5FFFA\n;

print TABLE width=\700\\n;
print TR\n;
print   TD width=\300\ align=center\n;
print   year = $year\n;
print   /TD\n;
print /TR\n;
print /TABLE\n;
print /BODY\n;
print /HTML\n;



__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.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: broadcast photo on other site not by up load

2002-12-23 Thread Peter Kappus
Season's greets, Eric  fellow Perlites:

Yes, chances are, if you're getting *something* but not an image, you're
either sending the wrong headers to the browser OR you're sending the right
headers and then getting a compilation error...Or both.  On a windows
machine, there's also the possibility that you're not using Binary mode on
your image file handles (but since you're doing it in linux for the time
being, that's one problem we won't have to worry about)

What I usually do when this happens, is right click (from NS6+ or Mozilla)
and do a view source on the image itself... in the source you'll see the
actual output of your script which will contain the error, if there is one.

Another good test, which I'm sure you've already done, is to makes sure that
when you type
% perl showphoto.pl
you're script actually compiles, and runs and then spews a bunch of binary
data to your terminal...(after printing Content-type: image/jpg\n\n (or
whatever))
I'd recommend this over redirecting you're output into a file because it
should tell you immediately if you're having compilation errors.

The other thing to do is make sure you're dying where appropriate... I
don't remember your original script but make sure you have things like:

open(IMAGE,myPic.jpg) or die(Couldn't open pic! $!);

(the $! will tell you what actual error occured... this way, if you've got
the wrong path or insufficient priviladges, etc. you'll find out the easy
way...

HTH  good luck!

-Peter




-Original Message-
From: zentara [mailto:[EMAIL PROTECTED]]
Sent: Sunday, December 22, 2002 4:54 AM
To: [EMAIL PROTECTED]
Subject: Re: broadcast photo on other site not by up load


On Sat, 21 Dec 2002 14:07:03 -0700, [EMAIL PROTECTED] (Eric Lin)
wrote:

   Now I am in linux again,
I did /usr/bin/perl  /usr/lib/cgi-bin/showphoto.pl  mytestout.jpg
then at netscape 7 's url type /home/fsshl/mytestout.jpg

it showed
---
The image file:///home/fsshl/mytestout.jpg cannot be displayed, 
because it contains errors

Make sure your showphoto.pl script is not outputting an html header.
Can you look at mytestout.jpg with somethong else like xv.
Look at mytestout.jpg with a hex editor and see what the first few lines
are. Are they a valid jpeg header? Compare it to other known good jpegs
you have.
Your showphoto.pl script should be able to read in a image and then
print it out without corrupting it. Post your showphoto.pl that you are
using.


-- 
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: File upload - probably simple..

2002-12-23 Thread Peter Kappus
If you're only uploading jpgs then you could also write this as
my ($name) = $path =~ /\w+\.jpg$/i;

since a regexp match returns an array, you're actually creating an array
with a single element ($name) and mapping it to the return from your match
$path =~ /etc/i;  you're match says one or more word characters [A-z0-9_]
followed by .jpg at the end of the string ($) and match case insensitively
(using the /i modifier)

In retrospect, Teddy's solution is probably cleaner but hopefully this will
be useful anyway...  this technique is best suited for grabbing various
elements out of a match ie. to grab the filename and extension you'd use:

my ($name, $ext) = $path =~ /(\w+)\.(\w+)$/i;

good luck.
-p


-Original Message-
From: Octavian Rasnita [mailto:[EMAIL PROTECTED]]
Sent: Sunday, December 22, 2002 10:17 AM
To: james lundeen; beginners-cgi
Subject: Re: File upload - probably simple..


Use regular expressions to get only the file name from the path.

You should use something like this:

$path =~ s/^.*[\\\/]//;

Teddy,
Teddy's Center: http://teddy.fcc.ro/
Email: [EMAIL PROTECTED]

- Original Message - 
From: james lundeen [EMAIL PROTECTED]
To: beginners-cgi [EMAIL PROTECTED]
Sent: Sunday, December 22, 2002 12:56 AM
Subject: File upload - probably simple..


hey, do you have a solution to this?

I need to upload a file, but i just want the file name, not the entire
path.  Currently, it saves the actual file on the server as:

G:\ISIR\ISIR2002gallery\images\isir1.jpg   as the FILENAME!!!

i just want it to save as isir1.jpg or whatever the filename is for
the file that the user is uploading...

windows machine path for the file:
G:\ISIR\ISIR2002gallery\images\isir1.jpg

should end up as the following on the linux server:
/home/website1/html/images/isir1.jpg

Anyone with info on this, I'd really appreciate feedback.  Thanks!!!



__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.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]

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




RE: Form TextArea loading

2002-12-16 Thread Peter Kappus
Well...I'd do something like this:

open(IN,myFile.txt);

#by undefining the input separator (below), 
#we can read the whole file as one scalar
undef $/;  

my $fileContents= IN;
close(IN);

printeof;
HTML
BODY
FORM
Here's my file:
textarea name=myTextArea$fileContents/textarea
/FORM
eof

voila!

As for your second question, if you wanna strip spaces at the ends you could
do this

$myString =~ s/^\s+(.+?)\s+$/$1/g;

This says, if you see multiple spaces at the beggining or end of a string
with any  other characters in the middle, replace the whole thing with the
non-space stuff in the middle

If you just want to remove spaces, do something like this:

$myString =~ s/\s+//g;

There are many other ways of doing this, too... if you need more help, tell
us specifically what you're trying to do...

-Peter



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 16, 2002 7:50 AM
To: [EMAIL PROTECTED]
Subject: Form TextArea loading


Hi all,


Can sombody tell me how to load the contents of a text file into a textarea 
of a form in cgi? thanks...

oh and also need to to remove blank spaces from a string non realated
though

Ambrose

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




RE: really basic question about CGI module

2002-12-13 Thread Peter Kappus
In my experience, the only character you really have to watch out for with
mySQL is a single quote (') which you can just replace with a double-single
quote ('').  So I usually do something like this on each piece of text that
I plan to write to a database:

$someInput =~ s/'/''/g;

good luck!


-Original Message-
From: james lundeen [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 12, 2002 12:41 PM
To: '[EMAIL PROTECTED]'
Subject: really basic question about CGI module


I use CGI in my routines very often and at times need to look at the
incoming values from forms
to make sure that they don't include ' , and other things that might
blow up my connection
with mysql database.   Can someone please give me a nice piece of reusable
code that will read the
incoming variable and clean up all of the charecters that the user might
have entered that certain
programming routines might not like?Specifically, I have run into
problems if the user has  
'   ,   in the field.   maybe there are others too? any help and code
would be appreciated!  
-jimmyjames


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.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: cronjob via perl

2002-12-12 Thread Peter Kappus
Hi sven (et al)
Wiggins(?) has a good point about calling the script remotely.  But
I was trying to figure out what the script actually does and I couldn't find
a value for $sql...but my guess is that it looks for new members of some
sort and gives them a random password?  Is this something that could be
performed as part of some other task?  Perhaps, make it part of the login
process for new users?  Obviously, I don't know the whole scope of the
problem but often times, while cron may be the most elegant option, there
are other places where a task may be completed without interfering too much
in the workflow for the user or the performance of the system.  I guess what
I'm suggesting is that you revisit the problem to see if there are more
event driven ways of solving it rather than doing it in a repeated
fashion.

Also, in this line:
 my $password = join '', (1..9,a..z,A..Z,0..9)[map {rand 36}
0..9];
why use 1..9 AND 0..9?  doesn't this give you the same characters as
simply 0..9? and why rand 36?  aren't there a lot more than 36 characters in
your array?  Just curious...  looks clever, though.

Good luck!

-peter

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 12, 2002 7:22 AM
To: Sven Bentlage; [EMAIL PROTECTED] [EMAIL PROTECTED]
Subject: RE: cronjob via perl


You could setup the script to run through CGI and then use cron on another
box to curl, lynx, LWP, etc. the script at your intervals. This is obviously
less secure, but you could do things like require a password, check the IP
of the machine doing the call (though this can be spoofed as well, just less
easily), etc.

http://danconia.org


On Thu, 12 Dec 2002 15:31:53 +0100, Sven Bentlage [EMAIL PROTECTED]
wrote:

 My provider doesn`t allow any user cronjobs, but I have to perform a 
 regular task (set back passwords ).
 So I just wrote a small script to the job for me, but I am not sure if 
 it will need to much resources (and because of this would be killed by 
 my provider)
 
 Does anyone know a better solution than continuously running a perl 
 script?
 
 Thanks for your help in advance.
 
 Sven
 
 #!/bin/perl -w
 BEGIN {
   $| = 1;
   push(@INC,'/htdocs/www/cgi-bin/lib');
   use DBI;
   }
 
 
 #Version 0.1
 
 
 
 
 
 my $date = localtime(time);
 my $dsn = '';
# Data Source Name
 my $db_user = '';
# Database User
 my $db_pass = '';
# database pass
 my $logfile = cron_log.txt; #
Logfile
 
 
 open (LOG, $logfile) || mydie($_);
 
 pw_switch();
 
 sub pw_switch {
 
   sleep(8*60*60);
   my $new_password = pw_create();
   my $dbh = DBI-connect( $dsn, $db_user, $db_pass) || 
 mydie($DBI::errstr);
 #my $number = $dbh-do(select count(*) from memberscopy where
 my $del_pw = $dbh -do( $sql ) || mydie($DBI::errstr);
 print LOG  $date -- $sql\n;
   
   $dbh-disconnect;
   close (LOG);
   print qq ~
   html
   head
   titlePassword switching done/title
   /head
   body bgcolor=red
   h1Password switched/h1
   /body
   /html
   ~;
 
   
   }
 
 sub pw_create {
   my $password = join '', (1..9,a..z,A..Z,0..9)[map {rand 
 36} 0..9];
   $password = substr($password, 0, 8);
 
 
   chomp $password;
   return ($password);
 }
 
 
 
 sub mydie {
   open (LG, .Mydie_cron.txt);
   print LG $_  -- $date \n;
   close (LG);
   exit;
 }
 
 
 -- 


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




RE: automatically downloading files into a certain directory

2002-12-12 Thread Peter Kappus
Yup...I'm afraid this isn't possible within a browser (for security reasons)
but you could easily build a simple perl client that would (using LWP) make
a request to a CGI and save the result locally.  The problem there is the
UI...If you're not using a browser to retrieve the info from a server, then
you'd have to create some sort of UI within your client and since your user
isn't computer savvy, that probably means using Tcl/TK (about which I know
next to nothing;-)  OR it means building a web-based front end for your
client app which means writing your own web-server capable of CGI like
behavior and showing your user how to connect to http://localhost:8008 or
some such...  not pretty either way.

If it isn't imperative that the user gets the file immediately, I'd build
the core of the app as a CGI (with a web-based front-end for the user) which
gathers the info and creates the appropriate file in a predetermined
location on the server, and then I'd make a client app that sits in the
background on the users' machine and checks for a new file on the server
every 5 minutes (or whatever) and, if it finds a fresh copy, downloads it to
a local directory.

Still kinda clunky but there's no other way to force a download to a
client's box without having it either initiated by the user or handled by a
client-side app of some sort.

Good luck!
-Peter



-Original Message-
From: zentara [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 12, 2002 5:36 AM
To: [EMAIL PROTECTED]
Subject: Re: automatically downloading files into a certain directory


On Thu, 12 Dec 2002 09:21:37 +0100, [EMAIL PROTECTED] (Anette
Seiler) wrote:

I want to do something where I am not sure it can be done with perl...

Basically a user should klick on a button on a website. Then the script 
should create a file with certain information from a database on the 
webserver (that's easy) and that file should automatically be downloaded 
into a certain directory on the user's computer (that is the difficult 
part). The user is not computer illaterate, but he should not bother about 
downloading and choosing certain directories (as he will have to download 
hundreds of these files)  and definitely not about ftp or something like
that.

Well, as I said, it is the downloading part that I don't know how to do. 
Can it be done with perl or should I look at something else - maybe
javascript?

I don't think it can be done automatically like you want, from a web
browser. It would cause too many security problems. In a web browser,
the user must be asked to save anything to disk, once for each file.

If you need automation of this kind, you should look into using a
LWP script to automatically get the files, and keep the browser out of
it.


-- 
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: can we use system() inside cgi ?

2002-12-10 Thread Peter Kappus
I don't know much about suidperl but if I were doing this, I probably
wouldn't give root privileges to my CGI.  If it doesn't need to happen
instantaneously, I'd consider a two-step approach: (of course, it probably
does need to run instantaneously since you're doing it as a CGI anyway...)

Instead of doing everything from the CGI, what I would do is write one Perl
CGI to gather your config input from the user and write it to a file. Then,
create a second script which will take run as root (as a cron job?) and read
the config file written by your first script and act accordingly.  Of
course, this is extremely slow and inefficient but seems more secure than
giving root access to your CGI.  Besides, if you can't get the other way to
work, I think this might do the trick.  But again, I'm sure there's a more
elegant solution.  I'd still like to know what suid perl is and why it won't
let you run /sbin/ifup|ifdown.  It might be just a simple environment thing
where the script can't find ifup Are you calling it as ifup or /sbin/ifup?

good luck!

-peter


-Original Message-
From: Admin-Stress [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 10, 2002 1:29 PM
To: perl cgi
Subject: RE: can we use system() inside cgi ?


I did read it, but still dont understand. What does tainted means? 

I changed my cgi like this :

   #!/usr/bin/suidperl

Then :

   chown root:root saveconfig.pl
   chmod 755 saveconfig.pl

It's now 'partly working', it can changed the content of /etc/sysconfig/...
by overwriting it's
content (open ... print ... close).

But, still, I cant executing /sbin/ifup /sbin/ifdown.

Basically, I dont know the way suidperl working nor executing cgi which
neeed root permission.

That work around I just found it with trial and error. If someone could
explain or just tell me
what should I do in terms of permission setting or modification. What I need
is just :

   overwriting /etc/sysconfig/...
   executing /sbin/ifup /sbin/ifdown

I must finish this project the day after tomorrow :((

Thanks.
kapot

--- [EMAIL PROTECTED] wrote:
 You need to read up on tainted variables, I think.
 
 perldoc perlsec
 
 The problem isn't that it is a CGI, pretty sure the problem is that it is
setuid.
 
 http://danconia.org
 
 
 On Tue, 10 Dec 2002 07:20:16 -0800 (PST), Admin-Stress
[EMAIL PROTECTED] wrote:
 
  I got this error :
  
  [error] [client 10.0.0.88] Insecure $ENV{PATH} while running setuid at
  /var/www/cgi-bin/ifcfg_rh80.pl line 60., referer:
http://10.0.0.50/cgi-bin/editconfig.pl
  
  And line 60 of ifcfg_rh80.pl is :
  
 system(/sbin/ifdown $device);
 sleep 2;
 system(/sbin/ifup $device);
  
  I chmoded +s both editconfig.pl and ifcfg_rh80.pl.
  
  And I installed suid-perl ...
  
  Anything else that I can do? I made a cgi to change server ip address.
  
  Thanks.


__
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.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: Changing row color with subroutine - a shortcut...

2002-11-22 Thread Peter Kappus
Another neat trick I use to get subroutine arguments is the old shift
function without an argument.

Since, @_ is the default array in a subroutine you can just say

my $firstParm = shift; #shift off the first arg from @_


Therefore, 

print add(30,50);

sub addTwo{
my $firstNum = shift;
my $secondNum = shift;
return $firstNum + $secondNum;
}

will print 80.  neato eh?

another fun trick if you have, say, 3 arguments is to say

my ($name, $size, $color) = @_;

this will map the first three args in your args array two the variables
$name, $size, and $color.

I hope this is useful...

-PK

-Original Message-
From: zentara [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 6:33 AM
To: [EMAIL PROTECTED]
Subject: Re: Changing row color with subroutine


On Fri, 22 Nov 2002 03:28:39 -0800, [EMAIL PROTECTED] (Poster) wrote:

Hi, I am having a little trouble with a sub that is using the modulus
operator.

Yeah, it fooled me too for a bit :-)
The problem is the way you pass the value to the
sub, @_ always is 1, the count of elements in @_.
Change @_ to @_[0]  or better yet $_[0]

--here is the sub
sub color_rows
{
my $num = @_;


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




RE: console window

2002-11-21 Thread Peter Kappus
Another quick dirty trick is to just put a 
STDIN;
at the end of your script.  This makes yours script wait for input.  When
you hit enter it will terminate and the window will close.  Of course,
this only works if your script gets to the end.  If it runs into a compile
error, you'll see the error message for 3 microseconds before the window
closes... Many editors let you execute commands from the IDE.  I like gVim
(steep learning curve but oh-so-snappy once your fingers learn a few simple
commands) Anybody know how to do more sophistocated error trapping or
console execution?  Yes, I know, this isn't really even a CGI question.  Who
uses a console for CGI development anyway?

-p


-Original Message-
From: Jason Purdy [mailto:[EMAIL PROTECTED]]
Sent: Thursday, November 21, 2002 8:08 AM
To: [EMAIL PROTECTED]
Subject: Re: console window


At the end of your perl program, add the line:
system( PAUSE );

http://www.computing.net/programming/wwwboard/forum/3270.html

HTH,

when i run the perl programs from windows explorer, the console
window opens, executes and closes before i can see anything in it.

thank you

gary rocco

[EMAIL PROTECTED]



-- 
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: Weekly list FAQ posting

2002-11-14 Thread Peter Kappus
Hi Casey et al,

Thanks for the useful information!  I was just noticing that all of our
email addresses are available as-is on the discussion archives
(http://archive.develooper.com/beginners-cgi%40perl.org/) where they could
easily be harvested by evil spam-bots and used to send us junk.

Do you think it would be possible to either hide our addresses completely or
protect them with some manner of text-armor (a la slashdot perhaps?
peter[dot]kappus[at]corbis[dot]com, etc.)

I see that we're using MHonArc for our list archiving and it doesn't seem to
support such a feature.  So we may need to hack something onto the existing
system.  If it's a resources issue, I'm happy to help out however I can...

Does anybody else share these concerns or have other approaches for a
solution?  I suspect everybody on the perl.org lists is susceptible to
having their email sucked up and sold...

Many thanks and happy coding,

-Peter


-Original Message-
From: [EMAIL PROTECTED] [mailto:casey;geeknest.com]
Sent: Thursday, November 14, 2002 5:00 AM
To: [EMAIL PROTECTED]
Subject: Weekly list FAQ posting

  1.4 - Is there an archive on the web?

Yes, there is. It is located at:

http://archive.develooper.com/beginners-cgi%40perl.org/

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




congrats kelvin....also, mail receipts for Sven

2002-11-12 Thread Peter Kappus
Kelvin...Congrats on your CGI success!  Yes, it is a simple but easy to
forget fact that the physical location of your documents on the server is
not the same as the URL...  if you're document root (set in your httpd.conf
file) is /var/www/ and inside it you have a folder called myStuff then
the URL will be http://localhost/myStuff and NOT
http://localhost/var/www/myStuff   (simple but tricky the first few
times..still, important to remember)

and to Sven,
 I don't believe that SMTP supports read receipts (or delivery confirmation)
but I may be wrong...(anybody?)  This is where the evil transparent tracking
gif's come into play.  But they require that you use the even more evil HTML
email which I don't recommend under any circumstances despite the fact that
marketing folks just love it.  The downside is that not everybody can read
HTML email and you generally have to send both a plaintext and HTML versions
which make even a short message about 30k.

BUT, assuming you MUST have delivery confirmation, the trick is to use HTML
email and do the following:

1) Create a CGI on a web server that accepts an email address as a parameter
and delivers a single pixel transparent gif to the client while recording
the email address in a DB or text-file (or whatever)

2) embed a customized link to this CGI from the email you're sending (img
src=http://myserver/mySneakyCGI.cgi?email=recipientAddress;somedomain.com
)  (remember to URL encode the address)

your CGI might look something like this:

#!/usr/bin/perl -w
use CGI qw/:standard/;

open(LOG,pathToLog.txt);
#write a timestamp and the email address to our log file
write LOG scalar(localtime()) . \t . param(email);  
close(LOG);

#now send our image
open(IMG,pathToImgFile.gif);
#if you're on Windoze make sure you specify binmode 
#(otherwise your image will get mangled)
binmode(IMG);

#send our mime-type to the browser 
#(so it doesn't get confused)
print Content-Type: image/gif\r\n\r\n;  

binmode(STDOUT);#use binmode for our output filehandle, too
print IMG;#print the whole image file to the browser
close(IMG); #clean up


THE END
(Can somebody show me how this would look using DBI instead of text files?)
DISCLAIMER:  I haven't tried to run this...it probably doesn't work as-is.

Now your log file knows when the email was read, and by who (and how many
times!)
and your poor unsuspecting user is none the wiser.  mwuhahah!  NOTE:  you
could easily use a name, or customerID or whatever you like in your query
string that you send to the CGI.

just remember to use your perl powers for good, instead of evil.

Good luck.
-Peter


-Original Message-
From: Kelvin McWha [mailto:kelvin.mcwha;btinternet.com]
Sent: Tuesday, November 12, 2002 8:15 AM
To: 'zentara'; [EMAIL PROTECTED]
Subject: RE: Unable to run cgi script


Got it, after spending two days on just this problem I have found the
answer with the help of David T_G and David Kirol and others, many
thanks.

And the answer was

Setting ScriptAlias /cgi-bin   /home/kelvin/cgi-bin/

Means that I still need http://localhost/

But I don't now need /home/Kelvin

So the final path is http://localhost/cgi-bin/myscript.cgi

Simple eh!

thanks again

Kelvin

Ps just spotted that Scott suggested this within one of his answers
yesterday

 -Original Message-
 From: [EMAIL PROTECTED] [mailto:Linux;onion.perl.org] On Behalf Of
 zentara
 Sent: 12 November 2002 14:15
 To: [EMAIL PROTECTED]
 Subject: Re: Unable to run cgi script
 
 On Mon, 11 Nov 2002 12:27:25 -, [EMAIL PROTECTED]
(Kelvin
 McWha) wrote:
 
 System is
 SuSe 8.1 stand-a-lone
 Apache 1.3
 
 Have got Apache running OK and tested it in standalone mode using
 http://localhost
 which shows the appropriate test page
 
 Can you get http://localhost/~kevin to run?
 
 In SuSE 8.1 you need to enabled user home dirs.
 
 Look at /etc/sysconfig/apache  and see if you have home directories
 enabled.
 
 
 
 
 --
 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]

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




RE: Translators

2002-11-04 Thread Peter Kappus
Are we talking programming languages like C to Perl? 
Or spoken languages like Spanish to Italian?

if you're talking about localization I know there are lots of modules and
tools to help you out...
you might look here:
http://cpan.org/modules/by-category/13_Internationalization_Locale/Locale/
maketext sounds like a good starting point.

gnu gettext is another popular way to internationalize perl scripts (or any
software, I suppose) http://www.gnu.org/manual/gettext/index.html

Of course, with both of these, I think you'll still have to do most of the
translation yourself.
Does anybody have experience with either of these?  Are there other freeware
products that handle translation memories and things like that?  I know the
TMX project sounds pretty cool in that it allows you to reuse translations,
etc.  http://www.lisa.org/tmx/  of course, I don't actually know how it
works...

Anyway, I hope this helps!

-Peter


-Original Message-
From: Octavian Rasnita [mailto:[EMAIL PROTECTED]]
Sent: Saturday, November 02, 2002 11:17 AM
To: [EMAIL PROTECTED]
Subject: Translators


Hi all,

Does anyone know if there are perl modules that can translate from a
language into another?
Or free perl programs? I don't need a proffessional one but just an example.

Thanks.

Teddy

Teddy's Center: teddy.fcc.ro
Email: [EMAIL PROTECTED]



-- 
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: How to check server for perl setup?

2002-11-04 Thread Peter Kappus
I tend to agree with zentara...Are you able to run simple perl scripts from
the command line?  If so then your perl install is okay...  Can you run
simple CGI scripts?  When i first start using a new  server I always run a
quick:

#!/usr/bin/perl
print Content-type: text/html\n\n;
print Howdy y'all!;

(yes, you could do this on one line but this seems easier for me to read...)

If it runs at all then that usually means my Apache config is okay and ready
to go (which usually isn't the case ;-) If it gives me a premature end of
script headers message, then it usually means that perl is not where I
thought it was...in which case I'll telnet (or SSH) into the box and run a
which perl as zentara recommends.  (I assume you've got telnet or ssh
access since it sounds like this is your own box) 

If my shebang line (#!) is okay, then I check to make sure that I've changed
the permissons on the  script to be executable by others (chmod o+x
scriptname.pl)  If that doesn't work, I go out for coffee.

Lastly, do your trusty old perl scripts use any non-standard modules?  Have
you installed those on your new box?  Are they in your perl lib directory
where perl expects to find them?

One good way to test this is to try running the script from the command
line.  If it's having package problems it should let you know and tell you
where it's looking for stuff...


Good luck!

-Peter




-Original Message-
From: zentara [mailto:zentara;highstream.net]
Sent: Saturday, November 02, 2002 5:57 AM
To: [EMAIL PROTECTED]
Subject: Re: How to check server for perl setup?


On Sat, 2 Nov 2002 06:21:43 -0500, [EMAIL PROTECTED] (Dan Sabo) wrote:

Hi,

Is there a way I can check my server to see if my perl setup and
configuration is running OK and ready to run cgi scripts?

I've run pre written perl cgi scripts for a few years on a shared server
but
recently set up my own server and for some reason I can't seem to get my
long used cgi script running.  I think my path settings are correct in my
config files for the script - /usr/bin/perl, but how can I check to see if
perl is actually ready to go on my server and being accessed by the cgi
scripts OK?

I use Linux 7.3, apache 1.3.23 and perl 5.6.1

If you are switching scripts from another server, a likely culprit is
your directories have changed. Like they used to be in
/var/www/httpd/cgi-bin  and 
now they are in  /usr/local/httpd/cgi-bin.
( Or something similar).


Your best bet is to put in a simple cgi test script on the server and
see if it runs. If it dos'nt, you probably need to work on your
httpd.conf file to enable cgi execution in your cgi-bin.

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