Skip to content

Zerotierlib DOCS v.1.4

Riemaru Karurosu edited this page May 28, 2023 · 1 revision

Libraries required

  • requests
  • subprocess
  • psutil
  • pydbus
  • pathlib

Why there is not a requierements.txt

Flatpak imports requierements in a different way, so there's no need to create one, but, you could use in theory this library in other way.

ZeroTierNetwork

Thanks to ZeroTierOne API v.0.1.0 we can manipulate the zerotier-one service, this in theory works for Linux, MacOS and Windows versions, but this library only works (meant to work) in Linux OS.

Constants

  • COMMANDS : Tuple of commands to manage ZeroTier service.
  • URL : Base URL for the ZeroTier API (You could try it on postman).
  • FILE: Configuration file where X-ZT1-Auth is stored.
  • SERVICE: Name of ZeroTier service.

Methods

They're a total of 16 methods,

  • __init__: The class constructor.
  • ztStart: (Deprecated) Old way to start the application.
  • ztStatus: Checks if the ZeroTier service is active.
  • ztEnableStatus: Checks the enable status of the ZeroTier service.
  • service: Changes the status of the ZeroTier service.
  • _ztActivate: Activates the ZeroTier service based on the current status, NOT FOR ACUAL USE OUTSIDE OF THE LIBRARY.
  • readToken: Reads the API token from the configuration file.
  • checkToken: Checks if the provided API token is valid.
  • saveToken: Saves the API token to the configuration file.
  • getToken: Retrieves the API token from the ZeroTier service.
  • getNetworks: Retrieves information about ZeroTier networks.
  • joinNetworks: Joins a ZeroTier network.
  • updateNetwork: (Not implemented) Updates a ZeroTier network.
  • leaveNetworks: Leaves a ZeroTier network.
  • getPeers: Retrieves information about peers in a ZeroTier network.

These methods provide functionality to interact with the ZeroTier API, perform operations on the ZeroTier service, and obtain information about networks and peers within those networks.

__init__

Initializes a new instance of the ZeroTierNetwork class.

Args:

  • api_token (str, optional): The API token for ZeroTier authentication. Defaults to None.

ztStart (Deprecated)

Old way to start application, not sure if it works with flatpak, needs reimplementation.

Returns:

  • str: Result of the operation

Return Ex: 'OK'

ztStatus

Checks if the ZeroTier service is active, it's like doing "sudo systemctl status"

Returns:

  • bool: True if the service is active, False otherwise.

ztEnableStatus

Checks the enable status of the Zerotier Service

Returns:

  • bool: True if the service is enable, False otherwise.

service

Change the status of the ZeroTier service.

Args:

  • setstatus (int): The desired status of the service Ex:
  1. start
  2. stop
  3. enable (won't work)
  4. disable (won't work)

Returns:

  • bool: True if the operation was succesful, False otherwise.

_ztActivate

Internal class that activates the current status, use service() instead.

readToken

Reads the API token from the configuration file.

Returns: int: Status code indicating the result of reading the token.

200 - OK 401 - Auth problems 404 - No response.

checkToken

Check if the provided API token is valid.

Args:

  • api_token (str): The API token to check.

Returns:

  • bool: True if the token is valid, False otherwise.

saveToken

Saves the API token to the configuration file internal use only.

getToken

Retrieves the API token "X-ZT1-Auth" from the ZeroTier service and use saveToken to save it.

Returns: str: The retrieved X-ZT1-Auth API token.

What is X-ZT1-Auth

Token that is needed to make a petition to zerotier-one service.

getNetworks

Retrieves information about all networks or a specific network.

Args:

  • network (str,optional): The network ID to retrieve information for. Defaults to none.

Returns:

  • dict: The JSON response containing network information.

Example use: Get all network information: from zerotierlib import ZeroTierNetwork networks = ZeroTierNetwork('[X-ZT1-Auth]') print(networks.getNetworks()) Get a specific network information: from zerotierlib import ZeroTierNetwork networks = ZeroTierNetwork('[X-ZT1-Auth]') print(networks.getNetworks('e8da8895f2fc2be'))

joinNetworks

Joins a ZeroTier network

Args:

  • network (str): The network Id to join

Returns:

  • dict: The JSON response indicating the result of the operation.

Ex: from zerotierlib import ZeroTierNetwork networks = ZeroTierNetwork('[X-ZT1-Auth]') print(networks.joinNetworks('e8da8895f2fc2be'))

updateNetwork (not implemented)

Update a ZeroTier network, implementation is planned in version 2.0 Args: network (str): The network ID to update. config (dict): The configuration data to update the network with. Note: his method is planned for implementation in Version 2.0.

leaveNetworks

Leaves a ZeroTier network. Args:

  • network (str): The network ID to leave. Returns:
  • Response: The response object indicating the result of the operation

getPeers

Retrieves information about peers in a ZeroTier network.

Args:

  • network (str,optional): The network ID to retrieve peer information for. Defaults to None.

Returns:

  • dict: The JSON response containing peer information.