Ejemplo n.º 1
0
def main():
    setup()

    bus = pydbus.SystemBus()

    pattern_include = re.compile("wlan*")
    pattern_exclude = re.compile("ScreenlyOSE-*")

    wireless_connections = filter(
        lambda c: not pattern_exclude.search(str(c['Id'])),
        filter(
            lambda c: pattern_include.search(str(c['Devices'])),
            get_active_connections(bus)
        )
    )

    # Displays the hotspot page
    if not path.isfile(HOME + INITIALIZED_FILE) and not gateways().get('default'):
        if wireless_connections is None or len(wireless_connections) == 0:
            url = 'http://{0}/hotspot'.format(LISTEN)
            load_browser(url=url)

    # Wait until the network is configured
    while not path.isfile(HOME + INITIALIZED_FILE) and not gateways().get('default'):
        if len(wireless_connections) == 0:
            sleep(1)
            wireless_connections = filter(
                lambda c: not pattern_exclude.search(str(c['Id'])),
                filter(
                    lambda c: pattern_include.search(str(c['Devices'])),
                    get_active_connections(bus)
                )
            )
            continue
        if wireless_connections is None:
            sleep(1)
            continue
        break

    wait_for_node_ip(5)

    url = 'http://{0}:{1}/splash_page'.format(LISTEN, PORT) if settings['show_splash'] else 'file://' + BLACK_PAGE
    browser_url(url=url)

    if settings['show_splash']:
        sleep(SPLASH_DELAY)

    global scheduler
    scheduler = Scheduler()

    subscriber = ZmqSubscriber()
    subscriber.daemon = True
    subscriber.start()

    # We don't want to show splash_page if there are active assets but all of them are not available
    view_image(HOME + LOAD_SCREEN)

    logging.debug('Entering infinite loop.')
    while True:
        asset_loop(scheduler)
Ejemplo n.º 2
0
def setup_hotspot():
    bus = pydbus.SystemBus()

    pattern_include = re.compile("wlan*")
    pattern_exclude = re.compile("ScreenlyOSE-*")

    wireless_connections = filter(
        lambda c: not pattern_exclude.search(str(c['Id'])),
        filter(lambda c: pattern_include.search(str(c['Devices'])),
               get_active_connections(bus)))

    # Displays the hotspot page
    if not path.isfile(HOME +
                       INITIALIZED_FILE) and not gateways().get('default'):
        if wireless_connections is None or len(wireless_connections) == 0:
            url = 'http://{0}/hotspot'.format(LISTEN)
            load_browser(url=url)

    # Wait until the network is configured
    while not path.isfile(HOME +
                          INITIALIZED_FILE) and not gateways().get('default'):
        if len(wireless_connections) == 0:
            sleep(1)
            wireless_connections = filter(
                lambda c: not pattern_exclude.search(str(c['Id'])),
                filter(lambda c: pattern_include.search(str(c['Devices'])),
                       get_active_connections(bus)))
            continue
        if wireless_connections is None:
            sleep(1)
            continue
        break
Ejemplo n.º 3
0
    def get(self):
        home = getenv('HOME')
        file_path = path.join(home, '.screenly/initialized')

        if path.isfile(file_path):
            remove(file_path)

        bus = pydbus.SystemBus()

        pattern_include = re.compile("wlan*")
        pattern_exclude = re.compile("ScreenlyOSE-*")

        wireless_connections = get_active_connections(bus)

        if wireless_connections is not None:
            device_uuid = None

            wireless_connections = filter(
                lambda c: not pattern_exclude.search(str(c['Id'])),
                filter(lambda c: pattern_include.search(str(c['Devices'])),
                       wireless_connections))

            if len(wireless_connections) > 0:
                device_uuid = wireless_connections[0].get('Uuid')

            if not device_uuid:
                raise Exception('The device has no active connection.')

            remove_connection(bus, device_uuid)

        return '', 204
Ejemplo n.º 4
0
    def get(self):
        home = getenv('HOME')
        file_path = path.join(home, '.screenly/initialized')

        if path.isfile(file_path):
            remove(file_path)

        bus = pydbus.SystemBus()

        pattern_include = re.compile("wlan*")
        pattern_exclude = re.compile("ScreenlyOSE-*")

        wireless_connections = filter(
            lambda c: not pattern_exclude.search(str(c['Id'])),
            filter(
                lambda c: pattern_include.search(str(c['Devices'])),
                get_active_connections(bus)
            )
        )

        if wireless_connections is not None:
            device_uuid = None

            if len(wireless_connections) > 0:
                device_uuid = wireless_connections[0].get('Uuid')

            if not device_uuid:
                raise Exception('The device has no active connection.')

            remove_connection(bus, device_uuid)

        return '', 204
Ejemplo n.º 5
0
def setup_hotspot():
    bus = pydbus.SystemBus()

    pattern_include = re.compile("wlan*")
    pattern_exclude = re.compile("ScreenlyOSE-*")

    wireless_connections = filter(
        lambda c: not pattern_exclude.search(str(c['Id'])),
        filter(
            lambda c: pattern_include.search(str(c['Devices'])),
            get_active_connections(bus)
        )
    )

    # Displays the hotspot page
    if not path.isfile(HOME + INITIALIZED_FILE) and not gateways().get('default'):
        if wireless_connections is None or len(wireless_connections) == 0:
            url = 'http://{0}/hotspot'.format(LISTEN)
            load_browser(url=url)

    # Wait until the network is configured
    while not path.isfile(HOME + INITIALIZED_FILE) and not gateways().get('default'):
        if len(wireless_connections) == 0:
            sleep(1)
            wireless_connections = filter(
                lambda c: not pattern_exclude.search(str(c['Id'])),
                filter(
                    lambda c: pattern_include.search(str(c['Devices'])),
                    get_active_connections(bus)
                )
            )
            continue
        if wireless_connections is None:
            sleep(1)
            continue
        break
Ejemplo n.º 6
0
    with open(template_path) as f:
        template = Template(f.read())

    context = {'network': ssid, 'ssid_pswd': pswd, 'address': address}

    with open('/tmp/hotspot.html', 'w') as out_file:
        out_file.write(template.render(context=context))


if __name__ == "__main__":
    bus = pydbus.SystemBus()

    pattern_include = re.compile("wlan*")
    pattern_exclude = re.compile("ScreenlyOSE-*")

    wireless_connections = get_active_connections(bus)

    if wireless_connections is None:
        exit()

    wireless_connections = filter(
        lambda c: not pattern_exclude.search(str(c['Id'])),
        filter(lambda c: pattern_include.search(str(c['Devices'])),
               wireless_connections))

    if not gateways().get('default') and filter(pattern_include.match,
                                                interfaces()):
        if len(wireless_connections) == 0:
            ssid = 'mktronik-WLAN-{}'.format(
                generate_perfect_paper_password(pw_length=4,
                                                has_symbols=False))
Ejemplo n.º 7
0
    context = {'network': ssid, 'ssid_pswd': pswd, 'address': address}

    with open('/tmp/hotspot.html', 'w') as out_file:
        out_file.write(template.render(context=context))


if __name__ == "__main__":
    bus = pydbus.SystemBus()

    pattern_include = re.compile("wlan*")
    pattern_exclude = re.compile("ScreenlyOSE-*")

    wireless_connections = filter(
        lambda c: not pattern_exclude.search(str(c['Id'])),
        filter(lambda c: pattern_include.search(str(c['Devices'])),
               get_active_connections(bus)))

    if not gateways().get('default') and filter(pattern_include.match,
                                                interfaces()):
        if wireless_connections is None or len(wireless_connections) == 0:
            ssid = 'ScreenlyOSE-{}'.format(
                generate_perfect_paper_password(pw_length=4,
                                                has_symbols=False))
            ssid_password = generate_perfect_paper_password(pw_length=8,
                                                            has_symbols=False)
            generate_page(ssid, ssid_password, 'screenly.io/wifi')

            wifi_connect = sh.sudo('wifi-connect', '-s', ssid, '-p',
                                   ssid_password, '-o', '9090')
    else:
        pass
Ejemplo n.º 8
0
        'address': address
    }

    with open('/tmp/hotspot.html', 'w') as out_file:
        out_file.write(template.render(context=context))


if __name__ == "__main__":
    bus = pydbus.SystemBus()

    pattern_include = re.compile("wlan*")
    pattern_exclude = re.compile("ScreenlyOSE-*")

    wireless_connections = filter(
        lambda c: not pattern_exclude.search(str(c['Id'])),
        filter(
            lambda c: pattern_include.search(str(c['Devices'])),
            get_active_connections(bus)
        )
    )

    if not gateways().get('default') and filter(pattern_include.match, interfaces()):
        if wireless_connections is None or len(wireless_connections) == 0:
            ssid = 'ScreenlyOSE-{}'.format(generate_perfect_paper_password(pw_length=4, has_symbols=False))
            ssid_password = generate_perfect_paper_password(pw_length=8, has_symbols=False)
            generate_page(ssid, ssid_password, 'screenly.io/wifi')

            wifi_connect = sh.sudo('wifi-connect', '-s', ssid, '-p', ssid_password, '-o', '9090')
    else:
        pass