Added .htaccess
Changed kwotes.conf.pl to not use "constant", and modified the rest of the scripts to reflect that
This commit is contained in:
		
							
								
								
									
										3
									
								
								.htaccess
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.htaccess
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
AddHandler cgi-script .pl
 | 
			
		||||
Options +ExecCGI
 | 
			
		||||
Options -Indexes
 | 
			
		||||
@@ -50,23 +50,23 @@ sub cleanup {
 | 
			
		||||
		"INSERT INTO kwote_backup SELECT * FROM kwote WHERE ".
 | 
			
		||||
		"(now()-submit_dt)>? AND rating<=?"
 | 
			
		||||
	);
 | 
			
		||||
	$sth->bind_param(1, NEGATIVE_KWOTE_TTL);
 | 
			
		||||
	$sth->bind_param(2, KWOTE_DEATH_RATING);
 | 
			
		||||
	$sth->bind_param(1, $NEGATIVE_KWOTE_TTL);
 | 
			
		||||
	$sth->bind_param(2, $KWOTE_DEATH_RATING);
 | 
			
		||||
	$sth->execute() or die "Couldn't backup kwotes";
 | 
			
		||||
 | 
			
		||||
	# delete kwotes
 | 
			
		||||
	$sth = $dbh->prepare(
 | 
			
		||||
		"DELETE FROM kwote WHERE (now()-submit_dt)>? AND rating<=?"
 | 
			
		||||
	);
 | 
			
		||||
	$sth->bind_param(1, NEGATIVE_KWOTE_TTL);
 | 
			
		||||
	$sth->bind_param(2, KWOTE_DEATH_RATING);
 | 
			
		||||
	$sth->bind_param(1, $NEGATIVE_KWOTE_TTL);
 | 
			
		||||
	$sth->bind_param(2, $KWOTE_DEATH_RATING);
 | 
			
		||||
	$sth->execute() or die "Couldn't delete kwotes";
 | 
			
		||||
 | 
			
		||||
	# delete the vote log (this doesn't affect kwote rating)
 | 
			
		||||
	$sth = $dbh->prepare(
 | 
			
		||||
		"DELETE FROM vote WHERE (now()-vote_dt)>?"
 | 
			
		||||
	);
 | 
			
		||||
	$sth->bind_param(1, VOTE_TTL);
 | 
			
		||||
	$sth->bind_param(1, $VOTE_TTL);
 | 
			
		||||
	$sth->execute() or die "Couldn't delete votes";
 | 
			
		||||
	
 | 
			
		||||
	# let em know we're good 
 | 
			
		||||
@@ -99,7 +99,7 @@ sub  vote {
 | 
			
		||||
	my $row = $sth->fetchrow_hashref();
 | 
			
		||||
	
 | 
			
		||||
	# check if they suck
 | 
			
		||||
	return undef if ($row->{"vote_count"}>=MAX_VOTES_PER_IP);
 | 
			
		||||
	return undef if ($row->{"vote_count"}>=$MAX_VOTES_PER_IP);
 | 
			
		||||
	
 | 
			
		||||
	# prepare
 | 
			
		||||
	$sth = $dbh->prepare(
 | 
			
		||||
@@ -136,7 +136,7 @@ sub add_kwote {
 | 
			
		||||
		"SELECT COUNT(*) as kwote_count FROM kwote WHERE ip_address=? AND (now()-submit_dt)<?"
 | 
			
		||||
	);
 | 
			
		||||
	$sth->bind_param(1, $ip_address);
 | 
			
		||||
	$sth->bind_param(2, SECS_BETWEEN_KWOTES);
 | 
			
		||||
	$sth->bind_param(2, $SECS_BETWEEN_KWOTES);
 | 
			
		||||
	
 | 
			
		||||
	# execute
 | 
			
		||||
	$sth->execute() or return undef;
 | 
			
		||||
@@ -145,7 +145,7 @@ sub add_kwote {
 | 
			
		||||
	my $row = $sth->fetchrow_hashref() or return undef;
 | 
			
		||||
	
 | 
			
		||||
	# check if they suck
 | 
			
		||||
	return undef if ($row->{"kwote_count"}>=MAX_KWOTES_PER_IP);
 | 
			
		||||
	return undef if ($row->{"kwote_count"}>=$MAX_KWOTES_PER_IP);
 | 
			
		||||
	
 | 
			
		||||
	# prepare statement
 | 
			
		||||
	my $sth = $dbh->prepare(
 | 
			
		||||
@@ -258,9 +258,9 @@ sub list_kwotes {
 | 
			
		||||
sub get_db_connection {
 | 
			
		||||
	if (!$GLOBAL_DBH) {
 | 
			
		||||
		$GLOBAL_DBH = DBI->connect(
 | 
			
		||||
			"dbi:".DB_TYPE.":".DB_NAME.":".DB_HOST,
 | 
			
		||||
			DB_USER,
 | 
			
		||||
			DB_PASS
 | 
			
		||||
			"dbi:$DB_TYPE:$DB_NAME:$DB_HOST",
 | 
			
		||||
			$DB_USER,
 | 
			
		||||
			$DB_PASS
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
	return $GLOBAL_DBH;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,45 +1,54 @@
 | 
			
		||||
#!/usr/bin/perl
 | 
			
		||||
 | 
			
		||||
use constant {
 | 
			
		||||
	DB_TYPE						=> "mysql",		# dbi database type (only MySQL is
 | 
			
		||||
												# supported currently, due to the
 | 
			
		||||
												# fact that "LIMIT X,X" is used
 | 
			
		||||
$DB_TYPE = "mysql";
 | 
			
		||||
# dbi database type (only MySQL is
 | 
			
		||||
# supported currently, due to the
 | 
			
		||||
# fact that "LIMIT X,X" is used
 | 
			
		||||
												
 | 
			
		||||
	DB_NAME						=> "kwotes",	# database name
 | 
			
		||||
$DB_NAME = "kwotes";
 | 
			
		||||
# database name
 | 
			
		||||
	
 | 
			
		||||
	DB_HOST						=> "127.0.0.1",	# database host
 | 
			
		||||
$DB_HOST = "mysql";
 | 
			
		||||
# database host
 | 
			
		||||
 | 
			
		||||
	DB_USER						=> "kwotes",	# database user
 | 
			
		||||
$DB_USER = "kwotes";
 | 
			
		||||
# database user
 | 
			
		||||
	
 | 
			
		||||
	DB_PASS						=> "kw0tes",	# database password
 | 
			
		||||
$DB_PASS = "kw0t3s";
 | 
			
		||||
# database password
 | 
			
		||||
	
 | 
			
		||||
	SECS_BETWEEN_KWOTES			=>	60*60,		# seconds a user must wait after
 | 
			
		||||
												# submitting MAX_KWOTES_PER_IP
 | 
			
		||||
												# kwotes to the system before they
 | 
			
		||||
												# are allowed to submit another
 | 
			
		||||
												# kwote
 | 
			
		||||
$SECS_BETWEEN_KWOTES = 60*60;
 | 
			
		||||
# seconds a user must wait after
 | 
			
		||||
# submitting MAX_KWOTES_PER_IP
 | 
			
		||||
# kwotes to the system before they
 | 
			
		||||
# are allowed to submit another
 | 
			
		||||
# kwote
 | 
			
		||||
	
 | 
			
		||||
	KWOTE_DEATH_RATING			=>	-1,			# lowest rating a quote can be
 | 
			
		||||
												# before it's deleted.  A kwote is
 | 
			
		||||
												# only deleted if it's been this
 | 
			
		||||
												# number (or lower) for longer than
 | 
			
		||||
												# the KWOTE_TTL
 | 
			
		||||
$KWOTE_DEATH_RATING = -1;
 | 
			
		||||
# lowest rating a quote can be
 | 
			
		||||
# before it's deleted.  A kwote is
 | 
			
		||||
# only deleted if it's been this
 | 
			
		||||
# number (or lower) for longer than
 | 
			
		||||
# the KWOTE_TTL
 | 
			
		||||
												
 | 
			
		||||
	KWOTE_TTL					=> (60*60)*24,	# seconds before a "dead"
 | 
			
		||||
												# quote is moved to the kwote
 | 
			
		||||
												# backup table and deleted
 | 
			
		||||
$KWOTE_TTL = (60*60)*24;	
 | 
			
		||||
# seconds before a "dead"
 | 
			
		||||
# quote is moved to the kwote
 | 
			
		||||
# backup table and deleted
 | 
			
		||||
												
 | 
			
		||||
	VOTE_TTL					=> (60*60)*24,	# seconds a vote log lasts, the vote
 | 
			
		||||
												# log is the mechanism that keeps
 | 
			
		||||
												# people from voting over and over
 | 
			
		||||
$VOTE_TTL = (60*60)*24;
 | 
			
		||||
# seconds a vote log lasts, the vote
 | 
			
		||||
# log is the mechanism that keeps
 | 
			
		||||
# people from voting over and over
 | 
			
		||||
												
 | 
			
		||||
	MAX_VOTES_PER_IP			=>	4,			# maximum votes per ip address per
 | 
			
		||||
												# VOTE_TTL seconds.
 | 
			
		||||
$MAX_VOTES_PER_IP = 4;
 | 
			
		||||
# maximum votes per ip address per
 | 
			
		||||
# VOTE_TTL seconds.
 | 
			
		||||
	
 | 
			
		||||
	MAX_KWOTES_PER_IP			=>  5			# maximum kwotes allowed per ip
 | 
			
		||||
												# in SECS_BETWEEN_KWOTES
 | 
			
		||||
$MAX_KWOTES_PER_IP = 5;
 | 
			
		||||
# maximum kwotes allowed per ip
 | 
			
		||||
# in SECS_BETWEEN_KWOTES
 | 
			
		||||
												
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
1;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								kwotes.pl
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								kwotes.pl
									
									
									
									
									
								
							@@ -7,12 +7,12 @@
 | 
			
		||||
# something about kwotes being GPL                #
 | 
			
		||||
###################################################
 | 
			
		||||
 | 
			
		||||
# bring in the config
 | 
			
		||||
require "kwotes.conf.pl";
 | 
			
		||||
 | 
			
		||||
# bring in the required libs
 | 
			
		||||
require "kwotes-lib.pl";
 | 
			
		||||
 | 
			
		||||
# bring in the config
 | 
			
		||||
require "kwotes.conf.pl";
 | 
			
		||||
 | 
			
		||||
# is this getting called by the "delete" cronjob?
 | 
			
		||||
if ($ARGV[0] eq "cleanup") {
 | 
			
		||||
	exit cleanup();
 | 
			
		||||
@@ -31,13 +31,13 @@ foreach my $key (keys %ENV) {
 | 
			
		||||
	$vars{$key} = $ENV{$key};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
# send the HTML header
 | 
			
		||||
send_html_header();
 | 
			
		||||
 | 
			
		||||
# add information that is displayed on every page
 | 
			
		||||
$vars{KWOTE_COUNT} = get_kwote_count();
 | 
			
		||||
$vars{KWOTE_BACKUP_COUNT} = get_kwote_backup_count();
 | 
			
		||||
 | 
			
		||||
# send the HTML header
 | 
			
		||||
send_html_header();
 | 
			
		||||
 | 
			
		||||
############
 | 
			
		||||
# action: add (show add form)
 | 
			
		||||
if ($action eq "add") {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user