[Phonehome-commits] r67 - in trunk/server: . common dbschema
lauren at garage.maemo.org
lauren at garage.maemo.org
Sun Oct 19 04:45:31 EEST 2008
Author: lauren
Date: 2008-10-19 04:45:30 +0300 (Sun, 19 Oct 2008)
New Revision: 67
Added:
trunk/server/.htaccess
trunk/server/device_del.php
trunk/server/device_edit.php
Modified:
trunk/server/common/useful_stuff.php
trunk/server/dbschema/db_etmaemo.sql
trunk/server/device_add.php
trunk/server/ets.php
trunk/server/gpsdata.php
trunk/server/index.php
trunk/server/profile.php
Log:
1. fixed some bugs
2. updated the server code (without merge yet)
3. very basic gps data page (should work with data)
Added: trunk/server/.htaccess
===================================================================
--- trunk/server/.htaccess (rev 0)
+++ trunk/server/.htaccess 2008-10-19 01:45:30 UTC (rev 67)
@@ -0,0 +1,10 @@
+
+# uncomment the lines below and replace "LIVE_DOMAIN_NAME"
+# with the live domain name to prevent any access to the images
+# unless the request comes from our domain name, ie, from
+# our scripts
+#
+#RewriteEngine on
+#RewriteCond %{HTTP_REFERER} !^$
+#RewriteCond %{HTTP_REFERER} !^http://(www\.)?LIVE_DOMAIN_NAME/.*$ [NC]
+#RewriteRule \.(gif|jpg|js|css)$ - [F]
Modified: trunk/server/common/useful_stuff.php
===================================================================
--- trunk/server/common/useful_stuff.php 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/common/useful_stuff.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -8,7 +8,7 @@
////////////////////////////////////////////////
// xml-rpc param offsets
-define("XMLRPC_USERNAME",0);
+define("XMLRPC_MAC",0);
define("XMLRPC_PW",1);
define("XMLRPC_LAT",2);
Modified: trunk/server/dbschema/db_etmaemo.sql
===================================================================
--- trunk/server/dbschema/db_etmaemo.sql 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/dbschema/db_etmaemo.sql 2008-10-19 01:45:30 UTC (rev 67)
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: localhost
--- Generation Time: Oct 17, 2008 at 05:14 PM
+-- Generation Time: Oct 18, 2008 at 06:38 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.4-2ubuntu5.3
@@ -25,16 +25,15 @@
-- Table structure for table `devices`
--
-DROP TABLE IF EXISTS `devices`;
CREATE TABLE IF NOT EXISTS `devices` (
`device_id` int(11) NOT NULL auto_increment,
`user_id` int(11) NOT NULL,
`status` char(1) NOT NULL default 'A',
- `mac` varchar(30) default NULL,
+ `mac` varchar(30) NOT NULL,
`name` varchar(250) NOT NULL,
- `description` text NOT NULL,
+ `description` text,
PRIMARY KEY (`device_id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
-- --------------------------------------------------------
@@ -42,11 +41,10 @@
-- Table structure for table `gps_info`
--
-DROP TABLE IF EXISTS `gps_info`;
CREATE TABLE IF NOT EXISTS `gps_info` (
`gi_id` int(11) NOT NULL auto_increment,
`device_id` int(11) NOT NULL,
- `longtitude` varchar(100) NOT NULL,
+ `longitude` varchar(100) NOT NULL,
`latitude` varchar(100) NOT NULL,
`gps_time` datetime NOT NULL,
PRIMARY KEY (`gi_id`)
@@ -58,7 +56,6 @@
-- Table structure for table `images`
--
-DROP TABLE IF EXISTS `images`;
CREATE TABLE IF NOT EXISTS `images` (
`image_id` int(11) NOT NULL auto_increment,
`device_id` int(11) NOT NULL,
@@ -73,7 +70,6 @@
-- Table structure for table `users`
--
-DROP TABLE IF EXISTS `users`;
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(11) NOT NULL auto_increment,
`status` char(1) NOT NULL default 'A',
@@ -83,4 +79,4 @@
`joined` datetime NOT NULL,
`lastlogin` datetime NOT NULL,
PRIMARY KEY (`user_id`)
-) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
+) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
Modified: trunk/server/device_add.php
===================================================================
--- trunk/server/device_add.php 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/device_add.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -8,71 +8,7 @@
die();
}
-$errmsg = "";
-$dname = getvar("dname");
-$dstatus = getvar("dstatus");
-$dmac = getvar("dmac");
-$ddesc = getvar("ddesc");
-$doit = getvar("doit");
-if ($doit == "yes"){
- if ($dname == ""){
- $errmsg = "Please supply a device name!";
- }
- else if ($dmac == ""){
- $errmsg = "Please enter a mac address!";
- }
- else {
- mysql_query("insert into devices (user_id,status,mac,name,description)
- values ({$_uid},'{$dstatus}','{$dmac}','{$dname}','{$ddesc}')");
- header("location:profile.php");
- die();
- }
-}
-
+mysql_query("insert into devices (user_id,status,name,mac) values ({$_uid},'N','--- new device ---','---')");
+$id = mysql_insert_id();
+header("location:device_edit.php?did={$id}");
?>
-<html>
-<head>
-<title>ET-MAEMO | Add Device</title>
-<link rel="stylesheet" type="text/css" href="css/main.css">
-</head>
-<body>
-<?php
-include 'common/header.php';
-
-echo "<table width='100%' cellpadding='1' cellspacing='1' border='0'>
-<tr>
- <td style='vertical-align:top;width:40%;'>
- <b>Add Device</b>
- <div style='color:red;'><b>{$errmsg} </b></div>
- <form method='post' action='{$_SERVER['PHP_SELF']}'>
- <input type='hidden' name='doit' value='yes'>
- device name<br><input type='text' name='dname' size='30' value='".stripslashes(htmlentities($dname,ENT_QUOTES))."'>
- <br>device mac address<br><input type='text' name='dmac' size='30' value='".stripslashes(htmlentities($dmac,ENT_QUOTES))."'>
- <br>device status<br><select name='dstatus'>";
- if ($dstatus == "A"){
- echo "<option value='A' selected>ACTIVE</option><option value='N'>NOT ACTIVE</option>";
- }
- else {
- echo "<option value='A'>ACTIVE</option><option value='N' selected>NOT ACTIVE</option>";
- }
- echo "</select>
- <br>device description<br><textarea name='ddesc' cols='30' rows='3'>".stripslashes(htmlentities($ddesc,ENT_QUOTES))."</textarea>
- <br><input type='submit' value='Add This Device'>
- </form>
- </td>
- <td style='vertical-align:top;padding-left:30px;'>
- <b>Notes</b>
- <p>The name you give should be unique so you can easily identify your devices. The description
- is completely optional.
- <p>The status will determine whether or not data will be collected for
- this device.
- <p>The MAC Address *must* be unique (mac addresses are supposed to be) and should contain the
- \":\" characters, ie, 00:34:DE:43:21:AF
- </td>
-</tr>
-</table>";
-
-include 'common/footer.php';
-?>
-</body>
-</html>
Added: trunk/server/device_del.php
===================================================================
--- trunk/server/device_del.php (rev 0)
+++ trunk/server/device_del.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -0,0 +1,21 @@
+<?php
+include 'common/useful_stuff.php';
+if (!db_connect())
+ die();
+
+if ($_uid == 0){
+ header("location:login.php");
+ die();
+}
+$did = getvar("did","n");
+if ($did == 0){
+ header("location:profile.php");
+ die();
+}
+
+mysql_query("delete from gps_info where device_id={$did} and user_id={$_uid}");
+mysql_query("delete from devices where device_id={$did} and user_id={$_uid}");
+mysql_query("delete from images where image_id in (select image_id from images where device_id={$did} and user_id={$_uid})");
+
+header("location:profile.php");
+?>
Added: trunk/server/device_edit.php
===================================================================
--- trunk/server/device_edit.php (rev 0)
+++ trunk/server/device_edit.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -0,0 +1,96 @@
+<?php
+include 'common/useful_stuff.php';
+if (!db_connect())
+ die();
+
+if ($_uid == 0){
+ header("location:login.php");
+ die();
+}
+$did = getvar("did","n");
+if ($did == 0){
+ header("location:profile.php");
+ die();
+}
+
+$errmsg = "";
+$dname = getvar("dname");
+$dstatus = getvar("dstatus");
+$dmac = getvar("dmac");
+$ddesc = getvar("ddesc");
+$doit = getvar("doit");
+if ($doit == "yes"){
+ if ($dname == ""){
+ $errmsg = "Please supply a device name!";
+ }
+ else if ($dmac == ""){
+ $errmsg = "Please enter a mac address!";
+ }
+ else {
+ mysql_query("update devices set status='{$dstatus}',mac='{$dmac}',name='{$dname}',description='{$ddesc}'
+ where device_id={$did} and user_id={$_uid}");
+ header("location:profile.php");
+ die();
+ }
+}
+// else we get the existing data from the db first time thru
+else {
+ $res = mysql_query("select status,mac,name,description from devices where device_id={$did} and user_id={$_uid}");
+ $row = mysql_fetch_assoc($res);
+ if (!$row){
+ header("location:profile.php");
+ die();
+ }
+ $dstatus = $row['status'];
+ $dname = $row['name'];
+ $dmac = $row['mac'];
+ $ddesc = $row['description'];
+}
+?>
+<html>
+<head>
+<title>ET-MAEMO | Add Device</title>
+<link rel="stylesheet" type="text/css" href="css/main.css">
+</head>
+<body>
+<?php
+include 'common/header.php';
+
+echo "<table width='100%' cellpadding='1' cellspacing='1' border='0'>
+<tr>
+ <td style='vertical-align:top;width:40%;'>
+ <b>Add Device</b>
+ <div style='color:red;'><b>{$errmsg} </b></div>
+ <form method='post' action='{$_SERVER['PHP_SELF']}'>
+ <input type='hidden' name='did' value='{$did}'>
+ <input type='hidden' name='doit' value='yes'>
+ device name<br><input type='text' name='dname' size='30' value='".stripslashes(htmlentities($dname,ENT_QUOTES))."'>
+ <br>device mac address<br><input type='text' name='dmac' size='30' value='".stripslashes(htmlentities($dmac,ENT_QUOTES))."'>
+ <br>device status<br><select name='dstatus'>";
+ if ($dstatus == "A"){
+ echo "<option value='A' selected>ACTIVE</option><option value='N'>NOT ACTIVE</option>";
+ }
+ else {
+ echo "<option value='A'>ACTIVE</option><option value='N' selected>NOT ACTIVE</option>";
+ }
+ echo "</select>
+ <br>device description<br><textarea name='ddesc' cols='30' rows='3'>".stripslashes(htmlentities($ddesc,ENT_QUOTES))."</textarea>
+ <br><input type='submit' value='Save Changes'> <input type='button' value='Back To Profile' onclick='location.href=\"profile.php\"'>
+ </form>
+ </td>
+ <td style='vertical-align:top;padding-left:30px;'>
+ <b>Notes</b>
+ <p>The name you give should be unique so you can easily identify your devices. The description
+ is completely optional.
+ <p>The status will determine whether or not data will be collected for
+ this device.
+ <p>The MAC Address *must* be unique (mac addresses are supposed to be) and should contain the
+ \":\" characters, ie, 00:34:DE:43:21:AF
+ </td>
+</tr>
+</table>";
+
+include 'common/footer.php';
+?>
+</body>
+</html>
Modified: trunk/server/ets.php
===================================================================
--- trunk/server/ets.php 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/ets.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -9,17 +9,21 @@
///////////////////////////////////////////////////////////////////////
-// check if a given user exists based on mac & password
-function get_uid($mac,$pw)
+// get user_id & device_id from mac & password
+// or return false
+function get_info($mac,$pw)
{
- $safe_uname = mysql_real_escape_string($uname);
+ $safe_mac = mysql_real_escape_string($mac);
$safe_pw = mysql_real_escape_string($pw);
- $res = mysql_query("select user_id from users where uname='{$safe_uname}' and pw='{$safe_pw}'");
+ $res = mysql_query("select devices.device_id,devices.user_id
+ from devices inner join users on users.user_id=devices.user_id
+ where devices.mac='{$safe_mac}' and users.pw='{$safe_pw}'");
$row = mysql_fetch_assoc($res);
if (!$row)
- return 0;
- // else we return the user_id
- return $row['user_id'];
+ return false;
+
+ // else we return the device_id & user_id
+ return array($row['device_id'],$row['user_id']);
}
@@ -27,20 +31,18 @@
// store gps data
function rpc_store_location($method_name,$params,$app_data)
{
- // get user_id or zero
- $uid = get_uid($params[XMLRPC_USERNAME],$params[XMLRPC_PW]);
- if ($uid == 0)
+ // get info
+ $info = get_info($params[XMLRPC_MAC],$params[XMLRPC_PW]);
+ if (!$info)
return false;
// convert date string
$date_recvd = date("Y-m-d H:i:s",$params[4]);
// write to the db
- mysql_query("insert into gps_infos (user_id,lat,lon,gps_time) values ('{$uid}','{$params[XMLRPC_LAT]}','{$params[XMLRPC_LON]}','{$date_recvd}')";
-
- $out=mysql_query($query) or die('Error, insert query failed');
- //print "yo ".$query,
- return True;
+ mysql_query("insert into gps_infos (device_id,latitude,longitude,gps_time)
+ values ('{$info[0]}','{$params[XMLRPC_LAT]}','{$params[XMLRPC_LON]}','{$date_recvd}')");
+ return true;
}
@@ -48,16 +50,16 @@
// store image in user specific directory (created dynamically)
function rpc_store_picture($method_name,$params,$app_data)
{
- $uid = get_uid($params[XMLRPC_USERNAME],$params[XMLRPC_PW]);
- if ($uid == 0)
+ $info = get_info($params[XMLRPC_MAC],$params[XMLRPC_PW]);
+ if (!$info)
return false;
- if (!file_exists("img/user{$uid}")
- mkdir("img/user{$uid}");
+ if (!file_exists("img/user{$info[1]}"))
+ mkdir("img/user{$info[1]}");
$ts = time();
- $filename = "{$uid}_{$ts}.jpg";
- if (!file_put_contents("img/user{$uid}/{$filename}",base64_decode($params[XMLRPC_IMG])))
+ $filename = "{$info[0]}_{$ts}.jpg";
+ if (!file_put_contents("img/user{$info[1]}/{$filename}",base64_decode($params[XMLRPC_IMG])))
return false;
return true;
@@ -74,7 +76,7 @@
xmlrpc_server_register_method($xmlrpc_server,"store_picture","rpc_store_picture");
// get the data from the request & process it
-$request_xml = file_get_contents(("php://input");
+$request_xml = file_get_contents("php://input");
echo xmlrpc_server_call_method($xmlrpc_server,$request_xml,'');
// bye bye
Modified: trunk/server/gpsdata.php
===================================================================
--- trunk/server/gpsdata.php 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/gpsdata.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -8,6 +8,8 @@
die();
}
+$did = getvar("did","n");
+
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
@@ -19,8 +21,48 @@
<?php
include 'common/header.php';
-echo "<h1>GPS Data here</h1>";
+// device droplist
+echo "<div><b>Your Devices</b>
+<form method='post' action='{$_SERVER['PHP_SELF']}'>
+<select name='device' onchange='document.forms[0].submit()'><option value='0'>Select the device to see data for...</option>";
+$res = mysql_query("select device_id,name,mac from devices where user_id={$_uid} order by name");
+while ($row = mysql_fetch_assoc($res)){
+ // save first device for initial list
+ if ($did == 0){
+ $did = $row['device_id'];
+ }
+ // add to droplist
+ if ($did == $row['device_id']){
+ echo "<option value='{$row['device_id']}' selected>{$row['name']} - ({$row['mac']})</option>";
+ }
+ else {
+ echo "<option value='{$row['device_id']}'>{$row['name']} - ({$row['mac']})</option>";
+ }
+}
+echo "</select>
+</form>
+</div>";
+// do they have a device registered?
+if ($did == 0){
+ echo "<h3 style='color:red;'>
+ Please enter at least one device<br>
+ on your <a href='profile.php'>PROFILE</a> page to use ET-MAEMO
+ </h3>";
+}
+// else we can draw data for selected device or initial device
+else {
+ $res = mysql_query("select longitude,latitude,gps_time
+ from gps_info
+ where device_id={$did} order by gps_time desc");
+ while ($row = mysql_fetch_assoc($res)){
+
+ echo "<div style='padding:3px;'>
+ GPS Time: {$row['gps_time']} | Long: {$row['longitude']} | Lat: {$row['latitude']}
+ </div>";
+ }
+}
+
include 'common/footer.php';
?>
</body>
Modified: trunk/server/index.php
===================================================================
--- trunk/server/index.php 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/index.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -14,7 +14,9 @@
<?php
include 'common/header.php';
-echo "<h1>welcome to et-maemo (phonehome)</h1>";
+echo "<h1>welcome to et-maemo (phonehome)</h1>
+<h3>here we can put xome more blurb about the site and the app, and
+we can show some stats maybe about users etc</h3>";
include 'common/footer.php';
?>
Modified: trunk/server/profile.php
===================================================================
--- trunk/server/profile.php 2008-10-18 21:32:21 UTC (rev 66)
+++ trunk/server/profile.php 2008-10-19 01:45:30 UTC (rev 67)
@@ -40,6 +40,15 @@
<head>
<title>ET-MAEMO | My Profile</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
+<script type='text/javascript'>
+function chk_del()
+{
+ if (confirm("DELETE DEVICE AND ALL DATA!!!\nAre you sure?") == false)
+ return false;
+ if (confirm("Are you VERY VERY sure?") == false)
+ return false;
+}
+</script>
</head>
<body>
<?php
@@ -70,14 +79,14 @@
</td>
<td style='vertical-align:top;padding-left:20px;'>
- <b>Your Devices</b>
+ <b>Your Devices</b> (very basic for now)
<p><a href='device_add.php'>Add a new device »»</a><p>";
$res = mysql_query("select device_id,status,name,mac from devices where user_id={$_uid} order by name");
$got_device = false;
while ($row = mysql_fetch_assoc($res)){
echo "<div style='padding:2px;margin:1px solid #999;'>
<a href='device_edit.php?did={$row['device_id']}'>[ edit ]</a>
- <a href='device_del.php?did={$row['device_id']}'>[ del ]</a>
+ <a href='device_del.php?did={$row['device_id']}' onclick='return chk_del()'>[ del ]</a>
<span style='margin-left:10px;'>{$row['status']}</span>
<span style='margin-left:10px;'>{$row['mac']}</span>
<span style='margin-left:10px;'>{$row['name']}</span>
More information about the Phonehome-commits
mailing list