def join_batman_network_guest(ssid, ap, ip_range):
	'''Join the Batman network in the guest IP spot.

	ARGS:
	@ssid		-- The name of the network to be joined.
	@ap 		-- The MAC address of the access point of the network.
	@ip_range 	-- The IP address range of the network being joined.

	RETURNS:
	None		-- Sends a message to the network access point with device address
				   information to which the access point should respond with a
				   switch IP message.
	'''
	import sys
	sys.path.append('..')
	from run_command import run_command
	from is_valid_ip_range import is_valid_ip_range
	from is_valid_mac_address import is_valid_mac_address
	from join_batman_network import join_batman_network

	# If network information invalid do not change network settings just QUIT.
	if not is_valid_ip_range(ip_range) or not is_valid_mac_address(ap):
		return None

	# Determine gateway and guest IP address based on the IP range
	ip = ip_range + '.255'
	gateway_ip = ip_range + '.0'

	# Configure the BATMAN-Advanced network using the guest ip
	join_batman_network(ssid, ap, ip)
Example #2
0
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 join_batman_network_as_client(ssid = 'squids_network',
								  ap = '02:12:34:56:78:9A',
								  channel = 1,
								  gateway = False):
	import sys
	sys.path.append('..')
	from run_command import run_command
	
	if gateway:
		(from join_batman_network_as_gateway 
		 import join_batman_network_as_gateway)
		join_batman_network_as_gateway(ssid, ap, channel)
	else:
		from join_batman_network import join_batman_network
		join_batman_network(ssid, ap, channel)
def join_batman_network_as_master(ssid = 'squids_network',
								  ap = '02:12:34:56:78:9A',
								  channel = 1,
								  gateway = True):
	import sys
	import threading
	sys.path.append('..')
	from run_command import run_command

	if gateway:
		from join_batman_network_as_gateway import join_batman_network_as_gateway
		interface = 'br-lan'
		join_batman_network_as_gateway(ssid, ap, channel)
	else:
		from join_batman_network import join_batman_network
		interface = 'bat0'
		join_batman_network(ssid, ap, channel)

	with open('/etc/dhcp/dhcpd.conf', 'w') as dhcp_file:
		dhcp_file.write('ddns-update-style none;\n\n' +
						'default-lease-time 600;\n' +
						'max-lease-time 7200;\n\n' +
						'authoritative;\n\n' +
						'subnet 192.168.10.0 netmask 255.255.255.0 {\n' +
						'	range 192.168.10.10 192.168.10.250;\n' +
						'	option broadcast-address 192.168.10.255;\n' +
						'	option routers 192.168.10.1;\n' +
						'	default-lease-time 600;\n' +
						'	max-lease-time 7200;\n' +
						'	option domain-name "batlan";\n' +
						'	option domain-name-servers 8.8.8.8 8.8.4.4;\n' +
						'}')

	with open('/etc/default/isc-dhcp-server', 'w') as server_file:
		server_file.write('INTERFACES="' + interface + '"')

	run_command('sudo ifdown wlan0')
	with open('/etc/network/interfaces', 'w') as interfaces_file:
		interfaces_file.write('auto lo\n\n' +
							  'iface lo inet loopback\n' +
							  'iface eth0 inet dhcp\n\n' +
							  'allow-hotplug ' + interface + '\n\n' +
							  'iface ' + interface + ' inet static\n' +
							  ' address 192.168.10.1\n' +
							  ' netmask 255.255.255.0')

	command = 'sudo service isc-dhcp-server restart'
	thread = threading.Thread(target=run_command, args=(command, ))
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'
Example #6
0
def join():
	import requests
	import webbrowser
	from sockets import TCPSocket
	from run_command import run_command
	from read_mac_address import read_mac_address
	from join_batman_network import join_batman_network

	error = None
	try:
		from 
		from run_command import run_command
		from sockets import TCPSocket
		from join_batman_network import join_batman_network
		ssid = request.form['ssid']
		publickey = request.form['publickey']
		mac = request.form['mac']
		password = request.form['admin_password']
		interface = request.form['interfaces']

		join_batman_network(password = password,
				    interface = interface,
				    network_name = ssid,
				    ap_mac = mac)

		if_mac = read_mac_address(interface)
		sock = TCPSocket()
		sock.connect('192.168.2.15', 5005)
		sock.write('DHCP ' + if_mac + '/n')

		response = socket.read()
		run_command('sudo ifconfig bat0 ' + response, password)		
		
		print 'Successfully Joined Network'
	except StormpathError, err:
		error = err.message