-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New Metric: Altitude #168
base: master
Are you sure you want to change the base?
New Metric: Altitude #168
Changes from 1 commit
f550c13
6c788e3
13b6664
6b556c1
8fd96ba
24750a3
9cbd1cc
b5dad6e
082da40
27a1959
4ae423a
33e19cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,48 +21,37 @@ | |
$session = new Client($memcache, $sid); | ||
if (!$session->exists()) die($LANG['session_expired']."\n"); | ||
|
||
// FIXME: Get rid of duplicate code | ||
if (!$session->isEncrypted()) { | ||
// Perform input validation. | ||
$lat = floatval($_POST["lat"]); | ||
$lon = floatval($_POST["lon"]); | ||
$time = floatval($_POST["time"]); | ||
if ($lat < -90 || $lat > 90 || $lon < -180 || $lon > 180) die($LANG['location_invalid']."\n"); | ||
|
||
// Not all devices report speed and accuracy, but if available, report them | ||
// too. | ||
$speed = isset($_POST["spd"]) ? floatval($_POST["spd"]) : null; | ||
$altitude = isset($_POST["alt"]) ? doubleval($_POST["alt"]) : null; | ||
$accuracy = isset($_POST["acc"]) ? floatval($_POST["acc"]) : null; | ||
$provider = isset($_POST["prv"]) && $_POST["prv"] == "1" ? 1 : 0; | ||
|
||
// The location data object contains the sharing interval (i), duration (d) | ||
// and a location list (l). Each entry in the location list contains a | ||
// latitude, longitude, timestamp, provider, accuracy and speed, in that | ||
// order, as an array. | ||
$session->addPoint([$lat, $lon, $time, $provider, $accuracy, $speed, $altitude])->save(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would make sense to store the values as a map, then it would be easier to retrieve them in the frontend (and also less error prone) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would definitely be an idea - storing the values as a map and saving it to storage as JSON would probably be a better approach than what I'm currently doing. |
||
|
||
} else { | ||
// Input validation cannot be performed for end-to-end encrypted data. | ||
$lat = $_POST["lat"]; | ||
$lon = $_POST["lon"]; | ||
$time = $_POST["time"]; | ||
$speed = isset($_POST["spd"]) ? $_POST["spd"] : null; | ||
$accuracy = isset($_POST["acc"]) ? $_POST["acc"] : null; | ||
$provider = isset($_POST["prv"]) ? $_POST["prv"] : null; | ||
$altitude = isset($_POST["alt"]) ? $_POST["alt"] : null; | ||
|
||
$lat = $_POST["lat"]; | ||
$lon = $_POST["lon"]; | ||
$time = $_POST["time"]; | ||
$speed = isset($_POST["spd"]) ? $_POST["spd"] : null; | ||
$altitude = isset($_POST["alt"]) ? $_POST["alt"] : null; | ||
$accuracy = isset($_POST["acc"]) ? $_POST["acc"] : null; | ||
$provider = isset($_POST["prv"]) ? $_POST["prv"] : null; | ||
|
||
// The location data object contains the sharing interval (i), duration (d) | ||
// and a location list (l). Each entry in the location list contains a | ||
// latitude, longitude, timestamp, provider, accuracy and speed, in that | ||
// order, as an array. | ||
$point = [$lat, $lon, $time, $provider, $accuracy, $speed, $altitude]; | ||
|
||
if ($session->isEncrypted()) { | ||
// End-to-end encrypted connections also have an IV field used to decrypt | ||
// the data fields. | ||
requirePOST("iv"); | ||
$iv = $_POST["iv"]; | ||
|
||
// The IV field is prepended to the array to send to the client. | ||
$session->addPoint([$iv, $lat, $lon, $time, $provider, $accuracy, $speed, $altitude])->save(); | ||
array_unshift($point , $iv); | ||
} else { | ||
// Perform input validation | ||
if (floatval($lat) < -90 || floatval($lat) > 90 || floatval($lon) < -180 || floatval($lon) > 180) die($LANG['location_invalid']."\n"); | ||
bilde2910 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
$session->addPoint($point)->save(); | ||
|
||
if ($session->hasExpired()) { | ||
echo $LANG['session_expired']."\n"; | ||
} else { | ||
echo "OK\n".getConfig("public_url")."?%s\n".implode(",", $session->getTargetIDs())."\n"; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured out (correct me if I'm wrong) that converting String to float is not really necessary here, as it will end up in a JSON object anyway, therefore I got away with just one way of retrieving the metrics.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The conversion from String to float was that it ensures the value is always a number. In that case it is also saved to JSON as a float, and parsed directly by JavaScript into a float value, rather than a string. E.g.
{"lat":50.2,"lon":20.1}
(float) vs{"lat":"50.2","lon":"20.1"}
(String).