-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from phate999/master
Added Installer_UI and removed Boot2
- Loading branch information
Showing
274 changed files
with
105,666 additions
and
505 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
# Installer_UI - simple UI for installers to configure WiFi | ||
from csclient import EventingCSClient | ||
from flask import Flask, render_template, request, jsonify, send_from_directory | ||
import time | ||
import os | ||
from speedtest import Speedtest | ||
|
||
cp = EventingCSClient('Installer_UI') | ||
cp.log('Starting... edit Installer Password under System > SDK Data.') | ||
app = Flask(__name__) | ||
|
||
@app.route('/favicon.ico') | ||
def favicon(): | ||
return send_from_directory(os.path.join(app.root_path, 'static'), | ||
'favicon.ico', mimetype='image/vnd.microsoft.icon') | ||
@app.route('/') | ||
def index(): | ||
current_ssid = get_ssid() | ||
return render_template('index.html', current_ssid=current_ssid) | ||
|
||
@app.route('/save', methods=['POST']) | ||
def save(): | ||
installer_password = get_config('installer_password') | ||
wifi_ssid = request.form['wifi_ssid'] | ||
wifi_password = request.form['wifi_password'] | ||
password_entered = request.form['password_entered'] | ||
if not all([wifi_ssid, wifi_password, password_entered]): | ||
return jsonify({ | ||
'success': False, | ||
'result': 'Please enter all fields!' | ||
}) | ||
if password_entered == installer_password: | ||
cp.log(f'Installer changed WiFi SSID to {wifi_ssid} and password to {wifi_password}') | ||
cp.put(f'config/wlan/radio/0/bss/0/ssid', wifi_ssid) | ||
cp.put(f'config/wlan/radio/1/bss/0/ssid', wifi_ssid) | ||
cp.put(f'config/wlan/radio/0/bss/0/wpapsk', wifi_password) | ||
cp.put(f'config/wlan/radio/1/bss/0/wpapsk', wifi_password) | ||
return jsonify({ | ||
'success': True, | ||
'result': 'Success!\nRestarting WiFi...', | ||
'current_ssid': wifi_ssid | ||
}) | ||
else: | ||
cp.log('Incorrect password entered') | ||
return jsonify({ | ||
'success': False, | ||
'result': 'Incorrect Password!' | ||
}) | ||
|
||
@app.route('/speedtest', methods=['POST']) | ||
def speedtest(): | ||
installer_password = get_config('installer_password') | ||
password_entered = request.form['password_entered'] | ||
if password_entered == installer_password: | ||
result = run_speedtest() | ||
return jsonify({ | ||
'success': True, | ||
'result': result | ||
}) | ||
else: | ||
cp.log('Incorrect password entered') | ||
return jsonify({ | ||
'success': False, | ||
'result': 'Incorrect Password!' | ||
}) | ||
|
||
def run_speedtest(): | ||
try: | ||
cp.log('Starting Speedtest...') | ||
s = Speedtest() | ||
server = s.get_best_server() | ||
cp.log(f'Found Best Ookla Server: {server["sponsor"]}') | ||
cp.log("Performing Ookla Download Test...") | ||
d = s.download() | ||
cp.log("Performing Ookla Upload Test...") | ||
u = s.upload(pre_allocate=False) | ||
download = '{:.2f}'.format(d / 1000 / 1000) | ||
upload = '{:.2f}'.format(u / 1000 / 1000) | ||
cp.log('Ookla Speedtest Complete! Results:') | ||
cp.log(f'Client ISP: {s.results.client["isp"]}') | ||
cp.log(f'Ookla Server: {s.results.server["sponsor"]}') | ||
cp.log(f'Ping: {s.results.ping}ms') | ||
cp.log(f'Download Speed: {download}Mb/s') | ||
cp.log(f'Upload Speed: {upload} Mb/s') | ||
cp.log(f'Ookla Results Image: {s.results.share()}') | ||
text = f'{s.results.client["isp"]}\nDL:{download}Mbps\nUL:{upload}Mbps\nPing:{s.results.ping:.0f}ms' | ||
return text | ||
except Exception as e: | ||
cp.logger.exception(e) | ||
def get_ssid(): | ||
return cp.get('config/wlan/radio/1/bss/0/ssid') | ||
|
||
def get_config(name): | ||
appdata = cp.get('config/system/sdk/appdata') | ||
try: | ||
password = [x["value"] for x in appdata if x["name"] == name][0] | ||
except: | ||
password = cp.get('status/product_info/manufacturing/serial_num') | ||
cp.post('config/system/sdk/appdata', {"name": name, "value": password}) | ||
return password | ||
|
||
def open_firewall(): | ||
app_fwd = {"dst_zone_id": "00000001-695c-3d87-95cb-d0ee2029d0b5", "enabled": True, "filter_policy_id": "00000000-77db-3b20-980e-2de482869073", "src_zone_id": "00000003-695c-3d87-95cb-d0ee2029d0b5"} | ||
forwardings = cp.get('config/security/zfw/forwardings') | ||
for forwarding in forwardings: | ||
if forwarding['src_zone_id'] == app_fwd['src_zone_id'] and forwarding['dst_zone_id'] == app_fwd['dst_zone_id']: | ||
return | ||
cp.post('config/security/zfw/forwardings', app_fwd) | ||
cp.log('Forwarded Primary LAN Zone to Router Zone with Default Allow All policy') | ||
|
||
get_config('installer_password') | ||
open_firewall() | ||
while True: | ||
try: | ||
app.run(host='0.0.0.0', port=8000) | ||
except UnicodeError as e: | ||
cp.logger.exception(e) | ||
cp.log('Error starting webserver! Ensure hostname meets requirements for a valid hostname: (A-Z, 0-9 and -)') | ||
cp.log('Restarting server in 60 seconds...') | ||
time.sleep(60) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
# encoding: utf-8 | ||
# module _csv | ||
# from (pre-generated) | ||
# by generator 1.147 | ||
""" | ||
CSV parsing and writing. | ||
This module provides classes that assist in the reading and writing | ||
of Comma Separated Value (CSV) files, and implements the interface | ||
described by PEP 305. Although many CSV files are simple to parse, | ||
the format is not formally defined by a stable specification and | ||
is subtle enough that parsing lines of a CSV file with something | ||
like line.split(",") is bound to fail. The module supports three | ||
basic APIs: reading, writing, and registration of dialects. | ||
DIALECT REGISTRATION: | ||
Readers and writers support a dialect argument, which is a convenient | ||
handle on a group of settings. When the dialect argument is a string, | ||
it identifies one of the dialects previously registered with the module. | ||
If it is a class or instance, the attributes of the argument are used as | ||
the settings for the reader or writer: | ||
class excel: | ||
delimiter = ',' | ||
quotechar = '"' | ||
escapechar = None | ||
doublequote = True | ||
skipinitialspace = False | ||
lineterminator = '\r\n' | ||
quoting = QUOTE_MINIMAL | ||
SETTINGS: | ||
* quotechar - specifies a one-character string to use as the | ||
quoting character. It defaults to '"'. | ||
* delimiter - specifies a one-character string to use as the | ||
field separator. It defaults to ','. | ||
* skipinitialspace - specifies how to interpret whitespace which | ||
immediately follows a delimiter. It defaults to False, which | ||
means that whitespace immediately following a delimiter is part | ||
of the following field. | ||
* lineterminator - specifies the character sequence which should | ||
terminate rows. | ||
* quoting - controls when quotes should be generated by the writer. | ||
It can take on any of the following module constants: | ||
csv.QUOTE_MINIMAL means only when required, for example, when a | ||
field contains either the quotechar or the delimiter | ||
csv.QUOTE_ALL means that quotes are always placed around fields. | ||
csv.QUOTE_NONNUMERIC means that quotes are always placed around | ||
fields which do not parse as integers or floating point | ||
numbers. | ||
csv.QUOTE_NONE means that quotes are never placed around fields. | ||
* escapechar - specifies a one-character string used to escape | ||
the delimiter when quoting is set to QUOTE_NONE. | ||
* doublequote - controls the handling of quotes inside fields. When | ||
True, two consecutive quotes are interpreted as one during read, | ||
and when writing, each quote character embedded in the data is | ||
written as two quotes | ||
""" | ||
# no imports | ||
|
||
# Variables with simple values | ||
|
||
QUOTE_ALL = 1 | ||
QUOTE_MINIMAL = 0 | ||
QUOTE_NONE = 3 | ||
QUOTE_NONNUMERIC = 2 | ||
|
||
__version__ = '1.0' | ||
|
||
|
||
# functions | ||
|
||
def field_size_limit(limit=None): # real signature unknown; restored from __doc__ | ||
""" | ||
Sets an upper limit on parsed fields. | ||
csv.field_size_limit([limit]) | ||
Returns old limit. If limit is not given, no new limit is set and | ||
the old limit is returned | ||
""" | ||
pass | ||
|
||
|
||
def get_dialect(name): # real signature unknown; restored from __doc__ | ||
""" | ||
Return the dialect instance associated with name. | ||
dialect = csv.get_dialect(name) | ||
""" | ||
pass | ||
|
||
|
||
def list_dialects(): # real signature unknown; restored from __doc__ | ||
""" | ||
Return a list of all know dialect names. | ||
names = csv.list_dialects() | ||
""" | ||
pass | ||
|
||
|
||
def reader(iterable, dialect='excel', *args, **kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ | ||
""" | ||
csv_reader = reader(iterable [, dialect='excel'] | ||
[optional keyword args]) | ||
for row in csv_reader: | ||
process(row) | ||
The "iterable" argument can be any object that returns a line | ||
of input for each iteration, such as a file object or a list. The | ||
optional "dialect" parameter is discussed below. The function | ||
also accepts optional keyword arguments which override settings | ||
provided by the dialect. | ||
The returned object is an iterator. Each iteration returns a row | ||
of the CSV file (which can span multiple input lines). | ||
""" | ||
pass | ||
|
||
|
||
def register_dialect(name, dialect=None, **fmtparams): # real signature unknown; restored from __doc__ | ||
""" | ||
Create a mapping from a string name to a dialect class. | ||
dialect = csv.register_dialect(name[, dialect[, **fmtparams]]) | ||
""" | ||
pass | ||
|
||
|
||
def unregister_dialect(name): # real signature unknown; restored from __doc__ | ||
""" | ||
Delete the name/dialect mapping associated with a string name. | ||
csv.unregister_dialect(name) | ||
""" | ||
pass | ||
|
||
|
||
def writer(fileobj, dialect='excel', *args, | ||
**kwargs): # real signature unknown; NOTE: unreliably restored from __doc__ | ||
""" | ||
csv_writer = csv.writer(fileobj [, dialect='excel'] | ||
[optional keyword args]) | ||
for row in sequence: | ||
csv_writer.writerow(row) | ||
[or] | ||
csv_writer = csv.writer(fileobj [, dialect='excel'] | ||
[optional keyword args]) | ||
csv_writer.writerows(rows) | ||
The "fileobj" argument can be any object that supports the file API. | ||
""" | ||
pass | ||
|
||
|
||
# classes | ||
|
||
class Dialect(object): | ||
""" | ||
CSV dialect | ||
The Dialect type records CSV parsing and generation options. | ||
""" | ||
|
||
def __init__(self, *args, **kwargs): # real signature unknown | ||
pass | ||
|
||
@staticmethod # known case of __new__ | ||
def __new__(*args, **kwargs): # real signature unknown | ||
""" Create and return a new object. See help(type) for accurate signature. """ | ||
pass | ||
|
||
delimiter = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
doublequote = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
escapechar = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
lineterminator = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
quotechar = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
quoting = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
skipinitialspace = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
strict = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
|
||
|
||
class Error(Exception): | ||
# no doc | ||
def __init__(self, *args, **kwargs): # real signature unknown | ||
pass | ||
|
||
__weakref__ = property(lambda self: object(), lambda self, v: None, lambda self: None) # default | ||
"""list of weak references to the object (if defined)""" | ||
|
||
|
||
# variables with complex values | ||
|
||
_dialects = {} | ||
|
||
__loader__ = None # (!) real value is '<_frozen_importlib_external.ExtensionFileLoader object at 0x101941a20>' | ||
|
||
__spec__ = None # (!) real value is "ModuleSpec(name='_csv', loader=<_frozen_importlib_external.ExtensionFileLoader object at 0x101941a20>, origin='/opt/buildAgent/system/.persistent_cache/pycharm/pythons4skeletons/python36/lib/python3.6/lib-dynload/_csv.cpython-36m-darwin.so')" | ||
|
Oops, something went wrong.