2018-05-16 11:18:23 +02:00
|
|
|
#!/usr/bin/python
|
2018-01-15 14:18:15 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
"""!
|
|
|
|
|
____ ____ ______ __ __ __ _____
|
|
|
|
|
/ __ )/ __ \/ ___/ | / /___ _/ /______/ /_ |__ /
|
|
|
|
|
/ __ / / / /\__ \| | /| / / __ `/ __/ ___/ __ \ /_ <
|
|
|
|
|
/ /_/ / /_/ /___/ /| |/ |/ / /_/ / /_/ /__/ / / / ___/ /
|
|
|
|
|
/_____/\____//____/ |__/|__/\__,_/\__/\___/_/ /_/ /____/
|
|
|
|
|
German BOS Information Script
|
|
|
|
|
by Bastian Schroll
|
|
|
|
|
|
|
|
|
|
@file: wildcard.py
|
|
|
|
|
@date: 15.01.2018
|
|
|
|
|
@author: Bastian Schroll
|
2019-10-25 21:58:35 +02:00
|
|
|
@description: Functions to replace wildcards in stings
|
2018-01-15 14:18:15 +01:00
|
|
|
"""
|
|
|
|
|
import logging
|
2018-02-22 13:36:50 +01:00
|
|
|
import time
|
2018-01-15 14:18:15 +01:00
|
|
|
|
|
|
|
|
logging.debug("- %s loaded", __name__)
|
|
|
|
|
|
2019-10-26 18:35:31 +02:00
|
|
|
# todo check function - write an test
|
2019-10-25 21:58:35 +02:00
|
|
|
|
|
|
|
|
_additionalWildcards = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def registerWildcard(wildcard, bwPacketField):
|
2019-10-26 18:35:31 +02:00
|
|
|
"""!Register a new additional wildcard
|
|
|
|
|
|
|
|
|
|
@param wildcard: New wildcard string with format: '{WILDCARD}'
|
|
|
|
|
@param bwPacketField: Field of the bwPacket which is used for wildcard replacement"""
|
2019-10-25 21:58:35 +02:00
|
|
|
if wildcard in _additionalWildcards:
|
|
|
|
|
logging.error("wildcard always registered: %s", wildcard)
|
|
|
|
|
return
|
|
|
|
|
logging.debug("register new wildcard %s for field: %s", wildcard, bwPacketField)
|
|
|
|
|
_additionalWildcards[wildcard] = bwPacketField
|
2018-01-15 14:18:15 +01:00
|
|
|
|
|
|
|
|
|
2018-02-22 13:36:50 +01:00
|
|
|
def replaceWildcards(message, bwPacket):
|
2019-10-26 18:35:31 +02:00
|
|
|
"""!Replace the wildcards in a given message
|
|
|
|
|
|
|
|
|
|
@param message: Message in which wildcards should be replaced
|
|
|
|
|
@param bwPacket: bwPacket instance with the replacement information
|
|
|
|
|
@return Input message with the replaced wildcards"""
|
2018-02-01 14:41:09 +01:00
|
|
|
_wildcards = {
|
|
|
|
|
# formatting wildcards
|
2019-10-26 13:41:17 +02:00
|
|
|
# todo check if br and par are needed - if not also change config
|
2018-02-22 13:36:50 +01:00
|
|
|
"{BR}": "\r\n",
|
|
|
|
|
"{LPAR}": "(",
|
|
|
|
|
"{RPAR}": ")",
|
2019-10-26 10:18:55 +02:00
|
|
|
"{TIME}": time.strftime("%d.%m.%Y %H:%M:%S"),
|
2018-02-22 13:36:50 +01:00
|
|
|
|
|
|
|
|
# info wildcards
|
2019-03-02 09:15:40 +01:00
|
|
|
# server
|
2018-02-22 13:36:50 +01:00
|
|
|
"{SNAME}": bwPacket.getField("serverName"),
|
|
|
|
|
"{SVERS}": bwPacket.getField("serverVersion"),
|
|
|
|
|
"{SDATE}": bwPacket.getField("serverBuildDate"),
|
|
|
|
|
"{SBRCH}": bwPacket.getField("serverBranch"),
|
2019-09-20 13:06:15 +02:00
|
|
|
|
2019-03-02 09:15:40 +01:00
|
|
|
# client
|
2018-02-22 13:36:50 +01:00
|
|
|
"{CNAME}": bwPacket.getField("clientName"),
|
2018-05-16 11:18:23 +02:00
|
|
|
"{CIP}": bwPacket.getField("clientIP"),
|
2018-02-22 13:36:50 +01:00
|
|
|
"{CVERS}": bwPacket.getField("clientVersion"),
|
|
|
|
|
"{CDATE}": bwPacket.getField("clientBuildDate"),
|
|
|
|
|
"{CBRCH}": bwPacket.getField("clientBranch"),
|
2018-01-15 14:18:15 +01:00
|
|
|
|
2018-02-01 14:41:09 +01:00
|
|
|
# boswatch wildcards
|
2018-02-23 06:48:23 +01:00
|
|
|
"{INSRC}": bwPacket.getField("mode"),
|
|
|
|
|
"{TIMES}": bwPacket.getField("mode"),
|
2018-02-22 13:36:50 +01:00
|
|
|
"{FREQ}": bwPacket.getField("frequency"),
|
2018-02-23 06:48:23 +01:00
|
|
|
"{MODE}": bwPacket.getField("mode"),
|
2018-01-15 14:18:15 +01:00
|
|
|
|
2018-02-01 14:41:09 +01:00
|
|
|
# fms wildcards
|
2018-02-22 13:36:50 +01:00
|
|
|
"{FMS}": bwPacket.getField("fms"),
|
|
|
|
|
"{SERV}": bwPacket.getField("service"),
|
|
|
|
|
"{COUNT}": bwPacket.getField("country"),
|
|
|
|
|
"{LOC}": bwPacket.getField("location"),
|
|
|
|
|
"{VEHC}": bwPacket.getField("vehicle"),
|
|
|
|
|
"{STAT}": bwPacket.getField("status"),
|
|
|
|
|
"{DIR}": bwPacket.getField("direction"),
|
|
|
|
|
"{DIRT}": bwPacket.getField("dirextionText"),
|
|
|
|
|
"{TACI}": bwPacket.getField("tacticalInfo"),
|
|
|
|
|
|
2018-02-01 14:41:09 +01:00
|
|
|
# pocsag wildcards
|
2018-02-22 13:36:50 +01:00
|
|
|
"{BIT}": bwPacket.getField("bitrate"),
|
|
|
|
|
"{RIC}": bwPacket.getField("ric"),
|
|
|
|
|
"{SRIC}": bwPacket.getField("subric"),
|
|
|
|
|
"{SRICT}": bwPacket.getField("subricText"),
|
|
|
|
|
"{MSG}": bwPacket.getField("message"),
|
|
|
|
|
|
2018-02-01 14:41:09 +01:00
|
|
|
# zvei wildcards
|
2018-02-22 13:36:50 +01:00
|
|
|
"{TONE}": bwPacket.getField("tone"),
|
2018-02-01 14:41:09 +01:00
|
|
|
|
2018-02-22 13:36:50 +01:00
|
|
|
# message for MSG packet is done in poc
|
|
|
|
|
}
|
2019-10-25 21:58:35 +02:00
|
|
|
for wildcard, field in _wildcards.items():
|
|
|
|
|
message = message.replace(wildcard, field)
|
|
|
|
|
|
|
|
|
|
for wildcard, field in _additionalWildcards.items():
|
|
|
|
|
message = message.replace(wildcard, bwPacket.getField(field))
|
2018-02-01 14:41:09 +01:00
|
|
|
|
|
|
|
|
return message
|