コード例 #1
0
def show_netconfig():
	ifaces = netifaces.interfaces()
	config_ifaces = config['interfaces']
	addrs = {}
	for ni in ifaces:
		try:
			addrs[ni] = netifaces.ifaddresses(ni)[netifaces.AF_INET][0]['addr']
		except KeyError:
			addrs[ni] = 'None'
			pass

	gateway = 'None'
	gws = netifaces.gateways()
	if 'default' in gws and netifaces.AF_INET in gws['default']:
		gateway = gws['default'][netifaces.AF_INET][0]

	essids = {}
	for ni in ifaces:
		essids[ni] = ''
		if ni in config_ifaces:
			if config_ifaces[ni] == 'wpa':
				wpa = wpa_supplicant(ni)
				status = wpa.status()
				if status['wpa_state'] == 'COMPLETED':
					essids[ni] = status['ssid']

	dnslist = get_dns()

	return render_template('netconfig.html',
		ifaces=ifaces, addrs=addrs, gateway=gateway,
		essids=essids, dns=dnslist[0], config_ifaces=config_ifaces)
コード例 #2
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def show_wpa_select():
	iface = request.args.get('iface')
	nwid = request.args.get('id')
	wpa = wpa_supplicant(iface)
	wpa.select_network(nwid)
	return render_template('wpa_status.html',
		iface=iface,
		menu = menu_add_params(wpa_menu, {"iface" : iface}), active_name="status")
コード例 #3
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def api_wpa_status():
	iface = request.args.get('iface')
	getbss = request.args.get('getbss')
	getaddrs = request.args.get('getaddrs')
	wpa = wpa_supplicant(iface)
	status = wpa.status()
	if getbss != None and 'bssid' in status:
		status['bss'] = wpa.bss(status['bssid'])
	if getaddrs != None:
		status['addrs'] = _net_addr(iface)

	return json.dumps(status)
コード例 #4
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def show_wpa_remove_network():
	iface = request.args.get('iface')
	ssid = request.args.get('ssid', '')

	conf = wpaconf.parse('/etc/wpa_supplicant/wpa_supplicant.conf')
	wpaconf.remove_network(conf, ssid)
	wpaconf.unparse(conf, '/etc/wpa_supplicant/wpa_supplicant.conf')

	if iface != None:
		wpa = wpa_supplicant(iface)
		wpa.wpa_cli('reconfigure')

	names = wpaconf_networks(conf)
	return render_template('networks.html', networks=names, iface=iface,
		menu = menu_add_params(wpa_menu, {"iface" : iface}), active_name="networks")
コード例 #5
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def api_wpaconf_setnetwork():
	iface = request.args.get('iface')

	name = request.args.get('name')
	passwd = request.args.get('password')

	conf = wpaconf.parse('/etc/wpa_supplicant/wpa_supplicant.conf')
	wpaconf.setnetwork(conf, name, passwd)
	wpaconf.unparse(conf, '/etc/wpa_supplicant/wpa_supplicant.conf')

	if iface != None:
		wpa = wpa_supplicant(iface)
		wpa.wpa_cli('reconfigure')

	return json.dumps('OK')
コード例 #6
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def show_netconfig():
	ifaces = netifaces.interfaces()
	config_ifaces = config['interfaces']
	addrs = {}
	for ni in ifaces:
		try:
			addrs[ni] = netifaces.ifaddresses(ni)[netifaces.AF_INET][0]['addr']
		except KeyError:
			addrs[ni] = 'None'
			pass

	gateway = 'None'
	gws = netifaces.gateways()
	if 'default' in gws and netifaces.AF_INET in gws['default']:
		gateway = gws['default'][netifaces.AF_INET][0]

	essids = {}
	for ni in ifaces:
		essids[ni] = ''
		if ni in config_ifaces:
			if config_ifaces[ni].lower() == 'wpa':
				try:
					wpa = wpa_supplicant(ni)
					status = wpa.status()
					if status['wpa_state'] == 'COMPLETED':
						essids[ni] = status['ssid']
				except:
					pass
			elif config_ifaces[ni].upper() == 'AP':
				ha = hostapd(ni)
				ha_config = ha.get_config()
				try:
					essids[ni] = ha_config['ssid']
				except KeyError:
					pass

	dnslist = get_dns()

	return render_template('netconfig.html',
		ifaces=ifaces, addrs=addrs, gateway=gateway,
		essids=essids, dns=dnslist[0], config_ifaces=config_ifaces,
		menu=main_menu, active_name="main")
コード例 #7
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def _wpa_scan_list(iface):
	wpa = wpa_supplicant(iface)
	scan_list = wpa.scan_results()

	nwlist = wpa.list_networks()
	nwdict = {}
	for nw in nwlist:
		nwdict[nw['ssid']] = nw

	for bss in scan_list:
		ssid = bss['ssid']
		if ssid in nwdict and ( nwdict[ssid]['bssid'] == 'any' or nwdict[ssid]['bssid'] == bss['bssid'] ):
			bss['nwid'] = nwdict[ssid]['id']

		level = int(bss['level'])
		# different drivers report different ranges - attempt to make it consistent
		if level < 0:
			level += 110
		bss['color'] = _range2color(level, 20, 80)

	return scan_list
コード例 #8
0
def show_wpa_scan():
	iface = request.args.get('iface')
	wpa = wpa_supplicant(iface)
	result = wpa.scan_results()

	nwlist = wpa.list_networks()
	nwdict = {}
	for i in range(0, len(nwlist)-1):
		nwdict[nwlist[i]['ssid']] = nwlist[i]

	for i in range(0, len(result)):
		ssid = result[i]['ssid']
		if ssid in nwdict and ( nwdict[ssid]['bssid'] == 'any' or nwdict[ssid]['bssid'] == result[i]['bssid'] ):
			result[i]['nwid'] = nwdict[ssid]['id']

		level = int(result[i]['level'])
		# different drivers report different ranges - attempt to make it consistent
		if level < 0:
			level += 110
		result[i]['color'] = _range2color(level, 20, 80)

	return render_template('scan.html', iface=iface, bss_list=result)
コード例 #9
0
def api_wpa_bss():
	iface = request.args.get('iface')
	id = request.args.get('id')
	wpa = wpa_supplicant(iface)
	return json.dumps(wpa.bss(id))
コード例 #10
0
def api_wpa_select_network():
	iface = request.args.get('iface')
	nwid = request.args.get('id')
	wpa = wpa_supplicant(iface)
	wpa.select_network(nwid)
	return json.dumps('OK')
コード例 #11
0
def api_wpa_scan_results():
	iface = request.args.get('iface')
	wpa = wpa_supplicant(iface)
	result = wpa.scan_results()
	return json.dumps(result)
コード例 #12
0
def api_wpa_status():
	iface = request.args.get('iface')
	wpa = wpa_supplicant(iface)
	return json.dumps(wpa.status())
コード例 #13
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def api_wpa_select_network():
	iface = request.args.get('iface')
	nwid = request.args.get('id')
	wpa = wpa_supplicant(iface)
	wpa.select_network(nwid)
	return json.dumps('OK')
コード例 #14
0
def show_wpa_select():
	iface = request.args.get('iface')
	nwid = request.args.get('id')
	wpa = wpa_supplicant(iface)
	wpa.select_network(nwid)
	return _wpa_status(wpa, iface)
コード例 #15
0
def show_wpa_disconnect():
	iface = request.args.get('iface')
	wpa = wpa_supplicant(iface)
	wpa.disconnect(iface)
	return _wpa_status(wpa, iface)
コード例 #16
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def api_wpa_scan_results():
	iface = request.args.get('iface')
	wpa = wpa_supplicant(iface)
	result = wpa.scan_results()
	return json.dumps(result)
コード例 #17
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def api_wpa_disconnect():
	iface = request.args.get('iface')
	wpa = wpa_supplicant(iface)
	wpa.disconnect(iface)
	return json.dumps('OK')
コード例 #18
0
ファイル: main.py プロジェクト: oliverkurth/pypiwifi
def api_wpa_bss():
	iface = request.args.get('iface')
	id = request.args.get('id')
	wpa = wpa_supplicant(iface)
	return json.dumps(wpa.bss(id))