diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..6d14a03b --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,26 @@ +# Changelog + + +#### __[v2.2.1]__ - 19.09.2017 +##### Added +- Neues Service Script +- Eigene Message fpr jeden Typ im Telegram Plugin + +##### Changed +- Name der csv Dateien um überschreiben bei Update zu vermeiden +- Description Liste kann nun zusätzlich Einträge für jede Subric enthalten +- RegEX verbietet nun grundsätzlich alles - Es muss explizit zugelassen werden + +##### Deprecated +##### Removed +##### Fixed +- Bug im SMS77 Plugin + +##### Security + + +---------------------------- + + +Zum schreiben des Changelog's siehe: +http://keepachangelog.com/de/1.0.0/ diff --git a/README.md b/README.md index c08f8058..ac3d336b 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ unless you are developer you can use the develop-Branch - may be unstable! - other Ideas per Issues please -###Plugins +### Plugins If you want to code your own Plugin, see `plugins/README.md`. ##### Implemented plugins: @@ -81,7 +81,7 @@ For the other functions see "Usage" below. For the RegEX filter functions see Section `[Filters]` http://www.regexr.com/ - RegEX test tool an documentation -No filter for a combination typ/plugin = all data will pass +If RegEX is enabled - only alloewd data will pass ! Syntax: `INDIVIDUAL_NAME = TYP;DATAFIELD;PLUGIN;FREQUENZ;REGEX` (separator `;`) - `TYP` = the data typ (FMS|ZVEI|POC) diff --git a/config/config.template.ini b/config/config.template.ini index be5484b1..d943faff 100644 --- a/config/config.template.ini +++ b/config/config.template.ini @@ -49,7 +49,7 @@ doubleFilter_ignore_time = 5 doubleFilter_check_msg = 0 # writes the multimon-ng raw data stream into a text file named mm_raw.txt -writeMultimonRaw = 1 +writeMultimonRaw = 0 [NMAHandler] # you can use a logging handler for sending logging records to NotifyMyAndroid @@ -169,6 +169,8 @@ tableSIG = bos_signal [httpRequest] # example URL http://example.com/remote.php?DESCR=%DESCR% +# multiple URLs can be separated by comma + # you can use the following wildcards in your URL as GET params: # http://en.wikipedia.org/wiki/Query_string @@ -413,13 +415,46 @@ RICforLocationAPIKey = # Required if you want to create a map based on location information received with the above RIC. GoogleAPIKey = +# %FMS% = FMS Code +# %STATUS% = FMS Status +# %DIR% = Direction of the telegram (0/1) +# %DIRT% = Direction of the telegram (Text-String) +# %TSI% = Tactical Short Information (I-IV) +# %DESCR% = Description, if description-module is used +# %DATE% = Date (by script) +# %TIME% = Time (by script) +# %LPAR% = ( +# %RPAR% = ) +FMS_message = %DATE% %TIME%: %FMS% + +# %ZVEI% = ZVEI 5-tone Code +# %DESCR% = Description, if description-module is used +# %DATE% = Date (by script) +# %TIME% = Time (by script) +# %LPAR% = ( +# %RPAR% = ) +ZVEI_message = %DATE% %TIME%: %ZVEI% + +# %RIC% = POCSAG RIC +# %FUNC% = POCSAG function/Subric (1-4) +# %FUNCCHAR% = POCSAG function/Subric als character (a-d) +# %MSG% = Message of the POCSAG telegram +# %BITRATE% = Bitrate of the POCSAG telegram +# %DESCR% = Description, if description-module is used +# %DATE% = Date (by script) +# %TIME% = Time (by script) +# %LPAR% = ( +# %RPAR% = ) +POC_message = %MSG% + + [yowsup] # number or chat-number who whants to become the news -empfaenger = +empfaenger = # WhatsApp-number of that the news comes -sender = +sender = # password from this number -password= +password= # %FMS% = FMS Code # %STATUS% = FMS Status diff --git a/csv/fms.csv b/csv/fms.template.csv similarity index 100% rename from csv/fms.csv rename to csv/fms.template.csv diff --git a/csv/nma.csv b/csv/nma.template.csv similarity index 100% rename from csv/nma.csv rename to csv/nma.template.csv diff --git a/csv/poc.csv b/csv/poc.template.csv similarity index 100% rename from csv/poc.csv rename to csv/poc.template.csv diff --git a/csv/zvei.csv b/csv/zvei.template.csv similarity index 100% rename from csv/zvei.csv rename to csv/zvei.template.csv diff --git a/exampleAddOns/alarmMonitorWeb/MySQL-Import/login.sql b/exampleAddOns/alarmMonitorWeb/MySQL-Import/login.sql index b7b4bc59..925dd53d 100644 --- a/exampleAddOns/alarmMonitorWeb/MySQL-Import/login.sql +++ b/exampleAddOns/alarmMonitorWeb/MySQL-Import/login.sql @@ -36,7 +36,7 @@ CREATE TABLE `login` ( LOCK TABLES `login` WRITE; /*!40000 ALTER TABLE `login` DISABLE KEYS */; -INSERT INTO `login` VALUES ,(1,'Test','098f6bcd4621d373cade4e832627b4f6'); +INSERT INTO `login` VALUES (1,'admin',md5('admin')); /*!40000 ALTER TABLE `login` ENABLE KEYS */; UNLOCK TABLES; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; diff --git a/exampleAddOns/alarmMonitorWeb/config.php b/exampleAddOns/alarmMonitorWeb/config.php index 3d9fb883..f3a439c8 100644 --- a/exampleAddOns/alarmMonitorWeb/config.php +++ b/exampleAddOns/alarmMonitorWeb/config.php @@ -1,8 +1,8 @@ + + + + + + +Zurück"; + exit; + } +$passwort = md5($passwort); + +$result = mysqli_query($verbindung, "SELECT id FROM login WHERE username LIKE '$username'"); +$menge = mysqli_num_rows($result); + +if($menge == 0) + { + $eintrag = "INSERT INTO login (username, passwort) VALUES ('$username', '$passwort')"; + $eintragen = mysqli_query($verbindung, $eintrag); + + if($eintragen == true) + { + echo "Benutzername $username wurde erstellt. Login"; + } + else + { + echo "Fehler beim Speichern des Benutzernames. Zurück"; + } + + + } + +else + { + echo "Benutzername schon vorhanden. Zurück"; + } +?> diff --git a/exampleAddOns/alarmMonitorWeb/eintragen.html b/exampleAddOns/alarmMonitorWeb/eintragen.html deleted file mode 100644 index b850f57a..00000000 --- a/exampleAddOns/alarmMonitorWeb/eintragen.html +++ /dev/null @@ -1,111 +0,0 @@ - - - - - -einloggen"; - exit; - } -?> - - - - - - BOSwatch - - - - - - - - - - - - - - - -
- -
- - - - -
-
Usermanagment
-
- -
- -
-Username:
-
- -Passwort:
-
- -Passwort wiederholen:
-
- - -
- -
- -
-
- - - - - - - - - - \ No newline at end of file diff --git a/exampleAddOns/alarmMonitorWeb/eintragen.php b/exampleAddOns/alarmMonitorWeb/eintragen.php index 22488dc2..91bba00c 100644 --- a/exampleAddOns/alarmMonitorWeb/eintragen.php +++ b/exampleAddOns/alarmMonitorWeb/eintragen.php @@ -1,58 +1,111 @@ + + einloggen"; exit; } ?> + + + + BOSwatch + + + + + + + + + + + + + -Zurück"; - exit; - } -$passwort = md5($passwort); - -$result = mysql_query("SELECT id FROM login WHERE username LIKE '$username'"); -$menge = mysql_num_rows($result); - -if($menge == 0) - { - $eintrag = "INSERT INTO login (username, passwort) VALUES ('$username', '$passwort')"; - $eintragen = mysql_query($eintrag); - - if($eintragen == true) - { - echo "Benutzername $username wurde erstellt. Login"; - } - else - { - echo "Fehler beim Speichern des Benutzernames. Zurück"; - } - - - } - -else - { - echo "Benutzername schon vorhanden. Zurück"; - } -?> + +
+ +
+ + + + +
+
Usermanagment
+
+ +
+ +
+Username:
+
+ +Passwort:
+
+ +Passwort wiederholen:
+
+ + +
+ +
+ +
+
+ + + + + + + + + + diff --git a/exampleAddOns/alarmMonitorWeb/index.php b/exampleAddOns/alarmMonitorWeb/index.php index c6165ce5..a04cdaa3 100644 --- a/exampleAddOns/alarmMonitorWeb/index.php +++ b/exampleAddOns/alarmMonitorWeb/index.php @@ -40,7 +40,7 @@ @@ -75,6 +75,14 @@
+Startanzeige:
+
+ + @@ -100,4 +108,4 @@ - \ No newline at end of file + diff --git a/exampleAddOns/alarmMonitorWeb/login.php b/exampleAddOns/alarmMonitorWeb/login.php index f12c4ddc..264c6b5b 100644 --- a/exampleAddOns/alarmMonitorWeb/login.php +++ b/exampleAddOns/alarmMonitorWeb/login.php @@ -4,25 +4,44 @@ Login"; + exit; +} $username = $_POST["username"]; $passwort = md5($_POST["password"]); -$abfrage = "SELECT username, passwort FROM" $tableLOG "WHERE username LIKE '$username' LIMIT 1"; -$ergebnis = mysql_query($abfrage); -$row = mysql_fetch_object($ergebnis); + +$abfrage = "SELECT username, passwort FROM ".$tableLOG." WHERE username LIKE '$username' LIMIT 1"; +$ergebnis = mysqli_query($verbindung, $abfrage); +$row = mysqli_fetch_object($ergebnis); if($row->passwort == $passwort) { $_SESSION["username"] = $username; - header("Location: /show_pocsag.php"); + switch ($_POST["view"]) { + case 'pocsag': + header("Location: show_pocsag.php"); + break; + case 'zvei': + header("Location: show_zvei.php"); + break; + case 'fms': + header("Location: show_fms.php"); + break; + default: + header("Location: show_pocsag.php"); + } } else { - echo "Benutzername und/oder Passwort waren falsch. Login"; + echo "Benutzername und/oder Passwort waren falsch. Login"; } ?> diff --git a/exampleAddOns/alarmMonitorWeb/logout.php b/exampleAddOns/alarmMonitorWeb/logout.php new file mode 100644 index 00000000..314640c4 --- /dev/null +++ b/exampleAddOns/alarmMonitorWeb/logout.php @@ -0,0 +1,6 @@ + diff --git a/exampleAddOns/alarmMonitorWeb/prefs.php b/exampleAddOns/alarmMonitorWeb/prefs.php index 29a2a359..ddf63789 100644 --- a/exampleAddOns/alarmMonitorWeb/prefs.php +++ b/exampleAddOns/alarmMonitorWeb/prefs.php @@ -11,7 +11,7 @@ ?>
Einstellungen
- +
@@ -60,4 +60,4 @@ - \ No newline at end of file + diff --git a/exampleAddOns/alarmMonitorWeb/tpl/a_header.php b/exampleAddOns/alarmMonitorWeb/tpl/a_header.php index 3614643e..866b34f7 100644 --- a/exampleAddOns/alarmMonitorWeb/tpl/a_header.php +++ b/exampleAddOns/alarmMonitorWeb/tpl/a_header.php @@ -41,7 +41,8 @@
  • FMS
  • ZVEI
  • Einstellungen
  • -
  • Nutzer anlegen
  • +
  • Nutzer anlegen
  • +
  • Ausloggen
  • diff --git a/exampleAddOns/alarmMonitorWeb/tpl/mysql.class.php b/exampleAddOns/alarmMonitorWeb/tpl/mysql.class.php index 69d5fbdb..3910fd90 100644 --- a/exampleAddOns/alarmMonitorWeb/tpl/mysql.class.php +++ b/exampleAddOns/alarmMonitorWeb/tpl/mysql.class.php @@ -23,16 +23,16 @@ function __construct($host, $user, $password, $database, $show_error = 1) { $this->show_error = $show_error; - @$this->conn = mysql_connect($host, $user, $password); + @$this->conn = mysqli_connect($host, $user, $password); if ($this->conn == false) { - $this->error("Keine Verbindung zum Datenbank Server!", mysql_error()); + $this->error("Keine Verbindung zum Datenbank Server!", mysqli_error($this->conn)); return false; } - if (!@mysql_select_db($database, $this->conn)) + if (!@mysqli_select_db($this->conn, $database)) { - $this->error("Datenbank nicht gefunden!", mysql_error()); + $this->error("Datenbank nicht gefunden!", mysqli_error($this->conn)); return false; } return true; @@ -48,10 +48,10 @@ function __construct($host, $user, $password, $database, $show_error = 1) */ function query($query) { - $this->result = @mysql_query($query, $this->conn); + $this->result = @mysqli_query($this->conn, $query); if ($this->result == false) { - $this->error("Fehlerhafte Datenbank Anfrage!", mysql_error()); + $this->error("Fehlerhafte Datenbank Anfrage!", mysqli_error($this->conn)); return false; } return $this->result; @@ -69,10 +69,10 @@ function fetchAssoc($result = null) { if ($result != null) { - return @mysql_fetch_assoc($result); + return @mysqli_fetch_assoc($result); } else { - return @mysql_fetch_assoc($this->result); + return @mysqli_fetch_assoc($this->result); } } diff --git a/exampleAddOns/alarmMonitorWeb/tpl/pocsag.php b/exampleAddOns/alarmMonitorWeb/tpl/pocsag.php index 4e4c6f29..5e86ebbc 100644 --- a/exampleAddOns/alarmMonitorWeb/tpl/pocsag.php +++ b/exampleAddOns/alarmMonitorWeb/tpl/pocsag.php @@ -10,7 +10,7 @@ query("SELECT id, time, ric, funktion, text, description FROM ".$tablePOC." ORDER BY id DESC LIMIT 100"); + $db->query("SELECT id, time, ric, function, msg, description FROM ".$tablePOC." ORDER BY id DESC LIMIT 100"); $Rows = array(); while ($daten = $db->fetchAssoc()) { @@ -29,11 +29,11 @@ // echo "". $poc['id'] . ""; // echo "". $poc['description'] . ""; - echo "". $poc['text'] . ""; + echo "". $poc['msg'] . ""; echo "". $time . ""; echo "". $poc['ric'] . ""; - echo "". $poc['funktion'] . ""; + echo "". $poc['function'] . ""; echo ""; } ?> - \ No newline at end of file + diff --git a/includes/decoders/poc.py b/includes/decoders/poc.py index 46be0427..b0198f09 100644 --- a/includes/decoders/poc.py +++ b/includes/decoders/poc.py @@ -126,7 +126,7 @@ def decode(freq, decoded): # If enabled, look up description if globalVars.config.getint("POC", "idDescribed"): from includes import descriptionList - data["description"] = descriptionList.getDescription("POC", poc_id) + data["description"] = descriptionList.getDescription("POC", poc_id+data["functionChar"]) # processing the alarm try: from includes import alarmHandler diff --git a/includes/descriptionList.py b/includes/descriptionList.py index cca894fb..9e548fd9 100644 --- a/includes/descriptionList.py +++ b/includes/descriptionList.py @@ -11,6 +11,7 @@ import logging # Global logger import csv # for loading the description files +import re # for matching IDs with a regular expression from includes import globalVars # Global variables from includes.helper import stringConverter @@ -41,10 +42,10 @@ def loadCSV(typ, idField): reader = csv.DictReader(csvfile) for row in reader: logging.debug(row) - # only import rows with an integer as id - if row[idField].isdigit() == True: + # only import rows with an integer as id, allow subrics though + if re.match("^[0-9]+[A-D]?$", row[idField], re.IGNORECASE): try: - resultList[row[idField]] = stringConverter.convertToUTF8(row['description']) + resultList[row[idField].lower()] = stringConverter.convertToUTF8(row['description']) except: # skip entry in case of an exception pass @@ -105,14 +106,12 @@ def getDescription(typ, data): logging.debug("look up description lists") try: if typ == "FMS": - global fmsDescribtionList resultStr = fmsDescribtionList[data] elif typ == "ZVEI": - global zveiDescribtionList resultStr = zveiDescribtionList[data] elif typ == "POC": - global ricDescribtionList - resultStr = ricDescribtionList[data] + resultStr = ricDescribtionList[data[:-1]] # MainRIC + resultStr += " " + ricDescribtionList[data] # SubRIC else: logging.warning("Invalid Typ: %s", typ) diff --git a/includes/doubleFilter.py b/includes/doubleFilter.py index 85506403..887b074f 100644 --- a/includes/doubleFilter.py +++ b/includes/doubleFilter.py @@ -31,12 +31,10 @@ def checkID(typ, data, msg=""): @return: True if check was OK @return: False if double was found """ - global doubleList timestamp = int(time.time()) # Get Timestamp logging.debug("checkID: %s (%s)", data, msg) - for i in range(len(doubleList)): - (xID, xTimestamp, xMsg) = doubleList[i] + for (xID, xTimestamp, xMsg) in doubleList: # given ID found? # return False if the first entry in double_ignore_time is found, we will not check for younger ones... if data == xID and timestamp < xTimestamp + globalVars.config.getint("BOSWatch", "doubleFilter_ignore_time"): diff --git a/includes/globalVars.py b/includes/globalVars.py index 9be0fac0..0d6f2b3c 100644 --- a/includes/globalVars.py +++ b/includes/globalVars.py @@ -9,8 +9,9 @@ """ # version info -versionNr = "2.2" -buildDate = "2017/03/30" +versionNr = "2.2.1-beta" +buildDate = "2017/09/19" + # Global variables config = 0 diff --git a/includes/helper/wildcardHandler.py b/includes/helper/wildcardHandler.py index d67dde23..e85e6f81 100644 --- a/includes/helper/wildcardHandler.py +++ b/includes/helper/wildcardHandler.py @@ -17,7 +17,7 @@ from includes.helper import timeHandler -def replaceWildcards(text, data, lineBrakeAllowed=False): +def replaceWildcards(text, data): """ Replace all official Wildcards with the Information from the data[] var @@ -25,8 +25,6 @@ def replaceWildcards(text, data, lineBrakeAllowed=False): @param text: Input text with wildcards @type data: map @param data: map of data (structure see readme.md in plugin folder) - @type lineBrakeAllowed: Boolean - @param lineBrakeAllowed: switch to allow lineBreak (%BR%) as wildcard @return: text with replaced wildcards @exception: Exception if Error at replace @@ -36,8 +34,7 @@ def replaceWildcards(text, data, lineBrakeAllowed=False): text = text.replace("%TIME%", timeHandler.getTime(data["timestamp"])).replace("%DATE%", timeHandler.getDate(data["timestamp"])) # replace some special chars - if lineBrakeAllowed == True: - text = text.replace("%BR%", "\r\n") + text = text.replace("%BR%", "\r\n") text = text.replace("%LPAR%", "(") text = text.replace("%RPAR%", ")") diff --git a/includes/pynma/pynma.py b/includes/pynma/pynma.py index ff91a316..08a71cbe 100644 --- a/includes/pynma/pynma.py +++ b/includes/pynma/pynma.py @@ -39,16 +39,16 @@ def __init__(self, apikey=[], developerkey=None): self._developerkey = None self.developerkey(developerkey) if apikey: - if type(apikey) == str: + if isinstance(apikey, str): apikey = [apikey] self._apikey = uniq(apikey) def addkey(self, key): "Add a key (register ?)" - if type(key) == str: + if isinstance(key, str): if not key in self._apikey: self._apikey.append(key) - elif type(key) == list: + elif isinstance(key, list): for k in key: if not k in self._apikey: self._apikey.append(k) @@ -65,7 +65,7 @@ def delkey(self, key): def developerkey(self, developerkey): "Sets the developer key (and check it has the good length)" - if type(developerkey) == str and len(developerkey) == 48: + if isinstance(developerkey, str) and len(developerkey) == 48: self._developerkey = developerkey def pushWithAPIKey(self, apikey=[], application="", event="", description="", url="", contenttype=None, priority=0, batch_mode=False, html=False): diff --git a/includes/regexFilter.py b/includes/regexFilter.py index 20838c8e..bccd7ea5 100644 --- a/includes/regexFilter.py +++ b/includes/regexFilter.py @@ -28,7 +28,6 @@ def loadFilters(): @return: nothing """ - global filterList try: logging.debug("loading filters") # For each entry in config.ini [Filters] section @@ -89,7 +88,7 @@ def checkFilters(typ, data, plugin, freq): return False else: logging.debug("no Filter found") - return True + return False except: logging.error("Error in filter checking") diff --git a/plugins/MySQL/MySQL.py b/plugins/MySQL/MySQL.py index 02be083f..59415719 100644 --- a/plugins/MySQL/MySQL.py +++ b/plugins/MySQL/MySQL.py @@ -111,9 +111,9 @@ def run(typ,freq,data): elif typ == "POC": if isSignal(data["ric"]): - cursor.execute("UPDATE "+globalVars.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = "+data["ric"]) + cursor.execute("UPDATE "+globalVars.config.get("MySQL","tableSIG")+" SET time = NOW() WHERE ric = '"+data["ric"]+"';") if cursor.rowcount == 0: - cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(),"+data["ric"]+")") + cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tableSIG")+" (time,ric) VALUES (NOW(), '"+data["ric"]+"');") else: cursor.execute("INSERT INTO "+globalVars.config.get("MySQL","tablePOC")+" (time, ric, function, functionChar, msg, bitrate, description) VALUES (FROM_UNIXTIME(%s),%s,%s,%s,%s,%s,%s)", (data["timestamp"], data["ric"], data["function"], data["functionChar"], data["msg"], data["bitrate"], data["description"])) diff --git a/plugins/MySQL/boswatch.sql b/plugins/MySQL/boswatch.sql index 8a88c684..6f938610 100644 --- a/plugins/MySQL/boswatch.sql +++ b/plugins/MySQL/boswatch.sql @@ -104,44 +104,6 @@ CREATE TABLE IF NOT EXISTS `bos_signal` ( PRIMARY KEY (`ID`) ) ENGINE=MYISAM DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1; --- -------------------------------------------------------- - --- --- Schedule für Tabelle `bos_pocsag` --- -CREATE EVENT IF NOT EXISTS `Delete POCSAG Entries > 3 Months` - ON SCHEDULE EVERY 1 DAY - STARTS '2016-01-01 00:00:00' - ON COMPLETION PRESERVE ENABLE - DO - DELETE FROM bos_pocsag WHERE time < DATE_SUB(NOW(),INTERVAL 3 MONTH); - --- -------------------------------------------------------- - --- --- Schedule für Tabelle `bos_fms` --- - -CREATE EVENT IF NOT EXISTS `Delete FMS Entries > 3 Months` - ON SCHEDULE EVERY 1 DAY - STARTS '2016-01-01 00:00:00' - ON COMPLETION PRESERVE ENABLE - DO - DELETE FROM bos_fms WHERE time < DATE_SUB(NOW(),INTERVAL 3 MONTH); - --- -------------------------------------------------------- - --- --- Schedule für Tabelle `bos_zvei` --- - -CREATE EVENT IF NOT EXISTS `Delete ZVEI Entries > 3 Months` - ON SCHEDULE EVERY 1 DAY - STARTS '2016-01-01 00:00:00' - ON COMPLETION PRESERVE ENABLE - DO - DELETE FROM bos_zvei WHERE time < DATE_SUB(NOW(),INTERVAL 3 MONTH); - /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; diff --git a/plugins/MySQL/boswatch_cleanup.sql b/plugins/MySQL/boswatch_cleanup.sql new file mode 100644 index 00000000..eb3fcb06 --- /dev/null +++ b/plugins/MySQL/boswatch_cleanup.sql @@ -0,0 +1,40 @@ +-- Cleanup-routines for boswatch-tables + +use boswatch; +-- -------------------------------------------------------- + +-- +-- Schedule für Tabelle `bos_pocsag` +-- +CREATE EVENT IF NOT EXISTS `Delete POCSAG Entries > 3 Months` + ON SCHEDULE EVERY 1 DAY + STARTS '2016-01-01 00:00:00' + ON COMPLETION PRESERVE ENABLE + DO + DELETE FROM bos_pocsag WHERE time < DATE_SUB(NOW(),INTERVAL 3 MONTH); + +-- -------------------------------------------------------- + +-- +-- Schedule für Tabelle `bos_fms` +-- + +CREATE EVENT IF NOT EXISTS `Delete FMS Entries > 3 Months` + ON SCHEDULE EVERY 1 DAY + STARTS '2016-01-01 00:00:00' + ON COMPLETION PRESERVE ENABLE + DO + DELETE FROM bos_fms WHERE time < DATE_SUB(NOW(),INTERVAL 3 MONTH); + +-- -------------------------------------------------------- + +-- +-- Schedule für Tabelle `bos_zvei` +-- + +CREATE EVENT IF NOT EXISTS `Delete ZVEI Entries > 3 Months` + ON SCHEDULE EVERY 1 DAY + STARTS '2016-01-01 00:00:00' + ON COMPLETION PRESERVE ENABLE + DO + DELETE FROM bos_zvei WHERE time < DATE_SUB(NOW(),INTERVAL 3 MONTH); diff --git a/plugins/Sms77/Sms77.py b/plugins/Sms77/Sms77.py index 9fb49437..e4353d13 100644 --- a/plugins/Sms77/Sms77.py +++ b/plugins/Sms77/Sms77.py @@ -58,6 +58,20 @@ def run(typ,freq,data): """ try: if configHandler.checkConfig("Sms77"): #read and debug the config + + # create an empty message an fill it with the required information + message = "Alarm" + if typ == "FMS": + logging.debug("FMS detected, building message") + message = data["description"]+"
    "+data["status"] + elif typ == "ZVEI": + logging.debug("ZVEI detected, building message") + message = data["zvei"]+" - "+data["description"] + elif typ == "POC": + logging.debug("POC detected, building message") + message = data["description"]+"
    "+data["msg"].replace(";", "
    ") + else: + logging.warning("Invalid typ - use empty message") try: @@ -74,7 +88,7 @@ def run(typ,freq,data): "to": globalVars.config.get("Sms77", "to"), "from": globalVars.config.get("Sms77", "from"), "type": globalVars.config.get("Sms77", "type"), - "text": data["description"]+"
    "+data["msg"].replace(";", "
    ") + "text": message }),{"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}) except: diff --git a/plugins/Telegram/Telegram.py b/plugins/Telegram/Telegram.py index 0d890c86..fc4acc78 100644 --- a/plugins/Telegram/Telegram.py +++ b/plugins/Telegram/Telegram.py @@ -16,8 +16,8 @@ from includes import globalVars # Global variables # Helper function, uncomment to use +from includes.helper import wildcardHandler from includes.helper import configHandler -from includes.helper import timeHandler # local variables BOTTokenAPIKey = None @@ -78,20 +78,21 @@ def run(typ,freq,data): try: ########## User Plugin CODE ########## try: - if typ == "POC": - logging.debug("Compose output from POCSAG-message") + if typ in ("POC", "FMS", "ZVEI"): + logging.debug("Read format and compose output for %s-message" % typ) # compose message content - output = timeHandler.curtime()+"\n"+data["ric"]+"("+data["functionChar"]+")\n"+data["description"]+"\n"+data["msg"] + text = globalVars.config.get("Telegram", "%s_message" % typ) + text = wildcardHandler.replaceWildcards(text, data) # Initiate Telegram Bot logging.debug("Initiate Telegram BOT") bot = telegram.Bot(token='%s' % BOTTokenAPIKey) # Send message to chat via Telegram BOT API logging.debug("Send message to chat via Telegram BOT API") - bot.sendMessage('%s' % BOTChatIDAPIKey, output) + bot.sendMessage('%s' % BOTChatIDAPIKey, text) # Generate location information only for specific RIC - if data["ric"] == RICforLocationAPIKey: + if typ == "POC" and data["ric"] == RICforLocationAPIKey: # Generate map logging.debug("Extract address from POCSAG message") address = "+".join(data["msg"].split(')')[0].split('/',1)[1].replace('(',' ').split()) @@ -113,28 +114,6 @@ def run(typ,freq,data): gcode_result = gcode.geocode(address) logging.debug("Send location via Telegram BOT API") bot.sendLocation('%s' % BOTChatIDAPIKey, gcode_result[0]['geometry']['location']['lat'], gcode_result[0]['geometry']['location']['lng'], disable_notification='true') - elif typ == "FMS": - logging.debug("Compose output from FMS-message") - # compose message content - output = timeHandler.curtime()+"\n"+data["fms"]+"\n"+data["description"]+"\n"+data["status"] - - # Initiate Telegram Bot - logging.debug("Initiate Telegram BOT") - bot = telegram.Bot(token='%s' % BOTTokenAPIKey) - # Send message to chat via Telegram BOT API - logging.debug("Send message to chat via Telegram BOT API") - bot.sendMessage('%s' % BOTChatIDAPIKey, output) - elif typ == "ZVEI": - logging.debug("Compose output from ZVEI-message") - # compose message content - output = timeHandler.curtime()+"\n"+data["zvei"]+"\n"+data["description"] - - # Initiate Telegram Bot - logging.debug("Initiate Telegram BOT") - bot = telegram.Bot(token='%s' % BOTTokenAPIKey) - # Send message to chat via Telegram BOT API - logging.debug("Send message to chat via Telegram BOT API") - bot.sendMessage('%s' % BOTChatIDAPIKey, output) else: logging.warning("Invalid Typ: %s", typ) except Unauthorized: diff --git a/plugins/eMail/eMail.py b/plugins/eMail/eMail.py index d054c85a..ec271b20 100644 --- a/plugins/eMail/eMail.py +++ b/plugins/eMail/eMail.py @@ -137,7 +137,7 @@ def run(typ,freq,data): # read mailtext-structure from config.ini mailtext = globalVars.config.get("eMail", "fms_message") # replace wildcards with helper function - mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True) + mailtext = wildcardHandler.replaceWildcards(mailtext, data) # send eMail doSendmail(server, subject, mailtext) @@ -157,7 +157,7 @@ def run(typ,freq,data): # read mailtext-structure from config.ini mailtext = globalVars.config.get("eMail", "zvei_message") # replace wildcards with helper function - mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True) + mailtext = wildcardHandler.replaceWildcards(mailtext, data) # send eMail doSendmail(server, subject, mailtext) @@ -177,7 +177,7 @@ def run(typ,freq,data): # read mailtext-structure from config.ini mailtext = globalVars.config.get("eMail", "poc_message") # replace wildcards with helper function - mailtext = wildcardHandler.replaceWildcards(mailtext, data, lineBrakeAllowed=True) + mailtext = wildcardHandler.replaceWildcards(mailtext, data) # send eMail doSendmail(server, subject, mailtext) diff --git a/plugins/httpRequest/httpRequest.py b/plugins/httpRequest/httpRequest.py index 3d8d90e0..744f6216 100644 --- a/plugins/httpRequest/httpRequest.py +++ b/plugins/httpRequest/httpRequest.py @@ -14,6 +14,7 @@ # # Imports # +import urllib import urllib2 import logging # Global logger from includes import globalVars # Global variables @@ -67,36 +68,41 @@ def run(typ,freq,data): try: # - # Create URL + # Replace special characters in data Strings for URL + # + for key in data: + if isinstance(data[key], basestring): + data[key] = urllib.quote(data[key]) + # + # Get URLs # if typ == "FMS": - url = globalVars.config.get("httpRequest", "fms_url") #Get URL - url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function - url = url.replace(" ","%20") # replace space with %20 to be a vaild http request + urls = globalVars.config.get("httpRequest", "fms_url").split(",") elif typ == "ZVEI": - url = globalVars.config.get("httpRequest", "zvei_url") #Get URL - url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function - url = url.replace(" ","%20") # replace space with %20 to be a vaild http request + urls = globalVars.config.get("httpRequest", "zvei_url").split(",") elif typ == "POC": - url = globalVars.config.get("httpRequest", "poc_url") #Get URL - url = wildcardHandler.replaceWildcards(url, data) # replace wildcards with helper function - url = url.replace(" ","%20") # replace space with %20 to be a vaild http request + urls = globalVars.config.get("httpRequest", "poc_url").split(",") else: logging.warning("Invalid Typ: %s", typ) return # + # replace wildcards + # + for (i, url) in enumerate(urls): + urls[i] = wildcardHandler.replaceWildcards(urls[i].strip(), data) + # # HTTP-Request # - logging.debug("send %s HTTP request", typ) - - try: - #resp = urllib2.urlopen(url) - urllib2.urlopen(url) - except urllib2.HTTPError as e: - logging.warning("HTTP response: %s", e.code) - except urllib2.URLError as e: - logging.warning("HTTP-specific error: %s", e.args) + logging.debug("send %s HTTP requests", typ) + + for url in urls: + try: + urllib2.urlopen(url) + except urllib2.HTTPError as e: + logging.warning("HTTP response: %s", e.code) + except urllib2.URLError as e: + logging.warning("HTTP-specific error: %s", e.args) except: logging.error("cannot send HTTP request") diff --git a/plugins/notifyMyAndroid/notifyMyAndroid.py b/plugins/notifyMyAndroid/notifyMyAndroid.py index ece18591..7fa535f5 100644 --- a/plugins/notifyMyAndroid/notifyMyAndroid.py +++ b/plugins/notifyMyAndroid/notifyMyAndroid.py @@ -173,9 +173,6 @@ def run(typ,freq,data): @return: nothing """ # local variables - global fmsAPIKeyList - global zveiAPIKeyList - global pocAPIKeyList try: try: diff --git a/service/README.md b/service/README.md index 3057ee47..41337a91 100644 --- a/service/README.md +++ b/service/README.md @@ -1,3 +1,20 @@ +### Use BOSWatch as service ### + +Old description below + +We assume that BOSWatch is installed to /opt/boswatch! Otherwise you need to adapt all the pathes in this description and in the service-file itself. + +#### Adapt the script +Enter the frequency and the decoder(s) you want to use in line 7; you can add more specific switches if you need to + +### Install the service +1. Copy the file to /lib/systemd/system: sudo cp /opt/boswatch/service/boswatch.service /lib/systemd/system/ +2. Change the rights: sudo chmod 644 /lib/systemd/system/boswatch.service +3. Enable the service: sudo systemcl enable boswatch.service +4. Start the service: sudo systemcl start boswatch.service + +--- + ### Start BOSWatch as a daemon ##### Changing the init script diff --git a/service/boswatch.service b/service/boswatch.service new file mode 100644 index 00000000..80c440b5 --- /dev/null +++ b/service/boswatch.service @@ -0,0 +1,11 @@ +[Unit] +Description=BOSWatch +After=multi-user.target + +[Service] +Type=simple +ExecStart=/usr/bin/python /opt/boswatch/boswatch.py -f 123.45M -a POC512 +Restart=on-abort + +[Install] +WantedBy=multi-user.target