mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-10 06:28:07 +02:00
Compare commits
111 Commits
1.14.1
...
d52bd65d21
| Author | SHA1 | Date | |
|---|---|---|---|
| d52bd65d21 | |||
| eb0cdda0f9 | |||
| 552adf3200 | |||
| eba25fcc4d | |||
| 673cd0fcd1 | |||
| b941b5571f | |||
| ca026b41c0 | |||
| 29a683a815 | |||
| 69dbd20ea5 | |||
| 427ee026ac | |||
| 0a537c6830 | |||
| 89682a2ee4 | |||
| 78b00a18cc | |||
| 192702daf9 | |||
| 2ba49e84bb | |||
| 4c8d2266ec | |||
| bb98bf03aa | |||
| 2810632f4a | |||
| 57681dcd3d | |||
| 168ce549f7 | |||
| 9ec94441f3 | |||
| 53e7b99605 | |||
| 20088ef82b | |||
| 1e0b1a3607 | |||
| 24e8455c73 | |||
| e42a732e93 | |||
| d333cb5199 | |||
| a6db4f20ad | |||
| 9ed9472c01 | |||
| f7fcde8312 | |||
| 6660c850f3 | |||
| 8a08bdf9f0 | |||
| 87807e22e0 | |||
| 0eb39abdb4 | |||
| a499ebc158 | |||
| 9467e6c032 | |||
| 9d849a0ced | |||
| 982c692c40 | |||
| 0c3ce7836c | |||
| 7ef86c5707 | |||
| f62b88b930 | |||
| 03a326c841 | |||
| 4df4cafd70 | |||
| 4b9539cc6d | |||
| 87135c90bd | |||
| 853d416b2f | |||
| bfd14b87bd | |||
| 88aba4e169 | |||
| 99e2fcb2e8 | |||
| 1f138ab68c | |||
| 99ded7454e | |||
| f82cacac6d | |||
| a548f61ea6 | |||
| bfae715076 | |||
| 358e25b7c2 | |||
| 2c3fa54933 | |||
| 00cdd5833e | |||
| 52b1164e58 | |||
| 657bc9cdf0 | |||
| ec6bcd41b0 | |||
| 1721cce040 | |||
| e41a5ad6b0 | |||
| ee1eca9e66 | |||
| d049369172 | |||
| 6280a68d51 | |||
| 32054dc4f6 | |||
| 831c631048 | |||
| e23711bcce | |||
| 440bff57d0 | |||
| 7345cc81c1 | |||
| 164ab26069 | |||
| 4b6ace80d3 | |||
| 653127a0f7 | |||
| bf3a1e20fc | |||
| d7a44e7589 | |||
| 6c0d583557 | |||
| 13f0fb25da | |||
| 818aca9ec8 | |||
| 1c7fb476b0 | |||
| 93843ed733 | |||
| 0973313703 | |||
| bfbfbe8b11 | |||
| 8c62d9fe78 | |||
| d5558f55ed | |||
| a96ad6bd07 | |||
| 00d9482a99 | |||
| 0f90e2a30f | |||
| 3eed636404 | |||
| a67f88381f | |||
| 808fd856d1 | |||
| 5b9b532458 | |||
| 9fba9bd6b7 | |||
| c5ece144d0 | |||
| b64e2e11db | |||
| 0ccd5714f9 | |||
| e2dfc3eb20 | |||
| 40eeb9b7cb | |||
| 8fa62a0908 | |||
| 446eba8bc9 | |||
| 18579c0647 | |||
| 2bb94e24eb | |||
| 0d37e08638 | |||
| a21f49cb02 | |||
| ef697c4864 | |||
| 2652dea09a | |||
| efa9312fca | |||
| 074ee70025 | |||
| 77117e48e3 | |||
| da112d3417 | |||
| 75b9703793 | |||
| 322f3bfb1d |
+126
-23
@@ -329,20 +329,89 @@ jobs:
|
|||||||
skopeo login ghcr.io -u "${{ github.actor }}" -p "${{ secrets.GITHUB_TOKEN }}"
|
skopeo login ghcr.io -u "${{ github.actor }}" -p "${{ secrets.GITHUB_TOKEN }}"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Copy tag from Docker Hub to GHCR
|
- name: Copy tags from Docker Hub to GHCR
|
||||||
# Mirror the already-built image (all architectures) to GHCR so we can sign it
|
# Mirror the already-built images (all architectures) to GHCR so we can sign them
|
||||||
# Wait a bit for both architectures to be available in Docker Hub manifest
|
# Wait a bit for both architectures to be available in Docker Hub manifest
|
||||||
env:
|
env:
|
||||||
REGISTRY_AUTH_FILE: ${{ runner.temp }}/containers/auth.json
|
REGISTRY_AUTH_FILE: ${{ runner.temp }}/containers/auth.json
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
TAG=${{ env.TAG }}
|
TAG=${{ env.TAG }}
|
||||||
echo "Waiting for multi-arch manifest to be ready..."
|
MAJOR_TAG=$(echo $TAG | cut -d. -f1)
|
||||||
|
MINOR_TAG=$(echo $TAG | cut -d. -f1,2)
|
||||||
|
|
||||||
|
echo "Waiting for multi-arch manifests to be ready..."
|
||||||
sleep 30
|
sleep 30
|
||||||
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:${TAG} -> ${{ env.GHCR_IMAGE }}:${TAG}"
|
|
||||||
skopeo copy --all --retry-times 3 \
|
# Determine if this is an RC release
|
||||||
docker://$DOCKERHUB_IMAGE:$TAG \
|
IS_RC="false"
|
||||||
docker://$GHCR_IMAGE:$TAG
|
if echo "$TAG" | grep -qE "rc[0-9]+$"; then
|
||||||
|
IS_RC="true"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$IS_RC" = "true" ]; then
|
||||||
|
echo "RC release detected - copying version-specific tags only"
|
||||||
|
|
||||||
|
# SQLite OSS
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:${TAG} -> ${{ env.GHCR_IMAGE }}:${TAG}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:$TAG \
|
||||||
|
docker://$GHCR_IMAGE:$TAG
|
||||||
|
|
||||||
|
# PostgreSQL OSS
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:postgresql-${TAG} -> ${{ env.GHCR_IMAGE }}:postgresql-${TAG}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:postgresql-$TAG \
|
||||||
|
docker://$GHCR_IMAGE:postgresql-$TAG
|
||||||
|
|
||||||
|
# SQLite Enterprise
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:ee-${TAG} -> ${{ env.GHCR_IMAGE }}:ee-${TAG}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:ee-$TAG \
|
||||||
|
docker://$GHCR_IMAGE:ee-$TAG
|
||||||
|
|
||||||
|
# PostgreSQL Enterprise
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:ee-postgresql-${TAG} -> ${{ env.GHCR_IMAGE }}:ee-postgresql-${TAG}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:ee-postgresql-$TAG \
|
||||||
|
docker://$GHCR_IMAGE:ee-postgresql-$TAG
|
||||||
|
else
|
||||||
|
echo "Regular release detected - copying all tags (latest, major, minor, full version)"
|
||||||
|
|
||||||
|
# SQLite OSS - all tags
|
||||||
|
for TAG_SUFFIX in "latest" "$MAJOR_TAG" "$MINOR_TAG" "$TAG"; do
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:${TAG_SUFFIX} -> ${{ env.GHCR_IMAGE }}:${TAG_SUFFIX}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:$TAG_SUFFIX \
|
||||||
|
docker://$GHCR_IMAGE:$TAG_SUFFIX
|
||||||
|
done
|
||||||
|
|
||||||
|
# PostgreSQL OSS - all tags
|
||||||
|
for TAG_SUFFIX in "latest" "$MAJOR_TAG" "$MINOR_TAG" "$TAG"; do
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:postgresql-${TAG_SUFFIX} -> ${{ env.GHCR_IMAGE }}:postgresql-${TAG_SUFFIX}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:postgresql-$TAG_SUFFIX \
|
||||||
|
docker://$GHCR_IMAGE:postgresql-$TAG_SUFFIX
|
||||||
|
done
|
||||||
|
|
||||||
|
# SQLite Enterprise - all tags
|
||||||
|
for TAG_SUFFIX in "latest" "$MAJOR_TAG" "$MINOR_TAG" "$TAG"; do
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:ee-${TAG_SUFFIX} -> ${{ env.GHCR_IMAGE }}:ee-${TAG_SUFFIX}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:ee-$TAG_SUFFIX \
|
||||||
|
docker://$GHCR_IMAGE:ee-$TAG_SUFFIX
|
||||||
|
done
|
||||||
|
|
||||||
|
# PostgreSQL Enterprise - all tags
|
||||||
|
for TAG_SUFFIX in "latest" "$MAJOR_TAG" "$MINOR_TAG" "$TAG"; do
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:ee-postgresql-${TAG_SUFFIX} -> ${{ env.GHCR_IMAGE }}:ee-postgresql-${TAG_SUFFIX}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:ee-postgresql-$TAG_SUFFIX \
|
||||||
|
docker://$GHCR_IMAGE:ee-postgresql-$TAG_SUFFIX
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "All images copied successfully to GHCR!"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
- name: Login to GitHub Container Registry (for cosign)
|
- name: Login to GitHub Container Registry (for cosign)
|
||||||
@@ -371,28 +440,62 @@ jobs:
|
|||||||
issuer="https://token.actions.githubusercontent.com"
|
issuer="https://token.actions.githubusercontent.com"
|
||||||
id_regex="^https://github.com/${{ github.repository }}/.+" # accept this repo (all workflows/refs)
|
id_regex="^https://github.com/${{ github.repository }}/.+" # accept this repo (all workflows/refs)
|
||||||
|
|
||||||
for IMAGE in "${GHCR_IMAGE}" "${DOCKERHUB_IMAGE}"; do
|
# Determine if this is an RC release
|
||||||
echo "Processing ${IMAGE}:${TAG}"
|
IS_RC="false"
|
||||||
|
if echo "$TAG" | grep -qE "rc[0-9]+$"; then
|
||||||
|
IS_RC="true"
|
||||||
|
fi
|
||||||
|
|
||||||
DIGEST="$(skopeo inspect --retry-times 3 docker://${IMAGE}:${TAG} | jq -r '.Digest')"
|
# Define image variants to sign
|
||||||
REF="${IMAGE}@${DIGEST}"
|
if [ "$IS_RC" = "true" ]; then
|
||||||
echo "Resolved digest: ${REF}"
|
echo "RC release - signing version-specific tags only"
|
||||||
|
IMAGE_TAGS=(
|
||||||
|
"${TAG}"
|
||||||
|
"postgresql-${TAG}"
|
||||||
|
"ee-${TAG}"
|
||||||
|
"ee-postgresql-${TAG}"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
echo "Regular release - signing all tags"
|
||||||
|
MAJOR_TAG=$(echo $TAG | cut -d. -f1)
|
||||||
|
MINOR_TAG=$(echo $TAG | cut -d. -f1,2)
|
||||||
|
IMAGE_TAGS=(
|
||||||
|
"latest" "$MAJOR_TAG" "$MINOR_TAG" "$TAG"
|
||||||
|
"postgresql-latest" "postgresql-$MAJOR_TAG" "postgresql-$MINOR_TAG" "postgresql-$TAG"
|
||||||
|
"ee-latest" "ee-$MAJOR_TAG" "ee-$MINOR_TAG" "ee-$TAG"
|
||||||
|
"ee-postgresql-latest" "ee-postgresql-$MAJOR_TAG" "ee-postgresql-$MINOR_TAG" "ee-postgresql-$TAG"
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
echo "==> cosign sign (keyless) --recursive ${REF}"
|
# Sign each image variant for both registries
|
||||||
cosign sign --recursive "${REF}"
|
for BASE_IMAGE in "${GHCR_IMAGE}" "${DOCKERHUB_IMAGE}"; do
|
||||||
|
for IMAGE_TAG in "${IMAGE_TAGS[@]}"; do
|
||||||
|
echo "Processing ${BASE_IMAGE}:${IMAGE_TAG}"
|
||||||
|
|
||||||
echo "==> cosign sign (key) --recursive ${REF}"
|
DIGEST="$(skopeo inspect --retry-times 3 docker://${BASE_IMAGE}:${IMAGE_TAG} | jq -r '.Digest')"
|
||||||
cosign sign --key env://COSIGN_PRIVATE_KEY --recursive "${REF}"
|
REF="${BASE_IMAGE}@${DIGEST}"
|
||||||
|
echo "Resolved digest: ${REF}"
|
||||||
|
|
||||||
echo "==> cosign verify (public key) ${REF}"
|
echo "==> cosign sign (keyless) --recursive ${REF}"
|
||||||
cosign verify --key env://COSIGN_PUBLIC_KEY "${REF}" -o text
|
cosign sign --recursive "${REF}"
|
||||||
|
|
||||||
echo "==> cosign verify (keyless policy) ${REF}"
|
echo "==> cosign sign (key) --recursive ${REF}"
|
||||||
cosign verify \
|
cosign sign --key env://COSIGN_PRIVATE_KEY --recursive "${REF}"
|
||||||
--certificate-oidc-issuer "${issuer}" \
|
|
||||||
--certificate-identity-regexp "${id_regex}" \
|
echo "==> cosign verify (public key) ${REF}"
|
||||||
"${REF}" -o text
|
cosign verify --key env://COSIGN_PUBLIC_KEY "${REF}" -o text
|
||||||
|
|
||||||
|
echo "==> cosign verify (keyless policy) ${REF}"
|
||||||
|
cosign verify \
|
||||||
|
--certificate-oidc-issuer "${issuer}" \
|
||||||
|
--certificate-identity-regexp "${id_regex}" \
|
||||||
|
"${REF}" -o text
|
||||||
|
|
||||||
|
echo "✓ Successfully signed and verified ${BASE_IMAGE}:${IMAGE_TAG}"
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo "All images signed and verified successfully!"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
post-run:
|
post-run:
|
||||||
|
|||||||
@@ -0,0 +1,426 @@
|
|||||||
|
name: CI/CD Pipeline
|
||||||
|
|
||||||
|
# CI/CD workflow for building, publishing, mirroring, signing container images and building release binaries.
|
||||||
|
# Actions are pinned to specific SHAs to reduce supply-chain risk. This workflow triggers on tag push events.
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write # for GHCR push
|
||||||
|
id-token: write # for Cosign Keyless (OIDC) Signing
|
||||||
|
|
||||||
|
# Required secrets:
|
||||||
|
# - DOCKER_HUB_USERNAME / DOCKER_HUB_ACCESS_TOKEN: push to Docker Hub
|
||||||
|
# - GITHUB_TOKEN: used for GHCR login and OIDC keyless signing
|
||||||
|
# - COSIGN_PRIVATE_KEY / COSIGN_PASSWORD / COSIGN_PUBLIC_KEY: for key-based signing
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+"
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+-rc.[0-9]+"
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-run:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions: write-all
|
||||||
|
steps:
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v2
|
||||||
|
with:
|
||||||
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
|
||||||
|
role-duration-seconds: 3600
|
||||||
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
|
|
||||||
|
- name: Verify AWS identity
|
||||||
|
run: aws sts get-caller-identity
|
||||||
|
|
||||||
|
- name: Start EC2 instances
|
||||||
|
run: |
|
||||||
|
aws ec2 start-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_ARM_RUNNER }}
|
||||||
|
aws ec2 start-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_AMD_RUNNER }}
|
||||||
|
echo "EC2 instances started"
|
||||||
|
|
||||||
|
|
||||||
|
release-arm:
|
||||||
|
name: Build and Release (ARM64)
|
||||||
|
runs-on: [self-hosted, linux, arm64, us-east-1]
|
||||||
|
needs: [pre-run]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
needs.pre-run.result == 'success'
|
||||||
|
}}
|
||||||
|
# Job-level timeout to avoid runaway or stuck runs
|
||||||
|
timeout-minutes: 120
|
||||||
|
env:
|
||||||
|
# Target images
|
||||||
|
DOCKERHUB_IMAGE: docker.io/fosrl/${{ github.event.repository.name }}
|
||||||
|
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
|
- name: Monitor storage space
|
||||||
|
run: |
|
||||||
|
THRESHOLD=75
|
||||||
|
USED_SPACE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
|
||||||
|
echo "Used space: $USED_SPACE%"
|
||||||
|
if [ "$USED_SPACE" -ge "$THRESHOLD" ]; then
|
||||||
|
echo "Used space is below the threshold of 75% free. Running Docker system prune."
|
||||||
|
echo y | docker system prune -a
|
||||||
|
else
|
||||||
|
echo "Storage space is above the threshold. No action needed."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
|
with:
|
||||||
|
registry: docker.io
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract tag name
|
||||||
|
id: get-tag
|
||||||
|
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Update version in package.json
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
sed -i "s/export const APP_VERSION = \".*\";/export const APP_VERSION = \"$TAG\";/" server/lib/consts.ts
|
||||||
|
cat server/lib/consts.ts
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Check if release candidate
|
||||||
|
id: check-rc
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
if [[ "$TAG" == *"-rc."* ]]; then
|
||||||
|
echo "IS_RC=true" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "IS_RC=false" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Build and push Docker images (Docker Hub - ARM64)
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
if [ "$IS_RC" = "true" ]; then
|
||||||
|
make build-rc-arm tag=$TAG
|
||||||
|
else
|
||||||
|
make build-release-arm tag=$TAG
|
||||||
|
fi
|
||||||
|
echo "Built & pushed ARM64 images to: ${{ env.DOCKERHUB_IMAGE }}:${TAG}"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
release-amd:
|
||||||
|
name: Build and Release (AMD64)
|
||||||
|
runs-on: [self-hosted, linux, x64, us-east-1]
|
||||||
|
needs: [pre-run]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
needs.pre-run.result == 'success'
|
||||||
|
}}
|
||||||
|
# Job-level timeout to avoid runaway or stuck runs
|
||||||
|
timeout-minutes: 120
|
||||||
|
env:
|
||||||
|
# Target images
|
||||||
|
DOCKERHUB_IMAGE: docker.io/fosrl/${{ github.event.repository.name }}
|
||||||
|
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
|
- name: Monitor storage space
|
||||||
|
run: |
|
||||||
|
THRESHOLD=75
|
||||||
|
USED_SPACE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
|
||||||
|
echo "Used space: $USED_SPACE%"
|
||||||
|
if [ "$USED_SPACE" -ge "$THRESHOLD" ]; then
|
||||||
|
echo "Used space is below the threshold of 75% free. Running Docker system prune."
|
||||||
|
echo y | docker system prune -a
|
||||||
|
else
|
||||||
|
echo "Storage space is above the threshold. No action needed."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
|
with:
|
||||||
|
registry: docker.io
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract tag name
|
||||||
|
id: get-tag
|
||||||
|
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Update version in package.json
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
sed -i "s/export const APP_VERSION = \".*\";/export const APP_VERSION = \"$TAG\";/" server/lib/consts.ts
|
||||||
|
cat server/lib/consts.ts
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Check if release candidate
|
||||||
|
id: check-rc
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
if [[ "$TAG" == *"-rc."* ]]; then
|
||||||
|
echo "IS_RC=true" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "IS_RC=false" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Build and push Docker images (Docker Hub - AMD64)
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
if [ "$IS_RC" = "true" ]; then
|
||||||
|
make build-rc-amd tag=$TAG
|
||||||
|
else
|
||||||
|
make build-release-amd tag=$TAG
|
||||||
|
fi
|
||||||
|
echo "Built & pushed AMD64 images to: ${{ env.DOCKERHUB_IMAGE }}:${TAG}"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
create-manifest:
|
||||||
|
name: Create Multi-Arch Manifests
|
||||||
|
runs-on: [self-hosted, linux, x64, us-east-1]
|
||||||
|
needs: [release-arm, release-amd]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
needs.release-arm.result == 'success' &&
|
||||||
|
needs.release-amd.result == 'success'
|
||||||
|
}}
|
||||||
|
timeout-minutes: 30
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
|
- name: Log in to Docker Hub
|
||||||
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
|
with:
|
||||||
|
registry: docker.io
|
||||||
|
username: ${{ secrets.DOCKER_HUB_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
|
||||||
|
|
||||||
|
- name: Extract tag name
|
||||||
|
id: get-tag
|
||||||
|
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Check if release candidate
|
||||||
|
id: check-rc
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
if [[ "$TAG" == *"-rc."* ]]; then
|
||||||
|
echo "IS_RC=true" >> $GITHUB_ENV
|
||||||
|
else
|
||||||
|
echo "IS_RC=false" >> $GITHUB_ENV
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Create multi-arch manifests
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
if [ "$IS_RC" = "true" ]; then
|
||||||
|
make create-manifests-rc tag=$TAG
|
||||||
|
else
|
||||||
|
make create-manifests tag=$TAG
|
||||||
|
fi
|
||||||
|
echo "Created multi-arch manifests for tag: ${TAG}"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
sign-and-package:
|
||||||
|
name: Sign and Package
|
||||||
|
runs-on: [self-hosted, linux, x64, us-east-1]
|
||||||
|
needs: [release-arm, release-amd, create-manifest]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
needs.release-arm.result == 'success' &&
|
||||||
|
needs.release-amd.result == 'success' &&
|
||||||
|
needs.create-manifest.result == 'success'
|
||||||
|
}}
|
||||||
|
# Job-level timeout to avoid runaway or stuck runs
|
||||||
|
timeout-minutes: 120
|
||||||
|
env:
|
||||||
|
# Target images
|
||||||
|
DOCKERHUB_IMAGE: docker.io/fosrl/${{ github.event.repository.name }}
|
||||||
|
GHCR_IMAGE: ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
|
- name: Extract tag name
|
||||||
|
id: get-tag
|
||||||
|
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Install Go
|
||||||
|
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
|
||||||
|
with:
|
||||||
|
go-version: 1.24
|
||||||
|
|
||||||
|
- name: Update version in package.json
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
sed -i "s/export const APP_VERSION = \".*\";/export const APP_VERSION = \"$TAG\";/" server/lib/consts.ts
|
||||||
|
cat server/lib/consts.ts
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Pull latest Gerbil version
|
||||||
|
id: get-gerbil-tag
|
||||||
|
run: |
|
||||||
|
LATEST_TAG=$(curl -s https://api.github.com/repos/fosrl/gerbil/tags | jq -r '.[0].name')
|
||||||
|
echo "LATEST_GERBIL_TAG=$LATEST_TAG" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Pull latest Badger version
|
||||||
|
id: get-badger-tag
|
||||||
|
run: |
|
||||||
|
LATEST_TAG=$(curl -s https://api.github.com/repos/fosrl/badger/tags | jq -r '.[0].name')
|
||||||
|
echo "LATEST_BADGER_TAG=$LATEST_TAG" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Update install/main.go
|
||||||
|
run: |
|
||||||
|
PANGOLIN_VERSION=${{ env.TAG }}
|
||||||
|
GERBIL_VERSION=${{ env.LATEST_GERBIL_TAG }}
|
||||||
|
BADGER_VERSION=${{ env.LATEST_BADGER_TAG }}
|
||||||
|
sed -i "s/config.PangolinVersion = \".*\"/config.PangolinVersion = \"$PANGOLIN_VERSION\"/" install/main.go
|
||||||
|
sed -i "s/config.GerbilVersion = \".*\"/config.GerbilVersion = \"$GERBIL_VERSION\"/" install/main.go
|
||||||
|
sed -i "s/config.BadgerVersion = \".*\"/config.BadgerVersion = \"$BADGER_VERSION\"/" install/main.go
|
||||||
|
echo "Updated install/main.go with Pangolin version $PANGOLIN_VERSION, Gerbil version $GERBIL_VERSION, and Badger version $BADGER_VERSION"
|
||||||
|
cat install/main.go
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Build installer
|
||||||
|
working-directory: install
|
||||||
|
run: |
|
||||||
|
make go-build-release
|
||||||
|
|
||||||
|
- name: Upload artifacts from /install/bin
|
||||||
|
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
|
||||||
|
with:
|
||||||
|
name: install-bin
|
||||||
|
path: install/bin/
|
||||||
|
|
||||||
|
- name: Install skopeo + jq
|
||||||
|
# skopeo: copy/inspect images between registries
|
||||||
|
# jq: JSON parsing tool used to extract digest values
|
||||||
|
run: |
|
||||||
|
sudo apt-get update -y
|
||||||
|
sudo apt-get install -y skopeo jq
|
||||||
|
skopeo --version
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Login to GHCR
|
||||||
|
env:
|
||||||
|
REGISTRY_AUTH_FILE: ${{ runner.temp }}/containers/auth.json
|
||||||
|
run: |
|
||||||
|
mkdir -p "$(dirname "$REGISTRY_AUTH_FILE")"
|
||||||
|
skopeo login ghcr.io -u "${{ github.actor }}" -p "${{ secrets.GITHUB_TOKEN }}"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Copy tag from Docker Hub to GHCR
|
||||||
|
# Mirror the already-built image (all architectures) to GHCR so we can sign it
|
||||||
|
# Wait a bit for both architectures to be available in Docker Hub manifest
|
||||||
|
env:
|
||||||
|
REGISTRY_AUTH_FILE: ${{ runner.temp }}/containers/auth.json
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
echo "Waiting for multi-arch manifest to be ready..."
|
||||||
|
sleep 30
|
||||||
|
echo "Copying ${{ env.DOCKERHUB_IMAGE }}:${TAG} -> ${{ env.GHCR_IMAGE }}:${TAG}"
|
||||||
|
skopeo copy --all --retry-times 3 \
|
||||||
|
docker://$DOCKERHUB_IMAGE:$TAG \
|
||||||
|
docker://$GHCR_IMAGE:$TAG
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Login to GitHub Container Registry (for cosign)
|
||||||
|
uses: docker/login-action@5e57cd118135c172c3672efd75eb46360885c0ef # v3.6.0
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
- name: Install cosign
|
||||||
|
# cosign is used to sign and verify container images (key and keyless)
|
||||||
|
uses: sigstore/cosign-installer@faadad0cce49287aee09b3a48701e75088a2c6ad # v4.0.0
|
||||||
|
|
||||||
|
- name: Dual-sign and verify (GHCR & Docker Hub)
|
||||||
|
# Sign each image by digest using keyless (OIDC) and key-based signing,
|
||||||
|
# then verify both the public key signature and the keyless OIDC signature.
|
||||||
|
env:
|
||||||
|
TAG: ${{ env.TAG }}
|
||||||
|
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }}
|
||||||
|
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }}
|
||||||
|
COSIGN_PUBLIC_KEY: ${{ secrets.COSIGN_PUBLIC_KEY }}
|
||||||
|
COSIGN_YES: "true"
|
||||||
|
run: |
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
issuer="https://token.actions.githubusercontent.com"
|
||||||
|
id_regex="^https://github.com/${{ github.repository }}/.+" # accept this repo (all workflows/refs)
|
||||||
|
|
||||||
|
for IMAGE in "${GHCR_IMAGE}" "${DOCKERHUB_IMAGE}"; do
|
||||||
|
echo "Processing ${IMAGE}:${TAG}"
|
||||||
|
|
||||||
|
DIGEST="$(skopeo inspect --retry-times 3 docker://${IMAGE}:${TAG} | jq -r '.Digest')"
|
||||||
|
REF="${IMAGE}@${DIGEST}"
|
||||||
|
echo "Resolved digest: ${REF}"
|
||||||
|
|
||||||
|
echo "==> cosign sign (keyless) --recursive ${REF}"
|
||||||
|
cosign sign --recursive "${REF}"
|
||||||
|
|
||||||
|
echo "==> cosign sign (key) --recursive ${REF}"
|
||||||
|
cosign sign --key env://COSIGN_PRIVATE_KEY --recursive "${REF}"
|
||||||
|
|
||||||
|
echo "==> cosign verify (public key) ${REF}"
|
||||||
|
cosign verify --key env://COSIGN_PUBLIC_KEY "${REF}" -o text
|
||||||
|
|
||||||
|
echo "==> cosign verify (keyless policy) ${REF}"
|
||||||
|
cosign verify \
|
||||||
|
--certificate-oidc-issuer "${issuer}" \
|
||||||
|
--certificate-identity-regexp "${id_regex}" \
|
||||||
|
"${REF}" -o text
|
||||||
|
done
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
post-run:
|
||||||
|
needs: [pre-run, release-arm, release-amd, create-manifest, sign-and-package]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
always() &&
|
||||||
|
needs.pre-run.result == 'success' &&
|
||||||
|
(needs.release-arm.result == 'success' || needs.release-arm.result == 'skipped' || needs.release-arm.result == 'failure') &&
|
||||||
|
(needs.release-amd.result == 'success' || needs.release-amd.result == 'skipped' || needs.release-amd.result == 'failure') &&
|
||||||
|
(needs.create-manifest.result == 'success' || needs.create-manifest.result == 'skipped' || needs.create-manifest.result == 'failure') &&
|
||||||
|
(needs.sign-and-package.result == 'success' || needs.sign-and-package.result == 'skipped' || needs.sign-and-package.result == 'failure')
|
||||||
|
}}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions: write-all
|
||||||
|
steps:
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v2
|
||||||
|
with:
|
||||||
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
|
||||||
|
role-duration-seconds: 3600
|
||||||
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
|
|
||||||
|
- name: Verify AWS identity
|
||||||
|
run: aws sts get-caller-identity
|
||||||
|
|
||||||
|
- name: Stop EC2 instances
|
||||||
|
run: |
|
||||||
|
aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_ARM_RUNNER }}
|
||||||
|
aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_AMD_RUNNER }}
|
||||||
|
echo "EC2 instances stopped"
|
||||||
@@ -0,0 +1,125 @@
|
|||||||
|
name: CI/CD Pipeline
|
||||||
|
|
||||||
|
# CI/CD workflow for building, publishing, mirroring, signing container images and building release binaries.
|
||||||
|
# Actions are pinned to specific SHAs to reduce supply-chain risk. This workflow triggers on tag push events.
|
||||||
|
|
||||||
|
permissions:
|
||||||
|
contents: read
|
||||||
|
packages: write # for GHCR push
|
||||||
|
id-token: write # for Cosign Keyless (OIDC) Signing
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "[0-9]+.[0-9]+.[0-9]+-s.[0-9]+"
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.ref }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
pre-run:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions: write-all
|
||||||
|
steps:
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v2
|
||||||
|
with:
|
||||||
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
|
||||||
|
role-duration-seconds: 3600
|
||||||
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
|
|
||||||
|
- name: Verify AWS identity
|
||||||
|
run: aws sts get-caller-identity
|
||||||
|
|
||||||
|
- name: Start EC2 instances
|
||||||
|
run: |
|
||||||
|
aws ec2 start-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_ARM_RUNNER }}
|
||||||
|
echo "EC2 instances started"
|
||||||
|
|
||||||
|
|
||||||
|
release-arm:
|
||||||
|
name: Build and Release (ARM64)
|
||||||
|
runs-on: [self-hosted, linux, arm64, us-east-1]
|
||||||
|
needs: [pre-run]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
needs.pre-run.result == 'success'
|
||||||
|
}}
|
||||||
|
# Job-level timeout to avoid runaway or stuck runs
|
||||||
|
timeout-minutes: 120
|
||||||
|
env:
|
||||||
|
# Target images
|
||||||
|
AWS_IMAGE: ${{ secrets.aws_account_id }}.dkr.ecr.us-east-1.amazonaws.com/${{ github.event.repository.name }}
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
|
||||||
|
|
||||||
|
- name: Monitor storage space
|
||||||
|
run: |
|
||||||
|
THRESHOLD=75
|
||||||
|
USED_SPACE=$(df / | grep / | awk '{ print $5 }' | sed 's/%//g')
|
||||||
|
echo "Used space: $USED_SPACE%"
|
||||||
|
if [ "$USED_SPACE" -ge "$THRESHOLD" ]; then
|
||||||
|
echo "Used space is below the threshold of 75% free. Running Docker system prune."
|
||||||
|
echo y | docker system prune -a
|
||||||
|
else
|
||||||
|
echo "Storage space is above the threshold. No action needed."
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v2
|
||||||
|
with:
|
||||||
|
role-to-assume: arn:aws:iam::${{ secrets.aws_account_id }}:role/${{ secrets.AWS_ROLE_NAME }}
|
||||||
|
role-duration-seconds: 3600
|
||||||
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
|
|
||||||
|
- name: Login to Amazon ECR
|
||||||
|
id: login-ecr
|
||||||
|
uses: aws-actions/amazon-ecr-login@v2
|
||||||
|
|
||||||
|
- name: Extract tag name
|
||||||
|
id: get-tag
|
||||||
|
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Update version in package.json
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
sed -i "s/export const APP_VERSION = \".*\";/export const APP_VERSION = \"$TAG\";/" server/lib/consts.ts
|
||||||
|
cat server/lib/consts.ts
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
- name: Build and push Docker images (Docker Hub - ARM64)
|
||||||
|
run: |
|
||||||
|
TAG=${{ env.TAG }}
|
||||||
|
make build-saas tag=$TAG
|
||||||
|
echo "Built & pushed ARM64 images to: ${{ env.AWS_IMAGE }}:${TAG}"
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
post-run:
|
||||||
|
needs: [pre-run, release-arm]
|
||||||
|
if: >-
|
||||||
|
${{
|
||||||
|
always() &&
|
||||||
|
needs.pre-run.result == 'success' &&
|
||||||
|
(needs.release-arm.result == 'success' || needs.release-arm.result == 'skipped' || needs.release-arm.result == 'failure')
|
||||||
|
}}
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions: write-all
|
||||||
|
steps:
|
||||||
|
- name: Configure AWS credentials
|
||||||
|
uses: aws-actions/configure-aws-credentials@v2
|
||||||
|
with:
|
||||||
|
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/${{ secrets.AWS_ROLE_NAME }}
|
||||||
|
role-duration-seconds: 3600
|
||||||
|
aws-region: ${{ secrets.AWS_REGION }}
|
||||||
|
|
||||||
|
- name: Verify AWS identity
|
||||||
|
run: aws sts get-caller-identity
|
||||||
|
|
||||||
|
- name: Stop EC2 instances
|
||||||
|
run: |
|
||||||
|
aws ec2 stop-instances --instance-ids ${{ secrets.EC2_INSTANCE_ID_ARM_RUNNER }}
|
||||||
|
echo "EC2 instances stopped"
|
||||||
+23
@@ -1,10 +1,20 @@
|
|||||||
FROM node:24-alpine AS builder
|
FROM node:24-alpine AS builder
|
||||||
|
|
||||||
|
# OCI Image Labels - Build Args for dynamic values
|
||||||
|
ARG VERSION="dev"
|
||||||
|
ARG REVISION=""
|
||||||
|
ARG CREATED=""
|
||||||
|
ARG LICENSE="AGPL-3.0"
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
ARG BUILD=oss
|
ARG BUILD=oss
|
||||||
ARG DATABASE=sqlite
|
ARG DATABASE=sqlite
|
||||||
|
|
||||||
|
# Derive title and description based on BUILD type
|
||||||
|
ARG IMAGE_TITLE="Pangolin"
|
||||||
|
ARG IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere"
|
||||||
|
|
||||||
RUN apk add --no-cache curl tzdata python3 make g++
|
RUN apk add --no-cache curl tzdata python3 make g++
|
||||||
|
|
||||||
# COPY package.json package-lock.json ./
|
# COPY package.json package-lock.json ./
|
||||||
@@ -69,4 +79,17 @@ RUN chmod +x /usr/local/bin/pangctl ./dist/cli.mjs
|
|||||||
COPY server/db/names.json ./dist/names.json
|
COPY server/db/names.json ./dist/names.json
|
||||||
COPY public ./public
|
COPY public ./public
|
||||||
|
|
||||||
|
# OCI Image Labels
|
||||||
|
# https://github.com/opencontainers/image-spec/blob/main/annotations.md
|
||||||
|
LABEL org.opencontainers.image.source="https://github.com/fosrl/pangolin" \
|
||||||
|
org.opencontainers.image.url="https://github.com/fosrl/pangolin" \
|
||||||
|
org.opencontainers.image.documentation="https://docs.pangolin.net" \
|
||||||
|
org.opencontainers.image.vendor="Fossorial" \
|
||||||
|
org.opencontainers.image.licenses="${LICENSE}" \
|
||||||
|
org.opencontainers.image.title="${IMAGE_TITLE}" \
|
||||||
|
org.opencontainers.image.description="${IMAGE_DESCRIPTION}" \
|
||||||
|
org.opencontainers.image.version="${VERSION}" \
|
||||||
|
org.opencontainers.image.revision="${REVISION}" \
|
||||||
|
org.opencontainers.image.created="${CREATED}"
|
||||||
|
|
||||||
CMD ["npm", "run", "start"]
|
CMD ["npm", "run", "start"]
|
||||||
|
|||||||
@@ -3,6 +3,25 @@
|
|||||||
major_tag := $(shell echo $(tag) | cut -d. -f1)
|
major_tag := $(shell echo $(tag) | cut -d. -f1)
|
||||||
minor_tag := $(shell echo $(tag) | cut -d. -f1,2)
|
minor_tag := $(shell echo $(tag) | cut -d. -f1,2)
|
||||||
|
|
||||||
|
# OCI label variables
|
||||||
|
CREATED := $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
|
||||||
|
REVISION := $(shell git rev-parse HEAD 2>/dev/null || echo "unknown")
|
||||||
|
|
||||||
|
# Common OCI build args for OSS builds
|
||||||
|
OCI_ARGS_OSS = --build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$(REVISION) \
|
||||||
|
--build-arg CREATED=$(CREATED) \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere"
|
||||||
|
|
||||||
|
# Common OCI build args for Enterprise builds
|
||||||
|
OCI_ARGS_EE = --build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$(REVISION) \
|
||||||
|
--build-arg CREATED=$(CREATED) \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere"
|
||||||
|
|
||||||
.PHONY: build-release build-sqlite build-postgresql build-ee-sqlite build-ee-postgresql
|
.PHONY: build-release build-sqlite build-postgresql build-ee-sqlite build-ee-postgresql
|
||||||
|
|
||||||
build-release: build-sqlite build-postgresql build-ee-sqlite build-ee-postgresql
|
build-release: build-sqlite build-postgresql build-ee-sqlite build-ee-postgresql
|
||||||
@@ -15,6 +34,7 @@ build-sqlite:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
$(OCI_ARGS_OSS) \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:latest \
|
--tag fosrl/pangolin:latest \
|
||||||
--tag fosrl/pangolin:$(major_tag) \
|
--tag fosrl/pangolin:$(major_tag) \
|
||||||
@@ -30,6 +50,7 @@ build-postgresql:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
$(OCI_ARGS_OSS) \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:postgresql-latest \
|
--tag fosrl/pangolin:postgresql-latest \
|
||||||
--tag fosrl/pangolin:postgresql-$(major_tag) \
|
--tag fosrl/pangolin:postgresql-$(major_tag) \
|
||||||
@@ -45,6 +66,7 @@ build-ee-sqlite:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
$(OCI_ARGS_EE) \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-latest \
|
--tag fosrl/pangolin:ee-latest \
|
||||||
--tag fosrl/pangolin:ee-$(major_tag) \
|
--tag fosrl/pangolin:ee-$(major_tag) \
|
||||||
@@ -60,6 +82,7 @@ build-ee-postgresql:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
$(OCI_ARGS_EE) \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-latest \
|
--tag fosrl/pangolin:ee-postgresql-latest \
|
||||||
--tag fosrl/pangolin:ee-postgresql-$(major_tag) \
|
--tag fosrl/pangolin:ee-postgresql-$(major_tag) \
|
||||||
@@ -67,6 +90,18 @@ build-ee-postgresql:
|
|||||||
--tag fosrl/pangolin:ee-postgresql-$(tag) \
|
--tag fosrl/pangolin:ee-postgresql-$(tag) \
|
||||||
--push .
|
--push .
|
||||||
|
|
||||||
|
build-saas:
|
||||||
|
@if [ -z "$(tag)" ]; then \
|
||||||
|
echo "Error: tag is required. Usage: make build-release tag=<tag>"; \
|
||||||
|
exit 1; \
|
||||||
|
fi
|
||||||
|
docker buildx build \
|
||||||
|
--build-arg BUILD=saas \
|
||||||
|
--build-arg DATABASE=pg \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
--tag $(AWS_IMAGE):$(tag) \
|
||||||
|
--push .
|
||||||
|
|
||||||
build-release-arm:
|
build-release-arm:
|
||||||
@if [ -z "$(tag)" ]; then \
|
@if [ -z "$(tag)" ]; then \
|
||||||
echo "Error: tag is required. Usage: make build-release-arm tag=<tag>"; \
|
echo "Error: tag is required. Usage: make build-release-arm tag=<tag>"; \
|
||||||
@@ -74,9 +109,16 @@ build-release-arm:
|
|||||||
fi
|
fi
|
||||||
@MAJOR_TAG=$$(echo $(tag) | cut -d. -f1); \
|
@MAJOR_TAG=$$(echo $(tag) | cut -d. -f1); \
|
||||||
MINOR_TAG=$$(echo $(tag) | cut -d. -f1,2); \
|
MINOR_TAG=$$(echo $(tag) | cut -d. -f1,2); \
|
||||||
|
CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:latest-arm64 \
|
--tag fosrl/pangolin:latest-arm64 \
|
||||||
--tag fosrl/pangolin:$$MAJOR_TAG-arm64 \
|
--tag fosrl/pangolin:$$MAJOR_TAG-arm64 \
|
||||||
@@ -86,6 +128,11 @@ build-release-arm:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:postgresql-latest-arm64 \
|
--tag fosrl/pangolin:postgresql-latest-arm64 \
|
||||||
--tag fosrl/pangolin:postgresql-$$MAJOR_TAG-arm64 \
|
--tag fosrl/pangolin:postgresql-$$MAJOR_TAG-arm64 \
|
||||||
@@ -95,6 +142,12 @@ build-release-arm:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:ee-latest-arm64 \
|
--tag fosrl/pangolin:ee-latest-arm64 \
|
||||||
--tag fosrl/pangolin:ee-$$MAJOR_TAG-arm64 \
|
--tag fosrl/pangolin:ee-$$MAJOR_TAG-arm64 \
|
||||||
@@ -104,6 +157,12 @@ build-release-arm:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-latest-arm64 \
|
--tag fosrl/pangolin:ee-postgresql-latest-arm64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-$$MAJOR_TAG-arm64 \
|
--tag fosrl/pangolin:ee-postgresql-$$MAJOR_TAG-arm64 \
|
||||||
@@ -118,9 +177,16 @@ build-release-amd:
|
|||||||
fi
|
fi
|
||||||
@MAJOR_TAG=$$(echo $(tag) | cut -d. -f1); \
|
@MAJOR_TAG=$$(echo $(tag) | cut -d. -f1); \
|
||||||
MINOR_TAG=$$(echo $(tag) | cut -d. -f1,2); \
|
MINOR_TAG=$$(echo $(tag) | cut -d. -f1,2); \
|
||||||
|
CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:latest-amd64 \
|
--tag fosrl/pangolin:latest-amd64 \
|
||||||
--tag fosrl/pangolin:$$MAJOR_TAG-amd64 \
|
--tag fosrl/pangolin:$$MAJOR_TAG-amd64 \
|
||||||
@@ -130,6 +196,11 @@ build-release-amd:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:postgresql-latest-amd64 \
|
--tag fosrl/pangolin:postgresql-latest-amd64 \
|
||||||
--tag fosrl/pangolin:postgresql-$$MAJOR_TAG-amd64 \
|
--tag fosrl/pangolin:postgresql-$$MAJOR_TAG-amd64 \
|
||||||
@@ -139,6 +210,12 @@ build-release-amd:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-latest-amd64 \
|
--tag fosrl/pangolin:ee-latest-amd64 \
|
||||||
--tag fosrl/pangolin:ee-$$MAJOR_TAG-amd64 \
|
--tag fosrl/pangolin:ee-$$MAJOR_TAG-amd64 \
|
||||||
@@ -148,6 +225,12 @@ build-release-amd:
|
|||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-latest-amd64 \
|
--tag fosrl/pangolin:ee-postgresql-latest-amd64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-$$MAJOR_TAG-amd64 \
|
--tag fosrl/pangolin:ee-postgresql-$$MAJOR_TAG-amd64 \
|
||||||
@@ -201,27 +284,51 @@ build-rc:
|
|||||||
echo "Error: tag is required. Usage: make build-release tag=<tag>"; \
|
echo "Error: tag is required. Usage: make build-release tag=<tag>"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:$(tag) \
|
--tag fosrl/pangolin:$(tag) \
|
||||||
--push .
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:postgresql-$(tag) \
|
--tag fosrl/pangolin:postgresql-$(tag) \
|
||||||
--push .
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-$(tag) \
|
--tag fosrl/pangolin:ee-$(tag) \
|
||||||
--push .
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64,linux/amd64 \
|
--platform linux/arm64,linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-$(tag) \
|
--tag fosrl/pangolin:ee-postgresql-$(tag) \
|
||||||
--push .
|
--push .
|
||||||
@@ -231,27 +338,51 @@ build-rc-arm:
|
|||||||
echo "Error: tag is required. Usage: make build-rc-arm tag=<tag>"; \
|
echo "Error: tag is required. Usage: make build-rc-arm tag=<tag>"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:$(tag)-arm64 \
|
--tag fosrl/pangolin:$(tag)-arm64 \
|
||||||
--push . && \
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:postgresql-$(tag)-arm64 \
|
--tag fosrl/pangolin:postgresql-$(tag)-arm64 \
|
||||||
--push . && \
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:ee-$(tag)-arm64 \
|
--tag fosrl/pangolin:ee-$(tag)-arm64 \
|
||||||
--push . && \
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/arm64 \
|
--platform linux/arm64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-$(tag)-arm64 \
|
--tag fosrl/pangolin:ee-postgresql-$(tag)-arm64 \
|
||||||
--push .
|
--push .
|
||||||
@@ -261,27 +392,51 @@ build-rc-amd:
|
|||||||
echo "Error: tag is required. Usage: make build-rc-amd tag=<tag>"; \
|
echo "Error: tag is required. Usage: make build-rc-amd tag=<tag>"; \
|
||||||
exit 1; \
|
exit 1; \
|
||||||
fi
|
fi
|
||||||
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:$(tag)-amd64 \
|
--tag fosrl/pangolin:$(tag)-amd64 \
|
||||||
--push . && \
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=oss \
|
--build-arg BUILD=oss \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:postgresql-$(tag)-amd64 \
|
--tag fosrl/pangolin:postgresql-$(tag)-amd64 \
|
||||||
--push . && \
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=sqlite \
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-$(tag)-amd64 \
|
--tag fosrl/pangolin:ee-$(tag)-amd64 \
|
||||||
--push . && \
|
--push . && \
|
||||||
docker buildx build \
|
docker buildx build \
|
||||||
--build-arg BUILD=enterprise \
|
--build-arg BUILD=enterprise \
|
||||||
--build-arg DATABASE=pg \
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=$(tag) \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg LICENSE="Fossorial Commercial" \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin EE" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Pangolin Enterprise Edition - Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
--platform linux/amd64 \
|
--platform linux/amd64 \
|
||||||
--tag fosrl/pangolin:ee-postgresql-$(tag)-amd64 \
|
--tag fosrl/pangolin:ee-postgresql-$(tag)-amd64 \
|
||||||
--push .
|
--push .
|
||||||
@@ -314,16 +469,52 @@ create-manifests-rc:
|
|||||||
echo "All RC multi-arch manifests created successfully!"
|
echo "All RC multi-arch manifests created successfully!"
|
||||||
|
|
||||||
build-arm:
|
build-arm:
|
||||||
docker buildx build --platform linux/arm64 -t fosrl/pangolin:latest .
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
|
docker buildx build \
|
||||||
|
--build-arg VERSION=dev \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
-t fosrl/pangolin:latest .
|
||||||
|
|
||||||
build-x86:
|
build-x86:
|
||||||
docker buildx build --platform linux/amd64 -t fosrl/pangolin:latest .
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
|
docker buildx build \
|
||||||
|
--build-arg VERSION=dev \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
|
--platform linux/amd64 \
|
||||||
|
-t fosrl/pangolin:latest .
|
||||||
|
|
||||||
dev-build-sqlite:
|
dev-build-sqlite:
|
||||||
docker build --build-arg DATABASE=sqlite -t fosrl/pangolin:latest .
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
|
docker build \
|
||||||
|
--build-arg DATABASE=sqlite \
|
||||||
|
--build-arg VERSION=dev \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
|
-t fosrl/pangolin:latest .
|
||||||
|
|
||||||
dev-build-pg:
|
dev-build-pg:
|
||||||
docker build --build-arg DATABASE=pg -t fosrl/pangolin:postgresql-latest .
|
@CREATED=$$(date -u +"%Y-%m-%dT%H:%M:%SZ"); \
|
||||||
|
REVISION=$$(git rev-parse HEAD 2>/dev/null || echo "unknown"); \
|
||||||
|
docker build \
|
||||||
|
--build-arg DATABASE=pg \
|
||||||
|
--build-arg VERSION=dev \
|
||||||
|
--build-arg REVISION=$$REVISION \
|
||||||
|
--build-arg CREATED=$$CREATED \
|
||||||
|
--build-arg IMAGE_TITLE="Pangolin" \
|
||||||
|
--build-arg IMAGE_DESCRIPTION="Identity-aware VPN and proxy for remote access to anything, anywhere" \
|
||||||
|
-t fosrl/pangolin:postgresql-latest .
|
||||||
|
|
||||||
test:
|
test:
|
||||||
docker run -it -p 3000:3000 -p 3001:3001 -p 3002:3002 -v ./config:/app/config fosrl/pangolin:latest
|
docker run -it -p 3000:3000 -p 3001:3001 -p 3002:3002 -v ./config:/app/config fosrl/pangolin:latest
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
http:
|
http:
|
||||||
middlewares:
|
middlewares:
|
||||||
|
badger:
|
||||||
|
plugin:
|
||||||
|
badger:
|
||||||
|
disableForwardAuth: true
|
||||||
redirect-to-https:
|
redirect-to-https:
|
||||||
redirectScheme:
|
redirectScheme:
|
||||||
scheme: https
|
scheme: https
|
||||||
@@ -13,6 +17,7 @@ http:
|
|||||||
- web
|
- web
|
||||||
middlewares:
|
middlewares:
|
||||||
- redirect-to-https
|
- redirect-to-https
|
||||||
|
- badger
|
||||||
|
|
||||||
# Next.js router (handles everything except API and WebSocket paths)
|
# Next.js router (handles everything except API and WebSocket paths)
|
||||||
next-router:
|
next-router:
|
||||||
@@ -21,6 +26,8 @@ http:
|
|||||||
priority: 10
|
priority: 10
|
||||||
entryPoints:
|
entryPoints:
|
||||||
- websecure
|
- websecure
|
||||||
|
middlewares:
|
||||||
|
- badger
|
||||||
tls:
|
tls:
|
||||||
certResolver: letsencrypt
|
certResolver: letsencrypt
|
||||||
|
|
||||||
@@ -31,6 +38,8 @@ http:
|
|||||||
priority: 100
|
priority: 100
|
||||||
entryPoints:
|
entryPoints:
|
||||||
- websecure
|
- websecure
|
||||||
|
middlewares:
|
||||||
|
- badger
|
||||||
tls:
|
tls:
|
||||||
certResolver: letsencrypt
|
certResolver: letsencrypt
|
||||||
|
|
||||||
|
|||||||
@@ -43,9 +43,12 @@ entryPoints:
|
|||||||
http:
|
http:
|
||||||
tls:
|
tls:
|
||||||
certResolver: "letsencrypt"
|
certResolver: "letsencrypt"
|
||||||
|
encodedCharacters:
|
||||||
|
allowEncodedSlash: true
|
||||||
|
allowEncodedQuestionMark: true
|
||||||
|
|
||||||
serversTransport:
|
serversTransport:
|
||||||
insecureSkipVerify: true
|
insecureSkipVerify: true
|
||||||
|
|
||||||
ping:
|
ping:
|
||||||
entryPoint: "web"
|
entryPoint: "web"
|
||||||
|
|||||||
+1
-1
@@ -340,7 +340,7 @@ func collectUserInput(reader *bufio.Reader) Config {
|
|||||||
// Basic configuration
|
// Basic configuration
|
||||||
fmt.Println("\n=== Basic Configuration ===")
|
fmt.Println("\n=== Basic Configuration ===")
|
||||||
|
|
||||||
config.IsEnterprise = readBoolNoDefault(reader, "Do you want to install the Enterprise version of Pangolin? The EE is free for persoal use or for businesses making less than 100k USD annually.")
|
config.IsEnterprise = readBoolNoDefault(reader, "Do you want to install the Enterprise version of Pangolin? The EE is free for personal use or for businesses making less than 100k USD annually.")
|
||||||
|
|
||||||
config.BaseDomain = readString(reader, "Enter your base domain (no subdomain e.g. example.com)", "")
|
config.BaseDomain = readString(reader, "Enter your base domain (no subdomain e.g. example.com)", "")
|
||||||
|
|
||||||
|
|||||||
+34
-4
@@ -1118,6 +1118,10 @@
|
|||||||
"actionUpdateIdpOrg": "Update IDP Org",
|
"actionUpdateIdpOrg": "Update IDP Org",
|
||||||
"actionCreateClient": "Create Client",
|
"actionCreateClient": "Create Client",
|
||||||
"actionDeleteClient": "Delete Client",
|
"actionDeleteClient": "Delete Client",
|
||||||
|
"actionArchiveClient": "Archive Client",
|
||||||
|
"actionUnarchiveClient": "Unarchive Client",
|
||||||
|
"actionBlockClient": "Block Client",
|
||||||
|
"actionUnblockClient": "Unblock Client",
|
||||||
"actionUpdateClient": "Update Client",
|
"actionUpdateClient": "Update Client",
|
||||||
"actionListClients": "List Clients",
|
"actionListClients": "List Clients",
|
||||||
"actionGetClient": "Get Client",
|
"actionGetClient": "Get Client",
|
||||||
@@ -1135,7 +1139,7 @@
|
|||||||
"create": "Create",
|
"create": "Create",
|
||||||
"orgs": "Organizations",
|
"orgs": "Organizations",
|
||||||
"loginError": "An error occurred while logging in",
|
"loginError": "An error occurred while logging in",
|
||||||
"loginRequiredForDevice": "Login is required to authenticate your device.",
|
"loginRequiredForDevice": "Login is required for your device.",
|
||||||
"passwordForgot": "Forgot your password?",
|
"passwordForgot": "Forgot your password?",
|
||||||
"otpAuth": "Two-Factor Authentication",
|
"otpAuth": "Two-Factor Authentication",
|
||||||
"otpAuthDescription": "Enter the code from your authenticator app or one of your single-use backup codes.",
|
"otpAuthDescription": "Enter the code from your authenticator app or one of your single-use backup codes.",
|
||||||
@@ -1876,7 +1880,7 @@
|
|||||||
"orgAuthChooseIdpDescription": "Choose your identity provider to continue",
|
"orgAuthChooseIdpDescription": "Choose your identity provider to continue",
|
||||||
"orgAuthNoIdpConfigured": "This organization doesn't have any identity providers configured. You can log in with your Pangolin identity instead.",
|
"orgAuthNoIdpConfigured": "This organization doesn't have any identity providers configured. You can log in with your Pangolin identity instead.",
|
||||||
"orgAuthSignInWithPangolin": "Sign in with Pangolin",
|
"orgAuthSignInWithPangolin": "Sign in with Pangolin",
|
||||||
"orgAuthSignInToOrg": "Sign in to an organization",
|
"orgAuthSignInToOrg": "Use organization's identity provider",
|
||||||
"orgAuthSelectOrgTitle": "Organization Sign In",
|
"orgAuthSelectOrgTitle": "Organization Sign In",
|
||||||
"orgAuthSelectOrgDescription": "Enter your organization ID to continue",
|
"orgAuthSelectOrgDescription": "Enter your organization ID to continue",
|
||||||
"orgAuthOrgIdPlaceholder": "your-organization",
|
"orgAuthOrgIdPlaceholder": "your-organization",
|
||||||
@@ -2244,7 +2248,7 @@
|
|||||||
"deviceOrganizationsAccess": "Access to all organizations your account has access to",
|
"deviceOrganizationsAccess": "Access to all organizations your account has access to",
|
||||||
"deviceAuthorize": "Authorize {applicationName}",
|
"deviceAuthorize": "Authorize {applicationName}",
|
||||||
"deviceConnected": "Device Connected!",
|
"deviceConnected": "Device Connected!",
|
||||||
"deviceAuthorizedMessage": "Device is authorized to access your account.",
|
"deviceAuthorizedMessage": "Device is authorized to access your account. Please return to the client application.",
|
||||||
"pangolinCloud": "Pangolin Cloud",
|
"pangolinCloud": "Pangolin Cloud",
|
||||||
"viewDevices": "View Devices",
|
"viewDevices": "View Devices",
|
||||||
"viewDevicesDescription": "Manage your connected devices",
|
"viewDevicesDescription": "Manage your connected devices",
|
||||||
@@ -2394,5 +2398,31 @@
|
|||||||
"maintenanceScreenTitle": "Service Temporarily Unavailable",
|
"maintenanceScreenTitle": "Service Temporarily Unavailable",
|
||||||
"maintenanceScreenMessage": "We are currently experiencing technical difficulties. Please check back soon.",
|
"maintenanceScreenMessage": "We are currently experiencing technical difficulties. Please check back soon.",
|
||||||
"maintenanceScreenEstimatedCompletion": "Estimated Completion:",
|
"maintenanceScreenEstimatedCompletion": "Estimated Completion:",
|
||||||
"createInternalResourceDialogDestinationRequired": "Destination is required"
|
"createInternalResourceDialogDestinationRequired": "Destination is required",
|
||||||
|
"available": "Available",
|
||||||
|
"archived": "Archived",
|
||||||
|
"noArchivedDevices": "No archived devices found",
|
||||||
|
"deviceArchived": "Device archived",
|
||||||
|
"deviceArchivedDescription": "The device has been successfully archived.",
|
||||||
|
"errorArchivingDevice": "Error archiving device",
|
||||||
|
"failedToArchiveDevice": "Failed to archive device",
|
||||||
|
"deviceQuestionArchive": "Are you sure you want to archive this device?",
|
||||||
|
"deviceMessageArchive": "The device will be archived and removed from your active devices list.",
|
||||||
|
"deviceArchiveConfirm": "Archive Device",
|
||||||
|
"archiveDevice": "Archive Device",
|
||||||
|
"archive": "Archive",
|
||||||
|
"deviceUnarchived": "Device unarchived",
|
||||||
|
"deviceUnarchivedDescription": "The device has been successfully unarchived.",
|
||||||
|
"errorUnarchivingDevice": "Error unarchiving device",
|
||||||
|
"failedToUnarchiveDevice": "Failed to unarchive device",
|
||||||
|
"unarchive": "Unarchive",
|
||||||
|
"archiveClient": "Archive Client",
|
||||||
|
"archiveClientQuestion": "Are you sure you want to archive this client?",
|
||||||
|
"archiveClientMessage": "The client will be archived and removed from your active clients list.",
|
||||||
|
"archiveClientConfirm": "Archive Client",
|
||||||
|
"blockClient": "Block Client",
|
||||||
|
"blockClientQuestion": "Are you sure you want to block this client?",
|
||||||
|
"blockClientMessage": "The device will be forced to disconnect if currently connected. You can unblock the device later.",
|
||||||
|
"blockClientConfirm": "Block Client",
|
||||||
|
"active": "Active"
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -3,7 +3,7 @@
|
|||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "Tunneled Reverse Proxy Management Server with Identity and Access Control and Dashboard UI",
|
"description": "Identity-aware VPN and proxy for remote access to anything, anywhere and Dashboard UI",
|
||||||
"homepage": "https://github.com/fosrl/pangolin",
|
"homepage": "https://github.com/fosrl/pangolin",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|||||||
@@ -78,6 +78,10 @@ export enum ActionsEnum {
|
|||||||
updateSiteResource = "updateSiteResource",
|
updateSiteResource = "updateSiteResource",
|
||||||
createClient = "createClient",
|
createClient = "createClient",
|
||||||
deleteClient = "deleteClient",
|
deleteClient = "deleteClient",
|
||||||
|
archiveClient = "archiveClient",
|
||||||
|
unarchiveClient = "unarchiveClient",
|
||||||
|
blockClient = "blockClient",
|
||||||
|
unblockClient = "unblockClient",
|
||||||
updateClient = "updateClient",
|
updateClient = "updateClient",
|
||||||
listClients = "listClients",
|
listClients = "listClients",
|
||||||
getClient = "getClient",
|
getClient = "getClient",
|
||||||
|
|||||||
@@ -688,7 +688,9 @@ export const clients = pgTable("clients", {
|
|||||||
online: boolean("online").notNull().default(false),
|
online: boolean("online").notNull().default(false),
|
||||||
// endpoint: varchar("endpoint"),
|
// endpoint: varchar("endpoint"),
|
||||||
lastHolePunch: integer("lastHolePunch"),
|
lastHolePunch: integer("lastHolePunch"),
|
||||||
maxConnections: integer("maxConnections")
|
maxConnections: integer("maxConnections"),
|
||||||
|
archived: boolean("archived").notNull().default(false),
|
||||||
|
blocked: boolean("blocked").notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const clientSitesAssociationsCache = pgTable(
|
export const clientSitesAssociationsCache = pgTable(
|
||||||
@@ -726,7 +728,8 @@ export const olms = pgTable("olms", {
|
|||||||
userId: text("userId").references(() => users.userId, {
|
userId: text("userId").references(() => users.userId, {
|
||||||
// optionally tied to a user and in this case delete when the user deletes
|
// optionally tied to a user and in this case delete when the user deletes
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
})
|
}),
|
||||||
|
archived: boolean("archived").notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const olmSessions = pgTable("clientSession", {
|
export const olmSessions = pgTable("clientSession", {
|
||||||
|
|||||||
@@ -383,7 +383,9 @@ export const clients = sqliteTable("clients", {
|
|||||||
type: text("type").notNull(), // "olm"
|
type: text("type").notNull(), // "olm"
|
||||||
online: integer("online", { mode: "boolean" }).notNull().default(false),
|
online: integer("online", { mode: "boolean" }).notNull().default(false),
|
||||||
// endpoint: text("endpoint"),
|
// endpoint: text("endpoint"),
|
||||||
lastHolePunch: integer("lastHolePunch")
|
lastHolePunch: integer("lastHolePunch"),
|
||||||
|
archived: integer("archived", { mode: "boolean" }).notNull().default(false),
|
||||||
|
blocked: integer("blocked", { mode: "boolean" }).notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const clientSitesAssociationsCache = sqliteTable(
|
export const clientSitesAssociationsCache = sqliteTable(
|
||||||
@@ -423,7 +425,8 @@ export const olms = sqliteTable("olms", {
|
|||||||
userId: text("userId").references(() => users.userId, {
|
userId: text("userId").references(() => users.userId, {
|
||||||
// optionally tied to a user and in this case delete when the user deletes
|
// optionally tied to a user and in this case delete when the user deletes
|
||||||
onDelete: "cascade"
|
onDelete: "cascade"
|
||||||
})
|
}),
|
||||||
|
archived: integer("archived", { mode: "boolean" }).notNull().default(false)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const twoFactorBackupCodes = sqliteTable("twoFactorBackupCodes", {
|
export const twoFactorBackupCodes = sqliteTable("twoFactorBackupCodes", {
|
||||||
|
|||||||
@@ -290,8 +290,8 @@ export const ClientResourceSchema = z
|
|||||||
alias: z
|
alias: z
|
||||||
.string()
|
.string()
|
||||||
.regex(
|
.regex(
|
||||||
/^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/,
|
/^(?:[a-zA-Z0-9*?](?:[a-zA-Z0-9*?-]{0,61}[a-zA-Z0-9*?])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/,
|
||||||
"Alias must be a fully qualified domain name (e.g., example.com)"
|
"Alias must be a fully qualified domain name with optional wildcards (e.g., example.com, *.example.com, host-0?.example.internal)"
|
||||||
)
|
)
|
||||||
.optional(),
|
.optional(),
|
||||||
roles: z
|
roles: z
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ export * from "./verifyApiKeyIsRoot";
|
|||||||
export * from "./verifyApiKeyApiKeyAccess";
|
export * from "./verifyApiKeyApiKeyAccess";
|
||||||
export * from "./verifyApiKeyClientAccess";
|
export * from "./verifyApiKeyClientAccess";
|
||||||
export * from "./verifyApiKeySiteResourceAccess";
|
export * from "./verifyApiKeySiteResourceAccess";
|
||||||
|
export * from "./verifyApiKeyIdpAccess";
|
||||||
|
|||||||
@@ -0,0 +1,88 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { idp, idpOrg, apiKeyOrg } from "@server/db";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
|
||||||
|
export async function verifyApiKeyIdpAccess(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const apiKey = req.apiKey;
|
||||||
|
const idpId = req.params.idpId || req.body.idpId || req.query.idpId;
|
||||||
|
const orgId = req.params.orgId;
|
||||||
|
|
||||||
|
if (!apiKey) {
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.UNAUTHORIZED, "Key not authenticated")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!orgId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.BAD_REQUEST, "Invalid organization ID")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!idpId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(HttpCode.BAD_REQUEST, "Invalid IDP ID")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiKey.isRoot) {
|
||||||
|
// Root keys can access any IDP in any org
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
|
const [idpRes] = await db
|
||||||
|
.select()
|
||||||
|
.from(idp)
|
||||||
|
.innerJoin(idpOrg, eq(idp.idpId, idpOrg.idpId))
|
||||||
|
.where(and(eq(idp.idpId, idpId), eq(idpOrg.orgId, orgId)))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!idpRes || !idpRes.idp || !idpRes.idpOrg) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`IdP with ID ${idpId} not found for organization ${orgId}`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.apiKeyOrg) {
|
||||||
|
const apiKeyOrgRes = await db
|
||||||
|
.select()
|
||||||
|
.from(apiKeyOrg)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(apiKeyOrg.apiKeyId, apiKey.apiKeyId),
|
||||||
|
eq(apiKeyOrg.orgId, idpRes.idpOrg.orgId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
req.apiKeyOrg = apiKeyOrgRes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!req.apiKeyOrg) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.FORBIDDEN,
|
||||||
|
"Key does not have access to this organization"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return next();
|
||||||
|
} catch (error) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Error verifying IDP access"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -139,6 +139,10 @@ export class PrivateConfig {
|
|||||||
process.env.USE_PANGOLIN_DNS =
|
process.env.USE_PANGOLIN_DNS =
|
||||||
this.rawPrivateConfig.flags.use_pangolin_dns.toString();
|
this.rawPrivateConfig.flags.use_pangolin_dns.toString();
|
||||||
}
|
}
|
||||||
|
if (this.rawPrivateConfig.flags.use_org_only_idp) {
|
||||||
|
process.env.USE_ORG_ONLY_IDP =
|
||||||
|
this.rawPrivateConfig.flags.use_org_only_idp.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getRawPrivateConfig() {
|
public getRawPrivateConfig() {
|
||||||
|
|||||||
@@ -50,10 +50,14 @@ export async function sendToExitNode(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return sendToClient(remoteExitNode.remoteExitNodeId, {
|
return sendToClient(
|
||||||
type: request.remoteType,
|
remoteExitNode.remoteExitNodeId,
|
||||||
data: request.data
|
{
|
||||||
});
|
type: request.remoteType,
|
||||||
|
data: request.data
|
||||||
|
},
|
||||||
|
{ incrementConfigVersion: true }
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
let hostname = exitNode.reachableAt;
|
let hostname = exitNode.reachableAt;
|
||||||
|
|
||||||
|
|||||||
@@ -288,7 +288,7 @@ export function selectBestExitNode(
|
|||||||
const validNodes = pingResults.filter((n) => !n.error && n.weight > 0);
|
const validNodes = pingResults.filter((n) => !n.error && n.weight > 0);
|
||||||
|
|
||||||
if (validNodes.length === 0) {
|
if (validNodes.length === 0) {
|
||||||
logger.error("No valid exit nodes available");
|
logger.debug("No valid exit nodes available");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+60
-40
@@ -24,7 +24,9 @@ export class LockManager {
|
|||||||
*/
|
*/
|
||||||
async acquireLock(
|
async acquireLock(
|
||||||
lockKey: string,
|
lockKey: string,
|
||||||
ttlMs: number = 30000
|
ttlMs: number = 30000,
|
||||||
|
maxRetries: number = 3,
|
||||||
|
retryDelayMs: number = 100
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (!redis || !redis.status || redis.status !== "ready") {
|
if (!redis || !redis.status || redis.status !== "ready") {
|
||||||
return true;
|
return true;
|
||||||
@@ -35,49 +37,67 @@ export class LockManager {
|
|||||||
}:${Date.now()}`;
|
}:${Date.now()}`;
|
||||||
const redisKey = `lock:${lockKey}`;
|
const redisKey = `lock:${lockKey}`;
|
||||||
|
|
||||||
try {
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
// Use SET with NX (only set if not exists) and PX (expire in milliseconds)
|
try {
|
||||||
// This is atomic and handles both setting and expiration
|
// Use SET with NX (only set if not exists) and PX (expire in milliseconds)
|
||||||
const result = await redis.set(
|
// This is atomic and handles both setting and expiration
|
||||||
redisKey,
|
const result = await redis.set(
|
||||||
lockValue,
|
redisKey,
|
||||||
"PX",
|
lockValue,
|
||||||
ttlMs,
|
"PX",
|
||||||
"NX"
|
ttlMs,
|
||||||
);
|
"NX"
|
||||||
|
|
||||||
if (result === "OK") {
|
|
||||||
logger.debug(
|
|
||||||
`Lock acquired: ${lockKey} by ${
|
|
||||||
config.getRawConfig().gerbil.exit_node_name
|
|
||||||
}`
|
|
||||||
);
|
);
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the existing lock is from this worker (reentrant behavior)
|
if (result === "OK") {
|
||||||
const existingValue = await redis.get(redisKey);
|
logger.debug(
|
||||||
if (
|
`Lock acquired: ${lockKey} by ${
|
||||||
existingValue &&
|
config.getRawConfig().gerbil.exit_node_name
|
||||||
existingValue.startsWith(
|
}`
|
||||||
`${config.getRawConfig().gerbil.exit_node_name}:`
|
);
|
||||||
)
|
return true;
|
||||||
) {
|
}
|
||||||
// Extend the lock TTL since it's the same worker
|
|
||||||
await redis.pexpire(redisKey, ttlMs);
|
|
||||||
logger.debug(
|
|
||||||
`Lock extended: ${lockKey} by ${
|
|
||||||
config.getRawConfig().gerbil.exit_node_name
|
|
||||||
}`
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
// Check if the existing lock is from this worker (reentrant behavior)
|
||||||
} catch (error) {
|
const existingValue = await redis.get(redisKey);
|
||||||
logger.error(`Failed to acquire lock ${lockKey}:`, error);
|
if (
|
||||||
return false;
|
existingValue &&
|
||||||
|
existingValue.startsWith(
|
||||||
|
`${config.getRawConfig().gerbil.exit_node_name}:`
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
// Extend the lock TTL since it's the same worker
|
||||||
|
await redis.pexpire(redisKey, ttlMs);
|
||||||
|
logger.debug(
|
||||||
|
`Lock extended: ${lockKey} by ${
|
||||||
|
config.getRawConfig().gerbil.exit_node_name
|
||||||
|
}`
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this isn't our last attempt, wait before retrying with exponential backoff
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
const delay = retryDelayMs * Math.pow(2, attempt);
|
||||||
|
logger.debug(
|
||||||
|
`Lock ${lockKey} not available, retrying in ${delay}ms (attempt ${attempt + 1}/${maxRetries})`
|
||||||
|
);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Failed to acquire lock ${lockKey} (attempt ${attempt + 1}/${maxRetries}):`, error);
|
||||||
|
// On error, still retry if we have attempts left
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
const delay = retryDelayMs * Math.pow(2, attempt);
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, delay));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.debug(
|
||||||
|
`Failed to acquire lock ${lockKey} after ${maxRetries} attempts`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -83,7 +83,8 @@ export const privateConfigSchema = z.object({
|
|||||||
flags: z
|
flags: z
|
||||||
.object({
|
.object({
|
||||||
enable_redis: z.boolean().optional().default(false),
|
enable_redis: z.boolean().optional().default(false),
|
||||||
use_pangolin_dns: z.boolean().optional().default(false)
|
use_pangolin_dns: z.boolean().optional().default(false),
|
||||||
|
use_org_only_idp: z.boolean().optional().default(false)
|
||||||
})
|
})
|
||||||
.optional()
|
.optional()
|
||||||
.prefault({}),
|
.prefault({}),
|
||||||
|
|||||||
@@ -573,6 +573,20 @@ class RedisManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async incr(key: string): Promise<number> {
|
||||||
|
if (!this.isRedisEnabled() || !this.writeClient) return 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await this.executeWithRetry(
|
||||||
|
() => this.writeClient!.incr(key),
|
||||||
|
"Redis INCR"
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Redis INCR error:", error);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async sadd(key: string, member: string): Promise<boolean> {
|
public async sadd(key: string, member: string): Promise<boolean> {
|
||||||
if (!this.isRedisEnabled() || !this.writeClient) return false;
|
if (!this.isRedisEnabled() || !this.writeClient) return false;
|
||||||
|
|
||||||
|
|||||||
@@ -456,11 +456,11 @@ export async function getTraefikConfig(
|
|||||||
// );
|
// );
|
||||||
} else if (resource.maintenanceModeType === "automatic") {
|
} else if (resource.maintenanceModeType === "automatic") {
|
||||||
showMaintenancePage = !hasHealthyServers;
|
showMaintenancePage = !hasHealthyServers;
|
||||||
if (showMaintenancePage) {
|
// if (showMaintenancePage) {
|
||||||
logger.warn(
|
// logger.warn(
|
||||||
`Resource ${resource.name} (${fullDomain}) has no healthy servers - showing maintenance page (AUTOMATIC mode)`
|
// `Resource ${resource.name} (${fullDomain}) has no healthy servers - showing maintenance page (AUTOMATIC mode)`
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,18 @@ export async function verifyValidSubscription(
|
|||||||
return next();
|
return next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const tier = await getOrgTierData(req.params.orgId);
|
const orgId = req.params.orgId || req.body.orgId || req.query.orgId || req.userOrgId;
|
||||||
|
|
||||||
|
if (!orgId) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
"Organization ID is required to verify subscription"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const tier = await getOrgTierData(orgId);
|
||||||
|
|
||||||
if (!tier.active) {
|
if (!tier.active) {
|
||||||
return next(
|
return next(
|
||||||
|
|||||||
@@ -436,18 +436,18 @@ authenticated.get(
|
|||||||
|
|
||||||
authenticated.post(
|
authenticated.post(
|
||||||
"/re-key/:clientId/regenerate-client-secret",
|
"/re-key/:clientId/regenerate-client-secret",
|
||||||
|
verifyClientAccess, // this is first to set the org id
|
||||||
verifyValidLicense,
|
verifyValidLicense,
|
||||||
verifyValidSubscription,
|
verifyValidSubscription,
|
||||||
verifyClientAccess,
|
|
||||||
verifyUserHasAction(ActionsEnum.reGenerateSecret),
|
verifyUserHasAction(ActionsEnum.reGenerateSecret),
|
||||||
reKey.reGenerateClientSecret
|
reKey.reGenerateClientSecret
|
||||||
);
|
);
|
||||||
|
|
||||||
authenticated.post(
|
authenticated.post(
|
||||||
"/re-key/:siteId/regenerate-site-secret",
|
"/re-key/:siteId/regenerate-site-secret",
|
||||||
|
verifySiteAccess, // this is first to set the org id
|
||||||
verifyValidLicense,
|
verifyValidLicense,
|
||||||
verifyValidSubscription,
|
verifyValidSubscription,
|
||||||
verifySiteAccess,
|
|
||||||
verifyUserHasAction(ActionsEnum.reGenerateSecret),
|
verifyUserHasAction(ActionsEnum.reGenerateSecret),
|
||||||
reKey.reGenerateSiteSecret
|
reKey.reGenerateSiteSecret
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ import * as logs from "#private/routers/auditLogs";
|
|||||||
import {
|
import {
|
||||||
verifyApiKeyHasAction,
|
verifyApiKeyHasAction,
|
||||||
verifyApiKeyIsRoot,
|
verifyApiKeyIsRoot,
|
||||||
verifyApiKeyOrgAccess
|
verifyApiKeyOrgAccess,
|
||||||
|
verifyApiKeyIdpAccess
|
||||||
} from "@server/middlewares";
|
} from "@server/middlewares";
|
||||||
import {
|
import {
|
||||||
verifyValidSubscription,
|
verifyValidSubscription,
|
||||||
@@ -31,6 +32,8 @@ import {
|
|||||||
authenticated as a
|
authenticated as a
|
||||||
} from "@server/routers/integration";
|
} from "@server/routers/integration";
|
||||||
import { logActionAudit } from "#private/middlewares";
|
import { logActionAudit } from "#private/middlewares";
|
||||||
|
import config from "#private/lib/config";
|
||||||
|
import { build } from "@server/build";
|
||||||
|
|
||||||
export const unauthenticated = ua;
|
export const unauthenticated = ua;
|
||||||
export const authenticated = a;
|
export const authenticated = a;
|
||||||
@@ -88,3 +91,49 @@ authenticated.get(
|
|||||||
logActionAudit(ActionsEnum.exportLogs),
|
logActionAudit(ActionsEnum.exportLogs),
|
||||||
logs.exportAccessAuditLogs
|
logs.exportAccessAuditLogs
|
||||||
);
|
);
|
||||||
|
|
||||||
|
authenticated.put(
|
||||||
|
"/org/:orgId/idp/oidc",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyApiKeyOrgAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.createIdp),
|
||||||
|
logActionAudit(ActionsEnum.createIdp),
|
||||||
|
orgIdp.createOrgOidcIdp
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/org/:orgId/idp/:idpId/oidc",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyApiKeyOrgAccess,
|
||||||
|
verifyApiKeyIdpAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.updateIdp),
|
||||||
|
logActionAudit(ActionsEnum.updateIdp),
|
||||||
|
orgIdp.updateOrgOidcIdp
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.delete(
|
||||||
|
"/org/:orgId/idp/:idpId",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyApiKeyOrgAccess,
|
||||||
|
verifyApiKeyIdpAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.deleteIdp),
|
||||||
|
logActionAudit(ActionsEnum.deleteIdp),
|
||||||
|
orgIdp.deleteOrgIdp
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.get(
|
||||||
|
"/org/:orgId/idp/:idpId",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyApiKeyOrgAccess,
|
||||||
|
verifyApiKeyIdpAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.getIdp),
|
||||||
|
orgIdp.getOrgIdp
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.get(
|
||||||
|
"/org/:orgId/idp",
|
||||||
|
verifyValidLicense,
|
||||||
|
verifyApiKeyOrgAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.listIdps),
|
||||||
|
orgIdp.listOrgIdps
|
||||||
|
);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import { eq, InferInsertModel } from "drizzle-orm";
|
|||||||
import { getOrgTierData } from "#private/lib/billing";
|
import { getOrgTierData } from "#private/lib/billing";
|
||||||
import { TierId } from "@server/lib/billing/tiers";
|
import { TierId } from "@server/lib/billing/tiers";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
|
import config from "@server/private/lib/config";
|
||||||
|
|
||||||
const paramsSchema = z.strictObject({
|
const paramsSchema = z.strictObject({
|
||||||
orgId: z.string()
|
orgId: z.string()
|
||||||
@@ -94,8 +95,10 @@ export async function upsertLoginPageBranding(
|
|||||||
typeof loginPageBranding
|
typeof loginPageBranding
|
||||||
>;
|
>;
|
||||||
|
|
||||||
if (build !== "saas") {
|
if (
|
||||||
// org branding settings are only considered in the saas build
|
build !== "saas" &&
|
||||||
|
!config.getRawPrivateConfig().flags.use_org_only_idp
|
||||||
|
) {
|
||||||
const { orgTitle, orgSubtitle, ...rest } = updateData;
|
const { orgTitle, orgSubtitle, ...rest } = updateData;
|
||||||
updateData = rest;
|
updateData = rest;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,22 +46,23 @@ const bodySchema = z.strictObject({
|
|||||||
roleMapping: z.string().optional()
|
roleMapping: z.string().optional()
|
||||||
});
|
});
|
||||||
|
|
||||||
// registry.registerPath({
|
registry.registerPath({
|
||||||
// method: "put",
|
method: "put",
|
||||||
// path: "/idp/oidc",
|
path: "/org/{orgId}/idp/oidc",
|
||||||
// description: "Create an OIDC IdP.",
|
description: "Create an OIDC IdP for a specific organization.",
|
||||||
// tags: [OpenAPITags.Idp],
|
tags: [OpenAPITags.Idp, OpenAPITags.Org],
|
||||||
// request: {
|
request: {
|
||||||
// body: {
|
params: paramsSchema,
|
||||||
// content: {
|
body: {
|
||||||
// "application/json": {
|
content: {
|
||||||
// schema: bodySchema
|
"application/json": {
|
||||||
// }
|
schema: bodySchema
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// },
|
}
|
||||||
// responses: {}
|
},
|
||||||
// });
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
export async function createOrgOidcIdp(
|
export async function createOrgOidcIdp(
|
||||||
req: Request,
|
req: Request,
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ const paramsSchema = z
|
|||||||
|
|
||||||
registry.registerPath({
|
registry.registerPath({
|
||||||
method: "delete",
|
method: "delete",
|
||||||
path: "/idp/{idpId}",
|
path: "/org/{orgId}/idp/{idpId}",
|
||||||
description: "Delete IDP.",
|
description: "Delete IDP for a specific organization.",
|
||||||
tags: [OpenAPITags.Idp],
|
tags: [OpenAPITags.Idp, OpenAPITags.Org],
|
||||||
request: {
|
request: {
|
||||||
params: paramsSchema
|
params: paramsSchema
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -48,16 +48,16 @@ async function query(idpId: number, orgId: string) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// registry.registerPath({
|
registry.registerPath({
|
||||||
// method: "get",
|
method: "get",
|
||||||
// path: "/idp/{idpId}",
|
path: "/org/:orgId/idp/:idpId",
|
||||||
// description: "Get an IDP by its IDP ID.",
|
description: "Get an IDP by its IDP ID for a specific organization.",
|
||||||
// tags: [OpenAPITags.Idp],
|
tags: [OpenAPITags.Idp, OpenAPITags.Org],
|
||||||
// request: {
|
request: {
|
||||||
// params: paramsSchema
|
params: paramsSchema
|
||||||
// },
|
},
|
||||||
// responses: {}
|
responses: {}
|
||||||
// });
|
});
|
||||||
|
|
||||||
export async function getOrgIdp(
|
export async function getOrgIdp(
|
||||||
req: Request,
|
req: Request,
|
||||||
|
|||||||
@@ -62,16 +62,17 @@ async function query(orgId: string, limit: number, offset: number) {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
// registry.registerPath({
|
registry.registerPath({
|
||||||
// method: "get",
|
method: "get",
|
||||||
// path: "/idp",
|
path: "/org/{orgId}/idp",
|
||||||
// description: "List all IDP in the system.",
|
description: "List all IDP for a specific organization.",
|
||||||
// tags: [OpenAPITags.Idp],
|
tags: [OpenAPITags.Idp, OpenAPITags.Org],
|
||||||
// request: {
|
request: {
|
||||||
// query: querySchema
|
query: querySchema,
|
||||||
// },
|
params: paramsSchema
|
||||||
// responses: {}
|
},
|
||||||
// });
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
export async function listOrgIdps(
|
export async function listOrgIdps(
|
||||||
req: Request,
|
req: Request,
|
||||||
|
|||||||
@@ -53,23 +53,23 @@ export type UpdateOrgIdpResponse = {
|
|||||||
idpId: number;
|
idpId: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
// registry.registerPath({
|
registry.registerPath({
|
||||||
// method: "post",
|
method: "post",
|
||||||
// path: "/idp/{idpId}/oidc",
|
path: "/org/{orgId}/idp/{idpId}/oidc",
|
||||||
// description: "Update an OIDC IdP.",
|
description: "Update an OIDC IdP for a specific organization.",
|
||||||
// tags: [OpenAPITags.Idp],
|
tags: [OpenAPITags.Idp, OpenAPITags.Org],
|
||||||
// request: {
|
request: {
|
||||||
// params: paramsSchema,
|
params: paramsSchema,
|
||||||
// body: {
|
body: {
|
||||||
// content: {
|
content: {
|
||||||
// "application/json": {
|
"application/json": {
|
||||||
// schema: bodySchema
|
schema: bodySchema
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// responses: {}
|
responses: {}
|
||||||
// });
|
});
|
||||||
|
|
||||||
export async function updateOrgOidcIdp(
|
export async function updateOrgOidcIdp(
|
||||||
req: Request,
|
req: Request,
|
||||||
|
|||||||
+126
-19
@@ -43,7 +43,8 @@ import {
|
|||||||
WSMessage,
|
WSMessage,
|
||||||
TokenPayload,
|
TokenPayload,
|
||||||
WebSocketRequest,
|
WebSocketRequest,
|
||||||
RedisMessage
|
RedisMessage,
|
||||||
|
SendMessageOptions
|
||||||
} from "@server/routers/ws";
|
} from "@server/routers/ws";
|
||||||
import { validateSessionToken } from "@server/auth/sessions/app";
|
import { validateSessionToken } from "@server/auth/sessions/app";
|
||||||
|
|
||||||
@@ -118,12 +119,21 @@ const processMessage = async (
|
|||||||
if (response.broadcast) {
|
if (response.broadcast) {
|
||||||
await broadcastToAllExcept(
|
await broadcastToAllExcept(
|
||||||
response.message,
|
response.message,
|
||||||
response.excludeSender ? clientId : undefined
|
response.excludeSender ? clientId : undefined,
|
||||||
|
response.options
|
||||||
);
|
);
|
||||||
} else if (response.targetClientId) {
|
} else if (response.targetClientId) {
|
||||||
await sendToClient(response.targetClientId, response.message);
|
await sendToClient(
|
||||||
|
response.targetClientId,
|
||||||
|
response.message,
|
||||||
|
response.options
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
ws.send(JSON.stringify(response.message));
|
await sendToClient(
|
||||||
|
clientId,
|
||||||
|
response.message,
|
||||||
|
response.options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -172,6 +182,9 @@ const REDIS_CHANNEL = "websocket_messages";
|
|||||||
// Client tracking map (local to this node)
|
// Client tracking map (local to this node)
|
||||||
const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
|
const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
|
||||||
|
|
||||||
|
// Config version tracking map (local to this node, resets on server restart)
|
||||||
|
const clientConfigVersions: Map<string, number> = new Map();
|
||||||
|
|
||||||
// Recovery tracking
|
// Recovery tracking
|
||||||
let isRedisRecoveryInProgress = false;
|
let isRedisRecoveryInProgress = false;
|
||||||
|
|
||||||
@@ -182,6 +195,8 @@ const getClientMapKey = (clientId: string) => clientId;
|
|||||||
const getConnectionsKey = (clientId: string) => `ws:connections:${clientId}`;
|
const getConnectionsKey = (clientId: string) => `ws:connections:${clientId}`;
|
||||||
const getNodeConnectionsKey = (nodeId: string, clientId: string) =>
|
const getNodeConnectionsKey = (nodeId: string, clientId: string) =>
|
||||||
`ws:node:${nodeId}:${clientId}`;
|
`ws:node:${nodeId}:${clientId}`;
|
||||||
|
const getConfigVersionKey = (clientId: string) =>
|
||||||
|
`ws:configVersion:${clientId}`;
|
||||||
|
|
||||||
// Initialize Redis subscription for cross-node messaging
|
// Initialize Redis subscription for cross-node messaging
|
||||||
const initializeRedisSubscription = async (): Promise<void> => {
|
const initializeRedisSubscription = async (): Promise<void> => {
|
||||||
@@ -377,17 +392,80 @@ const removeClient = async (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper to get the current config version for a client
|
||||||
|
const getClientConfigVersion = async (clientId: string): Promise<number> => {
|
||||||
|
// Try Redis first if available
|
||||||
|
if (redisManager.isRedisEnabled()) {
|
||||||
|
try {
|
||||||
|
const redisVersion = await redisManager.get(
|
||||||
|
getConfigVersionKey(clientId)
|
||||||
|
);
|
||||||
|
if (redisVersion !== null) {
|
||||||
|
const version = parseInt(redisVersion, 10);
|
||||||
|
// Sync local cache with Redis
|
||||||
|
clientConfigVersions.set(clientId, version);
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to get config version from Redis:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to local cache
|
||||||
|
return clientConfigVersions.get(clientId) || 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Helper to increment and get the new config version for a client
|
||||||
|
const incrementClientConfigVersion = async (
|
||||||
|
clientId: string
|
||||||
|
): Promise<number> => {
|
||||||
|
let newVersion: number;
|
||||||
|
|
||||||
|
if (redisManager.isRedisEnabled()) {
|
||||||
|
try {
|
||||||
|
// Use Redis INCR for atomic increment across nodes
|
||||||
|
newVersion = await redisManager.incr(getConfigVersionKey(clientId));
|
||||||
|
// Sync local cache
|
||||||
|
clientConfigVersions.set(clientId, newVersion);
|
||||||
|
return newVersion;
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Failed to increment config version in Redis:", error);
|
||||||
|
// Fall through to local increment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local increment
|
||||||
|
const currentVersion = clientConfigVersions.get(clientId) || 0;
|
||||||
|
newVersion = currentVersion + 1;
|
||||||
|
clientConfigVersions.set(clientId, newVersion);
|
||||||
|
return newVersion;
|
||||||
|
};
|
||||||
|
|
||||||
// Local message sending (within this node)
|
// Local message sending (within this node)
|
||||||
const sendToClientLocal = async (
|
const sendToClientLocal = async (
|
||||||
clientId: string,
|
clientId: string,
|
||||||
message: WSMessage
|
message: WSMessage,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
const mapKey = getClientMapKey(clientId);
|
const mapKey = getClientMapKey(clientId);
|
||||||
const clients = connectedClients.get(mapKey);
|
const clients = connectedClients.get(mapKey);
|
||||||
if (!clients || clients.length === 0) {
|
if (!clients || clients.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const messageString = JSON.stringify(message);
|
|
||||||
|
// Handle config version
|
||||||
|
let configVersion = await getClientConfigVersion(clientId);
|
||||||
|
if (options.incrementConfigVersion) {
|
||||||
|
configVersion = await incrementClientConfigVersion(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add config version to message
|
||||||
|
const messageWithVersion = {
|
||||||
|
...message,
|
||||||
|
configVersion
|
||||||
|
};
|
||||||
|
|
||||||
|
const messageString = JSON.stringify(messageWithVersion);
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
client.send(messageString);
|
client.send(messageString);
|
||||||
@@ -395,7 +473,7 @@ const sendToClientLocal = async (
|
|||||||
});
|
});
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`sendToClient: Message type ${message.type} sent to clientId ${clientId}`
|
`sendToClient: Message type ${message.type} sent to clientId ${clientId} (configVersion: ${configVersion})`
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -403,35 +481,60 @@ const sendToClientLocal = async (
|
|||||||
|
|
||||||
const broadcastToAllExceptLocal = async (
|
const broadcastToAllExceptLocal = async (
|
||||||
message: WSMessage,
|
message: WSMessage,
|
||||||
excludeClientId?: string
|
excludeClientId?: string,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
connectedClients.forEach((clients, mapKey) => {
|
for (const [mapKey, clients] of connectedClients.entries()) {
|
||||||
const [type, id] = mapKey.split(":");
|
const [type, id] = mapKey.split(":");
|
||||||
if (!(excludeClientId && id === excludeClientId)) {
|
const clientId = mapKey; // mapKey is the clientId
|
||||||
|
if (!(excludeClientId && clientId === excludeClientId)) {
|
||||||
|
// Handle config version per client
|
||||||
|
let configVersion = await getClientConfigVersion(clientId);
|
||||||
|
if (options.incrementConfigVersion) {
|
||||||
|
configVersion = await incrementClientConfigVersion(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add config version to message
|
||||||
|
const messageWithVersion = {
|
||||||
|
...message,
|
||||||
|
configVersion
|
||||||
|
};
|
||||||
|
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
client.send(JSON.stringify(message));
|
client.send(JSON.stringify(messageWithVersion));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Cross-node message sending (via Redis)
|
// Cross-node message sending (via Redis)
|
||||||
const sendToClient = async (
|
const sendToClient = async (
|
||||||
clientId: string,
|
clientId: string,
|
||||||
message: WSMessage
|
message: WSMessage,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
// Try to send locally first
|
// Try to send locally first
|
||||||
const localSent = await sendToClientLocal(clientId, message);
|
const localSent = await sendToClientLocal(clientId, message, options);
|
||||||
|
|
||||||
// Only send via Redis if the client is not connected locally and Redis is enabled
|
// Only send via Redis if the client is not connected locally and Redis is enabled
|
||||||
if (!localSent && redisManager.isRedisEnabled()) {
|
if (!localSent && redisManager.isRedisEnabled()) {
|
||||||
try {
|
try {
|
||||||
|
// If we need to increment config version, do it before sending via Redis
|
||||||
|
// so remote nodes send the correct version
|
||||||
|
let configVersion = await getClientConfigVersion(clientId);
|
||||||
|
if (options.incrementConfigVersion) {
|
||||||
|
configVersion = await incrementClientConfigVersion(clientId);
|
||||||
|
}
|
||||||
|
|
||||||
const redisMessage: RedisMessage = {
|
const redisMessage: RedisMessage = {
|
||||||
type: "direct",
|
type: "direct",
|
||||||
targetClientId: clientId,
|
targetClientId: clientId,
|
||||||
message,
|
message: {
|
||||||
|
...message,
|
||||||
|
configVersion
|
||||||
|
},
|
||||||
fromNodeId: NODE_ID
|
fromNodeId: NODE_ID
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -458,19 +561,22 @@ const sendToClient = async (
|
|||||||
|
|
||||||
const broadcastToAllExcept = async (
|
const broadcastToAllExcept = async (
|
||||||
message: WSMessage,
|
message: WSMessage,
|
||||||
excludeClientId?: string
|
excludeClientId?: string,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
// Broadcast locally
|
// Broadcast locally
|
||||||
await broadcastToAllExceptLocal(message, excludeClientId);
|
await broadcastToAllExceptLocal(message, excludeClientId, options);
|
||||||
|
|
||||||
// If Redis is enabled, also broadcast via Redis pub/sub to other nodes
|
// If Redis is enabled, also broadcast via Redis pub/sub to other nodes
|
||||||
|
// Note: For broadcasts, we include the options so remote nodes can handle versioning
|
||||||
if (redisManager.isRedisEnabled()) {
|
if (redisManager.isRedisEnabled()) {
|
||||||
try {
|
try {
|
||||||
const redisMessage: RedisMessage = {
|
const redisMessage: RedisMessage = {
|
||||||
type: "broadcast",
|
type: "broadcast",
|
||||||
excludeClientId,
|
excludeClientId,
|
||||||
message,
|
message,
|
||||||
fromNodeId: NODE_ID
|
fromNodeId: NODE_ID,
|
||||||
|
options
|
||||||
};
|
};
|
||||||
|
|
||||||
await redisManager.publish(
|
await redisManager.publish(
|
||||||
@@ -936,5 +1042,6 @@ export {
|
|||||||
getActiveNodes,
|
getActiveNodes,
|
||||||
disconnectClient,
|
disconnectClient,
|
||||||
NODE_ID,
|
NODE_ID,
|
||||||
cleanup
|
cleanup,
|
||||||
|
getClientConfigVersion
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,4 +16,4 @@ export * from "./checkResourceSession";
|
|||||||
export * from "./securityKey";
|
export * from "./securityKey";
|
||||||
export * from "./startDeviceWebAuth";
|
export * from "./startDeviceWebAuth";
|
||||||
export * from "./verifyDeviceWebAuth";
|
export * from "./verifyDeviceWebAuth";
|
||||||
export * from "./pollDeviceWebAuth";
|
export * from "./pollDeviceWebAuth";
|
||||||
@@ -49,27 +49,43 @@ const auditLogBuffer: Array<{
|
|||||||
|
|
||||||
const BATCH_SIZE = 100; // Write to DB every 100 logs
|
const BATCH_SIZE = 100; // Write to DB every 100 logs
|
||||||
const BATCH_INTERVAL_MS = 5000; // Or every 5 seconds, whichever comes first
|
const BATCH_INTERVAL_MS = 5000; // Or every 5 seconds, whichever comes first
|
||||||
|
const MAX_BUFFER_SIZE = 10000; // Prevent unbounded memory growth
|
||||||
let flushTimer: NodeJS.Timeout | null = null;
|
let flushTimer: NodeJS.Timeout | null = null;
|
||||||
|
let isFlushInProgress = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Flush buffered logs to database
|
* Flush buffered logs to database
|
||||||
*/
|
*/
|
||||||
async function flushAuditLogs() {
|
async function flushAuditLogs() {
|
||||||
if (auditLogBuffer.length === 0) {
|
if (auditLogBuffer.length === 0 || isFlushInProgress) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isFlushInProgress = true;
|
||||||
|
|
||||||
// Take all current logs and clear buffer
|
// Take all current logs and clear buffer
|
||||||
const logsToWrite = auditLogBuffer.splice(0, auditLogBuffer.length);
|
const logsToWrite = auditLogBuffer.splice(0, auditLogBuffer.length);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Batch insert all logs at once
|
// Batch insert logs in groups of 25 to avoid overwhelming the database
|
||||||
await db.insert(requestAuditLog).values(logsToWrite);
|
const BATCH_DB_SIZE = 25;
|
||||||
|
for (let i = 0; i < logsToWrite.length; i += BATCH_DB_SIZE) {
|
||||||
|
const batch = logsToWrite.slice(i, i + BATCH_DB_SIZE);
|
||||||
|
await db.insert(requestAuditLog).values(batch);
|
||||||
|
}
|
||||||
logger.debug(`Flushed ${logsToWrite.length} audit logs to database`);
|
logger.debug(`Flushed ${logsToWrite.length} audit logs to database`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error flushing audit logs:", error);
|
logger.error("Error flushing audit logs:", error);
|
||||||
// On error, we lose these logs - consider a fallback strategy if needed
|
// On error, we lose these logs - consider a fallback strategy if needed
|
||||||
// (e.g., write to file, or put back in buffer with retry limit)
|
// (e.g., write to file, or put back in buffer with retry limit)
|
||||||
|
} finally {
|
||||||
|
isFlushInProgress = false;
|
||||||
|
// If buffer filled up while we were flushing, flush again
|
||||||
|
if (auditLogBuffer.length >= BATCH_SIZE) {
|
||||||
|
flushAuditLogs().catch((err) =>
|
||||||
|
logger.error("Error in follow-up flush:", err)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +111,10 @@ export async function shutdownAuditLogger() {
|
|||||||
clearTimeout(flushTimer);
|
clearTimeout(flushTimer);
|
||||||
flushTimer = null;
|
flushTimer = null;
|
||||||
}
|
}
|
||||||
|
// Force flush even if one is in progress by waiting and retrying
|
||||||
|
while (isFlushInProgress) {
|
||||||
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||||
|
}
|
||||||
await flushAuditLogs();
|
await flushAuditLogs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,6 +232,14 @@ export async function logRequestAudit(
|
|||||||
? stripPortFromHost(body.requestIp)
|
? stripPortFromHost(body.requestIp)
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
// Prevent unbounded buffer growth - drop oldest entries if buffer is too large
|
||||||
|
if (auditLogBuffer.length >= MAX_BUFFER_SIZE) {
|
||||||
|
const dropped = auditLogBuffer.splice(0, BATCH_SIZE);
|
||||||
|
logger.warn(
|
||||||
|
`Audit log buffer exceeded max size (${MAX_BUFFER_SIZE}), dropped ${dropped.length} oldest entries`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Add to buffer instead of writing directly to DB
|
// Add to buffer instead of writing directly to DB
|
||||||
auditLogBuffer.push({
|
auditLogBuffer.push({
|
||||||
timestamp,
|
timestamp,
|
||||||
|
|||||||
@@ -1035,14 +1035,25 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
|||||||
logger.debug(`Normalized pattern parts: [${patternParts.join(", ")}]`);
|
logger.debug(`Normalized pattern parts: [${patternParts.join(", ")}]`);
|
||||||
logger.debug(`Normalized path parts: [${pathParts.join(", ")}]`);
|
logger.debug(`Normalized path parts: [${pathParts.join(", ")}]`);
|
||||||
|
|
||||||
|
// Maximum recursion depth to prevent stack overflow and memory issues
|
||||||
|
const MAX_RECURSION_DEPTH = 100;
|
||||||
|
|
||||||
// Recursive function to try different wildcard matches
|
// Recursive function to try different wildcard matches
|
||||||
function matchSegments(patternIndex: number, pathIndex: number): boolean {
|
function matchSegments(patternIndex: number, pathIndex: number, depth: number = 0): boolean {
|
||||||
const indent = " ".repeat(pathIndex); // Indent based on recursion depth
|
// Check recursion depth limit
|
||||||
|
if (depth > MAX_RECURSION_DEPTH) {
|
||||||
|
logger.warn(
|
||||||
|
`Path matching exceeded maximum recursion depth (${MAX_RECURSION_DEPTH}) for pattern "${pattern}" and path "${path}"`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const indent = " ".repeat(depth); // Indent based on recursion depth
|
||||||
const currentPatternPart = patternParts[patternIndex];
|
const currentPatternPart = patternParts[patternIndex];
|
||||||
const currentPathPart = pathParts[pathIndex];
|
const currentPathPart = pathParts[pathIndex];
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Checking patternIndex=${patternIndex} (${currentPatternPart || "END"}) vs pathIndex=${pathIndex} (${currentPathPart || "END"})`
|
`${indent}Checking patternIndex=${patternIndex} (${currentPatternPart || "END"}) vs pathIndex=${pathIndex} (${currentPathPart || "END"}) [depth=${depth}]`
|
||||||
);
|
);
|
||||||
|
|
||||||
// If we've consumed all pattern parts, we should have consumed all path parts
|
// If we've consumed all pattern parts, we should have consumed all path parts
|
||||||
@@ -1075,7 +1086,7 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Trying to skip wildcard (consume 0 segments)`
|
`${indent}Trying to skip wildcard (consume 0 segments)`
|
||||||
);
|
);
|
||||||
if (matchSegments(patternIndex + 1, pathIndex)) {
|
if (matchSegments(patternIndex + 1, pathIndex, depth + 1)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Successfully matched by skipping wildcard`
|
`${indent}Successfully matched by skipping wildcard`
|
||||||
);
|
);
|
||||||
@@ -1086,7 +1097,7 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Trying to consume segment "${currentPathPart}" for wildcard`
|
`${indent}Trying to consume segment "${currentPathPart}" for wildcard`
|
||||||
);
|
);
|
||||||
if (matchSegments(patternIndex, pathIndex + 1)) {
|
if (matchSegments(patternIndex, pathIndex + 1, depth + 1)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Successfully matched by consuming segment for wildcard`
|
`${indent}Successfully matched by consuming segment for wildcard`
|
||||||
);
|
);
|
||||||
@@ -1114,7 +1125,7 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
`${indent}Segment with wildcard matches: "${currentPatternPart}" matches "${currentPathPart}"`
|
`${indent}Segment with wildcard matches: "${currentPatternPart}" matches "${currentPathPart}"`
|
||||||
);
|
);
|
||||||
return matchSegments(patternIndex + 1, pathIndex + 1);
|
return matchSegments(patternIndex + 1, pathIndex + 1, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
@@ -1135,10 +1146,10 @@ export function isPathAllowed(pattern: string, path: string): boolean {
|
|||||||
`${indent}Segments match: "${currentPatternPart}" = "${currentPathPart}"`
|
`${indent}Segments match: "${currentPatternPart}" = "${currentPathPart}"`
|
||||||
);
|
);
|
||||||
// Move to next segments in both pattern and path
|
// Move to next segments in both pattern and path
|
||||||
return matchSegments(patternIndex + 1, pathIndex + 1);
|
return matchSegments(patternIndex + 1, pathIndex + 1, depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = matchSegments(0, 0);
|
const result = matchSegments(0, 0, 0);
|
||||||
logger.debug(`Final result: ${result}`);
|
logger.debug(`Final result: ${result}`);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { clients } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
import { rebuildClientAssociationsFromClient } from "@server/lib/rebuildClientAssociations";
|
||||||
|
import { sendTerminateClient } from "./terminate";
|
||||||
|
|
||||||
|
const archiveClientSchema = z.strictObject({
|
||||||
|
clientId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerPath({
|
||||||
|
method: "post",
|
||||||
|
path: "/client/{clientId}/archive",
|
||||||
|
description: "Archive a client by its client ID.",
|
||||||
|
tags: [OpenAPITags.Client],
|
||||||
|
request: {
|
||||||
|
params: archiveClientSchema
|
||||||
|
},
|
||||||
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function archiveClient(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = archiveClientSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { clientId } = parsedParams.data;
|
||||||
|
|
||||||
|
// Check if client exists
|
||||||
|
const [client] = await db
|
||||||
|
.select()
|
||||||
|
.from(clients)
|
||||||
|
.where(eq(clients.clientId, clientId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!client) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Client with ID ${clientId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.archived) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`Client with ID ${clientId} is already archived`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.transaction(async (trx) => {
|
||||||
|
// Archive the client
|
||||||
|
await trx
|
||||||
|
.update(clients)
|
||||||
|
.set({ archived: true })
|
||||||
|
.where(eq(clients.clientId, clientId));
|
||||||
|
|
||||||
|
// Rebuild associations to clean up related data
|
||||||
|
await rebuildClientAssociationsFromClient(client, trx);
|
||||||
|
|
||||||
|
// Send terminate signal if there's an associated OLM
|
||||||
|
if (client.olmId) {
|
||||||
|
await sendTerminateClient(client.clientId, client.olmId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Client archived successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to archive client"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { clients } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
import { sendTerminateClient } from "./terminate";
|
||||||
|
|
||||||
|
const blockClientSchema = z.strictObject({
|
||||||
|
clientId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerPath({
|
||||||
|
method: "post",
|
||||||
|
path: "/client/{clientId}/block",
|
||||||
|
description: "Block a client by its client ID.",
|
||||||
|
tags: [OpenAPITags.Client],
|
||||||
|
request: {
|
||||||
|
params: blockClientSchema
|
||||||
|
},
|
||||||
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function blockClient(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = blockClientSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { clientId } = parsedParams.data;
|
||||||
|
|
||||||
|
// Check if client exists
|
||||||
|
const [client] = await db
|
||||||
|
.select()
|
||||||
|
.from(clients)
|
||||||
|
.where(eq(clients.clientId, clientId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!client) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Client with ID ${clientId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (client.blocked) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`Client with ID ${clientId} is already blocked`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await db.transaction(async (trx) => {
|
||||||
|
// Block the client
|
||||||
|
await trx
|
||||||
|
.update(clients)
|
||||||
|
.set({ blocked: true })
|
||||||
|
.where(eq(clients.clientId, clientId));
|
||||||
|
|
||||||
|
// Send terminate signal if there's an associated OLM and it's connected
|
||||||
|
if (client.olmId && client.online) {
|
||||||
|
await sendTerminateClient(client.clientId, client.olmId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Client blocked successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to block client"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,11 +60,12 @@ export async function deleteClient(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only allow deletion of machine clients (clients without userId)
|
||||||
if (client.userId) {
|
if (client.userId) {
|
||||||
return next(
|
return next(
|
||||||
createHttpError(
|
createHttpError(
|
||||||
HttpCode.BAD_REQUEST,
|
HttpCode.BAD_REQUEST,
|
||||||
`Cannot delete a user client with this endpoint`
|
`Cannot delete a user client. User clients must be archived instead.`
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
export * from "./pickClientDefaults";
|
export * from "./pickClientDefaults";
|
||||||
export * from "./createClient";
|
export * from "./createClient";
|
||||||
export * from "./deleteClient";
|
export * from "./deleteClient";
|
||||||
|
export * from "./archiveClient";
|
||||||
|
export * from "./unarchiveClient";
|
||||||
|
export * from "./blockClient";
|
||||||
|
export * from "./unblockClient";
|
||||||
export * from "./listClients";
|
export * from "./listClients";
|
||||||
export * from "./updateClient";
|
export * from "./updateClient";
|
||||||
export * from "./getClient";
|
export * from "./getClient";
|
||||||
|
|||||||
@@ -136,7 +136,10 @@ function queryClients(
|
|||||||
username: users.username,
|
username: users.username,
|
||||||
userEmail: users.email,
|
userEmail: users.email,
|
||||||
niceId: clients.niceId,
|
niceId: clients.niceId,
|
||||||
agent: olms.agent
|
agent: olms.agent,
|
||||||
|
olmArchived: olms.archived,
|
||||||
|
archived: clients.archived,
|
||||||
|
blocked: clients.blocked
|
||||||
})
|
})
|
||||||
.from(clients)
|
.from(clients)
|
||||||
.leftJoin(orgs, eq(clients.orgId, orgs.orgId))
|
.leftJoin(orgs, eq(clients.orgId, orgs.orgId))
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export async function addTargets(newtId: string, targets: SubnetProxyTarget[]) {
|
|||||||
await sendToClient(newtId, {
|
await sendToClient(newtId, {
|
||||||
type: `newt/wg/targets/add`,
|
type: `newt/wg/targets/add`,
|
||||||
data: batches[i]
|
data: batches[i]
|
||||||
});
|
}, { incrementConfigVersion: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ export async function removeTargets(
|
|||||||
await sendToClient(newtId, {
|
await sendToClient(newtId, {
|
||||||
type: `newt/wg/targets/remove`,
|
type: `newt/wg/targets/remove`,
|
||||||
data: batches[i]
|
data: batches[i]
|
||||||
});
|
},{ incrementConfigVersion: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ export async function updateTargets(
|
|||||||
oldTargets: oldBatches[i] || [],
|
oldTargets: oldBatches[i] || [],
|
||||||
newTargets: newBatches[i] || []
|
newTargets: newBatches[i] || []
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ export async function addPeerData(
|
|||||||
remoteSubnets: remoteSubnets,
|
remoteSubnets: remoteSubnets,
|
||||||
aliases: aliases
|
aliases: aliases
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ export async function removePeerData(
|
|||||||
remoteSubnets: remoteSubnets,
|
remoteSubnets: remoteSubnets,
|
||||||
aliases: aliases
|
aliases: aliases
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ export async function updatePeerData(
|
|||||||
...remoteSubnets,
|
...remoteSubnets,
|
||||||
...aliases
|
...aliases
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { clients } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
|
||||||
|
const unarchiveClientSchema = z.strictObject({
|
||||||
|
clientId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerPath({
|
||||||
|
method: "post",
|
||||||
|
path: "/client/{clientId}/unarchive",
|
||||||
|
description: "Unarchive a client by its client ID.",
|
||||||
|
tags: [OpenAPITags.Client],
|
||||||
|
request: {
|
||||||
|
params: unarchiveClientSchema
|
||||||
|
},
|
||||||
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function unarchiveClient(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = unarchiveClientSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { clientId } = parsedParams.data;
|
||||||
|
|
||||||
|
// Check if client exists
|
||||||
|
const [client] = await db
|
||||||
|
.select()
|
||||||
|
.from(clients)
|
||||||
|
.where(eq(clients.clientId, clientId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!client) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Client with ID ${clientId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!client.archived) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`Client with ID ${clientId} is not archived`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unarchive the client
|
||||||
|
await db
|
||||||
|
.update(clients)
|
||||||
|
.set({ archived: false })
|
||||||
|
.where(eq(clients.clientId, clientId));
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Client unarchived successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to unarchive client"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { Request, Response, NextFunction } from "express";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { clients } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import { OpenAPITags, registry } from "@server/openApi";
|
||||||
|
|
||||||
|
const unblockClientSchema = z.strictObject({
|
||||||
|
clientId: z.string().transform(Number).pipe(z.int().positive())
|
||||||
|
});
|
||||||
|
|
||||||
|
registry.registerPath({
|
||||||
|
method: "post",
|
||||||
|
path: "/client/{clientId}/unblock",
|
||||||
|
description: "Unblock a client by its client ID.",
|
||||||
|
tags: [OpenAPITags.Client],
|
||||||
|
request: {
|
||||||
|
params: unblockClientSchema
|
||||||
|
},
|
||||||
|
responses: {}
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function unblockClient(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = unblockClientSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { clientId } = parsedParams.data;
|
||||||
|
|
||||||
|
// Check if client exists
|
||||||
|
const [client] = await db
|
||||||
|
.select()
|
||||||
|
.from(clients)
|
||||||
|
.where(eq(clients.clientId, clientId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!client) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`Client with ID ${clientId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!client.blocked) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`Client with ID ${clientId} is not blocked`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unblock the client
|
||||||
|
await db
|
||||||
|
.update(clients)
|
||||||
|
.set({ blocked: false })
|
||||||
|
.where(eq(clients.clientId, clientId));
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Client unblocked successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to unblock client"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -174,6 +174,38 @@ authenticated.delete(
|
|||||||
client.deleteClient
|
client.deleteClient
|
||||||
);
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/archive",
|
||||||
|
verifyClientAccess,
|
||||||
|
verifyUserHasAction(ActionsEnum.archiveClient),
|
||||||
|
logActionAudit(ActionsEnum.archiveClient),
|
||||||
|
client.archiveClient
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/unarchive",
|
||||||
|
verifyClientAccess,
|
||||||
|
verifyUserHasAction(ActionsEnum.unarchiveClient),
|
||||||
|
logActionAudit(ActionsEnum.unarchiveClient),
|
||||||
|
client.unarchiveClient
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/block",
|
||||||
|
verifyClientAccess,
|
||||||
|
verifyUserHasAction(ActionsEnum.blockClient),
|
||||||
|
logActionAudit(ActionsEnum.blockClient),
|
||||||
|
client.blockClient
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/unblock",
|
||||||
|
verifyClientAccess,
|
||||||
|
verifyUserHasAction(ActionsEnum.unblockClient),
|
||||||
|
logActionAudit(ActionsEnum.unblockClient),
|
||||||
|
client.unblockClient
|
||||||
|
);
|
||||||
|
|
||||||
authenticated.post(
|
authenticated.post(
|
||||||
"/client/:clientId",
|
"/client/:clientId",
|
||||||
verifyClientAccess, // this will check if the user has access to the client
|
verifyClientAccess, // this will check if the user has access to the client
|
||||||
@@ -808,11 +840,18 @@ authenticated.put("/user/:userId/olm", verifyIsLoggedInUser, olm.createUserOlm);
|
|||||||
|
|
||||||
authenticated.get("/user/:userId/olms", verifyIsLoggedInUser, olm.listUserOlms);
|
authenticated.get("/user/:userId/olms", verifyIsLoggedInUser, olm.listUserOlms);
|
||||||
|
|
||||||
authenticated.delete(
|
authenticated.post(
|
||||||
"/user/:userId/olm/:olmId",
|
"/user/:userId/olm/:olmId/archive",
|
||||||
verifyIsLoggedInUser,
|
verifyIsLoggedInUser,
|
||||||
verifyOlmAccess,
|
verifyOlmAccess,
|
||||||
olm.deleteUserOlm
|
olm.archiveUserOlm
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/user/:userId/olm/:olmId/unarchive",
|
||||||
|
verifyIsLoggedInUser,
|
||||||
|
verifyOlmAccess,
|
||||||
|
olm.unarchiveUserOlm
|
||||||
);
|
);
|
||||||
|
|
||||||
authenticated.get(
|
authenticated.get(
|
||||||
|
|||||||
@@ -751,9 +751,10 @@ authenticated.post(
|
|||||||
);
|
);
|
||||||
|
|
||||||
authenticated.get(
|
authenticated.get(
|
||||||
"/idp",
|
"/idp", // no guards on this because anyone can list idps for login purposes
|
||||||
verifyApiKeyIsRoot,
|
// we do the same for the external api
|
||||||
verifyApiKeyHasAction(ActionsEnum.listIdps),
|
// verifyApiKeyIsRoot,
|
||||||
|
// verifyApiKeyHasAction(ActionsEnum.listIdps),
|
||||||
idp.listIdps
|
idp.listIdps
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -842,6 +843,38 @@ authenticated.delete(
|
|||||||
client.deleteClient
|
client.deleteClient
|
||||||
);
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/archive",
|
||||||
|
verifyApiKeyClientAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.archiveClient),
|
||||||
|
logActionAudit(ActionsEnum.archiveClient),
|
||||||
|
client.archiveClient
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/unarchive",
|
||||||
|
verifyApiKeyClientAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.unarchiveClient),
|
||||||
|
logActionAudit(ActionsEnum.unarchiveClient),
|
||||||
|
client.unarchiveClient
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/block",
|
||||||
|
verifyApiKeyClientAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.blockClient),
|
||||||
|
logActionAudit(ActionsEnum.blockClient),
|
||||||
|
client.blockClient
|
||||||
|
);
|
||||||
|
|
||||||
|
authenticated.post(
|
||||||
|
"/client/:clientId/unblock",
|
||||||
|
verifyApiKeyClientAccess,
|
||||||
|
verifyApiKeyHasAction(ActionsEnum.unblockClient),
|
||||||
|
logActionAudit(ActionsEnum.unblockClient),
|
||||||
|
client.unblockClient
|
||||||
|
);
|
||||||
|
|
||||||
authenticated.post(
|
authenticated.post(
|
||||||
"/client/:clientId",
|
"/client/:clientId",
|
||||||
verifyApiKeyClientAccess,
|
verifyApiKeyClientAccess,
|
||||||
|
|||||||
@@ -0,0 +1,278 @@
|
|||||||
|
import { clients, clientSiteResourcesAssociationsCache, clientSitesAssociationsCache, db, ExitNode, resources, Site, siteResources, targetHealthCheck, targets } from "@server/db";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { initPeerAddHandshake, updatePeer } from "../olm/peers";
|
||||||
|
import { eq, and } from "drizzle-orm";
|
||||||
|
import config from "@server/lib/config";
|
||||||
|
import { generateSubnetProxyTargets, SubnetProxyTarget } from "@server/lib/ip";
|
||||||
|
|
||||||
|
export async function buildClientConfigurationForNewtClient(
|
||||||
|
site: Site,
|
||||||
|
exitNode?: ExitNode
|
||||||
|
) {
|
||||||
|
const siteId = site.siteId;
|
||||||
|
|
||||||
|
// Get all clients connected to this site
|
||||||
|
const clientsRes = await db
|
||||||
|
.select()
|
||||||
|
.from(clients)
|
||||||
|
.innerJoin(
|
||||||
|
clientSitesAssociationsCache,
|
||||||
|
eq(clients.clientId, clientSitesAssociationsCache.clientId)
|
||||||
|
)
|
||||||
|
.where(eq(clientSitesAssociationsCache.siteId, siteId));
|
||||||
|
|
||||||
|
let peers: Array<{
|
||||||
|
publicKey: string;
|
||||||
|
allowedIps: string[];
|
||||||
|
endpoint?: string;
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
if (site.publicKey && site.endpoint && exitNode) {
|
||||||
|
// Prepare peers data for the response
|
||||||
|
peers = await Promise.all(
|
||||||
|
clientsRes
|
||||||
|
.filter((client) => {
|
||||||
|
if (!client.clients.pubKey) {
|
||||||
|
logger.warn(
|
||||||
|
`Client ${client.clients.clientId} has no public key, skipping`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!client.clients.subnet) {
|
||||||
|
logger.warn(
|
||||||
|
`Client ${client.clients.clientId} has no subnet, skipping`
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
})
|
||||||
|
.map(async (client) => {
|
||||||
|
// Add or update this peer on the olm if it is connected
|
||||||
|
|
||||||
|
// const allSiteResources = await db // only get the site resources that this client has access to
|
||||||
|
// .select()
|
||||||
|
// .from(siteResources)
|
||||||
|
// .innerJoin(
|
||||||
|
// clientSiteResourcesAssociationsCache,
|
||||||
|
// eq(
|
||||||
|
// siteResources.siteResourceId,
|
||||||
|
// clientSiteResourcesAssociationsCache.siteResourceId
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// .where(
|
||||||
|
// and(
|
||||||
|
// eq(siteResources.siteId, site.siteId),
|
||||||
|
// eq(
|
||||||
|
// clientSiteResourcesAssociationsCache.clientId,
|
||||||
|
// client.clients.clientId
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
|
||||||
|
// update the peer info on the olm
|
||||||
|
// if the peer has not been added yet this will be a no-op
|
||||||
|
await updatePeer(client.clients.clientId, {
|
||||||
|
siteId: site.siteId,
|
||||||
|
endpoint: site.endpoint!,
|
||||||
|
relayEndpoint: `${exitNode.endpoint}:${config.getRawConfig().gerbil.clients_start_port}`,
|
||||||
|
publicKey: site.publicKey!,
|
||||||
|
serverIP: site.address,
|
||||||
|
serverPort: site.listenPort
|
||||||
|
// remoteSubnets: generateRemoteSubnets(
|
||||||
|
// allSiteResources.map(
|
||||||
|
// ({ siteResources }) => siteResources
|
||||||
|
// )
|
||||||
|
// ),
|
||||||
|
// aliases: generateAliasConfig(
|
||||||
|
// allSiteResources.map(
|
||||||
|
// ({ siteResources }) => siteResources
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
});
|
||||||
|
|
||||||
|
// also trigger the peer add handshake in case the peer was not already added to the olm and we need to hole punch
|
||||||
|
// if it has already been added this will be a no-op
|
||||||
|
await initPeerAddHandshake(
|
||||||
|
// this will kick off the add peer process for the client
|
||||||
|
client.clients.clientId,
|
||||||
|
{
|
||||||
|
siteId,
|
||||||
|
exitNode: {
|
||||||
|
publicKey: exitNode.publicKey,
|
||||||
|
endpoint: exitNode.endpoint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
publicKey: client.clients.pubKey!,
|
||||||
|
allowedIps: [
|
||||||
|
`${client.clients.subnet.split("/")[0]}/32`
|
||||||
|
], // we want to only allow from that client
|
||||||
|
endpoint: client.clientSitesAssociationsCache.isRelayed
|
||||||
|
? ""
|
||||||
|
: client.clientSitesAssociationsCache.endpoint! // if its relayed it should be localhost
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Filter out any null values from peers that didn't have an olm
|
||||||
|
const validPeers = peers.filter((peer) => peer !== null);
|
||||||
|
|
||||||
|
// Get all enabled site resources for this site
|
||||||
|
const allSiteResources = await db
|
||||||
|
.select()
|
||||||
|
.from(siteResources)
|
||||||
|
.where(eq(siteResources.siteId, siteId));
|
||||||
|
|
||||||
|
const targetsToSend: SubnetProxyTarget[] = [];
|
||||||
|
|
||||||
|
for (const resource of allSiteResources) {
|
||||||
|
// Get clients associated with this specific resource
|
||||||
|
const resourceClients = await db
|
||||||
|
.select({
|
||||||
|
clientId: clients.clientId,
|
||||||
|
pubKey: clients.pubKey,
|
||||||
|
subnet: clients.subnet
|
||||||
|
})
|
||||||
|
.from(clients)
|
||||||
|
.innerJoin(
|
||||||
|
clientSiteResourcesAssociationsCache,
|
||||||
|
eq(
|
||||||
|
clients.clientId,
|
||||||
|
clientSiteResourcesAssociationsCache.clientId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.siteResourceId,
|
||||||
|
resource.siteResourceId
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
const resourceTargets = generateSubnetProxyTargets(
|
||||||
|
resource,
|
||||||
|
resourceClients
|
||||||
|
);
|
||||||
|
|
||||||
|
targetsToSend.push(...resourceTargets);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
peers: validPeers,
|
||||||
|
targets: targetsToSend
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function buildTargetConfigurationForNewtClient(siteId: number) {
|
||||||
|
// Get all enabled targets with their resource protocol information
|
||||||
|
const allTargets = await db
|
||||||
|
.select({
|
||||||
|
resourceId: targets.resourceId,
|
||||||
|
targetId: targets.targetId,
|
||||||
|
ip: targets.ip,
|
||||||
|
method: targets.method,
|
||||||
|
port: targets.port,
|
||||||
|
internalPort: targets.internalPort,
|
||||||
|
enabled: targets.enabled,
|
||||||
|
protocol: resources.protocol,
|
||||||
|
hcEnabled: targetHealthCheck.hcEnabled,
|
||||||
|
hcPath: targetHealthCheck.hcPath,
|
||||||
|
hcScheme: targetHealthCheck.hcScheme,
|
||||||
|
hcMode: targetHealthCheck.hcMode,
|
||||||
|
hcHostname: targetHealthCheck.hcHostname,
|
||||||
|
hcPort: targetHealthCheck.hcPort,
|
||||||
|
hcInterval: targetHealthCheck.hcInterval,
|
||||||
|
hcUnhealthyInterval: targetHealthCheck.hcUnhealthyInterval,
|
||||||
|
hcTimeout: targetHealthCheck.hcTimeout,
|
||||||
|
hcHeaders: targetHealthCheck.hcHeaders,
|
||||||
|
hcMethod: targetHealthCheck.hcMethod,
|
||||||
|
hcTlsServerName: targetHealthCheck.hcTlsServerName
|
||||||
|
})
|
||||||
|
.from(targets)
|
||||||
|
.innerJoin(resources, eq(targets.resourceId, resources.resourceId))
|
||||||
|
.leftJoin(
|
||||||
|
targetHealthCheck,
|
||||||
|
eq(targets.targetId, targetHealthCheck.targetId)
|
||||||
|
)
|
||||||
|
.where(and(eq(targets.siteId, siteId), eq(targets.enabled, true)));
|
||||||
|
|
||||||
|
const { tcpTargets, udpTargets } = allTargets.reduce(
|
||||||
|
(acc, target) => {
|
||||||
|
// Filter out invalid targets
|
||||||
|
if (!target.internalPort || !target.ip || !target.port) {
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Format target into string
|
||||||
|
const formattedTarget = `${target.internalPort}:${target.ip}:${target.port}`;
|
||||||
|
|
||||||
|
// Add to the appropriate protocol array
|
||||||
|
if (target.protocol === "tcp") {
|
||||||
|
acc.tcpTargets.push(formattedTarget);
|
||||||
|
} else {
|
||||||
|
acc.udpTargets.push(formattedTarget);
|
||||||
|
}
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{ tcpTargets: [] as string[], udpTargets: [] as string[] }
|
||||||
|
);
|
||||||
|
|
||||||
|
const healthCheckTargets = allTargets.map((target) => {
|
||||||
|
// make sure the stuff is defined
|
||||||
|
if (
|
||||||
|
!target.hcPath ||
|
||||||
|
!target.hcHostname ||
|
||||||
|
!target.hcPort ||
|
||||||
|
!target.hcInterval ||
|
||||||
|
!target.hcMethod
|
||||||
|
) {
|
||||||
|
logger.debug(
|
||||||
|
`Skipping target ${target.targetId} due to missing health check fields`
|
||||||
|
);
|
||||||
|
return null; // Skip targets with missing health check fields
|
||||||
|
}
|
||||||
|
|
||||||
|
// parse headers
|
||||||
|
const hcHeadersParse = target.hcHeaders
|
||||||
|
? JSON.parse(target.hcHeaders)
|
||||||
|
: null;
|
||||||
|
const hcHeadersSend: { [key: string]: string } = {};
|
||||||
|
if (hcHeadersParse) {
|
||||||
|
hcHeadersParse.forEach(
|
||||||
|
(header: { name: string; value: string }) => {
|
||||||
|
hcHeadersSend[header.name] = header.value;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: target.targetId,
|
||||||
|
hcEnabled: target.hcEnabled,
|
||||||
|
hcPath: target.hcPath,
|
||||||
|
hcScheme: target.hcScheme,
|
||||||
|
hcMode: target.hcMode,
|
||||||
|
hcHostname: target.hcHostname,
|
||||||
|
hcPort: target.hcPort,
|
||||||
|
hcInterval: target.hcInterval, // in seconds
|
||||||
|
hcUnhealthyInterval: target.hcUnhealthyInterval, // in seconds
|
||||||
|
hcTimeout: target.hcTimeout, // in seconds
|
||||||
|
hcHeaders: hcHeadersSend,
|
||||||
|
hcMethod: target.hcMethod,
|
||||||
|
hcTlsServerName: target.hcTlsServerName
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Filter out any null values from health check targets
|
||||||
|
const validHealthCheckTargets = healthCheckTargets.filter(
|
||||||
|
(target) => target !== null
|
||||||
|
);
|
||||||
|
|
||||||
|
return {
|
||||||
|
validHealthCheckTargets,
|
||||||
|
tcpTargets,
|
||||||
|
udpTargets
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,19 +2,10 @@ import { z } from "zod";
|
|||||||
import { MessageHandler } from "@server/routers/ws";
|
import { MessageHandler } from "@server/routers/ws";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { fromError } from "zod-validation-error";
|
import { fromError } from "zod-validation-error";
|
||||||
import {
|
import { db, ExitNode, exitNodes, Newt, sites } from "@server/db";
|
||||||
db,
|
|
||||||
ExitNode,
|
|
||||||
exitNodes,
|
|
||||||
siteResources,
|
|
||||||
clientSiteResourcesAssociationsCache
|
|
||||||
} from "@server/db";
|
|
||||||
import { clients, clientSitesAssociationsCache, Newt, sites } from "@server/db";
|
|
||||||
import { eq } from "drizzle-orm";
|
import { eq } from "drizzle-orm";
|
||||||
import { initPeerAddHandshake, updatePeer } from "../olm/peers";
|
|
||||||
import { sendToExitNode } from "#dynamic/lib/exitNodes";
|
import { sendToExitNode } from "#dynamic/lib/exitNodes";
|
||||||
import { generateSubnetProxyTargets, SubnetProxyTarget } from "@server/lib/ip";
|
import { buildClientConfigurationForNewtClient } from "./buildConfiguration";
|
||||||
import config from "@server/lib/config";
|
|
||||||
|
|
||||||
const inputSchema = z.object({
|
const inputSchema = z.object({
|
||||||
publicKey: z.string(),
|
publicKey: z.string(),
|
||||||
@@ -130,167 +121,18 @@ export const handleGetConfigMessage: MessageHandler = async (context) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all clients connected to this site
|
const { peers, targets } = await buildClientConfigurationForNewtClient(
|
||||||
const clientsRes = await db
|
site,
|
||||||
.select()
|
exitNode
|
||||||
.from(clients)
|
);
|
||||||
.innerJoin(
|
|
||||||
clientSitesAssociationsCache,
|
|
||||||
eq(clients.clientId, clientSitesAssociationsCache.clientId)
|
|
||||||
)
|
|
||||||
.where(eq(clientSitesAssociationsCache.siteId, siteId));
|
|
||||||
|
|
||||||
let peers: Array<{
|
|
||||||
publicKey: string;
|
|
||||||
allowedIps: string[];
|
|
||||||
endpoint?: string;
|
|
||||||
}> = [];
|
|
||||||
|
|
||||||
if (site.publicKey && site.endpoint && exitNode) {
|
|
||||||
// Prepare peers data for the response
|
|
||||||
peers = await Promise.all(
|
|
||||||
clientsRes
|
|
||||||
.filter((client) => {
|
|
||||||
if (!client.clients.pubKey) {
|
|
||||||
logger.warn(
|
|
||||||
`Client ${client.clients.clientId} has no public key, skipping`
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!client.clients.subnet) {
|
|
||||||
logger.warn(
|
|
||||||
`Client ${client.clients.clientId} has no subnet, skipping`
|
|
||||||
);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
.map(async (client) => {
|
|
||||||
// Add or update this peer on the olm if it is connected
|
|
||||||
|
|
||||||
// const allSiteResources = await db // only get the site resources that this client has access to
|
|
||||||
// .select()
|
|
||||||
// .from(siteResources)
|
|
||||||
// .innerJoin(
|
|
||||||
// clientSiteResourcesAssociationsCache,
|
|
||||||
// eq(
|
|
||||||
// siteResources.siteResourceId,
|
|
||||||
// clientSiteResourcesAssociationsCache.siteResourceId
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// .where(
|
|
||||||
// and(
|
|
||||||
// eq(siteResources.siteId, site.siteId),
|
|
||||||
// eq(
|
|
||||||
// clientSiteResourcesAssociationsCache.clientId,
|
|
||||||
// client.clients.clientId
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
|
|
||||||
// update the peer info on the olm
|
|
||||||
// if the peer has not been added yet this will be a no-op
|
|
||||||
await updatePeer(client.clients.clientId, {
|
|
||||||
siteId: site.siteId,
|
|
||||||
endpoint: site.endpoint!,
|
|
||||||
relayEndpoint: `${exitNode.endpoint}:${config.getRawConfig().gerbil.clients_start_port}`,
|
|
||||||
publicKey: site.publicKey!,
|
|
||||||
serverIP: site.address,
|
|
||||||
serverPort: site.listenPort
|
|
||||||
// remoteSubnets: generateRemoteSubnets(
|
|
||||||
// allSiteResources.map(
|
|
||||||
// ({ siteResources }) => siteResources
|
|
||||||
// )
|
|
||||||
// ),
|
|
||||||
// aliases: generateAliasConfig(
|
|
||||||
// allSiteResources.map(
|
|
||||||
// ({ siteResources }) => siteResources
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
});
|
|
||||||
|
|
||||||
// also trigger the peer add handshake in case the peer was not already added to the olm and we need to hole punch
|
|
||||||
// if it has already been added this will be a no-op
|
|
||||||
await initPeerAddHandshake(
|
|
||||||
// this will kick off the add peer process for the client
|
|
||||||
client.clients.clientId,
|
|
||||||
{
|
|
||||||
siteId,
|
|
||||||
exitNode: {
|
|
||||||
publicKey: exitNode.publicKey,
|
|
||||||
endpoint: exitNode.endpoint
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return {
|
|
||||||
publicKey: client.clients.pubKey!,
|
|
||||||
allowedIps: [
|
|
||||||
`${client.clients.subnet.split("/")[0]}/32`
|
|
||||||
], // we want to only allow from that client
|
|
||||||
endpoint: client.clientSitesAssociationsCache.isRelayed
|
|
||||||
? ""
|
|
||||||
: client.clientSitesAssociationsCache.endpoint! // if its relayed it should be localhost
|
|
||||||
};
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Filter out any null values from peers that didn't have an olm
|
|
||||||
const validPeers = peers.filter((peer) => peer !== null);
|
|
||||||
|
|
||||||
// Get all enabled site resources for this site
|
|
||||||
const allSiteResources = await db
|
|
||||||
.select()
|
|
||||||
.from(siteResources)
|
|
||||||
.where(eq(siteResources.siteId, siteId));
|
|
||||||
|
|
||||||
const targetsToSend: SubnetProxyTarget[] = [];
|
|
||||||
|
|
||||||
for (const resource of allSiteResources) {
|
|
||||||
// Get clients associated with this specific resource
|
|
||||||
const resourceClients = await db
|
|
||||||
.select({
|
|
||||||
clientId: clients.clientId,
|
|
||||||
pubKey: clients.pubKey,
|
|
||||||
subnet: clients.subnet
|
|
||||||
})
|
|
||||||
.from(clients)
|
|
||||||
.innerJoin(
|
|
||||||
clientSiteResourcesAssociationsCache,
|
|
||||||
eq(
|
|
||||||
clients.clientId,
|
|
||||||
clientSiteResourcesAssociationsCache.clientId
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.where(
|
|
||||||
eq(
|
|
||||||
clientSiteResourcesAssociationsCache.siteResourceId,
|
|
||||||
resource.siteResourceId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
const resourceTargets = generateSubnetProxyTargets(
|
|
||||||
resource,
|
|
||||||
resourceClients
|
|
||||||
);
|
|
||||||
|
|
||||||
targetsToSend.push(...resourceTargets);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build the configuration response
|
|
||||||
const configResponse = {
|
|
||||||
ipAddress: site.address,
|
|
||||||
peers: validPeers,
|
|
||||||
targets: targetsToSend
|
|
||||||
};
|
|
||||||
|
|
||||||
logger.debug("Sending config: ", configResponse);
|
|
||||||
return {
|
return {
|
||||||
message: {
|
message: {
|
||||||
type: "newt/wg/receive-config",
|
type: "newt/wg/receive-config",
|
||||||
data: {
|
data: {
|
||||||
...configResponse
|
ipAddress: site.address,
|
||||||
|
peers,
|
||||||
|
targets
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
broadcast: false,
|
broadcast: false,
|
||||||
|
|||||||
@@ -0,0 +1,163 @@
|
|||||||
|
import { db, sites } from "@server/db";
|
||||||
|
import { disconnectClient } from "#dynamic/routers/ws";
|
||||||
|
import { getClientConfigVersion, MessageHandler } from "@server/routers/ws";
|
||||||
|
import { clients, Newt } from "@server/db";
|
||||||
|
import { eq, lt, isNull, and, or } from "drizzle-orm";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { validateSessionToken } from "@server/auth/sessions/app";
|
||||||
|
import { checkOrgAccessPolicy } from "#dynamic/lib/checkOrgAccessPolicy";
|
||||||
|
import { sendTerminateClient } from "../client/terminate";
|
||||||
|
import { encodeHexLowerCase } from "@oslojs/encoding";
|
||||||
|
import { sha256 } from "@oslojs/crypto/sha2";
|
||||||
|
import { sendNewtSyncMessage } from "./sync";
|
||||||
|
|
||||||
|
// Track if the offline checker interval is running
|
||||||
|
// let offlineCheckerInterval: NodeJS.Timeout | null = null;
|
||||||
|
// const OFFLINE_CHECK_INTERVAL = 30 * 1000; // Check every 30 seconds
|
||||||
|
// const OFFLINE_THRESHOLD_MS = 2 * 60 * 1000; // 2 minutes
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts the background interval that checks for clients that haven't pinged recently
|
||||||
|
* and marks them as offline
|
||||||
|
*/
|
||||||
|
// export const startNewtOfflineChecker = (): void => {
|
||||||
|
// if (offlineCheckerInterval) {
|
||||||
|
// return; // Already running
|
||||||
|
// }
|
||||||
|
|
||||||
|
// offlineCheckerInterval = setInterval(async () => {
|
||||||
|
// try {
|
||||||
|
// const twoMinutesAgo = Math.floor(
|
||||||
|
// (Date.now() - OFFLINE_THRESHOLD_MS) / 1000
|
||||||
|
// );
|
||||||
|
|
||||||
|
// // TODO: WE NEED TO MAKE SURE THIS WORKS WITH DISTRIBUTED NODES ALL DOING THE SAME THING
|
||||||
|
|
||||||
|
// // Find clients that haven't pinged in the last 2 minutes and mark them as offline
|
||||||
|
// const offlineClients = await db
|
||||||
|
// .update(clients)
|
||||||
|
// .set({ online: false })
|
||||||
|
// .where(
|
||||||
|
// and(
|
||||||
|
// eq(clients.online, true),
|
||||||
|
// or(
|
||||||
|
// lt(clients.lastPing, twoMinutesAgo),
|
||||||
|
// isNull(clients.lastPing)
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// )
|
||||||
|
// .returning();
|
||||||
|
|
||||||
|
// for (const offlineClient of offlineClients) {
|
||||||
|
// logger.info(
|
||||||
|
// `Kicking offline newt client ${offlineClient.clientId} due to inactivity`
|
||||||
|
// );
|
||||||
|
|
||||||
|
// if (!offlineClient.newtId) {
|
||||||
|
// logger.warn(
|
||||||
|
// `Offline client ${offlineClient.clientId} has no newtId, cannot disconnect`
|
||||||
|
// );
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // Send a disconnect message to the client if connected
|
||||||
|
// try {
|
||||||
|
// await sendTerminateClient(
|
||||||
|
// offlineClient.clientId,
|
||||||
|
// offlineClient.newtId
|
||||||
|
// ); // terminate first
|
||||||
|
// // wait a moment to ensure the message is sent
|
||||||
|
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||||
|
// await disconnectClient(offlineClient.newtId);
|
||||||
|
// } catch (error) {
|
||||||
|
// logger.error(
|
||||||
|
// `Error sending disconnect to offline newt ${offlineClient.clientId}`,
|
||||||
|
// { error }
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// } catch (error) {
|
||||||
|
// logger.error("Error in offline checker interval", { error });
|
||||||
|
// }
|
||||||
|
// }, OFFLINE_CHECK_INTERVAL);
|
||||||
|
|
||||||
|
// logger.debug("Started offline checker interval");
|
||||||
|
// };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stops the background interval that checks for offline clients
|
||||||
|
*/
|
||||||
|
// export const stopNewtOfflineChecker = (): void => {
|
||||||
|
// if (offlineCheckerInterval) {
|
||||||
|
// clearInterval(offlineCheckerInterval);
|
||||||
|
// offlineCheckerInterval = null;
|
||||||
|
// logger.info("Stopped offline checker interval");
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles ping messages from clients and responds with pong
|
||||||
|
*/
|
||||||
|
export const handleNewtPingMessage: MessageHandler = async (context) => {
|
||||||
|
const { message, client: c, sendToClient } = context;
|
||||||
|
const newt = c as Newt;
|
||||||
|
|
||||||
|
if (!newt) {
|
||||||
|
logger.warn("Newt ping message: Newt not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!newt.siteId) {
|
||||||
|
logger.warn("Newt ping message: has no site ID");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the site
|
||||||
|
const [site] = await db
|
||||||
|
.select()
|
||||||
|
.from(sites)
|
||||||
|
.where(eq(sites.siteId, newt.siteId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!site) {
|
||||||
|
logger.warn(
|
||||||
|
`Newt ping message: site with ID ${newt.siteId} not found`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the version
|
||||||
|
const configVersion = await getClientConfigVersion(newt.newtId);
|
||||||
|
|
||||||
|
if (message.configVersion && configVersion != message.configVersion) {
|
||||||
|
logger.warn(
|
||||||
|
`Newt ping with outdated config version: ${message.configVersion} (current: ${configVersion})`
|
||||||
|
);
|
||||||
|
|
||||||
|
await sendNewtSyncMessage(newt, site);
|
||||||
|
}
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// // Update the client's last ping timestamp
|
||||||
|
// await db
|
||||||
|
// .update(clients)
|
||||||
|
// .set({
|
||||||
|
// lastPing: Math.floor(Date.now() / 1000),
|
||||||
|
// online: true
|
||||||
|
// })
|
||||||
|
// .where(eq(clients.clientId, newt.clientId));
|
||||||
|
// } catch (error) {
|
||||||
|
// logger.error("Error handling ping message", { error });
|
||||||
|
// }
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: {
|
||||||
|
type: "pong",
|
||||||
|
data: {
|
||||||
|
timestamp: new Date().toISOString()
|
||||||
|
}
|
||||||
|
},
|
||||||
|
broadcast: false,
|
||||||
|
excludeSender: false
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -18,6 +18,7 @@ import {
|
|||||||
} from "#dynamic/lib/exitNodes";
|
} from "#dynamic/lib/exitNodes";
|
||||||
import { fetchContainers } from "./dockerSocket";
|
import { fetchContainers } from "./dockerSocket";
|
||||||
import { lockManager } from "#dynamic/lib/lock";
|
import { lockManager } from "#dynamic/lib/lock";
|
||||||
|
import { buildTargetConfigurationForNewtClient } from "./buildConfiguration";
|
||||||
|
|
||||||
export type ExitNodePingResult = {
|
export type ExitNodePingResult = {
|
||||||
exitNodeId: number;
|
exitNodeId: number;
|
||||||
@@ -233,109 +234,8 @@ export const handleNewtRegisterMessage: MessageHandler = async (context) => {
|
|||||||
.where(eq(newts.newtId, newt.newtId));
|
.where(eq(newts.newtId, newt.newtId));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all enabled targets with their resource protocol information
|
const { tcpTargets, udpTargets, validHealthCheckTargets } =
|
||||||
const allTargets = await db
|
await buildTargetConfigurationForNewtClient(siteId);
|
||||||
.select({
|
|
||||||
resourceId: targets.resourceId,
|
|
||||||
targetId: targets.targetId,
|
|
||||||
ip: targets.ip,
|
|
||||||
method: targets.method,
|
|
||||||
port: targets.port,
|
|
||||||
internalPort: targets.internalPort,
|
|
||||||
enabled: targets.enabled,
|
|
||||||
protocol: resources.protocol,
|
|
||||||
hcEnabled: targetHealthCheck.hcEnabled,
|
|
||||||
hcPath: targetHealthCheck.hcPath,
|
|
||||||
hcScheme: targetHealthCheck.hcScheme,
|
|
||||||
hcMode: targetHealthCheck.hcMode,
|
|
||||||
hcHostname: targetHealthCheck.hcHostname,
|
|
||||||
hcPort: targetHealthCheck.hcPort,
|
|
||||||
hcInterval: targetHealthCheck.hcInterval,
|
|
||||||
hcUnhealthyInterval: targetHealthCheck.hcUnhealthyInterval,
|
|
||||||
hcTimeout: targetHealthCheck.hcTimeout,
|
|
||||||
hcHeaders: targetHealthCheck.hcHeaders,
|
|
||||||
hcMethod: targetHealthCheck.hcMethod,
|
|
||||||
hcTlsServerName: targetHealthCheck.hcTlsServerName
|
|
||||||
})
|
|
||||||
.from(targets)
|
|
||||||
.innerJoin(resources, eq(targets.resourceId, resources.resourceId))
|
|
||||||
.leftJoin(
|
|
||||||
targetHealthCheck,
|
|
||||||
eq(targets.targetId, targetHealthCheck.targetId)
|
|
||||||
)
|
|
||||||
.where(and(eq(targets.siteId, siteId), eq(targets.enabled, true)));
|
|
||||||
|
|
||||||
const { tcpTargets, udpTargets } = allTargets.reduce(
|
|
||||||
(acc, target) => {
|
|
||||||
// Filter out invalid targets
|
|
||||||
if (!target.internalPort || !target.ip || !target.port) {
|
|
||||||
return acc;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format target into string
|
|
||||||
const formattedTarget = `${target.internalPort}:${target.ip}:${target.port}`;
|
|
||||||
|
|
||||||
// Add to the appropriate protocol array
|
|
||||||
if (target.protocol === "tcp") {
|
|
||||||
acc.tcpTargets.push(formattedTarget);
|
|
||||||
} else {
|
|
||||||
acc.udpTargets.push(formattedTarget);
|
|
||||||
}
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
{ tcpTargets: [] as string[], udpTargets: [] as string[] }
|
|
||||||
);
|
|
||||||
|
|
||||||
const healthCheckTargets = allTargets.map((target) => {
|
|
||||||
// make sure the stuff is defined
|
|
||||||
if (
|
|
||||||
!target.hcPath ||
|
|
||||||
!target.hcHostname ||
|
|
||||||
!target.hcPort ||
|
|
||||||
!target.hcInterval ||
|
|
||||||
!target.hcMethod
|
|
||||||
) {
|
|
||||||
logger.debug(
|
|
||||||
`Skipping target ${target.targetId} due to missing health check fields`
|
|
||||||
);
|
|
||||||
return null; // Skip targets with missing health check fields
|
|
||||||
}
|
|
||||||
|
|
||||||
// parse headers
|
|
||||||
const hcHeadersParse = target.hcHeaders
|
|
||||||
? JSON.parse(target.hcHeaders)
|
|
||||||
: null;
|
|
||||||
const hcHeadersSend: { [key: string]: string } = {};
|
|
||||||
if (hcHeadersParse) {
|
|
||||||
hcHeadersParse.forEach(
|
|
||||||
(header: { name: string; value: string }) => {
|
|
||||||
hcHeadersSend[header.name] = header.value;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: target.targetId,
|
|
||||||
hcEnabled: target.hcEnabled,
|
|
||||||
hcPath: target.hcPath,
|
|
||||||
hcScheme: target.hcScheme,
|
|
||||||
hcMode: target.hcMode,
|
|
||||||
hcHostname: target.hcHostname,
|
|
||||||
hcPort: target.hcPort,
|
|
||||||
hcInterval: target.hcInterval, // in seconds
|
|
||||||
hcUnhealthyInterval: target.hcUnhealthyInterval, // in seconds
|
|
||||||
hcTimeout: target.hcTimeout, // in seconds
|
|
||||||
hcHeaders: hcHeadersSend,
|
|
||||||
hcMethod: target.hcMethod,
|
|
||||||
hcTlsServerName: target.hcTlsServerName
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
// Filter out any null values from health check targets
|
|
||||||
const validHealthCheckTargets = healthCheckTargets.filter(
|
|
||||||
(target) => target !== null
|
|
||||||
);
|
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`Sending health check targets to newt ${newt.newtId}: ${JSON.stringify(validHealthCheckTargets)}`
|
`Sending health check targets to newt ${newt.newtId}: ${JSON.stringify(validHealthCheckTargets)}`
|
||||||
|
|||||||
@@ -6,3 +6,4 @@ export * from "./handleGetConfigMessage";
|
|||||||
export * from "./handleSocketMessages";
|
export * from "./handleSocketMessages";
|
||||||
export * from "./handleNewtPingRequestMessage";
|
export * from "./handleNewtPingRequestMessage";
|
||||||
export * from "./handleApplyBlueprintMessage";
|
export * from "./handleApplyBlueprintMessage";
|
||||||
|
export * from "./handleNewtPingMessage";
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ export async function addPeer(
|
|||||||
await sendToClient(newtId, {
|
await sendToClient(newtId, {
|
||||||
type: "newt/wg/peer/add",
|
type: "newt/wg/peer/add",
|
||||||
data: peer
|
data: peer
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -81,7 +81,7 @@ export async function deletePeer(
|
|||||||
data: {
|
data: {
|
||||||
publicKey
|
publicKey
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -128,7 +128,7 @@ export async function updatePeer(
|
|||||||
publicKey,
|
publicKey,
|
||||||
...peer
|
...peer
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
import { ExitNode, exitNodes, Newt, Site, db } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import { sendToClient } from "#dynamic/routers/ws";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import {
|
||||||
|
buildClientConfigurationForNewtClient,
|
||||||
|
buildTargetConfigurationForNewtClient
|
||||||
|
} from "./buildConfiguration";
|
||||||
|
|
||||||
|
export async function sendNewtSyncMessage(newt: Newt, site: Site) {
|
||||||
|
const { tcpTargets, udpTargets, validHealthCheckTargets } =
|
||||||
|
await buildTargetConfigurationForNewtClient(site.siteId);
|
||||||
|
|
||||||
|
let exitNode: ExitNode | undefined;
|
||||||
|
if (site.exitNodeId) {
|
||||||
|
[exitNode] = await db
|
||||||
|
.select()
|
||||||
|
.from(exitNodes)
|
||||||
|
.where(eq(exitNodes.exitNodeId, site.exitNodeId))
|
||||||
|
.limit(1);
|
||||||
|
}
|
||||||
|
const { peers, targets } = await buildClientConfigurationForNewtClient(
|
||||||
|
site,
|
||||||
|
exitNode
|
||||||
|
);
|
||||||
|
|
||||||
|
await sendToClient(newt.newtId, {
|
||||||
|
type: "newt/sync",
|
||||||
|
data: {
|
||||||
|
proxyTargets: {
|
||||||
|
udp: udpTargets,
|
||||||
|
tcp: tcpTargets
|
||||||
|
},
|
||||||
|
healthCheckTargets: validHealthCheckTargets,
|
||||||
|
peers: peers,
|
||||||
|
clientTargets: targets
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
logger.warn(`Error sending newt sync message:`, error);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -22,7 +22,7 @@ export async function addTargets(
|
|||||||
data: {
|
data: {
|
||||||
targets: payloadTargets
|
targets: payloadTargets
|
||||||
}
|
}
|
||||||
});
|
}, { incrementConfigVersion: true });
|
||||||
|
|
||||||
// Create a map for quick lookup
|
// Create a map for quick lookup
|
||||||
const healthCheckMap = new Map<number, TargetHealthCheck>();
|
const healthCheckMap = new Map<number, TargetHealthCheck>();
|
||||||
@@ -103,7 +103,7 @@ export async function addTargets(
|
|||||||
data: {
|
data: {
|
||||||
targets: validHealthCheckTargets
|
targets: validHealthCheckTargets
|
||||||
}
|
}
|
||||||
});
|
}, { incrementConfigVersion: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removeTargets(
|
export async function removeTargets(
|
||||||
@@ -124,7 +124,7 @@ export async function removeTargets(
|
|||||||
data: {
|
data: {
|
||||||
targets: payloadTargets
|
targets: payloadTargets
|
||||||
}
|
}
|
||||||
});
|
}, { incrementConfigVersion: true });
|
||||||
|
|
||||||
const healthCheckTargets = targets.map((target) => {
|
const healthCheckTargets = targets.map((target) => {
|
||||||
return target.targetId;
|
return target.targetId;
|
||||||
@@ -135,5 +135,5 @@ export async function removeTargets(
|
|||||||
data: {
|
data: {
|
||||||
ids: healthCheckTargets
|
ids: healthCheckTargets
|
||||||
}
|
}
|
||||||
});
|
}, { incrementConfigVersion: true });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { olms, clients } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { rebuildClientAssociationsFromClient } from "@server/lib/rebuildClientAssociations";
|
||||||
|
import { sendTerminateClient } from "../client/terminate";
|
||||||
|
|
||||||
|
const paramsSchema = z
|
||||||
|
.object({
|
||||||
|
userId: z.string(),
|
||||||
|
olmId: z.string()
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
|
export async function archiveUserOlm(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { olmId } = parsedParams.data;
|
||||||
|
|
||||||
|
// Archive the OLM and disconnect associated clients in a transaction
|
||||||
|
await db.transaction(async (trx) => {
|
||||||
|
// Find all clients associated with this OLM
|
||||||
|
const associatedClients = await trx
|
||||||
|
.select()
|
||||||
|
.from(clients)
|
||||||
|
.where(eq(clients.olmId, olmId));
|
||||||
|
|
||||||
|
// Disconnect clients from the OLM (set olmId to null)
|
||||||
|
for (const client of associatedClients) {
|
||||||
|
await trx
|
||||||
|
.update(clients)
|
||||||
|
.set({ olmId: null })
|
||||||
|
.where(eq(clients.clientId, client.clientId));
|
||||||
|
|
||||||
|
await rebuildClientAssociationsFromClient(client, trx);
|
||||||
|
await sendTerminateClient(client.clientId, olmId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Archive the OLM (set archived to true)
|
||||||
|
await trx
|
||||||
|
.update(olms)
|
||||||
|
.set({ archived: true })
|
||||||
|
.where(eq(olms.olmId, olmId));
|
||||||
|
});
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Device archived successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to archive device"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,145 @@
|
|||||||
|
import { Client, clientSiteResourcesAssociationsCache, clientSitesAssociationsCache, db, exitNodes, siteResources, sites } from "@server/db";
|
||||||
|
import { generateAliasConfig, generateRemoteSubnets } from "@server/lib/ip";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
import { and, eq } from "drizzle-orm";
|
||||||
|
import { addPeer, deletePeer } from "../newt/peers";
|
||||||
|
import config from "@server/lib/config";
|
||||||
|
|
||||||
|
export async function buildSiteConfigurationForOlmClient(
|
||||||
|
client: Client,
|
||||||
|
publicKey: string | null,
|
||||||
|
relay: boolean
|
||||||
|
) {
|
||||||
|
const siteConfigurations = [];
|
||||||
|
|
||||||
|
// Get all sites data
|
||||||
|
const sitesData = await db
|
||||||
|
.select()
|
||||||
|
.from(sites)
|
||||||
|
.innerJoin(
|
||||||
|
clientSitesAssociationsCache,
|
||||||
|
eq(sites.siteId, clientSitesAssociationsCache.siteId)
|
||||||
|
)
|
||||||
|
.where(eq(clientSitesAssociationsCache.clientId, client.clientId));
|
||||||
|
|
||||||
|
// Process each site
|
||||||
|
for (const {
|
||||||
|
sites: site,
|
||||||
|
clientSitesAssociationsCache: association
|
||||||
|
} of sitesData) {
|
||||||
|
if (!site.exitNodeId) {
|
||||||
|
logger.warn(
|
||||||
|
`Site ${site.siteId} does not have exit node, skipping`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate endpoint and hole punch status
|
||||||
|
if (!site.endpoint) {
|
||||||
|
logger.warn(
|
||||||
|
`In olm register: site ${site.siteId} has no endpoint, skipping`
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if (site.lastHolePunch && now - site.lastHolePunch > 6 && relay) {
|
||||||
|
// logger.warn(
|
||||||
|
// `Site ${site.siteId} last hole punch is too old, skipping`
|
||||||
|
// );
|
||||||
|
// continue;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// If public key changed, delete old peer from this site
|
||||||
|
if (client.pubKey && client.pubKey != publicKey) {
|
||||||
|
logger.info(
|
||||||
|
`Public key mismatch. Deleting old peer from site ${site.siteId}...`
|
||||||
|
);
|
||||||
|
await deletePeer(site.siteId, client.pubKey!);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!site.subnet) {
|
||||||
|
logger.warn(`Site ${site.siteId} has no subnet, skipping`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [clientSite] = await db
|
||||||
|
.select()
|
||||||
|
.from(clientSitesAssociationsCache)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(clientSitesAssociationsCache.clientId, client.clientId),
|
||||||
|
eq(clientSitesAssociationsCache.siteId, site.siteId)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
// Add the peer to the exit node for this site
|
||||||
|
if (clientSite.endpoint && publicKey) {
|
||||||
|
logger.info(
|
||||||
|
`Adding peer ${publicKey} to site ${site.siteId} with endpoint ${clientSite.endpoint}`
|
||||||
|
);
|
||||||
|
await addPeer(site.siteId, {
|
||||||
|
publicKey: publicKey,
|
||||||
|
allowedIps: [`${client.subnet.split("/")[0]}/32`], // we want to only allow from that client
|
||||||
|
endpoint: relay ? "" : clientSite.endpoint
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
logger.warn(
|
||||||
|
`Client ${client.clientId} has no endpoint, skipping peer addition`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
let relayEndpoint: string | undefined = undefined;
|
||||||
|
if (relay) {
|
||||||
|
const [exitNode] = await db
|
||||||
|
.select()
|
||||||
|
.from(exitNodes)
|
||||||
|
.where(eq(exitNodes.exitNodeId, site.exitNodeId))
|
||||||
|
.limit(1);
|
||||||
|
if (!exitNode) {
|
||||||
|
logger.warn(`Exit node not found for site ${site.siteId}`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
relayEndpoint = `${exitNode.endpoint}:${config.getRawConfig().gerbil.clients_start_port}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const allSiteResources = await db // only get the site resources that this client has access to
|
||||||
|
.select()
|
||||||
|
.from(siteResources)
|
||||||
|
.innerJoin(
|
||||||
|
clientSiteResourcesAssociationsCache,
|
||||||
|
eq(
|
||||||
|
siteResources.siteResourceId,
|
||||||
|
clientSiteResourcesAssociationsCache.siteResourceId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.where(
|
||||||
|
and(
|
||||||
|
eq(siteResources.siteId, site.siteId),
|
||||||
|
eq(
|
||||||
|
clientSiteResourcesAssociationsCache.clientId,
|
||||||
|
client.clientId
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// Add site configuration to the array
|
||||||
|
siteConfigurations.push({
|
||||||
|
siteId: site.siteId,
|
||||||
|
name: site.name,
|
||||||
|
// relayEndpoint: relayEndpoint, // this can be undefined now if not relayed // lets not do this for now because it would conflict with the hole punch testing
|
||||||
|
endpoint: site.endpoint,
|
||||||
|
publicKey: site.publicKey,
|
||||||
|
serverIP: site.address,
|
||||||
|
serverPort: site.listenPort,
|
||||||
|
remoteSubnets: generateRemoteSubnets(
|
||||||
|
allSiteResources.map(({ siteResources }) => siteResources)
|
||||||
|
),
|
||||||
|
aliases: generateAliasConfig(
|
||||||
|
allSiteResources.map(({ siteResources }) => siteResources)
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return siteConfigurations;
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import { db } from "@server/db";
|
import { db } from "@server/db";
|
||||||
import { disconnectClient } from "#dynamic/routers/ws";
|
import { disconnectClient } from "#dynamic/routers/ws";
|
||||||
import { MessageHandler } from "@server/routers/ws";
|
import { getClientConfigVersion, MessageHandler } from "@server/routers/ws";
|
||||||
import { clients, Olm } from "@server/db";
|
import { clients, olms, Olm } from "@server/db";
|
||||||
import { eq, lt, isNull, and, or } from "drizzle-orm";
|
import { eq, lt, isNull, and, or } from "drizzle-orm";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { validateSessionToken } from "@server/auth/sessions/app";
|
import { validateSessionToken } from "@server/auth/sessions/app";
|
||||||
@@ -9,6 +9,7 @@ import { checkOrgAccessPolicy } from "#dynamic/lib/checkOrgAccessPolicy";
|
|||||||
import { sendTerminateClient } from "../client/terminate";
|
import { sendTerminateClient } from "../client/terminate";
|
||||||
import { encodeHexLowerCase } from "@oslojs/encoding";
|
import { encodeHexLowerCase } from "@oslojs/encoding";
|
||||||
import { sha256 } from "@oslojs/crypto/sha2";
|
import { sha256 } from "@oslojs/crypto/sha2";
|
||||||
|
import { sendOlmSyncMessage } from "./sync";
|
||||||
|
|
||||||
// Track if the offline checker interval is running
|
// Track if the offline checker interval is running
|
||||||
let offlineCheckerInterval: NodeJS.Timeout | null = null;
|
let offlineCheckerInterval: NodeJS.Timeout | null = null;
|
||||||
@@ -108,29 +109,17 @@ export const handleOlmPingMessage: MessageHandler = async (context) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (olm.userId) {
|
if (!olm.clientId) {
|
||||||
// we need to check a user token to make sure its still valid
|
logger.warn("Olm has no client ID!");
|
||||||
const { session: userSession, user } =
|
return;
|
||||||
await validateSessionToken(userToken);
|
}
|
||||||
if (!userSession || !user) {
|
|
||||||
logger.warn("Invalid user session for olm ping");
|
|
||||||
return; // by returning here we just ignore the ping and the setInterval will force it to disconnect
|
|
||||||
}
|
|
||||||
if (user.userId !== olm.userId) {
|
|
||||||
logger.warn("User ID mismatch for olm ping");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
try {
|
||||||
// get the client
|
// get the client
|
||||||
const [client] = await db
|
const [client] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(clients)
|
.from(clients)
|
||||||
.where(
|
.where(eq(clients.clientId, olm.clientId))
|
||||||
and(
|
|
||||||
eq(clients.olmId, olm.olmId),
|
|
||||||
eq(clients.userId, olm.userId)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
.limit(1);
|
||||||
|
|
||||||
if (!client) {
|
if (!client) {
|
||||||
@@ -138,38 +127,75 @@ export const handleOlmPingMessage: MessageHandler = async (context) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const sessionId = encodeHexLowerCase(
|
if (client.blocked) {
|
||||||
sha256(new TextEncoder().encode(userToken))
|
// NOTE: by returning we dont update the lastPing, so the offline checker will eventually disconnect them
|
||||||
);
|
logger.debug(
|
||||||
|
`Blocked client ${client.clientId} attempted olm ping`
|
||||||
const policyCheck = await checkOrgAccessPolicy({
|
|
||||||
orgId: client.orgId,
|
|
||||||
userId: olm.userId,
|
|
||||||
sessionId // this is the user token passed in the message
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!policyCheck.allowed) {
|
|
||||||
logger.warn(
|
|
||||||
`Olm user ${olm.userId} does not pass access policies for org ${client.orgId}: ${policyCheck.error}`
|
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (!olm.clientId) {
|
if (olm.userId) {
|
||||||
logger.warn("Olm has no client ID!");
|
// we need to check a user token to make sure its still valid
|
||||||
return;
|
const { session: userSession, user } =
|
||||||
}
|
await validateSessionToken(userToken);
|
||||||
|
if (!userSession || !user) {
|
||||||
|
logger.warn("Invalid user session for olm ping");
|
||||||
|
return; // by returning here we just ignore the ping and the setInterval will force it to disconnect
|
||||||
|
}
|
||||||
|
if (user.userId !== olm.userId) {
|
||||||
|
logger.warn("User ID mismatch for olm ping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (user.userId !== client.userId) {
|
||||||
|
logger.warn("Client user ID mismatch for olm ping");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sessionId = encodeHexLowerCase(
|
||||||
|
sha256(new TextEncoder().encode(userToken))
|
||||||
|
);
|
||||||
|
|
||||||
|
const policyCheck = await checkOrgAccessPolicy({
|
||||||
|
orgId: client.orgId,
|
||||||
|
userId: olm.userId,
|
||||||
|
sessionId // this is the user token passed in the message
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!policyCheck.allowed) {
|
||||||
|
logger.warn(
|
||||||
|
`Olm user ${olm.userId} does not pass access policies for org ${client.orgId}: ${policyCheck.error}`
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// get the version
|
||||||
|
const configVersion = await getClientConfigVersion(olm.olmId);
|
||||||
|
|
||||||
|
if (message.configVersion && configVersion != message.configVersion) {
|
||||||
|
logger.warn(
|
||||||
|
`Olm ping with outdated config version: ${message.configVersion} (current: ${configVersion})`
|
||||||
|
);
|
||||||
|
await sendOlmSyncMessage(olm, client);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
// Update the client's last ping timestamp
|
// Update the client's last ping timestamp
|
||||||
await db
|
await db
|
||||||
.update(clients)
|
.update(clients)
|
||||||
.set({
|
.set({
|
||||||
lastPing: Math.floor(Date.now() / 1000),
|
lastPing: Math.floor(Date.now() / 1000),
|
||||||
online: true
|
online: true,
|
||||||
|
archived: false
|
||||||
})
|
})
|
||||||
.where(eq(clients.clientId, olm.clientId));
|
.where(eq(clients.clientId, olm.clientId));
|
||||||
|
|
||||||
|
if (olm.archived) {
|
||||||
|
await db
|
||||||
|
.update(olms)
|
||||||
|
.set({ archived: false })
|
||||||
|
.where(eq(olms.olmId, olm.olmId));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error handling ping message", { error });
|
logger.error("Error handling ping message", { error });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
Client,
|
||||||
clientSiteResourcesAssociationsCache,
|
clientSiteResourcesAssociationsCache,
|
||||||
db,
|
db,
|
||||||
orgs,
|
orgs,
|
||||||
@@ -13,7 +14,7 @@ import {
|
|||||||
olms,
|
olms,
|
||||||
sites
|
sites
|
||||||
} from "@server/db";
|
} from "@server/db";
|
||||||
import { and, eq, inArray, isNull } from "drizzle-orm";
|
import { and, count, eq, inArray, isNull } from "drizzle-orm";
|
||||||
import { addPeer, deletePeer } from "../newt/peers";
|
import { addPeer, deletePeer } from "../newt/peers";
|
||||||
import logger from "@server/logger";
|
import logger from "@server/logger";
|
||||||
import { generateAliasConfig } from "@server/lib/ip";
|
import { generateAliasConfig } from "@server/lib/ip";
|
||||||
@@ -23,6 +24,7 @@ import { validateSessionToken } from "@server/auth/sessions/app";
|
|||||||
import config from "@server/lib/config";
|
import config from "@server/lib/config";
|
||||||
import { encodeHexLowerCase } from "@oslojs/encoding";
|
import { encodeHexLowerCase } from "@oslojs/encoding";
|
||||||
import { sha256 } from "@oslojs/crypto/sha2";
|
import { sha256 } from "@oslojs/crypto/sha2";
|
||||||
|
import { buildSiteConfigurationForOlmClient } from "./buildConfiguration";
|
||||||
|
|
||||||
export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
||||||
logger.info("Handling register olm message!");
|
logger.info("Handling register olm message!");
|
||||||
@@ -55,6 +57,11 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (client.blocked) {
|
||||||
|
logger.debug(`Client ${client.clientId} is blocked. Ignoring register.`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const [org] = await db
|
const [org] = await db
|
||||||
.select()
|
.select()
|
||||||
.from(orgs)
|
.from(orgs)
|
||||||
@@ -112,18 +119,20 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
(olmVersion && olm.version !== olmVersion) ||
|
(olmVersion && olm.version !== olmVersion) ||
|
||||||
(olmAgent && olm.agent !== olmAgent)
|
(olmAgent && olm.agent !== olmAgent) ||
|
||||||
|
olm.archived
|
||||||
) {
|
) {
|
||||||
await db
|
await db
|
||||||
.update(olms)
|
.update(olms)
|
||||||
.set({
|
.set({
|
||||||
version: olmVersion,
|
version: olmVersion,
|
||||||
agent: olmAgent
|
agent: olmAgent,
|
||||||
|
archived: false
|
||||||
})
|
})
|
||||||
.where(eq(olms.olmId, olm.olmId));
|
.where(eq(olms.olmId, olm.olmId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client.pubKey !== publicKey) {
|
if (client.pubKey !== publicKey || client.archived) {
|
||||||
logger.info(
|
logger.info(
|
||||||
"Public key mismatch. Updating public key and clearing session info..."
|
"Public key mismatch. Updating public key and clearing session info..."
|
||||||
);
|
);
|
||||||
@@ -131,7 +140,8 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
await db
|
await db
|
||||||
.update(clients)
|
.update(clients)
|
||||||
.set({
|
.set({
|
||||||
pubKey: publicKey
|
pubKey: publicKey,
|
||||||
|
archived: false,
|
||||||
})
|
})
|
||||||
.where(eq(clients.clientId, client.clientId));
|
.where(eq(clients.clientId, client.clientId));
|
||||||
|
|
||||||
@@ -145,8 +155,8 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get all sites data
|
// Get all sites data
|
||||||
const sitesData = await db
|
const sitesCountResult = await db
|
||||||
.select()
|
.select({ count: count() })
|
||||||
.from(sites)
|
.from(sites)
|
||||||
.innerJoin(
|
.innerJoin(
|
||||||
clientSitesAssociationsCache,
|
clientSitesAssociationsCache,
|
||||||
@@ -154,140 +164,29 @@ export const handleOlmRegisterMessage: MessageHandler = async (context) => {
|
|||||||
)
|
)
|
||||||
.where(eq(clientSitesAssociationsCache.clientId, client.clientId));
|
.where(eq(clientSitesAssociationsCache.clientId, client.clientId));
|
||||||
|
|
||||||
|
// Extract the count value from the result array
|
||||||
|
const sitesCount =
|
||||||
|
sitesCountResult.length > 0 ? sitesCountResult[0].count : 0;
|
||||||
|
|
||||||
// Prepare an array to store site configurations
|
// Prepare an array to store site configurations
|
||||||
const siteConfigurations = [];
|
logger.debug(`Found ${sitesCount} sites for client ${client.clientId}`);
|
||||||
logger.debug(
|
|
||||||
`Found ${sitesData.length} sites for client ${client.clientId}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// this prevents us from accepting a register from an olm that has not hole punched yet.
|
// this prevents us from accepting a register from an olm that has not hole punched yet.
|
||||||
// the olm will pump the register so we can keep checking
|
// the olm will pump the register so we can keep checking
|
||||||
// TODO: I still think there is a better way to do this rather than locking it out here but ???
|
// TODO: I still think there is a better way to do this rather than locking it out here but ???
|
||||||
if (now - (client.lastHolePunch || 0) > 5 && sitesData.length > 0) {
|
if (now - (client.lastHolePunch || 0) > 5 && sitesCount > 0) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Client last hole punch is too old and we have sites to send; skipping this register"
|
"Client last hole punch is too old and we have sites to send; skipping this register"
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Process each site
|
// NOTE: its important that the client here is the old client and the public key is the new key
|
||||||
for (const {
|
const siteConfigurations = await buildSiteConfigurationForOlmClient(
|
||||||
sites: site,
|
client,
|
||||||
clientSitesAssociationsCache: association
|
publicKey,
|
||||||
} of sitesData) {
|
relay
|
||||||
if (!site.exitNodeId) {
|
);
|
||||||
logger.warn(
|
|
||||||
`Site ${site.siteId} does not have exit node, skipping`
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate endpoint and hole punch status
|
|
||||||
if (!site.endpoint) {
|
|
||||||
logger.warn(
|
|
||||||
`In olm register: site ${site.siteId} has no endpoint, skipping`
|
|
||||||
);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (site.lastHolePunch && now - site.lastHolePunch > 6 && relay) {
|
|
||||||
// logger.warn(
|
|
||||||
// `Site ${site.siteId} last hole punch is too old, skipping`
|
|
||||||
// );
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// If public key changed, delete old peer from this site
|
|
||||||
if (client.pubKey && client.pubKey != publicKey) {
|
|
||||||
logger.info(
|
|
||||||
`Public key mismatch. Deleting old peer from site ${site.siteId}...`
|
|
||||||
);
|
|
||||||
await deletePeer(site.siteId, client.pubKey!);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!site.subnet) {
|
|
||||||
logger.warn(`Site ${site.siteId} has no subnet, skipping`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [clientSite] = await db
|
|
||||||
.select()
|
|
||||||
.from(clientSitesAssociationsCache)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(clientSitesAssociationsCache.clientId, client.clientId),
|
|
||||||
eq(clientSitesAssociationsCache.siteId, site.siteId)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.limit(1);
|
|
||||||
|
|
||||||
// Add the peer to the exit node for this site
|
|
||||||
if (clientSite.endpoint) {
|
|
||||||
logger.info(
|
|
||||||
`Adding peer ${publicKey} to site ${site.siteId} with endpoint ${clientSite.endpoint}`
|
|
||||||
);
|
|
||||||
await addPeer(site.siteId, {
|
|
||||||
publicKey: publicKey,
|
|
||||||
allowedIps: [`${client.subnet.split("/")[0]}/32`], // we want to only allow from that client
|
|
||||||
endpoint: relay ? "" : clientSite.endpoint
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
logger.warn(
|
|
||||||
`Client ${client.clientId} has no endpoint, skipping peer addition`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let relayEndpoint: string | undefined = undefined;
|
|
||||||
if (relay) {
|
|
||||||
const [exitNode] = await db
|
|
||||||
.select()
|
|
||||||
.from(exitNodes)
|
|
||||||
.where(eq(exitNodes.exitNodeId, site.exitNodeId))
|
|
||||||
.limit(1);
|
|
||||||
if (!exitNode) {
|
|
||||||
logger.warn(`Exit node not found for site ${site.siteId}`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
relayEndpoint = `${exitNode.endpoint}:${config.getRawConfig().gerbil.clients_start_port}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const allSiteResources = await db // only get the site resources that this client has access to
|
|
||||||
.select()
|
|
||||||
.from(siteResources)
|
|
||||||
.innerJoin(
|
|
||||||
clientSiteResourcesAssociationsCache,
|
|
||||||
eq(
|
|
||||||
siteResources.siteResourceId,
|
|
||||||
clientSiteResourcesAssociationsCache.siteResourceId
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.where(
|
|
||||||
and(
|
|
||||||
eq(siteResources.siteId, site.siteId),
|
|
||||||
eq(
|
|
||||||
clientSiteResourcesAssociationsCache.clientId,
|
|
||||||
client.clientId
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Add site configuration to the array
|
|
||||||
siteConfigurations.push({
|
|
||||||
siteId: site.siteId,
|
|
||||||
name: site.name,
|
|
||||||
// relayEndpoint: relayEndpoint, // this can be undefined now if not relayed // lets not do this for now because it would conflict with the hole punch testing
|
|
||||||
endpoint: site.endpoint,
|
|
||||||
publicKey: site.publicKey,
|
|
||||||
serverIP: site.address,
|
|
||||||
serverPort: site.listenPort,
|
|
||||||
remoteSubnets: generateRemoteSubnets(
|
|
||||||
allSiteResources.map(({ siteResources }) => siteResources)
|
|
||||||
),
|
|
||||||
aliases: generateAliasConfig(
|
|
||||||
allSiteResources.map(({ siteResources }) => siteResources)
|
|
||||||
)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// REMOVED THIS SO IT CREATES THE INTERFACE AND JUST WAITS FOR THE SITES
|
// REMOVED THIS SO IT CREATES THE INTERFACE AND JUST WAITS FOR THE SITES
|
||||||
// if (siteConfigurations.length === 0) {
|
// if (siteConfigurations.length === 0) {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ export * from "./getOlmToken";
|
|||||||
export * from "./createUserOlm";
|
export * from "./createUserOlm";
|
||||||
export * from "./handleOlmRelayMessage";
|
export * from "./handleOlmRelayMessage";
|
||||||
export * from "./handleOlmPingMessage";
|
export * from "./handleOlmPingMessage";
|
||||||
export * from "./deleteUserOlm";
|
export * from "./archiveUserOlm";
|
||||||
|
export * from "./unarchiveUserOlm";
|
||||||
export * from "./listUserOlms";
|
export * from "./listUserOlms";
|
||||||
export * from "./deleteUserOlm";
|
|
||||||
export * from "./getUserOlm";
|
export * from "./getUserOlm";
|
||||||
export * from "./handleOlmServerPeerAddMessage";
|
export * from "./handleOlmServerPeerAddMessage";
|
||||||
export * from "./handleOlmUnRelayMessage";
|
export * from "./handleOlmUnRelayMessage";
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ export type ListUserOlmsResponse = {
|
|||||||
name: string | null;
|
name: string | null;
|
||||||
clientId: number | null;
|
clientId: number | null;
|
||||||
userId: string | null;
|
userId: string | null;
|
||||||
|
archived: boolean;
|
||||||
}>;
|
}>;
|
||||||
pagination: {
|
pagination: {
|
||||||
total: number;
|
total: number;
|
||||||
@@ -89,7 +90,7 @@ export async function listUserOlms(
|
|||||||
|
|
||||||
const { userId } = parsedParams.data;
|
const { userId } = parsedParams.data;
|
||||||
|
|
||||||
// Get total count
|
// Get total count (including archived OLMs)
|
||||||
const [totalCountResult] = await db
|
const [totalCountResult] = await db
|
||||||
.select({ count: count() })
|
.select({ count: count() })
|
||||||
.from(olms)
|
.from(olms)
|
||||||
@@ -97,7 +98,7 @@ export async function listUserOlms(
|
|||||||
|
|
||||||
const total = totalCountResult?.count || 0;
|
const total = totalCountResult?.count || 0;
|
||||||
|
|
||||||
// Get OLMs for the current user
|
// Get OLMs for the current user (including archived OLMs)
|
||||||
const userOlms = await db
|
const userOlms = await db
|
||||||
.select({
|
.select({
|
||||||
olmId: olms.olmId,
|
olmId: olms.olmId,
|
||||||
@@ -105,7 +106,8 @@ export async function listUserOlms(
|
|||||||
version: olms.version,
|
version: olms.version,
|
||||||
name: olms.name,
|
name: olms.name,
|
||||||
clientId: olms.clientId,
|
clientId: olms.clientId,
|
||||||
userId: olms.userId
|
userId: olms.userId,
|
||||||
|
archived: olms.archived
|
||||||
})
|
})
|
||||||
.from(olms)
|
.from(olms)
|
||||||
.where(eq(olms.userId, userId))
|
.where(eq(olms.userId, userId))
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export async function addPeer(
|
|||||||
remoteSubnets: peer.remoteSubnets, // optional, comma-separated list of subnets that this site can access
|
remoteSubnets: peer.remoteSubnets, // optional, comma-separated list of subnets that this site can access
|
||||||
aliases: peer.aliases
|
aliases: peer.aliases
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ export async function deletePeer(
|
|||||||
publicKey,
|
publicKey,
|
||||||
siteId: siteId
|
siteId: siteId
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -121,7 +121,7 @@ export async function updatePeer(
|
|||||||
remoteSubnets: peer.remoteSubnets,
|
remoteSubnets: peer.remoteSubnets,
|
||||||
aliases: peer.aliases
|
aliases: peer.aliases
|
||||||
}
|
}
|
||||||
}).catch((error) => {
|
}, { incrementConfigVersion: true }).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,6 +161,8 @@ export async function initPeerAddHandshake(
|
|||||||
endpoint: peer.exitNode.endpoint
|
endpoint: peer.exitNode.endpoint
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// }, { incrementConfigVersion: true }).catch((error) => {
|
||||||
|
// TODO: DOES THIS NEED TO BE A INCREMENT VERSION? I AM NOT SURE BECAUSE IT WOULD BE TRIGGERED BY THE SYNC?
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
logger.warn(`Error sending message:`, error);
|
logger.warn(`Error sending message:`, error);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
import { Client, Olm } from "@server/db";
|
||||||
|
import { buildSiteConfigurationForOlmClient } from "./buildConfiguration";
|
||||||
|
import { sendToClient } from "#dynamic/routers/ws";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
|
||||||
|
export async function sendOlmSyncMessage(olm: Olm, client: Client) {
|
||||||
|
// NOTE: WE ARE HARDCODING THE RELAY PARAMETER TO FALSE HERE BUT IN THE REGISTER MESSAGE ITS DEFINED BY THE CLIENT
|
||||||
|
const siteConfigurations = await buildSiteConfigurationForOlmClient(
|
||||||
|
client,
|
||||||
|
client.pubKey,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
await sendToClient(olm.olmId, {
|
||||||
|
type: "olm/sync",
|
||||||
|
data: {
|
||||||
|
sites: siteConfigurations
|
||||||
|
}
|
||||||
|
}).catch((error) => {
|
||||||
|
logger.warn(`Error sending olm sync message:`, error);
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
import { NextFunction, Request, Response } from "express";
|
||||||
|
import { db } from "@server/db";
|
||||||
|
import { olms } from "@server/db";
|
||||||
|
import { eq } from "drizzle-orm";
|
||||||
|
import HttpCode from "@server/types/HttpCode";
|
||||||
|
import createHttpError from "http-errors";
|
||||||
|
import response from "@server/lib/response";
|
||||||
|
import { z } from "zod";
|
||||||
|
import { fromError } from "zod-validation-error";
|
||||||
|
import logger from "@server/logger";
|
||||||
|
|
||||||
|
const paramsSchema = z
|
||||||
|
.object({
|
||||||
|
userId: z.string(),
|
||||||
|
olmId: z.string()
|
||||||
|
})
|
||||||
|
.strict();
|
||||||
|
|
||||||
|
export async function unarchiveUserOlm(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
): Promise<any> {
|
||||||
|
try {
|
||||||
|
const parsedParams = paramsSchema.safeParse(req.params);
|
||||||
|
if (!parsedParams.success) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
fromError(parsedParams.error).toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { olmId } = parsedParams.data;
|
||||||
|
|
||||||
|
// Check if OLM exists and is archived
|
||||||
|
const [olm] = await db
|
||||||
|
.select()
|
||||||
|
.from(olms)
|
||||||
|
.where(eq(olms.olmId, olmId))
|
||||||
|
.limit(1);
|
||||||
|
|
||||||
|
if (!olm) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.NOT_FOUND,
|
||||||
|
`OLM with ID ${olmId} not found`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!olm.archived) {
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.BAD_REQUEST,
|
||||||
|
`OLM with ID ${olmId} is not archived`
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unarchive the OLM (set archived to false)
|
||||||
|
await db
|
||||||
|
.update(olms)
|
||||||
|
.set({ archived: false })
|
||||||
|
.where(eq(olms.olmId, olmId));
|
||||||
|
|
||||||
|
return response(res, {
|
||||||
|
data: null,
|
||||||
|
success: true,
|
||||||
|
error: false,
|
||||||
|
message: "Device unarchived successfully",
|
||||||
|
status: HttpCode.OK
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
return next(
|
||||||
|
createHttpError(
|
||||||
|
HttpCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"Failed to unarchive device"
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -213,9 +213,11 @@ export async function updateTarget(
|
|||||||
|
|
||||||
// When health check is disabled, reset hcHealth to "unknown"
|
// When health check is disabled, reset hcHealth to "unknown"
|
||||||
// to prevent previously unhealthy targets from being excluded
|
// to prevent previously unhealthy targets from being excluded
|
||||||
|
// Also when the site is not a newt, set hcHealth to "unknown"
|
||||||
const hcHealthValue =
|
const hcHealthValue =
|
||||||
parsedBody.data.hcEnabled === false ||
|
parsedBody.data.hcEnabled === false ||
|
||||||
parsedBody.data.hcEnabled === null
|
parsedBody.data.hcEnabled === null ||
|
||||||
|
site.type !== "newt"
|
||||||
? "unknown"
|
? "unknown"
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,8 @@ import {
|
|||||||
handleDockerStatusMessage,
|
handleDockerStatusMessage,
|
||||||
handleDockerContainersMessage,
|
handleDockerContainersMessage,
|
||||||
handleNewtPingRequestMessage,
|
handleNewtPingRequestMessage,
|
||||||
handleApplyBlueprintMessage
|
handleApplyBlueprintMessage,
|
||||||
|
handleNewtPingMessage
|
||||||
} from "../newt";
|
} from "../newt";
|
||||||
import {
|
import {
|
||||||
handleOlmRegisterMessage,
|
handleOlmRegisterMessage,
|
||||||
@@ -24,6 +25,7 @@ export const messageHandlers: Record<string, MessageHandler> = {
|
|||||||
"olm/wg/relay": handleOlmRelayMessage,
|
"olm/wg/relay": handleOlmRelayMessage,
|
||||||
"olm/wg/unrelay": handleOlmUnRelayMessage,
|
"olm/wg/unrelay": handleOlmUnRelayMessage,
|
||||||
"olm/ping": handleOlmPingMessage,
|
"olm/ping": handleOlmPingMessage,
|
||||||
|
"newt/ping": handleNewtPingMessage,
|
||||||
"newt/wg/register": handleNewtRegisterMessage,
|
"newt/wg/register": handleNewtRegisterMessage,
|
||||||
"newt/wg/get-config": handleGetConfigMessage,
|
"newt/wg/get-config": handleGetConfigMessage,
|
||||||
"newt/receive-bandwidth": handleReceiveBandwidthMessage,
|
"newt/receive-bandwidth": handleReceiveBandwidthMessage,
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export interface AuthenticatedWebSocket extends WebSocket {
|
|||||||
connectionId?: string;
|
connectionId?: string;
|
||||||
isFullyConnected?: boolean;
|
isFullyConnected?: boolean;
|
||||||
pendingMessages?: Buffer[];
|
pendingMessages?: Buffer[];
|
||||||
|
configVersion?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TokenPayload {
|
export interface TokenPayload {
|
||||||
@@ -36,6 +37,7 @@ export interface TokenPayload {
|
|||||||
export interface WSMessage {
|
export interface WSMessage {
|
||||||
type: string;
|
type: string;
|
||||||
data: any;
|
data: any;
|
||||||
|
configVersion?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HandlerResponse {
|
export interface HandlerResponse {
|
||||||
@@ -43,6 +45,7 @@ export interface HandlerResponse {
|
|||||||
broadcast?: boolean;
|
broadcast?: boolean;
|
||||||
excludeSender?: boolean;
|
excludeSender?: boolean;
|
||||||
targetClientId?: string;
|
targetClientId?: string;
|
||||||
|
options?: SendMessageOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface HandlerContext {
|
export interface HandlerContext {
|
||||||
@@ -50,10 +53,15 @@ export interface HandlerContext {
|
|||||||
senderWs: WebSocket;
|
senderWs: WebSocket;
|
||||||
client: Newt | Olm | RemoteExitNode | undefined;
|
client: Newt | Olm | RemoteExitNode | undefined;
|
||||||
clientType: ClientType;
|
clientType: ClientType;
|
||||||
sendToClient: (clientId: string, message: WSMessage) => Promise<boolean>;
|
sendToClient: (
|
||||||
|
clientId: string,
|
||||||
|
message: WSMessage,
|
||||||
|
options?: SendMessageOptions
|
||||||
|
) => Promise<boolean>;
|
||||||
broadcastToAllExcept: (
|
broadcastToAllExcept: (
|
||||||
message: WSMessage,
|
message: WSMessage,
|
||||||
excludeClientId?: string
|
excludeClientId?: string,
|
||||||
|
options?: SendMessageOptions
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
connectedClients: Map<string, WebSocket[]>;
|
connectedClients: Map<string, WebSocket[]>;
|
||||||
}
|
}
|
||||||
@@ -62,6 +70,11 @@ export type MessageHandler = (
|
|||||||
context: HandlerContext
|
context: HandlerContext
|
||||||
) => Promise<HandlerResponse | void>;
|
) => Promise<HandlerResponse | void>;
|
||||||
|
|
||||||
|
// Options for sending messages with config version tracking
|
||||||
|
export interface SendMessageOptions {
|
||||||
|
incrementConfigVersion?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
// Redis message type for cross-node communication
|
// Redis message type for cross-node communication
|
||||||
export interface RedisMessage {
|
export interface RedisMessage {
|
||||||
type: "direct" | "broadcast";
|
type: "direct" | "broadcast";
|
||||||
@@ -69,4 +82,5 @@ export interface RedisMessage {
|
|||||||
excludeClientId?: string;
|
excludeClientId?: string;
|
||||||
message: WSMessage;
|
message: WSMessage;
|
||||||
fromNodeId: string;
|
fromNodeId: string;
|
||||||
|
options?: SendMessageOptions;
|
||||||
}
|
}
|
||||||
|
|||||||
+68
-14
@@ -15,7 +15,8 @@ import {
|
|||||||
TokenPayload,
|
TokenPayload,
|
||||||
WebSocketRequest,
|
WebSocketRequest,
|
||||||
WSMessage,
|
WSMessage,
|
||||||
AuthenticatedWebSocket
|
AuthenticatedWebSocket,
|
||||||
|
SendMessageOptions
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { validateSessionToken } from "@server/auth/sessions/app";
|
import { validateSessionToken } from "@server/auth/sessions/app";
|
||||||
|
|
||||||
@@ -34,6 +35,8 @@ const NODE_ID = uuidv4();
|
|||||||
|
|
||||||
// Client tracking map (local to this node)
|
// Client tracking map (local to this node)
|
||||||
const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
|
const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
|
||||||
|
// Config version tracking map (clientId -> version)
|
||||||
|
const clientConfigVersions: Map<string, number> = new Map();
|
||||||
// Helper to get map key
|
// Helper to get map key
|
||||||
const getClientMapKey = (clientId: string) => clientId;
|
const getClientMapKey = (clientId: string) => clientId;
|
||||||
|
|
||||||
@@ -84,14 +87,34 @@ const removeClient = async (
|
|||||||
// Local message sending (within this node)
|
// Local message sending (within this node)
|
||||||
const sendToClientLocal = async (
|
const sendToClientLocal = async (
|
||||||
clientId: string,
|
clientId: string,
|
||||||
message: WSMessage
|
message: WSMessage,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
const mapKey = getClientMapKey(clientId);
|
const mapKey = getClientMapKey(clientId);
|
||||||
const clients = connectedClients.get(mapKey);
|
const clients = connectedClients.get(mapKey);
|
||||||
if (!clients || clients.length === 0) {
|
if (!clients || clients.length === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const messageString = JSON.stringify(message);
|
|
||||||
|
// Increment config version if requested
|
||||||
|
if (options.incrementConfigVersion) {
|
||||||
|
const currentVersion = clientConfigVersions.get(clientId) || 0;
|
||||||
|
const newVersion = currentVersion + 1;
|
||||||
|
clientConfigVersions.set(clientId, newVersion);
|
||||||
|
// Update version on all client connections
|
||||||
|
clients.forEach((client) => {
|
||||||
|
client.configVersion = newVersion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include config version in message
|
||||||
|
const configVersion = clientConfigVersions.get(clientId) || 0;
|
||||||
|
const messageWithVersion = {
|
||||||
|
...message,
|
||||||
|
configVersion
|
||||||
|
};
|
||||||
|
|
||||||
|
const messageString = JSON.stringify(messageWithVersion);
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
client.send(messageString);
|
client.send(messageString);
|
||||||
@@ -102,14 +125,31 @@ const sendToClientLocal = async (
|
|||||||
|
|
||||||
const broadcastToAllExceptLocal = async (
|
const broadcastToAllExceptLocal = async (
|
||||||
message: WSMessage,
|
message: WSMessage,
|
||||||
excludeClientId?: string
|
excludeClientId?: string,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
connectedClients.forEach((clients, mapKey) => {
|
connectedClients.forEach((clients, mapKey) => {
|
||||||
const [type, id] = mapKey.split(":");
|
const [type, id] = mapKey.split(":");
|
||||||
if (!(excludeClientId && id === excludeClientId)) {
|
const clientId = mapKey; // mapKey is the clientId
|
||||||
|
if (!(excludeClientId && clientId === excludeClientId)) {
|
||||||
|
// Handle config version per client
|
||||||
|
if (options.incrementConfigVersion) {
|
||||||
|
const currentVersion = clientConfigVersions.get(clientId) || 0;
|
||||||
|
const newVersion = currentVersion + 1;
|
||||||
|
clientConfigVersions.set(clientId, newVersion);
|
||||||
|
clients.forEach((client) => {
|
||||||
|
client.configVersion = newVersion;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Include config version in message for this client
|
||||||
|
const configVersion = clientConfigVersions.get(clientId) || 0;
|
||||||
|
const messageWithVersion = {
|
||||||
|
...message,
|
||||||
|
configVersion
|
||||||
|
};
|
||||||
clients.forEach((client) => {
|
clients.forEach((client) => {
|
||||||
if (client.readyState === WebSocket.OPEN) {
|
if (client.readyState === WebSocket.OPEN) {
|
||||||
client.send(JSON.stringify(message));
|
client.send(JSON.stringify(messageWithVersion));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -119,10 +159,11 @@ const broadcastToAllExceptLocal = async (
|
|||||||
// Cross-node message sending
|
// Cross-node message sending
|
||||||
const sendToClient = async (
|
const sendToClient = async (
|
||||||
clientId: string,
|
clientId: string,
|
||||||
message: WSMessage
|
message: WSMessage,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
// Try to send locally first
|
// Try to send locally first
|
||||||
const localSent = await sendToClientLocal(clientId, message);
|
const localSent = await sendToClientLocal(clientId, message, options);
|
||||||
|
|
||||||
logger.debug(
|
logger.debug(
|
||||||
`sendToClient: Message type ${message.type} sent to clientId ${clientId}`
|
`sendToClient: Message type ${message.type} sent to clientId ${clientId}`
|
||||||
@@ -133,10 +174,11 @@ const sendToClient = async (
|
|||||||
|
|
||||||
const broadcastToAllExcept = async (
|
const broadcastToAllExcept = async (
|
||||||
message: WSMessage,
|
message: WSMessage,
|
||||||
excludeClientId?: string
|
excludeClientId?: string,
|
||||||
|
options: SendMessageOptions = {}
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
// Broadcast locally
|
// Broadcast locally
|
||||||
await broadcastToAllExceptLocal(message, excludeClientId);
|
await broadcastToAllExceptLocal(message, excludeClientId, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Check if a client has active connections across all nodes
|
// Check if a client has active connections across all nodes
|
||||||
@@ -146,6 +188,11 @@ const hasActiveConnections = async (clientId: string): Promise<boolean> => {
|
|||||||
return !!(clients && clients.length > 0);
|
return !!(clients && clients.length > 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get the current config version for a client
|
||||||
|
const getClientConfigVersion = async (clientId: string): Promise<number> => {
|
||||||
|
return clientConfigVersions.get(clientId) || 0;
|
||||||
|
};
|
||||||
|
|
||||||
// Get all active nodes for a client
|
// Get all active nodes for a client
|
||||||
const getActiveNodes = async (
|
const getActiveNodes = async (
|
||||||
clientType: ClientType,
|
clientType: ClientType,
|
||||||
@@ -259,15 +306,21 @@ const setupConnection = async (
|
|||||||
if (response.broadcast) {
|
if (response.broadcast) {
|
||||||
await broadcastToAllExcept(
|
await broadcastToAllExcept(
|
||||||
response.message,
|
response.message,
|
||||||
response.excludeSender ? clientId : undefined
|
response.excludeSender ? clientId : undefined,
|
||||||
|
response.options
|
||||||
);
|
);
|
||||||
} else if (response.targetClientId) {
|
} else if (response.targetClientId) {
|
||||||
await sendToClient(
|
await sendToClient(
|
||||||
response.targetClientId,
|
response.targetClientId,
|
||||||
response.message
|
response.message,
|
||||||
|
response.options
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
ws.send(JSON.stringify(response.message));
|
await sendToClient(
|
||||||
|
clientId,
|
||||||
|
response.message,
|
||||||
|
response.options
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -434,5 +487,6 @@ export {
|
|||||||
getActiveNodes,
|
getActiveNodes,
|
||||||
disconnectClient,
|
disconnectClient,
|
||||||
NODE_ID,
|
NODE_ID,
|
||||||
cleanup
|
cleanup,
|
||||||
|
getClientConfigVersion
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { pullEnv } from "@app/lib/pullEnv";
|
||||||
|
import { build } from "@server/build";
|
||||||
|
import { redirect } from "next/navigation";
|
||||||
|
|
||||||
|
interface LayoutProps {
|
||||||
|
children: React.ReactNode;
|
||||||
|
params: Promise<{}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function Layout(props: LayoutProps) {
|
||||||
|
const env = pullEnv();
|
||||||
|
|
||||||
|
if (build !== "saas" && !env.flags.useOrgOnlyIdp) {
|
||||||
|
redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
return props.children;
|
||||||
|
}
|
||||||
@@ -59,7 +59,9 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
|||||||
username: client.username,
|
username: client.username,
|
||||||
userEmail: client.userEmail,
|
userEmail: client.userEmail,
|
||||||
niceId: client.niceId,
|
niceId: client.niceId,
|
||||||
agent: client.agent
|
agent: client.agent,
|
||||||
|
archived: client.archived || false,
|
||||||
|
blocked: client.blocked || false
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ export default async function ClientsPage(props: ClientsPageProps) {
|
|||||||
username: client.username,
|
username: client.username,
|
||||||
userEmail: client.userEmail,
|
userEmail: client.userEmail,
|
||||||
niceId: client.niceId,
|
niceId: client.niceId,
|
||||||
agent: client.agent
|
agent: client.agent,
|
||||||
|
archived: client.archived || false,
|
||||||
|
blocked: client.blocked || false
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ export default async function SettingsLayout(props: SettingsLayoutProps) {
|
|||||||
<Layout
|
<Layout
|
||||||
orgId={params.orgId}
|
orgId={params.orgId}
|
||||||
orgs={orgs}
|
orgs={orgs}
|
||||||
navItems={orgNavSections()}
|
navItems={orgNavSections(env)}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ import {
|
|||||||
import type { ResourceContextType } from "@app/contexts/resourceContext";
|
import type { ResourceContextType } from "@app/contexts/resourceContext";
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
import { useEnvContext } from "@app/hooks/useEnvContext";
|
||||||
import { useOrgContext } from "@app/hooks/useOrgContext";
|
import { useOrgContext } from "@app/hooks/useOrgContext";
|
||||||
|
import { usePaidStatus } from "@app/hooks/usePaidStatus";
|
||||||
import { useResourceContext } from "@app/hooks/useResourceContext";
|
import { useResourceContext } from "@app/hooks/useResourceContext";
|
||||||
import { useSubscriptionStatusContext } from "@app/hooks/useSubscriptionStatusContext";
|
|
||||||
import { toast } from "@app/hooks/useToast";
|
import { toast } from "@app/hooks/useToast";
|
||||||
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
import { createApiClient, formatAxiosError } from "@app/lib/api";
|
||||||
import { orgQueries, resourceQueries } from "@app/lib/queries";
|
import { orgQueries, resourceQueries } from "@app/lib/queries";
|
||||||
@@ -95,7 +95,7 @@ export default function ResourceAuthenticationPage() {
|
|||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
const subscription = useSubscriptionStatusContext();
|
const { isPaidUser } = usePaidStatus();
|
||||||
|
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const { data: resourceRoles = [], isLoading: isLoadingResourceRoles } =
|
const { data: resourceRoles = [], isLoading: isLoadingResourceRoles } =
|
||||||
@@ -129,7 +129,8 @@ export default function ResourceAuthenticationPage() {
|
|||||||
);
|
);
|
||||||
const { data: orgIdps = [], isLoading: isLoadingOrgIdps } = useQuery(
|
const { data: orgIdps = [], isLoading: isLoadingOrgIdps } = useQuery(
|
||||||
orgQueries.identityProviders({
|
orgQueries.identityProviders({
|
||||||
orgId: org.org.orgId
|
orgId: org.org.orgId,
|
||||||
|
useOrgOnlyIdp: env.flags.useOrgOnlyIdp
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -159,7 +160,7 @@ export default function ResourceAuthenticationPage() {
|
|||||||
|
|
||||||
const allIdps = useMemo(() => {
|
const allIdps = useMemo(() => {
|
||||||
if (build === "saas") {
|
if (build === "saas") {
|
||||||
if (subscription?.subscribed) {
|
if (isPaidUser) {
|
||||||
return orgIdps.map((idp) => ({
|
return orgIdps.map((idp) => ({
|
||||||
id: idp.idpId,
|
id: idp.idpId,
|
||||||
text: idp.name
|
text: idp.name
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { AxiosResponse } from "axios";
|
|||||||
import { authCookieHeader } from "@app/lib/api/cookies";
|
import { authCookieHeader } from "@app/lib/api/cookies";
|
||||||
import { Layout } from "@app/components/Layout";
|
import { Layout } from "@app/components/Layout";
|
||||||
import { adminNavSections } from "../navigation";
|
import { adminNavSections } from "../navigation";
|
||||||
|
import { pullEnv } from "@app/lib/pullEnv";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -27,6 +28,8 @@ export default async function AdminLayout(props: LayoutProps) {
|
|||||||
const getUser = cache(verifySession);
|
const getUser = cache(verifySession);
|
||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
|
|
||||||
|
const env = pullEnv();
|
||||||
|
|
||||||
if (!user || !user.serverAdmin) {
|
if (!user || !user.serverAdmin) {
|
||||||
redirect(`/`);
|
redirect(`/`);
|
||||||
}
|
}
|
||||||
@@ -48,7 +51,7 @@ export default async function AdminLayout(props: LayoutProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<UserProvider user={user}>
|
<UserProvider user={user}>
|
||||||
<Layout orgs={orgs} navItems={adminNavSections}>
|
<Layout orgs={orgs} navItems={adminNavSections(env)}>
|
||||||
{props.children}
|
{props.children}
|
||||||
</Layout>
|
</Layout>
|
||||||
</UserProvider>
|
</UserProvider>
|
||||||
|
|||||||
+1
-21
@@ -44,7 +44,7 @@ export default async function AuthLayout({ children }: AuthLayoutProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="h-full flex flex-col">
|
<div className="h-full flex flex-col">
|
||||||
<div className="flex justify-end items-center p-3 space-x-2">
|
<div className="hidden md:flex justify-end items-center p-3 space-x-2">
|
||||||
<ThemeSwitcher />
|
<ThemeSwitcher />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -127,26 +127,6 @@ export default async function AuthLayout({ children }: AuthLayoutProps) {
|
|||||||
</a>
|
</a>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<Separator orientation="vertical" />
|
|
||||||
<a
|
|
||||||
href="https://docs.pangolin.net"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
aria-label="Built by Fossorial"
|
|
||||||
className="flex items-center space-x-2 whitespace-nowrap"
|
|
||||||
>
|
|
||||||
<span>{t("docs")}</span>
|
|
||||||
</a>
|
|
||||||
<Separator orientation="vertical" />
|
|
||||||
<a
|
|
||||||
href="https://github.com/fosrl/pangolin"
|
|
||||||
target="_blank"
|
|
||||||
rel="noopener noreferrer"
|
|
||||||
aria-label="GitHub"
|
|
||||||
className="flex items-center space-x-2 whitespace-nowrap"
|
|
||||||
>
|
|
||||||
<span>{t("github")}</span>
|
|
||||||
</a>
|
|
||||||
</div>
|
</div>
|
||||||
</footer>
|
</footer>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
|||||||
import { CheckCircle2 } from "lucide-react";
|
import { CheckCircle2 } from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
|
import { useEffect } from "react";
|
||||||
|
|
||||||
export default function DeviceAuthSuccessPage() {
|
export default function DeviceAuthSuccessPage() {
|
||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
@@ -20,6 +21,32 @@ export default function DeviceAuthSuccessPage() {
|
|||||||
? env.branding.logo?.authPage?.height || 58
|
? env.branding.logo?.authPage?.height || 58
|
||||||
: 58;
|
: 58;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
// Detect if we're on iOS or Android
|
||||||
|
const userAgent = navigator.userAgent || navigator.vendor || (window as any).opera;
|
||||||
|
const isIOS = /iPad|iPhone|iPod/.test(userAgent) && !(window as any).MSStream;
|
||||||
|
const isAndroid = /android/i.test(userAgent);
|
||||||
|
|
||||||
|
if (isAndroid) {
|
||||||
|
// For Android Chrome Custom Tabs, use intent:// scheme which works more reliably
|
||||||
|
// This explicitly tells Chrome to send an intent to the app, which will bring
|
||||||
|
// SignInCodeActivity back to the foreground (it has launchMode="singleTop")
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = "intent://auth-success#Intent;scheme=pangolin;package=net.pangolin.Pangolin;end";
|
||||||
|
}, 500);
|
||||||
|
} else if (isIOS) {
|
||||||
|
// Wait 500ms then attempt to open the app
|
||||||
|
setTimeout(() => {
|
||||||
|
// Try to open the app using deep link
|
||||||
|
window.location.href = "pangolin://";
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.href = "https://apps.apple.com/app/pangolin/net.pangolin.Pangolin.PangoliniOS";
|
||||||
|
}, 2000);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Card>
|
<Card>
|
||||||
@@ -55,4 +82,4 @@ export default function DeviceAuthSuccessPage() {
|
|||||||
</p>
|
</p>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ export default async function Page(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let loginIdps: LoginFormIDP[] = [];
|
let loginIdps: LoginFormIDP[] = [];
|
||||||
if (build !== "saas") {
|
if (build === "oss" || !env.flags.useOrgOnlyIdp) {
|
||||||
const idpsRes = await cache(
|
const idpsRes = await cache(
|
||||||
async () => await priv.get<AxiosResponse<ListIdpsResponse>>("/idp")
|
async () => await priv.get<AxiosResponse<ListIdpsResponse>>("/idp")
|
||||||
)();
|
)();
|
||||||
@@ -103,6 +103,10 @@ export default async function Page(props: {
|
|||||||
redirect={redirectUrl}
|
redirect={redirectUrl}
|
||||||
idps={loginIdps}
|
idps={loginIdps}
|
||||||
forceLogin={forceLogin}
|
forceLogin={forceLogin}
|
||||||
|
showOrgLogin={
|
||||||
|
!isInvite && (build === "saas" || env.flags.useOrgOnlyIdp)
|
||||||
|
}
|
||||||
|
searchParams={searchParams}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{(!signUpDisabled || isInvite) && (
|
{(!signUpDisabled || isInvite) && (
|
||||||
@@ -120,35 +124,6 @@ export default async function Page(props: {
|
|||||||
</Link>
|
</Link>
|
||||||
</p>
|
</p>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{!isInvite && build === "saas" ? (
|
|
||||||
<div className="text-center text-muted-foreground mt-12 flex flex-col items-center">
|
|
||||||
<span>{t("needToSignInToOrg")}</span>
|
|
||||||
<Link
|
|
||||||
href={`/auth/org${buildQueryString(searchParams)}`}
|
|
||||||
className="underline"
|
|
||||||
>
|
|
||||||
{t("orgAuthSignInToOrg")}
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
) : null}
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildQueryString(searchParams: {
|
|
||||||
[key: string]: string | string[] | undefined;
|
|
||||||
}): string {
|
|
||||||
const params = new URLSearchParams();
|
|
||||||
const redirect = searchParams.redirect;
|
|
||||||
const forceLogin = searchParams.forceLogin;
|
|
||||||
|
|
||||||
if (redirect && typeof redirect === "string") {
|
|
||||||
params.set("redirect", redirect);
|
|
||||||
}
|
|
||||||
if (forceLogin && typeof forceLogin === "string") {
|
|
||||||
params.set("forceLogin", forceLogin);
|
|
||||||
}
|
|
||||||
const queryString = params.toString();
|
|
||||||
return queryString ? `?${queryString}` : "";
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from "@server/routers/loginPage/types";
|
} from "@server/routers/loginPage/types";
|
||||||
import { redirect } from "next/navigation";
|
import { redirect } from "next/navigation";
|
||||||
import OrgLoginPage from "@app/components/OrgLoginPage";
|
import OrgLoginPage from "@app/components/OrgLoginPage";
|
||||||
|
import { pullEnv } from "@app/lib/pullEnv";
|
||||||
|
|
||||||
export const dynamic = "force-dynamic";
|
export const dynamic = "force-dynamic";
|
||||||
|
|
||||||
@@ -21,7 +22,9 @@ export default async function OrgAuthPage(props: {
|
|||||||
const searchParams = await props.searchParams;
|
const searchParams = await props.searchParams;
|
||||||
const params = await props.params;
|
const params = await props.params;
|
||||||
|
|
||||||
if (build !== "saas") {
|
const env = pullEnv();
|
||||||
|
|
||||||
|
if (build !== "saas" && !env.flags.useOrgOnlyIdp) {
|
||||||
const queryString = new URLSearchParams(searchParams as any).toString();
|
const queryString = new URLSearchParams(searchParams as any).toString();
|
||||||
redirect(`/auth/login${queryString ? `?${queryString}` : ""}`);
|
redirect(`/auth/login${queryString ? `?${queryString}` : ""}`);
|
||||||
}
|
}
|
||||||
@@ -50,29 +53,25 @@ export default async function OrgAuthPage(props: {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
let loginIdps: LoginFormIDP[] = [];
|
let loginIdps: LoginFormIDP[] = [];
|
||||||
if (build === "saas") {
|
const idpsRes = await priv.get<AxiosResponse<ListOrgIdpsResponse>>(
|
||||||
const idpsRes = await priv.get<AxiosResponse<ListOrgIdpsResponse>>(
|
`/org/${orgId}/idp`
|
||||||
`/org/${orgId}/idp`
|
);
|
||||||
);
|
|
||||||
|
|
||||||
loginIdps = idpsRes.data.data.idps.map((idp) => ({
|
loginIdps = idpsRes.data.data.idps.map((idp) => ({
|
||||||
idpId: idp.idpId,
|
idpId: idp.idpId,
|
||||||
name: idp.name,
|
name: idp.name,
|
||||||
variant: idp.variant
|
variant: idp.variant
|
||||||
})) as LoginFormIDP[];
|
})) as LoginFormIDP[];
|
||||||
}
|
|
||||||
|
|
||||||
let branding: LoadLoginPageBrandingResponse | null = null;
|
let branding: LoadLoginPageBrandingResponse | null = null;
|
||||||
if (build === "saas") {
|
try {
|
||||||
try {
|
const res = await priv.get<
|
||||||
const res = await priv.get<
|
AxiosResponse<LoadLoginPageBrandingResponse>
|
||||||
AxiosResponse<LoadLoginPageBrandingResponse>
|
>(`/login-page-branding?orgId=${orgId}`);
|
||||||
>(`/login-page-branding?orgId=${orgId}`);
|
if (res.status === 200) {
|
||||||
if (res.status === 200) {
|
branding = res.data.data;
|
||||||
branding = res.data.data;
|
}
|
||||||
}
|
} catch (error) {}
|
||||||
} catch (error) {}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<OrgLoginPage
|
<OrgLoginPage
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ export default async function OrgAuthPage(props: {
|
|||||||
const forceLoginParam = searchParams.forceLogin;
|
const forceLoginParam = searchParams.forceLogin;
|
||||||
const forceLogin = forceLoginParam === "true";
|
const forceLogin = forceLoginParam === "true";
|
||||||
|
|
||||||
if (build !== "saas") {
|
const env = pullEnv();
|
||||||
|
|
||||||
|
if (build !== "saas" && !env.flags.useOrgOnlyIdp) {
|
||||||
redirect("/");
|
redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
const env = pullEnv();
|
|
||||||
|
|
||||||
const authHeader = await authCookieHeader();
|
const authHeader = await authCookieHeader();
|
||||||
|
|
||||||
if (searchParams.token) {
|
if (searchParams.token) {
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ export default async function ResourceAuthPage(props: {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let loginIdps: LoginFormIDP[] = [];
|
let loginIdps: LoginFormIDP[] = [];
|
||||||
if (build === "saas") {
|
if (build === "saas" || env.flags.useOrgOnlyIdp) {
|
||||||
if (subscribed) {
|
if (subscribed) {
|
||||||
const idpsRes = await cache(
|
const idpsRes = await cache(
|
||||||
async () =>
|
async () =>
|
||||||
|
|||||||
+15
-12
@@ -1,4 +1,5 @@
|
|||||||
import { SidebarNavItem } from "@app/components/SidebarNav";
|
import { SidebarNavItem } from "@app/components/SidebarNav";
|
||||||
|
import { Env } from "@app/lib/types/env";
|
||||||
import { build } from "@server/build";
|
import { build } from "@server/build";
|
||||||
import {
|
import {
|
||||||
Settings,
|
Settings,
|
||||||
@@ -39,7 +40,7 @@ export const orgLangingNavItems: SidebarNavItem[] = [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
export const orgNavSections = (): SidebarNavSection[] => [
|
export const orgNavSections = (env?: Env): SidebarNavSection[] => [
|
||||||
{
|
{
|
||||||
heading: "sidebarGeneral",
|
heading: "sidebarGeneral",
|
||||||
items: [
|
items: [
|
||||||
@@ -92,8 +93,7 @@ export const orgNavSections = (): SidebarNavSection[] => [
|
|||||||
{
|
{
|
||||||
title: "sidebarRemoteExitNodes",
|
title: "sidebarRemoteExitNodes",
|
||||||
href: "/{orgId}/settings/remote-exit-nodes",
|
href: "/{orgId}/settings/remote-exit-nodes",
|
||||||
icon: <Server className="size-4 flex-none" />,
|
icon: <Server className="size-4 flex-none" />
|
||||||
showEE: true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
: [])
|
: [])
|
||||||
@@ -123,13 +123,12 @@ export const orgNavSections = (): SidebarNavSection[] => [
|
|||||||
href: "/{orgId}/settings/access/roles",
|
href: "/{orgId}/settings/access/roles",
|
||||||
icon: <Users className="size-4 flex-none" />
|
icon: <Users className="size-4 flex-none" />
|
||||||
},
|
},
|
||||||
...(build == "saas"
|
...(build == "saas" || env?.flags.useOrgOnlyIdp
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
title: "sidebarIdentityProviders",
|
title: "sidebarIdentityProviders",
|
||||||
href: "/{orgId}/settings/idp",
|
href: "/{orgId}/settings/idp",
|
||||||
icon: <Fingerprint className="size-4 flex-none" />,
|
icon: <Fingerprint className="size-4 flex-none" />
|
||||||
showEE: true
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
: []),
|
: []),
|
||||||
@@ -228,7 +227,7 @@ export const orgNavSections = (): SidebarNavSection[] => [
|
|||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
export const adminNavSections: SidebarNavSection[] = [
|
export const adminNavSections = (env?: Env): SidebarNavSection[] => [
|
||||||
{
|
{
|
||||||
heading: "sidebarAdmin",
|
heading: "sidebarAdmin",
|
||||||
items: [
|
items: [
|
||||||
@@ -242,11 +241,15 @@ export const adminNavSections: SidebarNavSection[] = [
|
|||||||
href: "/admin/api-keys",
|
href: "/admin/api-keys",
|
||||||
icon: <KeyRound className="size-4 flex-none" />
|
icon: <KeyRound className="size-4 flex-none" />
|
||||||
},
|
},
|
||||||
{
|
...(build === "oss" || !env?.flags.useOrgOnlyIdp
|
||||||
title: "sidebarIdentityProviders",
|
? [
|
||||||
href: "/admin/idp",
|
{
|
||||||
icon: <Fingerprint className="size-4 flex-none" />
|
title: "sidebarIdentityProviders",
|
||||||
},
|
href: "/admin/idp",
|
||||||
|
icon: <Fingerprint className="size-4 flex-none" />
|
||||||
|
}
|
||||||
|
]
|
||||||
|
: []),
|
||||||
...(build == "enterprise"
|
...(build == "enterprise"
|
||||||
? [
|
? [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -118,6 +118,7 @@ export default function AuthPageBrandingForm({
|
|||||||
const brandingData = form.getValues();
|
const brandingData = form.getValues();
|
||||||
|
|
||||||
if (!isValid || !isPaidUser) return;
|
if (!isValid || !isPaidUser) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const updateRes = await api.put(
|
const updateRes = await api.put(
|
||||||
`/org/${orgId}/login-page-branding`,
|
`/org/${orgId}/login-page-branding`,
|
||||||
@@ -289,7 +290,8 @@ export default function AuthPageBrandingForm({
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{build === "saas" && (
|
{build === "saas" ||
|
||||||
|
env.env.flags.useOrgOnlyIdp ? (
|
||||||
<>
|
<>
|
||||||
<div className="mt-3 mb-6">
|
<div className="mt-3 mb-6">
|
||||||
<SettingsSectionTitle>
|
<SettingsSectionTitle>
|
||||||
@@ -343,7 +345,7 @@ export default function AuthPageBrandingForm({
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
) : null}
|
||||||
|
|
||||||
<div className="mt-3 mb-6">
|
<div className="mt-3 mb-6">
|
||||||
<SettingsSectionTitle>
|
<SettingsSectionTitle>
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ export default function ConfirmDeleteDialog({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const isConfirmed = form.watch("string") === string;
|
||||||
|
|
||||||
async function onSubmit() {
|
async function onSubmit() {
|
||||||
try {
|
try {
|
||||||
await onConfirm();
|
await onConfirm();
|
||||||
@@ -139,7 +141,8 @@ export default function ConfirmDeleteDialog({
|
|||||||
type="submit"
|
type="submit"
|
||||||
form="confirm-delete-form"
|
form="confirm-delete-form"
|
||||||
loading={loading}
|
loading={loading}
|
||||||
disabled={loading}
|
disabled={loading || !isConfirmed}
|
||||||
|
className={!isConfirmed && !loading ? "opacity-50" : ""}
|
||||||
>
|
>
|
||||||
{buttonText}
|
{buttonText}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -17,17 +17,26 @@ import { cleanRedirect } from "@app/lib/cleanRedirect";
|
|||||||
import BrandingLogo from "@app/components/BrandingLogo";
|
import BrandingLogo from "@app/components/BrandingLogo";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
import { useLicenseStatusContext } from "@app/hooks/useLicenseStatusContext";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { Button } from "./ui/button";
|
||||||
|
import { ArrowRight } from "lucide-react";
|
||||||
|
|
||||||
type DashboardLoginFormProps = {
|
type DashboardLoginFormProps = {
|
||||||
redirect?: string;
|
redirect?: string;
|
||||||
idps?: LoginFormIDP[];
|
idps?: LoginFormIDP[];
|
||||||
forceLogin?: boolean;
|
forceLogin?: boolean;
|
||||||
|
showOrgLogin?: boolean;
|
||||||
|
searchParams?: {
|
||||||
|
[key: string]: string | string[] | undefined;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function DashboardLoginForm({
|
export default function DashboardLoginForm({
|
||||||
redirect,
|
redirect,
|
||||||
idps,
|
idps,
|
||||||
forceLogin
|
forceLogin,
|
||||||
|
showOrgLogin,
|
||||||
|
searchParams
|
||||||
}: DashboardLoginFormProps) {
|
}: DashboardLoginFormProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const { env } = useEnvContext();
|
const { env } = useEnvContext();
|
||||||
@@ -35,6 +44,9 @@ export default function DashboardLoginForm({
|
|||||||
const { isUnlocked } = useLicenseStatusContext();
|
const { isUnlocked } = useLicenseStatusContext();
|
||||||
|
|
||||||
function getSubtitle() {
|
function getSubtitle() {
|
||||||
|
if (forceLogin) {
|
||||||
|
return t("loginRequiredForDevice");
|
||||||
|
}
|
||||||
if (isUnlocked() && env.branding?.loginPage?.subtitleText) {
|
if (isUnlocked() && env.branding?.loginPage?.subtitleText) {
|
||||||
return env.branding.loginPage.subtitleText;
|
return env.branding.loginPage.subtitleText;
|
||||||
}
|
}
|
||||||
@@ -57,6 +69,22 @@ export default function DashboardLoginForm({
|
|||||||
<div className="text-center space-y-1 pt-3">
|
<div className="text-center space-y-1 pt-3">
|
||||||
<p className="text-muted-foreground">{getSubtitle()}</p>
|
<p className="text-muted-foreground">{getSubtitle()}</p>
|
||||||
</div>
|
</div>
|
||||||
|
{showOrgLogin && (
|
||||||
|
<div className="space-y-2 mt-4">
|
||||||
|
<Link
|
||||||
|
href={`/auth/org${buildQueryString(searchParams || {})}`}
|
||||||
|
className="underline"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="secondary"
|
||||||
|
className="w-full gap-2"
|
||||||
|
>
|
||||||
|
{t("orgAuthSignInToOrg")}
|
||||||
|
<ArrowRight className="h-4 w-4" />
|
||||||
|
</Button>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent className="pt-6">
|
<CardContent className="pt-6">
|
||||||
<LoginForm
|
<LoginForm
|
||||||
@@ -76,3 +104,20 @@ export default function DashboardLoginForm({
|
|||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function buildQueryString(searchParams: {
|
||||||
|
[key: string]: string | string[] | undefined;
|
||||||
|
}): string {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
const redirect = searchParams.redirect;
|
||||||
|
const forceLogin = searchParams.forceLogin;
|
||||||
|
|
||||||
|
if (redirect && typeof redirect === "string") {
|
||||||
|
params.set("redirect", redirect);
|
||||||
|
}
|
||||||
|
if (forceLogin && typeof forceLogin === "string") {
|
||||||
|
params.set("forceLogin", forceLogin);
|
||||||
|
}
|
||||||
|
const queryString = params.toString();
|
||||||
|
return queryString ? `?${queryString}` : "";
|
||||||
|
}
|
||||||
|
|||||||
@@ -85,8 +85,6 @@ export default function DeviceLoginForm({
|
|||||||
data.code = data.code.slice(0, 4) + "-" + data.code.slice(4);
|
data.code = data.code.slice(0, 4) + "-" + data.code.slice(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
||||||
|
|
||||||
// First check - get metadata
|
// First check - get metadata
|
||||||
const res = await api.post(
|
const res = await api.post(
|
||||||
"/device-web-auth/verify?forceLogin=true",
|
"/device-web-auth/verify?forceLogin=true",
|
||||||
@@ -117,8 +115,6 @@ export default function DeviceLoginForm({
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
||||||
|
|
||||||
// Final verify
|
// Final verify
|
||||||
await api.post("/device-web-auth/verify", {
|
await api.post("/device-web-auth/verify", {
|
||||||
code: code,
|
code: code,
|
||||||
|
|||||||
@@ -409,15 +409,6 @@ export default function LoginForm({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
{forceLogin && (
|
|
||||||
<Alert variant="neutral">
|
|
||||||
<AlertDescription className="flex items-center gap-2">
|
|
||||||
<LockIcon className="w-4 h-4" />
|
|
||||||
{t("loginRequiredForDevice")}
|
|
||||||
</AlertDescription>
|
|
||||||
</Alert>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{showSecurityKeyPrompt && (
|
{showSecurityKeyPrompt && (
|
||||||
<Alert>
|
<Alert>
|
||||||
<FingerprintIcon className="w-5 h-5 mr-2" />
|
<FingerprintIcon className="w-5 h-5 mr-2" />
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ import {
|
|||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUpDown,
|
ArrowUpDown,
|
||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
MoreHorizontal
|
MoreHorizontal,
|
||||||
|
CircleSlash
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -42,6 +43,8 @@ export type ClientRow = {
|
|||||||
userEmail: string | null;
|
userEmail: string | null;
|
||||||
niceId: string;
|
niceId: string;
|
||||||
agent: string | null;
|
agent: string | null;
|
||||||
|
archived?: boolean;
|
||||||
|
blocked?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClientTableProps = {
|
type ClientTableProps = {
|
||||||
@@ -58,6 +61,7 @@ export default function MachineClientsTable({
|
|||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const [isBlockModalOpen, setIsBlockModalOpen] = useState(false);
|
||||||
const [selectedClient, setSelectedClient] = useState<ClientRow | null>(
|
const [selectedClient, setSelectedClient] = useState<ClientRow | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@@ -103,6 +107,76 @@ export default function MachineClientsTable({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const archiveClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/archive`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error archiving client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error archiving client",
|
||||||
|
description: formatAxiosError(e, "Error archiving client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unarchiveClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/unarchive`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error unarchiving client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error unarchiving client",
|
||||||
|
description: formatAxiosError(e, "Error unarchiving client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const blockClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/block`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error blocking client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error blocking client",
|
||||||
|
description: formatAxiosError(e, "Error blocking client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
setIsBlockModalOpen(false);
|
||||||
|
setSelectedClient(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unblockClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/unblock`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error unblocking client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error unblocking client",
|
||||||
|
description: formatAxiosError(e, "Error unblocking client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Check if there are any rows without userIds in the current view's data
|
// Check if there are any rows without userIds in the current view's data
|
||||||
const hasRowsWithoutUserId = useMemo(() => {
|
const hasRowsWithoutUserId = useMemo(() => {
|
||||||
return machineClients.some((client) => !client.userId) ?? false;
|
return machineClients.some((client) => !client.userId) ?? false;
|
||||||
@@ -128,6 +202,25 @@ export default function MachineClientsTable({
|
|||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const r = row.original;
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{r.name}</span>
|
||||||
|
{r.archived && (
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{t("archived")}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
{r.blocked && (
|
||||||
|
<Badge variant="destructive" className="flex items-center gap-1">
|
||||||
|
<CircleSlash className="h-3 w-3" />
|
||||||
|
{t("blocked")}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -307,14 +400,33 @@ export default function MachineClientsTable({
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{/* <Link */}
|
<DropdownMenuItem
|
||||||
{/* className="block w-full" */}
|
onClick={() => {
|
||||||
{/* href={`/${clientRow.orgId}/settings/sites/${clientRow.nice}`} */}
|
if (clientRow.archived) {
|
||||||
{/* > */}
|
unarchiveClient(clientRow.id);
|
||||||
{/* <DropdownMenuItem> */}
|
} else {
|
||||||
{/* View settings */}
|
archiveClient(clientRow.id);
|
||||||
{/* </DropdownMenuItem> */}
|
}
|
||||||
{/* </Link> */}
|
}}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{clientRow.archived ? "Unarchive" : "Archive"}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
if (clientRow.blocked) {
|
||||||
|
unblockClient(clientRow.id);
|
||||||
|
} else {
|
||||||
|
setSelectedClient(clientRow);
|
||||||
|
setIsBlockModalOpen(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span>
|
||||||
|
{clientRow.blocked ? "Unblock" : "Block"}
|
||||||
|
</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedClient(clientRow);
|
setSelectedClient(clientRow);
|
||||||
@@ -365,6 +477,27 @@ export default function MachineClientsTable({
|
|||||||
title="Delete Client"
|
title="Delete Client"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{selectedClient && (
|
||||||
|
<ConfirmDeleteDialog
|
||||||
|
open={isBlockModalOpen}
|
||||||
|
setOpen={(val) => {
|
||||||
|
setIsBlockModalOpen(val);
|
||||||
|
if (!val) {
|
||||||
|
setSelectedClient(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
dialog={
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p>{t("blockClientQuestion")}</p>
|
||||||
|
<p>{t("blockClientMessage")}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
buttonText={t("blockClientConfirm")}
|
||||||
|
onConfirm={async () => blockClient(selectedClient!.id)}
|
||||||
|
string={selectedClient.name}
|
||||||
|
title={t("blockClient")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<DataTable
|
<DataTable
|
||||||
columns={columns}
|
columns={columns}
|
||||||
@@ -383,6 +516,43 @@ export default function MachineClientsTable({
|
|||||||
columnVisibility={defaultMachineColumnVisibility}
|
columnVisibility={defaultMachineColumnVisibility}
|
||||||
stickyLeftColumn="name"
|
stickyLeftColumn="name"
|
||||||
stickyRightColumn="actions"
|
stickyRightColumn="actions"
|
||||||
|
filters={[
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
label: t("status") || "Status",
|
||||||
|
multiSelect: true,
|
||||||
|
displayMode: "calculated",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "active",
|
||||||
|
label: t("active") || "Active",
|
||||||
|
value: "active"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "archived",
|
||||||
|
label: t("archived") || "Archived",
|
||||||
|
value: "archived"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "blocked",
|
||||||
|
label: t("blocked") || "Blocked",
|
||||||
|
value: "blocked"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
filterFn: (row: ClientRow, selectedValues: (string | number | boolean)[]) => {
|
||||||
|
if (selectedValues.length === 0) return true;
|
||||||
|
const rowArchived = row.archived || false;
|
||||||
|
const rowBlocked = row.blocked || false;
|
||||||
|
const isActive = !rowArchived && !rowBlocked;
|
||||||
|
|
||||||
|
if (selectedValues.includes("active") && isActive) return true;
|
||||||
|
if (selectedValues.includes("archived") && rowArchived) return true;
|
||||||
|
if (selectedValues.includes("blocked") && rowBlocked) return true;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
defaultValues: ["active"] // Default to showing active clients
|
||||||
|
}
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -103,6 +103,10 @@ function getActionsCategories(root: boolean) {
|
|||||||
Client: {
|
Client: {
|
||||||
[t("actionCreateClient")]: "createClient",
|
[t("actionCreateClient")]: "createClient",
|
||||||
[t("actionDeleteClient")]: "deleteClient",
|
[t("actionDeleteClient")]: "deleteClient",
|
||||||
|
[t("actionArchiveClient")]: "archiveClient",
|
||||||
|
[t("actionUnarchiveClient")]: "unarchiveClient",
|
||||||
|
[t("actionBlockClient")]: "blockClient",
|
||||||
|
[t("actionUnblockClient")]: "unblockClient",
|
||||||
[t("actionUpdateClient")]: "updateClient",
|
[t("actionUpdateClient")]: "updateClient",
|
||||||
[t("actionListClients")]: "listClients",
|
[t("actionListClients")]: "listClients",
|
||||||
[t("actionGetClient")]: "getClient"
|
[t("actionGetClient")]: "getClient"
|
||||||
@@ -114,6 +118,16 @@ function getActionsCategories(root: boolean) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (root || build === "saas" || env.flags.useOrgOnlyIdp) {
|
||||||
|
actionsByCategory["Identity Provider (IDP)"] = {
|
||||||
|
[t("actionCreateIdp")]: "createIdp",
|
||||||
|
[t("actionUpdateIdp")]: "updateIdp",
|
||||||
|
[t("actionDeleteIdp")]: "deleteIdp",
|
||||||
|
[t("actionListIdps")]: "listIdps",
|
||||||
|
[t("actionGetIdp")]: "getIdp"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (root) {
|
if (root) {
|
||||||
actionsByCategory["Organization"] = {
|
actionsByCategory["Organization"] = {
|
||||||
[t("actionListOrgs")]: "listOrgs",
|
[t("actionListOrgs")]: "listOrgs",
|
||||||
@@ -128,24 +142,21 @@ function getActionsCategories(root: boolean) {
|
|||||||
...actionsByCategory["Organization"]
|
...actionsByCategory["Organization"]
|
||||||
};
|
};
|
||||||
|
|
||||||
actionsByCategory["Identity Provider (IDP)"] = {
|
actionsByCategory["Identity Provider (IDP)"][t("actionCreateIdpOrg")] =
|
||||||
[t("actionCreateIdp")]: "createIdp",
|
"createIdpOrg";
|
||||||
[t("actionUpdateIdp")]: "updateIdp",
|
actionsByCategory["Identity Provider (IDP)"][t("actionDeleteIdpOrg")] =
|
||||||
[t("actionDeleteIdp")]: "deleteIdp",
|
"deleteIdpOrg";
|
||||||
[t("actionListIdps")]: "listIdps",
|
actionsByCategory["Identity Provider (IDP)"][t("actionListIdpOrgs")] =
|
||||||
[t("actionGetIdp")]: "getIdp",
|
"listIdpOrgs";
|
||||||
[t("actionCreateIdpOrg")]: "createIdpOrg",
|
actionsByCategory["Identity Provider (IDP)"][t("actionUpdateIdpOrg")] =
|
||||||
[t("actionDeleteIdpOrg")]: "deleteIdpOrg",
|
"updateIdpOrg";
|
||||||
[t("actionListIdpOrgs")]: "listIdpOrgs",
|
|
||||||
[t("actionUpdateIdpOrg")]: "updateIdpOrg"
|
|
||||||
};
|
|
||||||
|
|
||||||
actionsByCategory["User"] = {
|
actionsByCategory["User"] = {
|
||||||
[t("actionUpdateUser")]: "updateUser",
|
[t("actionUpdateUser")]: "updateUser",
|
||||||
[t("actionGetUser")]: "getUser"
|
[t("actionGetUser")]: "getUser"
|
||||||
};
|
};
|
||||||
|
|
||||||
if (build == "saas") {
|
if (build === "saas") {
|
||||||
actionsByCategory["SAAS"] = {
|
actionsByCategory["SAAS"] = {
|
||||||
["Send Usage Notification Email"]: "sendUsageNotification"
|
["Send Usage Notification Email"]: "sendUsageNotification"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ import {
|
|||||||
ArrowRight,
|
ArrowRight,
|
||||||
ArrowUpDown,
|
ArrowUpDown,
|
||||||
ArrowUpRight,
|
ArrowUpRight,
|
||||||
MoreHorizontal
|
MoreHorizontal,
|
||||||
|
CircleSlash
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
@@ -43,6 +44,8 @@ export type ClientRow = {
|
|||||||
userEmail: string | null;
|
userEmail: string | null;
|
||||||
niceId: string;
|
niceId: string;
|
||||||
agent: string | null;
|
agent: string | null;
|
||||||
|
archived?: boolean;
|
||||||
|
blocked?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
type ClientTableProps = {
|
type ClientTableProps = {
|
||||||
@@ -55,6 +58,7 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
||||||
|
const [isBlockModalOpen, setIsBlockModalOpen] = useState(false);
|
||||||
const [selectedClient, setSelectedClient] = useState<ClientRow | null>(
|
const [selectedClient, setSelectedClient] = useState<ClientRow | null>(
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
@@ -99,6 +103,76 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const archiveClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/archive`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error archiving client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error archiving client",
|
||||||
|
description: formatAxiosError(e, "Error archiving client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unarchiveClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/unarchive`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error unarchiving client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error unarchiving client",
|
||||||
|
description: formatAxiosError(e, "Error unarchiving client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const blockClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/block`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error blocking client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error blocking client",
|
||||||
|
description: formatAxiosError(e, "Error blocking client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
setIsBlockModalOpen(false);
|
||||||
|
setSelectedClient(null);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const unblockClient = (clientId: number) => {
|
||||||
|
api.post(`/client/${clientId}/unblock`)
|
||||||
|
.catch((e) => {
|
||||||
|
console.error("Error unblocking client", e);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: "Error unblocking client",
|
||||||
|
description: formatAxiosError(e, "Error unblocking client")
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
startTransition(() => {
|
||||||
|
router.refresh();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Check if there are any rows without userIds in the current view's data
|
// Check if there are any rows without userIds in the current view's data
|
||||||
const hasRowsWithoutUserId = useMemo(() => {
|
const hasRowsWithoutUserId = useMemo(() => {
|
||||||
return userClients.some((client) => !client.userId);
|
return userClients.some((client) => !client.userId);
|
||||||
@@ -124,6 +198,25 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
<ArrowUpDown className="ml-2 h-4 w-4" />
|
<ArrowUpDown className="ml-2 h-4 w-4" />
|
||||||
</Button>
|
</Button>
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
cell: ({ row }) => {
|
||||||
|
const r = row.original;
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<span>{r.name}</span>
|
||||||
|
{r.archived && (
|
||||||
|
<Badge variant="secondary">
|
||||||
|
{t("archived")}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
{r.blocked && (
|
||||||
|
<Badge variant="destructive" className="flex items-center gap-1">
|
||||||
|
<CircleSlash className="h-3 w-3" />
|
||||||
|
{t("blocked")}
|
||||||
|
</Badge>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -348,7 +441,7 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
header: () => <span className="p-3"></span>,
|
header: () => <span className="p-3"></span>,
|
||||||
cell: ({ row }) => {
|
cell: ({ row }) => {
|
||||||
const clientRow = row.original;
|
const clientRow = row.original;
|
||||||
return !clientRow.userId ? (
|
return (
|
||||||
<div className="flex items-center gap-2 justify-end">
|
<div className="flex items-center gap-2 justify-end">
|
||||||
<DropdownMenu>
|
<DropdownMenu>
|
||||||
<DropdownMenuTrigger asChild>
|
<DropdownMenuTrigger asChild>
|
||||||
@@ -358,34 +451,52 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
</Button>
|
</Button>
|
||||||
</DropdownMenuTrigger>
|
</DropdownMenuTrigger>
|
||||||
<DropdownMenuContent align="end">
|
<DropdownMenuContent align="end">
|
||||||
{/* <Link */}
|
|
||||||
{/* className="block w-full" */}
|
|
||||||
{/* href={`/${clientRow.orgId}/settings/sites/${clientRow.nice}`} */}
|
|
||||||
{/* > */}
|
|
||||||
{/* <DropdownMenuItem> */}
|
|
||||||
{/* View settings */}
|
|
||||||
{/* </DropdownMenuItem> */}
|
|
||||||
{/* </Link> */}
|
|
||||||
<DropdownMenuItem
|
<DropdownMenuItem
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setSelectedClient(clientRow);
|
if (clientRow.archived) {
|
||||||
setIsDeleteModalOpen(true);
|
unarchiveClient(clientRow.id);
|
||||||
|
} else {
|
||||||
|
archiveClient(clientRow.id);
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<span className="text-red-500">Delete</span>
|
<span>{clientRow.archived ? "Unarchive" : "Archive"}</span>
|
||||||
</DropdownMenuItem>
|
</DropdownMenuItem>
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
if (clientRow.blocked) {
|
||||||
|
unblockClient(clientRow.id);
|
||||||
|
} else {
|
||||||
|
setSelectedClient(clientRow);
|
||||||
|
setIsBlockModalOpen(true);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span>{clientRow.blocked ? "Unblock" : "Block"}</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
{!clientRow.userId && (
|
||||||
|
// Machine client - also show delete option
|
||||||
|
<DropdownMenuItem
|
||||||
|
onClick={() => {
|
||||||
|
setSelectedClient(clientRow);
|
||||||
|
setIsDeleteModalOpen(true);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="text-red-500">Delete</span>
|
||||||
|
</DropdownMenuItem>
|
||||||
|
)}
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
<Link
|
<Link
|
||||||
href={`/${clientRow.orgId}/settings/clients/${clientRow.id}`}
|
href={`/${clientRow.orgId}/settings/clients/${clientRow.id}`}
|
||||||
>
|
>
|
||||||
<Button variant={"outline"}>
|
<Button variant={"outline"}>
|
||||||
Edit
|
View
|
||||||
<ArrowRight className="ml-2 w-4 h-4" />
|
<ArrowRight className="ml-2 w-4 h-4" />
|
||||||
</Button>
|
</Button>
|
||||||
</Link>
|
</Link>
|
||||||
</div>
|
</div>
|
||||||
) : null;
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -394,7 +505,7 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{selectedClient && (
|
{selectedClient && !selectedClient.userId && (
|
||||||
<ConfirmDeleteDialog
|
<ConfirmDeleteDialog
|
||||||
open={isDeleteModalOpen}
|
open={isDeleteModalOpen}
|
||||||
setOpen={(val) => {
|
setOpen={(val) => {
|
||||||
@@ -413,6 +524,27 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
title="Delete Client"
|
title="Delete Client"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
{selectedClient && (
|
||||||
|
<ConfirmDeleteDialog
|
||||||
|
open={isBlockModalOpen}
|
||||||
|
setOpen={(val) => {
|
||||||
|
setIsBlockModalOpen(val);
|
||||||
|
if (!val) {
|
||||||
|
setSelectedClient(null);
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
dialog={
|
||||||
|
<div className="space-y-2">
|
||||||
|
<p>{t("blockClientQuestion")}</p>
|
||||||
|
<p>{t("blockClientMessage")}</p>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
buttonText={t("blockClientConfirm")}
|
||||||
|
onConfirm={async () => blockClient(selectedClient!.id)}
|
||||||
|
string={selectedClient.name}
|
||||||
|
title={t("blockClient")}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<ClientDownloadBanner />
|
<ClientDownloadBanner />
|
||||||
|
|
||||||
@@ -429,6 +561,43 @@ export default function UserDevicesTable({ userClients }: ClientTableProps) {
|
|||||||
columnVisibility={defaultUserColumnVisibility}
|
columnVisibility={defaultUserColumnVisibility}
|
||||||
stickyLeftColumn="name"
|
stickyLeftColumn="name"
|
||||||
stickyRightColumn="actions"
|
stickyRightColumn="actions"
|
||||||
|
filters={[
|
||||||
|
{
|
||||||
|
id: "status",
|
||||||
|
label: t("status") || "Status",
|
||||||
|
multiSelect: true,
|
||||||
|
displayMode: "calculated",
|
||||||
|
options: [
|
||||||
|
{
|
||||||
|
id: "active",
|
||||||
|
label: t("active") || "Active",
|
||||||
|
value: "active"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "archived",
|
||||||
|
label: t("archived") || "Archived",
|
||||||
|
value: "archived"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "blocked",
|
||||||
|
label: t("blocked") || "Blocked",
|
||||||
|
value: "blocked"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
filterFn: (row: ClientRow, selectedValues: (string | number | boolean)[]) => {
|
||||||
|
if (selectedValues.length === 0) return true;
|
||||||
|
const rowArchived = row.archived || false;
|
||||||
|
const rowBlocked = row.blocked || false;
|
||||||
|
const isActive = !rowArchived && !rowBlocked;
|
||||||
|
|
||||||
|
if (selectedValues.includes("active") && isActive) return true;
|
||||||
|
if (selectedValues.includes("archived") && rowArchived) return true;
|
||||||
|
if (selectedValues.includes("blocked") && rowBlocked) return true;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
defaultValues: ["active"] // Default to showing active clients
|
||||||
|
}
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import {
|
|||||||
TableHeader,
|
TableHeader,
|
||||||
TableRow
|
TableRow
|
||||||
} from "@app/components/ui/table";
|
} from "@app/components/ui/table";
|
||||||
|
import { Tabs, TabsList, TabsTrigger, TabsContent } from "@app/components/ui/tabs";
|
||||||
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
import ConfirmDeleteDialog from "@app/components/ConfirmDeleteDialog";
|
||||||
import { Loader2, RefreshCw } from "lucide-react";
|
import { Loader2, RefreshCw } from "lucide-react";
|
||||||
import moment from "moment";
|
import moment from "moment";
|
||||||
@@ -44,6 +45,7 @@ type Device = {
|
|||||||
name: string | null;
|
name: string | null;
|
||||||
clientId: number | null;
|
clientId: number | null;
|
||||||
userId: string | null;
|
userId: string | null;
|
||||||
|
archived: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function ViewDevicesDialog({
|
export default function ViewDevicesDialog({
|
||||||
@@ -57,8 +59,9 @@ export default function ViewDevicesDialog({
|
|||||||
|
|
||||||
const [devices, setDevices] = useState<Device[]>([]);
|
const [devices, setDevices] = useState<Device[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
|
const [isArchiveModalOpen, setIsArchiveModalOpen] = useState(false);
|
||||||
const [selectedDevice, setSelectedDevice] = useState<Device | null>(null);
|
const [selectedDevice, setSelectedDevice] = useState<Device | null>(null);
|
||||||
|
const [activeTab, setActiveTab] = useState<"available" | "archived">("available");
|
||||||
|
|
||||||
const fetchDevices = async () => {
|
const fetchDevices = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
@@ -90,26 +93,59 @@ export default function ViewDevicesDialog({
|
|||||||
}
|
}
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
const deleteDevice = async (olmId: string) => {
|
const archiveDevice = async (olmId: string) => {
|
||||||
try {
|
try {
|
||||||
await api.delete(`/user/${user?.userId}/olm/${olmId}`);
|
await api.post(`/user/${user?.userId}/olm/${olmId}/archive`);
|
||||||
toast({
|
toast({
|
||||||
title: t("deviceDeleted") || "Device deleted",
|
title: t("deviceArchived") || "Device archived",
|
||||||
description:
|
description:
|
||||||
t("deviceDeletedDescription") ||
|
t("deviceArchivedDescription") ||
|
||||||
"The device has been successfully deleted."
|
"The device has been successfully archived."
|
||||||
});
|
});
|
||||||
setDevices(devices.filter((d) => d.olmId !== olmId));
|
// Update the device's archived status in the local state
|
||||||
setIsDeleteModalOpen(false);
|
setDevices(
|
||||||
|
devices.map((d) =>
|
||||||
|
d.olmId === olmId ? { ...d, archived: true } : d
|
||||||
|
)
|
||||||
|
);
|
||||||
|
setIsArchiveModalOpen(false);
|
||||||
setSelectedDevice(null);
|
setSelectedDevice(null);
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error("Error deleting device:", error);
|
console.error("Error archiving device:", error);
|
||||||
toast({
|
toast({
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
title: t("errorDeletingDevice") || "Error deleting device",
|
title: t("errorArchivingDevice"),
|
||||||
description: formatAxiosError(
|
description: formatAxiosError(
|
||||||
error,
|
error,
|
||||||
t("failedToDeleteDevice") || "Failed to delete device"
|
t("failedToArchiveDevice")
|
||||||
|
)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const unarchiveDevice = async (olmId: string) => {
|
||||||
|
try {
|
||||||
|
await api.post(`/user/${user?.userId}/olm/${olmId}/unarchive`);
|
||||||
|
toast({
|
||||||
|
title: t("deviceUnarchived") || "Device unarchived",
|
||||||
|
description:
|
||||||
|
t("deviceUnarchivedDescription") ||
|
||||||
|
"The device has been successfully unarchived."
|
||||||
|
});
|
||||||
|
// Update the device's archived status in the local state
|
||||||
|
setDevices(
|
||||||
|
devices.map((d) =>
|
||||||
|
d.olmId === olmId ? { ...d, archived: false } : d
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (error: any) {
|
||||||
|
console.error("Error unarchiving device:", error);
|
||||||
|
toast({
|
||||||
|
variant: "destructive",
|
||||||
|
title: t("errorUnarchivingDevice") || "Error unarchiving device",
|
||||||
|
description: formatAxiosError(
|
||||||
|
error,
|
||||||
|
t("failedToUnarchiveDevice") || "Failed to unarchive device"
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -118,7 +154,7 @@ export default function ViewDevicesDialog({
|
|||||||
function reset() {
|
function reset() {
|
||||||
setDevices([]);
|
setDevices([]);
|
||||||
setSelectedDevice(null);
|
setSelectedDevice(null);
|
||||||
setIsDeleteModalOpen(false);
|
setIsArchiveModalOpen(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -147,9 +183,40 @@ export default function ViewDevicesDialog({
|
|||||||
<div className="flex items-center justify-center py-8">
|
<div className="flex items-center justify-center py-8">
|
||||||
<Loader2 className="h-6 w-6 animate-spin" />
|
<Loader2 className="h-6 w-6 animate-spin" />
|
||||||
</div>
|
</div>
|
||||||
) : devices.length === 0 ? (
|
) : (
|
||||||
|
<Tabs
|
||||||
|
value={activeTab}
|
||||||
|
onValueChange={(value) =>
|
||||||
|
setActiveTab(value as "available" | "archived")
|
||||||
|
}
|
||||||
|
className="w-full"
|
||||||
|
>
|
||||||
|
<TabsList className="grid w-full grid-cols-2">
|
||||||
|
<TabsTrigger value="available">
|
||||||
|
{t("available") || "Available"} (
|
||||||
|
{
|
||||||
|
devices.filter(
|
||||||
|
(d) => !d.archived
|
||||||
|
).length
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</TabsTrigger>
|
||||||
|
<TabsTrigger value="archived">
|
||||||
|
{t("archived") || "Archived"} (
|
||||||
|
{
|
||||||
|
devices.filter(
|
||||||
|
(d) => d.archived
|
||||||
|
).length
|
||||||
|
}
|
||||||
|
)
|
||||||
|
</TabsTrigger>
|
||||||
|
</TabsList>
|
||||||
|
<TabsContent value="available" className="mt-4">
|
||||||
|
{devices.filter((d) => !d.archived)
|
||||||
|
.length === 0 ? (
|
||||||
<div className="text-center py-8 text-muted-foreground">
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
{t("noDevices") || "No devices found"}
|
{t("noDevices") ||
|
||||||
|
"No devices found"}
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="rounded-md border">
|
<div className="rounded-md border">
|
||||||
@@ -164,22 +231,33 @@ export default function ViewDevicesDialog({
|
|||||||
"Date Created"}
|
"Date Created"}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
<TableHead>
|
<TableHead>
|
||||||
{t("actions") || "Actions"}
|
{t("actions") ||
|
||||||
|
"Actions"}
|
||||||
</TableHead>
|
</TableHead>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<TableBody>
|
<TableBody>
|
||||||
{devices.map((device) => (
|
{devices
|
||||||
<TableRow key={device.olmId}>
|
.filter(
|
||||||
|
(d) => !d.archived
|
||||||
|
)
|
||||||
|
.map((device) => (
|
||||||
|
<TableRow
|
||||||
|
key={device.olmId}
|
||||||
|
>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{device.name ||
|
{device.name ||
|
||||||
t("unnamedDevice") ||
|
t(
|
||||||
|
"unnamedDevice"
|
||||||
|
) ||
|
||||||
"Unnamed Device"}
|
"Unnamed Device"}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{moment(
|
{moment(
|
||||||
device.dateCreated
|
device.dateCreated
|
||||||
).format("lll")}
|
).format(
|
||||||
|
"lll"
|
||||||
|
)}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
<Button
|
<Button
|
||||||
@@ -188,13 +266,15 @@ export default function ViewDevicesDialog({
|
|||||||
setSelectedDevice(
|
setSelectedDevice(
|
||||||
device
|
device
|
||||||
);
|
);
|
||||||
setIsDeleteModalOpen(
|
setIsArchiveModalOpen(
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("delete") ||
|
{t(
|
||||||
"Delete"}
|
"archive"
|
||||||
|
) ||
|
||||||
|
"Archive"}
|
||||||
</Button>
|
</Button>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
@@ -202,6 +282,74 @@ export default function ViewDevicesDialog({
|
|||||||
</TableBody>
|
</TableBody>
|
||||||
</Table>
|
</Table>
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
|
</TabsContent>
|
||||||
|
<TabsContent value="archived" className="mt-4">
|
||||||
|
{devices.filter((d) => d.archived)
|
||||||
|
.length === 0 ? (
|
||||||
|
<div className="text-center py-8 text-muted-foreground">
|
||||||
|
{t("noArchivedDevices") ||
|
||||||
|
"No archived devices found"}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="rounded-md border">
|
||||||
|
<Table>
|
||||||
|
<TableHeader>
|
||||||
|
<TableRow>
|
||||||
|
<TableHead className="pl-3">
|
||||||
|
{t("name") || "Name"}
|
||||||
|
</TableHead>
|
||||||
|
<TableHead>
|
||||||
|
{t("dateCreated") ||
|
||||||
|
"Date Created"}
|
||||||
|
</TableHead>
|
||||||
|
<TableHead>
|
||||||
|
{t("actions") ||
|
||||||
|
"Actions"}
|
||||||
|
</TableHead>
|
||||||
|
</TableRow>
|
||||||
|
</TableHeader>
|
||||||
|
<TableBody>
|
||||||
|
{devices
|
||||||
|
.filter(
|
||||||
|
(d) => d.archived
|
||||||
|
)
|
||||||
|
.map((device) => (
|
||||||
|
<TableRow
|
||||||
|
key={device.olmId}
|
||||||
|
>
|
||||||
|
<TableCell className="font-medium">
|
||||||
|
{device.name ||
|
||||||
|
t(
|
||||||
|
"unnamedDevice"
|
||||||
|
) ||
|
||||||
|
"Unnamed Device"}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
{moment(
|
||||||
|
device.dateCreated
|
||||||
|
).format(
|
||||||
|
"lll"
|
||||||
|
)}
|
||||||
|
</TableCell>
|
||||||
|
<TableCell>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
onClick={() => {
|
||||||
|
unarchiveDevice(device.olmId);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{t("unarchive") || "Unarchive"}
|
||||||
|
</Button>
|
||||||
|
</TableCell>
|
||||||
|
</TableRow>
|
||||||
|
))}
|
||||||
|
</TableBody>
|
||||||
|
</Table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</TabsContent>
|
||||||
|
</Tabs>
|
||||||
)}
|
)}
|
||||||
</CredenzaBody>
|
</CredenzaBody>
|
||||||
<CredenzaFooter>
|
<CredenzaFooter>
|
||||||
@@ -216,9 +364,9 @@ export default function ViewDevicesDialog({
|
|||||||
|
|
||||||
{selectedDevice && (
|
{selectedDevice && (
|
||||||
<ConfirmDeleteDialog
|
<ConfirmDeleteDialog
|
||||||
open={isDeleteModalOpen}
|
open={isArchiveModalOpen}
|
||||||
setOpen={(val) => {
|
setOpen={(val) => {
|
||||||
setIsDeleteModalOpen(val);
|
setIsArchiveModalOpen(val);
|
||||||
if (!val) {
|
if (!val) {
|
||||||
setSelectedDevice(null);
|
setSelectedDevice(null);
|
||||||
}
|
}
|
||||||
@@ -226,19 +374,19 @@ export default function ViewDevicesDialog({
|
|||||||
dialog={
|
dialog={
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
<p>
|
<p>
|
||||||
{t("deviceQuestionRemove") ||
|
{t("deviceQuestionArchive") ||
|
||||||
"Are you sure you want to delete this device?"}
|
"Are you sure you want to archive this device?"}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
{t("deviceMessageRemove") ||
|
{t("deviceMessageArchive") ||
|
||||||
"This action cannot be undone."}
|
"The device will be archived and removed from your active devices list."}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
buttonText={t("deviceDeleteConfirm") || "Delete Device"}
|
buttonText={t("deviceArchiveConfirm") || "Archive Device"}
|
||||||
onConfirm={async () => deleteDevice(selectedDevice.olmId)}
|
onConfirm={async () => archiveDevice(selectedDevice.olmId)}
|
||||||
string={selectedDevice.name || selectedDevice.olmId}
|
string={selectedDevice.name || selectedDevice.olmId}
|
||||||
title={t("deleteDevice") || "Delete Device"}
|
title={t("archiveDevice") || "Archive Device"}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ import { Button } from "@app/components/ui/button";
|
|||||||
import { useEffect, useMemo, useRef, useState } from "react";
|
import { useEffect, useMemo, useRef, useState } from "react";
|
||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import { DataTablePagination } from "@app/components/DataTablePagination";
|
import { DataTablePagination } from "@app/components/DataTablePagination";
|
||||||
import { Plus, Search, RefreshCw, Columns } from "lucide-react";
|
import { Plus, Search, RefreshCw, Columns, Filter } from "lucide-react";
|
||||||
import {
|
import {
|
||||||
Card,
|
Card,
|
||||||
CardContent,
|
CardContent,
|
||||||
@@ -140,6 +140,22 @@ type TabFilter = {
|
|||||||
filterFn: (row: any) => boolean;
|
filterFn: (row: any) => boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
type FilterOption = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
value: string | number | boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
type DataTableFilter = {
|
||||||
|
id: string;
|
||||||
|
label: string;
|
||||||
|
options: FilterOption[];
|
||||||
|
multiSelect?: boolean;
|
||||||
|
filterFn: (row: any, selectedValues: (string | number | boolean)[]) => boolean;
|
||||||
|
defaultValues?: (string | number | boolean)[];
|
||||||
|
displayMode?: "label" | "calculated"; // How to display the filter button text
|
||||||
|
};
|
||||||
|
|
||||||
type DataTableProps<TData, TValue> = {
|
type DataTableProps<TData, TValue> = {
|
||||||
columns: ExtendedColumnDef<TData, TValue>[];
|
columns: ExtendedColumnDef<TData, TValue>[];
|
||||||
data: TData[];
|
data: TData[];
|
||||||
@@ -156,6 +172,8 @@ type DataTableProps<TData, TValue> = {
|
|||||||
};
|
};
|
||||||
tabs?: TabFilter[];
|
tabs?: TabFilter[];
|
||||||
defaultTab?: string;
|
defaultTab?: string;
|
||||||
|
filters?: DataTableFilter[];
|
||||||
|
filterDisplayMode?: "label" | "calculated"; // Global filter display mode (can be overridden per filter)
|
||||||
persistPageSize?: boolean | string;
|
persistPageSize?: boolean | string;
|
||||||
defaultPageSize?: number;
|
defaultPageSize?: number;
|
||||||
columnVisibility?: Record<string, boolean>;
|
columnVisibility?: Record<string, boolean>;
|
||||||
@@ -178,6 +196,8 @@ export function DataTable<TData, TValue>({
|
|||||||
defaultSort,
|
defaultSort,
|
||||||
tabs,
|
tabs,
|
||||||
defaultTab,
|
defaultTab,
|
||||||
|
filters,
|
||||||
|
filterDisplayMode = "label",
|
||||||
persistPageSize = false,
|
persistPageSize = false,
|
||||||
defaultPageSize = 20,
|
defaultPageSize = 20,
|
||||||
columnVisibility: defaultColumnVisibility,
|
columnVisibility: defaultColumnVisibility,
|
||||||
@@ -235,6 +255,15 @@ export function DataTable<TData, TValue>({
|
|||||||
const [activeTab, setActiveTab] = useState<string>(
|
const [activeTab, setActiveTab] = useState<string>(
|
||||||
defaultTab || tabs?.[0]?.id || ""
|
defaultTab || tabs?.[0]?.id || ""
|
||||||
);
|
);
|
||||||
|
const [activeFilters, setActiveFilters] = useState<Record<string, (string | number | boolean)[]>>(
|
||||||
|
() => {
|
||||||
|
const initial: Record<string, (string | number | boolean)[]> = {};
|
||||||
|
filters?.forEach((filter) => {
|
||||||
|
initial[filter.id] = filter.defaultValues || [];
|
||||||
|
});
|
||||||
|
return initial;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Track initial values to avoid storing defaults on first render
|
// Track initial values to avoid storing defaults on first render
|
||||||
const initialPageSize = useRef(pageSize);
|
const initialPageSize = useRef(pageSize);
|
||||||
@@ -242,19 +271,32 @@ export function DataTable<TData, TValue>({
|
|||||||
const hasUserChangedPageSize = useRef(false);
|
const hasUserChangedPageSize = useRef(false);
|
||||||
const hasUserChangedColumnVisibility = useRef(false);
|
const hasUserChangedColumnVisibility = useRef(false);
|
||||||
|
|
||||||
// Apply tab filter to data
|
// Apply tab and custom filters to data
|
||||||
const filteredData = useMemo(() => {
|
const filteredData = useMemo(() => {
|
||||||
if (!tabs || activeTab === "") {
|
let result = data;
|
||||||
return data;
|
|
||||||
|
// Apply tab filter
|
||||||
|
if (tabs && activeTab !== "") {
|
||||||
|
const activeTabFilter = tabs.find((tab) => tab.id === activeTab);
|
||||||
|
if (activeTabFilter) {
|
||||||
|
result = result.filter(activeTabFilter.filterFn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const activeTabFilter = tabs.find((tab) => tab.id === activeTab);
|
// Apply custom filters
|
||||||
if (!activeTabFilter) {
|
if (filters && filters.length > 0) {
|
||||||
return data;
|
filters.forEach((filter) => {
|
||||||
|
const selectedValues = activeFilters[filter.id] || [];
|
||||||
|
if (selectedValues.length > 0) {
|
||||||
|
result = result.filter((row) =>
|
||||||
|
filter.filterFn(row, selectedValues)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.filter(activeTabFilter.filterFn);
|
return result;
|
||||||
}, [data, tabs, activeTab]);
|
}, [data, tabs, activeTab, filters, activeFilters]);
|
||||||
|
|
||||||
const table = useReactTable({
|
const table = useReactTable({
|
||||||
data: filteredData,
|
data: filteredData,
|
||||||
@@ -318,6 +360,64 @@ export function DataTable<TData, TValue>({
|
|||||||
setPagination((prev) => ({ ...prev, pageIndex: 0 }));
|
setPagination((prev) => ({ ...prev, pageIndex: 0 }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFilterChange = (
|
||||||
|
filterId: string,
|
||||||
|
optionValue: string | number | boolean,
|
||||||
|
checked: boolean
|
||||||
|
) => {
|
||||||
|
setActiveFilters((prev) => {
|
||||||
|
const currentValues = prev[filterId] || [];
|
||||||
|
const filter = filters?.find((f) => f.id === filterId);
|
||||||
|
|
||||||
|
if (!filter) return prev;
|
||||||
|
|
||||||
|
let newValues: (string | number | boolean)[];
|
||||||
|
|
||||||
|
if (filter.multiSelect) {
|
||||||
|
// Multi-select: add or remove the value
|
||||||
|
if (checked) {
|
||||||
|
newValues = [...currentValues, optionValue];
|
||||||
|
} else {
|
||||||
|
newValues = currentValues.filter((v) => v !== optionValue);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Single-select: replace the value
|
||||||
|
newValues = checked ? [optionValue] : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
[filterId]: newValues
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// Reset to first page when changing filters
|
||||||
|
setPagination((prev) => ({ ...prev, pageIndex: 0 }));
|
||||||
|
};
|
||||||
|
|
||||||
|
// Calculate display text for a filter based on selected values
|
||||||
|
const getFilterDisplayText = (filter: DataTableFilter): string => {
|
||||||
|
const selectedValues = activeFilters[filter.id] || [];
|
||||||
|
|
||||||
|
if (selectedValues.length === 0) {
|
||||||
|
return filter.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
const selectedOptions = filter.options.filter((option) =>
|
||||||
|
selectedValues.includes(option.value)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (selectedOptions.length === 0) {
|
||||||
|
return filter.label;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selectedOptions.length === 1) {
|
||||||
|
return selectedOptions[0].label;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Multiple selections: always join with "and"
|
||||||
|
return selectedOptions.map((opt) => opt.label).join(" and ");
|
||||||
|
};
|
||||||
|
|
||||||
// Enhanced pagination component that updates our local state
|
// Enhanced pagination component that updates our local state
|
||||||
const handlePageSizeChange = (newPageSize: number) => {
|
const handlePageSizeChange = (newPageSize: number) => {
|
||||||
hasUserChangedPageSize.current = true;
|
hasUserChangedPageSize.current = true;
|
||||||
@@ -387,6 +487,63 @@ export function DataTable<TData, TValue>({
|
|||||||
/>
|
/>
|
||||||
<Search className="h-4 w-4 absolute left-2 top-1/2 transform -translate-y-1/2 text-muted-foreground" />
|
<Search className="h-4 w-4 absolute left-2 top-1/2 transform -translate-y-1/2 text-muted-foreground" />
|
||||||
</div>
|
</div>
|
||||||
|
{filters && filters.length > 0 && (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
{filters.map((filter) => {
|
||||||
|
const selectedValues = activeFilters[filter.id] || [];
|
||||||
|
const hasActiveFilters = selectedValues.length > 0;
|
||||||
|
const displayMode = filter.displayMode || filterDisplayMode;
|
||||||
|
const displayText = displayMode === "calculated"
|
||||||
|
? getFilterDisplayText(filter)
|
||||||
|
: filter.label;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DropdownMenu key={filter.id}>
|
||||||
|
<DropdownMenuTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant={"outline"}
|
||||||
|
size="sm"
|
||||||
|
className="h-9"
|
||||||
|
>
|
||||||
|
<Filter className="h-4 w-4 mr-2" />
|
||||||
|
{displayText}
|
||||||
|
{displayMode === "label" && hasActiveFilters && (
|
||||||
|
<span className="ml-2 bg-muted text-foreground rounded-full px-2 py-0.5 text-xs">
|
||||||
|
{selectedValues.length}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Button>
|
||||||
|
</DropdownMenuTrigger>
|
||||||
|
<DropdownMenuContent align="start" className="w-48">
|
||||||
|
<DropdownMenuLabel>
|
||||||
|
{filter.label}
|
||||||
|
</DropdownMenuLabel>
|
||||||
|
<DropdownMenuSeparator />
|
||||||
|
{filter.options.map((option) => {
|
||||||
|
const isChecked = selectedValues.includes(option.value);
|
||||||
|
return (
|
||||||
|
<DropdownMenuCheckboxItem
|
||||||
|
key={option.id}
|
||||||
|
checked={isChecked}
|
||||||
|
onCheckedChange={(checked) =>
|
||||||
|
handleFilterChange(
|
||||||
|
filter.id,
|
||||||
|
option.value,
|
||||||
|
checked
|
||||||
|
)
|
||||||
|
}
|
||||||
|
onSelect={(e) => e.preventDefault()}
|
||||||
|
>
|
||||||
|
{option.label}
|
||||||
|
</DropdownMenuCheckboxItem>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</DropdownMenuContent>
|
||||||
|
</DropdownMenu>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{tabs && tabs.length > 0 && (
|
{tabs && tabs.length > 0 && (
|
||||||
<Tabs
|
<Tabs
|
||||||
value={activeTab}
|
value={activeTab}
|
||||||
|
|||||||
+3
-1
@@ -63,7 +63,9 @@ export function pullEnv(): Env {
|
|||||||
disableProductHelpBanners:
|
disableProductHelpBanners:
|
||||||
process.env.FLAGS_DISABLE_PRODUCT_HELP_BANNERS === "true"
|
process.env.FLAGS_DISABLE_PRODUCT_HELP_BANNERS === "true"
|
||||||
? true
|
? true
|
||||||
: false
|
: false,
|
||||||
|
useOrgOnlyIdp:
|
||||||
|
process.env.USE_ORG_ONLY_IDP === "true" ? true : false
|
||||||
},
|
},
|
||||||
|
|
||||||
branding: {
|
branding: {
|
||||||
|
|||||||
+13
-2
@@ -157,7 +157,13 @@ export const orgQueries = {
|
|||||||
return res.data.data.domains;
|
return res.data.data.domains;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
identityProviders: ({ orgId }: { orgId: string }) =>
|
identityProviders: ({
|
||||||
|
orgId,
|
||||||
|
useOrgOnlyIdp
|
||||||
|
}: {
|
||||||
|
orgId: string;
|
||||||
|
useOrgOnlyIdp?: boolean;
|
||||||
|
}) =>
|
||||||
queryOptions({
|
queryOptions({
|
||||||
queryKey: ["ORG", orgId, "IDPS"] as const,
|
queryKey: ["ORG", orgId, "IDPS"] as const,
|
||||||
queryFn: async ({ signal, meta }) => {
|
queryFn: async ({ signal, meta }) => {
|
||||||
@@ -165,7 +171,12 @@ export const orgQueries = {
|
|||||||
AxiosResponse<{
|
AxiosResponse<{
|
||||||
idps: { idpId: number; name: string }[];
|
idps: { idpId: number; name: string }[];
|
||||||
}>
|
}>
|
||||||
>(build === "saas" ? `/org/${orgId}/idp` : "/idp", { signal });
|
>(
|
||||||
|
build === "saas" || useOrgOnlyIdp
|
||||||
|
? `/org/${orgId}/idp`
|
||||||
|
: "/idp",
|
||||||
|
{ signal }
|
||||||
|
);
|
||||||
return res.data.data.idps;
|
return res.data.data.idps;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ export type Env = {
|
|||||||
hideSupporterKey: boolean;
|
hideSupporterKey: boolean;
|
||||||
usePangolinDns: boolean;
|
usePangolinDns: boolean;
|
||||||
disableProductHelpBanners: boolean;
|
disableProductHelpBanners: boolean;
|
||||||
|
useOrgOnlyIdp: boolean;
|
||||||
};
|
};
|
||||||
branding: {
|
branding: {
|
||||||
appName?: string;
|
appName?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user