Solved

Struggling with cgi

Posted on 2002-04-23
6
325 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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 150 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

856 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