-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlatrine.php
executable file
·159 lines (126 loc) · 4.71 KB
/
latrine.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
###### Adjust the following storage location #########
# Storage location for files with a trailing slash to indicate a directory
# Currently it is set to latrine's dir
$store = './';
// $store = '/tmp/latrine/';
###### Adjust housekeeping time (if not using /tmp)
# Set to 24h. Change to fit your needs (time is in sec)
@$housekeeping = 24*60*60;
###### Change the following only if you know what you're doing #########
@$view = $_GET['view'];
@$geo = $_GET['geo'];
@$key = $_GET['key'];
@$delete = $_GET['delete'];
####### Locus Pro Parameters
# Latitude - current GPS latitude (in degree unit, rounded on 5 decimal places)
@$lat = $_GET['lat'];
# Longitude - current GPS longitude (in degree unit, rounded on 5 decimal places)
@$lon = $_GET['lon'];
# Altitude - current altitude value in meter (improved altitude value by filter and barometer)
@$alt = $_GET['alt'];
# Speed - current GPS speed (in m/s)
@$speed = $_GET['speed'];
# Accuracy - current GPS accuracy (in metres)
@$acc = $_GET['acc'];
# Battery - current akku (in percent)
@$battery = $_GET['battery'];
# GSM signal - current signal strength (in percent)
@$gsm_signal = $_GET['gsm_signal'];
# Bearing - current GPS bearing (in degree)
@$bearing = $_GET['bearing'];
# Messag - variable Message you're able to provide with a selfdefined var in locus
@$message = $_GET['message'];
# Time - current GPS time (in format defined by user. You may choose from predefined styles or define you own by this specification)
#my $time = param('time') || '';
# Text field - text field with own define key/value pair.
#y $var = param('var') || '';
# Check storage location
if (!is_dir($store)) {
if (!mkdir($store)) {
die("Store nicht verfügbar");
}
}
# Current Unix timestamp
$time = time();
$now = $time;
# JSON output
#echo header('application/json');
header('Content-Type: application/json;charset=utf-8');
echo '{';
# Check private key
if ($key!="") {
$geojson = $store.$key.".geojson";
$store .= "$key.latlon"; # Create storage location
# Housekeeping
if (filemtime($store)< (time()-$housekeeping)) {
unlink($geojson);
unlink($store);
}
##### Write to file
# Write latitude, longitude and other data into .latlon file when received from Locus
if ( $lat!="" && $lon!="" ) {
if ($handle = fopen($store, "w")) {
fwrite($handle,'"lat":"'.$lat.'","lon":"'.$lon.'","alt":"'.$alt.'","speed":"'.$speed.'","bearing":"'.$bearing.'","acc":"'.$acc.'","time":"'.$time.'","battery":"'.$battery.'","gsm_signal":"'.$gsm_signal.'","message":"'.$message.'"');
fclose($handle);
} else {
echo "Dateizugriffsfehler .latlon";
}
# Write latitude & longitude into .geojson file, collecting positions for track
if ($handle = fopen($geojson, "a+")) {
fwrite($handle,"[ ".$lon.", ".$lat." ], ");
fclose($handle);
} else {
echo "Dateizugriffsfehler .geojson";
}
##### Read from file
# Output latitude, longitude and other data as JSON
} else if ($view == '1' ) {
if ($handle = fopen($store, "r")) {
$contents=fread($handle,filesize($store));
$contents=$contents.',"now":"'.$now.'"';
echo $contents;
fclose($handle);
} else {
echo 'Dateilesefahler view=1';
}
# Output latitude, longitude as JSON for drawing track
} else if ($geo == '1') {
if ($handle = fopen($geojson, "r")) {
$contents=fread($handle,filesize($geojson));
//Get rid of last ","
$contents=substr($contents,0,strrpos($contents,","));
$contents=' "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {
"type": "MultiLineString",
"coordinates": [[
'.$contents.'
]]
}
}
]
';
echo $contents;
fclose($handle);
} else {
echo 'Dateilesefehler geo=1';
}
# Delete .latlon & .geojson by purpose
} else if ($delete == '1') {
unlink($geojson);
unlink($store);
# Parameters are missing
} else {
echo '"error":"bad parameters"';
}
# Private key is missing
} else {
echo 'Schlüssel falsch oder fehlt';
}
# Done!
echo '}';
?>