r786 - html/trunk/clfs html/trunk/lfs scripts/trunk

justin at linuxfromscratch.org justin at linuxfromscratch.org
Tue Aug 8 00:25:09 PDT 2006


Author: justin
Date: 2006-08-08 01:25:07 -0600 (Tue, 08 Aug 2006)
New Revision: 786

Added:
   scripts/trunk/lfscounter.cgi
Modified:
   html/trunk/clfs/menu.html
   html/trunk/lfs/menu.html
Log:
First try, adding lfscounter.cgi to svn.

Modified: html/trunk/clfs/menu.html
===================================================================
--- html/trunk/clfs/menu.html	2006-08-05 04:32:06 UTC (rev 785)
+++ html/trunk/clfs/menu.html	2006-08-08 07:25:07 UTC (rev 786)
@@ -1,7 +1,7 @@
     <div id="leftmenu">
       <ul id="clfsmenulist">
 	<li><a href="/clfs/index.html">CLFS Home</a></li>
-	<li><a href="http://www.linuxfromscratch.org/cgi-bin/lfscounter.cgi">Get Counted</a></li>
+	<li><a href="http://www.linuxfromscratch.org/cgi-bin/scripts/lfscounter.cgi">Get Counted</a></li>
         <li><a href="/clfs/contribute.html">Contribute</a></li>
       </ul>
     </div>

Modified: html/trunk/lfs/menu.html
===================================================================
--- html/trunk/lfs/menu.html	2006-08-05 04:32:06 UTC (rev 785)
+++ html/trunk/lfs/menu.html	2006-08-08 07:25:07 UTC (rev 786)
@@ -4,7 +4,7 @@
 	<li><a href="/lfs/news.html">News</a></li>
 	<li><a href="/lfs/download.html">Download</a></li>
 	<li><a href="/lfs/read.html">Read Online</a></li>
-	<li><a href="http://www.linuxfromscratch.org/cgi-bin/lfscounter.cgi">Get Counted</a></li>
+	<li><a href="http://www.linuxfromscratch.org/cgi-bin/scripts/lfscounter.cgi">Get Counted</a></li>
 	<li><a href="/lfs/support.html">Support</a></li>
         <li><a href="/mail.html">Mailing Lists</a></li>
         <li><a href="/lfs/contribute.html">Contribute</a></li>

Added: scripts/trunk/lfscounter.cgi
===================================================================
--- scripts/trunk/lfscounter.cgi	                        (rev 0)
+++ scripts/trunk/lfscounter.cgi	2006-08-08 07:25:07 UTC (rev 786)
@@ -0,0 +1,237 @@
+#!/usr/bin/perl -w
+# lfscounter.cgi - registers new LFS users and/or queries database for existing users.
+# Based on an earlier lfscounter.cgi
+# Major revisions by Jeremy Huntwork, 06-18-2004
+# $Id$
+
+use strict;
+use Template;
+use CGI;
+use Mysql;
+
+my $table = "users";
+my $me = "http://www.linuxfromscratch.org/cgi-bin/scripts/lfscounter.cgi";
+my $register;
+my $query;
+my $total;
+my $getUsers;
+my $pageType;
+my %query_hash;
+my @query_array;
+my @query_parts;
+my $reg_msg;
+my $ch = new CGI;
+my $dbhost = "localhost:3306";
+my $database = "lfscounter";
+my $dbuser = "lfscounter";
+my $dbpass = "12lfscounter34";
+my $db = Mysql->connect($dbhost, $database, $dbuser, $dbpass);
+
+my $name_regex = q/^(\w+[\s\w\-\.']*\w+)*$/;
+my $first_lfs_regex = '^1\.x$|^1\.0$|^1\.1$|^1\.2$|^1\.3$|' .
+	'^2\.x$|^2\.0\-beta1$|^2\.0\-beta2$|^2\.0\-pre1$|^2\.x\.x$|^2\.1\.x$|' .
+	'^2\.1\.5$|^2\.2$|^2\.3\.x$|^2\.3\.1$|^2\.3\.2$|^2\.3\.3$|' .
+	'^2\.3\.4$|^2\.3\.5$|^2\.3\.5b$|^2\.3\.6$|^2\.3\.7$|' .
+	'^2\.4$|^2\.4\.x$|^2\.4\.1$|^2\.4\.2$|^2\.4\.3$|^2\.4\.4$|' .
+	'^3\.0\-prex$|^3\.0\-pre1$|^3\.0\-pre2$|^3\.0\-pre3$|^3\.0\-pre4$|' .
+	'^3\.0\-rcx$|^3\.0\-rc1$|^3\.0\-rc2$|^3\.x$|^3\.0$|^3\.1$|^3\.2\-rc1$|' .
+	'^3\.2\-rc2$|^3\.2$|^3\.3$|^4\.x$|^4\.0\-rc1$|^4\.0$|^4\.1$|' .
+	'^5\.0\-pre1$|^5\.0\-pre2$|^5\.0\-pre3$|^5\.0$|^5\.1\-pre1$|^5\.1$|' .
+	'^5\.1\.1$|^6\.0$|^6\.1$|^6\.1\.1$|^6\.2$|^cvs$|^SVN$|^hlfs\-svn$|^clfs\-svn$';
+my $cvs_date_regex = '^\d{8,8}$';
+my $id_regex = '^\d{1,5}$';
+my $order_by_regex = '^id$|^name$|^first_lfs$';
+my $position_regex = '^\d{1,5}$';
+my $increment_regex = '^\d{1,5}$';
+my $sort_order_regex = '^asc$|^desc$';
+my $name_length = "30";
+my $first_lfs_length = "9";
+my $cvs_date_length = "8";
+my $id_length = "5";
+my $order_by_length = "9";
+my $position_length = "5";
+my $increment_length = "5";
+my $sort_order_length = "4";
+
+print "Content-type: text/html\n\n";
+
+my $file ='lfscounter.tmpl';
+my $vars = {
+	'totallfsers' => \&getTotal,
+	'me' => 'http://www.linuxfromscratch.org/cgi-bin/scripts/lfscounter.cgi',
+	'pageType' => \&getPageType,
+	'queryVars' => \&Query,
+	'regVars' => \&RegisterUser
+};
+
+my $template = Template->new({
+	INCLUDE_PATH => 'templates:templates/global',
+	PRE_PROCESS => 'lfscountercgi.conf'
+});
+
+$template->process($file, $vars) || die "Template process failed: ", $template->error(), "\n";
+
+
+sub getTotal {
+	my $sql_query = "select count(id) from $table";
+	my $getCount = $db->query($sql_query);
+	$total = $getCount->fetchrow;
+	return $total;
+}
+
+sub getPageType {
+	if (! $ch->param()) {
+		$pageType = 0;
+	} else {
+		$register = $ch->param('register');
+		$query = $ch->param('query');
+		if ($register) {
+			$pageType = 2;
+		} elsif ($query) {
+			$pageType = 1;
+		} else {
+			$pageType = 0;
+		}
+	}
+	return $pageType;
+}
+sub Query {
+	if ($pageType ne 1){
+		return;
+	} else {
+		my $id = $ch->param('query_id');
+		my $name = $ch->param('query_name');
+		my $first_lfs = $ch->param('query_first_lfs');
+		my $cvs_date = $ch->param('cvs_date');
+		my $order_by = $ch->param('order_by');
+		if (!$order_by) { $order_by = "id"; }
+		my $sort_order = $ch->param('sort_order');
+		if (!$sort_order) { $sort_order = "asc"; }
+		my $increment = $ch->param('increment');
+		if (!$increment) { $increment = "25"; };
+		my $lfsuserQuery;
+		my $position = $ch->param('position');
+		if (!$position) { $position = 0; }
+		my $lastposition;
+
+		if (!$id && !$name && !$first_lfs) {
+			$lfsuserQuery = "select * from $table order by $order_by $sort_order limit $position,$increment";
+			$total = getTotal();
+		} else {
+			if ($id) {
+				push (@query_parts, "id='$id'");
+			}
+			if ($name) {
+				push (@query_parts, "name regexp \"^.*$name.*\$\"");
+			}
+			if ($first_lfs && ($first_lfs ne "cvs")) {
+				push (@query_parts, "first_lfs='$first_lfs'");
+			}
+			elsif (($first_lfs eq "cvs") && $cvs_date) {
+				push (@query_parts, "first_lfs='$cvs_date'");
+			} 
+			elsif (($first_lfs eq "cvs") && !$cvs_date) {
+				push (@query_parts, "first_lfs regexp \"^[0-9]{8}\$\"");
+			}
+			$lfsuserQuery = "select count(id) from $table where " .
+				join (" and ", at query_parts). " order by $order_by";
+
+			my $getCount = $db->query($lfsuserQuery);
+			$total = $getCount->fetchrow;
+
+			$lfsuserQuery = "select * from $table where " .
+				join (" and ", at query_parts). " order by $order_by $sort_order limit $position,$increment";
+		}
+		if ($lfsuserQuery) {
+			$getUsers = $db->query($lfsuserQuery);
+			while (%query_hash = $getUsers->fetchhash){
+				push @query_array, { %query_hash }
+			}
+			%query_hash = (
+				query_id => $id,
+				query_name => $name,
+				query_first_lfs => $first_lfs,
+				position => ($position + $increment),
+				lastposition => ($position - $increment),
+				increment => $increment,
+				order_by => $order_by,
+				sort_order => $sort_order,
+				total => $total
+			);
+			push @query_array, { %query_hash }
+		}
+	}
+return \@query_array;
+}
+
+sub RegisterUser() {
+	if ($pageType ne 2){
+		return
+	} else {
+		my $name = $ch->param('reg_name');
+		my $first_lfs = $ch->param('reg_first_lfs');
+		my $cvs_date = $ch->param('reg_cvs_date');
+
+		if (!$name){
+			$reg_msg = "<font color=\"red\">You forgot to enter your name!</font>"
+		} elsif ($name !~ $name_regex) {
+			$reg_msg = "You entered: <strong>$name</strong>
+					<br />This does not match the expected regular expression for a name:
+					<strong>$name_regex</strong>
+					<br />Please try again.";
+		} elsif (length($name) > $name_length) {
+			$reg_msg = "Maximum length for name exceeded.<br />
+					Please enter a name that is less than $name_length characters.";
+		} elsif (($first_lfs eq "cvs") || ($cvs_date)) {
+			if (!$cvs_date){
+				$reg_msg = "<font color=\"red\">You forgot to enter a CVS date!</font>"
+			} else {
+				if ($cvs_date !~ $cvs_date_regex){
+					$reg_msg = "You entered: <strong>$cvs_date</strong>
+						<br />This does not match the expected regular expression
+						for a CVS date: <strong>$cvs_date_regex</strong>
+						<br />Please try again.";
+				} elsif ($cvs_date < 20010124){
+					$reg_msg = "Invalid value for CVS Date: <strong>$cvs_date</strong>
+						<br />This date is earlier than when CVS first became
+						operational at <strong>20010124</strong>
+						<br />Please try again.";
+				} else {
+					$first_lfs = $cvs_date;
+				}
+			}
+		} elsif ($first_lfs !~ $first_lfs_regex) {
+			$reg_msg = "You entered: <strong>$first_lfs</strong>
+				<br />This does not match the expected regular expression for a
+				First LFS Version.
+				<br />Please try again.";
+		} else {
+			my $lcname = lc($name);
+			my $name_check = $db->query("select * from $table where name='$lcname'");
+			$total = $name_check->numrows;
+			if ($total > 0){
+				my %row = $name_check->fetchhash;
+				my $exist_id = $row{'id'};
+				my $exist_name = $row{'name'};
+				my $exist_first_lfs = $row{'first_lfs'};
+				$reg_msg = "You have registered already:
+					<br />ID: <strong>$exist_id</strong>
+					<br />Name: <strong>$exist_name</strong>
+					<br />First LFS Version: <strong>$exist_first_lfs</strong>";
+			} else {
+				$db->query("insert into $table (name, first_lfs) values ('$name', '$first_lfs')");
+				my $getID = $db->query("select * from $table where name='$name'
+					and first_lfs='$first_lfs'");
+				my %row = $getID->fetchhash;
+				my $new_id = $row{'id'};
+				my $new_name = $row{'name'};
+				my $new_first_lfs = $row{'first_lfs'};
+				$reg_msg = "You have successfully registered!
+					<br />ID: <strong>$new_id</strong>
+					<br />Name: <strong>$new_name</strong>
+					<br />First LFS Version: <strong>$new_first_lfs</strong>";
+			}
+		}
+	}
+return $reg_msg;
+}




More information about the website mailing list