[FIX] hw_drievrs: Replace SSID on the first boot
We replace the SSID of the IoTBox with a unique SSID closes odoo/odoo#46255 X-original-commit: c847c1cb149e386331ff2e5b19a58862e1b66714 Signed-off-by: Quentin Lejeune (qle) <qle@odoo.com>
This commit is contained in:
@@ -196,10 +196,12 @@ class DisplayController(http.Controller):
|
||||
if 'wlan' in iface_id or 'eth' in iface_id:
|
||||
iface_obj = ni.ifaddresses(iface_id)
|
||||
ifconfigs = iface_obj.get(ni.AF_INET, [])
|
||||
essid = helpers.get_ssid()
|
||||
for conf in ifconfigs:
|
||||
if conf.get('addr'):
|
||||
display_ifaces.append({
|
||||
'iface_id': iface_id,
|
||||
'essid': essid,
|
||||
'addr': conf.get('addr'),
|
||||
'icon': 'sitemap' if 'eth' in iface_id else 'wifi',
|
||||
})
|
||||
|
||||
@@ -233,15 +233,8 @@ class PrinterDriver(Driver):
|
||||
mac = ''
|
||||
homepage = ''
|
||||
|
||||
hosting_ap = os.system('pgrep hostapd') == 0
|
||||
ssid = helpers.get_ssid()
|
||||
if hosting_ap:
|
||||
with open('/root_bypass_ramdisks/etc/hostapd/hostapd.conf') as config_file:
|
||||
lines = config_file.readlines()
|
||||
ssid = lines[1].split("=")[1].replace("\n", "")
|
||||
wlan = '\nWireless network:\n%s\n\n' % ssid
|
||||
elif ssid:
|
||||
wlan = '\nWireless network:\n%s\n\n' % ssid
|
||||
wlan = '\nWireless network:\n%s\n\n' % ssid
|
||||
|
||||
interfaces = ni.interfaces()
|
||||
ips = []
|
||||
|
||||
@@ -129,6 +129,9 @@ def get_mac_address():
|
||||
return netifaces.ifaddresses('wlan0')[netifaces.AF_LINK][0]['addr']
|
||||
|
||||
def get_ssid():
|
||||
ap = subprocess.call(['systemctl', 'is-active', 'hostapd']) # if service is active return 0 else inactive
|
||||
if not ap:
|
||||
return subprocess.check_output(['grep', '-oP', '(?<=ssid=).*', '/etc/hostapd/hostapd.conf']).decode('utf-8').rstrip()
|
||||
process_iwconfig = subprocess.Popen(['iwconfig'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||
process_grep = subprocess.Popen(['grep', 'ESSID:"'], stdin=process_iwconfig.stdout, stdout=subprocess.PIPE)
|
||||
return subprocess.check_output(['sed', 's/.*"\\(.*\\)"/\\1/'], stdin=process_grep.stdout).decode('utf-8').rstrip()
|
||||
|
||||
@@ -60,7 +60,7 @@
|
||||
<tbody>
|
||||
{% for display_iface in display_ifaces -%}
|
||||
<tr>
|
||||
<td><i class="fa fa-{{ display_iface.icon }}"></i></td>
|
||||
<td><i class="fa fa-{{ display_iface.icon }}"/> {{ display_iface.essid }}</td>
|
||||
<td>{{ display_iface.addr }}</td>
|
||||
</tr>
|
||||
{%- endfor %}
|
||||
|
||||
@@ -21,6 +21,16 @@ if [ -z "${WIRED_IP}" ] ; then
|
||||
else
|
||||
logger -t posbox_wireless_ap "Starting AP"
|
||||
|
||||
SSID=$(grep -oP '(?<=ssid=).*' /etc/hostapd/hostapd.conf)
|
||||
|
||||
if [ "${SSID}" = "IoTBox" ]
|
||||
then
|
||||
# override SSID to get a unique SSID
|
||||
MAC=$(ip link show wlan0 | tail -n 1 | awk '{print $2}' | sed 's/\://g')
|
||||
NEWSSID="${SSID}-${MAC}"
|
||||
sed -ie "s/$(echo ${SSID})/$(echo ${NEWSSID})/g" /etc/hostapd/hostapd.conf
|
||||
fi
|
||||
|
||||
service hostapd restart
|
||||
|
||||
ip addr add 10.11.12.1/24 dev wlan0
|
||||
|
||||
Reference in New Issue
Block a user