From f6f3149aa40f7107ccad024011f8d62f49766d5a Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Tue, 17 May 2016 23:10:13 -0400 Subject: [PATCH 01/14] Added database password confirmation. --- bash/portal/install.sh | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/bash/portal/install.sh b/bash/portal/install.sh index 42bf659..b36e703 100755 --- a/bash/portal/install.sh +++ b/bash/portal/install.sh @@ -229,20 +229,20 @@ if [[ $INSTALLED == "n" ]]; then DATABASEHOST="localhost" if [[ $LOCALDATABASE == 1 ]]; then - read -p "MySQL user login: [root] " DATABASEUSER - read -p "Password for MySQL user: " DATABASEPASSWORD + read -p "MySQL user login: [root] " DATABASEADMINUSER + read -p "Password for MySQL user: " DATABASEADMINPASSWORD if [[ $LOCALDATABASE == "" ]]; then - DATABASEUSER="root" + DATABASEADMINUSER="root" fi # Check that the supplied password is correct. - while ! mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e ";" ; do + while ! mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e ";" ; do echo -e "\033[31m" echo -e "Unable to connect to the MySQL server using the supplied login and password.\033[37m" - read -p "MySQL user login: [root] " DATABASEUSER - read -p "Password for MySQL user: " DATABASEPASSWORD + read -p "MySQL user login: [root] " DATABASEADMINUSER + read -p "Password for MySQL user: " DATABASEADMINPASSWORD if [[ $LOCALDATABASE == "" ]]; then - DATABASEUSER="root" + DATABASEADMINUSER="root" fi done fi @@ -254,6 +254,13 @@ if [[ $INSTALLED == "n" ]]; then read -p "Database Name: " DATABASENAME read -p "Database User Name: " DATABASEUSER read -p "Database User Password: " DATABASEPASSWORD + read -p "Confirm Database User Password: " CONFIRMDATABASEPASSWORD + while ! [[ DATABASEPASSWORD == CONFIRMDATABASEPASSWORD ]]; do + echo -e "\033[31m" + echo -e "The supplied database user passwords did not match.\033[37m" + read -p "Database User Password: " DATABASEPASSWORD + read -p "Confirm Database User Password: " CONFIRMDATABASEPASSWORD + done if [[ $LOCALDATABASE == 2 ]]; then # Check the connection to the remote MySQL server. @@ -261,17 +268,17 @@ if [[ $INSTALLED == "n" ]]; then echo -e "\033[31m" echo -e "Unable to connect to the MySQL server using the supplied login and password.\033[37m" read -p "MySQL Server Address: " DATABASEHOST - read -p "Database user Name: " DATABASEUSER + read -p "Database User Name: " DATABASEUSER read -p "Database User Password: " DATABASEPASSWORD done else # Create the database and user if running MySQL locally. echo -e "\033[33m" echo -e "Creating MySQL database and user...\033[37m" - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "CREATE DATABASE ${DATABASENAME};" - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD}\";"; - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';" - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "FLUSH PRIVILEGES;" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "CREATE DATABASE ${DATABASENAME};" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD}\";"; + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "FLUSH PRIVILEGES;" fi echo -e "\033[31m" From 93ef14788cab4e63bcf89a58fd79bd1b2abf6236 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Tue, 17 May 2016 23:41:44 -0400 Subject: [PATCH 02/14] Couple MySQL install fixes after password check. --- bash/portal/install.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bash/portal/install.sh b/bash/portal/install.sh index b36e703..5772643 100755 --- a/bash/portal/install.sh +++ b/bash/portal/install.sh @@ -228,7 +228,7 @@ if [[ $INSTALLED == "n" ]]; then echo -e "\033[37m" DATABASEHOST="localhost" - if [[ $LOCALDATABASE == 1 ]]; then + if [[ $LOCALDATABASE != 2 ]]; then read -p "MySQL user login: [root] " DATABASEADMINUSER read -p "Password for MySQL user: " DATABASEADMINPASSWORD if [[ $LOCALDATABASE == "" ]]; then @@ -237,6 +237,7 @@ if [[ $INSTALLED == "n" ]]; then # Check that the supplied password is correct. while ! mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e ";" ; do + echo "" echo -e "\033[31m" echo -e "Unable to connect to the MySQL server using the supplied login and password.\033[37m" read -p "MySQL user login: [root] " DATABASEADMINUSER @@ -246,6 +247,7 @@ if [[ $INSTALLED == "n" ]]; then fi done fi + echo "" if [[ $LOCALDATABASE == 2 ]]; then # Ask for remote MySQL address if the database is hosted remotely. @@ -255,7 +257,7 @@ if [[ $INSTALLED == "n" ]]; then read -p "Database User Name: " DATABASEUSER read -p "Database User Password: " DATABASEPASSWORD read -p "Confirm Database User Password: " CONFIRMDATABASEPASSWORD - while ! [[ DATABASEPASSWORD == CONFIRMDATABASEPASSWORD ]]; do + while [ $DATABASEPASSWORD != $CONFIRMDATABASEPASSWORD ]; do echo -e "\033[31m" echo -e "The supplied database user passwords did not match.\033[37m" read -p "Database User Password: " DATABASEPASSWORD From c84d60bc6813fb675d98654a52b20e0f7ef77b25 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Wed, 18 May 2016 01:41:29 -0400 Subject: [PATCH 03/14] Added database user password confirmation. --- bash/image.sh | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) mode change 100644 => 100755 bash/image.sh diff --git a/bash/image.sh b/bash/image.sh old mode 100644 new mode 100755 index 6787a63..a36af20 --- a/bash/image.sh +++ b/bash/image.sh @@ -144,7 +144,7 @@ echo "You have been warned." echo -e "\033[37m" read -p "Use portal with advanced features? [y/N] " ADVANCED -## ASK IF ADVANCED FEATURES ARE TO BE USED +## ASK IF ADVANCED FEATURES ARE TO BE USED if [[ $ADVANCED =~ ^[yY]$ ]]; then echo -e "\033[31m" @@ -211,24 +211,26 @@ if [[ $ADVANCED =~ ^[yY]$ ]]; then echo -e "\033[37m" DATABASEHOST="localhost" - if [[ $LOCALDATABASE == 1 ]]; then - read -p "MySQL user login: [root] " DATABASEUSER - read -p "Password for MySQL user: " DATABASEPASSWORD + if [[ $LOCALDATABASE != 2 ]]; then + read -p "MySQL user login: [root] " DATABASEADMINUSER + read -p "Password for MySQL user: " DATABASEADMINPASSWORD if [[ $LOCALDATABASE == "" ]]; then - DATABASEUSER="root" + DATABASEADMINUSER="root" fi # Check that the supplied password is correct. - while ! mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e ";" ; do + while ! mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e ";" ; do + echo "" echo -e "\033[31m" echo -e "Unable to connect to the MySQL server using the supplied login and password.\033[37m" - read -p "MySQL user login: [root] " DATABASEUSER - read -p "Password for MySQL user: " DATABASEPASSWORD + read -p "MySQL user login: [root] " DATABASEADMINUSER + read -p "Password for MySQL user: " DATABASEADMINPASSWORD if [[ $LOCALDATABASE == "" ]]; then - DATABASEUSER="root" + DATABASEADMINUSER="root" fi done fi + echo "" if [[ $LOCALDATABASE == 2 ]]; then # Ask for remote MySQL address if the database is hosted remotely. @@ -237,6 +239,13 @@ if [[ $ADVANCED =~ ^[yY]$ ]]; then read -p "Database Name: " DATABASENAME read -p "Database User Name: " DATABASEUSER read -p "Database User Password: " DATABASEPASSWORD + read -p "Confirm Database User Password: " CONFIRMDATABASEPASSWORD + while [ $DATABASEPASSWORD != $CONFIRMDATABASEPASSWORD ]; do + echo -e "\033[31m" + echo -e "The supplied database user passwords did not match.\033[37m" + read -p "Database User Password: " DATABASEPASSWORD + read -p "Confirm Database User Password: " CONFIRMDATABASEPASSWORD + done if [[ $LOCALDATABASE == 2 ]]; then # Check the connection to the remote MySQL server. @@ -251,10 +260,10 @@ if [[ $ADVANCED =~ ^[yY]$ ]]; then # Create the database and user if running MySQL locally. echo -e "\033[33m" echo -e "Creating MySQL database and user...\033[37m" - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "CREATE DATABASE ${DATABASENAME};" - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD}\";"; - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';" - mysql -u${DATABASEUSER} -p${DATABASEPASSWORD} -e "FLUSH PRIVILEGES;" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "CREATE DATABASE ${DATABASENAME};" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "CREATE USER '${DATABASEUSER}'@'localhost' IDENTIFIED BY \"${DATABASEPASSWORD}\";"; + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "GRANT ALL PRIVILEGES ON ${DATABASENAME}.* TO '${DATABASEUSER}'@'localhost';" + mysql -u${DATABASEADMINUSER} -p${DATABASEADMINPASSWORD} -e "FLUSH PRIVILEGES;" fi echo -e "\033[31m" @@ -269,7 +278,7 @@ if [[ $ADVANCED =~ ^[yY]$ ]]; then echo -e "\033[37m" read -p "Press enter to continue..." CONTINUE fi - + if [[ $DATABASEENGINE == 2 ]]; then # Create and empty SQLite databse and set the proper permissions on it. sudo sqlite3 ${DOCUMENTROOT}/data/portal.sqlite "" From 2a6ca33939f93aab028fcc0c11b38fc282997038 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Wed, 18 May 2016 01:58:16 -0400 Subject: [PATCH 04/14] Install or upgrade to v2.0.3. --- build/portal/html/install/index.php | 4 ++-- build/portal/html/install/upgrade.php | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/build/portal/html/install/index.php b/build/portal/html/install/index.php index 8af16cf..1e9d119 100644 --- a/build/portal/html/install/index.php +++ b/build/portal/html/install/index.php @@ -29,13 +29,13 @@ ///////////////////////////////////////////////////////////////////////////////////// // The most current stable release. - $thisVersion = "2.0.2"; + $thisVersion = "2.0.3"; // Begin the upgrade process if this release is newer than what is installed. if (file_exists("../classes/settings.class.php")) { require('../classes/common.class.php'); $common = new common(); - + if ($common-> getSetting("version") < $thisVersion) { // THis is an older version so forward the user to upgrade.php header ("Location: /install/upgrade.php"); diff --git a/build/portal/html/install/upgrade.php b/build/portal/html/install/upgrade.php index 569e744..cea03ca 100644 --- a/build/portal/html/install/upgrade.php +++ b/build/portal/html/install/upgrade.php @@ -35,7 +35,7 @@ $settings = new settings(); // The most current stable release. - $thisVersion = "2.0.2"; + $thisVersion = "2.0.3"; // Begin the upgrade process if this release is newer than what is installed. if ($common->getSetting("version") == $thisVersion) { @@ -205,6 +205,20 @@ chmod($_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR."data".DIRECTORY_SEPARATOR."portal.sqlite", 0666); } + $common->updateSetting("version", "2.0.2"); + $common->updateSetting("patch", ""); + } catch(Exception $e) { + $error = TRUE; + $errorMessage = $e->getMessage(); + } + } + + /////////////////////// + // UPGRADE RO V2.0.3 + /////////////////////// + + if ($common->getSetting("version") == "2.0.2") { + try { $common->updateSetting("version", $thisVersion); $common->updateSetting("patch", ""); } catch(Exception $e) { @@ -213,6 +227,7 @@ } } + require_once('../admin/includes/header.inc.php'); // Display the instalation wizard. From 1007a36d160305b82f4196704b4c7d1c995ff580 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Wed, 18 May 2016 02:10:24 -0400 Subject: [PATCH 05/14] Noted v2.0.3 changes. --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3148841..0dcb056 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ The following is a history of the changes made to this project. +## v2.0.2 *(May 18th, 2016)* + +* Added password confirmation for MySQL database user to bash script. *(advanced)* +* Changes applied to image configuration script including fixes for bugs and wording. +* The device's IP address is now properly displayed at end of the bash setup process. +* MySQL upgrades failed to detect local or remote installs properly. *(advanced)* +* Changes to resolve PHP errors after running the PHP portal installer. *(advanced)* + ## v2.0.2 *(May 12th, 2016)* * When reinstalling dump1090-mutability the user is no longer asked for LAT and LON. From 726665abeb434c386ecae1ab117bae05beeb2991 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Thu, 19 May 2016 19:40:58 -0400 Subject: [PATCH 06/14] Update release date for v2.0.3. --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dcb056..7f1821c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ The following is a history of the changes made to this project. -## v2.0.2 *(May 18th, 2016)* +## v2.0.3 *(May 19th, 2016)* * Added password confirmation for MySQL database user to bash script. *(advanced)* * Changes applied to image configuration script including fixes for bugs and wording. From 73f0c4c0b124c931888aace719d1f205877cf95f Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Thu, 19 May 2016 20:24:26 -0400 Subject: [PATCH 07/14] Update version variable. --- build/portal/html/classes/template.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/portal/html/classes/template.class.php b/build/portal/html/classes/template.class.php index 752928b..4b4df2a 100644 --- a/build/portal/html/classes/template.class.php +++ b/build/portal/html/classes/template.class.php @@ -38,7 +38,7 @@ // Check if the portal is installed or needs upgraded. if (!file_exists($_SERVER['DOCUMENT_ROOT']."/classes/settings.class.php")) { header ("Location: /install/install.php"); - } elseif ($common->getSetting("version") != "2.0.2"){ + } elseif ($common->getSetting("version") != "2.0.3"){ header ("Location: /install/upgrade.php"); } From 0c8ed469d598c0c69ad55ecd37ceb1c80f3a85a8 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Fri, 20 May 2016 10:32:51 -0400 Subject: [PATCH 08/14] Update install.sh --- bash/portal/install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bash/portal/install.sh b/bash/portal/install.sh index 5772643..42cf103 100755 --- a/bash/portal/install.sh +++ b/bash/portal/install.sh @@ -88,7 +88,7 @@ if [ -f $DOCUMENTROOT/classes/settings.class.php ]; then DATABASEENGINE=1 fi - if [ $HOST == "localhost" ] || [ $HOST == "127.0.0.1" ]; then + if [[ $HOST == "localhost" ]] || [[ $HOST == "127.0.0.1" ]]; then LOCALDATABASE=1 else LOCALDATABASE=2 From a46cbfb7de2ba0bf5454cb97a63ebfb5b8dd3bd3 Mon Sep 17 00:00:00 2001 From: Adam Kaplan Date: Wed, 8 Jun 2016 03:40:56 -0400 Subject: [PATCH 09/14] Refatored flights.py for improved performance --- build/portal/logging/flights.py | 248 +++++++++++++++++--------------- 1 file changed, 134 insertions(+), 114 deletions(-) diff --git a/build/portal/logging/flights.py b/build/portal/logging/flights.py index 9fef0a1..6d21b10 100644 --- a/build/portal/logging/flights.py +++ b/build/portal/logging/flights.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#i!/usr/bin/python #================================================================================# # ADS-B FEEDER PORTAL # @@ -41,134 +41,154 @@ import time import os #import urllib2 -while True: +def log(string): + #print(string) # uncomment to enable debug logging + return - # Read the configuration file. - with open(os.path.dirname(os.path.realpath(__file__)) + '/config.json') as config_file: - config = json.load(config_file) +# Read the configuration file. +with open(os.path.dirname(os.path.realpath(__file__)) + '/config.json') as config_file: + config = json.load(config_file) - # Import the needed database library. - if config["database"]["type"] == "mysql": - import MySQLdb - if config["database"]["type"] == "sqlite": - import sqlite3 +# Import the needed database library. +if config["database"]["type"] == "mysql": + import MySQLdb +else: + import sqlite3 - # Read dump1090-mutability's aircraft.json. - with open('/run/dump1090-mutability/aircraft.json') as data_file: - data = json.load(data_file) - # For testing using a remote JSON feed. - #response = urllib2.urlopen('http://192.168.254.2/dump1090/data/aircraft.json') - #data = json.load(response) +class FlightsProcessor(object): + def __init__(self, config): + self.config = config + self.dbType = config["database"]["type"] + # List of required keys for position data entries + self.position_keys = ('lat', 'lon', 'altitude', 'speed', 'track', 'vert_rate') - if config["database"]["type"] == "sqlite": - ## Connect to a SQLite database. - db = sqlite3.connect(config["database"]["db"]) - else: - ## Connect to a MySQL database. - db = MySQLdb.connect(host=config["database"]["host"], user=config["database"]["user"], passwd=config["database"]["passwd"], db=config["database"]["db"]) + def setupDBStatements(self, formatSymbol): + if hasattr(self, 'STMTS'): + return + mapping = { "s": formatSymbol } + self.STMTS = { + 'select_aircraft_count':"SELECT COUNT(*) FROM adsb_aircraft WHERE icao = %(s)s" % mapping, + 'select_aircraft_id': "SELECT id FROM adsb_aircraft WHERE icao = %(s)s" % mapping, + 'select_flight_count': "SELECT COUNT(*) FROM adsb_flights WHERE flight = %(s)s" % mapping, + 'select_flight_id': "SELECT id FROM adsb_flights WHERE flight = %(s)s" % mapping, + 'select_position': "SELECT message FROM adsb_positions WHERE flight = %(s)s AND message = %(s)s ORDER BY time DESC LIMIT 1" % mapping, + 'insert_aircraft': "INSERT INTO adsb_aircraft (icao, firstSeen, lastSeen) VALUES (%(s)s, %(s)s, %(s)s)" % mapping, + 'insert_flight': "INSERT INTO adsb_flights (aircraft, flight, firstSeen, lastSeen) VALUES (%(s)s, %(s)s, %(s)s, %(s)s)" % mapping, + 'insert_position_sqwk': "INSERT INTO adsb_positions (flight, time, message, squawk, latitude, longitude, track, altitude, verticleRate, speed) VALUES (%(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s)" % mapping, + 'insert_position': "INSERT INTO adsb_positions (flight, time, message, latitude, longitude, track, altitude, verticleRate, speed) VALUES (%(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s, %(s)s)" % mapping, + 'update_aircraft_seen': "UPDATE adsb_aircraft SET lastSeen = %(s)s WHERE icao = %(s)s" % mapping, + 'update_flight_seen': "UPDATE adsb_flights SET aircraft = %(s)s, lastSeen = %(s)s WHERE flight = %(s)s" % mapping + } - # Assign the time to a variable. - time_now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S") + def connectDB(self): + if self.dbType == "sqlite": ## Connect to a SQLite database. + self.setupDBStatements("?") + return sqlite3.connect(self.config["database"]["db"]) + else: ## Connect to a MySQL database. + self.setupDBStatements("%s") + return MySQLdb.connect(host=self.config["database"]["host"], + user=self.config["database"]["user"], + passwd=self.config["database"]["passwd"], + db=self.config["database"]["db"]) - cursor = db.cursor() - for aircraft in data["aircraft"]: + def processAircraftList(self, aircraftList): + db = self.connectDB() + # Get Database cursor handle + self.cursor = db.cursor() + # Assign the time to a variable. + self.time_now = datetime.datetime.utcnow().strftime("%Y/%m/%d %H:%M:%S") + + for aircraft in aircraftList: + self.processAircraft(aircraft) + + # Close the database connection. + db.commit() + db.close() + + def processAircraft(self, aircraft): + hexcode = aircraft["hex"] # Check if this aircraft was already seen. - if config["database"]["type"] == "sqlite": - params = (aircraft["hex"],) - cursor.execute("SELECT COUNT(*) FROM adsb_aircraft WHERE icao = ?", params) - else: - cursor.execute("SELECT COUNT(*) FROM adsb_aircraft WHERE icao = %s", aircraft["hex"]) - row_count = cursor.fetchone() + self.cursor.execute(self.STMTS['select_aircraft_count'], (hexcode,)) + row_count = self.cursor.fetchone() if row_count[0] == 0: # Insert the new aircraft. - #print("Added Aircraft: " + aircraft["hex"]) - if config["database"]["type"] == "sqlite": - params = (aircraft["hex"], time_now, time_now,) - cursor.execute("INSERT INTO adsb_aircraft (icao, firstSeen, lastSeen) VALUES (?, ?, ?)", params) - else: - cursor.execute("INSERT INTO adsb_aircraft (icao, firstSeen, lastSeen) VALUES (%s, %s, %s)", (aircraft["hex"], time_now, time_now)) + log("Added Aircraft: " + hexcode) + self.cursor.execute(self.STMTS['insert_aircraft'], (hexcode, self.time_now, self.time_now,)) else: # Update the existing aircraft. - if config["database"]["type"] == "sqlite": - params = (time_now, aircraft["hex"],) - cursor.execute("UPDATE adsb_aircraft SET lastSeen = ? WHERE icao = ?", params) - else: - cursor.execute("UPDATE adsb_aircraft SET lastSeen = %s WHERE icao = %s", (time_now, aircraft["hex"])) + self.cursor.execute(self.STMTS['update_aircraft_seen'], (self.time_now, hexcode,)) + log("Updating Aircraft: " + hexcode) # Get the ID of this aircraft. - if config["database"]["type"] == "sqlite": - params = (aircraft["hex"],) - cursor.execute("SELECT id FROM adsb_aircraft WHERE icao = ?", params) - else: - cursor.execute("SELECT id FROM adsb_aircraft WHERE icao = %s", aircraft["hex"]) - rows = cursor.fetchall() - for row in rows: - aircraft_id = row[0] + self.cursor.execute(self.STMTS['select_aircraft_id'], (hexcode,)) + row = self.cursor.fetchone() + aircraft_id = row[0] + log("\tFound Aircraft ID: " + str(aircraft_id)) # Check that a flight is tied to this track. if aircraft.has_key('flight'): - # Check to see if the flight already exists in the database. - if config["database"]["type"] == "sqlite": - params = (aircraft["flight"].strip(),) - cursor.execute("SELECT COUNT(*) FROM adsb_flights WHERE flight = ?", params) - else: - cursor.execute("SELECT COUNT(*) FROM adsb_flights WHERE flight = %s", aircraft["flight"].strip()) - row_count = cursor.fetchone() - if row_count[0] == 0: - # If the flight does not exist in the database add it. - if config["database"]["type"] == "sqlite": - params = (aircraft_id, aircraft["flight"].strip(), time_now, time_now,) - cursor.execute("INSERT INTO adsb_flights (aircraft, flight, firstSeen, lastSeen) VALUES (?, ?, ?, ?)", params) - else: - cursor.execute("INSERT INTO adsb_flights (aircraft, flight, firstSeen, lastSeen) VALUES (%s, %s, %s, %s)", (aircraft_id, aircraft["flight"].strip(), time_now, time_now)) - #print("Added Flight: " + aircraft["flight"].strip()) - else: - # If it already exists pdate the time it was last seen. - if config["database"]["type"] == "sqlite": - params =(aircraft_id, time_now, aircraft["flight"].strip(),) - cursor.execute("UPDATE adsb_flights SET aircraft = ?, lastSeen = ? WHERE flight = ?", params) - else: - cursor.execute("UPDATE adsb_flights SET aircraft = %s, lastSeen = %s WHERE flight = %s", (aircraft_id, time_now, aircraft["flight"].strip())) - # Get the ID of this flight. - if config["database"]["type"] == "sqlite": - params = (aircraft["flight"].strip(),) - cursor.execute("SELECT id FROM adsb_flights WHERE flight = ?", params) - else: - cursor.execute("SELECT id FROM adsb_flights WHERE flight = %s", aircraft["flight"].strip()) - rows = cursor.fetchall() - for row in rows: - flight_id = row[0] + self.processFlight(aircraft_id, aircraft) - # Check if position data is available. - if aircraft.has_key('lat') and aircraft.has_key('lon') and aircraft.has_key('altitude') and aircraft.has_key('speed') and aircraft.has_key('track') and aircraft.has_key('vert_rate') and aircraft["altitude"] != "ground": - # Check that this message has not already been added to the database. - if config["database"]["type"] == "sqlite": - params = (flight_id, aircraft["messages"],) - cursor.execute("SELECT message FROM adsb_positions WHERE flight = ? AND message = ? ORDER BY time DESC", params) - else: - cursor.execute("SELECT message FROM adsb_positions WHERE flight = %s AND message = %s ORDER BY time DESC", (flight_id, aircraft["messages"])) - rows = cursor.fetchall() - row_count = cursor.rowcount - last_message = 0 - for row in rows: - last_message = row[0] - if row_count == 0 or last_message != aircraft["messages"]: - # Add this position to the database. - if aircraft.has_key('squawk'): - if config["database"]["type"] == "sqlite": - params = (flight_id, time_now, aircraft["messages"], aircraft["squawk"], aircraft["lat"], aircraft["lon"], aircraft["track"], aircraft["altitude"], aircraft["vert_rate"], aircraft["speed"],) - cursor.execute("INSERT INTO adsb_positions (flight, time, message, squawk, latitude, longitude, track, altitude, verticleRate, speed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", params) - else: - cursor.execute("INSERT INTO adsb_positions (flight, time, message, squawk, latitude, longitude, track, altitude, verticleRate, speed) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", (flight_id, time_now, aircraft["messages"], aircraft["squawk"], aircraft["lat"], aircraft["lon"], aircraft["track"], aircraft["altitude"], aircraft["vert_rate"], aircraft["speed"])) - else: - if config["database"]["type"] == "sqlite": - params = (flight_id, time_now, aircraft["messages"], aircraft["lat"], aircraft["lon"], aircraft["track"], aircraft["altitude"], aircraft["vert_rate"], aircraft["speed"],) - cursor.execute("INSERT INTO adsb_positions (flight, time, message, latitude, longitude, track, altitude, verticleRate, speed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", params) - else: - cursor.execute("INSERT INTO adsb_positions (flight, time, message, latitude, longitude, track, altitude, verticleRate, speed) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", (flight_id, time_now, aircraft["messages"], aircraft["lat"], aircraft["lon"], aircraft["track"], aircraft["altitude"], aircraft["vert_rate"], aircraft["speed"])) + def processFlight(self, aircraft_id, aircraft): + flight = aircraft["flight"].strip() + # Check to see if the flight already exists in the database. + self.cursor.execute(self.STMTS['select_flight_count'], (flight,)) + row_count = self.cursor.fetchone() + if row_count[0] == 0: + # If the flight does not exist in the database add it. + params = (aircraft_id, flight, self.time_now, self.time_now,) + self.cursor.execute(self.STMTS['insert_flight'], params) + log("\t\tAdded Flight: " + flight) + else: + # If it already exists pdate the time it was last seen. + params = (aircraft_id, self.time_now, flight,) + self.cursor.execute(self.STMTS['update_flight_seen'], params) + log("\t\tUpdated Flight: " + flight) + # Get the ID of this flight. + self.cursor.execute(self.STMTS['select_flight_id'], (flight,)) + row = self.cursor.fetchone() + flight_id = row[0] - # Close the database connection. - db.commit() - db.close() + # Check if position data is available. + if (all (k in aircraft for k in self.position_keys) and aircraft["altitude"] != "ground"): + self.processPositions(flight_id, aircraft) + + def processPositions(self, flight_id, aircraft): + # Check that this message has not already been added to the database. + params = (flight_id, aircraft["messages"],) + self.cursor.execute(self.STMTS['select_position'], params) + row = self.cursor.fetchone() + + if row == None or row[0] != aircraft["messages"]: + # Add this position to the database. + if aircraft.has_key('squawk'): + params = (flight_id, self.time_now, aircraft["messages"], aircraft["squawk"], + aircraft["lat"], aircraft["lon"], aircraft["track"], + aircraft["altitude"], aircraft["vert_rate"], aircraft["speed"],) + self.cursor.execute(self.STMTS['insert_position_sqwk'], params) + log("\t\t\tInserted position w/ Squawk " + repr(params)) + else: + params = (flight_id, self.time_now, aircraft["messages"], aircraft["lat"], aircraft["lon"], + aircraft["track"], aircraft["altitude"], aircraft["vert_rate"], aircraft["speed"],) + self.cursor.execute(self.STMTS['insert_position'], params) + log("\t\t\tInserted position w/o Squawk " + repr(params)) + else: + log("\t\t\tMessage is the same") + + +if __name__ == "__main__": + processor = FlightsProcessor(config) + + # Main run loop + while True: + # Read dump1090-mutability's aircraft.json. + with open('/run/dump1090-mutability/aircraft.json') as data_file: + data = json.load(data_file) + # For testing using a remote JSON feed. + #response = urllib2.urlopen('http://192.168.254.2/dump1090/data/aircraft.json') + #data = json.load(response) + + processor.processAircraftList(data["aircraft"]) + + log("Last Run: " + datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")) + time.sleep(15) - #print("Last Run: " + datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")) - time.sleep(15) From a943ccb1fe4e19a2e11f8e95775d6dc09210ce66 Mon Sep 17 00:00:00 2001 From: Adam Kaplan Date: Wed, 8 Jun 2016 03:44:43 -0400 Subject: [PATCH 10/14] Fix type in shebang --- build/portal/logging/flights.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/portal/logging/flights.py b/build/portal/logging/flights.py index 6d21b10..0265670 100644 --- a/build/portal/logging/flights.py +++ b/build/portal/logging/flights.py @@ -1,4 +1,4 @@ -#i!/usr/bin/python +#!/usr/bin/python #================================================================================# # ADS-B FEEDER PORTAL # From eec49bbff8b547c3c2fc7d892574a5e67d957d56 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Wed, 8 Jun 2016 10:58:49 -0400 Subject: [PATCH 11/14] Check for the php5-json package. --- bash/portal/install.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bash/portal/install.sh b/bash/portal/install.sh index 42cf103..a7a4b07 100755 --- a/bash/portal/install.sh +++ b/bash/portal/install.sh @@ -156,9 +156,11 @@ if [ -f /etc/lsb-release ]; then CheckPackage php7.0-xml else CheckPackage php5-cgi + CheckPackage php5-json fi else CheckPackage php5-cgi + CheckPackage php5-json fi CheckPackage libpython2.7 From 02a46e5cc361af8c31c96c9905d7676efda46d18 Mon Sep 17 00:00:00 2001 From: Lee Armstrong Date: Wed, 17 Aug 2016 13:05:53 +0100 Subject: [PATCH 12/14] Updated to Plane Finder client 3.4.61 --- bash/variables.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash/variables.sh b/bash/variables.sh index c88e389..39ca1ea 100644 --- a/bash/variables.sh +++ b/bash/variables.sh @@ -38,8 +38,8 @@ PIAWAREVERSION="2.1-5" PIAWAREBRANCH="5c77c4924" # PlaneFinder ADS-B Client -PFCLIENTVERSIONARM="3.4.30" -PFCLIENTVERSIONI386="3.4.30" +PFCLIENTVERSIONARM="3.4.61" +PFCLIENTVERSIONI386="3.4.61" # Flightradar24 Linux Debian package FR24CLIENTVERSIONI386="1.0.18-5" From 77b4a69586ea0bae539cf04d8d1d299dc716c45c Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Thu, 18 Aug 2016 15:40:54 -0400 Subject: [PATCH 13/14] Add python-pyinotify as a required for merge request #204. --- bash/portal/install.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/bash/portal/install.sh b/bash/portal/install.sh index a7a4b07..8ed43b0 100755 --- a/bash/portal/install.sh +++ b/bash/portal/install.sh @@ -165,6 +165,7 @@ fi CheckPackage libpython2.7 if [[ $ADVANCED =~ ^[yY]$ ]]; then + CheckPackage python-pyinotify if [[ $DATABASEENGINE == 2 ]]; then CheckPackage sqlite3 From a296b422878de1e7a2e5d9745499f7f648384ca0 Mon Sep 17 00:00:00 2001 From: Joe Prochazka Date: Thu, 18 Aug 2016 18:04:57 -0400 Subject: [PATCH 14/14] Updated PiAware version. --- bash/variables.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bash/variables.sh b/bash/variables.sh index 39ca1ea..05c2532 100644 --- a/bash/variables.sh +++ b/bash/variables.sh @@ -34,8 +34,8 @@ ## SOFTWARE VERSIONS # FlightAware PiAware -PIAWAREVERSION="2.1-5" -PIAWAREBRANCH="5c77c4924" +PIAWAREVERSION="3.0.3" +PIAWAREBRANCH="master" # PlaneFinder ADS-B Client PFCLIENTVERSIONARM="3.4.61"