[PC-BSD Commits] r3321 - in websites/bsdstats.org: . bsdstats/lib scripts

svn at pcbsd.org svn at pcbsd.org
Fri Jan 23 18:26:31 PST 2009


Author: fabry
Date: 2009-01-23 18:26:30 -0800 (Fri, 23 Jan 2009)
New Revision: 3321

Removed:
   websites/bsdstats.org/_includes/
   websites/bsdstats.org/_templates/
   websites/bsdstats.org/_tpl_c/
   websites/bsdstats.org/freebsd/
   websites/bsdstats.org/midnightbsd/
Modified:
   websites/bsdstats.org/bsdstats/lib/bsdstats.php
   websites/bsdstats.org/scripts/disable_token.php
   websites/bsdstats.org/scripts/enable_token.php
   websites/bsdstats.org/scripts/getid.php
   websites/bsdstats.org/scripts/report_cpu.php
   websites/bsdstats.org/scripts/report_devices.php
   websites/bsdstats.org/scripts/report_ports.php
   websites/bsdstats.org/scripts/report_system.php
Log:
cleaning some code

Modified: websites/bsdstats.org/bsdstats/lib/bsdstats.php
===================================================================
--- websites/bsdstats.org/bsdstats/lib/bsdstats.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/bsdstats/lib/bsdstats.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -84,6 +84,7 @@
 		if($return==false){
 			$tmps = $this->db->query('SELECT cpus, count(1) AS cnt
 									FROM cpus
+									WHERE operating_system IN (\''.implode('\',\'',$this->get_list_os()).'\')
 									GROUP BY cpus
 									ORDER BY cpus;');
 			$cpu_stats = array();
@@ -93,6 +94,7 @@
 			
 			$tmps = $this->db->query('SELECT vendor, cpu_type, count(1) AS cnt
 									FROM cpus 
+									WHERE operating_system IN (\''.implode('\',\'',$this->get_list_os()).'\')
 									GROUP BY vendor, cpu_type 
 									ORDER BY vendor, cnt DESC;');
 			$vendor_stats = array();

Modified: websites/bsdstats.org/scripts/disable_token.php
===================================================================
--- websites/bsdstats.org/scripts/disable_token.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/disable_token.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,42 +1,11 @@
-<?php
-
-  if ( ! ereg("^fetch", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^OpenBSD ftp", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^Wget", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^MirOS ftp", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^NetBSD-ftp", $_SERVER["HTTP_USER_AGENT"] ) ) {
-    header("Location: /");
-    exit;
-  }
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  if(isset($_GET["key"])) {
-    $key = $_GET["key"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  if(isset($_GET["token"])) {
-    $token = $_GET["token"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-
-  $res = pg_query($conn, "SELECT id
-                           FROM system_ids
-                          WHERE unique_key = '$token'
-                            AND token = '$key';");
-  
-  if(pg_num_rows($res) == 1) {
-    $si = pg_fetch_object($res, 0);
-    pg_query($conn, "UPDATE system_ids SET enable = 'f' WHERE id = $si->id;");
-    print "STATUS=OK\n";
-  } else {
-    print "STATUS=FAIL\n";
-  }
-
-?>
+<?php
+$check_enable	= false;
+require_once 'head.php';
+if(pg_num_rows($res) == 1) {
+	$si = pg_fetch_object($res, 0);
+	pg_query($conn, "UPDATE system_ids SET enable = 'f' WHERE id = $si->id;");
+	print "STATUS=OK\n";
+} else {
+	print "STATUS=FAIL\n";
+}
+?>

Modified: websites/bsdstats.org/scripts/enable_token.php
===================================================================
--- websites/bsdstats.org/scripts/enable_token.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/enable_token.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,42 +1,11 @@
-<?php
-
-  if ( ! ereg("^fetch", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^OpenBSD ftp", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^Wget", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^MirOS ftp", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^NetBSD-ftp", $_SERVER["HTTP_USER_AGENT"] ) ) {
-    header("Location: /");
-    exit;
-  }
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  if(isset($_GET["key"])) {
-    $key = $_GET["key"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  if(isset($_GET["token"])) {
-    $token = $_GET["token"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-
-  $res = pg_query($conn, "SELECT id
-                           FROM system_ids
-                          WHERE unique_key = '$token'
-                            AND token = '$key';");
-
-  if(pg_num_rows($res) == 1) {
-    $si = pg_fetch_object($res, 0);
-    pg_query($conn, "UPDATE system_ids SET enable = 't' WHERE id = $si->id;");
-    print "STATUS=OK\n";
-  } else {
-    print "STATUS=FAIL\n";
-  }
-
-?>
+<?php
+$check_enable	= false;
+require_once 'head.php';
+if(pg_num_rows($res) == 1) {
+	$si = pg_fetch_object($res, 0);
+	pg_query($conn, "UPDATE system_ids SET enable = 't' WHERE id = $si->id;");
+	print "STATUS=OK\n";
+} else {
+	print "STATUS=FAIL\n";
+}
+?>

Modified: websites/bsdstats.org/scripts/getid.php
===================================================================
--- websites/bsdstats.org/scripts/getid.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/getid.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,45 +1,17 @@
-<?php
-
-  if ( ! ereg("^fetch", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^OpenBSD ftp", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^Wget", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^MirOS ftp", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^MirOS LiveCD", $_SERVER["HTTP_USER_AGENT"] ) &&
-       ! ereg("^NetBSD-ftp", $_SERVER["HTTP_USER_AGENT"] ) ) {
-    header("Location: /");
-    exit;
-  }
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  if(isset($_GET["key"])) {
-    $key = $_GET["key"];
-    if(strlen($key) < 40) {
-      print "FAIL: you must upgrade your client\n";
-      exit;
-    }
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  require_once "Net/GeoIP.php";
-
-  $geoip = Net_GeoIP::getInstance("/usr/local/share/GeoIP/GeoIP.dat");
-
-  $country = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
-
-  $uniquekey = md5( $key . $_SERVER['REMOTE_ADDR']);
-
-  $res = pg_query($conn, "SELECT id
-                           FROM system_ids
-                          WHERE token = '$key';");
-
-  if(pg_num_rows($res) == 0) {
-    pg_query($conn, "INSERT INTO system_ids ( unique_key, country_code, first_connect, token ) VALUES ( '$uniquekey', '$country', now(), '$key' );");
-    print "KEY='$uniquekey'\nTOKEN='$key'\n";
-  } else {
-    print "KEY='$uniquekey'\nTOKEN='$key'\n";
-  }
-
-?>
+<?php
+$getid		= true;
+require_once 'head.php';
+require_once "Net/GeoIP.php";
+$geoip		= Net_GeoIP::getInstance("/usr/local/share/GeoIP/GeoIP.dat");
+$country	= $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
+$uniquekey	= md5($key.$_SERVER['REMOTE_ADDR']);
+$res		= pg_query($conn, "SELECT id ".
+							  "FROM system_ids ".
+							  "WHERE token = '$key';");
+if(pg_num_rows($res) == 0) {
+	pg_query($conn, "INSERT INTO system_ids ( unique_key, country_code, first_connect, token ) VALUES ( '$uniquekey', '$country', now(), '$key' );");
+	print "KEY='$uniquekey'\nTOKEN='$key'\n";
+} else {
+	print "KEY='$uniquekey'\nTOKEN='$key'\n";
+}
+?>
\ No newline at end of file

Modified: websites/bsdstats.org/scripts/report_cpu.php
===================================================================
--- websites/bsdstats.org/scripts/report_cpu.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/report_cpu.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,45 +1,19 @@
-<?php
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  if(isset($_GET["key"])) {
-    $key = $_GET["key"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  if(isset($_GET["token"])) {
-    $token = $_GET["token"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  $res = pg_query($conn, "SELECT id
-                            FROM system_ids
-                           WHERE unique_key = '$key'
-                             AND token = '$token'
-                             AND enable;");
-
-  if(pg_num_rows($res) == 1) {
-    pg_query($conn, "BEGIN");
-    $system_ids = pg_fetch_object($res, 0);
-
-    pg_query("DELETE FROM cpus 
-                    WHERE id = $system_ids->id
-                      AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
-
-    $data = pg_fetch_object($res, 0);
-    $cpus = $_GET["cpus"];
-    $vendor = $_GET["vendor"];
-    $cpu_type = $_GET["cpu_type"];
-    pg_query($conn, "INSERT INTO cpus VALUES ( $system_ids->id, $cpus,'$vendor','$cpu_type',now() + '12 hours'::interval);");
-
-    pg_query("COMMIT");
-
-    print "STATUS=OK\n";
-  } else {
-    print "STATUS=FAIL\n";
-  }
-?>
+<?php
+require_once 'head.php';
+if(pg_num_rows($res) == 1) {
+	pg_query($conn, "BEGIN");
+	$system_ids = pg_fetch_object($res, 0);
+	pg_query("DELETE FROM cpus ".
+			 "WHERE id = $system_ids->id ".
+			 "AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
+	$data		= pg_fetch_object($res, 0);
+	$cpus		= $_GET["cpus"];
+	$vendor		= $_GET["vendor"];
+	$cpu_type	= $_GET["cpu_type"];
+	pg_query($conn, "INSERT INTO cpus VALUES ( $system_ids->id, $cpus,'$vendor','$cpu_type',now() + '12 hours'::interval);");
+	pg_query("COMMIT");
+	print "STATUS=OK\n";
+} else {
+	print "STATUS=FAIL\n";
+}
+?>

Modified: websites/bsdstats.org/scripts/report_devices.php
===================================================================
--- websites/bsdstats.org/scripts/report_devices.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/report_devices.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,49 +1,24 @@
-<?php
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  if(isset($_GET["key"])) {
-    $key = $_GET["key"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  if(isset($_GET["token"])) {
-    $token = $_GET["token"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  $res = pg_query($conn, "SELECT id
-                            FROM system_ids
-                           WHERE unique_key = '$key'
-                             AND token = '$token'
-                             AND enable;");
-
-  if(pg_num_rows($res) == 1) {
-    pg_query($conn, "BEGIN");
-    $system_ids = pg_fetch_object($res, 0);
-
-    pg_query("DELETE FROM devices 
-                    WHERE id = $system_ids->id
-                      AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
-
-    $dev_count = count($_GET["dev"]);
-    for($ii=0;$ii<$dev_count;$ii++) {
-      $device = array_pop($_GET["dev"]);
-      list( $driver, $chip, $class ) = split(':', $device);
-      $vendor = substr($chip, 0, 4);
-      $device = substr($chip, 4, 4);
-      $subclass = substr($class, 2, 4);
-      $class = substr($class, 0, 2);
-      pg_query($conn, "INSERT INTO devices ( id, driver, vendor, device, report_month, class, subclass ) VALUES ( $system_ids->id, '$driver','$vendor','$device',now() + '12 hours'::interval, '$class', '$subclass' );");
-    }
-    pg_query($conn, "COMMIT");
-
-    print "STATUS=OK\n";
-  } else {
-    print "STATUS=FAIL\n";
-  }
-?>
+<?php
+require_once 'head.php';
+if(pg_num_rows($res) == 1) {
+	pg_query($conn, "BEGIN");
+	$system_ids = pg_fetch_object($res, 0);
+	pg_query("DELETE FROM devices ".
+			 "WHERE id = $system_ids->id ".
+			    "AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
+	$dev_count = count($_GET["dev"]);
+	for($ii=0;$ii<$dev_count;$ii++) {
+		$device		= array_pop($_GET["dev"]);
+		list( $driver, $chip, $class ) = split(':', $device);
+		$vendor		= substr($chip, 0, 4);
+		$device		= substr($chip, 4, 4);
+		$subclass	= substr($class, 2, 4);
+		$class		= substr($class, 0, 2);
+		pg_query($conn, "INSERT INTO devices ( id, driver, vendor, device, report_month, class, subclass ) VALUES ( $system_ids->id, '$driver','$vendor','$device',now() + '12 hours'::interval, '$class', '$subclass' );");
+	}
+	pg_query($conn, "COMMIT");
+	print "STATUS=OK\n";
+} else {
+	print "STATUS=FAIL\n";
+}
+?>

Modified: websites/bsdstats.org/scripts/report_ports.php
===================================================================
--- websites/bsdstats.org/scripts/report_ports.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/report_ports.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,69 +1,42 @@
-<?php
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  if(isset($_POST["key"])) {
-    $key = $_POST["key"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  if(isset($_POST["token"])) {
-    $token = $_POST["token"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  $res = pg_query($conn, "SELECT id
-                            FROM system_ids
-                           WHERE unique_key = '$key'
-                             AND token = '$token'
-                             AND enable;");
-
-  if(pg_num_rows($res) == 1) {
-    pg_query($conn, "BEGIN");
-    $system_ids = pg_fetch_object($res, 0);
-
-    pg_query("DELETE FROM ports
-                    WHERE id = $system_ids->id
-                      AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
-
-    $dev_count = count($_POST["port"]);
-    for($ii=0;$ii<$dev_count;$ii++) {
-      $record = array_pop($_POST["port"]);
-      list ( $category, $port ) = split(':', $record );
-
-      if (preg_match('/^(.+)-([^\-]+)$/', $port, $matches)) {
-        $portname = $matches[1];
-        $portver = $matches[2];
-
-        $catqry = pg_query($conn, "SELECT id FROM port_categories WHERE category = lower('$category');");
-        if(pg_num_rows($catqry) == 1) {
-          $category_id = pg_fetch_object($catqry, 0);
-        } else {
-          pg_query($conn, "INSERT INTO port_categories ( category ) VALUES ( lower('$category') );");
-          $catqry = pg_query($conn, "SELECT id FROM port_categories WHERE category = lower('$category');");
-          $category_id = pg_fetch_object($catqry, 0);
-        }
-
-        $swqry = pg_query($conn, "SELECT id FROM port_software WHERE software = lower('$portname');");
-        if(pg_num_rows($swqry) == 1) {
-          $software_id = pg_fetch_object($swqry, 0);
-        } else {
-          pg_query($conn, "INSERT INTO port_software ( software ) VALUES ( lower('$portname') );");
-          $swqry = pg_query($conn, "SELECT id FROM port_software WHERE software = lower('$portname');");
-          $software_id = pg_fetch_object($swqry, 0);
-        }
-
-        pg_query($conn, "INSERT INTO ports(  id, catid, sw_id, version, report_month ) VALUES ( $system_ids->id, $category_id->id, $software_id->id, '$portver',now() + '12 hours'::interval );");
-      }
-    }
-    pg_query($conn, "COMMIT");
-
-    print "STATUS=OK\n";
-  } else {
-    print "STATUS=FAIL\n";
-  }
-?>
+<?php
+require_once 'head.php';
+if(pg_num_rows($res) == 1) {
+	pg_query($conn, "BEGIN");
+	$system_ids = pg_fetch_object($res, 0);
+	pg_query("DELETE FROM ports ".
+			 "WHERE id = $system_ids->id ".
+			 	"AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
+	
+	$dev_count = count($_POST["port"]);
+	for($ii=0;$ii<$dev_count;$ii++) {
+		$record = array_pop($_POST["port"]);
+		list ( $category, $port ) = split(':', $record );
+		if (preg_match('/^(.+)-([^\-]+)$/', $port, $matches)) {
+			$portname	= $matches[1];
+			$portver	= $matches[2];
+			$catqry		= pg_query($conn, "SELECT id FROM port_categories WHERE category = lower('$category');");
+			if(pg_num_rows($catqry) == 1) {
+				$category_id	= pg_fetch_object($catqry, 0);
+			} else {
+				pg_query($conn, "INSERT INTO port_categories ( category ) VALUES ( lower('$category') );");
+				$catqry			= pg_query($conn, "SELECT id FROM port_categories WHERE category = lower('$category');");
+				$category_id	= pg_fetch_object($catqry, 0);
+			}
+			$swqry = pg_query($conn, "SELECT id FROM port_software WHERE software = lower('$portname');");
+			if(pg_num_rows($swqry) == 1) {
+				$software_id	= pg_fetch_object($swqry, 0);
+			} else {
+				pg_query($conn, "INSERT INTO port_software ( software ) VALUES ( lower('$portname') );");
+				$swqry			= pg_query($conn, "SELECT id FROM port_software WHERE software = lower('$portname');");
+				$software_id	= pg_fetch_object($swqry, 0);
+			}
+			pg_query($conn, "INSERT INTO ports(  id, catid, sw_id, version, report_month ) VALUES ( $system_ids->id, $category_id->id, $software_id->id, '$portver',now() + '12 hours'::interval );");
+		}
+	}
+	pg_query($conn, "COMMIT");
+	
+	print "STATUS=OK\n";
+} else {
+	print "STATUS=FAIL\n";
+}
+?>

Modified: websites/bsdstats.org/scripts/report_system.php
===================================================================
--- websites/bsdstats.org/scripts/report_system.php	2009-01-22 20:52:51 UTC (rev 3320)
+++ websites/bsdstats.org/scripts/report_system.php	2009-01-24 02:26:30 UTC (rev 3321)
@@ -1,59 +1,31 @@
-<?php
-
-  $conn = pg_pconnect("host=bsdstats.org dbname=bsdstats_new user=pgsql");
-
-  $ip = $_SERVER["REMOTE_ADDR"];
-
-  if(isset($_GET["key"])) {
-    $key = $_GET["key"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  if(isset($_GET["token"])) {
-    $token = $_GET["token"];
-  } else {
-    header("Location: /");
-    exit;
-  }
-
-  $release = $_GET["rel"];
-  $architecture = $_GET["arch"];
-  $operating_system = $_GET["opsys"];
-
-  $res = pg_query($conn, "SELECT id
-                            FROM system_ids
-                           WHERE unique_key = '$key'
-                             AND token = '$token'
-                             AND enable;");
-
-  if(pg_num_rows($res) == 1) {
-    pg_query($conn, "BEGIN");
-    $system_ids = pg_fetch_object($res, 0);
-    $res = pg_query($conn, "SELECT id
-                             FROM systems
-                            WHERE id = $system_ids->id
-                              AND date_trunc('month',report_month) = date_trunc('month',now()  + '12 hours'::interval);");
-
-    if(pg_num_rows($res) == 0) {
-      pg_query($conn, "INSERT INTO systems ( id, os_id, release, architecture, report_month ) 
-                            VALUES ( $system_ids->id, ( SELECT id 
-                                                          FROM operating_systems 
-                                                         WHERE operating_system = '$operating_system' ), '$release', '$architecture', now()  + '12 hours'::interval );");
-    } else {
-      $data = pg_fetch_object($res, 0);
-      pg_query($conn, "UPDATE systems 
-                          SET report_month = now(), release = '$release', 
-                              architecture = '$architecture', os_id = ( SELECT id 
-                                                                          FROM operating_systems
-                                                                         WHERE operating_system = '$operating_system' )
-                        WHERE id = $system_ids->id 
-                          AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
-    }
-    pg_query($conn, "COMMIT");
-    print "STATUS=OK\n";
-  } else {
-    print "STATUS=FAIL\n";
-  }
-?>
+<?php
+require_once 'head.php';
+if(pg_num_rows($res) == 1) {
+	pg_query($conn, "BEGIN");
+	$system_ids	= pg_fetch_object($res, 0);
+	$res		= pg_query($conn, "SELECT id ".
+								  "FROM systems ".
+								  "WHERE id = $system_ids->id ".
+									  "AND date_trunc('month',report_month) = date_trunc('month',now()  + '12 hours'::interval);");
+	
+	if(pg_num_rows($res) == 0) {
+		pg_query($conn, "INSERT INTO systems ( id, os_id, release, architecture, report_month ) ".
+						"VALUES ( $system_ids->id, ( SELECT id ".
+													"FROM operating_systems ".
+													"WHERE operating_system = '$operating_system' ), '$release', '$architecture', now()  + '12 hours'::interval );");
+	} else {
+		$data = pg_fetch_object($res, 0);
+		pg_query($conn, "UPDATE systems ".
+						"SET report_month = now(), release = '$release',  ".
+							"architecture = '$architecture', os_id = ( SELECT id  ".
+																	  "FROM operating_systems ".
+																	  "WHERE operating_system = '$operating_system' ) ".
+						"WHERE id = $system_ids->id  ".
+							"AND date_trunc('month',report_month) = date_trunc('month',now() + '12 hours'::interval);");
+	}
+	pg_query($conn, "COMMIT");
+	print "STATUS=OK\n";
+} else {
+	print "STATUS=FAIL\n";
+}
+?>



More information about the Commits mailing list