# HBLink User Managment Server from flask import Flask, render_template_string, request, make_response, jsonify, render_template, Markup, flash, redirect, url_for, current_app from flask_sqlalchemy import SQLAlchemy from flask_user import login_required, UserManager, UserMixin, user_registered, roles_required from werkzeug.security import check_password_hash from flask_login import current_user, login_user, logout_user from wtforms import StringField, SubmitField import requests import base64, hashlib from dmr_utils3.utils import int_id, bytes_4 from config import * import ast import json import datetime, time from flask_babelex import Babel import libscrc import random from flask_mail import Message, Mail from socket import gethostbyname try: from gen_script_template import gen_script except: pass import os, ast ##import hb_config script_links = {} active_tgs = {} # Query radioid.net for list of IDs def get_ids(callsign): try: url = "https://www.radioid.net" response = requests.get(url+"/api/dmr/user/?callsign=" + callsign) result = response.json() ## print(result) # id_list = [] id_list = {} f_name = result['results'][0]['fname'] l_name = result['results'][0]['surname'] try: city = str(result['results'][0]['city'] + ', ' + result['results'][0]['state'] + ', ' + result['results'][0]['country']) except: city = result['results'][0]['country'] for i in result['results']: id_list[i['id']] = 0 return str([id_list, f_name, l_name, city]) except: return str([{}, '', '', '']) # Return string in NATO phonetics def convert_nato(string): d_nato = { 'A': 'ALPHA', 'B': 'BRAVO', 'C': 'CHARLIE', 'D': 'DELTA', 'E': 'ECHO', 'F': 'FOXTROT', 'G': 'GOLF', 'H': 'HOTEL', 'I': 'INDIA', 'J': 'JULIETT','K': 'KILO', 'L': 'LIMA', 'M': 'MIKE', 'N': 'NOVEMBER','O': 'OSCAR', 'P': 'PAPA', 'Q': 'QUEBEC', 'R': 'ROMEO', 'S': 'SIERRA', 'T': 'TANGO', 'U': 'UNIFORM', 'V': 'VICTOR', 'W': 'WHISKEY', 'X': 'X-RAY', 'Y': 'YANKEE', 'Z': 'ZULU', '0': 'zero(0)', '1': 'one(1)', '2': 'two(2)', '3': 'three(3)', '4': 'four(4)', '5': 'five(5)', '6': 'six(6)', '7': 'seven(7)', '8': 'eight(8)', '9': 'nine(9)', 'a': 'alpha', 'b': 'bravo', 'c': 'charlie', 'd': 'delta', 'e': 'echo', 'f': 'foxtrot', 'g': 'golf', 'h': 'hotel', 'i': 'india', 'j': 'juliett','k': 'kilo', 'l': 'lima', 'm': 'mike', 'n': 'november','o': 'oscar', 'p': 'papa', 'q': 'quebec', 'r': 'romeo', 's': 'sierra', 't': 'tango', 'u': 'uniform', 'v': 'victor', 'w': 'whiskey', 'x': 'x-ray', 'y': 'yankee', 'z': 'Zulu'} ns = '' for c in string: try: ns = ns + d_nato[c] + ' ' except: ns = ns + c + ' ' return ns # Class-based application configuration class ConfigClass(object): from config import MAIL_SERVER, MAIL_PORT, MAIL_USE_SSL, MAIL_USE_TLS, MAIL_USERNAME, MAIL_PASSWORD, MAIL_DEFAULT_SENDER, USER_ENABLE_EMAIL, USER_ENABLE_USERNAME, USER_REQUIRE_RETYPE_PASSWORD, USER_ENABLE_CHANGE_USERNAME, USER_ENABLE_MULTIPLE_EMAILS, USER_ENABLE_CONFIRM_EMAIL, USER_ENABLE_REGISTER, USER_AUTO_LOGIN_AFTER_CONFIRM, USER_SHOW_USERNAME_DOES_NOT_EXIST """ Flask application config """ # Flask settings SECRET_KEY = secret_key # Flask-SQLAlchemy settings SQLALCHEMY_DATABASE_URI = db_location # File-based SQL database SQLALCHEMY_TRACK_MODIFICATIONS = False # Avoids SQLAlchemy warning # Flask-User settings USER_APP_NAME = title # Shown in and email templates and page footers USER_EMAIL_SENDER_EMAIL = MAIL_DEFAULT_SENDER USER_EDIT_USER_PROFILE_TEMPLATE = 'flask_user/edit_user_profile.html' # Setup Flask-User def create_app(): """ Flask application factory """ # Create Flask app load app.config mail = Mail() app = Flask(__name__) app.config.from_object(__name__+'.ConfigClass') # Initialize Flask-BabelEx babel = Babel(app) # Initialize Flask-SQLAlchemy db = SQLAlchemy(app) # Define the User data-model. # NB: Make sure to add flask_user UserMixin !!! class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) active = db.Column('is_active', db.Boolean(), nullable=False, server_default='1') # User authentication information. The collation='NOCASE' is required # to search case insensitively when USER_IFIND_MODE is 'nocase_collation'. username = db.Column(db.String(100, collation='NOCASE'), nullable=False, unique=True) password = db.Column(db.String(255), nullable=False, server_default='') email_confirmed_at = db.Column(db.DateTime()) email = db.Column(db.String(255, collation='NOCASE'), nullable=False, unique=True) # User information first_name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') last_name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') dmr_ids = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') city = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') #Used for initial approval initial_admin_approved = db.Column('initial_admin_approved', db.Boolean(), nullable=False, server_default='1') # Define the relationship to Role via UserRoles roles = db.relationship('Role', secondary='user_roles') # Define the Role data-model class Role(db.Model): __tablename__ = 'roles' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(50), unique=True) # Define the UserRoles association table class UserRoles(db.Model): __tablename__ = 'user_roles' id = db.Column(db.Integer(), primary_key=True) user_id = db.Column(db.Integer(), db.ForeignKey('users.id', ondelete='CASCADE')) role_id = db.Column(db.Integer(), db.ForeignKey('roles.id', ondelete='CASCADE')) class BurnList(db.Model): __tablename__ = 'burn_list' dmr_id = db.Column(db.Integer(), unique=True, primary_key=True) version = db.Column(db.Integer(), primary_key=True) class AuthLog(db.Model): __tablename__ = 'auth_log' login_dmr_id = db.Column(db.Integer(), primary_key=True) login_time = db.Column(db.DateTime(), primary_key=True) peer_ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') server_name = db.Column(db.Integer(), primary_key=True) login_auth_method = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') portal_username = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') login_type = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') class mmdvmPeer(db.Model): __tablename__ = 'MMDVM_peers' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enabled = db.Column(db.Boolean(), nullable=False, server_default='1') loose = db.Column(db.Boolean(), nullable=False, server_default='1') ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='127.0.0.1') port = db.Column(db.Integer(), primary_key=False) master_ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') master_port = db.Column(db.Integer(), primary_key=False) passphrase = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') callsign = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') radio_id = db.Column(db.Integer(), primary_key=False) rx_freq = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tx_freq = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tx_power = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') color_code = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') latitude = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') longitude = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') height = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') location = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') description = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') slots = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') url = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') group_hangtime = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enable_unit = db.Column(db.Boolean(), nullable=False, server_default='1') options = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') use_acl = db.Column(db.Boolean(), nullable=False, server_default='0') sub_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg1_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg2_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') class xlxPeer(db.Model): __tablename__ = 'XLX_peers' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enabled = db.Column(db.Boolean(), nullable=False, server_default='1') loose = db.Column(db.Boolean(), nullable=False, server_default='1') ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='127.0.0.1') port = db.Column(db.Integer(), primary_key=False) master_ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') master_port = db.Column(db.Integer(), primary_key=False) passphrase = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') callsign = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') radio_id = db.Column(db.Integer(), primary_key=False) rx_freq = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tx_freq = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tx_power = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') color_code = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') latitude = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') longitude = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') height = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') location = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') description = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') slots = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') url = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') group_hangtime = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') xlxmodule = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') options = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enable_unit = db.Column(db.Boolean(), nullable=False, server_default='1') use_acl = db.Column(db.Boolean(), nullable=False, server_default='0') sub_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg1_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg2_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') class ServerList(db.Model): __tablename__ = 'server_list' name = db.Column(db.String(100, collation='NOCASE'), unique=True, primary_key=True) secret = db.Column(db.String(255), nullable=False, server_default='') ## public_list = db.Column(db.Boolean(), nullable=False, server_default='1') id = db.Column(db.Integer(), primary_key=False) ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') port = db.Column(db.Integer(), primary_key=False) global_path = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='./') global_ping_time = db.Column(db.Integer(), primary_key=False) global_max_missed = db.Column(db.Integer(), primary_key=False) global_use_acl = db.Column(db.Boolean(), nullable=False, server_default='1') global_reg_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='PERMIT:ALL') global_sub_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='DENY:1') global_tg1_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='PERMIT:ALL') global_tg2_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='PERMIT:ALL') ai_try_download = db.Column(db.Boolean(), nullable=False, server_default='1') ai_path = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='./') ai_peer_file = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='peer_ids.json') ai_subscriber_file = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='subscriber_ids.json') ai_tgid_file = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='talkgroup_ids.json') ai_peer_url = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='https://www.radioid.net/static/rptrs.json') ai_subs_url = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='https://www.radioid.net/static/users.json') ai_stale = db.Column(db.Integer(), primary_key=False, server_default='7') # Pull from config file for now ## um_append_int = db.Column(db.Integer(), primary_key=False, server_default='2') um_shorten_passphrase = db.Column(db.Boolean(), nullable=False, server_default='0') um_burn_file = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='./burned_ids.txt') # Pull from config file for now ## um_burn_int = db.Column(db.Integer(), primary_key=False, server_default='6') report_enable = db.Column(db.Boolean(), nullable=False, server_default='1') report_interval = db.Column(db.Integer(), primary_key=False, server_default='60') report_port = db.Column(db.Integer(), primary_key=False, server_default='4321') report_clients =db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='127.0.0.1') unit_time = db.Column(db.Integer(), primary_key=False, server_default='10080') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') class MasterList(db.Model): __tablename__ = 'master_list' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') static_positions = db.Column(db.Boolean(), nullable=False, server_default='0') repeat = db.Column(db.Boolean(), nullable=False, server_default='1') active = db.Column(db.Boolean(), nullable=False, server_default='1') max_peers = db.Column(db.Integer(), primary_key=False, server_default='10') ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') port = db.Column(db.Integer(), primary_key=False) enable_um = db.Column(db.Boolean(), nullable=False, server_default='1') passphrase = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') group_hang_time = db.Column(db.Integer(), primary_key=False, server_default='5') use_acl = db.Column(db.Boolean(), nullable=False, server_default='1') reg_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') sub_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg1_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg2_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enable_unit = db.Column(db.Boolean(), nullable=False, server_default='1') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') public_list = db.Column(db.Boolean(), nullable=False, server_default='1') class ProxyList(db.Model): __tablename__ = 'proxy_list' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') active = db.Column(db.Boolean(), nullable=False, server_default='1') static_positions = db.Column(db.Boolean(), nullable=False, server_default='0') repeat = db.Column(db.Boolean(), nullable=False, server_default='1') enable_um = db.Column(db.Boolean(), nullable=False, server_default='1') passphrase = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') external_proxy = db.Column(db.Boolean(), nullable=False, server_default='0') external_port = db.Column(db.Integer(), primary_key=False) group_hang_time = db.Column(db.Integer(), primary_key=False) internal_start_port = db.Column(db.Integer(), primary_key=False) internal_stop_port = db.Column(db.Integer(), primary_key=False) use_acl = db.Column(db.Boolean(), nullable=False, server_default='1') reg_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') sub_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg1_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg2_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enable_unit = db.Column(db.Boolean(), nullable=False, server_default='1') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') public_list = db.Column(db.Boolean(), nullable=False, server_default='1') class OBP(db.Model): __tablename__ = 'OpenBridge' id = db.Column(db.Integer(), primary_key=True) name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enabled = db.Column(db.Boolean(), nullable=False, server_default='1') network_id = db.Column(db.Integer(), primary_key=False) ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') port = db.Column(db.Integer(), primary_key=False) passphrase = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') target_ip = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') target_port = db.Column(db.Integer(), primary_key=False) both_slots = db.Column(db.Boolean(), nullable=False, server_default='1') use_acl = db.Column(db.Boolean(), nullable=False, server_default='1') sub_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') tg_acl = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') enable_unit = db.Column(db.Boolean(), nullable=False, server_default='1') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') class BridgeRules(db.Model): __tablename__ = 'bridge_rules' id = db.Column(db.Integer(), primary_key=True) bridge_name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') system_name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') ts = db.Column(db.Integer(), primary_key=False) tg = db.Column(db.Integer(), primary_key=False) active = db.Column(db.Boolean(), nullable=False, server_default='1') timeout = db.Column(db.Integer(), primary_key=False) to_type = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') on = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') off = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') reset = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') public_list = db.Column(db.Boolean(), nullable=False, server_default='0') proxy = db.Column(db.Boolean(), nullable=False, server_default='0') class BridgeList(db.Model): __tablename__ = 'bridge_list' id = db.Column(db.Integer(), primary_key=True) bridge_name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') description = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') public_list = db.Column(db.Boolean(), nullable=False, server_default='0') tg = db.Column(db.Integer(), primary_key=False) # Customize Flask-User class CustomUserManager(UserManager): # Override or extend the default login view method def login_view(self): """Prepare and process the login form.""" # Authenticate username/email and login authenticated users. safe_next_url = self._get_safe_next_url('next', self.USER_AFTER_LOGIN_ENDPOINT) safe_reg_next = self._get_safe_next_url('reg_next', self.USER_AFTER_REGISTER_ENDPOINT) # Immediately redirect already logged in users if self.call_or_get(current_user.is_authenticated) and self.USER_AUTO_LOGIN_AT_LOGIN: return redirect(safe_next_url) # Initialize form login_form = self.LoginFormClass(request.form) # for login.html register_form = self.RegisterFormClass() # for login_or_register.html if request.method != 'POST': login_form.next.data = register_form.next.data = safe_next_url login_form.reg_next.data = register_form.reg_next.data = safe_reg_next # Process valid POST if request.method == 'POST' and login_form.validate(): # Retrieve User user = None user_email = None if self.USER_ENABLE_USERNAME: # Find user record by username user = self.db_manager.find_user_by_username(login_form.username.data) # Find user record by email (with form.username) if not user and self.USER_ENABLE_EMAIL: user, user_email = self.db_manager.get_user_and_user_email_by_email(login_form.username.data) else: # Find user by email (with form.email) user, user_email = self.db_manager.get_user_and_user_email_by_email(login_form.email.data) #Add aditional message if not user.initial_admin_approved: flash('You account is waiting for approval from an administrator. See the Help page for more information. You will receive an email when your account is approved.', 'success') if user: # Log user in safe_next_url = self.make_safe_url(login_form.next.data) return self._do_login_user(user, safe_next_url, login_form.remember_me.data) # Render form self.prepare_domain_translations() template_filename = self.USER_LOGIN_AUTH0_TEMPLATE if self.USER_ENABLE_AUTH0 else self.USER_LOGIN_TEMPLATE return render_template(template_filename, form=login_form, login_form=login_form, register_form=register_form) #user_manager = UserManager(app, db, User) user_manager = CustomUserManager(app, db, User) # Create all database tables db.create_all() if not User.query.filter(User.username == 'admin').first(): user = User( username='admin', email='admin@no.reply', email_confirmed_at=datetime.datetime.utcnow(), password=user_manager.hash_password('admin'), initial_admin_approved = True, notes='Default admin account created during installation.', dmr_ids='{}' ) user.roles.append(Role(name='Admin')) user.roles.append(Role(name='User')) db.session.add(user) db.session.commit() # Query radioid.net for list of DMR IDs, then add to DB @user_registered.connect_via(app) def _after_user_registered_hook(sender, user, **extra): edit_user = User.query.filter(User.username == user.username).first() radioid_data = ast.literal_eval(get_ids(user.username)) edit_user.dmr_ids = str(radioid_data[0]) edit_user.first_name = str(radioid_data[1]) edit_user.last_name = str(radioid_data[2]) edit_user.city = str(radioid_data[3]) user_role = UserRoles( user_id=edit_user.id, role_id=2, ) db.session.add(user_role) if default_account_state == False: edit_user.active = default_account_state edit_user.initial_admin_approved = False db.session.commit() def gen_passphrase(dmr_id): _new_peer_id = bytes_4(int(str(dmr_id)[:7])) trimmed_id = int(str(dmr_id)[:7]) b_list = get_burnlist() # print(b_list) burned = False for ui in b_list.items(): # print(ui) #print(b_list) if ui[0] == trimmed_id: if ui[0] != 0: calc_passphrase = hashlib.sha256(str(extra_1).encode() + str(extra_int_1).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + b_list[trimmed_id].to_bytes(2, 'big') + burn_int.to_bytes(2, 'big') + append_int.to_bytes(2, 'big'))))[2:].zfill(8))) + hashlib.sha256(str(extra_2).encode() + str(extra_int_2).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] burned = True if burned == False: calc_passphrase = hashlib.sha256(str(extra_1).encode() + str(extra_int_1).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] + base64.b64encode(bytes.fromhex(str(hex(libscrc.ccitt((_new_peer_id) + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + append_int.to_bytes(2, 'big'))))[2:].zfill(8)))))[2:].zfill(4)) + (_new_peer_id) + append_int.to_bytes(2, 'big') + bytes.fromhex(str(hex(libscrc.posix((_new_peer_id) + append_int.to_bytes(2, 'big'))))[2:].zfill(8))) + hashlib.sha256(str(extra_2).encode() + str(extra_int_2).encode() + str(_new_peer_id).encode()[-3:]).hexdigest().upper().encode()[::14] if use_short_passphrase == True: trim_pass = str(calc_passphrase)[2:-1] new_pass = trim_pass[::int(shorten_sample)][-int(shorten_length):] return str(new_pass) elif use_short_passphrase ==False: return str(calc_passphrase)[2:-1] def update_from_radioid(callsign): edit_user = User.query.filter(User.username == callsign).first() #edit_user.dmr_ids = str(ast.literal_eval(get_ids(callsign))[0]) radioid_dict = ast.literal_eval(get_ids(callsign))[0] db_id_dict = ast.literal_eval(edit_user.dmr_ids) new_id_dict = db_id_dict.copy() for i in radioid_dict.items(): if i[0] in db_id_dict: pass elif i[0] not in db_id_dict: new_id_dict[i[0]] = 0 edit_user.dmr_ids = str(new_id_dict) edit_user.first_name = str(ast.literal_eval(get_ids(callsign))[1]) edit_user.last_name = str(ast.literal_eval(get_ids(callsign))[2]) edit_user.city = str(ast.literal_eval(get_ids(callsign))[3]) db.session.commit() # The Home page is accessible to anyone @app.route('/') def home_page(): #content = Markup('Index') return render_template('index.html') #, markup_content = content) @app.route('/help') def help_page(): #content = Markup('Index') return render_template('help.html') @app.route('/generate_passphrase/pi-star', methods = ['GET']) @login_required def gen_pi_star(): try: u = current_user ## print(u.username) id_dict = ast.literal_eval(u.dmr_ids) #u = User.query.filter_by(username=user).first() ## print(user_id) ## print(request.args.get('mode')) ## if request.args.get('mode') == 'generated': content = '''
Pi-Star Instructions
1: Log into your Pi-Star device. rpi-rw
sudo su - Note: Link can be used only once. To run the script again, simply reload the page and paste a new command into the command line. ''' for i in id_dict.items(): #if i[1] == '': link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8) script_links[i[0]] = link_num content = content + '''\nDMR ID: ''' + str(i[0]) + ''':
''' #else: # content = content + '''\n Error ''' content = content + '''\n |
''' except: content = Markup('No DMR IDs found or other error.') #return str(content) return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/generate_passphrase', methods = ['GET']) @login_required def gen(): #print(str(gen_passphrase(3153591))) #(int(i[0]))) ## try: #content = Markup('The HTML String') #user_id = request.args.get('user_id') u = current_user ## print(u.username) id_dict = ast.literal_eval(u.dmr_ids) #u = User.query.filter_by(username=user).first() ## print(user_id) ## print(request.args.get('mode')) ## if request.args.get('mode') == 'generated': #print(id_dict) content = '\n' for i in id_dict.items(): if isinstance(i[1], int) == True and i[1] != 0: link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8) script_links[i[0]] = link_num #print(script_links) content = content + '''\n
Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + str(gen_passphrase(int(i[0]))) + ''' Phonetically spelled: ''' + convert_nato(str(gen_passphrase(int(i[0])))) + ''' |
''' elif i[1] == 0: link_num = str(random.randint(1,99999999)).zfill(8) + str(time.time()) + str(random.randint(1,99999999)).zfill(8) script_links[i[0]] = link_num #print(script_links) content = content + '''\n
Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + str(gen_passphrase(int(i[0]))) + ''' Phonetically spelled: ''' + convert_nato(str(gen_passphrase(int(i[0])))) + ''' |
''' elif i[1] == '': content = content + '''
Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + legacy_passphrase + ''' Phonetically spelled: ''' + convert_nato(legacy_passphrase) + ''' |
''' else: content = content + '''
Your passphrase for ''' + str(i[0]) + ''': Copy and paste: ''' + str(i[1]) + ''' Phonetically spelled: ''' + convert_nato(str(i[1])) + ''' |
''' #content = content + '\n\n' + str(script_links[i[0]]) ## except: ## content = Markup('No DMR IDs found or other error.') #return str(content) return render_template('view_passphrase.html', markup_content = Markup(content)) ## # The Members page is only accessible to authenticated users via the @login_required decorator ## @app.route('/members') ## @login_required # User must be authenticated ## def member_page(): ## content = 'Mem only' ## return render_template('flask_user_layout.html', markup_content = content) @app.route('/update_ids', methods=['POST', 'GET']) @login_required # User must be authenticated def update_info(): #print(request.args.get('callsign')) #print(current_user.username) if request.args.get('callsign') == current_user.username or request.args.get('callsign') and request.args.get('callsign') != current_user.username and current_user.has_roles('Admin'): content = '
Use this page to sync changes from RadioID.net with this system (such as a new DMR ID, name change, etc.).
Updating your information from RadioID.net will overwrite any custom authentication passphrases, your city, and name in the database. Are you sure you want to continue?
''' elif request.method == 'POST': # and request.form.get('callsign') and request.form.get('subject') and request.form.get('message'): u = User.query.filter_by(username=request.args.get('callsign')).first() msg = Message(recipients=[u.email], subject=request.form.get('subject'), body=request.form.get('message')) mail.send(msg) content = '
Sent email to: ' + u.email + '
' else: content = '''Find user in "List Users", then click on the email link.'
''' return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/list_users') @roles_required('Admin') @login_required # User must be authenticated def list_users(): u = User.query.all() # Broken for now, link taken out -u_list = '''
Callsign | Name | Enabled | DMR ID:Authentication | Notes |
''' + str(i.username) + ''' | ''' + str(i.first_name) + ' ' + str(i.last_name) + ''' | ''' + str(i.active) + ''' | ''' + str(i.dmr_ids) + ''' | ''' + str(i.notes) + ''' |
''' return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/approve_users', methods=['POST', 'GET']) @login_required @roles_required('Admin') # Use of @roles_required decorator def approve_list(): u = User.query.all() wait_list = '''
Callsign | Name | Enabled | DMR ID:Authentication |
''' + str(i.username) + ''' | ''' + str(i.first_name) + ' ' + str(i.last_name) + ''' | ''' + str(i.active) + ''' | ''' + str(i.dmr_ids) + ''' |
''' return render_template('flask_user_layout.html', markup_content = Markup(content)) # The Admin page requires an 'Admin' role. @app.route('/edit_user', methods=['POST', 'GET']) @login_required @roles_required('Admin') # Use of @roles_required decorator def admin_page(): #print(request.args.get('callsign')) #print(request.args.get('callsign')) ## if request.method == 'POST' and request.form.get('callsign'): ## #result = request.json ## callsign = request.form.get('callsign') ## u = User.query.filter_by(username=callsign).first() ## content = u.dmr_ids if request.method == 'POST' and request.args.get('callsign') == None: content = 'Not found' elif request.method == 'POST' and request.args.get('callsign') and request.form.get('user_status'): user = request.args.get('callsign') #print(user) edit_user = User.query.filter(User.username == user).first() content = '' if request.form.get('user_status') != edit_user.active: if request.form.get('user_status') == "True": edit_user.active = True content = content + '''
User ''' + str(user) + ''' has been enabled.
\n''' if request.form.get('user_status') == "False": edit_user.active = False content = content + '''User ''' + str(user) + ''' has been disabled.
\n''' ## print(request.form.get('username')) if user != request.form.get('username'): #### #print(edit_user.username) content = content + '''User ''' + str(user) + ''' changed to ''' + request.form.get('username') + '''.
\n''' edit_user.username = request.form.get('username') if request.form.get('email') != edit_user.email: edit_user.email = request.form.get('email') content = content + '''Changed email for user: ''' + str(user) + ''' to ''' + request.form.get('email') + '''
\n''' if request.form.get('notes') != edit_user.notes: edit_user.notes = request.form.get('notes') content = content + '''Changed notes for user: ''' + str(user) + '''.
\n''' if request.form.get('password') != '': edit_user.password = user_manager.hash_password(request.form.get('password')) content = content + '''Changed password for user: ''' + str(user) + '''
\n''' if request.form.get('dmr_ids') != edit_user.dmr_ids: edit_user.dmr_ids = request.form.get('dmr_ids') dmr_auth_dict = ast.literal_eval(request.form.get('dmr_ids')) for id_user in dmr_auth_dict: if isinstance(dmr_auth_dict[id_user], int) == True and dmr_auth_dict[id_user] != 0: #print('burn it') if id_user in get_burnlist(): ## print('burned') if get_burnlist()[id_user] != dmr_auth_dict[id_user]: ## print('update vers') update_burnlist(id_user, dmr_auth_dict[id_user]) else: pass ## print('no update') else: add_burnlist(id_user, dmr_auth_dict[id_user]) ## print('not in list, adding') elif isinstance(dmr_auth_dict[id_user], int) == False and id_user in get_burnlist(): delete_burnlist(id_user) ## print('remove from burn list - string') elif dmr_auth_dict[id_user] == 0: ## print('remove from burn list') if id_user in get_burnlist(): delete_burnlist(id_user) content = content + '''Changed authentication settings for user: ''' + str(user) + '''
\n''' db.session.commit() #edit_user = User.query.filter(User.username == request.args.get('callsign')).first() elif request.method == 'GET' and request.args.get('callsign') and request.args.get('delete_user') == 'true': delete_user = User.query.filter(User.username == request.args.get('callsign')).first() db.session.delete(delete_user) db.session.commit() content = '''Deleted user: ''' + str(delete_user.username) + '''
\n''' elif request.method == 'GET' and request.args.get('callsign') and request.args.get('make_user_admin') == 'true': u = User.query.filter_by(username=request.args.get('callsign')).first() u_role = UserRoles.query.filter_by(user_id=u.id).first() u_role.role_id = 1 db.session.commit() content = '''User now Admin: ''' + str(request.args.get('callsign')) + '''
\n''' elif request.method == 'GET' and request.args.get('callsign') and request.args.get('make_user_admin') == 'false': u = User.query.filter_by(username=request.args.get('callsign')).first() u_role = UserRoles.query.filter_by(user_id=u.id).first() u_role.role_id = 2 db.session.commit() content = '''Admin now a user: ''' + str(request.args.get('callsign') ) + '''
\n''' elif request.method == 'GET' and request.args.get('callsign') and request.args.get('admin_approve') == 'true': edit_user = User.query.filter(User.username == request.args.get('callsign')).first() edit_user.active = True edit_user.initial_admin_approved = True db.session.commit() msg = Message(recipients=[edit_user.email], subject='Account Approval - ' + title, body='''You are receiving this message because an administrator has approved your account. You may now login and view your MMDVM passphrase(s).''') mail.send(msg) content = '''User approved: ''' + str(request.args.get('callsign')) + '''
\n''' elif request.method == 'GET' and request.args.get('callsign') and request.args.get('email_verified') == 'true': edit_user = User.query.filter(User.username == request.args.get('callsign')).first() edit_user.email_confirmed_at = datetime.datetime.utcnow() db.session.commit() content = '''Email verified for: ''' + str(request.args.get('callsign')) + '''
\n''' elif request.method == 'POST' and request.form.get('callsign') and not request.form.get('user_status') or request.method == 'GET' and request.args.get('callsign'):# and request.form.get('user_status') : if request.args.get('callsign'): callsign = request.args.get('callsign') if request.form.get('callsign'): callsign = request.form.get('callsign') u = User.query.filter_by(username=callsign).first() confirm_link = '' if u.email_confirmed_at == None: confirm_link = '''Verify email - ''' + str(u.username) + '''
\n''' u_role = UserRoles.query.filter_by(user_id=u.id).first() if u_role.role_id == 2: # Link to promote to Admin role_link = '''Give Admin role: ''' + str(u.username) + '''
\n''' if u_role.role_id == 1: # Link to promote to User role_link = '''Revert to User role: ''' + str(u.username) + '''
\n''' id_dict = ast.literal_eval(u.dmr_ids) passphrase_list = '''DMR ID | Passphrase |
''' + str(i[0]) + ''' | ''' + str(gen_passphrase(int(i[0]))) + ''' |
''' + str(i[0]) + ''' | ''' + legacy_passphrase + ''' |
''' + str(i[0]) + ''' | ''' + str(i[1]) + ''' |
First Name | Last Name |
''' + u.first_name + ''' | ''' + u.last_name + ''' |
City | ''' + u.city + ''' |
''' + passphrase_list + '''
''' + confirm_link + ''' Email confirmed: ''' + str(u.email_confirmed_at) + ''' |
|
''' + role_link + ''' | |
Calculated | Legacy (config) | Custom |
0 - default, 1-999 - new calculation |
'' | 'passphrase' |
{DMR ID: Method, 2nd DMR ID: Method}
Example:
{1234567: '', 134568: 0, 1234569: 'passphr8s3'}
''' return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/get_script') def get_script(): dmr_id = int(request.args.get('dmr_id')) number = float(request.args.get('number')) #print(type(script_links[dmr_id])) u = User.query.filter(User.dmr_ids.contains(request.args.get('dmr_id'))).first() #print(u.dmr_ids) if authorized_peer(dmr_id)[1] == 0: passphrase = gen_passphrase(dmr_id) elif authorized_peer(dmr_id)[1] != 0 and isinstance(authorized_peer(dmr_id)[1], int) == True: passphrase = gen_passphrase(dmr_id) elif authorized_peer(dmr_id)[1] == '': passphrase = legacy_passphrase print(passphrase) elif authorized_peer(dmr_id)[1] != '' or authorized_peer(dmr_id)[1] != 0: passphrase = authorized_peer(dmr_id)[1] #try: if dmr_id in script_links and number == float(script_links[dmr_id]): script_links.pop(dmr_id) return str(gen_script(dmr_id, passphrase)) #except: #else: #content = 'Link used or other error.' #return content #return render_template('flask_user_layout.html', markup_content = content, logo = logo) def authorized_peer(peer_id): try: u = User.query.filter(User.dmr_ids.contains(str(peer_id))).first() login_passphrase = ast.literal_eval(u.dmr_ids) return [u.is_active, login_passphrase[peer_id], str(u.username)] except: return [False] @app.route('/auth_log', methods=['POST', 'GET']) @login_required # User must be authenticated @roles_required('Admin') def all_auth_list(): if request.args.get('flush_db') == 'true': content = '''
Flushed entire auth DB.
\n''' authlog_flush() elif request.args.get('flush_user_db') == 'true' and request.args.get('portal_username'): content = '''Flushed auth DB for: ''' + request.args.get('portal_username') + '''
\n''' authlog_flush_user(request.args.get('portal_username')) elif request.args.get('flush_db_mmdvm') == 'true' and request.args.get('mmdvm_server'): content = '''Flushed auth DB for: ''' + request.args.get('mmdvm_server') + '''
\n''' authlog_flush_mmdvm_server(request.args.get('mmdvm_server')) elif request.args.get('flush_db_ip') == 'true' and request.args.get('peer_ip'): content = '''Flushed auth DB for: ''' + request.args.get('peer_ip') + '''
\n''' authlog_flush_ip(request.args.get('peer_ip')) elif request.args.get('flush_dmr_id_db') == 'true' and request.args.get('dmr_id'): content = '''Flushed auth DB for: ''' + request.args.get('dmr_id') + '''
\n''' authlog_flush_dmr_id(request.args.get('dmr_id')) elif request.args.get('portal_username') and not request.args.get('flush_user_db') and not request.args.get('flush_dmr_id_db') or request.args.get('dmr_id') and not request.args.get('flush_user_db') and not request.args.get('flush_dmr_id_db'): if request.args.get('portal_username'): ## s_filter = portal_username=request.args.get('portal_username') a = AuthLog.query.filter_by(portal_username=request.args.get('portal_username')).order_by(AuthLog.login_time.desc()).all() g_arg = request.args.get('portal_username') f_link = '''Flush auth log for: ''' + request.args.get('portal_username') + '''
''' elif request.args.get('dmr_id'): ## s_filter = login_dmr_id=request.args.get('dmr_id') a = AuthLog.query.filter_by(login_dmr_id=request.args.get('dmr_id')).order_by(AuthLog.login_time.desc()).all() g_arg = request.args.get('dmr_id') f_link = '''Flush auth log for: ''' + request.args.get('dmr_id') + '''
''' ## print(s_filter) ## a = AuthLog.query.filter_by(s_filter).order_by(AuthLog.login_dmr_id.desc()).all() content = '''
Log for: ''' + g_arg + '''
''' + f_link + '''
DMR ID |
Portal Username |
Login IP |
Passphrase |
Server |
Time (UTC) |
Login Status |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
Flush authentication log for server: ''' + request.args.get('mmdvm_server') + '''
Log for MMDVM server: ''' + request.args.get('mmdvm_server') + '''
DMR ID |
Portal Username |
Login IP |
Passphrase |
Server |
Time (UTC) |
Login Status |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + i.server_name + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + i.server_name + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + i.server_name + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
Flush authentication log for IP: ''' + request.args.get('peer_ip') + '''
Log for IP address: ''' + request.args.get('peer_ip') + '''
DMR ID |
Portal Username |
Login IP |
Passphrase |
Server |
Time (UTC) |
Login Status |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + i.peer_ip + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + i.peer_ip + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + i.peer_ip + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
Flush entire authentication log
Un-registered authentication attempts
Authentication log by DMR ID
DMR ID |
Portal Username |
Login IP |
Passphrase |
Server |
Time (UTC) |
Last Login Status |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
''' + str(i.login_dmr_id) + ''' | ''' + i.portal_username + ''' | ''' + str(i.peer_ip) + ''' | ''' + i.login_auth_method + ''' | ''' + str(i.server_name) + ''' | ''' + str(i.login_time) + ''' | ''' + str(i.login_type) + ''' |
Currently active talkgroups. Updated every 2 minutes.
' for s in sl: for i in user_ids.items(): for ts in active_tgs.items(): for x in ts[1]: print(x) print(s.name) ## print(active_tgs[s.name]) ## print(str(active_tgs[ts[1]])) # Remove 0 from TG list try: active_tgs[s.name][x][0]['1'].remove(0) active_tgs[s.name][x][1]['2'].remove(0) except: pass ## try: content = content + '''
Server: ''' + str(s.name) + '''DMR ID: ''' + str(i[0]) + ''' |
||||
|
Redirecting in 3 seconds.
''' else: server_add(request.form.get('server_name'), request.form.get('server_secret'), request.form.get('server_ip'), _port, request.form.get('global_path'), _global_ping_time, _global_max_missed, _global_use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('global_ts1_acl'), request.form.get('global_ts2_acl'), request.form.get('sub_file'), _ai_try_download, request.form.get('aliases_path'), request.form.get('peer_file'), request.form.get('tgid_file'), request.form.get('peer_url'), request.form.get('sub_url'), _ai_stale, _um_shorten_passphrase, request.form.get('um_burn_file'), _report_enabled, _report_interval, _report_port, request.form.get('report_clients'), request.form.get('unit_time'), request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' if request.args.get('save_mode') == 'edit': ## print(request.args.get('server')) server_edit(request.args.get('server'), request.form.get('server_secret'), request.form.get('server_ip'), _port, request.form.get('global_path'), _global_ping_time, _global_max_missed, _global_use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('global_ts1_acl'), request.form.get('global_ts2_acl'), request.form.get('sub_file'), _ai_try_download, request.form.get('aliases_path'), request.form.get('peer_file'), request.form.get('tgid_file'), request.form.get('peer_url'), request.form.get('sub_url'), _ai_stale, _um_shorten_passphrase, request.form.get('um_burn_file'), _report_enabled, _report_interval, _report_port, request.form.get('report_clients'), request.form.get('unit_time'), request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('delete_server'): server_delete(request.args.get('delete_server')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('edit_server'): s = ServerList.query.filter_by(name=request.args.get('edit_server')).first() content = '''
''' # Add new server elif request.args.get('add'): # == 'yes': content = '''
''' else: all_s = ServerList.query.all() p_list = '''
Add Server Config |
Name |
Notes |
'''
for s in all_s:
p_list = p_list + '''
''' + str(s.name) + ''' | ''' + s.notes + ''' |
Redirecting in 3 seconds.
''' else: if request.args.get('save_mode') == 'mmdvm_peer': peer_add('mmdvm', request.form.get('name_text'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), 'MMDVM', request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), request.form.get('server'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' if request.args.get('save_mode') == 'xlx_peer': peer_add('xlx', request.form.get('name_text'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), request.form.get('xlxmodule'), request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), request.form.get('server'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('add') == 'mmdvm' or request.args.get('add') == 'xlx': s = ServerList.query.all() if request.args.get('add') == 'mmdvm': mode = 'MMDVM' submit_link = 'manage_peers?save_mode=mmdvm_peer' xlx_module = '' if request.args.get('add') == 'xlx': xlx_module = '''
Redirecting in 3 seconds.
''' elif request.args.get('edit_mmdvm') == 'save' or request.args.get('edit_xlx') == 'save': peer_enabled = False use_acl = False peer_loose = True unit_enabled = False if request.form.get('enabled') == 'true': peer_enabled = True ## if request.form.get('loose') == 'true': ## peer_loose = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_unit') == 'True': unit_enabled = True ## else: ## peer_loose = False ## print((unit_enabled)) ## print(type(peer_enabled)) ## print(type(use_acl)) if request.args.get('edit_mmdvm') == 'save': peer_edit('mmdvm', request.args.get('server'), request.args.get('name'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), 'MMDVM', request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' if request.args.get('edit_xlx') == 'save': peer_edit('xlx', request.args.get('server'), request.args.get('name'), peer_enabled, peer_loose, request.form.get('ip'), request.form.get('port'), request.form.get('master_ip'), request.form.get('master_port'), request.form.get('passphrase'), request.form.get('callsign'), request.form.get('radio_id'), request.form.get('rx'), request.form.get('tx'), request.form.get('tx_power'), request.form.get('cc'), request.form.get('lat'), request.form.get('lon'), request.form.get('height'), request.form.get('location'), request.form.get('description'), request.form.get('slots'), request.form.get('url'), request.form.get('group_hangtime'), request.form.get('xlxmodule'), request.form.get('options'), use_acl, request.form.get('sub_acl'), request.form.get('tgid_ts1_acl'), request.form.get('tgid_ts2_acl'), unit_enabled, request.form.get('notes')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('server') and request.args.get('peer_name') and request.args.get('mode'): # and request.args.get('edit_peer') and request.args.get('mode') == 'mmdvm': if request.args.get('mode') == 'mmdvm': p = mmdvmPeer.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('peer_name')).first() xlx_module = '' mode = "MMDVM" form_submit = '''''' else: all_s = ServerList.query.all() p_list = '' for s in all_s: # print(s.name) p_list = p_list + '''
Name | Mode | Notes |
''' + str(p.name) + ''' | MMDVM | ''' + p.notes + ''' |
''' + str(x.name) + ''' | XLX | ''' + x.notes + ''' |
Add MMDVM peer | Add XLX peer |
''' + p_list return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/manage_masters', methods=['POST', 'GET']) @login_required @roles_required('Admin') def manage_masters(): #PROXY if request.args.get('proxy_save'): active = False use_acl = False enable_unit = False repeat = True aprs_pos = False enable_um = True external_proxy = False public = False if request.form.get('enable_um') == 'False': enable_um = False if request.form.get('aprs_pos') == 'True': aprs_pos = True if request.form.get('enabled') == 'True': active = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_unit') == 'True': enable_unit = True if request.form.get('repeat') == 'False': repeat = False if request.form.get('external_proxy') == 'True': external_proxy = True if request.form.get('public_list') == 'True': public = True if request.args.get('proxy_save') == 'add': if request.form.get('name_text') == '': content = '''
Redirecting in 3 seconds.
''' else: add_master('PROXY', request.form.get('name_text'), request.form.get('server'), aprs_pos, repeat, active, 0, request.form.get('ip'), request.form.get('external_port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), external_proxy, request.form.get('int_port_start'), request.form.get('int_port_stop'), '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('proxy_save') == 'edit': ## print(request.args.get('name')) edit_master('PROXY', request.args.get('name'), request.args.get('server'), aprs_pos, repeat, active, 0, request.form.get('ip'), request.form.get('external_port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), external_proxy, request.form.get('int_port_start'), request.form.get('int_port_stop'), '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('proxy_save') == 'delete': master_delete('PROXY', request.args.get('server'), request.args.get('name')) content = '''Redirecting in 3 seconds.
''' # OBP elif request.args.get('OBP_save'): enabled = False use_acl = False enable_unit = False both_slots = True if request.form.get('enabled') == 'True': enabled = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_unit') == 'True': enable_unit = True if request.form.get('both_slots') == 'False': both_slots = False if request.args.get('OBP_save') == 'add': if request.form.get('name_text') == '': content = '''Redirecting in 3 seconds.
''' else: add_master('OBP', request.form.get('name_text'), request.form.get('server'), '', '', enabled, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), '', request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('tg_acl'), '', enable_unit, request.form.get('notes'), '', '', '', request.form.get('network_id'), request.form.get('target_ip'), request.form.get('target_port'), both_slots, '') content = '''Redirecting in 3 seconds.
''' elif request.args.get('OBP_save') == 'edit': edit_master('OBP', request.args.get('name'), request.args.get('server'), '', '', enabled, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), '', request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('tg_acl'), '', enable_unit, request.form.get('notes'), '', '', '', request.form.get('network_id'), request.form.get('target_ip'), request.form.get('target_port'), both_slots, '') content = '''Redirecting in 3 seconds.
''' elif request.args.get('OBP_save') == 'delete': master_delete('OBP', request.args.get('server'), request.args.get('name')) content = '''Redirecting in 3 seconds.
''' # MASTER elif request.args.get('master_save'): aprs_pos = False repeat = False active = False use_acl = False enable_um = False enable_unit = False public = False if request.form.get('aprs_pos') == 'True': aprs_pos = True if request.form.get('repeat') == 'True': repeat = True if request.form.get('enabled') == 'True': active = True if request.form.get('use_acl') == 'True': use_acl = True if request.form.get('enable_um') == 'True': enable_um = True if request.form.get('enable_unit') == 'True': enable_unit = True if request.form.get('public_list') == 'True': public = True if request.args.get('master_save') == 'add': if request.form.get('name_text') == '': content = '''Redirecting in 3 seconds.
''' else: add_master('MASTER', request.form.get('name_text'), request.form.get('server'), aprs_pos, repeat, active, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), '', '', '', '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('master_save') == 'edit': edit_master('MASTER', request.args.get('name'), request.args.get('server'), aprs_pos, repeat, active, request.form.get('max_peers'), request.form.get('ip'), request.form.get('port'), enable_um, request.form.get('passphrase'), request.form.get('group_hangtime'), use_acl, request.form.get('reg_acl'), request.form.get('sub_acl'), request.form.get('ts1_acl'), request.form.get('ts2_acl'), enable_unit, request.form.get('notes'), '', '', '', '', '', '', '', public) content = '''Redirecting in 3 seconds.
''' elif request.args.get('master_save') == 'delete': master_delete('MASTER', request.args.get('server'), request.args.get('name')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('add_OBP'): s = ServerList.query.all() server_options = '' for i in s: server_options = server_options + '''\n''' content = '''
''' elif request.args.get('edit_proxy'): # print(request.args.get('server')) # print(request.args.get('edit_proxy')) p = ProxyList.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('edit_proxy')).first() content = '''
''' elif request.args.get('add_proxy'): s = ServerList.query.all() server_options = '' for i in s: server_options = server_options + '''\n''' content = '''
''' elif request.args.get('add_master'): s = ServerList.query.all() server_options = '' for i in s: server_options = server_options + '''\n''' content = '''
''' elif request.args.get('edit_OBP'): ## print(request.args.get('server')) ## print(request.args.get('edit_OBP')) ## s = ServerList.query.all() o = OBP.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('edit_OBP')).first() ## print(o.notes) content = '''
''' elif request.args.get('edit_master'): ## s = ServerList.query.all() m = MasterList.query.filter_by(server=request.args.get('server')).filter_by(name=request.args.get('edit_master')).first() content = '''
''' ## elif not request.args.get('edit_master') and not request.args.get('edit_OBP') and not request.args.get('add_OBP') and not request.args.get('add_master'): ## content = 'jglkdjklsd' else: #elif not request.args.get('add_proxy') or not request.args.get('add_OBP') or not request.args.get('add_master'): # or not request.args.get('proxy_save') or not request.args.get('master_save') or not request.args.get('OBP_save'): all_s = ServerList.query.all() m_list = '' for s in all_s: ## print(s.name) m_list = m_list + '''
Name | Mode | Notes |
''' + str(o.name) + ''' | OpenBridge | ''' + str(o.notes) + ''' |
''' + str(p.name) + ''' | PROXY | ''' + str(p.notes) + ''' |
''' + str(x.name) + ''' | MASTER | ''' + str(x.notes) + ''' |
Add MASTER | Add PROXY | Add OpenBridge |
''' + m_list return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/add_user', methods=['POST', 'GET']) @login_required @roles_required('Admin') def add_admin(): if request.method == 'GET': content = '''
''' elif request.method == 'POST' and request.form.get('username'): if not User.query.filter(User.username == request.form.get('username')).first(): radioid_data = ast.literal_eval(get_ids(request.form.get('username'))) user = User( username=request.form.get('username'), email=request.form.get('email'), email_confirmed_at=datetime.datetime.utcnow(), password=user_manager.hash_password(request.form.get('password')), dmr_ids = str(radioid_data[0]), initial_admin_approved = True, first_name = str(radioid_data[1]), last_name = str(radioid_data[2]), city = str(radioid_data[3]) ) db.session.add(user) u = User.query.filter_by(username=request.form.get('username')).first() user_role = UserRoles( user_id=u.id, role_id=2, ) db.session.add(user_role) db.session.commit() content = '''
Created user: ''' + str(request.form.get('username')) + '''
\n''' elif User.query.filter(User.username == request.form.get('username')).first(): content = 'Existing user: ' + str(request.form.get('username') + '. New user not created.') return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/manage_rules', methods=['POST', 'GET']) @login_required @roles_required('Admin') def manage_rules(): if request.args.get('save_bridge') == 'save': public = False if request.form.get('public_list') == 'True': public = True if request.form.get('bridge_name') == '': content = '''Redirecting in 3 seconds.
''' else: bridge_add(request.form.get('bridge_name'), request.form.get('description'), public, request.form.get('tg')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_bridge') == 'edit': public = False if request.form.get('public_list') == 'True': public = True update_bridge_list(request.args.get('bridge'), request.form.get('description'), public, request.form.get('bridge_name'), request.form.get('tg')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_bridge') == 'delete': bridge_delete(request.args.get('bridge')) content = '''Redirecting in 3 seconds.
''' #Rules elif request.args.get('save_rule'): public_list = False active = False if request.form.get('active_dropdown') == 'True': active = True if request.args.get('save_rule') == 'new': add_system_rule(request.form.get('bridge_dropdown'), request.form.get('system_text'), request.form.get('ts_dropdown'), request.form.get('tgid'), active, request.form.get('timer_time'), request.form.get('type_dropdown'), request.form.get('on'), request.form.get('off'), request.form.get('reset'), request.args.get('server'), public_list) content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_rule') == 'edit': content = '''Redirecting in 3 seconds.
''' elif request.args.get('save_rule') == 'delete': # print(request.args.get('bridge')) # print(request.args.get('server')) if request.args.get('system'): delete_system_rule(request.args.get('bridge'), request.args.get('server'), request.args.get('system')) else: delete_system_bridge(request.args.get('bridge'), request.args.get('server')) ## delete_system_rule(request.args.get('bridge'), request.args.get('server'), request.args.get('system')) content = '''Redirecting in 3 seconds.
''' elif request.args.get('add_rule'): ## svl = ServerList.query.all() bl = BridgeList.query.all() #filter(bridge_name== request.form.get('username')).all() all_o = OBP.query.filter_by(server=request.args.get('add_rule')).all() all_m = MasterList.query.filter_by(server=request.args.get('add_rule')).all() all_p = ProxyList.query.filter_by(server=request.args.get('add_rule')).all() m_l = mmdvmPeer.query.filter_by(server=request.args.get('add_rule')).all() x_l = xlxPeer.query.filter_by(server=request.args.get('add_rule')).all() ## print(sl) ## print(bl) ## svl_option = '' bl_option = '' sl_option = '' for i in all_o: sl_option = sl_option + '''''' for i in all_m: sl_option = sl_option + '''''' for i in all_p: sl_option = sl_option + '''''' for i in m_l: sl_option = sl_option + '''''' for i in x_l: sl_option = sl_option + '''''' for i in bl: bl_option = bl_option + '''''' content = '''''' elif request.args.get('edit_rule') and request.args.get('bridge'): br = BridgeRules.query.filter_by(server=request.args.get('edit_rule')).filter_by(bridge_name=request.args.get('bridge')).all() print(br) br_view = '''
Delete SYSTEM Rule |
|
''' content = br_view elif request.args.get('add_bridge'): s = ServerList.query.all() ## server_options = '' ## for i in s: ## server_options = server_options + '''\n''' content = '''
''' else: all_b = BridgeList.query.all() s = ServerList.query.all() b_list = '''
Add Bridge |
Name | Public | Description | TGID |
''' + str(i.bridge_name) + ''' | ''' + str(i.public_list) + ''' | ''' + str(i.description) + ''' | ''' + str(i.tg) + ''' |
Add a rule to server: ''' + str(i.name) + ''' |
Bridge Name | - | - |
''' + str(x.bridge_name) + ''' | Edit Bridge Rules | Delete Bridge from this server |
''' content = b_list + r_list + '''''' return render_template('flask_user_layout.html', markup_content = Markup(content)) @app.route('/svr', methods=['POST']) def auth(): hblink_req = request.json # print((hblink_req)) if hblink_req['secret'] in shared_secrets(): if 'login_id' in hblink_req and 'login_confirmed' not in hblink_req: if type(hblink_req['login_id']) == int: if authorized_peer(hblink_req['login_id'])[0]: if isinstance(authorized_peer(hblink_req['login_id'])[1], int) == True: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], gen_passphrase(hblink_req['login_id']), 'Attempt') response = jsonify( allow=True, mode='normal', ) elif authorized_peer(hblink_req['login_id'])[1] == '': authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'Config Passphrase: ' + legacy_passphrase, 'Attempt') response = jsonify( allow=True, mode='legacy', ) elif authorized_peer(hblink_req['login_id'])[1] != '' or isinstance(authorized_peer(hblink_req['login_id'])[1], int) == False: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], authorized_peer(hblink_req['login_id'])[1], 'Attempt') # print(authorized_peer(hblink_req['login_id'])) response = jsonify( allow=True, mode='override', value=authorized_peer(hblink_req['login_id'])[1] ) active_tgs[hblink_req['login_server']][hblink_req['system']] = [{'1':[]}, {'2':[]}, {'SYSTEM': ''}, {'peer_id':hblink_req['login_id']}] print(active_tgs) elif authorized_peer(hblink_req['login_id'])[0] == False: ## print('log fail') authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], 'Not Registered', '-', 'Failed') response = jsonify( allow=False) elif not type(hblink_req['login_id']) == int: user = hblink_req['login_id'] u = User.query.filter_by(username=user).first() if not u: msg = jsonify(auth=False, reason='User not found') response = make_response(msg, 401) if u: u_role = UserRoles.query.filter_by(user_id=u.id).first() password = user_manager.verify_password(hblink_req['password'], u.password) if u_role.role_id == 2: role = 'user' if u_role.role_id == 1: role = 'admin' if password: response = jsonify(auth=True, role=role) else: msg = jsonify(auth=False, reason='Incorrect password') response = make_response(msg, 401) elif 'login_id' in hblink_req and 'login_confirmed' in hblink_req: if hblink_req['old_auth'] == True: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'CONFIG, NO UMS', 'Confirmed') else: authlog_add(hblink_req['login_id'], hblink_req['login_ip'], hblink_req['login_server'], authorized_peer(hblink_req['login_id'])[2], 'USER MANAGER', 'Confirmed') response = jsonify( logged=True ) elif 'burn_list' in hblink_req: # ['burn_list']: # == 'burn_list': response = jsonify( burn_list=get_burnlist() ) elif 'get_config' in hblink_req: if hblink_req['get_config']: active_tgs[hblink_req['get_config']] = {} print(active_tgs) ## try: ## print(get_peer_configs(hblink_req['get_config'])) response = jsonify( config=server_get(hblink_req['get_config']), peers=get_peer_configs(hblink_req['get_config']), masters=masters_get(hblink_req['get_config']), ## OBP=get_OBP(hblink_req['get_config']) ) ## except: ## message = jsonify(message='Config error') ## response = make_response(message, 401) elif 'get_rules' in hblink_req: if hblink_req['get_rules']: # == 'burn_list': ## try: response = jsonify( rules=generate_rules(hblink_req['get_rules']), ## OBP=get_OBP(hblink_req['get_config']) ) ## except: ## message = jsonify(message='Config error') ## response = make_response(message, 401) elif 'update_tg' in hblink_req: if hblink_req['update_tg']: print(hblink_req) ## print(hblink_req['data'][0]['SYSTEM']) if 'on' == hblink_req['mode']: ## try: if hblink_req['dmr_id'] == 0: print('id 0') ## print(active_tgs) for system in active_tgs[hblink_req['update_tg']].items(): ## print(system) ## print('sys') if system[0] == hblink_req['data'][0]['SYSTEM']: print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']) ## print(hblink_req['data'][2]['tg']) print('---------') print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']) ## print(hblink_req['data'][1]['ts']) if hblink_req['data'][1]['ts'] == 1: #### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1']) if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'] == hblink_req['data'][2]['tg']: pass else: active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][2]['tg']) #### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0) if hblink_req['data'][1]['ts'] == 2: if active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'] == hblink_req['data'][2]['tg']: pass #### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2']) else: active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['tg']) else: print('---------on------------') print(hblink_req['data']) print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']) print(hblink_req['data'][2]['ts2']) print('-----------------------') ## active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['SYSTEM'] = hblink_req['data'][0]['SYSTEM'] #### active_tgs[hblink_req['update_tg']][hblink_req['dmr_id']].update({hblink_req['data'][0]['SYSTEM']: [{1:[hblink_req['data'][1]['ts1']]}, {2:[hblink_req['data'][2]['ts2']]}]}) #.update({[hblink_req['dmr_id']]:hblink_req['data']}) if hblink_req['data'][1]['ts1'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1']: active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].append(hblink_req['data'][1]['ts1']) if hblink_req['data'][2]['ts2'] not in active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2']: active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].append(hblink_req['data'][2]['ts2']) ## print('append') #### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0) ## print(hblink_req['data'][0]['SYSTEM']) ## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']]) ## print(active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][2]['2']) ## print(hblink_req['data'][1]['ts2']) ## print(active_tgs[hblink_req['update_tg']]) ## except: ## pass elif 'off' == hblink_req['mode']: print('off') for system in active_tgs[hblink_req['update_tg']].items(): print(system) if system[0] == hblink_req['data'][0]['SYSTEM']: print('yes it is') #### print(system[0]) #### print(active_tgs[hblink_req['update_tg']][system[0]]) if hblink_req['data'][1]['ts'] == 1: #### print(active_tgs[hblink_req['update_tg']][system[0]][0]['1']) active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][0]['1'].remove(hblink_req['data'][2]['tg']) #### active_tgs[hblink_req['update_tg']][system[0]][0]['1'].append(0) if hblink_req['data'][1]['ts'] == 2: #### print(active_tgs[hblink_req['update_tg']][system[0]][1]['2']) active_tgs[hblink_req['update_tg']][hblink_req['data'][0]['SYSTEM']][1]['2'].remove(hblink_req['data'][2]['tg']) #### active_tgs[hblink_req['update_tg']][system[0]][1]['2'].append(0) ## print() ## print(system) ## print(system[1][2]['SYSTEM']) ## print('off') ## print(hblink_req['data'][1]['ts']) ## print(hblink_req['data'][2]['tg']) print(active_tgs) response = 'got it' else: message = jsonify(message='Authentication error') response = make_response(message, 401) return response return app if __name__ == '__main__': app = create_app() app.run(debug = True, port=ums_port, host=ums_host)