From 2c985010d46b0592239505be4db6b07dbf062c93 Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Tue, 30 Aug 2022 09:47:25 +0200 Subject: [PATCH 1/8] Fixed create_backup by using mgr="backup" instead of mgr="system" --- pyunifi/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyunifi/controller.py b/pyunifi/controller.py index aafc9a2..81a59fe 100644 --- a/pyunifi/controller.py +++ b/pyunifi/controller.py @@ -546,7 +546,7 @@ def create_backup(self, days="0"): res = self._run_command( "backup", - mgr="system", + mgr="backup", params={"days": days} ) return res[0]["url"] From 3cd0361e9bbaad59ecd3cebd7c3404d9faeccc13 Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Tue, 30 Aug 2022 09:49:05 +0200 Subject: [PATCH 2/8] get_backup always failed with status code 200 (OK) --- pyunifi/controller.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyunifi/controller.py b/pyunifi/controller.py index 81a59fe..c3426a1 100644 --- a/pyunifi/controller.py +++ b/pyunifi/controller.py @@ -569,7 +569,7 @@ def get_backup(self, download_path=None, target_file="unifi-backup.unf"): response = self.session.get(self.url + download_path, stream=True) - if response != 200: + if response.status_code != 200: raise APIError("API backup failed: %i" % response.status_code) with open(target_file, "wb") as _backfh: From a60c150a20a6b6c726a057f22d1b638a82f1126c Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Tue, 30 Aug 2022 09:53:57 +0200 Subject: [PATCH 3/8] Added argument download_path for the function get_backup to the documentation in the README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f3b486d..059d421 100644 --- a/README.md +++ b/README.md @@ -151,11 +151,11 @@ then be used to restore a controller on another machine. Remember that this puts significant load on a controller for some time (depending on the amount of users and managed APs). -### `get_backup(self, targetfile)` +### `get_backup(self, download_path=None, targetfile="unifi-backup.unf")` Tells the controller to create a backup archive and downloads it to a file. It should have a .unf extension for later restore. - - - `targetfile` -- the target file name, you can also use a full path. Default creates unifi-backup.unf in the current directoy. + - `download_path` -- the url of the `.unf` file to be downloaded. If this is `None` then `create_backup()` is called first. + - `targetfile` -- the target file name. You can also use a full path. Default creates unifi-backup.unf in the current directoy. ### `authorize_guest(self, guest_mac, minutes, up_bandwidth=None, down_bandwidth=None, byte_quota=None, ap_mac=None)` From ae66546dfa43fc9dcf2cc8feb4e0b42f684d3b8e Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Sat, 26 Nov 2022 18:33:38 +0100 Subject: [PATCH 4/8] add function get_rogues to Controller; props to Moritz --- pyunifi/controller.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyunifi/controller.py b/pyunifi/controller.py index c3426a1..3a15475 100644 --- a/pyunifi/controller.py +++ b/pyunifi/controller.py @@ -861,3 +861,10 @@ def delete_voucher(self, voucher_id): cmd = "delete-voucher" params = {"_id": voucher_id} self._run_command(cmd, mgr="hotspot", params=params) + + def get_rogues(self, hours: int = 48): + """Return a list of rogue APs + """ + params = {"within": hours} + return self._api_read("stat/rogueap", params) + From 15e0645703def298493ce3594e2a3c7ac0e9d2ce Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Sun, 12 Mar 2023 21:04:43 +0100 Subject: [PATCH 5/8] add PKGBUILD --- PKGBUILD | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 PKGBUILD diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 0000000..58e413e --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,27 @@ +pkgname=python-pyunifi +pkgver=r252.a60c150 +pkgrel=1 +pkgdesc='A rewrite of https://github.com/unifi-hackers/unifi-lab in cleaner Python.' +arch=('any') +url='https://github.com/BoostCookie/pyunifi' +license=('MIT') +depends=('python-requests') +makedepends=('python-setuptools') +source=("${pkgname}::git+https://github.com/BoostCookie/pyunifi.git") +md5sums=('SKIP') + +pkgver() { + cd "$pkgname" + printf "r%s.%s" "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)" +} + +build() { + cd "$pkgname" + python setup.py build +} + +package() { + cd "$pkgname" + python setup.py install --root="$pkgdir" --optimize=1 +} + From d4c0db1ed0e1955c8eb9fd7d16300dbc42406200 Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Fri, 5 May 2023 08:35:56 +0200 Subject: [PATCH 6/8] pggver --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index 58e413e..d1baa37 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,5 +1,5 @@ pkgname=python-pyunifi -pkgver=r252.a60c150 +pkgver=r254.15e0645 pkgrel=1 pkgdesc='A rewrite of https://github.com/unifi-hackers/unifi-lab in cleaner Python.' arch=('any') From cf2c73593b7801a64f00a8e937143ead70134e53 Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Fri, 5 May 2023 22:40:18 +0200 Subject: [PATCH 7/8] Added functions for radius Added get_radius_profiles and set_radius_auth_servers --- pyunifi/controller.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pyunifi/controller.py b/pyunifi/controller.py index 3a15475..d43fc2e 100644 --- a/pyunifi/controller.py +++ b/pyunifi/controller.py @@ -9,6 +9,7 @@ import requests from urllib3.exceptions import InsecureRequestWarning +from typing import List, Dict """For testing purposes: @@ -868,3 +869,16 @@ def get_rogues(self, hours: int = 48): params = {"within": hours} return self._api_read("stat/rogueap", params) + def get_radius_profiles(self): + """ + Return a list of radius profiles + """ + return self._api_read("rest/radiusprofile") + + def set_radius_auth_servers(self, _id: str, auth_servers: List[Dict]): + """ + Return a list of radius profiles + """ + params = {"auth_servers": auth_servers} + return self._api_update("rest/radiusprofile/" + _id, params) + From 468609da4a855ab5cb2463b9af8765a562474687 Mon Sep 17 00:00:00 2001 From: Stefan Gehr Date: Thu, 2 May 2024 18:31:55 +0200 Subject: [PATCH 8/8] update version --- PKGBUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PKGBUILD b/PKGBUILD index d1baa37..bc2029b 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -1,5 +1,5 @@ pkgname=python-pyunifi -pkgver=r254.15e0645 +pkgver=r256.cf2c735 pkgrel=1 pkgdesc='A rewrite of https://github.com/unifi-hackers/unifi-lab in cleaner Python.' arch=('any')