Merge pull request #3 from Schrolli91/develop

merge
This commit is contained in:
Schrolli91 2015-04-11 20:50:10 +02:00
commit 2b7d6031c4
10 changed files with 263 additions and 130 deletions

View file

@ -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!**

View file

@ -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:

View file

@ -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,

View file

@ -2,7 +2,9 @@
<?php
require_once ("config.php");
require_once ("parser.php");
$db_link = mysqli_connect ($dbhost, $dbuser, $dbpassword, $database);
require_once ("mysql.class.php");
$db = new Database($dbhost, $dbuser, $dbpassword, $database, 1); //Show Error = 1!
?>
@ -15,78 +17,29 @@ $db_link = mysqli_connect ($dbhost, $dbuser, $dbpassword, $database);
<div style="text-align: center; width: 1250px; margin: 0px auto;">
<img src="gfx/logo.png" alt="BOSWatch"><br>
Last alarms for FMS and ZVEI (max. 50)<br><br>
<img src="gfx/logo.png" alt="BOSWatch"><br>
<a href="index.php?overview">[Übersicht]</a> - <a href="index.php?parser">[Parser]</a>
<div style="float: left; width: 800px;">
<b>Last FMS alarms</b>
<table border="1" style="width: 800px;">
<tr style="font-weight: bold;">
<td>ID</td>
<td>Datum - Zeit</td>
<td>BOS</td>
<td>Bundesland</td>
<td>Ort</td>
<td>Fahrzeug</td>
<td>Stat.</td>
<td>Richt.</td>
<td>TKI</td>
</tr>
<?php
$sql = "SELECT id, time, service, country, location, vehicle, status, direction, tsi FROM ".$tableFMS." ORDER BY id DESC LIMIT 50";
$db_erg = mysqli_query( $db_link, $sql );
while ($data = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
<br><br>
<?php
if(isset($_GET['overview']))
{
$time = strtotime($data['time']);
$time = date("d.m.Y H:i:s", $time);
$fms_id = $data['service'].$data['country'].$data['location'].$data['vehicle'].$data['status'].$data['direction'];
echo "<tr>";
echo "<td>". $data['id'] . "</td>";
echo "<td>". $time . "</td>";
echo "<td>". parse("service",$fms_id) . "</td>";
echo "<td>". parse("country",$fms_id) . "</td>";
echo "<td>". parse("location",$fms_id) . "</td>";
echo "<td>". parse("vehicle",$fms_id) . "</td>";
echo "<td>". $data['status'] . "</td>";
echo "<td>". parse("direction",$fms_id) . "</td>";
echo "<td>". $data['tsi'] . "</td>";
echo "</tr>";
include("tpl/content.overview.php");
include("tpl/template.overview.php");
}
?>
</table>
</div>
<div style="float: right; width: 400px;">
<b>Last ZVEI alarms</b>
<table border="1" style="width: 400px;">
<tr style="font-weight: bold;">
<td>ID</td>
<td>Datum - Zeit</td>
<td>Schleife</td>
</tr>
<?php
$sql = "SELECT id, time, zvei FROM ".$tableZVEI." ORDER BY id DESC LIMIT 50";
$db_erg = mysqli_query( $db_link, $sql );
while ($data = mysqli_fetch_array( $db_erg, MYSQL_ASSOC))
elseif(isset($_GET['parser']))
{
$time = strtotime($data['time']);
$time = date("d.m.Y H:i:s", $time);
echo "<tr>";
echo "<td>". $data['id'] . "</td>";
echo "<td>". $time . "</td>";
echo "<td>". parse('zvei',$data['zvei']) . "</td>";
echo "</tr>";
include("tpl/content.parser.php");
include("tpl/template.parser.php");
}
else
{
include("tpl/content.overview.php");
include("tpl/template.overview.php");
}
?>
</table>
</div>
?>
</div>
</body>

134
www/mysql.class.php Normal file
View file

@ -0,0 +1,134 @@
<?php class Database
/**
Simple Database Class (C) by Bastian Schroll
**/
{
//Variablen
private $conn = null;
private $result = null;
private $show_error = 1;
/**
* Database::__construct()
*
* Stellt eine Verbung mit der MySQL Datenbank fest
*
* @param mixed $host Hostname des Datenbank Server
* @param mixed $user Username des Datenbank Nutzers
* @param mixed $password Passwort des Datenbank Nutzers
* @param mixed $database Name der Datenbank
* @param integer $show_error Zeige Fehlermeldungen
* @return TRUE/FALSE
*/
function __construct($host, $user, $password, $database, $show_error = 1)
{
$this->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 "<br><strong>MySQL Error: $error_msg</strong><br>$sql_err";
return true;
//exit();
}
}
} ?>

View file

@ -1,5 +1,6 @@
<?php
//Data from TRBOS-FMS http://www.lfs-bw.de/Fachthemen/Digitalfunk-Funk/Documents/Pruefstelle/TRBOS-FMS.pdf
// TRBOS-FMS http://www.lfs-bw.de/Fachthemen/Digitalfunk-Funk/Documents/Pruefstelle/TRBOS-FMS.pdf
// FMS Bayern https://www.stmi.bayern.de/assets/stmi/sus/feuerwehr/id2_17a_03_02_fms_kenng_fw_anl1_20020523.pdf
function parse($mode, $data)
{
@ -42,22 +43,8 @@
"e" => "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":

View file

@ -0,0 +1,19 @@
<?php
//read FMS
$db->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;
?>

View file

@ -0,0 +1,3 @@
<?php
?>

View file

@ -0,0 +1,57 @@
Last alarms for FMS and ZVEI (max. 50)<br><br>
<div style="float: left; width: 800px;">
<b>Last FMS alarms</b>
<table border="1" style="width: 800px;">
<tr style="font-weight: bold;">
<td>ID</td>
<td>Datum - Zeit</td>
<td>FMS</td>
<td>Stat.</td>
<td>Richt.</td>
<td>TKI</td>
</tr>
<?php
foreach ($tpl['fms'] as $fms)
{
$time = strtotime($fms['time']);
$time = date("d.m.Y H:i:s", $time);
echo "<tr>";
echo "<td>". $fms['id'] . "</td>";
echo "<td>". $time . "</td>";
echo "<td>". $fms['fms'] . "</td>";
echo "<td>". $fms['status'] . "</td>";
echo "<td>". $fms['direction'] . "</td>";
echo "<td>". $fms['tsi'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>
<div style="float: right; width: 400px;">
<b>Last ZVEI alarms</b>
<table border="1" style="width: 400px;">
<tr style="font-weight: bold;">
<td>ID</td>
<td>Datum - Zeit</td>
<td>Schleife</td>
</tr>
<?php
foreach ($tpl['zvei'] as $zvei)
{
$time = strtotime($zvei['time']);
$time = date("d.m.Y H:i:s", $time);
echo "<tr>";
echo "<td>". $zvei['id'] . "</td>";
echo "<td>". $time . "</td>";
echo "<td>". $zvei['zvei'] . "</td>";
echo "</tr>";
}
?>
</table>
</div>

View file