# Plugins

> Use plugin configs to install, monitor and uninstall third-party software on your devices. Write scripts and when they run yourself, or import a template and edit it directly.

Source: https://www.widewired.com/page/docs/plugins

## Before you start

Plugins run scripts on devices you have already joined to your network. A device can have several **plugin configs**. One config is one complete job, for example running a tunnel on a gateway or keeping a proxy service alive, and it can be saved, disabled and removed as a whole.

A config follows the software's lifecycle in sections: **Variables**, **Install**, **Monitor**, **Other** and **Uninstall**. Each section is a script and the times it runs; there can be several monitors and other scripts.

Third-party open-source software can **import a template**: a ready-made set of scripts and execution times whose content is fully visible, and whose scripts you edit directly after importing it. You can also start from an empty config and write your own.

Common uses:

- **Work with third-party software**: install third-party software on a device and keep it in step with the virtual network, such as a tunnel, proxy or monitoring agent. It starts when the network is ready, alerts when it fails and is removed when the device leaves the network. The strongSwan site template is one example.
- **Deploy and keep a service or proxy running**: the install script deploys it, a monitor checks it on an interval and can recover it as it checks, and an alert follows after the set number of failures in a row.
- **Act when the network changes**: run a script when the network connects or disconnects, for example to switch routes or DNS or to mount a share.

Plugin scripts run directly on your devices. You are responsible for the software and system configuration they change, and for rollback.

- Only the account owner can manage plugins in the console. Management API keys can also write; see [Security boundaries](#security-boundaries).
- Plugins run on Linux (including OpenWrt) and Windows devices. macOS, iOS, Android and HarmonyOS devices do not run scripts.
- When the client on a device is too old, the device cannot be chosen for a config, and you are asked to upgrade first.
- Scripts run with the privileges of the `wwnet` background service, usually administrator or system privileges. Verify on a non-critical device before applying to production devices.
- **When a save runs an install.** An enabled config runs its install script when its install revision changes, for example after an edit to the install or variables script. Saving edits while disabled leaves scheduled execution paused. You can still use **Run now** to try an install, monitor or other script. Offline devices receive changes when they reconnect.

## What each section does

| Section | Per config | How the result is used |
| --- | --- | --- |
| Variables | 0 or 1 | Never runs on its own; every script in the config loads it first |
| Install | 0 or 1 | If it fails the config is marked install failed and no other script in the config runs |
| Monitor | Several | The exit code decides whether the config is healthy; the set number of failures in a row raises an alert |
| Other | Several | Only recorded |
| Uninstall | 0 or 1 | Runs best effort on removal if this device started the install script, including a trial run |

Each script has its own interpreter, which follows the device's system: PowerShell on Windows; `sh` or `bash` on Linux (including OpenWrt). When the variables script uses `sh`, other scripts can use `sh` or `bash`; when it uses `bash`, every other script must use `bash`.

## Execution times

Each execution time has a trigger, an interval and a timeout. There are two kinds of trigger: a moment runs the script once, a period runs it on an interval.

| Trigger | Runs | Used by |
| --- | --- | --- |
| When the config takes effect | Once | Install (fixed; only the timeout can change) |
| After service starts | Once | Other |
| Network connected | Once | Other |
| Network disconnected for 30 seconds | Once | Other |
| Before service stops | Once | Other |
| While the service runs | Repeats on an interval | Monitor, Other |
| While the network is connected | Repeats on an interval | Monitor, Other |
| When the config is removed | Once | Uninstall (fixed; only the timeout can change) |

- "Network" means at least one other device in the virtual network is usable. It does not mean internet reachability or the state of a third-party tunnel.
- If connectivity recovers within 30 seconds after a blip, the network does not count as disconnected and "Network connected" does not fire again.
- Each execution time of a monitor also has "alert after N failures in a row", where N is a whole number from 1 to 100, 3 by default.
- Period rhythm: the script runs immediately when the period begins, then each interval starts when the previous run ends. The minimum interval is 1 minute. When the period ends the loop stops and a run in progress is canceled.
- The timeout is required, from 1 second to 24 hours. Defaults: install 15 minutes, uninstall 5 minutes, monitor 30 seconds, other 60 seconds.
- All "Before service stops" scripts share at most 5 seconds. They cannot run after a power loss, a system crash or a forced termination.
- A monitor or other script can have several execution times. Scripts in the same config never run in parallel, and installs and uninstalls on one device run one at a time so they do not compete for the package manager.

## Create a config

Go to **Configuration → Plugins**. The page lists every config of the network with its device, status and last check. Before you create a config the page is empty; it does not list your devices in advance.

**New config** is the only action at the top right of the page. It opens no dialog: the config is created right away and its editing page opens. It is named "Config NNNN", disabled, and has no device yet. Choose the device, write scripts or import a template on the editing page.

### Editing page

Every config has its own editing page with an address you can bookmark or share. Open it from the config's name or **Edit** in the list; the breadcrumb takes you back.

The page runs top to bottom: Device, Variables, Install, Monitor, Other, Uninstall.

- **Device**: the device the config runs on. A config that has never been enabled can choose or change its device: select **Change device**, and every device of the network is listed below the section title with its name, virtual network address and system. Select one, then **Save changes**. Devices that cannot use plugins are listed too, grayed out with the reason, for example a client that is too old, or a system that does not run scripts. If you change or clear the device after a trial install, the old device attempts its saved uninstall script. The new device starts with no trial request. Once enabled, the config stays on its assigned device.
- **Each section has one title line**: its name, a short explanation (ⓘ), and on the right the script's interpreter, **Edit script** (**New script** while there is no script yet) and **⋯** with **Run now** and **Delete script**. Monitors and other scripts show their count when there are some, and only the name and button when there are none. A folded section shows a summary on that line, for example "21.6 KiB · Runs once when the config takes effect · timeout 15 min".
- **Below the title are the execution times, then the script**. They are read-only until you select **Edit script**; then the script, interpreter and execution times of that section (or of that monitor or other script) can change, and the title line shows **Discard changes** and **Save changes**, staying at the top of the page while you scroll. The page never saves on its own, so always finish with **Save changes**. You edit one place at a time; while one has unsaved changes, the other **Edit** buttons are unavailable. Each monitor and other script has a pencil next to its name: select it to rename in place, then Enter or ✓ saves right away and Esc cancels, without editing the script or confirming.
- **Run now** requests one install, monitor or other script on the selected device. The device processes the request when it receives the config. On an enabled config, monitor and other requests wait for the current installation to succeed. On a disabled config, they can run before installation and leave scheduling paused. A manual monitor run does not count towards its failure threshold. The confirmation names the device and script and links to the execution history.
- **The interpreter** is chosen while editing. The choices follow the device's system and the variables script's interpreter; unsuitable ones are grayed out with the reason. Without a device the interpreter cannot be decided yet, so choose the device first.
- Install and Uninstall run at fixed times; only their timeout can change. Each monitor and other script has its own name (**Monitor 1**, **Other 1** and so on by default) and a column of execution times below it, for example "While the service runs · every 60 s · timeout 30 s", and for a monitor also "alert after 3 failures in a row", which you can change while editing; to run the same script at more times, select **Add another time**.
- The script editor shows up to 10 lines by default; **Expand editor** at its top right makes it about a screen tall, and selecting it again shrinks it.
- **Variables**, **Install** and **Uninstall** are only a title line until you select **New script**; leaving one empty means the config has no such script. Add monitors and other scripts with **New script** on their title line; a new one opens for editing, and **Discard changes** drops it. **Delete script** in **⋯** asks first: Variables, Install and Uninstall go back to unwritten, and a monitor or other script is removed. A monitor or other script without any execution time is marked as never running, with one click to add a time while editing.
- The header stays at the top of the page. The edit button next to the name renames the config: Enter or ✓ saves, Esc cancels. On the right are the current state, **Enabled** or **Disabled**, then **Import template**, **Disable config**, **Enable config**, and **⋯** with **Executions** and **Delete config**. A button that cannot be used right now is grayed out and explains why on hover. Once imported, the scripts are yours and do not follow the template, so neither the list nor the editing page shows a template source.

### Enable, disable and save

**A config that has never been enabled**: each **Save changes** stores that change without a confirmation. It may be incomplete. Select **Run now** to send a script to the device for a trial run. When it is ready, select **Enable config**: the whole config is checked, including its device, and the page scrolls to the first section with a problem, marks it red and states the reason. When nothing is wrong, the confirmation states which device runs what after enabling. After enabling, the device runs the current install revision when it receives the config, unless it already attempted that revision during a trial. A successful trial needs no repeat. If that trial failed, correct the script or use **Run now** to retry. If the device ran the install script, including a trial run, deleting the config attempts to run its uninstall script.

**A config that has been enabled**: after editing a section, select **Save changes**; the confirmation lists the scripts and execution times you changed and states what the device runs right away. Deleting a script asks the same way. While enabled, changing the variables script and the install script together reinstalls once; changing only monitors, other scripts or execution times does not reinstall. **Disable config** and **Enable config** ask for confirmation too. Leaving the page with unsaved changes asks for confirmation.

If someone else changed the config while you were editing, saving never overwrites their change: the page tells you, and you choose to overwrite with this page (save this change on top of the latest version) or load the latest (discard this change).

A device can have up to 32 configs, and a config up to 16 scripts and 32 execution times. A script can be up to 256 KiB, and the combined JSON payload delivered to a device can be up to 512 KiB, including fields, schedules and escaping.

## Use a template

A template is a ready-made set of scripts and execution times that installs and runs a third-party open-source program. On a config's editing page, select **Import template** in the header and pick one in the dialog:

- The dialog works like the one for choosing applications in forwarding: you can search at the top; when the config has a device, only templates that fit it are listed by default, and **All** shows the rest, grayed out with the reason.
- Each template is one row with its name and summary, provider and license, supported systems and version; expand a row for the upstream, install source and requirements.
- Importing puts the template's scripts and execution times into the config, replacing all of its current scripts and execution times; when the config already has scripts you confirm first.
- A template has no form: the values to fill in are in the **Variables** script, each with a comment and a default, and those marked as required must be set. Every script starts with its variable area, which lists every variable the script uses. Editing the **Variables** script is enough; you can also edit the area of a script, or rewrite the script.
- After importing, the content is yours and behaves like a config you wrote yourself. When the template has next steps, they appear right after the import. When the config is enabled and the installation revision changes, the device runs the install script; see the config's executions for its output and status.

Templates only install the current version of open-source software from the distribution repository or the official upstream source, and never pin a version. The install script checks whether the distribution is supported and fails with a clear message when it is not. When a required variable is not set, the install script fails at its start and lists the missing variables.

Importing is a one-time copy: when the template gets a newer version later, configs that imported it do not change and are not notified. To use the new version, import it into the config again (this replaces all of its scripts and execution times, so note the values in your variables script first).

### strongSwan site access

This template connects sites that have an IPsec firewall or router but cannot run the client. Use it on a Linux device that has joined the network. One config can connect several sites: each site is a peer in the **Variables** script, with its address, identity, networks and pre-shared key.

- **Upgrading an existing v4 installation to v5:** disable the config before reimporting, restore at least one original peer in its original slot with the same identity and pre-shared key, then enable it. If v5 cannot verify the old setup or finds an unrelated resource with the same name, installation stops and leaves it in place. Verify the previous peer settings and the reported conflict before retrying.
- Requirement: the device and the peer can establish IKE (UDP 500/4500), and at least one side is reachable from the other.
- To add or remove a peer, change the number of peers and the matching group of variables as described in the **Variables** script. Saving an enabled config runs the install script again; the interface, connection and routes of a removed peer are cleaned up, and peers that did not change do not reconnect.
- Every peer has its own tunnel interface, named in the output of the install record. After the install succeeds and the interface exists, add a site route for the peer networks on this device under **Configuration → Routes**, without a gateway.
- While a tunnel is down, traffic to that peer's networks is dropped and never leaves through the device's default route. strongSwan reconnects the tunnel itself; the monitor names the broken peer, and the other peers are unaffected.
- **Delete the site route before removing a peer or deleting the config.** If the interface is removed while the site route still exists, all site routes of this device are withdrawn.

## Variables

Variables are set by a script. Before each run, the client loads the variables script and then the target script in the same interpreter process, so assignments in the variables script are visible to the target script. It runs again every time and should only assign values and do light computation. When the variables script fails, the run is recorded as failed and marked as a variables script error.

Variables set by a script are gone when its process ends. To keep a value for later runs, append a line `NAME=value` to the variables file whose path is given by `WWNET_CLIENT_PLUGIN_ENV_FILE`:

- The client parses the file and injects the values as environment variables; the interpreter never executes it.
- Names use upper-case letters, digits and underscores. The value runs to the end of the line and quotes are not processed. The last line wins for a repeated name. The file can be up to 64 KiB.
- The variables file is loaded first, then the variables script. The file is deleted when the config is removed.

Every run also receives these built-in variables:

| Variable | Meaning |
| --- | --- |
| `WWNET_CLIENT_PLUGIN_EXECUTION_ID` | ID of this run |
| `WWNET_CLIENT_PLUGIN_CONFIG_ID` | Config ID |
| `WWNET_CLIENT_PLUGIN_SCRIPT_TYPE` | Script type |
| `WWNET_CLIENT_PLUGIN_STAGE` | Trigger |
| `WWNET_CLIENT_PLUGIN_SCRIPT_REVISION`, `WWNET_CLIENT_PLUGIN_SCRIPT_SHA256` | Script revision and content digest |
| `WWNET_CLIENT_PLUGIN_OVERLAY_IP` | The device's virtual network address |
| `WWNET_CLIENT_PLUGIN_INTERFACE` | Virtual interface name |
| `WWNET_CLIENT_PLUGIN_NETWORK_CIDR` | Virtual network range |

## Install

- In an enabled config, changing the variables script or the install script, or selecting **Run now** in the install script's **⋯**, makes the device run the install script again. Changing only monitors, other scripts or execution times does not reinstall.
- A failure is not retried automatically: a non-zero exit code or a timeout marks the config as install failed until you change the script or run install again. Only a run interrupted by a service stop is repeated at the next start. The install script must be safe to run again.
- Until the current install succeeds, no other script in the config runs, and monitoring is paused during a reinstall.
- After a successful install the "After service starts" rows run once; if the network is already connected the "Network connected" rows run next, and then the period loops begin.
- Restarting or updating the client does not reinstall or uninstall; the loops resume.

## Status and alerts

A config is disabled, pending, installing, healthy, install failed or monitor failing. The list also shows when it was last checked.

- A monitor passes when it exits with 0; a timeout counts as a failure. The number of failures in a row set on its execution time (3 by default) marks it as failing, and the first success afterwards restores it. If any monitor is failing, the config is failing.
- Install failures and monitor failures appear under [Alerts](https://www.widewired.com/page/docs/alerts), deduplicated per device and config, with the recovery time recorded. No new monitor alert is raised while the device is offline.

## Disable and uninstall

- **Disabling** only stops the execution times from firing. The uninstall script does not run and the software stays on the device.
- **Deleting a config** removes it from the list immediately. If the device started its install script, including a failed or interrupted install or a trial while disabled, it attempts the saved uninstall script when it receives the removal. The device reports the result in execution history. Removal does not wait for success or retry a failed uninstall.
- **When a device leaves the network**, it also attempts the saved uninstall scripts for configs whose installation started on that device. This covers running `wwnet leave` or `wwnet uninstall` on the device, removing the device in the console, deleting the network or closing the account, and moving the device to another network. The cleanup runs in the background; the command does not wait for it and prints where the cleanup log is. The result of this cleanup is not reported to the console.
- While a device is blocked or awaiting approval nothing runs, including uninstalling. Stopping, restarting or updating the service does not uninstall either.

## Run long-lived components

Scripts should finish one operation and exit. For a third-party component that must keep running, have the script install, start or stop it through the operating system's service manager: systemd on Linux, procd on OpenWrt, and the Windows service manager on Windows.

Do not use `setsid` or similar techniques to detach a child process from the run. WideWired would be unable to clean it up when the script times out, is canceled or the service exits.

## View execution results

Select **Executions** on a config's row or under **⋯** on its editing page, to see that config's runs in reverse chronological order. Filter by type and status, and page through the list. Open a record to see its status, script revision, trigger reason, start and end time, exit code, stdout and stderr. Trial runs also have execution records.

- A recurring script is only recorded with output when its result changes; runs with an unchanged result only update the last-checked time.
- stdout and stderr each keep up to 256 lines and 4 MiB, with at most 16 KiB per line. Install and uninstall scripts keep the beginning and the end when they exceed the limit; other scripts keep the beginning.
- Records are kept per config and script: up to 100 runs from the last 30 days. The most recent install record of each config is not removed by age, because information to hand to the peer, such as a public key, is in its output.

## Security boundaries

- The variables script is stored like any other script, **neither encrypted nor masked**. Its content, including passwords and pre-shared keys, can be read by the account owner, read-only and management API keys, and support proxy sessions. Do not put a secret in a script if these readers must not see it.
- Management API keys and MCP can enable configs, edit active install or variables scripts, request trial runs and delete configs. These operations use the same execution rules as the console and have no interactive confirmation. See [Agent](https://www.widewired.com/page/docs/agent).
- A device's own private key should be generated on the device, printing only the public key.
- The activity log records changes to configs, scripts and execution times, never the script text.

## Quick troubleshooting

| Symptom | Checks and actions |
| --- | --- |
| The device has no plugins entry | Upgrade the client on the device; macOS and mobile devices do not run scripts |
| A config stays pending | An offline device runs it once it is back online; confirm the config is enabled |
| Install failed | Open the config's most recent install record and read the end of the output, then fix and save the script or select **Run now** in the install script's **⋯** |
| A monitor or other script does not run | None of them runs until the current install succeeds; confirm its execution time actually happened |
| A run is marked as a variables script error | Keep the variables script to assignments and light computation; check its syntax and exit status |
| Monitor failing | Check the monitor's recent failure records; the first success afterwards restores the config |
| A record shows canceled | The period ended, a new moment began, or the background service started exiting; installs and uninstalls are not affected by trigger changes |
| Leftovers after deleting a config | Uninstalling is best effort; check the device for leftovers and clean up manually if needed |
| All site routes fail after removing a strongSwan peer or deleting the config | Delete the site route before removing the peer or the config; deleting the leftover site route restores the others |
| The install of a config from a template fails because required variables are not set | Set the variables listed in the output in the **Variables** script and save |
