?
Solved

Struggling with cgi

Posted on 2002-04-23
6
Medium Priority
?
332 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

 
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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
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…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

770 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