(20250218) mkj
This commit is contained in:
@@ -224,7 +224,16 @@ async def authorize_software_client(
|
|||||||
|
|
||||||
elif inbound_data.softwareClient == "mikrotikHotspot1000":
|
elif inbound_data.softwareClient == "mikrotikHotspot1000":
|
||||||
|
|
||||||
pass
|
# Make the client controller test and save the auth:
|
||||||
|
response = await current_app.mikrotik_hotspot_1000_controller.save_auth(
|
||||||
|
sql_conn = current_app.sql_writer,
|
||||||
|
mongo_data_conn = current_app.data_mongo,
|
||||||
|
mikrotik_auth = inbound_data.auth
|
||||||
|
)
|
||||||
|
|
||||||
|
# Note down the results:
|
||||||
|
success = response.success
|
||||||
|
message = f"Action Chain '{response.actionChain}': {response.message}"
|
||||||
|
|
||||||
# ┳┓
|
# ┳┓
|
||||||
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
|
# ┣┫┏┓┏┏┓┏┓┏┓┏┏┓
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ from controllers_v2.finstitutions.payments.safaricom_mpesa_express import Safari
|
|||||||
# ---
|
# ---
|
||||||
from controllers_v2.software.mikrotik.all_mikrotik import AllMikroTikController
|
from controllers_v2.software.mikrotik.all_mikrotik import AllMikroTikController
|
||||||
from controllers_v2.software.mikrotik.mikrotik_pppoe_1000 import MikroTikPPPoE1000Controller
|
from controllers_v2.software.mikrotik.mikrotik_pppoe_1000 import MikroTikPPPoE1000Controller
|
||||||
|
from controllers_v2.software.mikrotik.mikrotik_hostpot_1000 import MikroTikHotspot1000Controller
|
||||||
|
|
||||||
# To make REST API calls:
|
# To make REST API calls:
|
||||||
import httpx
|
import httpx
|
||||||
@@ -573,6 +574,12 @@ async def app_startup(**kwargs):
|
|||||||
alert_url = current_app.script_data["alerts"]["url"],
|
alert_url = current_app.script_data["alerts"]["url"],
|
||||||
debug = enable_debugging
|
debug = enable_debugging
|
||||||
)
|
)
|
||||||
|
current_app.mikrotik_hotspot_1000_controller = MikroTikHotspot1000Controller(
|
||||||
|
cache = current_app.module_cache,
|
||||||
|
http_client = current_app.http_client,
|
||||||
|
alert_url = current_app.script_data["alerts"]["url"],
|
||||||
|
debug = enable_debugging
|
||||||
|
)
|
||||||
current_app.printer("Software/MikroTik (C) ready.")
|
current_app.printer("Software/MikroTik (C) ready.")
|
||||||
|
|
||||||
# ┏┓ ┓ ┏┓┓•
|
# ┏┓ ┓ ┏┓┓•
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -298,7 +298,7 @@ class MikroTikHotspot1000Auth(BaseModel):
|
|||||||
frozen = True
|
frozen = True
|
||||||
)
|
)
|
||||||
|
|
||||||
vlanRange: str = Field(
|
vlanIds: List[int] = Field(
|
||||||
description = "Don't know, and don't want to know.",
|
description = "Don't know, and don't want to know.",
|
||||||
min_length = 1,
|
min_length = 1,
|
||||||
frozen = True
|
frozen = True
|
||||||
@@ -330,6 +330,27 @@ class MikroTikHotspot1000Auth(BaseModel):
|
|||||||
class Config:
|
class Config:
|
||||||
extra = "forbid"
|
extra = "forbid"
|
||||||
|
|
||||||
|
# ┏┓ •
|
||||||
|
# ┃┃┏┓┏┓┏┓┏┓┏┓╋┓┏┓┏
|
||||||
|
# ┣┛┛ ┗┛┣┛┗ ┛ ┗┗┗ ┛
|
||||||
|
# ┛
|
||||||
|
|
||||||
|
@property
|
||||||
|
def firstPrivateIp(self) -> str:
|
||||||
|
return self.privateIpPool.split("-")[0]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lastPrivateIp(self) -> str:
|
||||||
|
return self.privateIpPool.split("-")[1]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def firstPublicIp(self) -> str:
|
||||||
|
return self.publicIpPool.split("-")[0]
|
||||||
|
|
||||||
|
@property
|
||||||
|
def lastPublicIp(self) -> str:
|
||||||
|
return self.publicIpPool.split("-")[1]
|
||||||
|
|
||||||
# ┓┏ ┓• ┓ •
|
# ┓┏ ┓• ┓ •
|
||||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||||
@@ -339,6 +360,14 @@ class MikroTikHotspot1000Auth(BaseModel):
|
|||||||
if isinstance(value, (str, float)): value = int(value)
|
if isinstance(value, (str, float)): value = int(value)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@field_validator("privateIpPool", "publicIpPool", mode = "before")
|
||||||
|
def validate_ip_range(cls, value):
|
||||||
|
return ip.to_hyphen_notation(value)
|
||||||
|
|
||||||
|
@field_validator("vlanIds", mode = "before")
|
||||||
|
def validate_vlans(cls, value):
|
||||||
|
return parse_vlans(value)
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -1,202 +0,0 @@
|
|||||||
"""
|
|
||||||
|
|
||||||
AUTHOR:
|
|
||||||
|
|
||||||
Khushal P Soonderji
|
|
||||||
|
|
||||||
DATE:
|
|
||||||
|
|
||||||
Create: Saturday, 18th May, 2022
|
|
||||||
Update: Thursday, 22nd Aug. 2024
|
|
||||||
|
|
||||||
OBJECTIVE:
|
|
||||||
|
|
||||||
To provide an easy way to work with '.json' data and files.
|
|
||||||
|
|
||||||
REFERENCES:
|
|
||||||
|
|
||||||
1) https://www.w3schools.com/python/python_json.asp
|
|
||||||
|
|
||||||
DOWNLOADS:
|
|
||||||
|
|
||||||
N/A
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
# ***** ****
|
|
||||||
# *** IMPORT ***
|
|
||||||
# ***** ****
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
# To make sibling directories accessible for imports:
|
|
||||||
import sys
|
|
||||||
sys.path.append(".")
|
|
||||||
sys.path.append("..")
|
|
||||||
|
|
||||||
# System-level activities:
|
|
||||||
import io
|
|
||||||
|
|
||||||
# To work with the JSON standard:
|
|
||||||
import json
|
|
||||||
|
|
||||||
# To work with files:
|
|
||||||
from utils_v2.system import files
|
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
# ***** ****
|
|
||||||
# *** MACROS / ONE-TIME INIT ***
|
|
||||||
# ***** ****
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
# --- Nothing Yet
|
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
# ***** ****
|
|
||||||
# *** VARIABLES ***
|
|
||||||
# ***** ****
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
# --- Nothing Yet
|
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
# ***** ****
|
|
||||||
# *** FUNCTIONS ***
|
|
||||||
# ***** ****
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
def from_string(json_data):
|
|
||||||
|
|
||||||
"""
|
|
||||||
Decodes a JSON string to a pythonic variable like a dict.
|
|
||||||
:param json_data: The JSON string to decode.
|
|
||||||
:return: The decoded pythonic variable.
|
|
||||||
"""
|
|
||||||
|
|
||||||
python_data = json.loads(json_data)
|
|
||||||
return python_data
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def to_string(
|
|
||||||
python_data,
|
|
||||||
indent = 4,
|
|
||||||
default = None,
|
|
||||||
separators = None,
|
|
||||||
no_space = False
|
|
||||||
):
|
|
||||||
|
|
||||||
"""
|
|
||||||
Converts the given pythonic data to a JSON string.
|
|
||||||
:param python_data: The input data like a dict.
|
|
||||||
:param indent: The tab-width for pretty presentation.
|
|
||||||
:param default: The function to use on something that cannot be directly parsed into a JSON string.
|
|
||||||
:param separators: Custom separators to use.
|
|
||||||
:param no_space: If you want a dense JSON string that saves memory by not using spaces or tabs or line-breaks. Not
|
|
||||||
good for human readability, very good for saving memory. WARNING: THIS OVERRIDES EVERY OTHER PARAMETER EXCEPT
|
|
||||||
'default'.
|
|
||||||
:return: The JSON string representation of the input pythonic data.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if no_space:
|
|
||||||
json_data = json.dumps(
|
|
||||||
python_data,
|
|
||||||
default = default,
|
|
||||||
separators = (',', ':')
|
|
||||||
)
|
|
||||||
|
|
||||||
else:
|
|
||||||
json_data = json.dumps(
|
|
||||||
python_data,
|
|
||||||
indent = indent,
|
|
||||||
default = default,
|
|
||||||
separators = separators
|
|
||||||
)
|
|
||||||
|
|
||||||
return json_data
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def from_file(file):
|
|
||||||
|
|
||||||
"""
|
|
||||||
Reads a JSON file and returns it as a pythonic variable like a dict.
|
|
||||||
:param file: The path to the file on the disk or a file held in RAM as a BytesIO object.
|
|
||||||
:return: The decoded pythonic variable.
|
|
||||||
"""
|
|
||||||
|
|
||||||
if isinstance(file, io.BytesIO):
|
|
||||||
file.seek(0)
|
|
||||||
json_data = file.getvalue()
|
|
||||||
else: json_data = files.read_file(file)
|
|
||||||
python_data = from_string(json_data)
|
|
||||||
return python_data
|
|
||||||
|
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
def to_file(
|
|
||||||
file,
|
|
||||||
python_data,
|
|
||||||
indent = 4,
|
|
||||||
default = None,
|
|
||||||
separators = None,
|
|
||||||
no_space = False
|
|
||||||
):
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
:param file: Either a path to a file on disk, or a buffer in RAM in the form of a BytesIO object.
|
|
||||||
:param python_data: The pythonic data to be converted to the JSON string.
|
|
||||||
:param indent: The tab-width for pretty presentation.
|
|
||||||
:param default: The function to use on something that cannot be directly parsed into a JSON string.
|
|
||||||
:param separators: Custom separators to use.
|
|
||||||
:param no_space: If you want a dense JSON string that saves memory by not using spaces or tabs or line-breaks. Not
|
|
||||||
good for human readability, very good for saving memory. WARNING: THIS OVERRIDES EVERY OTHER PARAMETER EXCEPT
|
|
||||||
'default'.
|
|
||||||
:return: True/False if a path was given, else the same BytesIO object with the written JSON data.
|
|
||||||
"""
|
|
||||||
|
|
||||||
json_data = to_string(
|
|
||||||
python_data,
|
|
||||||
indent = indent,
|
|
||||||
default = default,
|
|
||||||
separators = separators,
|
|
||||||
no_space = no_space
|
|
||||||
)
|
|
||||||
|
|
||||||
if isinstance(file, io.BytesIO):
|
|
||||||
file.write(json_data.encode("utf-8"))
|
|
||||||
file.seek(0)
|
|
||||||
return file
|
|
||||||
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
files.write_file(file, json_data, mode = "w")
|
|
||||||
return True
|
|
||||||
except: return False
|
|
||||||
|
|
||||||
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
# ***** ****
|
|
||||||
# *** MAIN PROGRAM ***
|
|
||||||
# ***** ****
|
|
||||||
# *****************************************************************************************************************
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
|
|
||||||
pass
|
|
||||||
Reference in New Issue
Block a user