Code Monkey home page Code Monkey logo

go-openvpn's Introduction

go-openvpvn

go-openvpn is a lightweight golang library to start and monitor an openvpn tunnel. It essentially just wraps around the openvpn process and interacts with it using the management interface. Right now only openvpn client configuration has been implemented and tested.

It supports the following features:

  • simple API
  • use an existing openvpn configuration
  • override the config file settings programmatically
  • go channel to receive events:
    • tunnel status (up/down)
    • openvpn statistics
  • send management command

Import

import (
	"github.com/Marlinski/go-openvpn"
	"github.com/Marlinski/go-openvpn/events"
)

Basic example

The following code shows how to run a simple openvpn:

cfg := openvpn.LoadConfig(m.iface, "test.ovpn") // openvpn config file
cfg.SetLogStd(true)                             // log openvpn standard output and error
cfg.Set("dev", "tun-test)                       // passed to the openvpn command line parameter --dev tun-test

channel := processEvents()                      // event loop
ctrl    := cfg.Run(channel)                     // run openvpvn, it returns a controller 

And the event loop processor:

func processEvents() chan events.OpenvpnEvent {
    channel := make(chan events.OpenvpnEvent)       // channel to process the events 

    go func() {
        for {
            e := <-channel
            if e.Code() == events.OpenvpnEventUp {
                // tunnel is up
            }
            if e.Code() == events.OpenvpnEventDown {
                // tunnel is down
            }
        }
    }()

    return channel
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.