def manage_database(timestamp): import time from server_communication.post_resource_to_server import * from read_ip_address import read_ip_address # Initialize array of delays and find the IP address of the interface that # the LAN host should be operating on index = 0 delay = [300, 300, 300, 600, 600, 1200] ip = read_ip_address('wlan0') # This loop will run until application termination to continuously sync # the local and remote databases while True: # Reset whether the DB has changed and define an empty dict, which # represents no changes in the current DB (this is so no data is # written to the local DB, but changes from it can still be # received) changed = False args = { 'timestamp' : timestamp, 'users' : None, 'networks' : None, 'devices' : None } session, response = post_resource_to_server('/db_manager', args, server = ip + ':3000') # NEED TO PARSE RESULT FOR PROPER DATABASE ENTRIES # Check for changes from the LAN host. If some exist flag that there # has been a change and store changes in dict. if users is not None or networks is not None or devices is not None: changed = True args['users'] = args['networks'] = args['devices'] = # Send the additions to the central server session, response = post_resource_to_server('/db_manager', args, server = 'batphone.co') # NEED TO PARSE RESULT FOR PROPER DATABASE ENTRIES AND TIMESTAMP timestamp = # Check for changes from the server. If some exist flag that there # has been a change, store changes in a dict, and add them to the # LAN host. if users is not None or networks is not None or devices is not None: changed = True args['users'] = args['networks'] = args['devices'] = session, response = post_resource_to_server('/db_manager', args, server = ip + ':3000') if not changed and index != 5: index = index + 1 elif changed: index = 0 time.sleep(delay)
def setup(): import sys sys.path.append('..') from application_management import database_clone import threading from sockets import TCPServerSocket from read_ip_address import read_ip_address from join_batman_network import join_batman_network from post_network_device import post_network_device # Pull info from form dev_name = request.form['name'] longitude = request.form['longitude'] latitude = request.form['latitude'] description = request.form['description'] notes = request.form['notes'] ssid = request.form['ssid'] mac = request.form['mac'] # Join the BATMAN network in the DHCP/Web App Host spot join_batman_network(interface='wlan0', network_name=ssid, ap_mac=mac) # Creates a thread to manage new network devices and # dish out open IP addresses. ip = read_ip_address('bat0') socket = TCPServerSocket.TCPServerSocket(ip, 3000) dhcp_thread = threading.Thread(target=socket.start_server) dhcp_thread.start() # Get the data from the server data = database_clone.database_clone() # Add the device's information to the database post_network_device(ssid=ssid, publickey='pgp', dev_name=dev_name, IP_address='192.168.2.4', MAC=mac, Gateway_mode='client', description=description, longitude=longitude, latitude=latitude, notes=notes) # Start hosting the web app, add the info to the database # Start managing the database syncing application_management.host_web_app.host_web_app() application_management.populate_db.populate_db(data) application_management.manage_db.manage_db() return 'OK'
def read_ip_mac_tuple(interface): '''Read an interfaces IP and MAC address. ARGS: @interface -- The interfaces IP and MAC to be read. Ex. Bat0, Eth0 RETURNS: @ip -- The interfaces IP as a STRING. @mac -- The interfaces MAC as a STRING. ''' from read_ip_address import read_ip_address from read_mac_address import read_mac_address ip = read_ip_address(interface) mac = read_mac_address(interface) return (ip, mac)
def setup(): import sys sys.path.append('..') from application_management import database_clone import threading from sockets import TCPServerSocket from read_ip_address import read_ip_address from join_batman_network import join_batman_network from post_network_device import post_network_device # Pull info from form dev_name = request.form['name'] longitude = request.form['longitude'] latitude = request.form['latitude'] description = request.form['description'] notes = request.form['notes'] ssid = request.form['ssid'] mac = request.form['mac'] # Join the BATMAN network in the DHCP/Web App Host spot join_batman_network(interface = 'wlan0', network_name = ssid, ap_mac = mac) # Creates a thread to manage new network devices and # dish out open IP addresses. ip = read_ip_address('bat0') socket = TCPServerSocket.TCPServerSocket(ip, 3000) dhcp_thread = threading.Thread(target = socket.start_server) dhcp_thread.start() # Get the data from the server data = database_clone.database_clone() # Add the device's information to the database post_network_device(ssid = ssid, publickey = 'pgp', dev_name = dev_name, IP_address = '192.168.2.4', MAC = mac, Gateway_mode = 'client', description = description, longitude = longitude, latitude = latitude, notes = notes) # Start hosting the web app, add the info to the database # Start managing the database syncing application_management.host_web_app.host_web_app() application_management.populate_db.populate_db(data) application_management.manage_db.manage_db() return 'OK'