Code Monkey home page Code Monkey logo

pfsense_fauxapi_client_python's Introduction

PfsenseFauxapi - Python Interface

PyPi Build Status

Python client for pfSense-FauxAPI - https://github.com/ndejong/pfsense_fauxapi

Install

via PyPi

pip3 install pfsense-fauxapi

Install via Source

# obtain the source material
git clone https://github.com/ndejong/pfsense_fauxapi_client_python.git
cd pfsense_fauxapi_client_python
python3 -m venv venv
source venv/bin/activate
pip3 install -r requirements.txt
python3 setup.py clean
python3 setup.py test
python3 setup.py install

Code Examples

Three Python code samples are provided that demonstrate interface usage

  • function-iterate.py - iterates (almost) all the FauxAPI functions to confirm operation.
  • update-aws-aliases.py - downloads the latest AWS ip-ranges.json and populates the pfsense alias table(s).
  • usergroup-management.py - demonstrates the ability to manage users and groups programmatically.

Command Line

Additionally this pip-package provides a command-line interface to work with FauxAPI

usage: fauxapi [-h] [--host [host]] [--apikey [key]] [--apisecret [secret]]
               [--verified-ssl] [--debug]
               [function] [[function] ...] [[function-args]]

FauxAPI

optional arguments:
  -h, --help            show this help message and exit

Call:
  --host [host]         Host address of the target pfSense host with the
                        PfsenseFauxapi package installed.
  --apikey [key]        FauxAPI apikey value - alternatively via the
                        FAUXAPI_APIKEY environment variable.
  --apisecret [secret]  FauxAPI apisecret value - alternatively via the
                        FAUXAPI_APIKEY environment variable.
  --verified-ssl        Enable SSL certificate checks - default does NOT check
                        SSL certificates.
  --debug               Enable debug response from the remote FauxAPI -
                        helpful in tracking down issues.
  [function]            The FauxAPI function being called
  [function-args]       Arguments to the function, space separated

Command line example, using environment variables to pass the FAUXAPI_APIKEY and FAUXAPI_APIKEY credentials.

$ fauxapi --host 192.168.1.200 gateway_status | jq .
{
  "callid": "5c8d0f7361cba",
  "action": "gateway_status",
  "message": "ok",
  "data": {
    "gateway_status": {
      "10.11.12.1": {
        "monitorip": "10.10.10.1",
        "srcip": "10.10.10.200",
        "name": "WAN_DHCP",
        "delay": "0.422ms",
        "stddev": "0.073ms",
        "loss": "0.0%",
        "status": "none"
      }
    }
  }
}

pfsense_fauxapi_client_python's People

Contributors

ndejong avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

pfsense_fauxapi_client_python's Issues

Unresponsive unless refreshing the actual pfSense page.

I am seeing some strange behavior with the fauxapi. Since I am using the Python interface, I thought I would start by posting here.

Versions:
I am using the latest from master: https://github.com/ndejong/pfsense_fauxapi_client_python
I followed the installation procedure for pfSense fauxAPI: https://github.com/ndejong/pfsense_fauxapi
pfSense version is:

2.4.5-RELEASE (amd64)
built on Tue Mar 24 15:25:50 EDT 2020
FreeBSD 11.3-STABLE

My python client authenticates with pfSense and seems to be functional. I am setting the configuration with the function call:

result = self.FauxapiLib.config_set(self.system_config)

If I am not manually logged into my pfSense web portal via a web browser the fauxapi reports the following after making the call above:

PfsenseFauxapi.PfsenseFauxapi.PfsenseFauxapiException: ('Unable to complete config_set() request', {'callid': '5f51134ea4d8f', 'action': 'config_set', 'message': 'failed to set new config', 'logs': [{'INFO': '20200903Z100118 :: fauxapi\\v1\\fauxApi::__call', 'DATA': {'user_action': 'config_set', 'callid': '5f51134ea4d8f', 'client_ip': '192.168.1.77'}}, {'ERROR': '20200903Z100222 :: unable confirm config reload before timeout', 'DATA': {'config_cache_filename': '/tmp/config.cache', 'timeout': 60}}, {'WARN': '20200903Z100222 :: attempting to revert config to last known backup', 'DATA': {'last_backup_file': '/cf/conf/backup/config-1599148878.xml'}}, {'INFO': '20200903Z100222 :: config file reverted to last known backup', 'DATA': {'config_file': '/cf/conf/backup/config-1599148878.xml'}}]})

If I am logged into the pfSense web portal via my web browser and make the call to:

result = self.FauxapiLib.config_set(self.system_config)

and then click on any page, for example System->Advanced, then the call goes through perfectly:

{'callid': '5f5115d828cce', 'action': 'send_event', 'message': 'ok'}

It appears as though pfSense needs this 'trigger' to process the fauxapi commands. I thought this was super strange and figured I was missing something entirely that maybe you or someone else would know how to fix.

I have created a video of the issue as it happens, but it contains a lot of identifying information. I can PM you a link if necessary.

Is there a way to reload the firewall rules?

I'm trying to enable/disable a firewall rule with this library. I've gotten the actual rule toggling working, but I'm not finding a way to tell pfSense to reload the firewall rules so that the change actually takes effect (unfortunately, a config reload isn't sufficient for this I think).

Does this functionality exist? If not, do you have any idea of how it might be implemented? I'm happy to put together a patch for this.

Set timeout (issue from `pfsense_fauxapi`)

This issue has been copied over from - ndejong/pfsense_fauxapi#76


Hello!

Are you able to set a timeout somewhere if the request is failing?
Let's say if the pfSense-machine is down.

fapi = PfsenseFauxapi(
    ip,
    faux_apikey,
    faux_apisecret
)
try:
    config = fapi.config_get()
except:
    config = None

The request is running for approx 30-40 seconds before moving on (I'm looping this code).

Feature: fauxapi command line

Looking for a way to automatically enable/disable/modify users using the fauxapi command line utility.
Does not seem like this is one of the supported options.

Am I missing something, or if this s athing that is not supported maybe it can be added? guessing this is something more people are also interested in.

Is it possible to import/export a config file directly into the client library?

While I'm eventually planning to interact with a pfsense box directly I'm currently exploring mixing cobbler and this toolset to help automate some work in my compute cluster backend. While I'm working on that being able to simply output a config.xml instead of having to have a pfsense machine to talk to would be very helpful.

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.