Files
cam-mitm/config.py

75 lines
1.8 KiB
Python
Raw Normal View History

"""Configuration management"""
import json
import os
DEFAULT_CONFIG = {
"camera_ip": "192.168.1.187",
"camera_mac": "14:92:f9:3e:58:0a",
"our_ip": "192.168.1.172",
"router_ip": "192.168.1.1",
"iface": "enP4p65s0",
"log_dir": os.path.expanduser("~/dumps/mitm_logs"),
"api_base": "https://portal.ubianet.com/api",
"api_email": "",
"api_password": "",
"api_token": "",
"device_uid": "",
"device_cam_user": "",
"device_cam_pwd": "",
"rest_port": 9090,
"fuzzer_threads": 5,
"fuzzer_delay": 0.2,
}
CONFIG_FILE = os.path.expanduser("~/setec_suite/cam-mitm/config.json")
class Config:
def __init__(self):
self._data = dict(DEFAULT_CONFIG)
self.load()
def __getitem__(self, key):
return self._data[key]
def __setitem__(self, key, value):
self._data[key] = value
def get(self, key, default=None):
return self._data.get(key, default)
def keys(self):
return self._data.keys()
def items(self):
return self._data.items()
def update(self, d):
self._data.update(d)
def load(self):
if os.path.exists(CONFIG_FILE):
try:
with open(CONFIG_FILE) as f:
self._data.update(json.load(f))
except:
pass
def save(self):
os.makedirs(os.path.dirname(CONFIG_FILE), exist_ok=True)
with open(CONFIG_FILE, "w") as f:
json.dump(self._data, f, indent=2)
def to_dict(self):
return dict(self._data)
def safe_dict(self):
"""Config dict with sensitive values masked"""
d = dict(self._data)
if d.get("api_password"):
d["api_password"] = "***"
if d.get("api_token"):
d["api_token"] = d["api_token"][:20] + "..."
return d