Mellowz
08-04-2004, 03:46 AM
This code will tell how many users are on my site, but I have problems setting the permissions. Someone help?
The Steps:
1.) Using a Zip decompression utility, extract the contents of UsersOnline*.zip.
2.) Open UsersOnline.cgi and make sure that the first line points to the correct path to your Perl interpreter. On most web servers the default setting will work perfectly. If you don't know where your perl interpreter is located, please ask your system administrators.
3.) Open your favorite FTP program and upload UsersOnline.cgi and logs.txt into your cgi-bin directory or any directory that allows you to run CGI scripts on your web server.
STEP I'M STUCK ON:
4.) Change UsersOnline.cgi permission mode 0755 and logs.txt to 0777. In most FTP programs, you can change the permissions on the files by right clicking on the files. You should then choose the option CHMOD or Change Permissions.
5.) Open your favorite web browser and run the UsersOnline.cgi by typing in the URL to the file on your web server in the location bar. If you see no error, you have done everything right.
Now, here's the code:
#!/usr/local/bin/perl
########## CONFIGURATIONS ###############
###The number of minutes of inactivity that a user is considered not-online
$CONFIG{active_duration}= q|10|;
### THis is the path to the file that we can write information to... CHange it to 0777
$CONFIG{log_file}= q|/home/jumbocgi/public_html/demo/usersonline/usersonline-txt1.0/logs.txt|;
##This is the text to display for than 1 user... [%ONLINE%] will be replaced with the actual number of users online.
$CONFIG{onlines}= q|There are [%ONLINE%] users online|;
##This is the text to display for only 1 user online
$CONFIG{online_template}= q|There is 1 user online|;
#################################################################
# UsersOnline
# ===============================================================
# Software First Released Date: 1/16/2004
# Software Last Updated Date: 1/23/2004
# Software Version Number: 1.01
# ===============================================================
# Software Distributed from: http://www.jumboCGI.com
# Software Written by: Kevin Pham kevin@jumboCGI.com
# Software Documented by: Kevin Pham http://www.jumboCGI.com
# Copyright (c)2000-2004 jumboCGI.com - All Rights Reserved
#################################################################
#1. License
#Selling or distributing the code of this software or a software
#derived from this software, without our prior written consent is
#expressly forbidden.
#
#2. Indemnification
#User agrees that it shall defend, indemnify, save and hold
#jumbocgi.com and any persons affiliated with jumbocgi.com,
#harmless from any and all demands, liabilities, losses, costs and claims,
#including reasonable attorney's fees asserted against jumbocgi.com,
#its agents, its customers, officers and employees, that may arise or result
#from any service provided or performed or agreed to be performed or any product
#sold by customer, its agents, employees or assigns. Customer agrees to defend,
#indemnify and hold harmless jumbocgi.com, its agents, its cusomters, officers,
#and employes, against liabilities arising out of:
#(a) any injury to person or property caused by a products sold or otherwise
# distributed in connection with mojoScripts.com products;
#(b) any material supplied by customer infringing or allegedly infringing on the
#proprietary rights of a third party;
#(c) copyright infringement and
#(d) any defective products sold to customer from jumbocgi.com
#
#3. Bugs
# For Comments, suggestions, or bugs reporting, please visit
# http://www.jumbocgi.com/forum/
#################################################################
##################################################
&main();
sub main{
$|++;
$CONFIG{systemtime} = time;
$CONFIG{active_duration} *= 60;
$CONFIG{lsh}= q|1|;
$CONFIG{lex}= q|2|;
$CONFIG{lun}= q|8|;
&LogUser();
&LogCleaning();
&WhoIsOnline();
}
sub LogUser{
my(@lines, $match, @tokens);
@lines = &LogCleaning($ENV{REMOTE_ADDR});
foreach (@lines){
@tokens = split(/\|/, $_);
if($tokens[1] eq $ENV{REMOTE_ADDR}){
$match = 1;
last;
}
}
unless($match){
push(@lines, "$CONFIG{systemtime}|$ENV{REMOTE_ADDR}|");
}
&FileWrite($CONFIG{log_file}, \@lines);
my $online = @lines;
if($online > 1){
($CONFIG{online_template} = $CONFIG{onlines}) =~ s/\[%ONLINE%\]/$online/gi;
}
}
sub LogCleaning{
my(@content,$line, @lines);
@lines = &FileRead($CONFIG{log_file});
foreach $line (@lines){
@tokens = split(/\|/, $line);
if ($tokens[0] + $CONFIG{active_duration} > $CONFIG{systemtime}){
push(@content, $line);
}
}
return wantarray?@content:\@content;
}
sub WhoIsOnline{
print "content-type: text/html\n\n";
if($ENV{QUERY_STRING} =~ /js/i){ print qq~document.write('$CONFIG{online_template}');~; }
else{ print $CONFIG{online_template}; }
exit;
}
sub FileRead{
my(@content,$file, $mode);
($file, $mode) = @_;
open (FILE, $file) or ($CONFIG{error} = $! and return 0);
binmode FILE if $mode;
while(<FILE>){
chomp;
push(@content, $_);
}
close(FILE);
return wantarray?@content:join("\n", @content);
}
sub FileWrite{
my(@content, $file, $ptr, $mode);
($file, $ptr, $mode)= @_;
open (FILE,">$file") or ($CONFIG{error} = $! and return 0);
flock($FILE, $CONFIG{lex});
binmode FILE if $mode;
if(ref($ptr) eq "SCALAR"){ print FILE $$ptr."\n"; }
elsif(ref($ptr) eq "ARRAY"){ foreach (@$ptr){ print FILE $_."\n"; } }
elsif(ref($ptr) eq "HASH"){ foreach (keys %$ptr){ print FILE "$_=qq|${%$ptr}{$_}|;"; }}
else{ print FILE $ptr."\n"; }
flock($FILE, $CONFIG{lun});
close(FILE);
chmod(0777, $file);
return 1;
}
1;
I need to kow how to set the Permissions...or maybe they are correct my server just doesn't like it.
The Steps:
1.) Using a Zip decompression utility, extract the contents of UsersOnline*.zip.
2.) Open UsersOnline.cgi and make sure that the first line points to the correct path to your Perl interpreter. On most web servers the default setting will work perfectly. If you don't know where your perl interpreter is located, please ask your system administrators.
3.) Open your favorite FTP program and upload UsersOnline.cgi and logs.txt into your cgi-bin directory or any directory that allows you to run CGI scripts on your web server.
STEP I'M STUCK ON:
4.) Change UsersOnline.cgi permission mode 0755 and logs.txt to 0777. In most FTP programs, you can change the permissions on the files by right clicking on the files. You should then choose the option CHMOD or Change Permissions.
5.) Open your favorite web browser and run the UsersOnline.cgi by typing in the URL to the file on your web server in the location bar. If you see no error, you have done everything right.
Now, here's the code:
#!/usr/local/bin/perl
########## CONFIGURATIONS ###############
###The number of minutes of inactivity that a user is considered not-online
$CONFIG{active_duration}= q|10|;
### THis is the path to the file that we can write information to... CHange it to 0777
$CONFIG{log_file}= q|/home/jumbocgi/public_html/demo/usersonline/usersonline-txt1.0/logs.txt|;
##This is the text to display for than 1 user... [%ONLINE%] will be replaced with the actual number of users online.
$CONFIG{onlines}= q|There are [%ONLINE%] users online|;
##This is the text to display for only 1 user online
$CONFIG{online_template}= q|There is 1 user online|;
#################################################################
# UsersOnline
# ===============================================================
# Software First Released Date: 1/16/2004
# Software Last Updated Date: 1/23/2004
# Software Version Number: 1.01
# ===============================================================
# Software Distributed from: http://www.jumboCGI.com
# Software Written by: Kevin Pham kevin@jumboCGI.com
# Software Documented by: Kevin Pham http://www.jumboCGI.com
# Copyright (c)2000-2004 jumboCGI.com - All Rights Reserved
#################################################################
#1. License
#Selling or distributing the code of this software or a software
#derived from this software, without our prior written consent is
#expressly forbidden.
#
#2. Indemnification
#User agrees that it shall defend, indemnify, save and hold
#jumbocgi.com and any persons affiliated with jumbocgi.com,
#harmless from any and all demands, liabilities, losses, costs and claims,
#including reasonable attorney's fees asserted against jumbocgi.com,
#its agents, its customers, officers and employees, that may arise or result
#from any service provided or performed or agreed to be performed or any product
#sold by customer, its agents, employees or assigns. Customer agrees to defend,
#indemnify and hold harmless jumbocgi.com, its agents, its cusomters, officers,
#and employes, against liabilities arising out of:
#(a) any injury to person or property caused by a products sold or otherwise
# distributed in connection with mojoScripts.com products;
#(b) any material supplied by customer infringing or allegedly infringing on the
#proprietary rights of a third party;
#(c) copyright infringement and
#(d) any defective products sold to customer from jumbocgi.com
#
#3. Bugs
# For Comments, suggestions, or bugs reporting, please visit
# http://www.jumbocgi.com/forum/
#################################################################
##################################################
&main();
sub main{
$|++;
$CONFIG{systemtime} = time;
$CONFIG{active_duration} *= 60;
$CONFIG{lsh}= q|1|;
$CONFIG{lex}= q|2|;
$CONFIG{lun}= q|8|;
&LogUser();
&LogCleaning();
&WhoIsOnline();
}
sub LogUser{
my(@lines, $match, @tokens);
@lines = &LogCleaning($ENV{REMOTE_ADDR});
foreach (@lines){
@tokens = split(/\|/, $_);
if($tokens[1] eq $ENV{REMOTE_ADDR}){
$match = 1;
last;
}
}
unless($match){
push(@lines, "$CONFIG{systemtime}|$ENV{REMOTE_ADDR}|");
}
&FileWrite($CONFIG{log_file}, \@lines);
my $online = @lines;
if($online > 1){
($CONFIG{online_template} = $CONFIG{onlines}) =~ s/\[%ONLINE%\]/$online/gi;
}
}
sub LogCleaning{
my(@content,$line, @lines);
@lines = &FileRead($CONFIG{log_file});
foreach $line (@lines){
@tokens = split(/\|/, $line);
if ($tokens[0] + $CONFIG{active_duration} > $CONFIG{systemtime}){
push(@content, $line);
}
}
return wantarray?@content:\@content;
}
sub WhoIsOnline{
print "content-type: text/html\n\n";
if($ENV{QUERY_STRING} =~ /js/i){ print qq~document.write('$CONFIG{online_template}');~; }
else{ print $CONFIG{online_template}; }
exit;
}
sub FileRead{
my(@content,$file, $mode);
($file, $mode) = @_;
open (FILE, $file) or ($CONFIG{error} = $! and return 0);
binmode FILE if $mode;
while(<FILE>){
chomp;
push(@content, $_);
}
close(FILE);
return wantarray?@content:join("\n", @content);
}
sub FileWrite{
my(@content, $file, $ptr, $mode);
($file, $ptr, $mode)= @_;
open (FILE,">$file") or ($CONFIG{error} = $! and return 0);
flock($FILE, $CONFIG{lex});
binmode FILE if $mode;
if(ref($ptr) eq "SCALAR"){ print FILE $$ptr."\n"; }
elsif(ref($ptr) eq "ARRAY"){ foreach (@$ptr){ print FILE $_."\n"; } }
elsif(ref($ptr) eq "HASH"){ foreach (keys %$ptr){ print FILE "$_=qq|${%$ptr}{$_}|;"; }}
else{ print FILE $ptr."\n"; }
flock($FILE, $CONFIG{lun});
close(FILE);
chmod(0777, $file);
return 1;
}
1;
I need to kow how to set the Permissions...or maybe they are correct my server just doesn't like it.