Menu

Show posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Show posts Menu

Messages - And1

#1
General Discussion / Certificate management via API
November 21, 2023, 02:53:25 PM
Hello everyone,

Is there a way to add and select new certificates via API? Under /api/ipsec/sessions/searchPhase1 I can display some information but I haven't gotten any further yet. The aim is actually to be able to upload a new certificate if it expires and then select it so that it is also used. If this has already been discussed somewhere, please just comment on the link. Thank you.

Greetings
And1
#2
German - Deutsch / Zertifikatsverwaltung per API
November 21, 2023, 02:52:24 PM
Hallo zusammen,

gibt es eine Möglichkeit per API, neue Zertifikate hinzuzufügen und auch auszuwählen. Unter /api/ipsec/sessions/searchPhase1 kann ich mir einige Informationen ausgeben lassen aber weiter bin ich bis jetzt noch nicht. Ziel ist es eigentlich, falls ein Zertifikat abläuft, ein neues hochladen zu können und dieses dann auch auszuwählen das es auch angewendet wird. Falls das schon einmal irgendwo diskutiert wurde bitte einfach den Link kommentieren. Danke.

Gruß
And1
#3
German - Deutsch / Restore über API mit Python
October 25, 2023, 12:56:44 PM
Hallo zusammen,

ich habe einem Pythonscript mit verschiedenen Optionen via OPNsense API.
Ich kann bereits ein Backup der aktuellen Einstellungen ziehen das passt auch so.
Ich möchte nun noch per API den Restore Prozess anstoßen, dass ich im Programm das vorher heruntergeladene Backup im xml Format übergebe und dann darauf zurückgesetzt wird. Gibt es hier überhaupt einen geeigneten API Endpunkt, geht es überhaupt wie ich es mir vorstelle oder gibt es einen ganz anderen Weg?

Gruß und Danke
And1
#4
General Discussion / Re: OPNsense Backup with Python
October 19, 2023, 08:35:55 AM
i solved it, the code is correct, but the backup_url must be:  f'{base_url}/backup/backup/download/?format=plain'

Greetings
And1
#5
General Discussion / OPNsense Backup with Python
October 17, 2023, 01:44:23 PM
Hey,
I've recently started working with OPNsense. It's a larger project, and one part of it involves using a Python script to pull a backup of the current settings, which should then be available as an XML file. I already have this code:

python
Copy code
def backup():
    try:
       
        params = {'format': 'plain'}

        backup_url = f'{base_url}/backup/backup/download'
           
        try:
            response = requests.get(backup_url, auth = (api_key, api_secret), params=params, verify=False)
        except Exception as error:
            print(f'Error: {error}')

        if response.status_code == 200:
            with open('test_backup.xml', 'wb') as file:
                file.write(response.content)
                print("Backup successfully downloaded.")
        else:
            print(f"Error downloading the backup. Status code: {response.status_code}")

    except Exception as e:
        print(f'Error: {e}')

    pass
The API key, API secret, and the base URL are declared outside of the function. However, when I execute the code, I always receive a status code of 401. Can someone help me with my little script, or are there completely different approaches to implement this with Python? Please accept that im new in OPNsense, ff I've simply made a silly mistake, please forgive me. I hope someone can assist me. Thank you very much in advance.

And1