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]
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.

status(request)[source]

paradrop.backend.airshark_ws module

class AirsharkAnalyzerFactory(airshark_manager, *args, **kwargs)[source]

Bases: autobahn.twisted.websocket.WebSocketServerFactory

buildProtocol(addr)[source]
class AirsharkAnalyzerProtocol(factory)[source]

Bases: autobahn.twisted.websocket.WebSocketServerProtocol

onClose(wasClean, code, reason)[source]
onOpen()[source]
on_analyzer_message(message)[source]
class AirsharkSpectrumFactory(airshark_manager, *args, **kwargs)[source]

Bases: autobahn.twisted.websocket.WebSocketServerFactory

buildProtocol(addr)[source]
class AirsharkSpectrumProtocol(factory)[source]

Bases: autobahn.twisted.websocket.WebSocketServerProtocol

onClose(wasClean, code, reason)[source]
onOpen()[source]
on_spectrum_data(data)[source]

paradrop.backend.auth module

class AuthApi(password_manager, token_manager)[source]

Bases: object

local_login(request)[source]

Login using local authentication (username+password).

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.

check_auth(password_manager, token_manager, auth_header)[source]
get_allowed_bearer()[source]

Return set of allowed bearer tokens.

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.

requires_auth(func)[source]

Use as a decorator for API functions to require authorization.

This checks the Authorization HTTP header. It handles username and password as well as bearer tokens.

verify_password(password_manager, userpass)[source]

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

create_chute(request)[source]
delete_chute(request, chute)[source]
delete_station(request, chute, network, mac)[source]
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"
  }
]
hostapd_control(request, chute, network)[source]
restart_chute(request, chute)[source]
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"
}
start_chute(request, chute)[source]
stop_chute(request, chute)[source]
update_chute(request, chute)[source]
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]
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]
extract_tarred_chute(data)[source]
tarfile_is_safe(tar)[source]

Check the names of files in the archive for safety.

Returns True if all paths are relative and safe or False if any of the paths are absolute (leading slash) or try to access parent directories (leading ..).

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.

factory_reset(*args, **kwargs)[source]

Initiate the factory reset process.

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_provision(request)[source]

Get the provision status of the device.

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.

provision(request)[source]

Provision the device with credentials from a cloud controller.

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.

sshKeys(request, user)[source]

Manage list of authorized keys for SSH access.

start_update(request)[source]
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/

config_cors(request)[source]

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

airshark_analyzer(request, *args, **kwargs)[source]
airshark_spectrum(request, *args, **kwargs)[source]
api_airshark(request, *args, **kwargs)[source]
api_auth(request)[source]
api_changes(request, *args, **kwargs)[source]
api_chute(request, *args, **kwargs)[source]
api_configuration(request, *args, **kwargs)[source]
api_information(request, *args, **kwargs)[source]
api_password(request, *args, **kwargs)[source]
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.

change_stream(request, *args, **kwargs)[source]
chute_logs(request, *args, **kwargs)[source]
home(request, *args, **kwargs)[source]
logs(request, *args, **kwargs)[source]
paradrop_logs(request, *args, **kwargs)[source]
snapd(request, *args, **kwargs)[source]
status(request, *args, **kwargs)[source]
annotate_routes(router, prefix)[source]

Annotate klein routes for compatibility with autoflask generator.

setup_http_server(http_server, host, port)[source]

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]
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(chutename)[source]

Bases: twisted.internet.protocol.Factory

buildProtocol(addr)[source]
class LogSockJSProtocol(factory)[source]

Bases: twisted.internet.protocol.Protocol

check_log()[source]
connectionLost(reason)[source]
connectionMade()[source]

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’

change(request)[source]
clear(request)[source]
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

class PasswordManager[source]

Bases: object

DEFAULT_PASSWORD = ''
DEFAULT_USER_NAME = 'paradrop'
add_user(user_name, password)[source]
change_password(user_name, newPassword)[source]
remove_user(user_name)[source]
reset()[source]
verify_password(user_name, password)[source]

paradrop.backend.snapd_resource module

class SnapdResource[source]

Bases: twisted.web.resource.Resource

Expose the snapd API by forwarding requests.

https://github.com/snapcore/snapd/wiki/REST-API

do_snapd_request(request)[source]

Forward the API request to snapd.

isLeaf = True
render(request)[source]

Fulfill requests by forwarding them to snapd.

We use a synchronous implementation of HTTP over Unix sockets, so we do the request in a worker thread and have it call request.finish.

paradrop.backend.status_sockjs module

class StatusSockJSFactory(system_status)[source]

Bases: twisted.internet.protocol.Factory

buildProtocol(addr)[source]
class StatusSockJSProtocol(factory)[source]

Bases: twisted.internet.protocol.Protocol

connectionLost(reason)[source]
connectionMade()[source]
dataReceived(data)[source]

Module contents