Skip to content

Add HA Sync (XMLRPC config sync) endpoint (/api/v2/system/hasync) #843

@TechAsen

Description

@TechAsen

Hi,

I would like to request adding support for managing pfSense HA Sync / XMLRPC configuration via the REST API package.

This would allow automation of HA deployments and configuration management without using the GUI.

Proposed endpoint:

  • /api/v2/system/hasync
  • Methods: GET, PATCH
  • Singleton model backed by config path: hasync

Fields to expose:

  • synchronizetoip
  • pfsyncpeerip
  • pfsyncinterface
  • username
  • password (write-only)
  • synchronizeusers
  • synchronizeauthservers
  • synchronizecerts
  • synchronizerules
  • synchronizeschedules
  • synchronizealiases
  • synchronizenat
  • synchronizeipsec
  • synchronizeopenvpn
  • synchronizedhcpd
  • synchronizedhcrelay
  • synchronizedhcrelay6
  • synchronizewol
  • synchronizestaticroutes
  • synchronizevirtualip
  • synchronizetrafficshaper
  • synchronizetrafficshaperlimiter
  • synchronizednsforwarder
  • synchronizecaptiveportal
  • pfsyncenabled

On PATCH the configuration should be applied similarly to GUI:

  • filter_configure_sync()
  • filter_configure()

Implementation draft is attached below.

[Hasinc.inc]

<?php

namespace RESTAPI\Models;

require_once 'RESTAPI/autoloader.inc';

use RESTAPI\Core\Model;
use RESTAPI\Fields\StringField;

class Hasync extends Model {
    public function __construct(...$options) {
        parent::__construct(...$options);

        $this->config_path = 'hasync';
        $this->many = false;

        // Core fields
        $this->synchronizetoip  = new StringField(allow_null: true);
        $this->pfsyncpeerip     = new StringField(allow_null: true);
        $this->pfsyncinterface  = new StringField(allow_null: true);

        $this->username         = new StringField(allow_null: true);
        $this->password         = new StringField(allow_null: true, write_only: true);

        // on/off flags
        foreach ([
            'synchronizeusers',
            'synchronizeauthservers',
            'synchronizecerts',
            'synchronizerules',
            'synchronizeschedules',
            'synchronizealiases',
            'synchronizenat',
            'synchronizeipsec',
            'synchronizeopenvpn',
            'synchronizedhcpd',
            'synchronizedhcrelay',
            'synchronizedhcrelay6',
            'synchronizewol',
            'synchronizestaticroutes',
            'synchronizevirtualip',
            'synchronizetrafficshaper',
            'synchronizetrafficshaperlimiter',
            'synchronizednsforwarder',
            'synchronizecaptiveportal',
            'pfsyncenabled',
        ] as $flag) {
            $this->$flag = new StringField(allow_null: true);
        }
    }

    public function apply_update(): void {
        @require_once('filter.inc');

        // Apply sync settings + reload
        if (function_exists('filter_configure_sync')) {
            filter_configure_sync();
        }
        if (function_exists('filter_configure')) {
            filter_configure();
        }
    }
}

HasyncEndpoint.inc

<?php

namespace RESTAPI\Endpoints;

require_once 'RESTAPI/autoloader.inc';

use RESTAPI\Core\Endpoint;

/**
 * HA Sync settings endpoint (singleton model)
 */
class HasyncEndpoint extends Endpoint {
    public function __construct() {
        $this->url = '/api/v2/system/hasync';
        $this->model_name = 'Hasync';
        $this->request_method_options = ['GET', 'PATCH'];

        parent::__construct();
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    backlogIssues backlogged for inclusion in future releasesfeature requestNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions