[Firebug-cvs] firebug/web/postgres architecture.php,NONE,1.1 connect.php,NONE,1.1 db_admin.php,NONE,
Brought to you by:
doolin
From: Kevin <kar...@us...> - 2004-08-19 16:27:48
|
Update of /cvsroot/firebug/firebug/web/postgres In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5385 Added Files: architecture.php connect.php db_admin.php db_create.php db_drop.php db_dropdb.php db_list.php db_list_databases.php db_select.php db_table_buttons.php db_table_select.php nav_footer.php Log Message: Added the Postgresql version of the Firebug database. --- NEW FILE: nav_footer.php --- <center> <a href="./index.html">[FireBug home]</a> <a href="./db_admin.php">[DB Admin]</a> <a href="./db_list.php">[DB List]</a> <a href="./db_drop.php">[DB Drop]</a> </center> --- NEW FILE: db_dropdb.php --- <html> <head> <title>FireBug database utility script</title> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <h1>FireBug database dropped</h1> <?php $dbname = $HTTP_POST_VARS["db1"]; print $dbname; ?> <hr /> <?php include("connect.php"); $dbh= connect_postgres("template1"); $statement = "DROP DATABASE $dbname"; $stat = @pg_exec($dbh,$statement); if (!$stat) { print "Error: Could not drop database $dbname"; } else { print "Database <strong>$dbname</strong> dropped."; } pg_close($dbh); ?> <br /> <hr /> <?php include("nav_footer.php"); ?> <hr /> </body> </html> --- NEW FILE: db_admin.php --- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>FireBug database utility script</title> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <h1>FireBug database administration</h1> FireBug logs to a sql database. Since the number of database operations necessary for logging are a limited subset of SQL, we wrap the database administration commands using <a href="http://www.php.net">PHP</a> with an <a href="http://www.apache.org">Apache</a> web server. <hr /> <form action="db_create.php" method="post"> NOTE: Database names are CASE-INSENSITIVE. <br /> Database name: <input type="text" name="dbname" /> <br /> Number of motes: <input type="text" name="nummotes"/> <br /> <input type="submit" value="Create database" /> </form> <hr /> <?php //$string = system("D:\cygwin\bin\gnuplot.exe < test.gnu"); `D:\cygwin\bin\gnuplot.exe < test.gnu`; include("nav_footer.php"); ?> <!-- --> <img src="../imagetest/test.png"> <!-- --> <hr /> <p> Last Updated: $Date: 2004/08/19 16:27:38 $ by $Author: karimushu $. </p> </body> </html> --- NEW FILE: db_create.php --- <html> <head> <title>FireBug database utility script</title> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <h1>FireBug database created</h1> <?php include("connect.php"); $dbname = strtolower($HTTP_POST_VARS["dbname"]); $nummotes = $HTTP_POST_VARS["nummotes"]; /** Need php v4.2 for this to work. */ /* Check to make sure we have numbers intead of garbage.*/ /* if (!ctype_digit($nummotes)) { print "Must be digits.<br />"; } */ $dbh = connect_postgres("template1"); $statement = "SELECT DATNAME FROM pg_database where not datname='template1' and not datname='template0'"; $conn_stat = @pg_exec($dbh,$statement); if (!$conn_stat) { print "Error: Could not check to see if database exists."; } else { $rows = pg_numrows($conn_stat); $flag=0; for ($i = 0; $i < $rows; $i++) { $data = pg_fetch_row($conn_stat, $i); if (strcmp(rtrim($data[0]),$dbname)==0) { $flag=1; } } if (!$flag) { $dbh = connect_postgres("template1"); $statement = "CREATE DATABASE $dbname"; $create_stat = @pg_exec($dbh,$statement); if (!$create_stat) { print "Error: Could not create database $dbname."; pg_close($dbh); } else { print "Database <strong>$dbname</strong> created."; print "<br />"; pg_close($dbh); $dbh = connect_postgres($dbname); /* 3 create table statements for firebug sensors. */ /* typedef struct GGAMsg { uint16_t mote_id uint8_t hours; uint8_t minutes; float dec_sec; uint8_t Lat_deg; float Lat_dec_min; uint8_t Long_deg; float Long_dec_min; uint8_t NSEWind; uint8_t num_sats; } GGAMsg; */ $sql = "CREATE TABLE location (mote_id SMALLINT, gps_hours SMALLINT, gps_minutes SMALLINT, gps_seconds REAL, lat_deg SMALLINT,"; $sql .= "lat_dec_min REAL, long_deg SMALLINT, long_dec_min REAL, nsew SMALLINT, numsats SMALLINT)"; $create_stat = @pg_exec($dbh, $sql); if (!$create_stat) { print "Error: Could not create table LOCATION."; } //$statement = "CREATE TABLE location (mote_id SMALLINT, gps_hours SMALLINT, gps_minutes SMALLINT, gps_seconds FLOAT, lat_deg SMALLINT,"; //$statement .= "lat_dec_min FLOAT, long_deg SMALLINT, long_dec_min FLOAT, nsew SMALLINT, numsats SMALLINT)"; //mysql_query($statement) or die("Error: ".mysql_error()." in creating location atable"); /* typedef struct Firedata_msg { uint16_t mote_id; uint16_t cnt; float temp; float rel_hum; float baro_pres; float lux; } Firedata_msg; */ $sql = "CREATE TABLE current (mote_id SMALLINT, time TIMESTAMP, cnt SMALLINT, temp REAL, rel_hum REAL, baro_pres REAL, lux REAL)"; $create_stat = @pg_exec($dbh, $sql); if (!$create_stat) { print "Error: Could not create table CURRENT."; $current_flag=1; } //$statement = "CREATE TABLE current (mote_id SMALLINT, time TIMESTAMP, cnt SMALLINT, temp FLOAT, rel_hum FLOAT, baro_pres FLOAT, lux FLOAT)"; //mysql_query($statement) or die("Error: ".mysql_error()." in creating current atable"); $sql = "CREATE TABLE cumulative (mote_id SMALLINT, time TIMESTAMP, cnt SMALLINT, temp REAL, rel_hum REAL, baro_pres REAL, lux REAL)"; $create_stat = @pg_exec($dbh, $sql); if (!$create_stat) { print "Error: Could not create table CUMULATIVE."; } //$statement = "CREATE TABLE cumulative (mote_id SMALLINT, time TIMESTAMP, cnt SMALLINT, temp FLOAT, rel_hum FLOAT, baro_pres FLOAT, lux FLOAT)"; //mysql_query($statement) or die("Error: ".mysql_error()." in creating cumulative atable"); $sql = "CREATE TABLE range (mote_id SMALLINT, time TIMESTAMP, count INTEGER, rssi INTEGER, voltage REAL)"; $create_stat = @pg_exec($dbh, $sql); if (!$create_stat) { print "Error: Could not create table RANGE."; } //$statement = "CREATE TABLE range (mote_id SMALLINT, time TIMESTAMP, count INTEGER, rssi INTEGER, voltage FLOAT)"; //mysql_query($statement) or die("Error: ".mysql_error()." in creating range table"); } ?> <?php if (!$current_flag) { for ($i = 1; $i <= $nummotes; $i++) { $statement = "INSERT INTO current (mote_id) VALUES ($i)"; print "<br />"; $create_stat = @pg_exec($dbh, $statement); if (!$create_stat) { print "Error: Could not INSERT INTO CURRENT (mote_id) VALUES ($i)"; } else { print $statement; } } } pg_close($dbh); } else { echo("Database $dbname already created."); print "<br />"; echo("Please create another database."); print "<br />"; print("<a href=\"db_admin.php\">Create Another Database</a>"); pg_close($dbh); } } ?> <br /> <hr /> <?php include("nav_footer.php"); ?> <hr /> </body> </html> --- NEW FILE: db_drop.php --- <html> <head> <title>Example FireBug Client</title> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <h1>FireBug web client database selection</h1> <center> <form action="db_dropdb.php" method="post"> <table class="db_schema"> <tr> <td>DataBase Name</td> <td>Selected</td> </tr> <?php include("connect.php"); function print_dbname_row($dbname) { print ("<tr><td>"); print $dbname; print ("</td>"); print ("<td>"); print ("<input type=radio name=db1 value=\"$dbname\">"); print ("</td>"); print ("</tr>"); } /** Print only the non-system databases */ $dbh = connect_postgres("template1"); $statement = "SELECT DATNAME FROM pg_database where not datname='template1' and not datname='template0'"; $stat = pg_exec($dbh,$statement); $rows = pg_numrows($stat); for ($i = 0; $i < $rows; $i++) { $data = pg_fetch_row($stat, $i); print_dbname_row($data[0]); } ?> </table> <input type="submit" value="Drop database"> </form> </center> <hr /> <?php include("nav_footer.php"); ?> <hr /> <p> Database data last updated: <?php echo date ("l dS F Y h:i:s A"); ?> </p> </body> </html> --- NEW FILE: db_select.php --- <html> <head> <title>FireBug database utility script</title> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <form action="db_table_select.php" method="post"> <?php include("connect.php"); $dbname = $HTTP_POST_VARS["db1"]; $dbh = connect_postgres($dbname); print("<h1>Database $dbname tables</h1>"); print("<center>\n"); print("<table class='db_schema'><tr><td>Table Name</td><td>Selected</td></tr>"); $statement = "SELECT TABLENAME FROM pg_tables WHERE NOT TABLENAME~'pg_.*' and not tablename~'sql_.*'"; $stat = pg_exec($dbh,$statement); $rows = pg_numrows($stat); for ($i = 0; $i < $rows; $i++) { $data = pg_fetch_row($stat, $i); print ("<tr>"); print ("<td>"); print $data[0]; print ("</td>"); print ("<td>"); print ("<input type=radio name=tbl1 value=\"" . htmlspecialchars($data[0]) . "\">"); print ("</td>"); print ("</tr>"); } print ("</table>"); print ("<input type=hidden name=db1 value=\"$dbname\">"); print ("<input type=submit value=SUBMIT>"); pg_close($dbh); ?> </form> </center> <br /> <!-- Add links to go back to the firebug home page running on the current server, and to the database admin page running on the current server. --> <hr /> <?php include("nav_footer.php"); ?> <hr /> </body> </html> --- NEW FILE: db_table_select.php --- <?php //session_start(); //session_register("dbname"); //session_register("tblname"); ?> <html> <head> <title>FireBug Client</title> <!-- <META HTTP-EQUIV="Refresh" CONTENT="30;URL=http://localhost/firebug/db_table_select.php"> --> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <hr /> <p> Sensor data last updated: <?php echo date ("l dS F Y h:i:s A"); ?> </p> <?php //if (!isset($HTTP_SESSION_VARS["tblname"])) { if ($HTTP_POST_VARS["tbl1"]!=Null){ $HTTP_SESSION_VARS["tblname"] = $HTTP_POST_VARS["tbl1"]; $HTTP_SESSION_VARS["dbname"] = $HTTP_POST_VARS["db1"]; } $dbname = $HTTP_SESSION_VARS["dbname"]; $tblname = $HTTP_SESSION_VARS["tblname"]; print("<h1>Mote activity: Database $dbname, table $tblname</h1>"); ?> <?php include("db_table_buttons.php"); ?> <center> <table class="db_schema"> <?php $dbh = connect_postgres($dbname); $statement = "SELECT a.attname FROM pg_attribute a,pg_class c where c.relname = 'current' and a.attrelid = c.oid and a.attnum > 0"; $stat = pg_exec($dbh,$statement); // Build the table header column names. Make this into a function. print("<tr>\n"); $cols = pg_numrows($stat); for ($i=0 ; $i < $cols; $i++) { print ("<td>"); $header = pg_fetch_row($stat,$i); print $header[0]; print ("</td>"); } print("</tr>\n"); $statement = "SELECT * FROM $tblname"; $stat = pg_exec($dbh,$statement); //Print the value for a row. function print_row($item2,$key) { print ("<td>\n"); echo "$item2\n"; print ("</td>\n"); } //Print every row. $rows = pg_numrows($stat); // for each row for ($i=0;$i<$rows;$i++) { print ("<tr>"); // For each column... $row = array_values(pg_fetch_row($stat,$i)); array_walk($row,'print_row'); print("</tr>"); } ?> </table> </center> <hr /> <hr /> <?php include("nav_footer.php"); ?> <hr /> <p> Sensor data last updated: <?php echo date ("l dS F Y h:i:s A"); ?> </p> </body> </html> --- NEW FILE: db_list.php --- <html> <head> <title>Example FireBug Client</title> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <link type="text/css" rel="stylesheet" href="firebug.css"> </head> <body> <h1>FireBug web client database selection</h1> <hr /> <center> <form action="db_select.php" method="post"> <?php include("db_list_databases.php"); ?> <input type="submit" value="Show tables"> </form> </center> <hr /> <?php include("nav_footer.php"); ?> <p> Database data last updated: <?php echo date ("l dS F Y h:i:s A"); ?> </p> </body> </html> --- NEW FILE: db_table_buttons.php --- <form action="db_table_select.php" method="post"> <?php include ("connect.php"); print("Choose different table: "); print("<table class='db_schema'>"); $dbh = connect_postgres($dbname); $statement = "SELECT TABLENAME FROM pg_tables WHERE NOT TABLENAME~'pg_.*' and not tablename~'sql_.*'"; $stat = pg_exec($dbh,$statement); $rows = pg_numrows($stat); for ($i = 0; $i < $rows; $i++) { $data = pg_fetch_row($stat, $i); print ("<input type=hidden name=db1 value=\"$dbname\">"); print ("<input type=submit name=tbl1 value=\"" . $data[0] . "\">"); } ?> </form> --- NEW FILE: db_list_databases.php --- <table class="db_schema"> <tr> <td>Database</td> <td>Selected</td> </tr> <?php include("connect.php"); $dbh = connect_postgres("template1"); $statement = "SELECT DATNAME FROM pg_database where not datname='template1' and not datname='template0'"; $stat = pg_exec($dbh,$statement); $rows = pg_numrows($stat); for ($i = 0; $i < $rows; $i++) { $data = pg_fetch_row($stat, $i); print ("<tr><td>"); print $data[0]; print ("</td>"); print ("<td>"); print ("<input type=radio name=db1 value=\"$data[0]\">"); print ("</td>"); print ("</tr>"); } ?> </table> --- NEW FILE: connect.php --- <?php /** Function connect_postgres takes in a database name, and returns the * database handle. */ function connect_postgres($db) { $connstr = "dbname=$db user=postgres host=localhost port=5432"; if(!($dbh = @pg_connect($connstr))) { die("Error: could not connect"); } return $dbh; } ?> --- NEW FILE: architecture.php --- <html> <head> <link type="text/css" rel="stylesheet" href="firebug.css"> <link rel="SHORTCUT ICON" href="./images/favicon.ico"> <title> FireBug </title> </head> <body> <?php include("header.php"); ?> <h1>System Architecture</h1> <p> The FireBug system is composed of a network of GPS-enabled, wireless thermal sensors, a control layer for processing sensor data, and a command center for interactively communicating with the sensor network. Each of these layers are independent of the others, communicating through well-defined interfaces. </p> <br> <center> <img src="images/sysarch.jpg"> </center> <br> <h2>Data Flow/Tool Chains</h2> <p> A large amount of sample data are greatly needed in a timely manner. Firebug tool chains handle the data flow with standard technology, make the data with accurate data value, reliable data transfer and world wide access of data. </p> <center> <img src="images/tool_chain.jpg"> </center> <br> <?php include("links.php"); ?> </body> </html> |