Giter Club home page Giter Club logo

pfsenseapi's Introduction

pfSenseAPI

This project is still a basic setup and is meant to be able to pull data out of pfSense remotely. The makers of pfSense have announced that the next major release of pfSense, version 3.0, will contain native REST endpoints to communicate with which will make this way easier. For now we're stuck with HTTP Replays and parsing HTML to get the data we need. You can easily fork from my code and add further implementations for data you require from pfSense.

If you'd like me to add functionality to get specific data from pfSense, just send me an e-mail and I'll look into adding it.

Version History

1.1.0.0 - September 29, 2021

  • Compiled against .NET 5.0 now
  • Fixed GetLastMonthsDataUse and GetThisMonthsDataUse not working anymore
  • Added SaveBackupAs and GetBackupContents to retrieve a backup from pfSense
  • Removed dependency on Newtonsoft JSON

1.0.1.0 - August 16, 2017

  • Transformed the framework to become asynchronous for all requests
  • You'll need to manually call Authenticate() once to authenticate your pfSense session. This breaks backward compatibility but makes things more common in the future. The async stuff will break backwards compatibility anyway.
  • Compiled against .NET 4.6.2 now

System Requirements

This API is built using the Microsoft .NET 5.0 framework and is fully asynchronous

Usage Instructions

To communicate with the pfSense API, add the NuGet package to your solution and add a using reference in your code:

using KoenZomers.pfSense.Api;

Then create a new session instance using:

var pfSense = new pfSense("https://192.168.0.1", "admin, "password");

Note that this line does not perform any communications with the pfSense API yet. You need to manually trigger authenticate before you can start using the session:

await pfsense.Authenticate();

Once this succeeds, you can call one of the methods on the session instance to retrieve data, i.e.:

// Gets this months data use
var dataUsage = await pfSense.GetThisMonthsDataUse();

Check out the UnitTest project in this solution for full insight in the possibilities and working code samples.

Available via NuGet

You can also pull this API in as a NuGet package by adding "KoenZomers.pfSense.Api" or running:

Install-Package KoenZomers.pfSense.Api

Package statistics: https://www.nuget.org/packages/KoenZomers.pfsense.Api

Current functionality

With this API at its current state you can:

  • Authenticate to pfSense
  • Get the RAW data from one of the pages on pfSense so you can parse it yourself
  • Get this months data use
  • Get lasts months data use
  • Download backup of pfSense

Opening in Visual Studio

  1. Git clone the project
  2. Copy the App.config.sample in the UnitTest project to App.config and fill it with the URL, username and password of your pfSense box
  3. Run the Unit Tests to see if it works well

Feedback

Any kind of feedback is welcome! Feel free to drop me an e-mail at [email protected] or create a new issue

pfsenseapi's People

Contributors

koenzomers avatar

Stargazers

Matthijs Smeets avatar Alexander Medchenko avatar Noah Halstead avatar Maras Chen avatar Stefan Amyotte avatar

Watchers

Jeremy Huylebroeck avatar James Cloos avatar  avatar Matthijs Smeets avatar  avatar

pfsenseapi's Issues

Can we get the XML Backup file?

Can we download the file /cf/conf/config.xml.

That would be nice :)

If it helps the page is /diag_backup.php

On page NetGate Backups there's some examples

For CURL

$ curl -L -k --cookie cookies.txt --cookie-jar cookies.txt \
     https://192.168.1.1/diag_backup.php  \
     | grep "name='__csrf_magic'"   \
     | sed 's/.*value="\(.*\)".*/\1/' > csrf.txt

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.