def networkUI(): net_dic = get_nets() x = list_apps() html = render_template('network.html', net_dic = net_dic) return render_template('config.html', netui = html, list_apps = x, current_app = default_app, netui_dir = 'config', update=check_update_api())
def connect(): ssid = request.form['ssid'] if 'pwd' in request.form: password = request.form['pwd'] else: password = '' log.add_log(f'/Wants to connect to SSID {ssid} with password {password}.') command = f'nmcli device wifi connect "{ssid}" password {password}' output = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) stdout, stderr = output.communicate() log.add_debug(f'stdout: {stdout}') log.add_debug(f'stderr: {stderr}') # Try to connect to the SSID if 'Error' in str(stdout): # Error handling. log.add_exception( f'/sys_ajax_net_connect_wpa could not connect to {ssid} with password {password}. stderr: {stderr}') msg = f"Couldn't connect to wi-fi network {ssid}" else: log.add_log(f'/sys_ajax_net_connect_wpa connected to {ssid} with password {password}. stdout: {stdout}') msg='' net_dic = get_nets() x = list_apps() html = render_template('network.html', net_dic = net_dic, msg=msg) return render_template('config.html', netui = html, list_apps = x, current_app = default_app, netui_dir = 'config', msg=msg, update=check_update_api())
def ajax_ui_endpoint(): l = list_apps() l = [i.replace('_', ' ') for i in l] # Javascript accesses this endpoint, gets the HTML, and renders it in the block return jsonify({ 'html': render_template("frameUnit/__modeSelector.html", current_app=default_app(), list_apps=l) })
def download(): id = request.args.get('id', default='0', type=int) filename = wget.download('http://{}/query?id={}'.format(store_ip, id)) # Json with two parts: meta and base64 tar.xz file. with open(filename) as f: struc = json.load(f) meta = struc['meta'] program = struc['program'] write_b64_to_file('database/tmp/{}.tree'.format(meta['name']), program) os.remove(filename) install('{}.tree'.format(meta['name'])) return render_template('config.html', list_apps = list_apps(), current_app = default_app(), up_to_date = True)
def disconnect(): # Disconnect from a wifi network in the post request. ssid = request.form['ssid'] print("Disconnecting from ", ssid) command = f'nmcli connection delete id {ssid}' output = Popen(command, shell=True, stdout=PIPE, stderr=PIPE) stdout, stderr = output.communicate() log.add_debug(f'stdout: {stdout}') log.add_debug(f'stderr: {stderr}') net_dic = get_nets() x = list_apps() html = render_template('network.html', net_dic=net_dic) return render_template('config.html', netui=html, list_apps=x, current_app=default_app, netui_dir='config', update=check_update_api())