Browse Source

Fix: Update ip outside of cidr (#1733)

* update packages

* check if ip is included on update

* update package manager
pull/1734/head
Bernd Storath 3 weeks ago
committed by GitHub
parent
commit
fc480df910
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      package.json
  2. 6
      src/package.json
  3. 481
      src/pnpm-lock.yaml
  4. 24
      src/server/database/repositories/client/service.ts

2
package.json

@ -7,5 +7,5 @@
"docs:preview": "docker run --rm -it -p 8080:8080 -v ./docs:/docs squidfunk/mkdocs-material serve -a 0.0.0.0:8080",
"scripts:version": "bash scripts/version.sh"
},
"packageManager": "pnpm@10.5.2"
"packageManager": "pnpm@10.6.2"
}

6
src/package.json

@ -21,7 +21,7 @@
"@eschricht/nuxt-color-mode": "^1.1.5",
"@libsql/client": "^0.14.0",
"@nuxtjs/i18n": "^9.3.1",
"@nuxtjs/tailwindcss": "^6.13.1",
"@nuxtjs/tailwindcss": "^6.13.2",
"@pinia/nuxt": "^0.10.1",
"@tailwindcss/forms": "^0.5.10",
"apexcharts": "^4.5.0",
@ -54,11 +54,11 @@
"@types/semver": "^7.5.8",
"drizzle-kit": "^0.30.5",
"eslint": "^9.22.0",
"eslint-config-prettier": "^10.0.2",
"eslint-config-prettier": "^10.1.1",
"prettier": "^3.5.3",
"prettier-plugin-tailwindcss": "^0.6.11",
"typescript": "^5.8.2",
"vue-tsc": "^2.2.8"
},
"packageManager": "pnpm@10.5.2"
"packageManager": "pnpm@10.6.2"
}

481
src/pnpm-lock.yaml

File diff suppressed because it is too large

24
src/server/database/repositories/client/service.ts

@ -1,5 +1,5 @@
import { eq, sql } from 'drizzle-orm';
import { parseCidr } from 'cidr-tools';
import { containsCidr, parseCidr } from 'cidr-tools';
import { client } from './schema';
import type {
ClientCreateFromExistingType,
@ -132,7 +132,27 @@ export class ClientService {
}
update(id: ID, data: UpdateClientType) {
return this.#db.update(client).set(data).where(eq(client.id, id)).execute();
return this.#db.transaction(async (tx) => {
const clientInterface = await tx.query.wgInterface
.findFirst({
where: eq(wgInterface.name, 'wg0'),
})
.execute();
if (!clientInterface) {
throw new Error('WireGuard interface not found');
}
if (!containsCidr(clientInterface.ipv4Cidr, data.ipv4Address)) {
throw new Error('IPv4 address is not within the CIDR range');
}
if (!containsCidr(clientInterface.ipv6Cidr, data.ipv6Address)) {
throw new Error('IPv6 address is not within the CIDR range');
}
await tx.update(client).set(data).where(eq(client.id, id)).execute();
});
}
async createFromExisting({

Loading…
Cancel
Save