Permalink
Browse files

fixed functions assign_existing_admin() and invite_admin() to support…

… controller versions 5.9 and higher because of changes in controller behavior
  • Loading branch information...
malle-pietje committed Jan 21, 2019
1 parent 78bed08 commit 55867197e3465cbf4477f4159ddb188be222d5f6
Showing with 31 additions and 29 deletions.
  1. +2 −2 README.md
  2. +29 −27 src/Client.php
@@ -84,11 +84,11 @@ Please refer to the `examples/` directory for some more detailed examples which

#### IMPORTANT NOTES:

1. In the example above, `$site_id` is the (usually 8 characters) short site "name" which is visible in the URL when managing the site in the UniFi SDN Controller:
1. In the above example, `$site_id` is the short site "name" (usually 8 characters long) that is visible in the URL when managing the site in the UniFi SDN Controller, for example with this URL:

`https://<controller IP address or FQDN>:8443/manage/site/jl3z2shm/dashboard`

In this case, `jl3z2shm` is the value required for $site_id.
`jl3z2shm` is the short site "name" and the value to assign to $site_id.

2. The last optional parameter that is passed to the constructor in the above example (`true`), enables validation of the controller's SSL certificate which is otherwise **disabled** by default. It is highly recommended to enable this feature in production environments where you have a valid SSL cert installed on the UniFi Controller, and which is associated with the FQDN of the server as used in the `controller_url` parameter. This option was added with API client version 1.1.16.

@@ -1522,7 +1522,7 @@ public function set_site_country($country_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/country/' . trim($country_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1544,7 +1544,7 @@ public function set_site_locale($locale_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/locale/' . trim($locale_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1566,7 +1566,7 @@ public function set_site_snmp($snmp_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/snmp/' . trim($snmp_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1588,7 +1588,7 @@ public function set_site_mgmt($mgmt_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/mgmt/' . trim($mgmt_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1610,7 +1610,7 @@ public function set_site_guest_access($guest_access_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/guest_access/' . trim($guest_access_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1632,7 +1632,7 @@ public function set_site_ntp($ntp_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/ntp/' . trim($ntp_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1654,7 +1654,7 @@ public function set_site_connectivity($connectivity_id, $setting)
$this->request_type = 'PUT';
$json = json_encode($setting);
$response = $this->exec_curl('/api/s/' . $this->site . '/rest/setting/connectivity/' . trim($connectivity_id),
'json=' . $json);
'json=' . $json);
return $this->process_response_boolean($response);
}
@@ -1704,11 +1704,11 @@ public function list_all_admins()
* permissions, default value is false which gives the new admin
* Administrator permissions
* optional parameter <device_adopt> = boolean, whether or not the new admin will have permissions to
* adopt devices, default value is false. Only applies when readonly
* is true.
* adopt devices, default value is false. With versions < 5.9.X this only applies
* when readonly is true.
* optional parameter <device_restart> = boolean, whether or not the new admin will have permissions to
* restart devices, default value is false. Only applies when readonly
* is true.
* restart devices, default value is false. With versions < 5.9.X this only applies
* when readonly is true.
*
* NOTES:
* - after issuing a valid request, an invite will be sent to the email address provided
@@ -1738,13 +1738,14 @@ public function invite_admin(
if ($readonly) {
$json['role'] = 'readonly';
if ($device_adopt) {
$permissions[] = "API_DEVICE_ADOPT";
}
}
if ($device_restart) {
$permissions[] = "API_DEVICE_RESTART";
}
if ($device_adopt) {
$permissions[] = "API_DEVICE_ADOPT";
}
if ($device_restart) {
$permissions[] = "API_DEVICE_RESTART";
}
$json['permissions'] = $permissions;
@@ -1764,11 +1765,11 @@ public function invite_admin(
* permissions, default value is false which gives the new admin
* Administrator permissions
* optional parameter <device_adopt> = boolean, whether or not the new admin will have permissions to
* adopt devices, default value is false. Only applies when readonly
* is true.
* adopt devices, default value is false. With versions < 5.9.X this only applies
* when readonly is true.
* optional parameter <device_restart> = boolean, whether or not the new admin will have permissions to
* restart devices, default value is false. Only applies when readonly
* is true.
* restart devices, default value is false. With versions < 5.9.X this only applies
* when readonly is true.
*/
public function assign_existing_admin(
$admin_id,
@@ -1785,13 +1786,14 @@ public function assign_existing_admin(
if ($readonly) {
$json['role'] = 'readonly';
if ($device_adopt) {
$permissions[] = "API_DEVICE_ADOPT";
}
}
if ($device_restart) {
$permissions[] = "API_DEVICE_RESTART";
}
if ($device_adopt) {
$permissions[] = "API_DEVICE_ADOPT";
}
if ($device_restart) {
$permissions[] = "API_DEVICE_RESTART";
}
$json['permissions'] = $permissions;

0 comments on commit 5586719

Please sign in to comment.