Skip to content

Commit 2ffd0e4

Browse files
Fixed #89, /api/v1/system/hostname now correctly applies backend changes
1 parent e1299a8 commit 2ffd0e4

1 file changed

Lines changed: 23 additions & 24 deletions

File tree

pfSense-pkg-API/files/etc/inc/api/models/APISystemHostnameUpdate.inc

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,44 +25,43 @@ class APISystemHostnameUpdate extends APIModel {
2525
}
2626

2727
public function action() {
28-
// Write our new hostname
29-
$this->write_config(); // Apply our configuration change
30-
// Update a slew of backend services
31-
if (isset($hostname) or isset($domain)) {
32-
system_hostname_configure();
33-
system_hosts_generate();
34-
system_resolvconf_generate();
35-
if (isset($this->config['dnsmasq']['enable'])) {
36-
services_dnsmasq_configure();
37-
} elseif (isset($this->config['unbound']['enable'])) {
38-
services_unbound_configure();
39-
}
40-
filter_configure();
41-
}
28+
# Write our new hostname and apply changes to the backend
29+
$this->write_config();
30+
$this->apply_backend_changes();
31+
4232
$data = ["hostname" => $this->config["system"]["hostname"], "domain" => $this->config["system"]["domain"]];
4333
return APIResponse\get(0, $data);
4434
}
4535

4636
public function validate_payload() {
4737
if (isset($this->initial_data['hostname'])) {
48-
$hostname = $this->initial_data['hostname'];
49-
$hostname = trim($hostname);
50-
// Check if our hostname is valid
51-
if (!is_hostname($hostname) or !is_unqualified_hostname($hostname)) {
38+
# Check if our hostname is valid
39+
if (!is_hostname($this->initial_data['hostname']) or !is_unqualified_hostname($this->initial_data['hostname'])) {
5240
$this->errors[] = APIResponse\get(1000);
5341
} else {
54-
$this->config["system"]["hostname"] = $hostname;
42+
$this->config["system"]["hostname"] = $this->initial_data['hostname'];
5543
}
5644
}
5745
if (isset($this->initial_data['domain'])) {
58-
$domain = $this->initial_data['domain'];
59-
$domain = trim($domain);
60-
// Check if our hostname is valid
61-
if (!is_domain($domain)) {
46+
# Check if our hostname is valid
47+
if (!is_domain($this->initial_data['domain'])) {
6248
$this->errors[] = APIResponse\get(1001);
6349
} else {
64-
$this->config["system"]["domain"] = $domain;
50+
$this->config["system"]["domain"] = $this->initial_data['domain'];
6551
}
6652
}
6753
}
54+
55+
public function apply_backend_changes() {
56+
# Update a slew of backend services
57+
system_hostname_configure();
58+
system_hosts_generate();
59+
system_resolvconf_generate();
60+
if (isset($this->config['dnsmasq']['enable'])) {
61+
services_dnsmasq_configure();
62+
} elseif (isset($this->config['unbound']['enable'])) {
63+
services_unbound_configure();
64+
}
65+
filter_configure();
66+
}
6867
}

0 commit comments

Comments
 (0)