@@ -13,8 +13,7 @@ use RESTAPI\Fields\StringField;
1313use RESTAPI \Responses \ValidationError ;
1414use RESTAPI \Validators \IPAddressValidator ;
1515
16- class WireGuardPeer extends Model
17- {
16+ class WireGuardPeer extends Model {
1817 public BooleanField $ enabled ;
1918 public ForeignModelField $ tun ;
2019 public StringField $ endpoint ;
@@ -24,66 +23,61 @@ class WireGuardPeer extends Model
2423 public StringField $ publickey ;
2524 public StringField $ presharedkey ;
2625 public NestedModelField $ allowedips ;
27-
28- public function __construct (mixed $ id = null , mixed $ parent_id = null , mixed $ data = [], ...$ options )
29- {
26+
27+ public function __construct (mixed $ id = null , mixed $ parent_id = null , mixed $ data = [], ...$ options ) {
3028 # Set model attributes
3129 $ this ->many = true ;
3230 $ this ->config_path = 'installedpackages/wireguard/peers/item ' ;
3331 $ this ->verbose_name = 'WireGuard Peer ' ;
3432 $ this ->subsystem = 'wireguard ' ;
3533 $ this ->packages = ['pfSense-pkg-WireGuard ' ];
3634 $ this ->package_includes = ['wireguard/includes/wg_service.inc ' , 'wireguard/includes/wg.inc ' ];
37-
35+
3836 # Set model fields
3937 $ this ->enabled = new BooleanField (
4038 default: false ,
41- indicates_true: " yes " ,
42- indicates_false: " no " ,
43- help_text: " Enables or disables this WireGuard peer. "
39+ indicates_true: ' yes ' ,
40+ indicates_false: ' no ' ,
41+ help_text: ' Enables or disables this WireGuard peer. ' ,
4442 );
4543 $ this ->tun = new ForeignModelField (
46- model_name: " WireGuardTunnel " ,
47- model_field: " name " ,
48- allowed_keywords: [" unassigned " ],
49- default: " unassigned " ,
50- help_text: " The WireGuard tunnel for this peer. "
44+ model_name: ' WireGuardTunnel ' ,
45+ model_field: ' name ' ,
46+ allowed_keywords: [' unassigned ' ],
47+ default: ' unassigned ' ,
48+ help_text: ' The WireGuard tunnel for this peer. ' ,
5149 );
5250 $ this ->endpoint = new StringField (
5351 default: null ,
5452 allow_null: true ,
5553 validators: [new IPAddressValidator (allow_ipv4: true , allow_ipv6: true , allow_fqdn: true )],
56- help_text: " The IP address or hostname of the remote peer. Set to `null` to make this a dynamic endpoint. "
54+ help_text: ' The IP address or hostname of the remote peer. Set to `null` to make this a dynamic endpoint. ' ,
5755 );
5856 $ this ->port = new PortField (
59- default: " 51820 " ,
60- conditions: [" !endpoint " => null ],
61- help_text: " The port used by the remote peer. "
57+ default: ' 51820 ' ,
58+ conditions: [' !endpoint ' => null ],
59+ help_text: ' The port used by the remote peer. ' ,
6260 );
6361 $ this ->persistentkeepalive = new IntegerField (
6462 default: null ,
6563 allow_null: true ,
6664 maximum: 65535 ,
67- help_text: "The interval (in seconds) for Keep Alive packets sent to this peer. Set to `null` to disable. "
68- );
69- $ this ->publickey = new StringField (
70- required: true ,
71- unique: true ,
72- help_text: "The public key for this peer. "
65+ help_text: 'The interval (in seconds) for Keep Alive packets sent to this peer. Set to `null` to disable. ' ,
7366 );
67+ $ this ->publickey = new StringField (required: true , unique: true , help_text: 'The public key for this peer. ' );
7468 $ this ->presharedkey = new StringField (
75- default: "" ,
69+ default: '' ,
7670 allow_null: true ,
7771 write_only: true ,
78- help_text: " The pre-shared key for this tunnel. "
72+ help_text: ' The pre-shared key for this tunnel. ' ,
7973 );
8074 $ this ->allowedips = new NestedModelField (
81- model_class: " WireGuardPeerAllowedIP " ,
75+ model_class: ' WireGuardPeerAllowedIP ' ,
8276 default: [],
8377 allow_empty: true ,
84- help_text: " The allowed IP/subnets for this WireGuard peer. "
78+ help_text: ' The allowed IP/subnets for this WireGuard peer. ' ,
8579 );
86-
80+
8781 parent ::__construct ($ id , $ parent_id , $ data , ...$ options );
8882 }
8983
@@ -97,8 +91,8 @@ class WireGuardPeer extends Model
9791 # Throw an error if this value is not a valid WireGuard key
9892 if (!wg_is_valid_key ($ presharedkey )) {
9993 throw new ValidationError (
100- message: " Field `presharedkey` must be a valid WireGuard pre-shared key. " ,
101- response_id: " WIREGUARD_PEER_PRESHAREDKEY_INVALID "
94+ message: ' Field `presharedkey` must be a valid WireGuard pre-shared key. ' ,
95+ response_id: ' WIREGUARD_PEER_PRESHAREDKEY_INVALID ' ,
10296 );
10397 }
10498
@@ -108,16 +102,14 @@ class WireGuardPeer extends Model
108102 /**
109103 * Serialize changes before applying.
110104 */
111- public function pre_apply (): void
112- {
105+ public function pre_apply (): void {
113106 wg_apply_list_add ('tunnels ' , [$ this ->tun ->value ]);
114107 }
115108
116109 /**
117110 * Applies changes to WireGuard tunnels/peers.
118111 */
119- public function apply (): void
120- {
112+ public function apply (): void {
121113 (new WireGuardSettingsDispatcher (async: $ this ->async ))->spawn_process ();
122114 }
123115}
0 commit comments