hoffmation-base 2.22.15 → 2.22.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
1
  import { Router } from './router';
2
2
  import { iAsusConfig } from '../../config';
3
3
  export declare class AsusRouter extends Router {
4
+ authorizeDevice(_mac: string, _minutes: number, _uploadLimit: number, _downloadLimit: number): Promise<boolean>;
4
5
  private _api;
5
6
  constructor(config: iAsusConfig);
6
7
  reconnectDeviceByIp(ip: string): Promise<boolean>;
@@ -6,6 +6,9 @@ const router_1 = require("./router");
6
6
  const log_service_1 = require("../log-service");
7
7
  const models_1 = require("../../../models");
8
8
  class AsusRouter extends router_1.Router {
9
+ authorizeDevice(_mac, _minutes, _uploadLimit, _downloadLimit) {
10
+ throw new Error('Method not implemented.');
11
+ }
9
12
  constructor(config) {
10
13
  super();
11
14
  this._api = new node_merlin_wrt_api_1.NodeMerlinWrtApi(config.username, config.password, config.address, config.ignoreSSL === true);
@@ -2,6 +2,15 @@ export declare abstract class Router {
2
2
  private static _router;
3
3
  static getRouter(): Router | undefined;
4
4
  protected static setRouter(router: Router): void;
5
+ /**
6
+ * Authorize a device to connect to the network.
7
+ * @param {string} mac - The MAC address of the device.
8
+ * @param {number} minutes - The number of minutes from now on the device is authorized to connect.
9
+ * @param {number} uploadLimit - The upload limit in kbps.
10
+ * @param {number} downloadLimit - The download limit in kbps.
11
+ * @returns {Promise<boolean>} - True if the device was authorized, false otherwise.
12
+ */
13
+ abstract authorizeDevice(mac: string, minutes: number, uploadLimit: number, downloadLimit: number): Promise<boolean>;
5
14
  abstract reconnectDeviceByMac(mac: string): Promise<boolean>;
6
15
  abstract reconnectDeviceByIp(ip: string): Promise<boolean>;
7
16
  }
@@ -5,6 +5,7 @@ export declare class UnifiRouter extends Router {
5
5
  private readonly _api;
6
6
  private _loggedIn;
7
7
  constructor(config: iUnifiSettings);
8
+ authorizeDevice(mac: string, minutes: number, uploadLimit: number, downloadLimit: number): Promise<boolean>;
8
9
  reconnectDeviceByMac(mac: string): Promise<boolean>;
9
10
  reconnectDeviceByIp(_ip: string): Promise<boolean>;
10
11
  private login;
@@ -21,18 +21,37 @@ class UnifiRouter extends router_1.Router {
21
21
  router_1.Router.setRouter(this);
22
22
  this.login();
23
23
  }
24
+ authorizeDevice(mac, minutes, uploadLimit, downloadLimit) {
25
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Unifi: AuthorizeDevice Device "${mac}" for ${minutes} minutes with ${uploadLimit} kbps upload and ${downloadLimit} kbps download`);
26
+ return new Promise(async (resolve, _reject) => {
27
+ if (!this.loggedIn && !(await this.login())) {
28
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Unifi: Can't AuthorizeDevice Device "${mac}" as we can't log in`);
29
+ resolve(false);
30
+ }
31
+ const result = await this._api
32
+ .authorizeGuest(mac, minutes, uploadLimit, downloadLimit)
33
+ .catch((error) => {
34
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Unifi: Failed to AuthorizeDevice "${mac}" due to: ${error}`);
35
+ resolve(false);
36
+ return;
37
+ });
38
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Unifi: AuthorizeDevice ${mac} resulted in ${result}`);
39
+ resolve(true);
40
+ });
41
+ }
24
42
  reconnectDeviceByMac(mac) {
43
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Unifi: Reconnecting Device "${mac}"`);
25
44
  return new Promise(async (resolve, _reject) => {
26
45
  if (!this.loggedIn && !(await this.login())) {
27
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Can't reconnect Device "${mac}" as we can't log in`);
46
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Unifi: Can't reconnect Device "${mac}" as we can't log in`);
28
47
  resolve(false);
29
48
  }
30
49
  const result = await this._api.reconnectClient(mac).catch((error) => {
31
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Failed to reconnect "${mac}" due to: ${error}`);
50
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Unifi: Failed to reconnect "${mac}" due to: ${error}`);
32
51
  resolve(false);
33
52
  return;
34
53
  });
35
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Reconnecting ${mac} resulted in ${result}`);
54
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Trace, `Unifi: Reconnecting ${mac} resulted in ${result}`);
36
55
  resolve(true);
37
56
  });
38
57
  }
@@ -40,12 +59,14 @@ class UnifiRouter extends router_1.Router {
40
59
  throw new Error('Method not implemented, use reconnectDeviceByMac instead.');
41
60
  }
42
61
  login() {
62
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, 'Unifi: Trying to login to Unifi-Controller');
43
63
  return new Promise(async (resolve, _reject) => {
44
64
  await this._api.login().catch((error) => {
45
- log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Unifi-Login failed: ${error}`);
65
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Unifi: Login failed: ${error}`);
46
66
  this._loggedIn = false;
47
67
  resolve(false);
48
68
  });
69
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Info, 'Unifi: Login successful');
49
70
  this._loggedIn = true;
50
71
  resolve(true);
51
72
  });