Skip to content

Commit 2f39343

Browse files
authored
Merge pull request #9 from mikelduke/docker
Docker and docker-compose
2 parents 97832c8 + 83f482c commit 2f39343

10 files changed

+105
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.vagrant
22
*.log
3+
dev-key.sh

Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
FROM php:7.3-apache
2+
3+
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
4+
5+
ENV APACHE_RUN_USER=daemon
6+
COPY src/ /var/www/html/

README.md

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# phpGPS
2+
23
A php based webservice for GPS tracking with Google Maps integration
4+
35
========
46

57
www.mikelduke.com
68

7-
89
*******************************************************************************
910
A php based webservice for GPS tracking with Google Maps integration
1011

@@ -17,8 +18,8 @@ https://developers.google.com/maps/documentation/embed/get-api-key
1718

1819
*******************************************************************************
1920

20-
2121
## Features
22+
2223
* Stores gps coordinates in a MySQL database, generates xml, and draws markers on to a Google Maps map.
2324
* Draw Paths on the map using the gps entries
2425
* Paths can be colored
@@ -32,34 +33,58 @@ https://developers.google.com/maps/documentation/embed/get-api-key
3233
* To embed on a webpage:
3334
```<iframe src="view.php" height="520" width="520" seamless></iframe>```
3435

35-
Example Update URL:
36-
http://yoursite.com/phpGPS/addGpsEntry.php?key=1234&newEntry=Y&gps_devicename=DeviceID&gps_type_id=1&gps_path_id=1&gps_date_dt=11-13-2014&gps_date_time=22.31&gps_status=&gps_latitude=32&gps_longitude=-96&gps_altitude=160.0&gps_accuracy=57&gps_name=test%20spot&gps_comment=test%20comment&gps_address1=address%201&gps_address2=address%202&gps_address3=address%203&gps_city=city&gps_zipcode=567567&gps_state=state&gps_country=country
36+
Example Update URL:
37+
`http://yoursite.com/phpGPS/addGpsEntry.php?key=1234&newEntry=Y&gps_devicename=DeviceID&gps_type_id=1&gps_path_id=1&gps_date_dt=11-13-2014&gps_date_time=22.31&gps_status=&gps_latitude=32&gps_longitude=-96&gps_altitude=160.0&gps_accuracy=57&gps_name=test%20spot&gps_comment=test%20comment&gps_address1=address%201&gps_address2=address%202&gps_address3=address%203&gps_city=city&gps_zipcode=567567&gps_state=state&gps_country=country`
38+
39+
*******************************************************************************
3740

3841
## Important Pages
42+
3943
* phpGPS_Settings.php - Settings File
4044
* generateXML.php - Generates xml for use by google maps
4145
* view.php - Displays the map with markers, embeddedable in an iframe
4246

43-
4447
## Requirements
48+
4549
* php 5+
4650
* MySQL
4751
* Webserver
4852

53+
*******************************************************************************
4954

5055
## Install Instructions
56+
5157
1. Extract php files to webhost
5258
1. Create Database for use by phpGPS
53-
1. Enter database settings and other config in phpGPS_Settings.php
59+
1. Enter database settings and other config in phpGPS_Settings.php or set using environment variables
5460
1. Open phpGPS/install/install.php in browser to create the necessary tables
5561
1. Delete the install folder on webhost
5662
1. Login as user admin/admin and change the default admin pass
5763
1. Set up owners, devices, paths, etc as desired and start creating markers
5864

59-
# Demo VM
65+
### Demo VM
66+
6067
Requires Vagrant + VM Provider like VirtualBox + Google Maps API Key
68+
6169
* Clone this repo and make sure .sh files use unix line endings LF
6270
* Set API Key in phpGPS_Settings.php
6371
* Run ```vagrant up```
64-
* Connect at http://localhost
72+
* Connect at `http://localhost`
73+
* Login with user/password: admin/admin
74+
75+
*******************************************************************************
76+
77+
## Development
78+
79+
Dockerfile and Docker-compose configs are included for easy setup on Linux/Mac. Windows + Docker is not as seamless.
80+
81+
Use `docker-compose up` to automatically load a basic mysql server and an apache+php server.
82+
The application is mounted as a volume to allow for modifying php scripts without restarts.
83+
84+
* Install docker and docker-compose if not already present `sudo apt install docker docker-compose`
85+
* Clone this repo, ensure Unix line endings are used
86+
* Set api key in shell `export DEV_KEY=1234567890`
87+
* Launch with `docker-compose up`
88+
* Connect at `http://localhost:8080`
6589
* Login with user/password: admin/admin
90+
* Control+C or `docker-compose down` to stop

docker-compose.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
version: '3'
2+
services:
3+
phpgps:
4+
build: .
5+
ports:
6+
- "8080:80"
7+
volumes:
8+
- "./src:/var/www/html/"
9+
environment:
10+
- DB_HOSTNAME=mysql
11+
- DB_NAME=phpgps
12+
- DB_USER=phpgps
13+
- DB_PASSWORD=password
14+
- DEV_KEY # set dev key here or export as envvar on local machine to passthrough
15+
networks:
16+
- test
17+
mysql:
18+
image: mysql/mysql-server:8.0
19+
hostname: mysql
20+
command: --default-authentication-plugin=mysql_native_password
21+
ports:
22+
- "3306:3306"
23+
environment:
24+
- MYSQL_ROOT_PASSWORD=root
25+
- MYSQL_DATABASE=phpgps
26+
- MYSQL_USER=phpgps
27+
- MYSQL_PASSWORD=password
28+
volumes:
29+
- "./sql:/docker-entrypoint-initdb.d/"
30+
networks:
31+
- test
32+
networks:
33+
test:
File renamed without changes.
File renamed without changes.

sql/DropTables.sql renamed to sql/DropTables.sql.disabled

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-- Drops tables used in phpGPS
2+
-- Rename to .sql
23

34
drop table users;
45
drop table user_types;

src/insertRecord.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@
4949
$field = phpGPS_DB::cleanInput($key);
5050
$val = phpGPS_DB::cleanInput($value);
5151

52-
if ($val != "NULL") $val = "'" . $val . "'";
52+
if ($val != "NULL" && $val !== "now()") {
53+
$val = "'" . $val . "'";
54+
}
5355
if ($hasValues) {
5456
$columns = $columns . ", ";
5557
$values = $values . ", ";

src/phpGPS_Settings.php

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<?php
22

3-
ini_set('display_errors',1);
4-
error_reporting(E_ALL);
3+
// enable for development only
4+
// ini_set('display_errors',1);
5+
// error_reporting(E_ALL);
56

67
class phpGPS_Settings {
8+
79
//Map Info
810
public static $_defaultZoom = 3;
911
public static $_defaultCenterLat = "41.988308";
@@ -32,5 +34,28 @@ class phpGPS_Settings {
3234

3335
//Secret key for adding an entry using addGpsEntry.php
3436
public static $_secretKey = "1234";
37+
38+
39+
// override defaults from environment variables if defined
40+
static function init() {
41+
phpGPS_Settings::$_host = phpGPS_Settings::loadFromEnv("DB_HOSTNAME", phpGPS_Settings::$_host);
42+
phpGPS_Settings::$_username = phpGPS_Settings::loadFromEnv("DB_USERNAME", phpGPS_Settings::$_username);
43+
phpGPS_Settings::$_password = phpGPS_Settings::loadFromEnv("DB_PASSWORD", phpGPS_Settings::$_password);
44+
phpGPS_Settings::$_dbname = phpGPS_Settings::loadFromEnv("DB_NAME", phpGPS_Settings::$_dbname);
45+
46+
phpGPS_Settings::$_devKey = phpGPS_Settings::loadFromEnv("DEV_KEY", phpGPS_Settings::$_devKey);
47+
48+
phpGPS_Settings::$_secretKey = phpGPS_Settings::loadFromEnv("SECRET_KEY", phpGPS_Settings::$_secretKey);
49+
}
50+
51+
private static function loadFromEnv($name, $default) {
52+
if (isset($_ENV[$name])) {
53+
return $_ENV[$name];
54+
} else {
55+
return $default;
56+
}
57+
}
3558
}
59+
60+
phpGPS_Settings::init();
3661
?>

src/view.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function saveMarkers() {
223223
var lat = newMarkers[i].getPosition().lat();
224224
var long = newMarkers[i].getPosition().lng();
225225
//TODO add passing in gps_date column, parsing from current date/time and adding editing for this field on edit marker page
226-
var url = "insertRecord.php?insert=true&table=gps_entries&gps_latitude=" + lat + "&gps_longitude=" + long + "&gps_entry_date=now()&gps_name=" + newMarkers[i].name;
226+
var url = "insertRecord.php?insert=true&table=gps_entries&gps_latitude=" + lat + "&gps_longitude=" + long + "&gps_entry_date=now()&gps_date=now()&gps_name=" + newMarkers[i].name;
227227
//prompt('', url);
228228
downloadUrl(url, function(data) {});
229229
}

0 commit comments

Comments
 (0)