Solved

Struggling with cgi

Posted on 2002-04-23
6
315 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
Comment Utility
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
Comment Utility
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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Author Comment

by:Glowman
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks for your prompt response and trials.
Works great now.  Perl is one tough cookie with its syntax.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now