diff --git a/README.md b/README.md index d113932..86a1ba7 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,9 @@ Python Script to receive and decode German BOS Information with rtl_fm and multimon-NG -#### Note: -**This software is for illustrative purposes only and may be used only by authorized persons.** - -**The intercept of the German BOS radio is strictly prohibited !!!** +#### Notice: +The intercept of the German BOS radio is **strictly prohibited** and will be prosecuted. the use is **only authorized** personnel permitted. +The software was developed using the Multimon-NG code, a function in the real operation can not be guaranteed. **Please** only use Code from **master**-Branch - thats **the only stable!** diff --git a/boswatch.py b/boswatch.py index 42326cc..de771e1 100644 --- a/boswatch.py +++ b/boswatch.py @@ -20,6 +20,7 @@ import argparse #for parse the args import ConfigParser #for parse the config file import re #Regex for validation + # Functions def curtime(format="%Y-%m-%d %H:%M:%S"): return time.strftime(format) @@ -228,37 +229,40 @@ try: if "CRC correct" in decoded: #check CRC is correct fms_id = fms_service+fms_country+fms_location+fms_vehicle+fms_status+fms_direction #build FMS id - if re.search("[0-9a-f]{2}[0-9]{6}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid + if re.search("[0-9a-f]{8}[0-9a-f]{1}[01]{1}", fms_id): #if FMS is valid if fms_id == fms_id_old and timestamp < fms_time_old + fms_double_ignore_time: #check for double alarm log("FMS double alarm: "+fms_id_old) fms_time_old = timestamp #in case of double alarm, fms_double_ignore_time set new else: - log("BOS:"+fms_service+" Bundesland:"+fms_country+" Ort:"+fms_location+" Fahrzeug:"+fms_vehicle+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi,"info") + log("FMS:"+fms_id[0:8]+" Status:"+fms_status+" Richtung:"+fms_direction+" TKI:"+fms_tsi,"info") fms_id_old = fms_id #save last id fms_time_old = timestamp #save last time if useMySQL: #only if MySQL is active - log("insert FMS into MySQL") + log("FMS to MySQL") try: connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) cursor = connection.cursor() - cursor.execute("INSERT INTO "+tableFMS+" (time,service,country,location,vehicle,status,direction,tsi) VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",(curtime(),fms_service,fms_country,fms_location,fms_vehicle,fms_status,fms_direction,fms_tsi)) + cursor.execute("INSERT INTO "+tableFMS+" (time,fms,status,direction,tsi) VALUES (%s,%s,%s,%s,%s)",(curtime(),fms_id[0:8],fms_status,fms_direction,fms_tsi)) cursor.close() connection.commit() except: - log("FMS cannot insert into MySQL","error") + log("FMS to MySQL failed","error") finally: connection.close() #Close connection in every case if useHTTPrequest: #only if HTTPrequest is active - log("FMS to HTTP request") + log("FMS to HTTP") try: httprequest = httplib.HTTPConnection(url) httprequest.request("HEAD", "/") httpresponse = httprequest.getresponse() - #if args.verbose: print httpresponse.status, httpresponse.reason + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + else: + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") except: - log("FMS HTTP request failed","error") + log("FMS to HTTP failed","error") else: log("No valid FMS: "+fms_id) else: @@ -281,7 +285,7 @@ try: zvei_time_old = timestamp #save last time if useMySQL: #only if MySQL is active - log("insert ZVEI into MySQL") + log("ZVEI to MySQL") try: connection = mysql.connector.connect(host = str(dbserver), user = str(dbuser), passwd = str(dbpassword), db = str(database)) cursor = connection.cursor() @@ -289,22 +293,26 @@ try: cursor.close() connection.commit() except: - log("ZVEI cannot insert into MySQL","error") + log("ZVEI to MySQL failed","error") finally: connection.close() #Close connection in every case if useHTTPrequest: #only if HTTPrequest is active - log("ZVEI to HTTP request") + log("ZVEI to HTTP") try: httprequest = httplib.HTTPConnection(url) httprequest.request("HEAD", "/") httpresponse = httprequest.getresponse() - #if args.verbose: print httpresponse.status, httpresponse.reason + if str(httpresponse.status) == "200": #Check HTTP Response an print a Log or Error + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason)) + else: + log("HTTP response: "+str(httpresponse.status)+" - "+str(httpresponse.reason),"error") except: - log("ZVEI HTTP request failed","error") + log("ZVEI to HTTP failed","error") else: log("No valid ZVEI: "+zvei_id) + except KeyboardInterrupt: log("Keyboard Interrupt","error") except: diff --git a/boswatch.sql b/boswatch.sql index 489eecd..735804b 100644 --- a/boswatch.sql +++ b/boswatch.sql @@ -29,10 +29,7 @@ SET time_zone = "+00:00"; CREATE TABLE IF NOT EXISTS `bos_fms` ( `id` int(11) NOT NULL AUTO_INCREMENT, `time` datetime NOT NULL, - `service` varchar(1) NOT NULL, - `country` varchar(2) NOT NULL, - `location` varchar(2) NOT NULL, - `vehicle` varchar(4) NOT NULL, + `fms` varchar(8) NOT NULL, `status` varchar(1) NOT NULL, `direction` varchar(1) NOT NULL, `tsi` varchar(3) NOT NULL, diff --git a/www/index.php b/www/index.php index c0495ba..e7146ec 100644 --- a/www/index.php +++ b/www/index.php @@ -2,7 +2,9 @@ @@ -15,78 +17,29 @@ $db_link = mysqli_connect ($dbhost, $dbuser, $dbpassword, $database);
- BOSWatch
- Last alarms for FMS and ZVEI (max. 50)

+ BOSWatch
+ [Übersicht] - [Parser] -
- Last FMS alarms - - - - - - - - - - - - -
+ "; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; - echo ""; + include("tpl/content.overview.php"); + include("tpl/template.overview.php"); } - ?> -
IDDatum - ZeitBOSBundeslandOrtFahrzeugStat.Richt.TKI
". $data['id'] . "". $time . "". parse("service",$fms_id) . "". parse("country",$fms_id) . "". parse("location",$fms_id) . "". parse("vehicle",$fms_id) . "". $data['status'] . "". parse("direction",$fms_id) . "". $data['tsi'] . "
-
- -
- Last ZVEI alarms - - - - - - - "; - echo ""; - echo ""; - echo ""; - echo ""; + include("tpl/content.parser.php"); + include("tpl/template.parser.php"); + } + else + { + include("tpl/content.overview.php"); + include("tpl/template.overview.php"); } - ?> -
IDDatum - ZeitSchleife
". $data['id'] . "". $time . "". parse('zvei',$data['zvei']) . "
-
+ ?>
diff --git a/www/mysql.class.php b/www/mysql.class.php new file mode 100644 index 0000000..9343fdd --- /dev/null +++ b/www/mysql.class.php @@ -0,0 +1,134 @@ +show_error = $show_error; + @$this->conn = mysql_connect($host, $user, $password); + if ($this->conn == false) + { + $this->error("Keine Verbindung zum Datenbank Server!", mysql_error()); + return false; + } + + if (!@mysql_select_db($database, $this->conn)) + { + $this->error("Datenbank nicht gefunden!", mysql_error()); + return false; + } + return true; + } + + /** + * Database::query() + * + * Führt einen MySQL Query aus + * + * @param mixed $query Auszuführender Query + * @return Result-Handler/FALSE + */ + function query($query) + { + $this->result = @mysql_query($query, $this->conn); + if ($this->result == false) + { + $this->error("Fehlerhafte Datenbank Anfrage!", mysql_error()); + return false; + } + return $this->result; + } + + /** + * Database::fetchAssoc() + * + * Liefert alle gefundnen Datensätze als Assoc + * + * @param mixed $result Externer Result-Handler + * @return gefundene Datensätze als Assoc + */ + function fetchAssoc($result = null) + { + if ($result != null) + { + return @mysql_fetch_assoc($result); + } else + { + return @mysql_fetch_assoc($this->result); + } + } + + /** + * Database::count() + * + * Zählt alle gefundenen Datensätze + * + * @param mixed $result Externer Result-Handler + * @return Anzahl gefundener Datensätze + */ + function count($result = null) + { + if ($result != null) + { + return @mysql_num_rows($result); + } else + { + return @mysql_num_rows($this->result); + } + } + + /** + * Database::closeConnection() + * + * Schließt die bestehende MySQL Verbindung + * + * @return TRUE/FALSE + */ + function closeConnection() + { + if (!@mysql_close($this->conn)) + { + $this->error("Verbindung zur Datenbank konnte nicht getrennt werden!", mysql_error()); + return false; + } + return true; + } + + /** + * Database::error() + * + * Gibt eine Interne Fehlermeldung aus + * + * @param mixed $error_msg Text der Fehlermeldung + * @param mixed $sql_err MySQL Fehlermeldung per mysql_error() + * @return NULL + */ + private function error($error_msg, $sql_err) + { + if ($this->show_error) + { + echo "
MySQL Error: $error_msg
$sql_err"; + return true; + //exit(); + } + } + +} ?> \ No newline at end of file diff --git a/www/parser.php b/www/parser.php index 4393f95..37bb708 100644 --- a/www/parser.php +++ b/www/parser.php @@ -1,5 +1,6 @@ "Meck-Pom/Sachsen-Anhalt", "f" => "Brandenburg/Thüringen", ); - - //Data for Location Parsing - $location = array( - "11" => "testLoc", - "22" => "testLoc", - "33" => "testLoc" - ); - - //Data for Vehicle Parsing - $vehicle = array( - "1111" => "testVeh", - "2222" => "testVeh", - "3333" => "testVeh" - ); - - + + //Data for ZVEI Parsing $zvei = array( "12345" => "testZvei", @@ -89,31 +76,7 @@ { return $data; } - break; - - //Parse Location - case "location": - $data = substr($data,2,2); - if (array_key_exists($data, $location)) - { - return $location[$data]; - }else - { - return $data; - } - break; - - //Parse Vehicle - case "vehicle": - $data = substr($data,4,4); - if (array_key_exists($data, $vehicle)) - { - return $vehicle[$data]; - }else - { - return $data; - } - break; + break; //Parse direction case "direction": diff --git a/www/tpl/content.overview.php b/www/tpl/content.overview.php new file mode 100644 index 0000000..8d2f141 --- /dev/null +++ b/www/tpl/content.overview.php @@ -0,0 +1,19 @@ +query("SELECT id, time, fms, status, direction, tsi FROM ".$tableFMS." ORDER BY id DESC LIMIT 50"); + $Rows = array(); + while ($daten = $db->fetchAssoc()) + { + $Rows[] = $daten; + } + $tpl['fms'] = $Rows; + + //read ZVEI + $db->query("SELECT id, time, zvei FROM ".$tableZVEI." ORDER BY id DESC LIMIT 50"); + $Rows = array(); + while ($daten = $db->fetchAssoc()) + { + $Rows[] = $daten; + } + $tpl['zvei'] = $Rows; +?> \ No newline at end of file diff --git a/www/tpl/content.parser.php b/www/tpl/content.parser.php new file mode 100644 index 0000000..15c5adc --- /dev/null +++ b/www/tpl/content.parser.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/www/tpl/template.overview.php b/www/tpl/template.overview.php new file mode 100644 index 0000000..e1c973a --- /dev/null +++ b/www/tpl/template.overview.php @@ -0,0 +1,57 @@ +Last alarms for FMS and ZVEI (max. 50)

+ +
+ Last FMS alarms + + + + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> +
IDDatum - ZeitFMSStat.Richt.TKI
". $fms['id'] . "". $time . "". $fms['fms'] . "". $fms['status'] . "". $fms['direction'] . "". $fms['tsi'] . "
+
+ +
+ Last ZVEI alarms + + + + + + + "; + echo ""; + echo ""; + echo ""; + echo ""; + } + ?> +
IDDatum - ZeitSchleife
". $zvei['id'] . "". $time . "". $zvei['zvei'] . "
+
\ No newline at end of file diff --git a/www/tpl/template.parser.php b/www/tpl/template.parser.php new file mode 100644 index 0000000..e69de29