diff --git a/bridge.py b/bridge.py index 3852040..8997e72 100755 --- a/bridge.py +++ b/bridge.py @@ -98,7 +98,7 @@ def download_config(L_CONFIG_FILE, cli_file): corrected_config['LOGGER'].update(L_CONFIG_FILE['LOGGER']) corrected_config['USER_MANAGER'].update(L_CONFIG_FILE['USER_MANAGER']) ## iterate_config.update(resp['masters'].copy()) - print(iterate_config) +## print(iterate_config) ## print(iterate_config) ## corrected_config = CONFIG_FILE.copy() @@ -117,21 +117,22 @@ def download_config(L_CONFIG_FILE, cli_file): corrected_config['GLOBAL']['SUB_ACL'] = config.acl_build(corrected_config['GLOBAL']['SUB_ACL'], 16776415) ## corrected_config['SYSTEMS'] = {} for i in iterate_config: - print(i) +## print(i) ## corrected_config['SYSTEMS'][i] = {} if iterate_config[i]['MODE'] == 'MASTER' or iterate_config[i]['MODE'] == 'PROXY': corrected_config['SYSTEMS'][i]['TG1_ACL'] = config.acl_build(iterate_config[i]['TG1_ACL'], 16776415) corrected_config['SYSTEMS'][i]['TG2_ACL'] = config.acl_build(iterate_config[i]['TG2_ACL'], 16776415) - else: + if iterate_config[i]['MODE'] == 'OPENBRIDGE': + corrected_config['SYSTEMS'][i]['NETWORK_ID'] = int(iterate_config[i]['NETWORK_ID']).to_bytes(4, 'big') + if iterate_config[i]['MODE'] == 'PEER' or iterate_config[i]['MODE'] == 'XLXPEER': corrected_config['SYSTEMS'][i]['RADIO_ID'] = int(iterate_config[i]['RADIO_ID']).to_bytes(4, 'big') corrected_config['SYSTEMS'][i]['TG1_ACL'] = config.acl_build(iterate_config[i]['TG1_ACL'], 16776415) corrected_config['SYSTEMS'][i]['TG2_ACL'] = config.acl_build(iterate_config[i]['TG2_ACL'], 16776415) corrected_config['SYSTEMS'][i]['MASTER_SOCKADDR'] = tuple(iterate_config[i]['MASTER_SOCKADDR']) corrected_config['SYSTEMS'][i]['SOCK_ADDR'] = tuple(iterate_config[i]['SOCK_ADDR']) - corrected_config['SYSTEMS'][i]['USE_ACL'] = iterate_config[i]['USE_ACL'] - corrected_config['SYSTEMS'][i]['SUB_ACL'] = config.acl_build(iterate_config[i]['SUB_ACL'], 16776415) - corrected_config['SYSTEMS'][i].update({'STATS':{ - 'CONNECTION': 'NO', # NO, RTPL_SENT, AUTHENTICATED, CONFIG-SENT, YES + if iterate_config[i]['MODE'] == 'PEER': + corrected_config['SYSTEMS'][i].update({'STATS':{ + 'CONNECTION': 'NO', # NO, RTPL_SENT, AUTHENTICATED, CONFIG-SENT, YES 'CONNECTED': None, 'PINGS_SENT': 0, 'PINGS_ACKD': 0, @@ -140,6 +141,20 @@ def download_config(L_CONFIG_FILE, cli_file): 'LAST_PING_TX_TIME': 0, 'LAST_PING_ACK_TIME': 0, }}) + if iterate_config[i]['MODE'] == 'XLXPEER': + corrected_config['SYSTEMS'][i].update({'XLXSTATS': { + 'CONNECTION': 'NO', # NO, RTPL_SENT, AUTHENTICATED, CONFIG-SENT, YES + 'CONNECTED': None, + 'PINGS_SENT': 0, + 'PINGS_ACKD': 0, + 'NUM_OUTSTANDING': 0, + 'PING_OUTSTANDING': False, + 'LAST_PING_TX_TIME': 0, + 'LAST_PING_ACK_TIME': 0, + }}) + corrected_config['SYSTEMS'][i]['USE_ACL'] = iterate_config[i]['USE_ACL'] + corrected_config['SYSTEMS'][i]['SUB_ACL'] = config.acl_build(iterate_config[i]['SUB_ACL'], 16776415) + ## print(iterate_masters) ## for i in iterate_masters: diff --git a/config.py b/config.py index 3d24025..30b4ba1 100755 --- a/config.py +++ b/config.py @@ -296,7 +296,7 @@ def build_config(_config_file): 'TG1_ACL': config.get(section, 'TGID_ACL'), 'TG2_ACL': 'PERMIT:ALL' }}) - + print( CONFIG['SYSTEMS'][section]) except configparser.Error as err: sys.exit('Error processing configuration file -- {}'.format(err)) diff --git a/user_managment/app.py b/user_managment/app.py index 0d5c4c8..3cd646c 100644 --- a/user_managment/app.py +++ b/user_managment/app.py @@ -293,11 +293,13 @@ def create_app(): __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) @@ -306,6 +308,25 @@ def create_app(): 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='') + + 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='') server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') notes = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') @@ -326,18 +347,6 @@ def create_app(): description = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') public_list = db.Column(db.Boolean(), nullable=False, server_default='0') - class ExcludeUnit(db.Model): - __tablename__ = 'exclude_unit' - id = db.Column(db.Integer(), primary_key=True) - system_name = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') - server = db.Column(db.String(100, collation='NOCASE'), nullable=False, server_default='') - - - - - - - # Customize Flask-User class CustomUserManager(UserManager): # Override or extend the default login view method @@ -1761,6 +1770,7 @@ def create_app(): #s = ServerList.query.filter_by(name=_name).first() # print(s.name) i = MasterList.query.filter_by(server=_name).all() + o = OBP.query.filter_by(server=_name).all() print('get masters') master_config_list = {} ## master_config_list['SYSTEMS'] = {} @@ -1784,52 +1794,26 @@ def create_app(): 'TG2_ACL': m.tg2_acl }}) master_config_list[m.name].update({'PEERS': {}}) + for obp in o: + print(type(obp.network_id)) + master_config_list.update({obp.name: { + 'MODE': 'OPENBRIDGE', + 'ENABLED': obp.enabled, + 'NETWORK_ID': obp.network_id, #int(obp.network_id).to_bytes(4, 'big'), + 'IP': gethostbyname(obp.ip), + 'PORT': obp.port, +## 'PASSPHRASE': bytes(obp.passphrase.ljust(20,'\x00')[:20], 'utf-8'), +## 'TARGET_SOCK': (obp.target_ip, obp.target_port), +## 'TARGET_IP': gethostbyname(obp.target_ip), + 'TARGET_PORT': obp.target_port, + 'BOTH_SLOTS': obp.both_slots, + 'USE_ACL': obp.use_acl, + 'SUB_ACL': obp.sub_acl, + 'TG1_ACL': obp.tg_acl, + 'TG2_ACL': 'PERMIT:ALL' + }}) print(master_config_list) return master_config_list -## print(i.name) -## s_config = {} -## s_config['GLOBAL'] = {} -## s_config['REPORTS'] = {} -## s_config['ALIASES'] = {} -## s_config['USER_MANAGER'] = {} -## -## s_config['GLOBAL'].update({ -## 'PATH': i.global_path, -## 'PING_TIME': i.global_ping_time, -## 'MAX_MISSED': i.global_max_missed, -## 'USE_ACL': i.global_use_acl, -## 'REG_ACL': i.global_reg_acl, -## 'SUB_ACL': i.global_sub_acl, -## 'TG1_ACL': i.global_tg1_acl, -## 'TG2_ACL': i.global_tg2_acl -## }) -## -## s_config['REPORTS'].update({ -## 'REPORT': i.report_enable, -## 'REPORT_INTERVAL': i.report_interval, -## 'REPORT_PORT': i.report_port, -## 'REPORT_CLIENTS': i.report_clients.split(',') -## }) -## s_config['ALIASES'].update({ -## 'TRY_DOWNLOAD':i.ai_try_download, -## 'PATH': i.ai_path, -## 'PEER_FILE': i.ai_peer_file, -## 'SUBSCRIBER_FILE': i.ai_subscriber_file, -## 'TGID_FILE': i.ai_tgid_file, -## 'PEER_URL': i.ai_peer_url, -## 'SUBSCRIBER_URL': i.ai_subs_url, -## 'STALE_TIME': i.ai_stale * 86400, -## }) -## s_config['USER_MANAGER'].update({ -## 'APPEND_INT': append_int, -## 'SHORTEN_PASSPHRASE': i.um_shorten_passphrase, -## 'BURN_FILE': i.um_burn_file, -## 'BURN_INT': burn_int, -## -## -## }) -## print(s_config['REPORTS']) -## return s_config def server_edit(_name, _secret, _ip, _public_list, _port, _global_path, _global_ping_time, _global_max_missed, _global_use_acl, _global_reg_acl, _global_sub_acl, _global_tg1_acl, _global_tg2_acl, _ai_subscriber_file, _ai_try_download, _ai_path, _ai_peer_file, _ai_tgid_file, _ai_peer_url, _ai_subs_url, _ai_stale, _um_shorten_passphrase, _um_burn_file, _report_enable, _report_interval, _report_port, _report_clients, _unit_time): s = ServerList.query.filter_by(name=_name).first() @@ -1875,10 +1859,15 @@ def create_app(): m = MasterList.query.filter_by(server=_server).filter_by(name=_name).first() if _mode == 'PROXY': m = ProxyList.query.filter_by(server=_server).filter_by(name=_name).first() + if _mode == 'OBP': + m = OBP.query.filter_by(server=_server).filter_by(name=_name).first() db.session.delete(m) db.session.commit() - def edit_master(_mode, _name, _server, _static_positions, _repeat, _active, _max_peers, _ip, _port, _enable_um, _passphrase, _group_hang_time, _use_acl, _reg_acl, _sub_acl, _tg1_acl, _tg2_acl, _enable_unit, _notes, _external_proxy, _int_start_port, _int_stop_port): + def edit_master(_mode, _name, _server, _static_positions, _repeat, _active, _max_peers, _ip, _port, _enable_um, _passphrase, _group_hang_time, _use_acl, _reg_acl, _sub_acl, _tg1_acl, _tg2_acl, _enable_unit, _notes, _external_proxy, _int_start_port, _int_stop_port, _network_id, _target_ip, _target_port, _both_slots): + print(_mode) + print(_server) + print(_name) if _mode == 'MASTER': ## print(_name) m = MasterList.query.filter_by(server=_server).filter_by(name=_name).first() @@ -1901,30 +1890,70 @@ def create_app(): ## m.server = _server m.notes = _notes db.session.commit() - add_proxy = ProxyList( - name = _name, - static_positions = _static_positions, - repeat = _repeat, - active = _active, - enable_um = _enable_um, - passphrase = _passphrase, - external_proxy = _external_proxy, - group_hang_time = int(_group_hang_time), - internal_start_port = int(_int_start_port), - internal_stop_port = int(_int_stop_port), - use_acl = _use_acl, - reg_acl = _reg_acl, - sub_acl = _sub_acl, - tg1_acl = _tg1_acl, - tg2_acl = _tg2_acl, - enable_unit = _enable_unit, - server = _server, - notes = _notes - ) - db.session.add(add_master) + if _mode == 'OBP': + o = OBP.query.filter_by(server=_server).filter_by(name=_name).first() + o.enabled = _active + o.network_id = _network_id + o.ip = _ip + o.port = _port + o.passphrase = _passphrase + o.target_ip = _target_ip + o.target_port = _target_port + o.both_slots = _both_slots + o.use_acl = _use_acl + o.sub_acl = _sub_acl + o.tg1_acl = _tg1_acl + o.tg2_acl = _tg2_acl + o.notes = _notes db.session.commit() + if _mode == 'PROXY': + print(_int_start_port) + print(_int_stop_port) + p = ProxyList.query.filter_by(server=_server).filter_by(name=_name).first() + p.name = _name + p.static_positions = _static_positions + p.repeat = _repeat + p.active = _active + p.enable_um = _enable_um + p.passphrase = _passphrase + p.external_proxy = _external_proxy + external_port = int(_port) + p.group_hang_time = int(_group_hang_time) + p.internal_start_port = _int_start_port + p.internal_stop_port = _int_stop_port + p.use_acl = _use_acl + p.reg_acl = _reg_acl + p.sub_acl = _sub_acl + p.tg1_acl = _tg1_acl + p.tg2_acl = _tg2_acl + p.enable_unit = _enable_unit + p.server = _server + p.notes = _notes + db.session.commit() +## add_proxy = ProxyList( +## name = _name, +## static_positions = _static_positions, +## repeat = _repeat, +## active = _active, +## enable_um = _enable_um, +## passphrase = _passphrase, +## external_proxy = _external_proxy, +## group_hang_time = int(_group_hang_time), +## internal_start_port = int(_int_start_port), +## internal_stop_port = int(_int_stop_port), +## use_acl = _use_acl, +## reg_acl = _reg_acl, +## sub_acl = _sub_acl, +## tg1_acl = _tg1_acl, +## tg2_acl = _tg2_acl, +## enable_unit = _enable_unit, +## server = _server, +## notes = _notes +## ) +## db.session.add(add_master) - def add_master(_mode, _name, _server, _static_positions, _repeat, _active, _max_peers, _ip, _port, _enable_um, _passphrase, _group_hang_time, _use_acl, _reg_acl, _sub_acl, _tg1_acl, _tg2_acl, _enable_unit, _notes, _external_proxy, _int_start_port, _int_stop_port): + def add_master(_mode, _name, _server, _static_positions, _repeat, _active, _max_peers, _ip, _port, _enable_um, _passphrase, _group_hang_time, _use_acl, _reg_acl, _sub_acl, _tg1_acl, _tg2_acl, _enable_unit, _notes, _external_proxy, _int_start_port, _int_stop_port, _network_id, _target_ip, _target_port, _both_slots): + print(_mode) if _mode == 'MASTER': add_master = MasterList( name = _name, @@ -1957,6 +1986,7 @@ def create_app(): enable_um = _enable_um, passphrase = _passphrase, external_proxy = _external_proxy, + external_port = int(_port), group_hang_time = int(_group_hang_time), internal_start_port = int(_int_start_port), internal_stop_port = int(_int_stop_port), @@ -1969,8 +1999,29 @@ def create_app(): server = _server, notes = _notes ) - db.session.add(add_master) + db.session.add(add_proxy) db.session.commit() + if _mode == 'OBP': + print(_name) + print(_network_id) + add_OBP = OBP( + name = _name, + enabled = _active, + network_id = _network_id, # + ip = _ip, + port = _port, + passphrase = _passphrase, + target_ip = _target_ip,# + target_port = _target_port,# + both_slots = _both_slots,# + use_acl = _use_acl, + sub_acl = _sub_acl, + tg_acl = _tg1_acl, + server = _server, + notes = _notes, + ) + db.session.add(add_OBP) + db.session.commit() def server_add(_name, _secret, _ip, _public_list, _port, _global_path, _global_ping_time, _global_max_missed, _global_use_acl, _global_reg_acl, _global_sub_acl, _global_tg1_acl, _global_tg2_acl, _ai_subscriber_file, _ai_try_download, _ai_path, _ai_peer_file, _ai_tgid_file, _ai_peer_url, _ai_subs_url, _ai_stale, _um_shorten_passphrase, _um_burn_file, _report_enable, _report_interval, _report_port, _report_clients, _unit_time): @@ -2564,6 +2615,7 @@ def create_app(): all_s = ServerList.query.all() p_list = '''
Name | Mode | +Notes | +
''' + str(o.name) + ''' | +OpenBridge | +''' + str(o.notes) + ''' | + +
''' + str(p.name) + ''' | +''' + str(p.name) + ''' | PROXY | -''' + str(p.notes) + ''' | + + ''' for x in all_m: m_list = m_list + '''
''' + str(x.name) + ''' | MASTER | -''' + str(x.notes) + ''' | + + + ''' m_list = m_list + '''
Add MASTER | Add PROXY | +Add OpenBridge | +