Coder Social home page Coder Social logo

eugenmayer / opnsense-cli Goto Github PK

View Code? Open in Web Editor NEW
27.0 6.0 2.0 22.57 MB

Client interface for OPNsense written in go. Can be used as cli or golang lib

License: MIT License

Go 97.91% Makefile 2.09%
opnsense golang cli library rest-api unbound openvpn

opnsense-cli's Introduction

build

WAT

Implementation of the OPNsense WebAPI to be used on the CLI or as a library - written in Golang

Compatible with OPNsense 22.1 and higher.

Installation

Its precompiled and has no dependencies, so just download the binary, and you are good to go

Pick a release from https://github.com/EugenMayer/opnsense-cli/releases
chmod +x opn-*

You need to create a .env (dotenv) for the secrets, or expose them into your ENV using export

OPN_URL=https://localhost:10443
OPN_APIKEY=5GWbPwKfXVLzgJnewKuu1IPw2HS7s510jKHmTM+rLA1y9VfEFE57yj/kJiWbXREB0EgpBK48u4gnyign
OPN_APISECRET=EtpPVbiCBdtvG5VDlYJQfLu7Qck2hRffoLi2vb73arn5bKzxEbGdti8+iZetgc9eHABJy6XYG6/UsW/1`
# if we should not verify SSL while talking to opn, enable that
#OPN_NOSSLVERIFY=1

Commands included

Just run

opn 

to see a full list. Currently implemented

  • managing host overrides for unbound (CRUD + list)

Usage: cli

opn --help

# unbound host DNS entries
opn unbound hostoverride create --host foo --domain bar.tld --ip 10.10.10.1
opn unbound hostoverride update --host foo --domain bar.tld --ip 10.10.10.2
opn unbound hostoverride show --host foo --domain bar.tld
opn unbound hostoverride rm --host foo --domain bar.tld
opn unbound hostoverride list

# unbound service
opn unbound service restart
opn unbound service reconfigure
opn unbound service status

HINT: Right now, as of 22.7, you have to run reconfigure everytime you change a hostentry on unbound, so e.g.

# this will yet not show up when you run a DNS query
opn unbound hostoverride create --host foo --domain bar.tld --ip 10.10.10.1
# after that, it will
opn unbound service reconfigure

This might change in later releases.

Usage: GoLang library

import (
  opn_unbound "github.com/eugenmayer/opnsense-cli/opnsense/api/unbound"
  opn_api "github.com/eugenmayer/opnsense-cli/opnsense/api"
)
 
func create_host_entry() error {
    var opnUnboundConnection opn_unbound.UnboundApi

    if opnConnection, opnErr := opn_api.ConfiugreFromEnv(); opnErr != nil {
        return errors.New(fmt.Sprintf("Error getting OPNsense connection: %s", opnErr))
    } else {
        opnUnboundConnection = opn_unbound.UnboundApi{opnConnection}
    }

    var dnsHostEntry = opn_unbound.HostOverride{
        Host:   "test,
        Domain: "foo.tld,
        Ip:     "10.10.10.1",
    }
    
    _, _ := opnUnboundConnection.HostOverrideCreateOrUpdate(dnsHostEntry)
}

Development

# building
make build

Contributions

If you like to add a new command implementing OPNsense API reference https://docs.opnsense.org/development/api.html#introduction - open a PR and iam happy to add it. Be bold.

opnsense-cli's People

Contributors

eugenmayer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

opnsense-cli's Issues

License

Is this project released under an open source license? If so, which one?

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.