paradrop.backend package¶
Submodules¶
paradrop.backend.airshark_api module¶
APIs for developers to check whether Airshark feature is available or not
-
class
AirsharkApi
(airshark_manager)[source]¶ Bases:
object
-
routes
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
paradrop.backend.airshark_ws module¶
-
class
AirsharkAnalyzerFactory
(airshark_manager, *args, **kwargs)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerFactory
-
buildProtocol
(addr)[source]¶ Create an instance of a subclass of Protocol.
The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.
Alternatively, C{None} may be returned to immediately close the new connection.
Override this method to alter how Protocol instances get created.
@param addr: an object implementing L{twisted.internet.interfaces.IAddress}
-
-
class
AirsharkAnalyzerProtocol
(factory)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerProtocol
-
class
AirsharkSpectrumFactory
(airshark_manager, *args, **kwargs)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerFactory
-
buildProtocol
(addr)[source]¶ Create an instance of a subclass of Protocol.
The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.
Alternatively, C{None} may be returned to immediately close the new connection.
Override this method to alter how Protocol instances get created.
@param addr: an object implementing L{twisted.internet.interfaces.IAddress}
-
paradrop.backend.auth module¶
-
class
AuthApi
(password_manager, token_manager)[source]¶ Bases:
object
-
auth_cloud
(request)[source]¶ Login using credentials from the cloud controller.
This is an experimental new login method that lets users present a token that they received from the cloud controller as a login credential for a node. The idea is to enable easy access for multiple developers to share a node, for example, during a tutorial.
Instead of a username/password, the user presents a token received from the cloud controller. The verify_cloud_token function verifies the validity of the token with the controller, and if successful, retrieves information about the bearer, particularly the username and role. Finally, we generate a new token that enables the user to authenticate with local API endpoints.
-
routes
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
-
get_username_password
(userpass)[source]¶ Please note: username and password can either be presented in plain text such as “admin:password” or base64 encoded such as “YWRtaW46cGFzc3dvcmQ=”. Both forms should be returned from this function.
paradrop.backend.chute_api module¶
Install and manage chutes on the host.
Endpoints for these functions can be found under /api/v1/chutes.
-
class
ChuteApi
(update_manager)[source]¶ Bases:
object
-
get_chute
(request, chute)[source]¶ Get information about an installed chute.
Example request:
GET /api/v1/chutes/hello-world
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "environment": {}, "name": "hello-world", "allocation": { "cpu_shares": 1024, "prioritize_traffic": false }, "state": "running", "version": "x1511808778", "resources": null }
-
get_chute_cache
(request, chute)[source]¶ Get chute cache contents.
The chute cache is a key-value store used during chute installation. It can be useful for debugging the Paradrop platform.
-
get_chute_config
(request, chute)[source]¶ Get current chute configuration.
Example request:
GET /api/v1/chutes/captive-portal/config
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "net": { "wifi": { "dhcp": { "lease": "1h", "limit": 250, "start": 3 }, "intfName": "wlan0", "options": { "isolate": True }, "ssid": "Free WiFi", "type": "wifi" } } }
-
get_chutes
(request)[source]¶ List installed chutes.
Example request:
GET /api/v1/chutes/
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ { "environment": {}, "name": "hello-world", "allocation": { "cpu_shares": 1024, "prioritize_traffic": false }, "state": "running", "version": "x1511808778", "resources": null } ]
-
get_hostapd_status
(request, chute, network)[source]¶ Get low-level status information from the access point.
Example request:
GET /api/v1/chutes/captive-portal/networks/wifi/hostapd_status
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "olbc_ht": "0", "cac_time_left_seconds": "N/A", "num_sta_no_short_slot_time": "0", "olbc": "1", "num_sta_non_erp": "0", "ht_op_mode": "0x4", "state": "ENABLED", "num_sta_ht40_intolerant": "0", "channel": "11", "bssid[0]": "02:00:08:24:03:dd", "ieee80211n": "1", "cac_time_seconds": "0", "num_sta[0]": "1", "ieee80211ac": "0", "phy": "phy0", "num_sta_ht_no_gf": "1", "freq": "2462", "num_sta_ht_20_mhz": "1", "num_sta_no_short_preamble": "0", "secondary_channel": "0", "ssid[0]": "Free WiFi", "num_sta_no_ht": "0", "bss[0]": "vwlan7e1b" }
-
get_leases
(request, chute, network)[source]¶ Get current list of DHCP leases for chute network.
Returns a list of DHCP lease records with the following fields:
- expires
- lease expiration time (seconds since Unix epoch)
- mac_addr
- device MAC address
- ip_addr
- device IP address
- hostname
- name that the device reported
- client_id
- optional identifier supplied by device
Example request:
GET /api/v1/chutes/captive-portal/networks/wifi/leases
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ { "client_id": "01:5c:59:48:7d:b9:e6", "expires": "1511816276", "ip_addr": "192.168.128.64", "mac_addr": "5c:59:48:7d:b9:e6", "hostname": "paradrops-iPod" } ]
-
get_network
(request, chute, network)[source]¶ Get information about a network configured for the chute.
Example request:
GET /api/v1/chutes/captive-portal/networks/wifi
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "interface": "wlan0", "type": "wifi", "name": "wifi" }
-
get_networks
(request, chute)[source]¶ Get list of networks configured for the chute.
Example request:
GET /api/v1/chutes/captive-portal/networks
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ { "interface": "wlan0", "type": "wifi", "name": "wifi" } ]
-
get_ssid
(request, chute, network)[source]¶ Get currently configured SSID for the chute network.
Example request:
GET /api/v1/chutes/captive-portal/networks/wifi/ssid
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "ssid": "Free WiFi", "bssid": "02:00:08:24:03:dd" }
-
get_station
(request, chute, network, mac)[source]¶ Get detailed information about a connected station.
Example request:
GET /api/v1/chutes/captive-portal/networks/wifi/stations/5c:59:48:7d:b9:e6
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "rx_packets": "230", "tdls_peer": "no", "authenticated": "yes", "rx_bytes": "12511", "tx_bitrate": "1.0 MBit/s", "tx_retries": "0", "signal": "-45 [-49, -48] dBm", "authorized": "yes", "rx_bitrate": "65.0 MBit/s MCS 7", "mfp": "no", "tx_failed": "0", "inactive_time": "4688 ms", "mac_addr": "5c:59:48:7d:b9:e6", "tx_bytes": "34176", "wmm_wme": "yes", "preamble": "short", "tx_packets": "88", "signal_avg": "-44 [-48, -47] dBm" }
-
get_stations
(request, chute, network)[source]¶ Get detailed information about connected wireless stations.
Example request:
GET /api/v1/chutes/captive-portal/networks/wifi/stations
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ { "rx_packets": "230", "tdls_peer": "no", "authenticated": "yes", "rx_bytes": "12511", "tx_bitrate": "1.0 MBit/s", "tx_retries": "0", "signal": "-45 [-49, -48] dBm", "authorized": "yes", "rx_bitrate": "65.0 MBit/s MCS 7", "mfp": "no", "tx_failed": "0", "inactive_time": "4688 ms", "mac_addr": "5c:59:48:7d:b9:e6", "tx_bytes": "34176", "wmm_wme": "yes", "preamble": "short", "tx_packets": "88", "signal_avg": "-44 [-48, -47] dBm" } ]
-
routes
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
set_chute_config
(request, chute)[source]¶ Update the chute configuration and restart to apply changes.
Example request:
PUT /api/v1/chutes/captive-portal/config Content-Type: application/json { "net": { "wifi": { "dhcp": { "lease": "1h", "limit": 250, "start": 3 }, "intfName": "wlan0", "options": { "isolate": True }, "ssid": "Better Free WiFi", "type": "wifi" } } }
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "change_id": 1 }
-
set_ssid
(request, chute, network)[source]¶ Change the configured SSID for the chute network.
The change will not persist after a reboot. If a persistent change is desired, you should update the chute configuration instead.
Example request:
PUT /api/v1/chutes/captive-portal/networks/wifi/ssid Content-Type: application/json { "ssid": "Best Free WiFi" }
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "message": "OK" }
-
-
class
ChuteCacheEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
JSON encoder for chute cache dictionary.
The chute cache can contain arbitrary objects, some of which may not be JSON-serializable. This encoder returns handles unserializable objects by returning the repr string.
-
default
(o)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
ChuteEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
-
default
(o)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
class
UpdateEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
-
default
(o)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
paradrop.backend.config_api module¶
This module exposes device configuration.
Endpoints for these functions can be found under /api/v1/config.
-
class
ConfigApi
(update_manager, update_fetcher)[source]¶ Bases:
object
Configuration API.
This class handles HTTP API calls related to router configuration.
-
get_hostconfig
(request)[source]¶ Get the device’s current host configuration.
Example request:
GET /api/v1/config/hostconfig
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "firewall": { "defaults": { "forward": "ACCEPT", "input": "ACCEPT", "output": "ACCEPT" } }, ... }
For a complete example, please see the Host Configuration section.
-
get_pdid
(request)[source]¶ Get the device’s current ParaDrop ID. This is the identifier assigned by the cloud controller.
Example request:
GET /api/v1/config/pdid
Example response:
HTTP/1.1 200 OK Content-Type: application/json { pdid: "5890e1e5ab7e317e6c6e049f" }
-
get_settings
(request)[source]¶ Get current values of system settings.
These are the values from paradrop.base.settings. Settings are loaded at system initialization from the settings.ini file and environment variables. They are intended to be read-only after initialization.
This endpoint returns the settings as a dictionary with lowercase field names.
Example: {
“portal_server_port”: 8080, …}
-
new_config
(request)[source]¶ Generate a new node configuration based on the hardware.
Example request:
GET /api/v1/config/new_config
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "firewall": { "defaults": { "forward": "ACCEPT", "input": "ACCEPT", "output": "ACCEPT" } }, ... }
For a complete example, please see the Host Configuration section.
-
pdconf
(request)[source]¶ Get configuration sections from pdconf.
This returns a list of configuration sections and whether they were successfully applied. This is intended for debugging purposes.
-
pdconf_reload
(request)[source]¶ Trigger pdconf to reload UCI configuration files.
Trigger pdconf to reload UCI configuration files and return the status. This function is intended for low-level debugging of the paradrop pdconf module.
-
routes
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
update_hostconfig
(request)[source]¶ Replace the device’s host configuration.
Example request:
PUT /api/v1/config/hostconfig Content-Type: application/json { "firewall": { "defaults": { "forward": "ACCEPT", "input": "ACCEPT", "output": "ACCEPT" } }, ... }
Example response:
HTTP/1.1 200 OK Content-Type: application/json { change_id: 1 }
For a complete example, please see the Host Configuration section.
-
paradrop.backend.cors module¶
Write the CROSS-ORIGIN RESOURCE SHARING headers required Reference: http://msoulier.wordpress.com/2010/06/05/cross-origin-requests-in-twisted/
paradrop.backend.http_server module¶
The HTTP server to serve local portal and provide RESTful APIs
-
class
HttpServer
(update_manager, update_fetcher, airshark_manager, portal_dir=None)[source]¶ Bases:
object
-
app
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
paradrop.backend.information_api module¶
Provide information of the router, e.g. board version, CPU information, memory size, disk size.
Endpoints for these functions can be found under /api/v1/info.
-
class
InformationApi
[source]¶ Bases:
object
-
get_environment
(request)[source]¶ Get environment variables.
Returns a dictionary containing the environment variables passed to the Paradrop daemon. This is useful for development and debugging purposes (e.g. see how PATH is set on Paradrop when running in different contexts).
Example request:
GET /api/v1/info/environment
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "LANG": "C.UTF-8", "SNAP_REVISION": "x73", "SNAP_COMMON": "/var/snap/paradrop-daemon/common", "XDG_RUNTIME_DIR": "/run/user/0/snap.paradrop-daemon", "SNAP_USER_COMMON": "/root/snap/paradrop-daemon/common", "SNAP_LIBRARY_PATH": "/var/lib/snapd/lib/gl:/var/lib/snapd/void", "SNAP_NAME": "paradrop-daemon", "PWD": "/var/snap/paradrop-daemon/x73", "PATH": "/snap/paradrop-daemon/x73/usr/sbin:/snap/paradrop-daemon/x73/usr/bin:/snap/paradrop-daemon/x73/sbin:/snap/paradrop-daemon/x73/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games", "SNAP": "/snap/paradrop-daemon/x73", "SNAP_DATA": "/var/snap/paradrop-daemon/x73", "SNAP_VERSION": "0.9.2", "SNAP_ARCH": "amd64", "SNAP_USER_DATA": "/root/snap/paradrop-daemon/x73", "TEMPDIR": "/tmp", "HOME": "/root/snap/paradrop-daemon/x73", "SNAP_REEXEC": "", "LD_LIBRARY_PATH": "/var/lib/snapd/lib/gl:/var/lib/snapd/void:/snap/paradrop-daemon/x73/usr/lib/x86_64-linux-gnu::/snap/paradrop-daemon/x73/lib:/snap/paradrop-daemon/x73/usr/lib:/snap/paradrop-daemon/x73/lib/x86_64-linux-gnu:/snap/paradrop-daemon/x73/usr/lib/x86_64-linux-gnu", "TMPDIR": "/tmp" ... }
-
get_features
(request)[source]¶ Get features supported by the host.
This is a list of strings specifying features supported by the daemon.
Explanation of feature strings:
- hostapd-control
- The daemon supports the hostapd control interface and provides a websocket channel for accessing it.
Example request:
GET /api/v1/info/features
Example response:
HTTP/1.1 200 OK Content-Type: application/json [ "hostapd-control" ]
-
get_telemetry
(request)[source]¶ Get a telemetry report.
This contains information about resource utilization by chute and system totals. This endpoint returns the same data that we periodically send to the controller if telemetry is enabled.
-
hardware_info
(request)[source]¶ Get information about the hardware platform.
Example request:
GET /api/v1/info/hardware
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "wifi": [ { "slot": "pci/0000:04:00.0", "vendorId": "0x168c", "macAddr": "04:f0:21:2f:b7:c1", "id": "pci-wifi-0", "deviceId": "0x003c" }, { "slot": "pci/0000:06:00.0", "vendorId": "0x168c", "macAddr": "04:f0:21:0f:78:28", "id": "pci-wifi-1", "deviceId": "0x002a" } ], "memory": 2065195008, "vendor": "PC Engines", "board": "APU 1.0", "cpu": "x86_64" }
-
routes
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
software_info
(request)[source]¶ Get information about the operating system.
Returns a dictionary containing information the BIOS version, OS version, kernel version, Paradrop version, and system uptime.
Example request:
GET /api/v1/info/software
Example response:
HTTP/1.1 200 OK Content-Type: application/json { "biosVersion": "SageBios_PCEngines_APU-45", "biosDate": "04/05/2014", "uptime": 15351, "kernelVersion": "Linux-4.4.0-101-generic", "pdVersion": "0.9.2", "biosVendor": "coreboot", "osVersion": "Ubuntu 4.4.0-101.124-generic 4.4.95" }
-
paradrop.backend.log_sockjs module¶
-
class
LogSockJSFactory
(chute)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerFactory
-
buildProtocol
(addr)[source]¶ Create an instance of a subclass of Protocol.
The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.
Alternatively, C{None} may be returned to immediately close the new connection.
Override this method to alter how Protocol instances get created.
@param addr: an object implementing L{twisted.internet.interfaces.IAddress}
-
paradrop.backend.password_api module¶
-
class
PasswordApi
(password_manager)[source]¶ Bases:
object
For now, we only support set/reset password for the default user: ‘paradrop’
-
routes
¶ L{Klein} is an object which is responsible for maintaining the routing configuration of our application.
- @ivar _url_map: A C{werkzeug.routing.Map} object which will be used for
- routing resolution.
@ivar _endpoints: A C{dict} mapping endpoint names to handler functions.
-
paradrop.backend.password_manager module¶
paradrop.backend.snapd_resource module¶
-
class
SnapdResource
[source]¶ Bases:
twisted.web.resource.Resource
Expose the snapd API by forwarding requests.
Changed in 0.13: we try to send the request through the governor service so that paradrop can be installed in strict mode.
https://github.com/snapcore/snapd/wiki/REST-API
-
isLeaf
= True¶
-
paradrop.backend.status_sockjs module¶
-
class
StatusSockJSFactory
(system_status)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerFactory
-
buildProtocol
(addr)[source]¶ Create an instance of a subclass of Protocol.
The returned instance will handle input on an incoming server connection, and an attribute “factory” pointing to the creating factory.
Alternatively, C{None} may be returned to immediately close the new connection.
Override this method to alter how Protocol instances get created.
@param addr: an object implementing L{twisted.internet.interfaces.IAddress}
-
-
class
StatusSockJSProtocol
(factory)[source]¶ Bases:
autobahn.twisted.websocket.WebSocketServerProtocol
-
onClose
(wasClean, code, reason)[source]¶ Implements
autobahn.websocket.interfaces.IWebSocketChannel.onClose()
-