Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create_backup and get_backup. #76

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pkgname=python-pyunifi
pkgver=r256.cf2c735
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
}

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`

Expand Down
25 changes: 23 additions & 2 deletions pyunifi/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import requests
from urllib3.exceptions import InsecureRequestWarning
from typing import List, Dict


"""For testing purposes:
Expand Down Expand Up @@ -546,7 +547,7 @@ def create_backup(self, days="0"):

res = self._run_command(
"backup",
mgr="system",
mgr="backup",
params={"days": days}
)
return res[0]["url"]
Expand All @@ -569,7 +570,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:
Expand Down Expand Up @@ -861,3 +862,23 @@ 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)

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)