https://github.com/cedws/openvpn-mgmt-go
Provides an API for connecting to, sending commands to, and receiving messages from an OpenVPN management socket
https://github.com/cedws/openvpn-mgmt-go
go openvpn
Last synced: about 1 year ago
JSON representation
Provides an API for connecting to, sending commands to, and receiving messages from an OpenVPN management socket
- Host: GitHub
- URL: https://github.com/cedws/openvpn-mgmt-go
- Owner: cedws
- License: gpl-3.0
- Created: 2022-11-09T17:59:20.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-12-25T02:54:31.000Z (over 3 years ago)
- Last Synced: 2024-06-20T22:34:47.552Z (about 2 years ago)
- Topics: go, openvpn
- Language: Go
- Homepage: https://pkg.go.dev/github.com/cedws/openvpn-mgmt-go
- Size: 36.1 KB
- Stars: 6
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# openvpn-mgmt-go
Provides an API for connecting to, sending commands to, and receiving messages from an OpenVPN management socket.
## Example
```go
package main
import (
openvpn "github.com/cedws/openvpn-mgmt-go"
"github.com/cedws/openvpn-mgmt-go/command"
"github.com/cedws/openvpn-mgmt-go/message"
)
func main() {
socket, err := openvpn.DialUnix("/run/openvpn/server/management.sock")
if err != nil {
// ...
}
plugin := AuthPlugin{socket}
plugin.Init()
}
type AuthPlugin struct {
socket *openvpn.Socket
}
func (a *AuthPlugin) Init() {
a.socket.OnClientConnect(a.onClientConnect)
a.socket.Start()
}
func (a *AuthPlugin) onClientConnect(c message.ClientConnect) {
// allow the connecting client
a.socket.Dispatch(command.ClientAuthNt{c.ClientID, c.KeyID})
}
```