Skip to content

Commit e1299a8

Browse files
Merge pull request #85 from jaredhendrickson13/pf250_fixes
v1.1.5 Features & Fixes
2 parents 066ec98 + dc4ae90 commit e1299a8

19 files changed

Lines changed: 8294 additions & 86 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
2+
*/__pycache__/
23
*.DS_Store
34
.phplint-cache
45

pfSense-pkg-API/files/etc/inc/api/framework/APIResponse.inc

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,13 +272,13 @@ function get($id, $data=[], $all=false) {
272272
"status" => "bad request",
273273
"code" => 400,
274274
"return" => $id,
275-
"message" => "Unbound host override alias already exists"
275+
"message" => "Unbound host override alias already exists with this IP address type"
276276
],
277277
2010 => [
278278
"status" => "bad request",
279279
"code" => 400,
280280
"return" => $id,
281-
"message" => "Unbound host override already exists"
281+
"message" => "Unbound host override already exists with this IP address type"
282282
],
283283
2011 => [
284284
"status" => "bad request",
@@ -490,6 +490,18 @@ function get($id, $data=[], $all=false) {
490490
"return" => $id,
491491
"message" => "DHCPd static mapping ID does not exist"
492492
],
493+
2046 => [
494+
"status" => "bad request",
495+
"code" => 400,
496+
"return" => $id,
497+
"message" => "Invalid unbound host value"
498+
],
499+
2047 => [
500+
"status" => "bad request",
501+
"code" => 400,
502+
"return" => $id,
503+
"message" => "Invalid unbound domain value"
504+
],
493505

494506
// 3000-3999 reserved for /interfaces API calls
495507
3000 => [

pfSense-pkg-API/files/etc/inc/api/framework/APITools.inc

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function create_jwt_server_key($rotate=false) {
119119
# Create a new server key if one is not set
120120
if (empty($api_config["server_key"]) or $rotate === true) {
121121
$config["installedpackages"]["package"][$pkg_index]["conf"]["server_key"] = bin2hex(random_bytes(32));
122-
write_config();
122+
write_config("API server key created");
123123
}
124124
}
125125

@@ -345,10 +345,11 @@ function get_pfsense_if_id($interface) {
345345
}
346346
}
347347

348-
// Check if input is valid for rule source and destination
348+
# Check if input is valid for rule source and destination
349+
# TODO: this function is messy, clean it up
349350
function is_valid_rule_addr($addr, $direction) {
350351
// Variables
351-
$addr_types = array("any", "pppoe", "l2tp"); // Array of special src/dst types
352+
$addr_types = array("any", "pppoe", "l2tp", "(self)"); // Array of special src/dst types
352353
$ret_val = array("valid" => true, "data" => array());
353354
// Check if our source values are valid
354355
if (is_string($addr)) {
@@ -357,24 +358,34 @@ function is_valid_rule_addr($addr, $direction) {
357358
$addr_not = true;
358359
$addr = str_replace("!", "", $addr);
359360
}
360-
// Check if our source data is valid
361-
$addr_if = str_replace("ip", "", $addr); // Save seperate variable to check for interface sourcees
361+
362+
// Check if our data is valid
363+
$addr_if = str_replace("ip", "", $addr);
364+
362365
if (is_ipaddr($addr) or is_subnet($addr)) {
363366
$ret_val["data"] = array($direction => array("address" => $addr));
364367
} elseif (is_alias($addr)) {
365368
$ret_val["data"] = array($direction => array("address" => $addr));
366369
} elseif (get_pfsense_if_id($addr_if)) {
367370
$addr_pfif = get_pfsense_if_id($addr_if); // Save our interface pfid
371+
368372
// If source was interface address (ending in ip), otherwise assume entire subnet
369373
if (str_replace($addr_if, "", $addr) === "ip") {
370374
$ret_val["data"] = array($direction => array("network" => $addr_pfif . "ip"));
371375
} else {
372376
$ret_val["data"] = array($direction => array("network" => $addr_pfif));
373377
}
374378
} elseif (in_array($addr, $addr_types)) {
379+
# Format config for any address
375380
if ($addr === "any") {
376381
$ret_val["data"] = array($direction => array("any" => ""));
377-
} else {
382+
}
383+
# Do not allow (self) address if direction is source
384+
elseif ($addr === "(self)" and $direction === "source") {
385+
$ret_val["valid"] = false;
386+
}
387+
# Otherwise, Format config as network
388+
else {
378389
$ret_val["data"] = array($direction => array("network" => $addr));
379390
}
380391
} else {
@@ -690,36 +701,6 @@ function unbound_reload_config() {
690701
}
691702
}
692703

693-
// Check if a DNS Resolver (Unbound) host override already exists
694-
function is_unbound_fqdn($hostname, $domain, $instance_id=null) {
695-
# Local variables
696-
global $config;
697-
$curr_hosts = (array_key_exists("hosts", $config["unbound"])) ? $config["unbound"]["hosts"] : [];
698-
$host_exists = false;
699-
$index = 0;
700-
701-
# Loop through each host override and check if the FQDN already exists
702-
foreach ($curr_hosts as $host_ent) {
703-
# Check the FQDN matches this entry
704-
if ($host_ent["host"] === $hostname and $host_ent["domain"] === $domain) {
705-
# If we are working with an existing instance, allow existing FQDN if ID matches
706-
if ($index !== $instance_id) {
707-
return true;
708-
}
709-
}
710-
711-
# Check FQDN within host override aliases as well
712-
if (is_array($host_ent["aliases"])) {
713-
foreach ($host_ent["aliases"]["item"] as $alias_ent) {
714-
if ($alias_ent["host"] === $hostname and $alias_ent["domain"] === $domain) {
715-
return true;
716-
}
717-
}
718-
}
719-
$index++;
720-
}
721-
return $host_exists;
722-
}
723704

724705
// Get a complete config list of ALL interfaces. Based off interfaces_assign.php
725706
function get_all_avail_interfaces() {

pfSense-pkg-API/files/etc/inc/api/framework/overrides/system.inc renamed to pfSense-pkg-API/files/etc/inc/api/framework/overrides/2.4.4-RELEASE/system.inc

File renamed without changes.

0 commit comments

Comments
 (0)