|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace RESTAPI\Models; |
| 4 | + |
| 5 | +require_once 'RESTAPI/autoloader.inc'; |
| 6 | + |
| 7 | +use RESTAPI\Core\Model; |
| 8 | +use RESTAPI\Dispatchers\FirewallApplyDispatcher; |
| 9 | +use RESTAPI\Fields\BooleanField; |
| 10 | +use RESTAPI\Fields\InterfaceField; |
| 11 | +use RESTAPI\Fields\StringField; |
| 12 | +use RESTAPI\Validators\IPAddressValidator; |
| 13 | + |
| 14 | +/** |
| 15 | + * Defines a Model for managing pfSense High Availability synchronization settings. |
| 16 | + */ |
| 17 | +class HASync extends Model { |
| 18 | + public StringField $synchronizetoip; |
| 19 | + public StringField $pfsyncpeerip; |
| 20 | + public InterfaceField $pfsyncinterface; |
| 21 | + public StringField $pfhostid; |
| 22 | + public StringField $username; |
| 23 | + public StringField $password; |
| 24 | + public BooleanField $pfsyncenabled; |
| 25 | + public BooleanField $adminsync; |
| 26 | + public BooleanField $synchronizeusers; |
| 27 | + public BooleanField $synchronizeauthservers; |
| 28 | + public BooleanField $synchronizecerts; |
| 29 | + public BooleanField $synchronizerules; |
| 30 | + public BooleanField $synchronizeschedules; |
| 31 | + public BooleanField $synchronizealiases; |
| 32 | + public BooleanField $synchronizenat; |
| 33 | + public BooleanField $synchronizeipsec; |
| 34 | + public BooleanField $synchronizeopenvpn; |
| 35 | + public BooleanField $synchronizedhcpd; |
| 36 | + public BooleanField $synchronizedhcpdv6; |
| 37 | + public BooleanField $synchronizekea6; |
| 38 | + public BooleanField $synchronizewol; |
| 39 | + public BooleanField $synchronizestaticroutes; |
| 40 | + public BooleanField $synchronizevirtualip; |
| 41 | + public BooleanField $synchronizetrafficshaper; |
| 42 | + public BooleanField $synchronizetrafficshaperlimiter; |
| 43 | + public BooleanField $synchronizednsforwarder; |
| 44 | + public BooleanField $synchronizecaptiveportal; |
| 45 | + public BooleanField $synchronizedhcrelay; |
| 46 | + public BooleanField $synchronizedhcrelay6; |
| 47 | + |
| 48 | + public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], mixed ...$options) { |
| 49 | + # Set Model attributes |
| 50 | + $this->config_path = 'hasync'; |
| 51 | + $this->many = false; |
| 52 | + $this->always_apply = true; |
| 53 | + $this->verbose_name = 'HA Sync Settings'; |
| 54 | + $this->verbose_name_plural = 'HA Sync Settings'; |
| 55 | + |
| 56 | + $this->pfsyncenabled = new BooleanField( |
| 57 | + default: false, |
| 58 | + indicates_true: 'on', |
| 59 | + indicates_false: null, |
| 60 | + help_text: 'Enable pfsync state synchronization.', |
| 61 | + ); |
| 62 | + $this->pfsyncinterface = new InterfaceField( |
| 63 | + default: 'lo0', |
| 64 | + allow_localhost_interface: true, |
| 65 | + allow_empty: true, |
| 66 | + help_text: 'The interface used by pfsync state synchronization.', |
| 67 | + ); |
| 68 | + $this->pfhostid = new StringField( |
| 69 | + default: '', |
| 70 | + allow_empty: true, |
| 71 | + maximum_length: 8, |
| 72 | + help_text: 'Custom pf host identifier carried in state data.', |
| 73 | + ); |
| 74 | + $this->pfsyncpeerip = new StringField( |
| 75 | + default: '', |
| 76 | + allow_empty: true, |
| 77 | + validators: [new IPAddressValidator(allow_ipv4: true, allow_ipv6: false)], |
| 78 | + help_text: 'The peer IP address used by pfsync.', |
| 79 | + ); |
| 80 | + $this->synchronizetoip = new StringField( |
| 81 | + default: '', |
| 82 | + allow_empty: true, |
| 83 | + validators: [new IPAddressValidator(allow_ipv4: true, allow_ipv6: false)], |
| 84 | + help_text: 'The remote pfSense host IP address used for XMLRPC configuration synchronization.', |
| 85 | + ); |
| 86 | + $this->username = new StringField( |
| 87 | + default: '', |
| 88 | + allow_empty: true, |
| 89 | + help_text: 'The remote pfSense username used for XMLRPC synchronization.', |
| 90 | + ); |
| 91 | + $this->password = new StringField( |
| 92 | + default: '', |
| 93 | + allow_empty: true, |
| 94 | + write_only: true, |
| 95 | + sensitive: true, |
| 96 | + internal_name: 'passwordfld', |
| 97 | + help_text: 'The remote pfSense password used for XMLRPC synchronization.', |
| 98 | + ); |
| 99 | + $this->adminsync = new BooleanField( |
| 100 | + default: false, |
| 101 | + indicates_true: 'on', |
| 102 | + indicates_false: null, |
| 103 | + help_text: 'Synchronize admin accounts and automatically update the XMLRPC sync password.', |
| 104 | + ); |
| 105 | + $this->synchronizeusers = new BooleanField( |
| 106 | + default: false, |
| 107 | + indicates_true: 'on', |
| 108 | + indicates_false: null, |
| 109 | + help_text: 'Synchronize users and groups.', |
| 110 | + ); |
| 111 | + $this->synchronizeauthservers = new BooleanField( |
| 112 | + default: false, |
| 113 | + indicates_true: 'on', |
| 114 | + indicates_false: null, |
| 115 | + help_text: 'Synchronize authentication servers.', |
| 116 | + ); |
| 117 | + $this->synchronizecerts = new BooleanField( |
| 118 | + default: false, |
| 119 | + indicates_true: 'on', |
| 120 | + indicates_false: null, |
| 121 | + help_text: 'Synchronize certificates.', |
| 122 | + ); |
| 123 | + $this->synchronizerules = new BooleanField( |
| 124 | + default: false, |
| 125 | + indicates_true: 'on', |
| 126 | + indicates_false: null, |
| 127 | + help_text: 'Synchronize firewall rules.', |
| 128 | + ); |
| 129 | + $this->synchronizeschedules = new BooleanField( |
| 130 | + default: false, |
| 131 | + indicates_true: 'on', |
| 132 | + indicates_false: null, |
| 133 | + help_text: 'Synchronize firewall schedules.', |
| 134 | + ); |
| 135 | + $this->synchronizealiases = new BooleanField( |
| 136 | + default: false, |
| 137 | + indicates_true: 'on', |
| 138 | + indicates_false: null, |
| 139 | + help_text: 'Synchronize firewall aliases.', |
| 140 | + ); |
| 141 | + $this->synchronizenat = new BooleanField( |
| 142 | + default: false, |
| 143 | + indicates_true: 'on', |
| 144 | + indicates_false: null, |
| 145 | + help_text: 'Synchronize NAT configuration.', |
| 146 | + ); |
| 147 | + $this->synchronizeipsec = new BooleanField( |
| 148 | + default: false, |
| 149 | + indicates_true: 'on', |
| 150 | + indicates_false: null, |
| 151 | + help_text: 'Synchronize IPsec configuration.', |
| 152 | + ); |
| 153 | + $this->synchronizeopenvpn = new BooleanField( |
| 154 | + default: false, |
| 155 | + indicates_true: 'on', |
| 156 | + indicates_false: null, |
| 157 | + help_text: 'Synchronize OpenVPN configuration.', |
| 158 | + ); |
| 159 | + $this->synchronizedhcpd = new BooleanField( |
| 160 | + default: false, |
| 161 | + indicates_true: 'on', |
| 162 | + indicates_false: null, |
| 163 | + help_text: 'Synchronize DHCP server configuration.', |
| 164 | + ); |
| 165 | + $this->synchronizedhcpdv6 = new BooleanField( |
| 166 | + default: false, |
| 167 | + indicates_true: 'on', |
| 168 | + indicates_false: null, |
| 169 | + help_text: 'Synchronize DHCPv6 server configuration.', |
| 170 | + ); |
| 171 | + $this->synchronizekea6 = new BooleanField( |
| 172 | + default: false, |
| 173 | + indicates_true: 'on', |
| 174 | + indicates_false: null, |
| 175 | + help_text: 'Synchronize Kea DHCPv6 server configuration.', |
| 176 | + ); |
| 177 | + $this->synchronizedhcrelay = new BooleanField( |
| 178 | + default: false, |
| 179 | + indicates_true: 'on', |
| 180 | + indicates_false: null, |
| 181 | + help_text: 'Synchronize DHCP relay configuration.', |
| 182 | + ); |
| 183 | + $this->synchronizedhcrelay6 = new BooleanField( |
| 184 | + default: false, |
| 185 | + indicates_true: 'on', |
| 186 | + indicates_false: null, |
| 187 | + help_text: 'Synchronize DHCPv6 relay configuration.', |
| 188 | + ); |
| 189 | + $this->synchronizewol = new BooleanField( |
| 190 | + default: false, |
| 191 | + indicates_true: 'on', |
| 192 | + indicates_false: null, |
| 193 | + help_text: 'Synchronize Wake-on-LAN configuration.', |
| 194 | + ); |
| 195 | + $this->synchronizestaticroutes = new BooleanField( |
| 196 | + default: false, |
| 197 | + indicates_true: 'on', |
| 198 | + indicates_false: null, |
| 199 | + help_text: 'Synchronize static routes.', |
| 200 | + ); |
| 201 | + $this->synchronizevirtualip = new BooleanField( |
| 202 | + default: false, |
| 203 | + indicates_true: 'on', |
| 204 | + indicates_false: null, |
| 205 | + help_text: 'Synchronize virtual IP addresses.', |
| 206 | + ); |
| 207 | + $this->synchronizetrafficshaper = new BooleanField( |
| 208 | + default: false, |
| 209 | + indicates_true: 'on', |
| 210 | + indicates_false: null, |
| 211 | + help_text: 'Synchronize traffic shaper queues.', |
| 212 | + ); |
| 213 | + $this->synchronizetrafficshaperlimiter = new BooleanField( |
| 214 | + default: false, |
| 215 | + indicates_true: 'on', |
| 216 | + indicates_false: null, |
| 217 | + help_text: 'Synchronize traffic shaper limiters.', |
| 218 | + ); |
| 219 | + $this->synchronizednsforwarder = new BooleanField( |
| 220 | + default: false, |
| 221 | + indicates_true: 'on', |
| 222 | + indicates_false: null, |
| 223 | + help_text: 'Synchronize DNS Forwarder and DNS Resolver configuration.', |
| 224 | + ); |
| 225 | + $this->synchronizecaptiveportal = new BooleanField( |
| 226 | + default: false, |
| 227 | + indicates_true: 'on', |
| 228 | + indicates_false: null, |
| 229 | + help_text: 'Synchronize captive portal configuration.', |
| 230 | + ); |
| 231 | + |
| 232 | + parent::__construct($id, $parent_id, $data, ...$options); |
| 233 | + } |
| 234 | + |
| 235 | + /** |
| 236 | + * Applies HA Sync configuration changes via the FirewallApplyDispatcher. |
| 237 | + */ |
| 238 | + public function apply(): void { |
| 239 | + (new FirewallApplyDispatcher(async: $this->async))->spawn_process(); |
| 240 | + } |
| 241 | +} |
0 commit comments