Skip to content

Commit 38896a3

Browse files
Merge branch 'next_patch' of github.com:jaredhendrickson13/pfsense-api into next_minor
# Conflicts: # pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/FirewallRule.inc
2 parents a2d8bfd + e4f3ff7 commit 38896a3

10 files changed

Lines changed: 323 additions & 56 deletions

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Core/Endpoint.inc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ class Endpoint {
239239
*/
240240
public array $delete_privileges = [];
241241

242+
/**
243+
* @var bool $requires_page_all_privilege
244+
* When enabled, this endpoint will always require the page-all privilege and will
245+
* disable auto-generated/scoped REST API privileges for this endpoint.
246+
*/
247+
public bool $requires_page_all_privilege = false;
248+
242249
/**
243250
* @var string $get_help_text
244251
* Sets the GET request's OpenAPI documentation for this Endpoint. This will be
@@ -534,6 +541,17 @@ class Endpoint {
534541
*/
535542
private function get_default_privs(): void {
536543
$page_all_priv = 'page-all';
544+
545+
# If this endpoint requires page-all, then only assign page-all to the privileges for each method
546+
if ($this->requires_page_all_privilege) {
547+
$this->get_privileges = [$page_all_priv];
548+
$this->post_privileges = [$page_all_priv];
549+
$this->patch_privileges = [$page_all_priv];
550+
$this->put_privileges = [$page_all_priv];
551+
$this->delete_privileges = [$page_all_priv];
552+
return;
553+
}
554+
537555
$this->get_privileges = [$page_all_priv, $this->get_method_priv_name('GET')];
538556
$this->post_privileges = [$page_all_priv, $this->get_method_priv_name('POST')];
539557
$this->patch_privileges = [$page_all_priv, $this->get_method_priv_name('PATCH')];
@@ -564,6 +582,11 @@ class Endpoint {
564582
* @returns array The pfSense priv list entry array corresponding to the privileges of this Endpoint.
565583
*/
566584
public function generate_pfsense_privs(): array {
585+
# If this endpoint requires page-all, do not generate privileges
586+
if ($this->requires_page_all_privilege) {
587+
return [];
588+
}
589+
567590
# Set an array to populate pfSense priv entries for this Endpoint
568591
$privs = [];
569592

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Endpoints/SystemRESTAPISettingsSyncEndpoint.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class SystemRESTAPISettingsSyncEndpoint extends Endpoint {
2222
$this->ignore_interfaces = true;
2323
$this->ignore_read_only = true;
2424
$this->auth_methods = ['BasicAuth'];
25+
$this->requires_page_all_privilege = true;
2526

2627
# Construct the parent Endpoint object
2728
parent::__construct();

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/FirewallRule.inc

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class FirewallRule extends Model {
3535
public StringField $descr;
3636
public BooleanField $disabled;
3737
public BooleanField $log;
38+
public StringField $dscp;
3839
public StringField $tag;
3940
public StringField $statetype;
4041
public BooleanField $tcp_flags_any;
@@ -138,8 +139,8 @@ class FirewallRule extends Model {
138139
'unreach',
139140
],
140141
many: true,
141-
conditions: ['protocol' => 'icmp'],
142142
verbose_name: 'ICMP Types',
143+
conditions: ['protocol' => 'icmp'],
143144
help_text: 'Th ICMP subtypes this rule applies to. This field is only applicable when ' .
144145
'`ipprotocol` is `inet` and `protocol` is `icmp`.',
145146
);
@@ -153,10 +154,10 @@ class FirewallRule extends Model {
153154
allow_alias: true,
154155
allow_range: true,
155156
allow_null: true,
157+
verbose_name: 'Source Port',
156158
internal_name: 'port',
157159
internal_namespace: 'source',
158160
conditions: ['protocol' => ['tcp', 'udp', 'tcp/udp']],
159-
verbose_name: 'Source Port',
160161
help_text: 'The source port this rule applies to. Set to `null` to allow any source port.',
161162
);
162163
$this->destination = new FilterAddressField(
@@ -169,10 +170,10 @@ class FirewallRule extends Model {
169170
allow_alias: true,
170171
allow_range: true,
171172
allow_null: true,
173+
verbose_name: 'Destination Port',
172174
internal_name: 'port',
173175
internal_namespace: 'destination',
174176
conditions: ['protocol' => ['tcp', 'udp', 'tcp/udp']],
175-
verbose_name: 'Destination Port',
176177
help_text: 'The destination port this rule applies to. Set to `null` to allow any destination port.',
177178
);
178179
$this->descr = new StringField(
@@ -192,8 +193,9 @@ class FirewallRule extends Model {
192193
help_text: 'Enable or disable logging of traffic that matches this rule.',
193194
);
194195
$this->dscp = new StringField(
195-
default: '',
196+
default: null,
196197
choices: [
198+
'',
197199
'af11',
198200
'af12',
199201
'af13',
@@ -220,6 +222,7 @@ class FirewallRule extends Model {
220222
'0x04',
221223
],
222224
allow_empty: true,
225+
allow_null: true,
223226
verbose_name: 'DSCP',
224227
help_text: 'The DSCP value this firewall rule should match.',
225228
);
@@ -237,28 +240,28 @@ class FirewallRule extends Model {
237240
);
238241
$this->tcp_flags_any = new BooleanField(
239242
default: false,
240-
internal_name: 'tcpflags_any',
241243
verbose_name: 'TCP Flags Any',
244+
internal_name: 'tcpflags_any',
242245
help_text: 'Allow any TCP flags.',
243246
);
244247
$this->tcp_flags_out_of = new StringField(
245248
default: null,
246249
choices: ['fin', 'syn', 'rst', 'psh', 'ack', 'urg', 'ece', 'cwr'],
247250
allow_null: true,
248251
many: true,
252+
verbose_name: 'TCP Flags Out Of',
249253
internal_name: 'tcpflags2',
250254
conditions: ['tcp_flags_any' => false],
251-
verbose_name: 'TCP Flags Out Of',
252255
help_text: 'The TCP flags that can be set for this rule to match.',
253256
);
254257
$this->tcp_flags_set = new StringField(
255258
default: null,
256259
choices: ['fin', 'syn', 'rst', 'psh', 'ack', 'urg', 'ece', 'cwr'],
257260
allow_null: true,
258261
many: true,
262+
verbose_name: 'TCP Flags Set',
259263
internal_name: 'tcpflags1',
260264
conditions: ['tcp_flags_any' => false],
261-
verbose_name: 'TCP Flags Set',
262265
help_text: 'The TCP flags that must be set for this rule to match.',
263266
);
264267
$this->gateway = new ForeignModelField(
@@ -317,16 +320,16 @@ class FirewallRule extends Model {
317320
$this->quick = new BooleanField(
318321
default: false,
319322
indicates_true: 'yes',
320-
conditions: ['floating' => true],
321323
verbose_name: 'Quick',
324+
conditions: ['floating' => true],
322325
help_text: 'Apply this action to traffic that matches this rule immediately. This field only applies ' .
323326
'to floating firewall rules.',
324327
);
325328
$this->direction = new StringField(
326329
default: 'any',
327330
choices: ['any', 'in', 'out'],
328-
conditions: ['floating' => true],
329331
verbose_name: 'Direction',
332+
conditions: ['floating' => true],
330333
help_text: 'The direction of traffic this firewall rule applies to. This field only applies to ' .
331334
'floating firewall rules.',
332335
);
@@ -343,43 +346,43 @@ class FirewallRule extends Model {
343346
allow_null: true,
344347
editable: false,
345348
read_only: true,
346-
internal_name: 'associated-rule-id',
347349
verbose_name: 'Associated Rule ID',
350+
internal_name: 'associated-rule-id',
348351
help_text: 'The internal rule ID for the NAT rule associated with this rule.',
349352
);
350353
$this->created_time = new UnixTimeField(
351354
editable: false,
352355
read_only: true,
353356
auto_add_now: true,
357+
verbose_name: 'Created Time',
354358
internal_name: 'time',
355359
internal_namespace: 'created',
356-
verbose_name: 'Created Time',
357360
help_text: 'The unix timestamp of when this firewall rule was original created.',
358361
);
359362
$this->created_by = new StringField(
360363
default: "{$this->client->username}@{$this->client->ip_address} (API)",
361364
editable: false,
362365
read_only: true,
366+
verbose_name: 'Created By',
363367
internal_name: 'username',
364368
internal_namespace: 'created',
365-
verbose_name: 'Created By',
366369
help_text: 'The username and IP of the user who originally created this firewall rule.',
367370
);
368371
$this->updated_time = new UnixTimeField(
369372
read_only: true,
370373
auto_add_now: true,
371374
auto_update_now: true,
375+
verbose_name: 'Updated Time',
372376
internal_name: 'time',
373377
internal_namespace: 'updated',
374-
verbose_name: 'Updated Time',
375378
help_text: 'The unix timestamp of when this firewall rule was original created.',
376379
);
377380
$this->updated_by = new StringField(
378381
default: "{$this->client->username}@{$this->client->ip_address} (API)",
379382
read_only: true,
383+
verbose_name: 'Updated By',
380384
internal_name: 'username',
381385
internal_namespace: 'updated',
382-
verbose_name: 'Updated By',
383386
help_text: 'The username and IP of the user who last updated this firewall rule.',
384387
);
385388

pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/LogSettings.inc

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ class LogSettings extends Model {
6262
);
6363
$this->reverseorder = new BooleanField(
6464
default: false,
65-
internal_name: 'reverse', # We can't use 'reverse' as the field name because it is a reserved field name
66-
verbose_name: 'Reverse Order',
65+
verbose_name: 'Reverse Order', # We can't use 'reverse' as the field name because it is a reserved field name
66+
internal_name: 'reverse',
6767
help_text: 'Reverse the order of log entries.',
6868
);
6969
$this->nentries = new IntegerField(
@@ -123,7 +123,7 @@ class LogSettings extends Model {
123123
$this->logfilesize = new IntegerField(
124124
default: 512000,
125125
minimum: 100000,
126-
maximum: 2147483648,
126+
maximum: PHP_INT_MAX,
127127
verbose_name: 'Log File Size',
128128
help_text: 'The maximum size of the log file in kilobytes.',
129129
);
@@ -142,126 +142,126 @@ class LogSettings extends Model {
142142
);
143143
$this->enableremotelogging = new BooleanField(
144144
default: false,
145-
internal_name: 'enable',
146145
verbose_name: 'Enable Remote Logging',
146+
internal_name: 'enable',
147147
help_text: 'Enable remote logging.',
148148
);
149149
$this->ipprotocol = new StringField(
150150
default: 'ipv4',
151151
choices: ['ipv4', 'ipv6'],
152-
conditions: ['enableremotelogging' => true],
153152
verbose_name: 'IP Protocol',
153+
conditions: ['enableremotelogging' => true],
154154
help_text: 'The IP protocol to use for remote logging.',
155155
);
156156
$this->sourceip = new InterfaceField(
157157
default: '',
158158
allow_localhost_interface: true,
159159
allow_custom: [''],
160160
allow_empty: true,
161-
conditions: ['enableremotelogging' => true],
162161
verbose_name: 'Source IP',
162+
conditions: ['enableremotelogging' => true],
163163
help_text: 'The interface to use as the source IP address for remote logging.',
164164
);
165165
$this->remoteserver = new StringField(
166166
default: null,
167167
allow_null: true,
168+
verbose_name: 'Remote Server',
168169
conditions: ['enableremotelogging' => true],
169170
validators: [new IPAddressValidator(allow_fqdn: true, allow_port: true)],
170-
verbose_name: 'Remote Server',
171171
help_text: 'The first remote syslog server to send log entries to.',
172172
);
173173
$this->remoteserver2 = new StringField(
174174
default: null,
175175
allow_null: true,
176+
verbose_name: 'Remote Server 2',
176177
conditions: ['enableremotelogging' => true, '!remoteserver' => null],
177178
validators: [new IPAddressValidator(allow_fqdn: true, allow_port: true)],
178-
verbose_name: 'Remote Server 2',
179179
help_text: 'The second remote syslog server to send log entries to.',
180180
);
181181
$this->remoteserver3 = new StringField(
182182
default: null,
183183
allow_null: true,
184+
verbose_name: 'Remote Server 3',
184185
conditions: ['enableremotelogging' => true, '!remoteserver' => null, '!remoteserver2' => null],
185186
validators: [new IPAddressValidator(allow_fqdn: true, allow_port: true)],
186-
verbose_name: 'Remote Server 3',
187187
help_text: 'The third remote syslog server to send log entries to.',
188188
);
189189
$this->logall = new BooleanField(
190190
default: false,
191-
conditions: ['enableremotelogging' => true],
192191
verbose_name: 'Log All',
192+
conditions: ['enableremotelogging' => true],
193193
help_text: 'Log everything to the remote syslog server(s).',
194194
);
195195
$this->filter = new BooleanField(
196196
default: false,
197-
conditions: ['enableremotelogging' => true, '!logall' => true],
198197
verbose_name: 'Filter',
198+
conditions: ['enableremotelogging' => true, '!logall' => true],
199199
help_text: 'Log filter events to the remote syslog server(s).',
200200
);
201201
$this->dhcp = new BooleanField(
202202
default: false,
203-
conditions: ['enableremotelogging' => true, '!logall' => true],
204203
verbose_name: 'DHCP',
204+
conditions: ['enableremotelogging' => true, '!logall' => true],
205205
help_text: 'Log DHCP events to the remote syslog server(s).',
206206
);
207207
$this->auth = new BooleanField(
208208
default: false,
209-
conditions: ['enableremotelogging' => true, '!logall' => true],
210209
verbose_name: 'Auth',
210+
conditions: ['enableremotelogging' => true, '!logall' => true],
211211
help_text: 'Log authentication events to the remote syslog server(s).',
212212
);
213213
$this->portalauth = new BooleanField(
214214
default: false,
215-
conditions: ['enableremotelogging' => true, '!logall' => true],
216215
verbose_name: 'Portal Auth',
216+
conditions: ['enableremotelogging' => true, '!logall' => true],
217217
help_text: 'Log captive portal authentication events to the remote syslog server(s).',
218218
);
219219
$this->vpn = new BooleanField(
220220
default: false,
221-
conditions: ['enableremotelogging' => true, '!logall' => true],
222221
verbose_name: 'VPN',
222+
conditions: ['enableremotelogging' => true, '!logall' => true],
223223
help_text: 'Log VPN events to the remote syslog server(s).',
224224
);
225225
$this->dpinger = new BooleanField(
226226
default: false,
227-
conditions: ['enableremotelogging' => true, '!logall' => true],
228227
verbose_name: 'Dpinger',
228+
conditions: ['enableremotelogging' => true, '!logall' => true],
229229
help_text: 'Log gateway monitoring events to the remote syslog server(s).',
230230
);
231231
$this->hostapd = new BooleanField(
232232
default: false,
233-
conditions: ['enableremotelogging' => true, '!logall' => true],
234233
verbose_name: 'Host APD',
234+
conditions: ['enableremotelogging' => true, '!logall' => true],
235235
help_text: 'Log wireless authentication events to the remote syslog server(s).',
236236
);
237237
$this->system = new BooleanField(
238238
default: false,
239-
conditions: ['enableremotelogging' => true, '!logall' => true],
240239
verbose_name: 'System',
240+
conditions: ['enableremotelogging' => true, '!logall' => true],
241241
help_text: 'Log system events to the remote syslog server(s).',
242242
);
243243
$this->resolver = new BooleanField(
244244
default: false,
245-
conditions: ['enableremotelogging' => true, '!logall' => true],
246245
verbose_name: 'Resolver',
246+
conditions: ['enableremotelogging' => true, '!logall' => true],
247247
help_text: 'Log DNS resolver events to the remote syslog server(s).',
248248
);
249249
$this->ppp = new BooleanField(
250250
default: false,
251-
conditions: ['enableremotelogging' => true, '!logall' => true],
252251
verbose_name: 'PPP',
252+
conditions: ['enableremotelogging' => true, '!logall' => true],
253253
help_text: 'Log PPP events to the remote syslog server(s).',
254254
);
255255
$this->routing = new BooleanField(
256256
default: false,
257-
conditions: ['enableremotelogging' => true, '!logall' => true],
258257
verbose_name: 'Routing',
258+
conditions: ['enableremotelogging' => true, '!logall' => true],
259259
help_text: 'Log routing events to the remote syslog server(s).',
260260
);
261261
$this->ntpd = new BooleanField(
262262
default: false,
263-
conditions: ['enableremotelogging' => true, '!logall' => true],
264263
verbose_name: 'NTPd',
264+
conditions: ['enableremotelogging' => true, '!logall' => true],
265265
help_text: 'Log NTP events to the remote syslog server(s).',
266266
);
267267

0 commit comments

Comments
 (0)