Menu Changes
This commit is contained in:
136
e911_helper.py
136
e911_helper.py
@@ -21,18 +21,6 @@ except ImportError:
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class bcolors:
|
|
||||||
HEADER = "\033[95m"
|
|
||||||
OKBLUE = "\033[94m"
|
|
||||||
OKCYAN = "\033[96m"
|
|
||||||
OKGREEN = "\033[92m"
|
|
||||||
WARNING = "\033[93m"
|
|
||||||
FAIL = "\033[91m"
|
|
||||||
ENDC = "\033[0m"
|
|
||||||
BOLD = "\033[1m"
|
|
||||||
UNDERLINE = "\033[4m"
|
|
||||||
|
|
||||||
class Colors:
|
class Colors:
|
||||||
""" ANSI color codes """
|
""" ANSI color codes """
|
||||||
BLACK = "\033[0;30m"
|
BLACK = "\033[0;30m"
|
||||||
@@ -94,17 +82,6 @@ TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN NO EVENT SHALL VOICE1 OR I
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: Set to config file.
|
|
||||||
config_file = "config.json"
|
|
||||||
if os.path.isfile(config_file):
|
|
||||||
with open(config_file) as f:
|
|
||||||
config_data = json.load(f)
|
|
||||||
else:
|
|
||||||
logger.critical(f"Unable to load config.json. Aborting.")
|
|
||||||
sys.exit()
|
|
||||||
|
|
||||||
|
|
||||||
add_type_list = [
|
add_type_list = [
|
||||||
"",
|
"",
|
||||||
"Apartment",
|
"Apartment",
|
||||||
@@ -133,6 +110,36 @@ add_type_list = [
|
|||||||
"Upper",
|
"Upper",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def prompt_credentials(config):
|
||||||
|
"""Prompt for credentials"""
|
||||||
|
|
||||||
|
print(f"{Colors.LIGHT_GREEN}DO NOT SHARE YOUR CREDENTIALS WITH ANYONE.{Colors.END}")
|
||||||
|
|
||||||
|
config["username"] = input("Enter your api.switchvoxuc.com username: ")
|
||||||
|
config["password"] = getpass("Enter your api.switchvoxuc.com password: ")
|
||||||
|
config["provider_username"] = input("Enter your api.nwsip.com username: ")
|
||||||
|
config["provider_password"] = getpass("Enter your api.nwsip.com password: ")
|
||||||
|
|
||||||
|
print(f"{Colors.LIGHT_GREEN}Configure additoinal tenant credentials.{Colors.END}")
|
||||||
|
tenant = input("Enter your tenant name or enter for None: ") or None
|
||||||
|
if tenant is not None:
|
||||||
|
tenant = tenant.upper()
|
||||||
|
config["tenant"] = {tenant: {}}
|
||||||
|
config["tenant"][tenant]["username"] = input(
|
||||||
|
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.switchvoxuc.com username: "
|
||||||
|
)
|
||||||
|
config["tenant"][tenant]["password"] = getpass(
|
||||||
|
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.switchvoxuc.com password: "
|
||||||
|
)
|
||||||
|
config["tenant"][tenant]["provider_username"] = input(
|
||||||
|
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.nwsip.com username: "
|
||||||
|
)
|
||||||
|
config["tenant"][tenant]["provider_password"] = getpass(
|
||||||
|
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.nwsip.com password: "
|
||||||
|
)
|
||||||
|
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
def create_helpdeskticket(**kwargs):
|
def create_helpdeskticket(**kwargs):
|
||||||
"""Open helpdesk ticket w/ VOICE1"""
|
"""Open helpdesk ticket w/ VOICE1"""
|
||||||
@@ -161,6 +168,13 @@ def get_nth_key(dictionary, n=0):
|
|||||||
return key
|
return key
|
||||||
raise IndexError("dictionary index out of range")
|
raise IndexError("dictionary index out of range")
|
||||||
|
|
||||||
|
def build_config():
|
||||||
|
config = {}
|
||||||
|
regcode = input(f"Enter your 6 digit regcode: ") or None
|
||||||
|
e911_callrule_id = int(input(f"Enter the default 'call_rule_id' for dialing 911 to use: ")) or 6
|
||||||
|
priority = int(input(f"Enter the default 'position' to add caller_id_rules: ")) or 0
|
||||||
|
redirect_extension = int(input(f"Enter the default 'extension number' to redirect calls to: ")) or 7001
|
||||||
|
return [config]
|
||||||
|
|
||||||
def set_tenant(**kwargs):
|
def set_tenant(**kwargs):
|
||||||
global regcode
|
global regcode
|
||||||
@@ -171,6 +185,10 @@ def set_tenant(**kwargs):
|
|||||||
global nwsip_url
|
global nwsip_url
|
||||||
global nwsip_auth
|
global nwsip_auth
|
||||||
|
|
||||||
|
# Empty config.json so build one in memory.
|
||||||
|
if not config_data:
|
||||||
|
config_data = build_config()
|
||||||
|
|
||||||
# Get 1st REGCODE in config.
|
# Get 1st REGCODE in config.
|
||||||
for i, r in enumerate(config_data):
|
for i, r in enumerate(config_data):
|
||||||
print(f"{i}) {r['regcode']}")
|
print(f"{i}) {r['regcode']}")
|
||||||
@@ -221,8 +239,6 @@ def get_caller_id_rule(phone_number=None):
|
|||||||
|
|
||||||
|
|
||||||
# Create outbound caller id rule
|
# Create outbound caller id rule
|
||||||
|
|
||||||
|
|
||||||
def set_caller_id_rule(
|
def set_caller_id_rule(
|
||||||
caller_id_number,
|
caller_id_number,
|
||||||
caller_id_name,
|
caller_id_name,
|
||||||
@@ -278,8 +294,6 @@ def set_caller_id_rule(
|
|||||||
|
|
||||||
|
|
||||||
# Remove Outbound 911 Caller ID Rule
|
# Remove Outbound 911 Caller ID Rule
|
||||||
|
|
||||||
|
|
||||||
def remove_caller_id_rule(cid_rule_id=None):
|
def remove_caller_id_rule(cid_rule_id=None):
|
||||||
"""
|
"""
|
||||||
:param cid_rule_id: The outbound caller id rule to specifiy for removal.
|
:param cid_rule_id: The outbound caller id rule to specifiy for removal.
|
||||||
@@ -288,7 +302,6 @@ def remove_caller_id_rule(cid_rule_id=None):
|
|||||||
# !! Remove the caller id rule
|
# !! Remove the caller id rule
|
||||||
url = swvx_url + f"/caller_ids/remove/{cid_rule_id}"
|
url = swvx_url + f"/caller_ids/remove/{cid_rule_id}"
|
||||||
logger.critical(f"Removing outbound caller id: {url}")
|
logger.critical(f"Removing outbound caller id: {url}")
|
||||||
# logger.debug(json.dumps(d, indent=4))
|
|
||||||
params = {}
|
params = {}
|
||||||
r = requests.delete(url, auth=swvx_auth, params=params)
|
r = requests.delete(url, auth=swvx_auth, params=params)
|
||||||
if r.status_code != 201:
|
if r.status_code != 201:
|
||||||
@@ -297,8 +310,6 @@ def remove_caller_id_rule(cid_rule_id=None):
|
|||||||
|
|
||||||
|
|
||||||
# Get inbound route of number
|
# Get inbound route of number
|
||||||
|
|
||||||
|
|
||||||
def inbound_route_by_number(inbound_did):
|
def inbound_route_by_number(inbound_did):
|
||||||
try:
|
try:
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
@@ -312,10 +323,7 @@ def inbound_route_by_number(inbound_did):
|
|||||||
|
|
||||||
|
|
||||||
# Redirect Inbound DID to new destination
|
# Redirect Inbound DID to new destination
|
||||||
|
|
||||||
|
|
||||||
def redirect_did(inbound_did, dest_account_id, note="", priority=1, label="Available"):
|
def redirect_did(inbound_did, dest_account_id, note="", priority=1, label="Available"):
|
||||||
|
|
||||||
route = inbound_route_by_number(inbound_did=inbound_did)
|
route = inbound_route_by_number(inbound_did=inbound_did)
|
||||||
payload = {
|
payload = {
|
||||||
"name": label,
|
"name": label,
|
||||||
@@ -471,8 +479,6 @@ def add_e911_address(address, extension, auto_correct=True):
|
|||||||
|
|
||||||
|
|
||||||
# Get E911 id by number.
|
# Get E911 id by number.
|
||||||
|
|
||||||
|
|
||||||
def get_e911id_by_number(number, **kwargs):
|
def get_e911id_by_number(number, **kwargs):
|
||||||
"""Returns E911 address ID by phone number."""
|
"""Returns E911 address ID by phone number."""
|
||||||
result = None
|
result = None
|
||||||
@@ -847,13 +853,13 @@ def menu():
|
|||||||
print(
|
print(
|
||||||
f"You are performing the following actions on {regcode.upper()} Tenant: {tenant}"
|
f"You are performing the following actions on {regcode.upper()} Tenant: {tenant}"
|
||||||
)
|
)
|
||||||
action = input(
|
action = input(f"What action are you performing?\n\
|
||||||
f"What action are you performing?\n\---------- PBX Actions ------------------------\n\
|
{Colors.YELLOW}---------- PBX Actions ------------------------{Colors.END}\n\
|
||||||
T = Tenant Change \n\
|
T = Tenant Change \n\
|
||||||
M = Move (redirect) DID. (from PBX {regcode.upper()})\n\
|
M = Move (redirect) incoming DID. (from PBX {regcode.upper()})\n\
|
||||||
C = Caller ID (from PBX {regcode.upper()} )\n\
|
C = Set Outgoing Caller ID Name & Number (from PBX {regcode.upper()} )\n\
|
||||||
\n\
|
\n\
|
||||||
---------- SIP Provider actions ----------------\n\
|
{Colors.LIGHT_CYAN}---------- SIP Provider actions ----------------{Colors.END}\n\
|
||||||
N = New E911 Address (from provider)\n\
|
N = New E911 Address (from provider)\n\
|
||||||
U = Update existing E911 Address (from provider)\n\
|
U = Update existing E911 Address (from provider)\n\
|
||||||
R = Remove E911 record (from provider).\n\
|
R = Remove E911 record (from provider).\n\
|
||||||
@@ -861,8 +867,8 @@ def menu():
|
|||||||
RN = Release DID from account (from provider). \n\
|
RN = Release DID from account (from provider). \n\
|
||||||
Q = Quit.\n\
|
Q = Quit.\n\
|
||||||
\n\
|
\n\
|
||||||
---------- Comming soon -------------------------\n\
|
{Colors.NEGATIVE}---------- Comming soon -------------------------{Colors.END}\n\
|
||||||
---------- PBX Location/Hotdesking --------------\n\
|
{Colors.LIGHT_RED}---------- PBX Location/Hotdesking --------------{Colors.END}\n\
|
||||||
L = List/Set device E911 Location/Hotdesking.\n\
|
L = List/Set device E911 Location/Hotdesking.\n\
|
||||||
H = Enable/Disable phone Hotdesking.\n\
|
H = Enable/Disable phone Hotdesking.\n\
|
||||||
E = Create/Remove PBX extension.\n\
|
E = Create/Remove PBX extension.\n\
|
||||||
@@ -933,6 +939,13 @@ def menu():
|
|||||||
x_pos = config["911_callrule_id"]
|
x_pos = config["911_callrule_id"]
|
||||||
out_call_rule_id = config["out_call_rule_id"]
|
out_call_rule_id = config["out_call_rule_id"]
|
||||||
|
|
||||||
|
print(f"{Colors.LIGHT_RED}If you attempting to set an outgoing "
|
||||||
|
f"caller ID number for E911 use STOP! You should be using the newer "
|
||||||
|
f"'phone_locations' function in your Switchvox.{Colors.END}")
|
||||||
|
ack_new_911 = input(f"Are you setting an outgoing 911 number?: ") or 'y'
|
||||||
|
if ack_new_911.lower().startswith('y'):
|
||||||
|
print(f"Finish setting up your phone_location rules and hot-desking in your switchvox.")
|
||||||
|
return
|
||||||
outbound_did = (
|
outbound_did = (
|
||||||
input(f"Enter the outbound Caller ID Number [{outbound_did}]: ")
|
input(f"Enter the outbound Caller ID Number [{outbound_did}]: ")
|
||||||
or outbound_did
|
or outbound_did
|
||||||
@@ -1213,38 +1226,15 @@ def menu():
|
|||||||
get_e911_info(e911_id)
|
get_e911_info(e911_id)
|
||||||
|
|
||||||
|
|
||||||
def prompt_credentials(config):
|
|
||||||
"""Prompt for credentials"""
|
|
||||||
|
|
||||||
print(f"{Colors.LIGHT_GREEN}DO NOT SHARE YOUR CREDENTIALS WITH ANYONE.{Colors.END}")
|
|
||||||
|
|
||||||
config["username"] = input("Enter your api.switchvoxuc.com username: ")
|
|
||||||
config["password"] = getpass("Enter your api.switchvoxuc.com password: ")
|
|
||||||
config["provider_username"] = input("Enter your api.nwsip.com username: ")
|
|
||||||
config["provider_password"] = getpass("Enter your api.nwsip.com password: ")
|
|
||||||
|
|
||||||
print(f"{Colors.LIGHT_GREEN}Configure additoinal tenant credentials.{Colors.END}")
|
|
||||||
tenant = input("Enter your tenant name or enter for None: ") or None
|
|
||||||
if tenant is not None:
|
|
||||||
tenant = tenant.upper()
|
|
||||||
config["tenant"] = {tenant: {}}
|
|
||||||
config["tenant"][tenant]["username"] = input(
|
|
||||||
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.switchvoxuc.com username: "
|
|
||||||
)
|
|
||||||
config["tenant"][tenant]["password"] = getpass(
|
|
||||||
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.switchvoxuc.com password: "
|
|
||||||
)
|
|
||||||
config["tenant"][tenant]["provider_username"] = input(
|
|
||||||
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.nwsip.com username: "
|
|
||||||
)
|
|
||||||
config["tenant"][tenant]["provider_password"] = getpass(
|
|
||||||
f"Enter your {Colors.LIGHT_CYAN}{tenant}{Colors.END} api.nwsip.com password: "
|
|
||||||
)
|
|
||||||
|
|
||||||
return config
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
# TODO: Set to config file.
|
||||||
|
config_file = "config.json"
|
||||||
|
if os.path.isfile(config_file):
|
||||||
|
with open(config_file) as f:
|
||||||
|
config_data = json.load(f)
|
||||||
|
else:
|
||||||
|
logger.critical(f"Unable to load config.json. Aborting.")
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
config_data = [prompt_credentials(config_data[0])]
|
config_data = [prompt_credentials(config_data[0])]
|
||||||
|
|||||||
Reference in New Issue
Block a user