mirror of
https://github.com/WGDashboard/WGDashboard.git
synced 2026-12-01 17:07:47 +00:00
+1







![dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)

Donald Zou
dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
daanselen
neolegshishov
Tom Mills
Giuseppe Marinelli
Claude Sonnet 4.6
freetushkan
sneds91
sgtdeagle
Truffle
b83c0f85ba
* build(deps): bump sqlalchemy from 2.0.46 to 2.0.49 in /src
Bumps [sqlalchemy](https://github.com/sqlalchemy/sqlalchemy) from 2.0.46 to 2.0.49.
- [Release notes](https://github.com/sqlalchemy/sqlalchemy/releases)
- [Changelog](https://github.com/sqlalchemy/sqlalchemy/blob/main/CHANGES.rst)
- [Commits](https://github.com/sqlalchemy/sqlalchemy/commits)
---
updated-dependencies:
- dependency-name: sqlalchemy
dependency-version: 2.0.49
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump ol from 10.7.0 to 10.8.0 in /src/static/app
Bumps [ol](https://github.com/openlayers/openlayers) from 10.7.0 to 10.8.0.
- [Release notes](https://github.com/openlayers/openlayers/releases)
- [Commits](https://github.com/openlayers/openlayers/compare/v10.7.0...v10.8.0)
---
updated-dependencies:
- dependency-name: ol
dependency-version: 10.8.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump vue from 3.5.31 to 3.5.32 in /src/static/app
Bumps [vue](https://github.com/vuejs/core) from 3.5.31 to 3.5.32.
- [Release notes](https://github.com/vuejs/core/releases)
- [Changelog](https://github.com/vuejs/core/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vuejs/core/compare/v3.5.31...v3.5.32)
---
updated-dependencies:
- dependency-name: vue
dependency-version: 3.5.32
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump fuse.js from 7.1.0 to 7.3.0 in /src/static/app
Bumps [fuse.js](https://github.com/krisk/Fuse) from 7.1.0 to 7.3.0.
- [Release notes](https://github.com/krisk/Fuse/releases)
- [Changelog](https://github.com/krisk/Fuse/blob/main/CHANGELOG.md)
- [Commits](https://github.com/krisk/Fuse/compare/v7.1.0...v7.3.0)
---
updated-dependencies:
- dependency-name: fuse.js
dependency-version: 7.3.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 7.3.1 to 8.0.8 in /src/static/app
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 7.3.1 to 8.0.8.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.8/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.8
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 6.4.1 to 8.0.8 in /src/static/client
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 6.4.1 to 8.0.8.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.8/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.8
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump cidr-tools from 11.3.2 to 11.3.3 in /src/static/app
Bumps [cidr-tools](https://github.com/silverwind/cidr-tools) from 11.3.2 to 11.3.3.
- [Release notes](https://github.com/silverwind/cidr-tools/releases)
- [Commits](https://github.com/silverwind/cidr-tools/compare/11.3.2...11.3.3)
---
updated-dependencies:
- dependency-name: cidr-tools
dependency-version: 11.3.3
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump uuid from 11.1.0 to 13.0.0 in /src/static/client
Bumps [uuid](https://github.com/uuidjs/uuid) from 11.1.0 to 13.0.0.
- [Release notes](https://github.com/uuidjs/uuid/releases)
- [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/uuidjs/uuid/compare/v11.1.0...v13.0.0)
---
updated-dependencies:
- dependency-name: uuid
dependency-version: 13.0.0
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump oidc-client-ts in /src/static/client
Bumps [oidc-client-ts](https://github.com/authts/oidc-client-ts) from 3.2.1 to 3.5.0.
- [Release notes](https://github.com/authts/oidc-client-ts/releases)
- [Commits](https://github.com/authts/oidc-client-ts/compare/v3.2.1...v3.5.0)
---
updated-dependencies:
- dependency-name: oidc-client-ts
dependency-version: 3.5.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump pydantic from 2.12.5 to 2.13.0 in /src
Bumps [pydantic](https://github.com/pydantic/pydantic) from 2.12.5 to 2.13.0.
- [Release notes](https://github.com/pydantic/pydantic/releases)
- [Changelog](https://github.com/pydantic/pydantic/blob/main/HISTORY.md)
- [Commits](https://github.com/pydantic/pydantic/compare/v2.12.5...v2.13.0)
---
updated-dependencies:
- dependency-name: pydantic
dependency-version: 2.13.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump vue from 3.5.16 to 3.5.32 in /src/static/client
Bumps [vue](https://github.com/vuejs/core) from 3.5.16 to 3.5.32.
- [Release notes](https://github.com/vuejs/core/releases)
- [Changelog](https://github.com/vuejs/core/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vuejs/core/compare/v3.5.16...v3.5.32)
---
updated-dependencies:
- dependency-name: vue
dependency-version: 3.5.32
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* fix: misspell (#1231)
* build(deps-dev): bump vite-plugin-vue-devtools in /src/static/client
Bumps [vite-plugin-vue-devtools](https://github.com/vuejs/devtools/tree/HEAD/packages/vite) from 7.7.6 to 8.1.1.
- [Release notes](https://github.com/vuejs/devtools/releases)
- [Commits](https://github.com/vuejs/devtools/commits/v8.1.1/packages/vite)
---
updated-dependencies:
- dependency-name: vite-plugin-vue-devtools
dependency-version: 8.1.1
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite-plugin-vue-devtools in /src/static/client
Bumps [vite-plugin-vue-devtools](https://github.com/vuejs/devtools/tree/HEAD/packages/vite) from 7.7.6 to 8.1.1.
- [Release notes](https://github.com/vuejs/devtools/releases)
- [Commits](https://github.com/vuejs/devtools/commits/v8.1.1/packages/vite)
---
updated-dependencies:
- dependency-name: vite-plugin-vue-devtools
dependency-version: 8.1.1
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump vue from 3.5.16 to 3.5.32 in /src/static/client
Bumps [vue](https://github.com/vuejs/core) from 3.5.16 to 3.5.32.
- [Release notes](https://github.com/vuejs/core/releases)
- [Changelog](https://github.com/vuejs/core/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vuejs/core/compare/v3.5.16...v3.5.32)
---
updated-dependencies:
- dependency-name: vue
dependency-version: 3.5.32
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump pydantic from 2.12.5 to 2.13.0 in /src
Bumps [pydantic](https://github.com/pydantic/pydantic) from 2.12.5 to 2.13.0.
- [Release notes](https://github.com/pydantic/pydantic/releases)
- [Changelog](https://github.com/pydantic/pydantic/blob/main/HISTORY.md)
- [Commits](https://github.com/pydantic/pydantic/compare/v2.12.5...v2.13.0)
---
updated-dependencies:
- dependency-name: pydantic
dependency-version: 2.13.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump sqlalchemy from 2.0.46 to 2.0.49 in /src
Bumps [sqlalchemy](https://github.com/sqlalchemy/sqlalchemy) from 2.0.46 to 2.0.49.
- [Release notes](https://github.com/sqlalchemy/sqlalchemy/releases)
- [Changelog](https://github.com/sqlalchemy/sqlalchemy/blob/main/CHANGES.rst)
- [Commits](https://github.com/sqlalchemy/sqlalchemy/commits)
---
updated-dependencies:
- dependency-name: sqlalchemy
dependency-version: 2.0.49
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* feat: commit PR 1237 to development
* Add preshared key default toggle (#1207)
* Add previous PR changes
* Import lowercase dayjs
* Build dist
* Revert "Build dist"
This reverts commit 152da2ca10
Dist not to be built at @DaanSelen request
* build(deps): bump pydantic from 2.13.0 to 2.13.3 in /src
Bumps [pydantic](https://github.com/pydantic/pydantic) from 2.13.0 to 2.13.3.
- [Release notes](https://github.com/pydantic/pydantic/releases)
- [Changelog](https://github.com/pydantic/pydantic/blob/main/HISTORY.md)
- [Commits](https://github.com/pydantic/pydantic/compare/v2.13.0...v2.13.3)
---
updated-dependencies:
- dependency-name: pydantic
dependency-version: 2.13.3
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump uuid from 13.0.0 to 14.0.0 in /src/static/app
Bumps [uuid](https://github.com/uuidjs/uuid) from 13.0.0 to 14.0.0.
- [Release notes](https://github.com/uuidjs/uuid/releases)
- [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/uuidjs/uuid/compare/v13.0.0...v14.0.0)
---
updated-dependencies:
- dependency-name: uuid
dependency-version: 14.0.0
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 8.0.8 to 8.0.9 in /src/static/app
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 8.0.8 to 8.0.9.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.9/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.9
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump @vue/language-server in /src/static/app
Bumps [@vue/language-server](https://github.com/vuejs/language-tools/tree/HEAD/packages/language-server) from 3.2.4 to 3.2.7.
- [Release notes](https://github.com/vuejs/language-tools/releases)
- [Changelog](https://github.com/vuejs/language-tools/blob/master/CHANGELOG.md)
- [Commits](https://github.com/vuejs/language-tools/commits/v3.2.7/packages/language-server)
---
updated-dependencies:
- dependency-name: "@vue/language-server"
dependency-version: 3.2.7
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump ol from 10.8.0 to 10.9.0 in /src/static/app
Bumps [ol](https://github.com/openlayers/openlayers) from 10.8.0 to 10.9.0.
- [Release notes](https://github.com/openlayers/openlayers/releases)
- [Commits](https://github.com/openlayers/openlayers/compare/v10.8.0...v10.9.0)
---
updated-dependencies:
- dependency-name: ol
dependency-version: 10.9.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump @vitejs/plugin-vue in /src/static/client
Bumps [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/HEAD/packages/plugin-vue) from 5.2.4 to 6.0.6.
- [Release notes](https://github.com/vitejs/vite-plugin-vue/releases)
- [Changelog](https://github.com/vitejs/vite-plugin-vue/blob/main/packages/plugin-vue/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite-plugin-vue/commits/[email protected]/packages/plugin-vue)
---
updated-dependencies:
- dependency-name: "@vitejs/plugin-vue"
dependency-version: 6.0.6
dependency-type: direct:development
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump axios from 1.14.0 to 1.15.1 in /src/static/client
Bumps [axios](https://github.com/axios/axios) from 1.14.0 to 1.15.1.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.14.0...v1.15.1)
---
updated-dependencies:
- dependency-name: axios
dependency-version: 1.15.1
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump uuid from 13.0.0 to 14.0.0 in /src/static/client
Bumps [uuid](https://github.com/uuidjs/uuid) from 13.0.0 to 14.0.0.
- [Release notes](https://github.com/uuidjs/uuid/releases)
- [Changelog](https://github.com/uuidjs/uuid/blob/main/CHANGELOG.md)
- [Commits](https://github.com/uuidjs/uuid/compare/v13.0.0...v14.0.0)
---
updated-dependencies:
- dependency-name: uuid
dependency-version: 14.0.0
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump pinia from 3.0.2 to 3.0.4 in /src/static/client
Bumps [pinia](https://github.com/vuejs/pinia) from 3.0.2 to 3.0.4.
- [Release notes](https://github.com/vuejs/pinia/releases)
- [Commits](https://github.com/vuejs/pinia/compare/v3.0.2...v3.0.4)
---
updated-dependencies:
- dependency-name: pinia
dependency-version: 3.0.4
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* Refactor peer schedule job API to use proper REST verbs (#1239)
* Fixed quotation marks
* Update wgd.sh
* Refactor peer schedule job API to use proper REST verbs
Replace single POST endpoints with POST/PUT/DELETE for peer schedule jobs.
Add require_fields decorator for request validation. Add fetchPut and
fetchDelete helpers in the frontend.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* Add local development with Docker section to docker/README.md
Explains how to mount src/ as a volume for live code editing
using a compose-local.yaml setup.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
* Update README dev section with frontend build instructions
Replace Vite dev server tip with npm install/build workflow
and docker restart step.
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
---------
Co-authored-by: Donald Zou <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
* A patch to support a wide range of AmneziaWG versions. (#1210)
Support for all keys ever used in AmneziaWG has been added. Setting an empty value to a key will prevent it from being used or rendered in the configuration. This ensures flexible support for all versions and specific configurations.
* Fix config info loss when renaming a tunnel. (#1254)
This migrates data to the new tunnel when renaming, such as: Description, OverridePeerSettings, PeerGroups, PeerHistoricalEndpointTracking, PeerTrafficTracking.
* build(deps-dev): bump @vitejs/plugin-vue in /src/static/app
Bumps [@vitejs/plugin-vue](https://github.com/vitejs/vite-plugin-vue/tree/HEAD/packages/plugin-vue) from 6.0.4 to 6.0.6.
- [Release notes](https://github.com/vitejs/vite-plugin-vue/releases)
- [Changelog](https://github.com/vitejs/vite-plugin-vue/blob/main/packages/plugin-vue/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite-plugin-vue/commits/[email protected]/packages/plugin-vue)
---
updated-dependencies:
- dependency-name: "@vitejs/plugin-vue"
dependency-version: 6.0.6
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump bootstrap from 5.3.6 to 5.3.8 in /src/static/client
Bumps [bootstrap](https://github.com/twbs/bootstrap) from 5.3.6 to 5.3.8.
- [Release notes](https://github.com/twbs/bootstrap/releases)
- [Commits](https://github.com/twbs/bootstrap/compare/v5.3.6...v5.3.8)
---
updated-dependencies:
- dependency-name: bootstrap
dependency-version: 5.3.8
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* Fix TOTP verification with valid window
* build(deps): bump pymysql from 1.1.2 to 1.1.3 in /src
Bumps [pymysql](https://github.com/PyMySQL/PyMySQL) from 1.1.2 to 1.1.3.
- [Release notes](https://github.com/PyMySQL/PyMySQL/releases)
- [Changelog](https://github.com/PyMySQL/PyMySQL/blob/main/CHANGELOG.md)
- [Commits](https://github.com/PyMySQL/PyMySQL/compare/v1.1.2...v1.1.3)
---
updated-dependencies:
- dependency-name: pymysql
dependency-version: 1.1.3
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump psycopg from 3.3.3 to 3.3.4 in /src
Bumps [psycopg](https://github.com/psycopg/psycopg) from 3.3.3 to 3.3.4.
- [Changelog](https://github.com/psycopg/psycopg/blob/master/docs/news.rst)
- [Commits](https://github.com/psycopg/psycopg/compare/3.3.3...3.3.4)
---
updated-dependencies:
- dependency-name: psycopg
dependency-version: 3.3.4
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump npm from 11.12.1 to 11.13.0 in /src/static/app
Bumps [npm](https://github.com/npm/cli) from 11.12.1 to 11.13.0.
- [Release notes](https://github.com/npm/cli/releases)
- [Changelog](https://github.com/npm/cli/blob/v11.13.0/CHANGELOG.md)
- [Commits](https://github.com/npm/cli/compare/v11.12.1...v11.13.0)
---
updated-dependencies:
- dependency-name: npm
dependency-version: 11.13.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump @vueuse/shared in /src/static/app
Bumps [@vueuse/shared](https://github.com/vueuse/vueuse/tree/HEAD/packages/shared) from 14.2.1 to 14.3.0.
- [Release notes](https://github.com/vueuse/vueuse/releases)
- [Commits](https://github.com/vueuse/vueuse/commits/v14.3.0/packages/shared)
---
updated-dependencies:
- dependency-name: "@vueuse/shared"
dependency-version: 14.3.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump vue-router from 5.0.4 to 5.0.6 in /src/static/app
Bumps [vue-router](https://github.com/vuejs/router) from 5.0.4 to 5.0.6.
- [Release notes](https://github.com/vuejs/router/releases)
- [Commits](https://github.com/vuejs/router/compare/v5.0.4...v5.0.6)
---
updated-dependencies:
- dependency-name: vue-router
dependency-version: 5.0.6
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 8.0.9 to 8.0.10 in /src/static/app
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 8.0.9 to 8.0.10.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.10/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.10
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump cidr-tools from 11.3.3 to 11.3.5 in /src/static/app
Bumps [cidr-tools](https://github.com/silverwind/cidr-tools) from 11.3.3 to 11.3.5.
- [Release notes](https://github.com/silverwind/cidr-tools/releases)
- [Commits](https://github.com/silverwind/cidr-tools/compare/11.3.3...11.3.5)
---
updated-dependencies:
- dependency-name: cidr-tools
dependency-version: 11.3.5
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump axios from 1.15.1 to 1.16.0 in /src/static/client
Bumps [axios](https://github.com/axios/axios) from 1.15.1 to 1.16.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.15.1...v1.16.0)
---
updated-dependencies:
- dependency-name: axios
dependency-version: 1.16.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* change email attachmentname to peerName if not empty
* Use network_address for single-address IPs
When parsing allowed_ip entries in API_ping_getAllPeersIpAddress(), detect networks with a single address (ip.num_addresses == 1) and append ip.network_address directly to the parsed list. This replaces the previous host-list construction (list(ip.hosts()) / host[0]) to simplify logic and avoid iterating hosts for /32 or single-address ranges while keeping existing error logging for invalid addresses.
* build(deps): bump requests from 2.32.5 to 2.34.0 in /src
Bumps [requests](https://github.com/psf/requests) from 2.32.5 to 2.34.0.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.32.5...v2.34.0)
---
updated-dependencies:
- dependency-name: requests
dependency-version: 2.34.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump gunicorn from 25.0.3 to 26.0.0 in /src
Bumps [gunicorn](https://github.com/benoitc/gunicorn) from 25.0.3 to 26.0.0.
- [Release notes](https://github.com/benoitc/gunicorn/releases)
- [Commits](https://github.com/benoitc/gunicorn/compare/25.0.3...26.0.0)
---
updated-dependencies:
- dependency-name: gunicorn
dependency-version: 26.0.0
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump pydantic from 2.13.3 to 2.13.4 in /src
Bumps [pydantic](https://github.com/pydantic/pydantic) from 2.13.3 to 2.13.4.
- [Release notes](https://github.com/pydantic/pydantic/releases)
- [Changelog](https://github.com/pydantic/pydantic/blob/v2.13.4/HISTORY.md)
- [Commits](https://github.com/pydantic/pydantic/compare/v2.13.3...v2.13.4)
---
updated-dependencies:
- dependency-name: pydantic
dependency-version: 2.13.4
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 8.0.8 to 8.0.12 in /src/static/client
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 8.0.8 to 8.0.12.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.12/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.12
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* Fix Python 3.11 SyntaxError in AmneziaPeer.py (#1290)
Python 3.11 raises 'f-string expression part cannot include a backslash'
on line 91, where strip('\n') sits inside an f-string {...}. PEP 701
lifted this restriction in 3.12.
Bind the decoded output to a local so the strip call happens outside
the f-string, which also removes the duplicate decode+strip already
performed on the preceding length check.
Closes #1289
Signed-off-by: Truffle <[email protected]>
* build(deps): bump vue from 3.5.32 to 3.5.35 in /src/static/client
Bumps [vue](https://github.com/vuejs/core) from 3.5.32 to 3.5.35.
- [Release notes](https://github.com/vuejs/core/releases)
- [Changelog](https://github.com/vuejs/core/blob/main/CHANGELOG.md)
- [Commits](https://github.com/vuejs/core/compare/v3.5.32...v3.5.35)
---
updated-dependencies:
- dependency-name: vue
dependency-version: 3.5.34
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite-plugin-vue-devtools in /src/static/client
Bumps [vite-plugin-vue-devtools](https://github.com/vuejs/devtools/tree/HEAD/packages/vite) from 8.1.1 to 8.1.2.
- [Release notes](https://github.com/vuejs/devtools/releases)
- [Commits](https://github.com/vuejs/devtools/commits/v8.1.2/packages/vite)
---
updated-dependencies:
- dependency-name: vite-plugin-vue-devtools
dependency-version: 8.1.2
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump vue-router from 4.5.1 to 5.1.0 in /src/static/client
Bumps [vue-router](https://github.com/vuejs/router) from 4.5.1 to 5.1.0.
- [Release notes](https://github.com/vuejs/router/releases)
- [Commits](https://github.com/vuejs/router/compare/v4.5.1...v5.1.0)
---
updated-dependencies:
- dependency-name: vue-router
dependency-version: 5.0.6
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump requests from 2.34.0 to 2.34.2 in /src
Bumps [requests](https://github.com/psf/requests) from 2.34.0 to 2.34.2.
- [Release notes](https://github.com/psf/requests/releases)
- [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md)
- [Commits](https://github.com/psf/requests/compare/v2.34.0...v2.34.2)
---
updated-dependencies:
- dependency-name: requests
dependency-version: 2.34.2
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump @vuepic/vue-datepicker in /src/static/app
Bumps [@vuepic/vue-datepicker](https://github.com/Vuepic/vue-datepicker) from 12.1.0 to 14.0.0.
- [Release notes](https://github.com/Vuepic/vue-datepicker/releases)
- [Changelog](https://github.com/Vuepic/vue-datepicker/blob/main/CHANGELOG.md)
- [Commits](https://github.com/Vuepic/vue-datepicker/compare/v12.1.0...v14.0.0)
---
updated-dependencies:
- dependency-name: "@vuepic/vue-datepicker"
dependency-version: 14.0.0
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump flask-cors from 6.0.2 to 6.0.5 in /src
Bumps [flask-cors](https://github.com/corydolphin/flask-cors) from 6.0.2 to 6.0.5.
- [Release notes](https://github.com/corydolphin/flask-cors/releases)
- [Changelog](https://github.com/corydolphin/flask-cors/blob/main/CHANGELOG.md)
- [Commits](https://github.com/corydolphin/flask-cors/compare/6.0.2...6.0.5)
---
updated-dependencies:
- dependency-name: flask-cors
dependency-version: 6.0.5
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump pymysql from 1.1.3 to 1.2.0 in /src
Bumps [pymysql](https://github.com/PyMySQL/PyMySQL) from 1.1.3 to 1.2.0.
- [Release notes](https://github.com/PyMySQL/PyMySQL/releases)
- [Changelog](https://github.com/PyMySQL/PyMySQL/blob/main/CHANGELOG.md)
- [Commits](https://github.com/PyMySQL/PyMySQL/compare/v1.1.3...v1.2.0)
---
updated-dependencies:
- dependency-name: pymysql
dependency-version: 1.2.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 8.0.10 to 8.0.16 in /src/static/app
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 8.0.10 to 8.0.16.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.16/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.16
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump cidr-tools from 11.3.5 to 12.0.2 in /src/static/app
Bumps [cidr-tools](https://github.com/silverwind/cidr-tools) from 11.3.5 to 12.0.2.
- [Release notes](https://github.com/silverwind/cidr-tools/releases)
- [Commits](https://github.com/silverwind/cidr-tools/compare/11.3.5...12.0.2)
---
updated-dependencies:
- dependency-name: cidr-tools
dependency-version: 12.0.2
dependency-type: direct:production
update-type: version-update:semver-major
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps-dev): bump vite from 8.0.12 to 8.0.16 in /src/static/client
Bumps [vite](https://github.com/vitejs/vite/tree/HEAD/packages/vite) from 8.0.12 to 8.0.16.
- [Release notes](https://github.com/vitejs/vite/releases)
- [Changelog](https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md)
- [Commits](https://github.com/vitejs/vite/commits/v8.0.16/packages/vite)
---
updated-dependencies:
- dependency-name: vite
dependency-version: 8.0.16
dependency-type: direct:development
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump dayjs from 1.11.20 to 1.11.21 in /src/static/client
Bumps [dayjs](https://github.com/iamkun/dayjs) from 1.11.20 to 1.11.21.
- [Release notes](https://github.com/iamkun/dayjs/releases)
- [Changelog](https://github.com/iamkun/dayjs/blob/dev/CHANGELOG.md)
- [Commits](https://github.com/iamkun/dayjs/compare/v1.11.20...v1.11.21)
---
updated-dependencies:
- dependency-name: dayjs
dependency-version: 1.11.21
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump pyotp from 2.9.0 to 2.10.0 in /src
Bumps [pyotp](https://github.com/pyauth/pyotp) from 2.9.0 to 2.10.0.
- [Release notes](https://github.com/pyauth/pyotp/releases)
- [Changelog](https://github.com/pyauth/pyotp/blob/main/Changes.rst)
- [Commits](https://github.com/pyauth/pyotp/compare/v2.9.0...v2.10.0)
---
updated-dependencies:
- dependency-name: pyotp
dependency-version: 2.10.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump alpine from 3.23 to 3.24 in /docker
Bumps alpine from 3.23 to 3.24.
---
updated-dependencies:
- dependency-name: alpine
dependency-version: '3.24'
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump sqlalchemy from 2.0.49 to 2.0.51 in /src
Bumps [sqlalchemy](https://github.com/sqlalchemy/sqlalchemy) from 2.0.49 to 2.0.51.
- [Release notes](https://github.com/sqlalchemy/sqlalchemy/releases)
- [Changelog](https://github.com/sqlalchemy/sqlalchemy/blob/main/CHANGES.rst)
- [Commits](https://github.com/sqlalchemy/sqlalchemy/commits)
---
updated-dependencies:
- dependency-name: sqlalchemy
dependency-version: 2.0.51
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <[email protected]>
* build(deps): bump axios from 1.16.0 to 1.18.0 in /src/static/client
Bumps [axios](https://github.com/axios/axios) from 1.16.0 to 1.18.0.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/v1.x/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v1.16.0...v1.18.0)
---
updated-dependencies:
- dependency-name: axios
dependency-version: 1.18.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <[email protected]>
* Added OIDC for admin side
* Updated OIDC Algorithm Fallback
* chore: remove dist
---------
Signed-off-by: dependabot[bot] <[email protected]>
Signed-off-by: Truffle <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Daan Selen <[email protected]>
Co-authored-by: neolegshishov <[email protected]>
Co-authored-by: Tom Mills <[email protected]>
Co-authored-by: Giuseppe Marinelli <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Co-authored-by: freetushkan <[email protected]>
Co-authored-by: sneds91 <[email protected]>
Co-authored-by: sgtdeagle <[email protected]>
Co-authored-by: Truffle <[email protected]>
1843 lines
81 KiB
Python
1843 lines
81 KiB
Python
import logging
|
|
import random, shutil, sqlite3, configparser, hashlib, ipaddress, json, os, secrets, subprocess
|
|
import time, re, uuid, bcrypt, psutil, pyotp, threading
|
|
import traceback
|
|
from functools import wraps
|
|
from urllib.parse import unquote
|
|
from uuid import uuid4
|
|
from zipfile import ZipFile
|
|
from datetime import datetime, timedelta
|
|
|
|
import sqlalchemy
|
|
from jinja2 import Template
|
|
from flask import Flask, request, render_template, session, send_file, current_app, redirect, url_for
|
|
from flask_cors import CORS
|
|
from icmplib import ping, traceroute
|
|
from flask.json.provider import DefaultJSONProvider
|
|
from itertools import islice
|
|
|
|
from sqlalchemy import RowMapping
|
|
|
|
from modules.Utilities import (
|
|
RegexMatch, StringToBoolean, ValidateDNSAddress,
|
|
GenerateWireguardPublicKey, GenerateWireguardPrivateKey
|
|
)
|
|
from packaging import version
|
|
from modules.Email import EmailSender
|
|
from modules.DashboardLogger import DashboardLogger
|
|
from modules.PeerJob import PeerJob
|
|
from modules.SystemStatus import SystemStatus
|
|
from modules.PeerShareLinks import PeerShareLinks
|
|
from modules.PeerJobs import PeerJobs
|
|
from modules.DashboardConfig import DashboardConfig
|
|
from modules.WireguardConfiguration import WireguardConfiguration
|
|
from modules.AmneziaConfiguration import AmneziaConfiguration
|
|
from modules.DashboardOIDC import DashboardOIDC
|
|
|
|
from client import createClientBlueprint
|
|
|
|
from logging.config import dictConfig
|
|
|
|
from modules.DashboardClients import DashboardClients
|
|
from modules.DashboardPlugins import DashboardPlugins
|
|
from modules.DashboardWebHooks import DashboardWebHooks
|
|
from modules.NewConfigurationTemplates import NewConfigurationTemplates
|
|
|
|
class CustomJsonEncoder(DefaultJSONProvider):
|
|
def __init__(self, app):
|
|
super().__init__(app)
|
|
|
|
def default(self, o):
|
|
if callable(getattr(o, "toJson", None)):
|
|
return o.toJson()
|
|
if type(o) is RowMapping:
|
|
return dict(o)
|
|
if type(o) is datetime:
|
|
return o.strftime("%Y-%m-%d %H:%M:%S")
|
|
return super().default(self)
|
|
|
|
|
|
|
|
'''
|
|
Response Object
|
|
'''
|
|
def ResponseObject(status=True, message=None, data=None, status_code = 200) -> Flask.response_class:
|
|
response = Flask.make_response(app, {
|
|
"status": status,
|
|
"message": message,
|
|
"data": data
|
|
})
|
|
response.status_code = status_code
|
|
response.content_type = "application/json"
|
|
return response
|
|
|
|
def require_fields(*fields):
|
|
"""Decorator that validates required fields in request.json."""
|
|
def decorator(f):
|
|
@wraps(f)
|
|
def decorated(*args, **kwargs):
|
|
data = request.json
|
|
if data is None:
|
|
return ResponseObject(False, "Request body must be JSON", status_code=400)
|
|
missing = [field for field in fields if field not in data]
|
|
if missing:
|
|
return ResponseObject(False, f"Missing required fields: {', '.join(missing)}", status_code=400)
|
|
return f(*args, **kwargs)
|
|
return decorated
|
|
return decorator
|
|
|
|
'''
|
|
Flask App
|
|
'''
|
|
_, APP_PREFIX_INIT = DashboardConfig().GetConfig("Server", "app_prefix")
|
|
app = Flask("WGDashboard",
|
|
template_folder=os.path.abspath("./static/dist/WGDashboardAdmin"),
|
|
static_folder=os.path.abspath("./static/dist/WGDashboardAdmin"),
|
|
static_url_path=APP_PREFIX_INIT if APP_PREFIX_INIT else '')
|
|
|
|
def peerInformationBackgroundThread():
|
|
global WireguardConfigurations
|
|
app.logger.info("Background Thread #1 Started")
|
|
app.logger.info("Background Thread #1 PID:" + str(threading.get_native_id()))
|
|
delay = 6
|
|
time.sleep(10)
|
|
while True:
|
|
with app.app_context():
|
|
try:
|
|
curKeys = list(WireguardConfigurations.keys())
|
|
for name in curKeys:
|
|
if name in WireguardConfigurations.keys() and WireguardConfigurations.get(name) is not None:
|
|
c = WireguardConfigurations.get(name)
|
|
if c.getStatus():
|
|
c.getPeersLatestHandshake()
|
|
c.getPeersTransfer()
|
|
c.getPeersEndpoint()
|
|
c.getPeers()
|
|
if DashboardConfig.GetConfig('WireGuardConfiguration', 'peer_tracking')[1] is True:
|
|
print("[WGDashboard] Tracking Peers")
|
|
if delay == 6:
|
|
if c.configurationInfo.PeerTrafficTracking:
|
|
c.logPeersTraffic()
|
|
if c.configurationInfo.PeerHistoricalEndpointTracking:
|
|
c.logPeersHistoryEndpoint()
|
|
c.getRestrictedPeersList()
|
|
except Exception as e:
|
|
app.logger.error(f"[WGDashboard] Background Thread #1 Error", e)
|
|
|
|
if delay == 6:
|
|
delay = 1
|
|
else:
|
|
delay += 1
|
|
time.sleep(10)
|
|
|
|
def peerJobScheduleBackgroundThread():
|
|
with app.app_context():
|
|
app.logger.info(f"Background Thread #2 Started")
|
|
app.logger.info(f"Background Thread #2 PID:" + str(threading.get_native_id()))
|
|
time.sleep(10)
|
|
while True:
|
|
try:
|
|
AllPeerJobs.runJob()
|
|
time.sleep(180)
|
|
except Exception as e:
|
|
app.logger.error("Background Thread #2 Error", e)
|
|
|
|
def gunicornConfig():
|
|
_, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
|
|
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
|
return app_ip, app_port
|
|
|
|
def ProtocolsEnabled() -> list[str]:
|
|
from shutil import which
|
|
protocols = []
|
|
if which('awg') is not None and which('awg-quick') is not None:
|
|
protocols.append("awg")
|
|
if which('wg') is not None and which('wg-quick') is not None:
|
|
protocols.append("wg")
|
|
return protocols
|
|
|
|
def InitWireguardConfigurationsList(startup: bool = False):
|
|
if os.path.exists(DashboardConfig.GetConfig("Server", "wg_conf_path")[1]):
|
|
confs = os.listdir(DashboardConfig.GetConfig("Server", "wg_conf_path")[1])
|
|
confs.sort()
|
|
for i in confs:
|
|
if RegexMatch("^(.{1,}).(conf)$", i):
|
|
i = i.replace('.conf', '')
|
|
try:
|
|
if i in WireguardConfigurations.keys():
|
|
if WireguardConfigurations[i].configurationFileChanged():
|
|
with app.app_context():
|
|
WireguardConfigurations[i] = WireguardConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, i)
|
|
else:
|
|
with app.app_context():
|
|
WireguardConfigurations[i] = WireguardConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, i, startup=startup)
|
|
except WireguardConfiguration.InvalidConfigurationFileException as e:
|
|
app.logger.error(f"{i} have an invalid configuration file.")
|
|
|
|
if "awg" in ProtocolsEnabled():
|
|
confs = os.listdir(DashboardConfig.GetConfig("Server", "awg_conf_path")[1])
|
|
confs.sort()
|
|
for i in confs:
|
|
if RegexMatch("^(.{1,}).(conf)$", i):
|
|
i = i.replace('.conf', '')
|
|
try:
|
|
if i in WireguardConfigurations.keys():
|
|
if WireguardConfigurations[i].configurationFileChanged():
|
|
with app.app_context():
|
|
WireguardConfigurations[i] = AmneziaConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, i)
|
|
else:
|
|
with app.app_context():
|
|
WireguardConfigurations[i] = AmneziaConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, i, startup=startup)
|
|
except WireguardConfiguration.InvalidConfigurationFileException as e:
|
|
app.logger.error(f"{i} have an invalid configuration file.")
|
|
|
|
def startThreads():
|
|
bgThread = threading.Thread(target=peerInformationBackgroundThread, daemon=True)
|
|
bgThread.start()
|
|
scheduleJobThread = threading.Thread(target=peerJobScheduleBackgroundThread, daemon=True)
|
|
scheduleJobThread.start()
|
|
|
|
dictConfig({
|
|
'version': 1,
|
|
'formatters': {'default': {
|
|
'format': '[%(asctime)s] [%(levelname)s] in [%(module)s] %(message)s',
|
|
}},
|
|
'root': {
|
|
'level': 'INFO'
|
|
}
|
|
})
|
|
|
|
|
|
WireguardConfigurations: dict[str, WireguardConfiguration] = {}
|
|
CONFIGURATION_PATH = os.getenv('CONFIGURATION_PATH', '.')
|
|
|
|
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 5206928
|
|
app.secret_key = secrets.token_urlsafe(32)
|
|
app.json = CustomJsonEncoder(app)
|
|
with app.app_context():
|
|
SystemStatus = SystemStatus()
|
|
DashboardConfig = DashboardConfig()
|
|
EmailSender = EmailSender(DashboardConfig)
|
|
AllPeerShareLinks: PeerShareLinks = PeerShareLinks(DashboardConfig, WireguardConfigurations)
|
|
AllPeerJobs: PeerJobs = PeerJobs(DashboardConfig, WireguardConfigurations, AllPeerShareLinks)
|
|
DashboardLogger: DashboardLogger = DashboardLogger()
|
|
DashboardPlugins: DashboardPlugins = DashboardPlugins(app, WireguardConfigurations)
|
|
DashboardWebHooks: DashboardWebHooks = DashboardWebHooks(DashboardConfig)
|
|
NewConfigurationTemplates: NewConfigurationTemplates = NewConfigurationTemplates()
|
|
InitWireguardConfigurationsList(startup=True)
|
|
DashboardClients: DashboardClients = DashboardClients(WireguardConfigurations)
|
|
AdminOIDC = DashboardOIDC("Admin")
|
|
app.register_blueprint(createClientBlueprint(WireguardConfigurations, DashboardConfig, DashboardClients))
|
|
|
|
_, APP_PREFIX = DashboardConfig.GetConfig("Server", "app_prefix")
|
|
cors = CORS(app, resources={rf"{APP_PREFIX}/api/*": {
|
|
"origins": "*",
|
|
"methods": "DELETE, POST, GET, OPTIONS",
|
|
"allow_headers": ["Content-Type", "wg-dashboard-apikey"]
|
|
}})
|
|
_, app_ip = DashboardConfig.GetConfig("Server", "app_ip")
|
|
_, app_port = DashboardConfig.GetConfig("Server", "app_port")
|
|
_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path")
|
|
|
|
'''
|
|
API Routes
|
|
'''
|
|
|
|
@app.before_request
|
|
def auth_req():
|
|
if request.method.lower() == 'options':
|
|
return ResponseObject(True)
|
|
|
|
DashboardConfig.APIAccessed = False
|
|
authenticationRequired = DashboardConfig.GetConfig("Server", "auth_req")[1]
|
|
d = request.headers
|
|
if authenticationRequired:
|
|
apiKey = d.get('wg-dashboard-apikey')
|
|
apiKeyEnabled = DashboardConfig.GetConfig("Server", "dashboard_api_key")[1]
|
|
if apiKey is not None and len(apiKey) > 0 and apiKeyEnabled:
|
|
apiKeyExist = len(list(filter(lambda x : x.Key == apiKey, DashboardConfig.DashboardAPIKeys))) == 1
|
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"API Key Access: {('true' if apiKeyExist else 'false')} - Key: {apiKey}")
|
|
if not apiKeyExist:
|
|
DashboardConfig.APIAccessed = False
|
|
response = Flask.make_response(app, {
|
|
"status": False,
|
|
"message": "API Key does not exist",
|
|
"data": None
|
|
})
|
|
response.content_type = "application/json"
|
|
response.status_code = 401
|
|
return response
|
|
DashboardConfig.APIAccessed = True
|
|
else:
|
|
DashboardConfig.APIAccessed = False
|
|
appPrefix = APP_PREFIX if len(APP_PREFIX) > 0 else ''
|
|
whiteList = [
|
|
# f'/static/',
|
|
f'{appPrefix}/api/validateAuthentication',
|
|
f'{appPrefix}/api/authenticate',
|
|
# f'{appPrefix}/api/getDashboardConfiguration',
|
|
f'{appPrefix}/api/getDashboardTheme',
|
|
f'{appPrefix}/api/getDashboardVersion',
|
|
f'{appPrefix}/api/sharePeer/get',
|
|
f'{appPrefix}/api/isTotpEnabled',
|
|
f'{appPrefix}/api/locale',
|
|
f'{appPrefix}/api/oidc/providers',
|
|
f'{appPrefix}/api/oidc/authenticate',
|
|
]
|
|
|
|
|
|
if (
|
|
("username" not in session or session.get("role") != "admin")
|
|
and (f"{appPrefix}/" != request.path and f"{appPrefix}" != request.path)
|
|
and not request.path.startswith(f'{appPrefix}/client')
|
|
and not request.path.startswith(f'{appPrefix}/img')
|
|
and not request.path.startswith(f'{appPrefix}/json')
|
|
and not request.path.startswith(f'{appPrefix}/assets')
|
|
and request.path not in whiteList
|
|
):
|
|
response = Flask.make_response(app, {
|
|
"status": False,
|
|
"message": "Unauthorized access.",
|
|
"data": None
|
|
})
|
|
response.content_type = "application/json"
|
|
response.status_code = 401
|
|
return response
|
|
|
|
@app.route(f'{APP_PREFIX}/api/handshake', methods=["GET", "OPTIONS"])
|
|
def API_Handshake():
|
|
return ResponseObject(True)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/validateAuthentication')
|
|
def API_ValidateAuthentication():
|
|
token = request.cookies.get("authToken")
|
|
if DashboardConfig.GetConfig("Server", "auth_req")[1]:
|
|
if token is None or token == "" or "username" not in session or session["username"] != token:
|
|
return ResponseObject(False, "Invalid authentication.")
|
|
return ResponseObject(True)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/requireAuthentication')
|
|
def API_RequireAuthentication():
|
|
return ResponseObject(data=DashboardConfig.GetConfig("Server", "auth_req")[1])
|
|
|
|
# OIDC for Admin
|
|
@app.get(f'{APP_PREFIX}/api/oidc/providers')
|
|
def API_OIDC_GetProviders():
|
|
_, oidc = DashboardConfig.GetConfig("OIDC", "admin_enable")
|
|
if not oidc:
|
|
return ResponseObject(status=False, message="OIDC is disabled")
|
|
|
|
return ResponseObject(data=AdminOIDC.GetProviders())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/oidc/authenticate')
|
|
def API_OIDC_Authenticate():
|
|
_, oidc = DashboardConfig.GetConfig("OIDC", "admin_enable")
|
|
if not oidc:
|
|
return ResponseObject(False, "OIDC is disabled")
|
|
|
|
requestData = request.get_json()
|
|
status, data = AdminOIDC.VerifyToken(**requestData)
|
|
if not status:
|
|
return ResponseObject(False, "OIDC Authentication Failed. Reason: " + data)
|
|
session['role'] = 'admin'
|
|
authToken = hashlib.sha256(f'${data['sid']}{datetime.now()}{app.secret_key}'.encode()).hexdigest()
|
|
session['username'] = authToken
|
|
session['signInMethod'] = 'OIDC'
|
|
session['signInPayload'] = {
|
|
"Provider": requestData.get('provider'),
|
|
"Payload": data
|
|
}
|
|
resp = ResponseObject()
|
|
resp.set_cookie('authToken', authToken)
|
|
return resp
|
|
|
|
|
|
@app.post(f'{APP_PREFIX}/api/authenticate')
|
|
def API_AuthenticateLogin():
|
|
data = request.get_json()
|
|
if not DashboardConfig.GetConfig("Server", "auth_req")[1]:
|
|
return ResponseObject(True, DashboardConfig.GetConfig("Other", "welcome_session")[1])
|
|
|
|
if DashboardConfig.APIAccessed:
|
|
authToken = hashlib.sha256(f"{request.headers.get('wg-dashboard-apikey')}{datetime.now()}".encode()).hexdigest()
|
|
session['role'] = 'admin'
|
|
session['username'] = authToken
|
|
resp = ResponseObject(True, DashboardConfig.GetConfig("Other", "welcome_session")[1])
|
|
resp.set_cookie("authToken", authToken)
|
|
session.permanent = True
|
|
return resp
|
|
valid = bcrypt.checkpw(data['password'].encode("utf-8"),
|
|
DashboardConfig.GetConfig("Account", "password")[1].encode("utf-8"))
|
|
totpEnabled = DashboardConfig.GetConfig("Account", "enable_totp")[1]
|
|
totpValid = False
|
|
if totpEnabled:
|
|
totp_code = str(data.get("totp", "")).strip()
|
|
totpValid = pyotp.TOTP(
|
|
DashboardConfig.GetConfig("Account", "totp_key")[1]
|
|
).verify(totp_code, valid_window=1)
|
|
|
|
if (valid
|
|
and data['username'] == DashboardConfig.GetConfig("Account", "username")[1]
|
|
and ((totpEnabled and totpValid) or not totpEnabled)
|
|
):
|
|
authToken = hashlib.sha256(f"{data['username']}{datetime.now()}".encode()).hexdigest()
|
|
session['role'] = 'admin'
|
|
session['username'] = authToken
|
|
session['signInMethod'] = 'local'
|
|
resp = ResponseObject(True, DashboardConfig.GetConfig("Other", "welcome_session")[1])
|
|
resp.set_cookie("authToken", authToken)
|
|
session.permanent = True
|
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"Login success: {data['username']}")
|
|
return resp
|
|
DashboardLogger.log(str(request.url), str(request.remote_addr), Message=f"Login failed: {data['username']}")
|
|
if totpEnabled:
|
|
return ResponseObject(False, "Sorry, your username, password or OTP is incorrect.")
|
|
else:
|
|
return ResponseObject(False, "Sorry, your username or password is incorrect.")
|
|
|
|
@app.get(f'{APP_PREFIX}/api/signout')
|
|
def API_SignOut():
|
|
resp = ResponseObject(True, "")
|
|
resp.delete_cookie("authToken")
|
|
if session.get('signInMethod') == "OIDC":
|
|
status, oidc_config = AdminOIDC.GetProviderConfiguration(session.get('signInPayload').get("Provider"))
|
|
signOut = requests.get(
|
|
oidc_config.get("end_session_endpoint"),
|
|
params={
|
|
'id_token_hint': session.get('signInPayload').get("Payload").get('sid')
|
|
}
|
|
)
|
|
session.clear()
|
|
return resp
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getWireguardConfigurations')
|
|
def API_getWireguardConfigurations():
|
|
InitWireguardConfigurationsList()
|
|
return ResponseObject(data=[wc for wc in WireguardConfigurations.values()])
|
|
|
|
@app.get(f'{APP_PREFIX}/api/newConfigurationTemplates')
|
|
def API_NewConfigurationTemplates():
|
|
return ResponseObject(data=NewConfigurationTemplates.GetTemplates())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/newConfigurationTemplates/createTemplate')
|
|
def API_NewConfigurationTemplates_CreateTemplate():
|
|
return ResponseObject(data=NewConfigurationTemplates.CreateTemplate().model_dump())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/newConfigurationTemplates/updateTemplate')
|
|
def API_NewConfigurationTemplates_UpdateTemplate():
|
|
data = request.get_json()
|
|
template = data.get('Template', None)
|
|
if not template:
|
|
return ResponseObject(False, "Please provide template")
|
|
|
|
status, msg = NewConfigurationTemplates.UpdateTemplate(template)
|
|
return ResponseObject(status, msg)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/newConfigurationTemplates/deleteTemplate')
|
|
def API_NewConfigurationTemplates_DeleteTemplate():
|
|
data = request.get_json()
|
|
template = data.get('Template', None)
|
|
if not template:
|
|
return ResponseObject(False, "Please provide template")
|
|
|
|
status, msg = NewConfigurationTemplates.DeleteTemplate(template)
|
|
return ResponseObject(status, msg)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/addWireguardConfiguration')
|
|
def API_addWireguardConfiguration():
|
|
data = request.get_json()
|
|
requiredKeys = [
|
|
"ConfigurationName", "Address", "ListenPort", "PrivateKey", "Protocol"
|
|
]
|
|
for i in requiredKeys:
|
|
if i not in data.keys():
|
|
return ResponseObject(False, "Please provide all required parameters.")
|
|
|
|
if data.get("Protocol") not in ProtocolsEnabled():
|
|
return ResponseObject(False, "Please provide a valid protocol: wg / awg.")
|
|
|
|
# Check duplicate names, ports, address
|
|
for i in WireguardConfigurations.values():
|
|
if i.Name == data['ConfigurationName']:
|
|
return ResponseObject(False,
|
|
f"Already have a configuration with the name \"{data['ConfigurationName']}\"",
|
|
"ConfigurationName")
|
|
|
|
if str(i.ListenPort) == str(data["ListenPort"]):
|
|
return ResponseObject(False,
|
|
f"Already have a configuration with the port \"{data['ListenPort']}\"",
|
|
"ListenPort")
|
|
|
|
if i.Address == data["Address"]:
|
|
return ResponseObject(False,
|
|
f"Already have a configuration with the address \"{data['Address']}\"",
|
|
"Address")
|
|
|
|
if "Backup" in data.keys():
|
|
path = {
|
|
"wg": DashboardConfig.GetConfig("Server", "wg_conf_path")[1],
|
|
"awg": DashboardConfig.GetConfig("Server", "awg_conf_path")[1]
|
|
}
|
|
|
|
if (os.path.exists(os.path.join(path['wg'], 'WGDashboard_Backup', data["Backup"])) and
|
|
os.path.exists(os.path.join(path['wg'], 'WGDashboard_Backup', data["Backup"].replace('.conf', '.sql')))):
|
|
protocol = "wg"
|
|
elif (os.path.exists(os.path.join(path['awg'], 'WGDashboard_Backup', data["Backup"])) and
|
|
os.path.exists(os.path.join(path['awg'], 'WGDashboard_Backup', data["Backup"].replace('.conf', '.sql')))):
|
|
protocol = "awg"
|
|
else:
|
|
return ResponseObject(False, "Backup does not exist")
|
|
|
|
shutil.copy(
|
|
os.path.join(path[protocol], 'WGDashboard_Backup', data["Backup"]),
|
|
os.path.join(path[protocol], f'{data["ConfigurationName"]}.conf')
|
|
)
|
|
WireguardConfigurations[data['ConfigurationName']] = (
|
|
WireguardConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, data=data, name=data['ConfigurationName'])) if protocol == 'wg' else (
|
|
AmneziaConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, data=data, name=data['ConfigurationName']))
|
|
else:
|
|
WireguardConfigurations[data['ConfigurationName']] = (
|
|
WireguardConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, data=data)) if data.get('Protocol') == 'wg' else (
|
|
AmneziaConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, data=data))
|
|
return ResponseObject()
|
|
|
|
@app.get(f'{APP_PREFIX}/api/toggleWireguardConfiguration')
|
|
def API_toggleWireguardConfiguration():
|
|
configurationName = request.args.get('configurationName')
|
|
if configurationName is None or len(
|
|
configurationName) == 0 or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Please provide a valid configuration name", status_code=404)
|
|
toggleStatus, msg = WireguardConfigurations[configurationName].toggleConfiguration()
|
|
return ResponseObject(toggleStatus, msg, WireguardConfigurations[configurationName].Status)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/updateWireguardConfiguration')
|
|
def API_updateWireguardConfiguration():
|
|
data = request.get_json()
|
|
requiredKeys = ["Name"]
|
|
for i in requiredKeys:
|
|
if i not in data.keys():
|
|
return ResponseObject(False, "Please provide these following field: " + ", ".join(requiredKeys))
|
|
name = data.get("Name")
|
|
if name not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
status, msg = WireguardConfigurations[name].updateConfigurationSettings(data)
|
|
|
|
return ResponseObject(status, message=msg, data=WireguardConfigurations[name])
|
|
|
|
@app.post(f'{APP_PREFIX}/api/updateWireguardConfigurationInfo')
|
|
def API_updateWireguardConfigurationInfo():
|
|
data = request.get_json()
|
|
name = data.get('Name')
|
|
key = data.get('Key')
|
|
value = data.get('Value')
|
|
if not all([data, key, name]):
|
|
return ResponseObject(status=False, message="Please provide configuration name, key and value")
|
|
if name not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
status, msg, key = WireguardConfigurations[name].updateConfigurationInfo(key, value)
|
|
|
|
return ResponseObject(status=status, message=msg, data=key)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getWireguardConfigurationRawFile')
|
|
def API_GetWireguardConfigurationRawFile():
|
|
configurationName = request.args.get('configurationName')
|
|
if configurationName is None or len(
|
|
configurationName) == 0 or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Please provide a valid configuration name", status_code=404)
|
|
|
|
return ResponseObject(data={
|
|
"path": WireguardConfigurations[configurationName].configPath,
|
|
"content": WireguardConfigurations[configurationName].getRawConfigurationFile()
|
|
})
|
|
|
|
@app.post(f'{APP_PREFIX}/api/updateWireguardConfigurationRawFile')
|
|
def API_UpdateWireguardConfigurationRawFile():
|
|
data = request.get_json()
|
|
configurationName = data.get('configurationName')
|
|
rawConfiguration = data.get('rawConfiguration')
|
|
if configurationName is None or len(
|
|
configurationName) == 0 or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Please provide a valid configuration name")
|
|
if rawConfiguration is None or len(rawConfiguration) == 0:
|
|
return ResponseObject(False, "Please provide content")
|
|
|
|
status, err = WireguardConfigurations[configurationName].updateRawConfigurationFile(rawConfiguration)
|
|
|
|
return ResponseObject(status=status, message=err)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/deleteWireguardConfiguration')
|
|
def API_deleteWireguardConfiguration():
|
|
data = request.get_json()
|
|
if "ConfigurationName" not in data.keys() or data.get("ConfigurationName") is None or data.get("ConfigurationName") not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Please provide the configuration name you want to delete", status_code=404)
|
|
rp = WireguardConfigurations.pop(data.get("ConfigurationName"))
|
|
|
|
status = rp.deleteConfiguration()
|
|
if not status:
|
|
WireguardConfigurations[data.get("ConfigurationName")] = rp
|
|
return ResponseObject(status)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/renameWireguardConfiguration')
|
|
def API_renameWireguardConfiguration():
|
|
data = request.get_json()
|
|
keys = ["ConfigurationName", "NewConfigurationName"]
|
|
for k in keys:
|
|
if (k not in data.keys() or data.get(k) is None or len(data.get(k)) == 0 or
|
|
(k == "ConfigurationName" and data.get(k) not in WireguardConfigurations.keys())):
|
|
return ResponseObject(False, "Please provide the configuration name you want to rename", status_code=404)
|
|
|
|
if data.get("NewConfigurationName") in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration name already exist", status_code=400)
|
|
|
|
rc = WireguardConfigurations.pop(data.get("ConfigurationName"))
|
|
|
|
status, message = rc.renameConfiguration(data.get("NewConfigurationName"))
|
|
if status:
|
|
WireguardConfigurations[data.get("NewConfigurationName")] = (WireguardConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, data.get("NewConfigurationName")) if rc.Protocol == 'wg' else AmneziaConfiguration(DashboardConfig, AllPeerJobs, AllPeerShareLinks, DashboardWebHooks, data.get("NewConfigurationName")))
|
|
else:
|
|
WireguardConfigurations[data.get("ConfigurationName")] = rc
|
|
return ResponseObject(status, message)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getWireguardConfigurationRealtimeTraffic')
|
|
def API_getWireguardConfigurationRealtimeTraffic():
|
|
configurationName = request.args.get('configurationName')
|
|
if configurationName is None or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
return ResponseObject(data=WireguardConfigurations[configurationName].getRealtimeTrafficUsage())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getWireguardConfigurationBackup')
|
|
def API_getWireguardConfigurationBackup():
|
|
configurationName = request.args.get('configurationName')
|
|
if configurationName is None or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
return ResponseObject(data=WireguardConfigurations[configurationName].getBackups())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getAllWireguardConfigurationBackup')
|
|
def API_getAllWireguardConfigurationBackup():
|
|
data = {
|
|
"ExistingConfigurations": {},
|
|
"NonExistingConfigurations": {}
|
|
}
|
|
existingConfiguration = WireguardConfigurations.keys()
|
|
for i in existingConfiguration:
|
|
b = WireguardConfigurations[i].getBackups(True)
|
|
if len(b) > 0:
|
|
data['ExistingConfigurations'][i] = WireguardConfigurations[i].getBackups(True)
|
|
|
|
for protocol in ProtocolsEnabled():
|
|
directory = os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup')
|
|
if os.path.exists(directory):
|
|
files = [(file, os.path.getctime(os.path.join(directory, file)))
|
|
for file in os.listdir(directory) if os.path.isfile(os.path.join(directory, file))]
|
|
files.sort(key=lambda x: x[1], reverse=True)
|
|
|
|
for f, ct in files:
|
|
if RegexMatch(r"^(.+)_(\d+)\.(conf)$", f):
|
|
s = re.search(r"^(.+)_(\d+)\.(conf)$", f)
|
|
name = s.group(1)
|
|
if name not in existingConfiguration:
|
|
if name not in data['NonExistingConfigurations'].keys():
|
|
data['NonExistingConfigurations'][name] = []
|
|
|
|
date = s.group(2)
|
|
d = {
|
|
"protocol": protocol,
|
|
"filename": f,
|
|
"backupDate": date,
|
|
"content": open(os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup', f), 'r').read()
|
|
}
|
|
if f.replace(".conf", ".sql") in list(os.listdir(directory)):
|
|
d['database'] = True
|
|
d['databaseContent'] = open(os.path.join(DashboardConfig.GetConfig("Server", f"{protocol}_conf_path")[1], 'WGDashboard_Backup', f.replace(".conf", ".sql")), 'r').read()
|
|
data['NonExistingConfigurations'][name].append(d)
|
|
return ResponseObject(data=data)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/createWireguardConfigurationBackup')
|
|
def API_createWireguardConfigurationBackup():
|
|
configurationName = request.args.get('configurationName')
|
|
if configurationName is None or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
return ResponseObject(status=WireguardConfigurations[configurationName].backupConfigurationFile()[0],
|
|
data=WireguardConfigurations[configurationName].getBackups())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/deleteWireguardConfigurationBackup')
|
|
def API_deleteWireguardConfigurationBackup():
|
|
data = request.get_json()
|
|
if ("ConfigurationName" not in data.keys() or
|
|
"BackupFileName" not in data.keys() or
|
|
len(data['ConfigurationName']) == 0 or
|
|
len(data['BackupFileName']) == 0):
|
|
return ResponseObject(False,
|
|
"Please provide configurationName and backupFileName in body", status_code=400)
|
|
configurationName = data['ConfigurationName']
|
|
backupFileName = data['BackupFileName']
|
|
if configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
status = WireguardConfigurations[configurationName].deleteBackup(backupFileName)
|
|
return ResponseObject(status=status, message=(None if status else 'Backup file does not exist'),
|
|
status_code = (200 if status else 404))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/downloadWireguardConfigurationBackup')
|
|
def API_downloadWireguardConfigurationBackup():
|
|
configurationName = os.path.basename(request.args.get('configurationName'))
|
|
backupFileName = os.path.basename(request.args.get('backupFileName'))
|
|
|
|
if configurationName is None or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
status, zip = WireguardConfigurations[configurationName].downloadBackup(backupFileName)
|
|
|
|
if not status:
|
|
current_app.logger.error(f"Failed to download a requested backup.\nConfiguration Name: {configurationName}\nBackup File Name: {backupFileName}")
|
|
return ResponseObject(False, "Internal server error", status_code=500)
|
|
|
|
return send_file(os.path.join('download', zip), as_attachment=True)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/restoreWireguardConfigurationBackup')
|
|
def API_restoreWireguardConfigurationBackup():
|
|
data = request.get_json()
|
|
if ("ConfigurationName" not in data.keys() or
|
|
"BackupFileName" not in data.keys() or
|
|
len(data['ConfigurationName']) == 0 or
|
|
len(data['BackupFileName']) == 0):
|
|
return ResponseObject(False,
|
|
"Please provide ConfigurationName and BackupFileName in body", status_code=400)
|
|
configurationName = data['ConfigurationName']
|
|
backupFileName = data['BackupFileName']
|
|
if configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
status = WireguardConfigurations[configurationName].restoreBackup(backupFileName)
|
|
return ResponseObject(status=status, message=(None if status else 'Restore backup failed'))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getDashboardConfiguration')
|
|
def API_getDashboardConfiguration():
|
|
return ResponseObject(data=DashboardConfig.toJson())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/updateDashboardConfigurationItem')
|
|
def API_updateDashboardConfigurationItem():
|
|
data = request.get_json()
|
|
if "section" not in data.keys() or "key" not in data.keys() or "value" not in data.keys():
|
|
return ResponseObject(False, "Invalid request.")
|
|
valid, msg = DashboardConfig.SetConfig(
|
|
data["section"], data["key"], data['value'])
|
|
if not valid:
|
|
return ResponseObject(False, msg)
|
|
if data['section'] == "Server":
|
|
if data['key'] == 'wg_conf_path':
|
|
WireguardConfigurations.clear()
|
|
WireguardConfigurations.clear()
|
|
InitWireguardConfigurationsList()
|
|
return ResponseObject(True, data=DashboardConfig.GetConfig(data["section"], data["key"])[1])
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getDashboardAPIKeys')
|
|
def API_getDashboardAPIKeys():
|
|
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
|
return ResponseObject(data=DashboardConfig.DashboardAPIKeys)
|
|
return ResponseObject(False, "WGDashboard API Keys function is disabled")
|
|
|
|
@app.post(f'{APP_PREFIX}/api/newDashboardAPIKey')
|
|
def API_newDashboardAPIKey():
|
|
data = request.get_json()
|
|
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
|
try:
|
|
if data['NeverExpire']:
|
|
expiredAt = None
|
|
else:
|
|
expiredAt = datetime.strptime(data['ExpiredAt'], '%Y-%m-%d %H:%M:%S')
|
|
DashboardConfig.createAPIKeys(expiredAt)
|
|
return ResponseObject(True, data=DashboardConfig.DashboardAPIKeys)
|
|
except Exception as e:
|
|
return ResponseObject(False, str(e))
|
|
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
|
|
|
@app.post(f'{APP_PREFIX}/api/deleteDashboardAPIKey')
|
|
def API_deleteDashboardAPIKey():
|
|
data = request.get_json()
|
|
if DashboardConfig.GetConfig('Server', 'dashboard_api_key'):
|
|
if len(data['Key']) > 0 and len(list(filter(lambda x : x.Key == data['Key'], DashboardConfig.DashboardAPIKeys))) > 0:
|
|
DashboardConfig.deleteAPIKey(data['Key'])
|
|
return ResponseObject(True, data=DashboardConfig.DashboardAPIKeys)
|
|
else:
|
|
return ResponseObject(False, "API Key does not exist", status_code=404)
|
|
return ResponseObject(False, "Dashboard API Keys function is disbaled")
|
|
|
|
@app.post(f'{APP_PREFIX}/api/updatePeerSettings/<configName>')
|
|
def API_updatePeerSettings(configName):
|
|
data = request.get_json()
|
|
id = data['id']
|
|
if len(id) > 0 and configName in WireguardConfigurations.keys():
|
|
name = data['name']
|
|
private_key = data['private_key']
|
|
dns_addresses = data['DNS']
|
|
allowed_ip = data['allowed_ip']
|
|
endpoint_allowed_ip = data['endpoint_allowed_ip']
|
|
preshared_key = data['preshared_key']
|
|
mtu = data['mtu']
|
|
keepalive = data['keepalive']
|
|
notes = data.get('notes', '')
|
|
wireguardConfig = WireguardConfigurations[configName]
|
|
foundPeer, peer = wireguardConfig.searchPeer(id)
|
|
if foundPeer:
|
|
if wireguardConfig.Protocol == 'wg':
|
|
status, msg = peer.updatePeer(name,
|
|
private_key,
|
|
preshared_key,
|
|
dns_addresses,
|
|
allowed_ip,
|
|
endpoint_allowed_ip,
|
|
mtu,
|
|
keepalive,
|
|
notes)
|
|
else:
|
|
status, msg = peer.updatePeer(name,
|
|
private_key,
|
|
preshared_key,
|
|
dns_addresses,
|
|
allowed_ip,
|
|
endpoint_allowed_ip,
|
|
mtu,
|
|
keepalive,
|
|
notes)
|
|
wireguardConfig.getPeers()
|
|
DashboardWebHooks.RunWebHook('peer_updated', {
|
|
"configuration": wireguardConfig.Name,
|
|
"peers": [id]
|
|
})
|
|
return ResponseObject(status, msg)
|
|
|
|
return ResponseObject(False, "Peer does not exist")
|
|
|
|
@app.post(f'{APP_PREFIX}/api/resetPeerData/<configName>')
|
|
def API_resetPeerData(configName):
|
|
data = request.get_json()
|
|
id = data['id']
|
|
type = data['type']
|
|
if len(id) == 0 or configName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration/Peer does not exist")
|
|
wgc = WireguardConfigurations.get(configName)
|
|
foundPeer, peer = wgc.searchPeer(id)
|
|
if not foundPeer:
|
|
return ResponseObject(False, "Configuration/Peer does not exist")
|
|
|
|
resetStatus = peer.resetDataUsage(type)
|
|
if resetStatus:
|
|
wgc.restrictPeers([id])
|
|
wgc.allowAccessPeers([id])
|
|
|
|
return ResponseObject(status=resetStatus)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/deletePeers/<configName>')
|
|
def API_deletePeers(configName: str) -> ResponseObject:
|
|
data = request.get_json()
|
|
peers = data['peers']
|
|
if configName in WireguardConfigurations.keys():
|
|
if len(peers) == 0:
|
|
return ResponseObject(False, "Please specify one or more peers", status_code=400)
|
|
configuration = WireguardConfigurations.get(configName)
|
|
status, msg = configuration.deletePeers(peers, AllPeerJobs, AllPeerShareLinks)
|
|
|
|
# Delete Assignment
|
|
|
|
for p in peers:
|
|
assignments = DashboardClients.DashboardClientsPeerAssignment.GetAssignedClients(configName, p)
|
|
for c in assignments:
|
|
DashboardClients.DashboardClientsPeerAssignment.UnassignClients(c.AssignmentID)
|
|
|
|
return ResponseObject(status, msg)
|
|
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/restrictPeers/<configName>')
|
|
def API_restrictPeers(configName: str) -> ResponseObject:
|
|
data = request.get_json()
|
|
peers = data['peers']
|
|
if configName in WireguardConfigurations.keys():
|
|
if len(peers) == 0:
|
|
return ResponseObject(False, "Please specify one or more peers")
|
|
configuration = WireguardConfigurations.get(configName)
|
|
status, msg = configuration.restrictPeers(peers)
|
|
return ResponseObject(status, msg)
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/sharePeer/create')
|
|
def API_sharePeer_create():
|
|
data: dict[str, str] = request.get_json()
|
|
Configuration = data.get('Configuration')
|
|
Peer = data.get('Peer')
|
|
ExpireDate = data.get('ExpireDate')
|
|
if Configuration is None or Peer is None:
|
|
return ResponseObject(False, "Please specify configuration and peers")
|
|
activeLink = AllPeerShareLinks.getLink(Configuration, Peer)
|
|
if len(activeLink) > 0:
|
|
return ResponseObject(True,
|
|
"This peer is already sharing. Please view data for shared link.",
|
|
data=activeLink[0]
|
|
)
|
|
status, message = AllPeerShareLinks.addLink(Configuration, Peer, datetime.strptime(ExpireDate, "%Y-%m-%d %H:%M:%S"))
|
|
if not status:
|
|
return ResponseObject(status, message)
|
|
return ResponseObject(data=AllPeerShareLinks.getLinkByID(message))
|
|
|
|
@app.post(f'{APP_PREFIX}/api/sharePeer/update')
|
|
def API_sharePeer_update():
|
|
data: dict[str, str] = request.get_json()
|
|
ShareID: str = data.get("ShareID")
|
|
ExpireDate: str = data.get("ExpireDate")
|
|
|
|
if not all([ShareID, ExpireDate]):
|
|
return ResponseObject(False, "Please specify ShareID")
|
|
|
|
if len(AllPeerShareLinks.getLinkByID(ShareID)) == 0:
|
|
return ResponseObject(False, "ShareID does not exist")
|
|
|
|
status, message = AllPeerShareLinks.updateLinkExpireDate(ShareID, datetime.strptime(ExpireDate, "%Y-%m-%d %H:%M:%S"))
|
|
if not status:
|
|
return ResponseObject(status, message)
|
|
return ResponseObject(data=AllPeerShareLinks.getLinkByID(ShareID))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/sharePeer/get')
|
|
def API_sharePeer_get():
|
|
data = request.args
|
|
ShareID = data.get("ShareID")
|
|
if ShareID is None or len(ShareID) == 0:
|
|
return ResponseObject(False, "Please provide ShareID")
|
|
link = AllPeerShareLinks.getLinkByID(ShareID)
|
|
if len(link) == 0:
|
|
return ResponseObject(False, "This link is either expired to invalid")
|
|
l = link[0]
|
|
if l.Configuration not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "The peer you're looking for does not exist")
|
|
c = WireguardConfigurations.get(l.Configuration)
|
|
fp, p = c.searchPeer(l.Peer)
|
|
if not fp:
|
|
return ResponseObject(False, "The peer you're looking for does not exist")
|
|
|
|
return ResponseObject(data=p.downloadPeer())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/allowAccessPeers/<configName>')
|
|
def API_allowAccessPeers(configName: str) -> ResponseObject:
|
|
data = request.get_json()
|
|
peers = data['peers']
|
|
if configName in WireguardConfigurations.keys():
|
|
if len(peers) == 0:
|
|
return ResponseObject(False, "Please specify one or more peers")
|
|
configuration = WireguardConfigurations.get(configName)
|
|
status, msg = configuration.allowAccessPeers(peers)
|
|
return ResponseObject(status, msg)
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
|
|
@app.post(f'{APP_PREFIX}/api/addPeers/<configName>')
|
|
def API_addPeers(configName):
|
|
if configName in WireguardConfigurations.keys():
|
|
data: dict = request.get_json()
|
|
try:
|
|
|
|
|
|
bulkAdd: bool = data.get("bulkAdd", False)
|
|
bulkAddAmount: int = data.get('bulkAddAmount', 0)
|
|
preshared_key_bulkAdd: bool = data.get('preshared_key_bulkAdd', False)
|
|
|
|
public_key: str = data.get('public_key', "")
|
|
allowed_ips: list[str] = data.get('allowed_ips', [])
|
|
allowed_ips_validation: bool = data.get('allowed_ips_validation', True)
|
|
|
|
endpoint_allowed_ip: str = data.get('endpoint_allowed_ip', DashboardConfig.GetConfig("Peers", "peer_endpoint_allowed_ip")[1])
|
|
dns_addresses: str = data.get('DNS', DashboardConfig.GetConfig("Peers", "peer_global_DNS")[1])
|
|
|
|
|
|
mtu: int = data.get('mtu', None)
|
|
keep_alive: int = data.get('keepalive', None)
|
|
notes: str = data.get('notes', '')
|
|
preshared_key: str = data.get('preshared_key', "")
|
|
|
|
if type(mtu) is not int or mtu < 0 or mtu > 1460:
|
|
default: str = DashboardConfig.GetConfig("Peers", "peer_mtu")[1]
|
|
if default.isnumeric():
|
|
try:
|
|
mtu = int(default)
|
|
except Exception as e:
|
|
mtu = 0
|
|
else:
|
|
mtu = 0
|
|
if type(keep_alive) is not int or keep_alive < 0:
|
|
default = DashboardConfig.GetConfig("Peers", "peer_keep_alive")[1]
|
|
if default.isnumeric():
|
|
try:
|
|
keep_alive = int(default)
|
|
except Exception as e:
|
|
keep_alive = 0
|
|
else:
|
|
keep_alive = 0
|
|
|
|
config = WireguardConfigurations.get(configName)
|
|
if not config.getStatus():
|
|
config.toggleConfiguration()
|
|
ipStatus, availableIps = config.getAvailableIP(-1)
|
|
ipCountStatus, numberOfAvailableIPs = config.getNumberOfAvailableIP()
|
|
defaultIPSubnet = list(availableIps.keys())[0]
|
|
if bulkAdd:
|
|
if type(preshared_key_bulkAdd) is not bool:
|
|
preshared_key_bulkAdd = False
|
|
if type(bulkAddAmount) is not int or bulkAddAmount < 1:
|
|
return ResponseObject(False, "Please specify amount of peers you want to add")
|
|
if not ipStatus:
|
|
return ResponseObject(False, "No more available IP can assign")
|
|
if len(availableIps.keys()) == 0:
|
|
return ResponseObject(False, "This configuration does not have any IP address available")
|
|
if bulkAddAmount > sum(list(numberOfAvailableIPs.values())):
|
|
return ResponseObject(False,
|
|
f"The maximum number of peers can add is {sum(list(numberOfAvailableIPs.values()))}")
|
|
keyPairs = []
|
|
addedCount = 0
|
|
for subnet in availableIps.keys():
|
|
for ip in availableIps[subnet]:
|
|
newPrivateKey = GenerateWireguardPrivateKey()[1]
|
|
addedCount += 1
|
|
keyPairs.append({
|
|
"private_key": newPrivateKey,
|
|
"id": GenerateWireguardPublicKey(newPrivateKey)[1],
|
|
"preshared_key": (GenerateWireguardPrivateKey()[1] if preshared_key_bulkAdd else ""),
|
|
"allowed_ip": ip,
|
|
"name": f"BulkPeer_{(addedCount + 1)}_{datetime.now().strftime('%Y%m%d_%H%M%S')}",
|
|
"DNS": dns_addresses,
|
|
"endpoint_allowed_ip": endpoint_allowed_ip,
|
|
"mtu": mtu,
|
|
"keepalive": keep_alive,
|
|
"notes": ""
|
|
})
|
|
if addedCount == bulkAddAmount:
|
|
break
|
|
if addedCount == bulkAddAmount:
|
|
break
|
|
if len(keyPairs) == 0 or (bulkAdd and len(keyPairs) != bulkAddAmount):
|
|
return ResponseObject(False, "Generating key pairs by bulk failed")
|
|
status, addedPeers, message = config.addPeers(keyPairs)
|
|
return ResponseObject(status=status, message=message, data=addedPeers)
|
|
|
|
else:
|
|
if config.searchPeer(public_key)[0] is True:
|
|
return ResponseObject(False, f"This peer already exist")
|
|
name = data.get("name", "")
|
|
private_key = data.get("private_key", "")
|
|
|
|
if len(public_key) == 0:
|
|
if len(private_key) == 0:
|
|
private_key = GenerateWireguardPrivateKey()[1]
|
|
public_key = GenerateWireguardPublicKey(private_key)[1]
|
|
else:
|
|
public_key = GenerateWireguardPublicKey(private_key)[1]
|
|
else:
|
|
if len(private_key) > 0:
|
|
genPub = GenerateWireguardPublicKey(private_key)[1]
|
|
# Check if provided pubkey match provided private key
|
|
if public_key != genPub:
|
|
return ResponseObject(False, "Provided Public Key does not match provided Private Key")
|
|
if len(allowed_ips) == 0:
|
|
if ipStatus:
|
|
for subnet in availableIps.keys():
|
|
for ip in availableIps[subnet]:
|
|
allowed_ips = [ip]
|
|
break
|
|
break
|
|
else:
|
|
return ResponseObject(False, "No more available IP can assign")
|
|
|
|
if allowed_ips_validation:
|
|
for i in allowed_ips:
|
|
found = False
|
|
for subnet in availableIps.keys():
|
|
try:
|
|
network = ipaddress.ip_network(subnet, False)
|
|
ap = ipaddress.ip_network(i)
|
|
except ValueError as e:
|
|
return ResponseObject(False, str(e))
|
|
if network.version == ap.version and ap.subnet_of(network):
|
|
found = True
|
|
|
|
if not found:
|
|
return ResponseObject(False, f"This IP is not available: {i}")
|
|
|
|
status, addedPeers, message = config.addPeers([
|
|
{
|
|
"name": name,
|
|
"id": public_key,
|
|
"private_key": private_key,
|
|
"allowed_ip": ','.join(allowed_ips),
|
|
"preshared_key": preshared_key,
|
|
"endpoint_allowed_ip": endpoint_allowed_ip,
|
|
"DNS": dns_addresses,
|
|
"mtu": mtu,
|
|
"keepalive": keep_alive,
|
|
"notes": notes
|
|
}]
|
|
)
|
|
return ResponseObject(status=status, message=message, data=addedPeers)
|
|
except Exception as e:
|
|
app.logger.error("Add peers failed", e)
|
|
return ResponseObject(False, f"Add peers failed.")
|
|
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
|
|
@app.get(f"{APP_PREFIX}/api/downloadPeer/<configName>")
|
|
def API_downloadPeer(configName):
|
|
data = request.args
|
|
if configName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
configuration = WireguardConfigurations[configName]
|
|
peerFound, peer = configuration.searchPeer(data['id'])
|
|
if len(data['id']) == 0 or not peerFound:
|
|
return ResponseObject(False, "Peer does not exist")
|
|
return ResponseObject(data=peer.downloadPeer())
|
|
|
|
@app.get(f"{APP_PREFIX}/api/downloadAllPeers/<configName>")
|
|
def API_downloadAllPeers(configName):
|
|
if configName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
configuration = WireguardConfigurations[configName]
|
|
peerData = []
|
|
untitledPeer = 0
|
|
for i in configuration.Peers:
|
|
file = i.downloadPeer()
|
|
if file["fileName"] == "UntitledPeer":
|
|
file["fileName"] = str(untitledPeer) + "_" + file["fileName"]
|
|
untitledPeer += 1
|
|
peerData.append(file)
|
|
return ResponseObject(data=peerData)
|
|
|
|
@app.get(f"{APP_PREFIX}/api/getAvailableIPs/<configName>")
|
|
def API_getAvailableIPs(configName):
|
|
if configName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
status, ips = WireguardConfigurations.get(configName).getAvailableIP()
|
|
return ResponseObject(status=status, data=ips)
|
|
|
|
@app.get(f"{APP_PREFIX}/api/getNumberOfAvailableIPs/<configName>")
|
|
def API_getNumberOfAvailableIPs(configName):
|
|
if configName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
status, ips = WireguardConfigurations.get(configName).getNumberOfAvailableIP()
|
|
return ResponseObject(status=status, data=ips)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getWireguardConfigurationInfo')
|
|
def API_getConfigurationInfo():
|
|
configurationName = request.args.get("configurationName")
|
|
if not configurationName or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Please provide configuration name")
|
|
return ResponseObject(data={
|
|
"configurationInfo": WireguardConfigurations[configurationName],
|
|
"configurationPeers": WireguardConfigurations[configurationName].getPeersList(),
|
|
"configurationRestrictedPeers": WireguardConfigurations[configurationName].getRestrictedPeersList()
|
|
})
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getPeerHistoricalEndpoints')
|
|
def API_GetPeerHistoricalEndpoints():
|
|
configurationName = request.args.get("configurationName")
|
|
id = request.args.get('id')
|
|
if not configurationName or not id:
|
|
return ResponseObject(False, "Please provide configurationName and id")
|
|
fp, p = WireguardConfigurations.get(configurationName).searchPeer(id)
|
|
if fp:
|
|
result = p.getEndpoints()
|
|
geo = {}
|
|
try:
|
|
r = requests.post(f"http://ip-api.com/batch?fields=city,country,lat,lon,query",
|
|
data=json.dumps([x['endpoint'] for x in result]))
|
|
d = r.json()
|
|
|
|
|
|
except Exception as e:
|
|
return ResponseObject(data=result, message="Failed to request IP address geolocation. " + str(e))
|
|
|
|
return ResponseObject(data={
|
|
"endpoints": p.getEndpoints(),
|
|
"geolocation": d
|
|
})
|
|
return ResponseObject(False, "Peer does not exist")
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getPeerSessions')
|
|
def API_GetPeerSessions():
|
|
configurationName = request.args.get("configurationName")
|
|
id = request.args.get('id')
|
|
try:
|
|
startDate = request.args.get('startDate', None)
|
|
endDate = request.args.get('endDate', None)
|
|
|
|
if startDate is None:
|
|
endDate = None
|
|
else:
|
|
startDate = datetime.strptime(startDate, "%Y-%m-%d")
|
|
if endDate:
|
|
endDate = datetime.strptime(endDate, "%Y-%m-%d")
|
|
if startDate > endDate:
|
|
return ResponseObject(False, "startDate must be smaller than endDate")
|
|
except Exception as e:
|
|
return ResponseObject(False, "Dates are invalid")
|
|
if not configurationName or not id:
|
|
return ResponseObject(False, "Please provide configurationName and id")
|
|
fp, p = WireguardConfigurations.get(configurationName).searchPeer(id)
|
|
if fp:
|
|
return ResponseObject(data=p.getSessions(startDate, endDate))
|
|
return ResponseObject(False, "Peer does not exist")
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getPeerTraffics')
|
|
def API_GetPeerTraffics():
|
|
configurationName = request.args.get("configurationName")
|
|
id = request.args.get('id')
|
|
try:
|
|
interval = request.args.get('interval', 30)
|
|
startDate = request.args.get('startDate', None)
|
|
endDate = request.args.get('endDate', None)
|
|
if type(interval) is str:
|
|
if not interval.isdigit():
|
|
return ResponseObject(False, "Interval must be integers in minutes")
|
|
interval = int(interval)
|
|
if startDate is None:
|
|
endDate = None
|
|
else:
|
|
startDate = datetime.strptime(startDate, "%Y-%m-%d")
|
|
if endDate:
|
|
endDate = datetime.strptime(endDate, "%Y-%m-%d")
|
|
if startDate > endDate:
|
|
return ResponseObject(False, "startDate must be smaller than endDate")
|
|
except Exception as e:
|
|
return ResponseObject(False, "Dates are invalid" + e)
|
|
if not configurationName or not id:
|
|
return ResponseObject(False, "Please provide configurationName and id")
|
|
fp, p = WireguardConfigurations.get(configurationName).searchPeer(id)
|
|
if fp:
|
|
return ResponseObject(data=p.getTraffics(interval, startDate, endDate))
|
|
return ResponseObject(False, "Peer does not exist")
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getPeerTrackingTableCounts')
|
|
def API_GetPeerTrackingTableCounts():
|
|
configurationName = request.args.get("configurationName")
|
|
if configurationName and configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
|
|
if configurationName:
|
|
c = WireguardConfigurations.get(configurationName)
|
|
return ResponseObject(data={
|
|
"TrafficTrackingTableSize": c.getTransferTableSize(),
|
|
"HistoricalTrackingTableSize": c.getHistoricalEndpointTableSize()
|
|
})
|
|
|
|
d = {}
|
|
for i in WireguardConfigurations.keys():
|
|
c = WireguardConfigurations.get(i)
|
|
d[i] = {
|
|
"TrafficTrackingTableSize": c.getTransferTableSize(),
|
|
"HistoricalTrackingTableSize": c.getHistoricalEndpointTableSize()
|
|
}
|
|
return ResponseObject(data=d)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/downloadPeerTrackingTable')
|
|
def API_DownloadPeerTackingTable():
|
|
configurationName = request.args.get("configurationName")
|
|
table = request.args.get('table')
|
|
if configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
if table not in ['TrafficTrackingTable', 'HistoricalTrackingTable']:
|
|
return ResponseObject(False, "Table does not exist")
|
|
c = WireguardConfigurations.get(configurationName)
|
|
return ResponseObject(
|
|
data=c.downloadTransferTable() if table == 'TrafficTrackingTable'
|
|
else c.downloadHistoricalEndpointTable())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/deletePeerTrackingTable')
|
|
def API_DeletePeerTrackingTable():
|
|
data = request.get_json()
|
|
configurationName = data.get('configurationName')
|
|
table = data.get('table')
|
|
if not configurationName or configurationName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
if not table or table not in ['TrafficTrackingTable', 'HistoricalTrackingTable']:
|
|
return ResponseObject(False, "Table does not exist")
|
|
c = WireguardConfigurations.get(configurationName)
|
|
return ResponseObject(
|
|
status=c.deleteTransferTable() if table == 'TrafficTrackingTable'
|
|
else c.deleteHistoryEndpointTable())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getDashboardTheme')
|
|
def API_getDashboardTheme():
|
|
return ResponseObject(data=DashboardConfig.GetConfig("Server", "dashboard_theme")[1])
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getDashboardVersion')
|
|
def API_getDashboardVersion():
|
|
return ResponseObject(data=DashboardConfig.GetConfig("Server", "version")[1])
|
|
|
|
@app.post(f'{APP_PREFIX}/api/PeerScheduleJob')
|
|
@require_fields('Configuration', 'Peer', 'Field', 'Operator', 'Value', 'Action')
|
|
def API_savePeerScheduleJob():
|
|
data = request.json
|
|
|
|
configuration = WireguardConfigurations.get(data['Configuration'])
|
|
if configuration is None:
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
peerKey = unquote(data['Peer'])
|
|
found, _ = configuration.searchPeer(peerKey)
|
|
if not found:
|
|
return ResponseObject(False, "Peer does not exist", status_code=404)
|
|
|
|
jobID = data.get('JobID', str(uuid4()))
|
|
if len(AllPeerJobs.searchJobById(jobID)) > 0:
|
|
return ResponseObject(False, "Job already exists", status_code=409)
|
|
|
|
success, result = AllPeerJobs.saveJob(PeerJob(
|
|
jobID, data['Configuration'], peerKey, data['Field'], data['Operator'], data['Value'],
|
|
datetime.now(), data.get('ExpireDate'), data['Action']))
|
|
if success:
|
|
return ResponseObject(success, data=result)
|
|
return ResponseObject(success, message=result)
|
|
|
|
@app.put(f'{APP_PREFIX}/api/PeerScheduleJob')
|
|
@require_fields('JobID', 'Configuration', 'Peer', 'Field', 'Operator', 'Value', 'Action')
|
|
def API_updatePeerScheduleJob():
|
|
data = request.json
|
|
|
|
configuration = WireguardConfigurations.get(data['Configuration'])
|
|
if configuration is None:
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
peerKey = unquote(data['Peer'])
|
|
found, _ = configuration.searchPeer(peerKey)
|
|
if not found:
|
|
return ResponseObject(False, "Peer does not exist", status_code=404)
|
|
|
|
existing = AllPeerJobs.searchJobById(data['JobID'])
|
|
if len(existing) == 0:
|
|
return ResponseObject(False, "Job does not exist", status_code=404)
|
|
|
|
success, result = AllPeerJobs.saveJob(PeerJob(
|
|
data['JobID'], data['Configuration'], peerKey, data['Field'], data['Operator'], data['Value'],
|
|
datetime.now(), data.get('ExpireDate'), data['Action']))
|
|
if success:
|
|
return ResponseObject(success, data=result)
|
|
return ResponseObject(success, message=result)
|
|
|
|
@app.delete(f'{APP_PREFIX}/api/PeerScheduleJob')
|
|
@require_fields('JobID', 'Configuration', 'Peer')
|
|
def API_deletePeerScheduleJob():
|
|
data = request.json
|
|
|
|
configuration = WireguardConfigurations.get(data['Configuration'])
|
|
if configuration is None:
|
|
return ResponseObject(False, "Configuration does not exist", status_code=404)
|
|
|
|
peerKey = unquote(data['Peer'])
|
|
success, result = AllPeerJobs.deleteJob(PeerJob(
|
|
data['JobID'], data['Configuration'], peerKey, data.get('Field', ''),
|
|
data.get('Operator', ''), data.get('Value', ''),
|
|
datetime.now(), data.get('ExpireDate'), data.get('Action', '')))
|
|
if success:
|
|
return ResponseObject(success, message="Job deleted successfully")
|
|
return ResponseObject(success, message=result)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/PeerScheduleJobLogs/<configName>')
|
|
def API_getPeerScheduleJobLogs(configName):
|
|
if configName not in WireguardConfigurations.keys():
|
|
return ResponseObject(False, "Configuration does not exist")
|
|
data = request.args.get("requestAll")
|
|
requestAll = False
|
|
if data is not None and data == "true":
|
|
requestAll = True
|
|
return ResponseObject(data=AllPeerJobs.getPeerJobLogs(configName))
|
|
|
|
'''
|
|
Tools
|
|
'''
|
|
|
|
@app.get(f'{APP_PREFIX}/api/ping/getAllPeersIpAddress')
|
|
def API_ping_getAllPeersIpAddress():
|
|
ips = {}
|
|
for c in WireguardConfigurations.values():
|
|
cips = {}
|
|
for p in c.Peers:
|
|
allowed_ip = p.allowed_ip.replace(" ", "").split(",")
|
|
parsed = []
|
|
for x in allowed_ip:
|
|
try:
|
|
ip = ipaddress.ip_network(x, strict=False)
|
|
if ip.num_addresses == 1:
|
|
parsed.append(str(ip.network_address))
|
|
except ValueError as e:
|
|
app.logger.error(f"Failed to parse IP address of {p.id} - {c.Name}")
|
|
|
|
endpoint = p.endpoint.replace(" ", "").replace("(none)", "")
|
|
if len(p.name) > 0:
|
|
cips[f"{p.name} - {p.id}"] = {
|
|
"allowed_ips": parsed,
|
|
"endpoint": endpoint
|
|
}
|
|
else:
|
|
cips[f"{p.id}"] = {
|
|
"allowed_ips": parsed,
|
|
"endpoint": endpoint
|
|
}
|
|
ips[c.Name] = cips
|
|
return ResponseObject(data=ips)
|
|
|
|
import requests
|
|
|
|
@app.get(f'{APP_PREFIX}/api/ping/execute')
|
|
def API_ping_execute():
|
|
if "ipAddress" in request.args.keys() and "count" in request.args.keys():
|
|
ip = request.args['ipAddress']
|
|
count = request.args['count']
|
|
try:
|
|
if ip is not None and len(ip) > 0 and count is not None and count.isnumeric():
|
|
result = ping(ip, count=int(count), source=None)
|
|
data = {
|
|
"address": result.address,
|
|
"is_alive": result.is_alive,
|
|
"min_rtt": result.min_rtt,
|
|
"avg_rtt": result.avg_rtt,
|
|
"max_rtt": result.max_rtt,
|
|
"package_sent": result.packets_sent,
|
|
"package_received": result.packets_received,
|
|
"package_loss": result.packet_loss,
|
|
"geo": None
|
|
}
|
|
try:
|
|
r = requests.get(f"http://ip-api.com/json/{result.address}?field=city")
|
|
data['geo'] = r.json()
|
|
except Exception as e:
|
|
pass
|
|
return ResponseObject(data=data)
|
|
return ResponseObject(False, "Please specify an IP Address (v4/v6)")
|
|
except Exception as exp:
|
|
return ResponseObject(False, exp)
|
|
return ResponseObject(False, "Please provide ipAddress and count")
|
|
|
|
|
|
@app.get(f'{APP_PREFIX}/api/traceroute/execute')
|
|
def API_traceroute_execute():
|
|
if "ipAddress" in request.args.keys() and len(request.args.get("ipAddress")) > 0:
|
|
ipAddress = request.args.get('ipAddress')
|
|
try:
|
|
tracerouteResult = traceroute(ipAddress, timeout=1, max_hops=64)
|
|
result = []
|
|
for hop in tracerouteResult:
|
|
if len(result) > 1:
|
|
skipped = False
|
|
for i in range(result[-1]["hop"] + 1, hop.distance):
|
|
result.append(
|
|
{
|
|
"hop": i,
|
|
"ip": "*",
|
|
"avg_rtt": "*",
|
|
"min_rtt": "*",
|
|
"max_rtt": "*"
|
|
}
|
|
)
|
|
skip = True
|
|
if skipped: continue
|
|
result.append(
|
|
{
|
|
"hop": hop.distance,
|
|
"ip": hop.address,
|
|
"avg_rtt": hop.avg_rtt,
|
|
"min_rtt": hop.min_rtt,
|
|
"max_rtt": hop.max_rtt
|
|
})
|
|
try:
|
|
r = requests.post(f"http://ip-api.com/batch?fields=city,country,lat,lon,query",
|
|
data=json.dumps([x['ip'] for x in result]))
|
|
d = r.json()
|
|
for i in range(len(result)):
|
|
result[i]['geo'] = d[i]
|
|
|
|
return ResponseObject(data=result)
|
|
|
|
except Exception as e:
|
|
app.logger.error(f"Failed to gather the geolocation data: {e}")
|
|
return ResponseObject(data=result, message="Failed to request IP address geolocation")
|
|
|
|
except Exception as e:
|
|
app.logger.error(f"Failed to execute the traceroute: {e}")
|
|
return ResponseObject(data=[], message="Failed to traceroute the given parameter")
|
|
else:
|
|
return ResponseObject(False, "Please provide ipAddress")
|
|
|
|
@app.get(f'{APP_PREFIX}/api/getDashboardUpdate')
|
|
def API_getDashboardUpdate():
|
|
import urllib.request as req
|
|
try:
|
|
r = req.urlopen("https://api.github.com/repos/WGDashboard/WGDashboard/releases/latest", timeout=5).read()
|
|
data = dict(json.loads(r))
|
|
tagName = data.get('tag_name')
|
|
htmlUrl = data.get('html_url')
|
|
if tagName is not None and htmlUrl is not None:
|
|
if version.parse(tagName) > version.parse(DashboardConfig.DashboardVersion):
|
|
return ResponseObject(message=f"{tagName} is now available for update!", data=htmlUrl)
|
|
else:
|
|
return ResponseObject(message="You're on the latest version")
|
|
return ResponseObject(False)
|
|
except Exception as e:
|
|
return ResponseObject(False, f"Request to GitHub API failed.")
|
|
|
|
'''
|
|
Sign Up
|
|
'''
|
|
|
|
@app.get(f'{APP_PREFIX}/api/isTotpEnabled')
|
|
def API_isTotpEnabled():
|
|
return (
|
|
ResponseObject(data=DashboardConfig.GetConfig("Account", "enable_totp")[1] and DashboardConfig.GetConfig("Account", "totp_verified")[1]))
|
|
|
|
|
|
@app.get(f'{APP_PREFIX}/api/Welcome_GetTotpLink')
|
|
def API_Welcome_GetTotpLink():
|
|
if not DashboardConfig.GetConfig("Account", "totp_verified")[1]:
|
|
DashboardConfig.SetConfig("Account", "totp_key", pyotp.random_base32(), True)
|
|
return ResponseObject(
|
|
data=pyotp.totp.TOTP(DashboardConfig.GetConfig("Account", "totp_key")[1]).provisioning_uri(
|
|
issuer_name="WGDashboard"))
|
|
return ResponseObject(False)
|
|
|
|
|
|
@app.post(f'{APP_PREFIX}/api/Welcome_VerifyTotpLink')
|
|
def API_Welcome_VerifyTotpLink():
|
|
data = request.get_json()
|
|
totp_code = str(data.get("totp", "")).strip()
|
|
totpValid = pyotp.TOTP(
|
|
DashboardConfig.GetConfig("Account", "totp_key")[1]
|
|
).verify(totp_code, valid_window=1)
|
|
|
|
if totpValid:
|
|
DashboardConfig.SetConfig("Account", "totp_verified", "true")
|
|
DashboardConfig.SetConfig("Account", "enable_totp", "true")
|
|
return ResponseObject(totpValid)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/Welcome_Finish')
|
|
def API_Welcome_Finish():
|
|
data = request.get_json()
|
|
if DashboardConfig.GetConfig("Other", "welcome_session")[1]:
|
|
if data["username"] == "":
|
|
return ResponseObject(False, "Username cannot be blank.")
|
|
|
|
if data["newPassword"] == "" or len(data["newPassword"]) < 8:
|
|
return ResponseObject(False, "Password must be at least 8 characters")
|
|
|
|
updateUsername, updateUsernameErr = DashboardConfig.SetConfig("Account", "username", data["username"])
|
|
updatePassword, updatePasswordErr = DashboardConfig.SetConfig("Account", "password",
|
|
{
|
|
"newPassword": data["newPassword"],
|
|
"repeatNewPassword": data["repeatNewPassword"],
|
|
"currentPassword": "admin"
|
|
})
|
|
if not updateUsername or not updatePassword:
|
|
return ResponseObject(False, f"{updateUsernameErr},{updatePasswordErr}".strip(","))
|
|
|
|
DashboardConfig.SetConfig("Other", "welcome_session", False)
|
|
return ResponseObject()
|
|
|
|
class Locale:
|
|
def __init__(self):
|
|
self.localePath = './static/locales/'
|
|
self.activeLanguages = {}
|
|
with open(os.path.join(f"{self.localePath}supported_locales.json"), "r") as f:
|
|
self.activeLanguages = sorted(json.loads(''.join(f.readlines())), key=lambda x : x['lang_name'])
|
|
|
|
def getLanguage(self) -> dict | None:
|
|
currentLanguage = DashboardConfig.GetConfig("Server", "dashboard_language")[1]
|
|
if currentLanguage == "en":
|
|
return None
|
|
if os.path.exists(os.path.join(f"{self.localePath}{currentLanguage}.json")):
|
|
with open(os.path.join(f"{self.localePath}{currentLanguage}.json"), "r") as f:
|
|
return dict(json.loads(''.join(f.readlines())))
|
|
else:
|
|
return None
|
|
|
|
def updateLanguage(self, lang_id):
|
|
if not os.path.exists(os.path.join(f"{self.localePath}{lang_id}.json")):
|
|
DashboardConfig.SetConfig("Server", "dashboard_language", "en-US")
|
|
else:
|
|
DashboardConfig.SetConfig("Server", "dashboard_language", lang_id)
|
|
|
|
Locale = Locale()
|
|
|
|
@app.get(f'{APP_PREFIX}/api/locale')
|
|
def API_Locale_CurrentLang():
|
|
return ResponseObject(data=Locale.getLanguage())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/locale/available')
|
|
def API_Locale_Available():
|
|
return ResponseObject(data=Locale.activeLanguages)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/locale/update')
|
|
def API_Locale_Update():
|
|
data = request.get_json()
|
|
if 'lang_id' not in data.keys():
|
|
return ResponseObject(False, "Please specify a lang_id")
|
|
Locale.updateLanguage(data['lang_id'])
|
|
return ResponseObject(data=Locale.getLanguage())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/email/ready')
|
|
def API_Email_Ready():
|
|
return ResponseObject(EmailSender.is_ready())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/email/send')
|
|
def API_Email_Send():
|
|
data = request.get_json()
|
|
if "Receiver" not in data.keys() or "Subject" not in data.keys():
|
|
return ResponseObject(False, "Please at least specify receiver and subject")
|
|
body = data.get('Body', '')
|
|
subject = data.get('Subject','')
|
|
download = None
|
|
if ("ConfigurationName" in data.keys()
|
|
and "Peer" in data.keys()):
|
|
if data.get('ConfigurationName') in WireguardConfigurations.keys():
|
|
configuration = WireguardConfigurations.get(data.get('ConfigurationName'))
|
|
attachmentName = ""
|
|
if configuration is not None:
|
|
fp, p = configuration.searchPeer(data.get('Peer'))
|
|
if fp:
|
|
template = Template(body)
|
|
download = p.downloadPeer()
|
|
body = template.render(peer=p.toJson(), configurationFile=download)
|
|
subject = Template(data.get('Subject', '')).render(peer=p.toJson(), configurationFile=download)
|
|
if data.get('IncludeAttachment', False):
|
|
u = str(uuid4())
|
|
peerName = p.toJson().get('name', '').strip()
|
|
attachmentName = f'{peerName if peerName else u}.conf'
|
|
with open(os.path.join('./attachments', attachmentName,), 'w+') as f:
|
|
f.write(download['file'])
|
|
|
|
|
|
s, m = EmailSender.send(data.get('Receiver'), subject, body,
|
|
data.get('IncludeAttachment', False), (attachmentName if download else ''))
|
|
return ResponseObject(s, m)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/email/preview')
|
|
def API_Email_PreviewBody():
|
|
data = request.get_json()
|
|
subject = data.get('Subject', '')
|
|
body = data.get('Body', '')
|
|
|
|
if ("ConfigurationName" not in data.keys()
|
|
or "Peer" not in data.keys() or data.get('ConfigurationName') not in WireguardConfigurations.keys()):
|
|
return ResponseObject(False, "Please specify configuration and peer")
|
|
|
|
configuration = WireguardConfigurations.get(data.get('ConfigurationName'))
|
|
fp, p = configuration.searchPeer(data.get('Peer'))
|
|
if not fp:
|
|
return ResponseObject(False, "Peer does not exist")
|
|
|
|
try:
|
|
template = Template(body)
|
|
download = p.downloadPeer()
|
|
return ResponseObject(data={
|
|
"Body": Template(body).render(peer=p.toJson(), configurationFile=download),
|
|
"Subject": Template(subject).render(peer=p.toJson(), configurationFile=download)
|
|
})
|
|
except Exception as e:
|
|
return ResponseObject(False, message=str(e))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/systemStatus')
|
|
def API_SystemStatus():
|
|
return ResponseObject(data=SystemStatus)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/protocolsEnabled')
|
|
def API_ProtocolsEnabled():
|
|
return ResponseObject(data=ProtocolsEnabled())
|
|
|
|
'''
|
|
OIDC Controller
|
|
'''
|
|
@app.get(f'{APP_PREFIX}/api/oidc/toggle')
|
|
def API_OIDC_Toggle():
|
|
data = request.args
|
|
if not data.get('mode'):
|
|
return ResponseObject(False, "Please provide mode")
|
|
mode = data.get('mode')
|
|
if mode == 'Client':
|
|
DashboardConfig.SetConfig("OIDC", "client_enable",
|
|
not DashboardConfig.GetConfig("OIDC", "client_enable")[1])
|
|
elif mode == 'Admin':
|
|
DashboardConfig.SetConfig("OIDC", "admin_enable",
|
|
not DashboardConfig.GetConfig("OIDC", "admin_enable")[1])
|
|
else:
|
|
return ResponseObject(False, "Mode does not exist")
|
|
return ResponseObject()
|
|
|
|
@app.get(f'{APP_PREFIX}/api/oidc/status')
|
|
def API_OIDC_Status():
|
|
data = request.args
|
|
if not data.get('mode'):
|
|
return ResponseObject(False, "Please provide mode")
|
|
mode = data.get('mode')
|
|
if mode == 'Client':
|
|
return ResponseObject(data=DashboardConfig.GetConfig("OIDC", "client_enable")[1])
|
|
elif mode == 'Admin':
|
|
return ResponseObject(data=DashboardConfig.GetConfig("OIDC", "admin_enable")[1])
|
|
return ResponseObject(False, "Mode does not exist")
|
|
|
|
'''
|
|
Client Controller
|
|
'''
|
|
|
|
@app.get(f'{APP_PREFIX}/api/clients/toggleStatus')
|
|
def API_Clients_ToggleStatus():
|
|
DashboardConfig.SetConfig("Clients", "enable",
|
|
not DashboardConfig.GetConfig("Clients", "enable")[1])
|
|
return ResponseObject(data=DashboardConfig.GetConfig("Clients", "enable")[1])
|
|
|
|
|
|
@app.get(f'{APP_PREFIX}/api/clients/allClients')
|
|
def API_Clients_AllClients():
|
|
return ResponseObject(data=DashboardClients.GetAllClients())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/clients/allClientsRaw')
|
|
def API_Clients_AllClientsRaw():
|
|
return ResponseObject(data=DashboardClients.GetAllClientsRaw())
|
|
|
|
@app.post(f'{APP_PREFIX}/api/clients/assignClient')
|
|
def API_Clients_AssignClient():
|
|
data = request.get_json()
|
|
configurationName = data.get('ConfigurationName')
|
|
id = data.get('Peer')
|
|
client = data.get('ClientID')
|
|
if not all([configurationName, id, client]):
|
|
return ResponseObject(False, "Please provide all required fields")
|
|
if not DashboardClients.GetClient(client):
|
|
return ResponseObject(False, "Client does not exist")
|
|
|
|
status, data = DashboardClients.AssignClient(configurationName, id, client)
|
|
if not status:
|
|
return ResponseObject(status, message="Client already assiged to this peer")
|
|
|
|
return ResponseObject(data=data)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/clients/unassignClient')
|
|
def API_Clients_UnassignClient():
|
|
data = request.get_json()
|
|
assignmentID = data.get('AssignmentID')
|
|
if not assignmentID:
|
|
return ResponseObject(False, "Please provide AssignmentID")
|
|
return ResponseObject(status=DashboardClients.UnassignClient(assignmentID))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/clients/assignedClients')
|
|
def API_Clients_AssignedClients():
|
|
data = request.args
|
|
configurationName = data.get('ConfigurationName')
|
|
peerID = data.get('Peer')
|
|
if not all([configurationName, id]):
|
|
return ResponseObject(False, "Please provide all required fields")
|
|
return ResponseObject(
|
|
data=DashboardClients.GetAssignedPeerClients(configurationName, peerID))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/clients/allConfigurationsPeers')
|
|
def API_Clients_AllConfigurationsPeers():
|
|
c = {}
|
|
for (key, val) in WireguardConfigurations.items():
|
|
c[key] = list(map(lambda x : {
|
|
"id": x.id,
|
|
"name": x.name
|
|
}, val.Peers))
|
|
|
|
return ResponseObject(
|
|
data=c
|
|
)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/clients/assignedPeers')
|
|
def API_Clients_AssignedPeers():
|
|
data = request.args
|
|
clientId = data.get("ClientID")
|
|
if not clientId:
|
|
return ResponseObject(False, "Please provide ClientID")
|
|
if not DashboardClients.GetClient(clientId):
|
|
return ResponseObject(False, "Client does not exist")
|
|
d = DashboardClients.GetClientAssignedPeersGrouped(clientId)
|
|
if d is None:
|
|
return ResponseObject(False, "Client does not exist")
|
|
return ResponseObject(data=d)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/clients/generatePasswordResetLink')
|
|
def API_Clients_GeneratePasswordResetLink():
|
|
data = request.get_json()
|
|
clientId = data.get("ClientID")
|
|
if not clientId:
|
|
return ResponseObject(False, "Please provide ClientID")
|
|
if not DashboardClients.GetClient(clientId):
|
|
return ResponseObject(False, "Client does not exist")
|
|
|
|
token = DashboardClients.GenerateClientPasswordResetToken(clientId)
|
|
if token:
|
|
return ResponseObject(data=token)
|
|
return ResponseObject(False, "Failed to generate link")
|
|
|
|
@app.post(f'{APP_PREFIX}/api/clients/updateProfileName')
|
|
def API_Clients_UpdateProfile():
|
|
data = request.get_json()
|
|
clientId = data.get("ClientID")
|
|
if not clientId:
|
|
return ResponseObject(False, "Please provide ClientID")
|
|
if not DashboardClients.GetClient(clientId):
|
|
return ResponseObject(False, "Client does not exist")
|
|
|
|
value = data.get('Name')
|
|
return ResponseObject(status=DashboardClients.UpdateClientProfile(clientId, value))
|
|
|
|
@app.post(f'{APP_PREFIX}/api/clients/deleteClient')
|
|
def API_Clients_DeleteClient():
|
|
data = request.get_json()
|
|
clientId = data.get("ClientID")
|
|
if not clientId:
|
|
return ResponseObject(False, "Please provide ClientID")
|
|
if not DashboardClients.GetClient(clientId):
|
|
return ResponseObject(False, "Client does not exist")
|
|
return ResponseObject(status=DashboardClients.DeleteClient(clientId))
|
|
|
|
@app.get(f'{APP_PREFIX}/api/webHooks/getWebHooks')
|
|
def API_WebHooks_GetWebHooks():
|
|
return ResponseObject(data=DashboardWebHooks.GetWebHooks())
|
|
|
|
@app.get(f'{APP_PREFIX}/api/webHooks/createWebHook')
|
|
def API_WebHooks_createWebHook():
|
|
return ResponseObject(data=DashboardWebHooks.CreateWebHook().model_dump(
|
|
exclude={'CreationDate'}
|
|
))
|
|
|
|
@app.post(f'{APP_PREFIX}/api/webHooks/updateWebHook')
|
|
def API_WebHooks_UpdateWebHook():
|
|
data = request.get_json()
|
|
status, msg = DashboardWebHooks.UpdateWebHook(data)
|
|
return ResponseObject(status, msg)
|
|
|
|
@app.post(f'{APP_PREFIX}/api/webHooks/deleteWebHook')
|
|
def API_WebHooks_DeleteWebHook():
|
|
data = request.get_json()
|
|
status, msg = DashboardWebHooks.DeleteWebHook(data)
|
|
return ResponseObject(status, msg)
|
|
|
|
@app.get(f'{APP_PREFIX}/api/webHooks/getWebHookSessions')
|
|
def API_WebHooks_GetWebHookSessions():
|
|
webhookID = request.args.get('WebHookID')
|
|
if not webhookID:
|
|
return ResponseObject(False, "Please provide WebHookID")
|
|
|
|
webHook = DashboardWebHooks.SearchWebHookByID(webhookID)
|
|
if not webHook:
|
|
return ResponseObject(False, "Webhook does not exist")
|
|
|
|
return ResponseObject(data=DashboardWebHooks.GetWebHookSessions(webHook))
|
|
|
|
|
|
'''
|
|
Index Page
|
|
'''
|
|
|
|
@app.get(f'{APP_PREFIX}/')
|
|
def index():
|
|
return render_template('index.html', APP_PREFIX=APP_PREFIX)
|
|
|
|
if __name__ == "__main__":
|
|
startThreads()
|
|
DashboardPlugins.startThreads()
|
|
app.run(host=app_ip, debug=False, port=app_port)
|