import json
import os
import sys
from colorama import Fore, Style
import configparser
default_json = {
"audio": {
"inputDevice": "hw:1,0",
"sampleRate": 44100,
"frequencyScaleFactor": 1,
"recordingScaleFactor": 2,
"silenceAmplitude": 0.05,
"channels": 1
},
"detection":
{
"minRecordingLengthSec": 30,
"maxRecordingLengthSec": 45,
"defaultMatchThreshold": 6,
"defaultTolerancePercent": 0.05,
"defaultResetTimeoutMs": 5000,
"defaultLockoutTimeoutMs": 7000,
"isRecordingEnabled": True,
"detectors": []
},
"coralogix": {
"applicationName": "FD-Tone-Notify",
"subsystemName": "Test"
},
"email": {
"from": "test@example.com",
"host": "smtp.sendgrid.net",
"port": 465,
"secure": True
}
}
default_detector = {
"name": "",
"tones": [],
"matchThreshold": 6,
"tolerancePercent": 0.02,
"resetTimeoutMs": 4000,
"isRecordingEnabled": True,
"lockoutTimeoutMs": 6000,
"minRecordingLengthSec": 45,
"maxRecordingLengthSec": 60,
"notifications": {
"preRecording": {
"pushbullet": [],
"webhooks": [],
"externalCommands": [],
"emails": []
},
"postRecording": {
"pushbullet": [],
"webhooks": [],
"externalCommands": [],
"emails": []
}
}
}
ttd_config_path = sys.argv[1]
if not ttd_config_path:
print(Fore.RED + "[X]" + Fore.YELLOW + " Please provide full link to tones.cfg." + Style.RESET_ALL)
sys.exit(0)
if not os.path.exists(ttd_config_path):
print(Fore.RED + "[X]" + Fore.YELLOW + " Can't find tones.cfg in that path." + Style.RESET_ALL)
sys.exit(0)
def convert_ttd(ttd_config_path):
parser = configparser.ConfigParser()
parser.read(ttd_config_path)
print(Fore.YELLOW + "[+] " + Fore.BLUE + "Converting...." + Style.RESET_ALL)
detectors = []
for tone in parser.sections():
new_detector = {
"name": parser[tone]["description"],
"tones": [float(parser[tone]["atone"]), float(parser[tone]["btone"])],
"matchThreshold": 6,
"tolerancePercent": 0.02,
"notifications": {
"preRecording": {
"pushbullet": [],
"webhooks": [],
"externalCommands": [],
"emails": []
},
"postRecording": {
"pushbullet": [],
"webhooks": [],
"externalCommands": [],
"emails": []
}
}
}
detectors.append(new_detector)
default_json["detection"]["detectors"] = detectors
with open('default.json', 'w+') as outfile:
json.dump(default_json, outfile, indent=4)
outfile.close()
print(Fore.GREEN + "[*] " + Fore.LIGHTGREEN_EX + " Conversion Complete default.json created in this directory.")
convert_ttd(ttd_config_path)