diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bba3cf7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +mysql-data/ diff --git a/nginx/Dockerfile b/nginx/Dockerfile new file mode 100755 index 0000000..de139f4 --- /dev/null +++ b/nginx/Dockerfile @@ -0,0 +1,2 @@ +FROM nginx +COPY ./default.conf /etc/nginx/conf.d/default.conf diff --git a/nginx/default.conf b/nginx/default.conf new file mode 100755 index 0000000..b8c9bbb --- /dev/null +++ b/nginx/default.conf @@ -0,0 +1,38 @@ +server { + + listen 80 default_server; + root /var/www/html; + index index.html index.php; + + charset utf-8; + + location / { + try_files $uri $uri/ /track.php?$query_string; + } + + location = /favicon.ico { access_log off; log_not_found off; } + location = /robots.txt { access_log off; log_not_found off; } + + access_log off; + error_log /var/log/nginx/error.log error; + + sendfile off; + + client_max_body_size 100m; + + location ~ .php$ { + fastcgi_split_path_info ^(.+.php)(/.+)$; + fastcgi_pass php:9000; + fastcgi_index index.php; + include fastcgi_params; + fastcgi_read_timeout 300; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_intercept_errors off; + fastcgi_buffer_size 16k; + fastcgi_buffers 4 16k; + } + + location ~ /.ht { + deny all; + } + } diff --git a/php_code/Dockerfile b/php_code/Dockerfile new file mode 100755 index 0000000..8cb909e --- /dev/null +++ b/php_code/Dockerfile @@ -0,0 +1,3 @@ +FROM php:7.0-fpm +RUN docker-php-ext-install mysqli pdo pdo_mysql +RUN docker-php-ext-enable mysqli diff --git a/php_code/loc.php b/php_code/loc.php new file mode 100755 index 0000000..a7bbec7 --- /dev/null +++ b/php_code/loc.php @@ -0,0 +1,35 @@ +prepare($sql); + # bind parameters (s = string, i = integer, d = double, b = blob) + $stmt->bind_param('ssdd', $dt, $tid, $lat, $lon); + $stmt->execute(); + $stmt->close(); + } + + $response = array(); + # optionally add objects to return to the app (e.g. + # friends or cards) + print json_encode($response); +?> diff --git a/php_code/track.php b/php_code/track.php new file mode 100644 index 0000000..ccb5d40 --- /dev/null +++ b/php_code/track.php @@ -0,0 +1,35 @@ +_type !== 'location') { + return; +} + +$db = new mysqli('172.28.0.25:3306', 'root', 'owntracks', 'owntracks'); +if ($db->connect_error) { + die('Connection failed: ' . $db->connect_error); +} + +$stmt = $db->prepare('INSERT INTO recordings (user, device, acc, alt, batt, bs, conn, created_at, lat, lon, t, tid, tst, vac, vel) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);'); +if ($stmt === false) { + die('failed to prepare query: ' . $db->error); +} + +if ($stmt->bind_param('ssiiiisiddssiii', $user, $device, $json->acc, $json->alt, $json->batt, $json->bs, $json->conn, $json->created_at, $json->lat, $json->lon, $json->t, $json->tid, $json->tst, $json->vac, $json->vel) === false) { + die('failed to bind params: ' . $stmt->error); +} + +$user = $_SERVER['HTTP_X_LIMIT_U']; +$device = $_SERVER['HTTP_X_LIMIT_D']; + +if ($stmt->execute() === false) { + die('failed to insert: ' . $stmt->error); +} + +$stmt->close(); +$db->close(); + +print json_encode(array());