?
Solved

Struggling with cgi

Posted on 2002-04-23
6
Medium Priority
?
336 Views
Last Modified: 2013-11-18
Hi,
First I am not a regular Perl user so please bear with me.  I have a cgi script that I am currently using in a vb project to log visitors to a FTP site.  I need to expand the cgi script to accept a few more parameters.  In the existing code there is an extra parameter that is remmed out with the "#" character.  I unremmed this argument and then added it to the Print line.  I also changed the name of the text file that it is creating/writing to.  I did this all locally using Notepad.  I Then posted the new cgi script ASCII to the cgi-bin on my server.  I also toggled the Execute property of the new cgi script using CHMOD so that is was checked.  The new text file is not being created.  My first question is does it sound like I have made the changes in a way that has caused my problems?  
And second what is this part of the code doing?

# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
print FILE "This is a test\n"; # First time

I have the rest of the code I just didn't want to post it all.  Thanks for any help you can give me.
0
Comment
Question by:Glowman
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:sstouk
ID: 6963022
You have to post the whole script here.
Otherwise we will be talking a "broken phone" conversation.
I could look though the script and see if it valid, even try it on my system to make sure it works and is not a script's problem (if it is).

So, please post the whole script.
0
 
LVL 4

Author Comment

by:Glowman
ID: 6963047
OK.
Thanks for your quick response.  Also does wordwrap affect anything?

#!/usr/local/bin/perl
# Set Variables
$counterfile     = 'IupdLog.txt';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

# Get the input
$link = $ENV{'DOCUMENT_NAME'};



 if ($ENV{'QUERY_STRING'} !~ /sort=\d/ && $ENV{'QUERY_STRING'}) {
     $adjust = '&' . $ENV{'QUERY_STRING'};
 }
 (@args) = split(/&/, $ENV{'QUERY_STRING'});
 foreach $arg (@args) {
     ($arg, $value) = split(/=/, $arg);
     $value =~ tr/+/ /;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
     if (($arg eq 'query') && ($value ne '')) { $ARGS{$arg} = '.*' }
     else { $ARGS{$arg} = $value }
 }
# $sort_order = ($ARGS{'sort'} || 0);
 $username = $ARGS{'username'};
 $file = $ARGS{'file'};
 $iver = $ARGS{'iver'};
 $time = $ARGS{'time'};
 $VAR{'query'} = $ARGS{'query'} if $ARGS{'query'};
 $VAR{'root_name'} = $ROOT_NAME;



# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
 print FILE "This is a test\n"; # First time
# print FILE $username, ",",  $file;
  print FILE $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
  print FILE  $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 , ",",  $time

# print FILE "1'$link\n"; # First time
flock(FILE, 8);
close(FILE);

$counter = '1';

&LocateLink;

 sub LocateLink {
#  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  print "Content-Type: text/html\n\n";
#  print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'},"\n" ;
#  print $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec;
 print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
 print $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 #  "\n\n";
#  print ,"\n\n";

#  print $counter;
  exit;
 }

Thats what I have to work with.
0
 
LVL 4

Author Comment

by:Glowman
ID: 6963134
OK.
Thanks for your quick response.  Also does wordwrap affect anything?

#!/usr/local/bin/perl
# Set Variables
$counterfile     = 'IupdLog.txt';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

# Get the input
$link = $ENV{'DOCUMENT_NAME'};



 if ($ENV{'QUERY_STRING'} !~ /sort=\d/ && $ENV{'QUERY_STRING'}) {
     $adjust = '&' . $ENV{'QUERY_STRING'};
 }
 (@args) = split(/&/, $ENV{'QUERY_STRING'});
 foreach $arg (@args) {
     ($arg, $value) = split(/=/, $arg);
     $value =~ tr/+/ /;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
     if (($arg eq 'query') && ($value ne '')) { $ARGS{$arg} = '.*' }
     else { $ARGS{$arg} = $value }
 }
# $sort_order = ($ARGS{'sort'} || 0);
 $username = $ARGS{'username'};
 $file = $ARGS{'file'};
 $iver = $ARGS{'iver'};
 $time = $ARGS{'time'};
 $VAR{'query'} = $ARGS{'query'} if $ARGS{'query'};
 $VAR{'root_name'} = $ROOT_NAME;



# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
 print FILE "This is a test\n"; # First time
# print FILE $username, ",",  $file;
  print FILE $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
  print FILE  $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 , ",",  $time

# print FILE "1'$link\n"; # First time
flock(FILE, 8);
close(FILE);

$counter = '1';

&LocateLink;

 sub LocateLink {
#  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  print "Content-Type: text/html\n\n";
#  print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'},"\n" ;
#  print $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec;
 print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
 print $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 #  "\n\n";
#  print ,"\n\n";

#  print $counter;
  exit;
 }

Thats what I have to work with.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Author Comment

by:Glowman
ID: 6963331
OK.
Thanks for your quick response.  Also does wordwrap affect anything?

#!/usr/local/bin/perl
# Set Variables
$counterfile     = 'IupdLog.txt';
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);

# Get the input
$link = $ENV{'DOCUMENT_NAME'};



 if ($ENV{'QUERY_STRING'} !~ /sort=\d/ && $ENV{'QUERY_STRING'}) {
     $adjust = '&' . $ENV{'QUERY_STRING'};
 }
 (@args) = split(/&/, $ENV{'QUERY_STRING'});
 foreach $arg (@args) {
     ($arg, $value) = split(/=/, $arg);
     $value =~ tr/+/ /;
     $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack("C", hex($1))/eg;
     if (($arg eq 'query') && ($value ne '')) { $ARGS{$arg} = '.*' }
     else { $ARGS{$arg} = $value }
 }
# $sort_order = ($ARGS{'sort'} || 0);
 $username = $ARGS{'username'};
 $file = $ARGS{'file'};
 $iver = $ARGS{'iver'};
 $time = $ARGS{'time'};
 $VAR{'query'} = $ARGS{'query'} if $ARGS{'query'};
 $VAR{'root_name'} = $ROOT_NAME;



# Add new link to database file
open(FILE, ">>$counterfile") || die Can't locate database file $!;
flock(FILE, 2); # blocking write lock
 print FILE "This is a test\n"; # First time
# print FILE $username, ",",  $file;
  print FILE $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
  print FILE  $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 , ",",  $time

# print FILE "1'$link\n"; # First time
flock(FILE, 8);
close(FILE);

$counter = '1';

&LocateLink;

 sub LocateLink {
#  ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime(time);
  print "Content-Type: text/html\n\n";
#  print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'},"\n" ;
#  print $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec;
 print $username, ", ",  $file, ", ", $ENV{'REMOTE_ADDR'}, ", ", $mon+1,"/",$mday,"/","0",$year-100," ",$hour, ":", $min, ":", $sec, ", " ;
 print $ENV{'HTTP_USER_AGENT'}, ", ", $ENV{'HTTP_FROM'}, ", ", $iver, "\n" ;

 #  "\n\n";
#  print ,"\n\n";

#  print $counter;
  exit;
 }

Thats what I have to work with.
0
 
LVL 6

Accepted Solution

by:
sstouk earned 600 total points
ID: 6963431
The problem is in the line:
, ",",  $time

Please either remark it or remove it.
I tested your script on my server.
As soon as I remarked the line, it created a text file and
responded to Internet Explorer's request properly.
0
 
LVL 4

Author Comment

by:Glowman
ID: 6963551
Thanks for your prompt response and trials.
Works great now.  Perl is one tough cookie with its syntax.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface In the first article: A Better Website Login System (http://www.experts-exchange.com/A_2902.html) I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Six Sigma Control Plans
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question