Crates.io | network-manager-connection-action |
lib.rs | network-manager-connection-action |
version | 1.3.1 |
source | src |
created_at | 2021-09-16 13:20:56.683974 |
updated_at | 2023-07-26 13:33:48.492345 |
description | Execute commands on connections change using DBus network manager events |
homepage | https://github.com/izissise/network-manager-connection-action |
repository | https://github.com/izissise/network-manager-connection-action |
max_upload_size | |
id | 452239 |
size | 38,872 |
Listen connections/deconnections using network-manager's dbus interface and execute specified commands without the need of root access
One possible use case is adding automatic ssh canonicalization for company domains when connecting to company VPN, this usage can be found in example
directory.
Output when configured to run with canonicalization on a vpn connection and connecting/disconnecting from NetworkManager:
<user>$ network-manager-connection-action -c example/config.toml
[2021-05-02T13:51:45Z INFO] Watching for NetworkManager events
[2021-05-02T13:53:41Z INFO] Entreprise VPN Up
CanonicalDomains public.entreprise.com internal.entreprise.com anotherdomains.fromvpn
[2021-05-02T13:56:21Z INFO] Entreprise VPN Down
CanonicalDomains public.entreprise.com
cargo build --release
cp target/release/network-manager-connection-action /usr/bin/network-manager-connection-action
You need the UUID of networks you want to watch
You can find connections's UUID using nmcli c
Create a config file, example $HOME/.config/network_manager_connection_actionrc
Config contains network manager uuid that correspond to an existing connection.
For each connection's config you can choose a command and a context, see examples
Put the unit file here
$HOME/.config/systemd/user/network-manager-connection-action.service
Run and enable
systemctl --user daemon-reload
systemctl --user start network-manager-connection-action.service
systemctl --user enable network-manager-connection-action.service
journalctl --user -fu network-manager-connection-action.service
Use systemd varlink interface
At start the program could query already connected connections and apply configuration
The code and functionality could be improved in many ways, don't hesitate to open merge requests :)