format files
This commit is contained in:
parent
106fbdcc7d
commit
a712b64798
3 changed files with 109 additions and 109 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -28,3 +28,5 @@ certs/*
|
||||||
!logs/README.md
|
!logs/README.md
|
||||||
!data/README.md
|
!data/README.md
|
||||||
!certs/README.md
|
!certs/README.md
|
||||||
|
|
||||||
|
venv/
|
||||||
|
|
@ -1,21 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
import asyncio
|
||||||
|
import importlib
|
||||||
|
import pkgutil
|
||||||
|
import socket
|
||||||
|
import sys
|
||||||
|
from logging.handlers import RotatingFileHandler
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from bumper.confserver import ConfServer
|
from bumper.confserver import ConfServer
|
||||||
|
from bumper.db import *
|
||||||
|
from bumper.models import *
|
||||||
from bumper.mqttserver import MQTTServer, MQTTHelperBot
|
from bumper.mqttserver import MQTTServer, MQTTHelperBot
|
||||||
from bumper.xmppserver import XMPPServer
|
from bumper.xmppserver import XMPPServer
|
||||||
from bumper.models import *
|
|
||||||
from bumper.db import *
|
|
||||||
import asyncio
|
|
||||||
import os
|
|
||||||
import logging
|
|
||||||
from logging.handlers import RotatingFileHandler
|
|
||||||
import socket
|
|
||||||
import sys
|
|
||||||
|
|
||||||
import importlib
|
|
||||||
import pkgutil
|
|
||||||
from pkgutil import extend_path
|
|
||||||
|
|
||||||
def strtobool(strbool):
|
def strtobool(strbool):
|
||||||
if str(strbool).lower() in ["true", "1", "t", "y", "on", "yes"]:
|
if str(strbool).lower() in ["true", "1", "t", "y", "on", "yes"]:
|
||||||
|
|
@ -39,8 +36,6 @@ os.makedirs(data_dir, exist_ok=True) # Ensure data directory exists or create
|
||||||
certs_dir = os.environ.get("BUMPER_CERTS") or os.path.join(bumper_dir, "certs")
|
certs_dir = os.environ.get("BUMPER_CERTS") or os.path.join(bumper_dir, "certs")
|
||||||
os.makedirs(certs_dir, exist_ok=True) # Ensure data directory exists or create
|
os.makedirs(certs_dir, exist_ok=True) # Ensure data directory exists or create
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Certs
|
# Certs
|
||||||
ca_cert = os.environ.get("BUMPER_CA") or os.path.join(certs_dir, "ca.crt")
|
ca_cert = os.environ.get("BUMPER_CA") or os.path.join(certs_dir, "ca.crt")
|
||||||
server_cert = os.environ.get("BUMPER_CERT") or os.path.join(certs_dir, "bumper.crt")
|
server_cert = os.environ.get("BUMPER_CERT") or os.path.join(certs_dir, "bumper.crt")
|
||||||
|
|
@ -51,7 +46,6 @@ bumper_listen = os.environ.get("BUMPER_LISTEN") or socket.gethostbyname(
|
||||||
socket.gethostname()
|
socket.gethostname()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
bumper_announce_ip = os.environ.get("BUMPER_ANNOUNCE_IP") or bumper_listen
|
bumper_announce_ip = os.environ.get("BUMPER_ANNOUNCE_IP") or bumper_listen
|
||||||
|
|
||||||
# Other
|
# Other
|
||||||
|
|
@ -186,7 +180,6 @@ else:
|
||||||
|
|
||||||
logging.getLogger("asyncio").setLevel(logging.CRITICAL + 1) # Ignore this logger
|
logging.getLogger("asyncio").setLevel(logging.CRITICAL + 1) # Ignore this logger
|
||||||
|
|
||||||
|
|
||||||
mqtt_listen_port = 8883
|
mqtt_listen_port = 8883
|
||||||
conf1_listen_port = 443
|
conf1_listen_port = 443
|
||||||
conf2_listen_port = 8007
|
conf2_listen_port = 8007
|
||||||
|
|
@ -194,7 +187,6 @@ xmpp_listen_port = 5223
|
||||||
|
|
||||||
|
|
||||||
async def start():
|
async def start():
|
||||||
|
|
||||||
try:
|
try:
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
except:
|
except:
|
||||||
|
|
@ -256,8 +248,10 @@ async def start():
|
||||||
|
|
||||||
# Start web servers
|
# Start web servers
|
||||||
conf_server.confserver_app()
|
conf_server.confserver_app()
|
||||||
asyncio.create_task(conf_server.start_site(conf_server.app, address=bumper_listen, port=conf1_listen_port, usessl=True))
|
asyncio.create_task(
|
||||||
asyncio.create_task(conf_server.start_site(conf_server.app, address=bumper_listen, port=conf2_listen_port, usessl=False))
|
conf_server.start_site(conf_server.app, address=bumper_listen, port=conf1_listen_port, usessl=True))
|
||||||
|
asyncio.create_task(
|
||||||
|
conf_server.start_site(conf_server.app, address=bumper_listen, port=conf2_listen_port, usessl=False))
|
||||||
|
|
||||||
# Start maintenance
|
# Start maintenance
|
||||||
while not shutting_down:
|
while not shutting_down:
|
||||||
|
|
@ -410,4 +404,3 @@ def main(argv=None):
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
asyncio.run(shutdown())
|
asyncio.run(shutdown())
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,27 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import logging
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
import json
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
import hbmqtt
|
import hbmqtt
|
||||||
|
import pkg_resources
|
||||||
from hbmqtt.broker import Broker
|
from hbmqtt.broker import Broker
|
||||||
from hbmqtt.client import MQTTClient
|
from hbmqtt.client import MQTTClient
|
||||||
from hbmqtt.mqtt.constants import QOS_0, QOS_1, QOS_2
|
from hbmqtt.mqtt.constants import QOS_0
|
||||||
import pkg_resources
|
|
||||||
import time
|
|
||||||
import bumper
|
|
||||||
import json
|
|
||||||
from datetime import datetime, timedelta
|
|
||||||
import bumper
|
|
||||||
from passlib.apps import custom_app_context as pwd_context
|
from passlib.apps import custom_app_context as pwd_context
|
||||||
|
|
||||||
|
import bumper
|
||||||
|
|
||||||
helperbotlog = logging.getLogger("helperbot")
|
helperbotlog = logging.getLogger("helperbot")
|
||||||
boterrorlog = logging.getLogger("boterror")
|
boterrorlog = logging.getLogger("boterror")
|
||||||
mqttserverlog = logging.getLogger("mqttserver")
|
mqttserverlog = logging.getLogger("mqttserver")
|
||||||
|
|
||||||
class MQTTHelperBot:
|
|
||||||
|
|
||||||
|
class MQTTHelperBot:
|
||||||
Client = None
|
Client = None
|
||||||
wait_resp_timeout_seconds = 60
|
wait_resp_timeout_seconds = 60
|
||||||
|
|
||||||
|
|
@ -253,7 +254,8 @@ class BumperMQTTServer_Plugin:
|
||||||
tmpbotdetail[1],
|
tmpbotdetail[1],
|
||||||
"eco-ng",
|
"eco-ng",
|
||||||
)
|
)
|
||||||
mqttserverlog.info(f"Bumper Authentication Success - Bot - SN: {username} - DID: {didsplit[0]} - Class: {tmpbotdetail[0]}")
|
mqttserverlog.info(
|
||||||
|
f"Bumper Authentication Success - Bot - SN: {username} - DID: {didsplit[0]} - Class: {tmpbotdetail[0]}")
|
||||||
authenticated = True
|
authenticated = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -274,7 +276,8 @@ class BumperMQTTServer_Plugin:
|
||||||
|
|
||||||
if auth:
|
if auth:
|
||||||
bumper.client_add(userid, realm, resource)
|
bumper.client_add(userid, realm, resource)
|
||||||
mqttserverlog.info(f"Bumper Authentication Success - Client - Username: {username} - ClientID: {client_id}")
|
mqttserverlog.info(
|
||||||
|
f"Bumper Authentication Success - Client - Username: {username} - ClientID: {client_id}")
|
||||||
authenticated = True
|
authenticated = True
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
@ -286,11 +289,13 @@ class BumperMQTTServer_Plugin:
|
||||||
if hash: # If there is a matching entry in passwd, check hash
|
if hash: # If there is a matching entry in passwd, check hash
|
||||||
authenticated = pwd_context.verify(password, hash)
|
authenticated = pwd_context.verify(password, hash)
|
||||||
if authenticated:
|
if authenticated:
|
||||||
mqttserverlog.info(f"File Authentication Success - Username: {username} - ClientID: {client_id}")
|
mqttserverlog.info(
|
||||||
|
f"File Authentication Success - Username: {username} - ClientID: {client_id}")
|
||||||
else:
|
else:
|
||||||
mqttserverlog.info(f"File Authentication Failed - Username: {username} - ClientID: {client_id}")
|
mqttserverlog.info(f"File Authentication Failed - Username: {username} - ClientID: {client_id}")
|
||||||
else:
|
else:
|
||||||
mqttserverlog.info(f"File Authentication Failed - No Entry for Username: {username} - ClientID: {client_id}")
|
mqttserverlog.info(
|
||||||
|
f"File Authentication Failed - No Entry for Username: {username} - ClientID: {client_id}")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
mqttserverlog.exception(
|
mqttserverlog.exception(
|
||||||
|
|
@ -304,7 +309,8 @@ class BumperMQTTServer_Plugin:
|
||||||
)
|
)
|
||||||
if allow_anonymous and not authenticated: # If anonymous auth is allowed and it isn't already authenticated
|
if allow_anonymous and not authenticated: # If anonymous auth is allowed and it isn't already authenticated
|
||||||
authenticated = True
|
authenticated = True
|
||||||
self.context.logger.debug(f"Anonymous Authentication Success: config allows anonymous - Username: {username}")
|
self.context.logger.debug(
|
||||||
|
f"Anonymous Authentication Success: config allows anonymous - Username: {username}")
|
||||||
mqttserverlog.info(f"Anonymous Authentication Success: config allows anonymous - Username: {username}")
|
mqttserverlog.info(f"Anonymous Authentication Success: config allows anonymous - Username: {username}")
|
||||||
|
|
||||||
return authenticated
|
return authenticated
|
||||||
|
|
@ -403,7 +409,6 @@ class BumperMQTTServer_Plugin:
|
||||||
)
|
)
|
||||||
bumper.mqtt_helperbot.command_responses.remove(msg)
|
bumper.mqtt_helperbot.command_responses.remove(msg)
|
||||||
|
|
||||||
|
|
||||||
async def on_broker_client_disconnected(self, client_id):
|
async def on_broker_client_disconnected(self, client_id):
|
||||||
|
|
||||||
didsplit = str(client_id).split("@")
|
didsplit = str(client_id).split("@")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue