Compare commits
No commits in common. 'dev' and 'refactor/config' have entirely different histories.
dev
...
refactor/c
@ -1,18 +0,0 @@
|
||||
# To get started with Dependabot version updates, you'll need to specify which
|
||||
# package ecosystems to update and where the package manifests are located.
|
||||
# Please see the documentation for all configuration options:
|
||||
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
||||
|
||||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/app"
|
||||
target-branch: "dev"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
|
||||
- package-ecosystem: "gomod"
|
||||
directory: "/"
|
||||
target-branch: "dev"
|
||||
schedule:
|
||||
interval: "weekly"
|
||||
@ -1,266 +1,265 @@
|
||||
name: Build
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
- '!weblate'
|
||||
paths:
|
||||
- "app/**/*.js"
|
||||
- "app/**/*.vue"
|
||||
- "app/src/language/**/*.po"
|
||||
- "app/i18n.json"
|
||||
- "app/package.json"
|
||||
- "app/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/build*.yml"
|
||||
- "resources/docker/docker/*"
|
||||
- "resources/development/*"
|
||||
- "resources/demo/*"
|
||||
- "Dockerfile"
|
||||
- "demo.Dockerfile"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.vue"
|
||||
- "app/package.json"
|
||||
- "app/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/*.yml"
|
||||
- "resources/docker/docker/*"
|
||||
- "resources/development/*"
|
||||
- "resources/demo/*"
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
paths:
|
||||
- "app/**/*.js"
|
||||
- "app/**/*.vue"
|
||||
- "app/src/language/**/*.po"
|
||||
- "app/i18n.json"
|
||||
- "app/package.json"
|
||||
- "app/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/build*.yml"
|
||||
- "resources/docker/docker/*"
|
||||
- "resources/development/*"
|
||||
- "resources/demo/*"
|
||||
- "Dockerfile"
|
||||
- "demo.Dockerfile"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "**/*.js"
|
||||
- "**/*.vue"
|
||||
- "app/package.json"
|
||||
- "app/.env*"
|
||||
- "**/*.go"
|
||||
- "go.mod"
|
||||
- "go.sum"
|
||||
- ".github/workflows/*.yml"
|
||||
- "resources/docker/docker/*"
|
||||
- "resources/development/*"
|
||||
- "resources/demo/*"
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
build_app:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
build_app:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: current
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: current
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
pnpm install
|
||||
working-directory: app
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
pnpm install
|
||||
working-directory: app
|
||||
|
||||
- name: Check frontend code style
|
||||
run: |
|
||||
pnpm run lint
|
||||
working-directory: app
|
||||
- name: Check frontend code style
|
||||
run: |
|
||||
pnpm run lint
|
||||
working-directory: app
|
||||
|
||||
- name: Check frontend types
|
||||
run: |
|
||||
pnpm run typecheck
|
||||
working-directory: app
|
||||
- name: Check frontend types
|
||||
run: |
|
||||
pnpm run typecheck
|
||||
working-directory: app
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
npx browserslist@latest --update-db
|
||||
pnpm build
|
||||
working-directory: app
|
||||
- name: Build
|
||||
run: |
|
||||
npx browserslist@latest --update-db
|
||||
pnpm build
|
||||
working-directory: app
|
||||
|
||||
- name: Archive app artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: app-dist
|
||||
path: app/dist
|
||||
- name: Archive app artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: app-dist
|
||||
path: app/dist
|
||||
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md app/dist
|
||||
find app/dist -printf '%P\n' | tar -C app/dist --no-recursion -zcvf app-dist.tar.gz -T -
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md app/dist
|
||||
find app/dist -printf '%P\n' | tar -C app/dist --no-recursion -zcvf app-dist.tar.gz -T -
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: app-dist.tar.gz
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: app-dist.tar.gz
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build_app
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [ linux, darwin ]
|
||||
goarch: [ amd64, 386, arm64 ]
|
||||
exclude:
|
||||
# Exclude i386 on darwin.
|
||||
- goarch: 386
|
||||
goos: darwin
|
||||
include:
|
||||
# BEGIN Linux ARM 5 6 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 6
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 5
|
||||
# END Linux ARM 5 6 7
|
||||
env:
|
||||
CGO_ENABLED: 1
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
GOARM: ${{ matrix.goarm }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
needs: build_app
|
||||
strategy:
|
||||
matrix:
|
||||
goos: [ linux, darwin ]
|
||||
goarch: [ amd64, 386, arm64 ]
|
||||
exclude:
|
||||
# Exclude i386 on darwin.
|
||||
- goarch: 386
|
||||
goos: darwin
|
||||
include:
|
||||
# BEGIN Linux ARM 5 6 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 7
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 6
|
||||
- goos: linux
|
||||
goarch: arm
|
||||
goarm: 5
|
||||
# END Linux ARM 5 6 7
|
||||
env:
|
||||
CGO_ENABLED: 1
|
||||
GOOS: ${{ matrix.goos }}
|
||||
GOARCH: ${{ matrix.goarch }}
|
||||
GOARM: ${{ matrix.goarm }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ^1.23.0
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: ^1.22.0
|
||||
|
||||
- name: Setup compiler environment
|
||||
id: info
|
||||
run: |
|
||||
export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
|
||||
export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
|
||||
export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
|
||||
export _ARTIFACT=nginx-ui-$GOOS-$GOARCH$(if [[ "$GOARM" ]]; then echo "v$GOARM"; fi)
|
||||
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME, ARTIFACT_NAME: $_ARTIFACT"
|
||||
echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
|
||||
echo "ABI=$_ABI" >> $GITHUB_ENV
|
||||
echo "DIST=$_NAME" >> $GITHUB_ENV
|
||||
echo "ARTIFACT=$_ARTIFACT" >> $GITHUB_ENV
|
||||
- name: Setup compiler environment
|
||||
id: info
|
||||
run: |
|
||||
export _NAME=nginx-ui-$(jq ".$GOOS[\"$GOARCH$GOARM\"].name" -r < .github/build/build_info.json)
|
||||
export _ARCH=$(jq ".$GOOS[\"$GOARCH$GOARM\"].arch" -r < .github/build/build_info.json)
|
||||
export _ABI=$(jq ".$GOOS[\"$GOARCH$GOARM\"].abi // \"\"" -r < .github/build/build_info.json)
|
||||
export _ARTIFACT=nginx-ui-$GOOS-$GOARCH$(if [[ "$GOARM" ]]; then echo "v$GOARM"; fi)
|
||||
echo "GOOS: $GOOS, GOARCH: $GOARCH, GOARM: $GOARM, ABI: $_ABI, RELEASE_NAME: $_NAME, ARTIFACT_NAME: $_ARTIFACT"
|
||||
echo "ARCH_NAME=$_ARCH" >> $GITHUB_ENV
|
||||
echo "ABI=$_ABI" >> $GITHUB_ENV
|
||||
echo "DIST=$_NAME" >> $GITHUB_ENV
|
||||
echo "ARTIFACT=$_ARTIFACT" >> $GITHUB_ENV
|
||||
|
||||
- name: Install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
uses: 0xJacky/musl-cross-compilers@v0.6.6
|
||||
id: musl
|
||||
with:
|
||||
target: ${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}
|
||||
- name: Install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
uses: 0xJacky/musl-cross-compilers@v0.6.6
|
||||
id: musl
|
||||
with:
|
||||
target: ${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}
|
||||
|
||||
- name: Post install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
run: |
|
||||
echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-gcc" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-g++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-w --extldflags '-static'" >> $GITHUB_ENV
|
||||
- name: Post install musl cross compiler
|
||||
if: env.GOOS == 'linux'
|
||||
run: |
|
||||
echo "PATH=${{ steps.musl.outputs.path }}:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-gcc" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-linux-musl${{ env.ABI }}-g++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-w --extldflags '-static'" >> $GITHUB_ENV
|
||||
|
||||
- name: Install darwin cross compiler
|
||||
if: env.GOOS == 'darwin'
|
||||
run: |
|
||||
curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
|
||||
tar xvaf crossosx.tar.zst
|
||||
echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
|
||||
echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-clang" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-clang++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-w" >> $GITHUB_ENV
|
||||
- name: Install darwin cross compiler
|
||||
if: env.GOOS == 'darwin'
|
||||
run: |
|
||||
curl -L https://github.com/Hintay/crossosx/releases/latest/download/crossosx.tar.zst -o crossosx.tar.zst
|
||||
tar xvaf crossosx.tar.zst
|
||||
echo "LD_LIBRARY_PATH=$(pwd)/crossosx/lib/" >> $GITHUB_ENV
|
||||
echo "PATH=$(pwd)/crossosx/bin/:$PATH" >> $GITHUB_ENV
|
||||
echo "CC=${{ env.ARCH_NAME }}-clang" >> $GITHUB_ENV
|
||||
echo "CXX=${{ env.ARCH_NAME }}-clang++" >> $GITHUB_ENV
|
||||
echo "LD_FLAGS=-w" >> $GITHUB_ENV
|
||||
|
||||
- name: Download app artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: app-dist
|
||||
path: app/dist
|
||||
- name: Download app artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
name: app-dist
|
||||
path: app/dist
|
||||
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p dist
|
||||
go build -tags=jsoniter -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
|
||||
- name: Build
|
||||
run: |
|
||||
mkdir -p dist
|
||||
go build -tags=jsoniter -ldflags "$LD_FLAGS -X 'github.com/0xJacky/Nginx-UI/settings.buildTime=$(date +%s)'" -o dist/nginx-ui -v main.go
|
||||
|
||||
- name: Archive backend artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.ARTIFACT }}
|
||||
path: dist/nginx-ui
|
||||
- name: Archive backend artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: ${{ env.ARTIFACT }}
|
||||
path: dist/nginx-ui
|
||||
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md ./dist
|
||||
find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
|
||||
openssl dgst -sha512 ${{ env.DIST }}.tar.gz | sed 's/([^)]*)//g' | awk '{print $NF}' >> ${{ env.DIST }}.tar.gz.digest
|
||||
- name: Prepare publish
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp README*.md ./dist
|
||||
find dist -printf '%P\n' | tar -C dist --no-recursion -zcvf ${{ env.DIST }}.tar.gz -T -
|
||||
openssl dgst -sha512 ${{ env.DIST }}.tar.gz | sed 's/([^)]*)//g' | awk '{print $NF}' >> ${{ env.DIST }}.tar.gz.digest
|
||||
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: |
|
||||
${{ env.DIST }}.tar.gz
|
||||
${{ env.DIST }}.tar.gz.digest
|
||||
- name: Publish
|
||||
uses: softprops/action-gh-release@v2
|
||||
if: github.event_name == 'release'
|
||||
with:
|
||||
files: |
|
||||
${{ env.DIST }}.tar.gz
|
||||
${{ env.DIST }}.tar.gz.digest
|
||||
|
||||
docker-build:
|
||||
if: github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
env:
|
||||
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/arm/v5
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
docker-build:
|
||||
if: github.event_name != 'pull_request'
|
||||
runs-on: ubuntu-latest
|
||||
needs: build
|
||||
env:
|
||||
PLATFORMS: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/arm/v5
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Get the version
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
|
||||
- name: Get the version
|
||||
id: get_version
|
||||
run: echo "VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: ./dist
|
||||
- name: Download artifacts
|
||||
uses: actions/download-artifact@v4
|
||||
with:
|
||||
path: ./dist
|
||||
|
||||
- name: Prepare Artifacts
|
||||
run: chmod +x ./dist/nginx-ui-*/nginx-ui
|
||||
- name: Prepare Artifacts
|
||||
run: chmod +x ./dist/nginx-ui-*/nginx-ui
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
- name: Login to DockerHub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USER }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Prepare Dockerfile
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp ./Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
- name: Prepare Dockerfile
|
||||
if: github.event_name == 'release'
|
||||
run: |
|
||||
cp ./Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
|
||||
- name: Build and push
|
||||
if: github.event_name == 'release'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui:latest
|
||||
uozi/nginx-ui:${{ steps.get_version.outputs.VERSION }}
|
||||
- name: Build and push
|
||||
if: github.event_name == 'release'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui:latest
|
||||
uozi/nginx-ui:${{ steps.get_version.outputs.VERSION }}
|
||||
|
||||
- name: Prepare Demo Dockerfile
|
||||
run: |
|
||||
cp ./demo.Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
- name: Prepare Demo Dockerfile
|
||||
run: |
|
||||
cp ./demo.Dockerfile ./dist
|
||||
cp -rp ./resources ./dist
|
||||
|
||||
- name: Build and push demo
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/demo.Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui-demo:latest
|
||||
- name: Build and push demo
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: ./dist
|
||||
file: ./dist/demo.Dockerfile
|
||||
platforms: ${{ env.PLATFORMS }}
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
tags: |
|
||||
uozi/nginx-ui-demo:latest
|
||||
|
||||
@ -1,64 +1,64 @@
|
||||
name: Build Documents
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
paths:
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "docs/**/*.vue"
|
||||
- "docs/package.json"
|
||||
- "docs/.env*"
|
||||
- "docs/**/*.md"
|
||||
- ".github/workflows/doc*.yml"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "docs/**/*.vue"
|
||||
- "docs/package.json"
|
||||
- "docs/.env*"
|
||||
- "docs/**/*.md"
|
||||
- ".github/workflows/doc*.yml"
|
||||
push:
|
||||
branches:
|
||||
- '*'
|
||||
paths:
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "docs/**/*.vue"
|
||||
- "docs/package.json"
|
||||
- "docs/.env*"
|
||||
- "docs/**/*.md"
|
||||
- ".github/workflows/doc*.yml"
|
||||
pull_request:
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "docs/**/*.vue"
|
||||
- "docs/package.json"
|
||||
- "docs/.env*"
|
||||
- "docs/**/*.md"
|
||||
- ".github/workflows/doc*.yml"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
build:
|
||||
runs-on: macos-14
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 21.x
|
||||
- name: Set up nodejs
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 21.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
pnpm install
|
||||
working-directory: docs
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
corepack enable
|
||||
corepack prepare pnpm@latest --activate
|
||||
pnpm install
|
||||
working-directory: docs
|
||||
|
||||
- name: Build
|
||||
run: COMMIT_REF=$(git rev-parse HEAD) pnpm docs:build
|
||||
working-directory: docs
|
||||
- name: Build
|
||||
run: COMMIT_REF=$(git rev-parse HEAD) pnpm docs:build
|
||||
working-directory: docs
|
||||
|
||||
- name: Archive artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: docs/.vitepress/dist
|
||||
- name: Archive artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: dist
|
||||
path: docs/.vitepress/dist
|
||||
|
||||
- name: Deploy to server
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: easingthemes/ssh-deploy@main
|
||||
env:
|
||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||
SOURCE: "docs/.vitepress/dist/"
|
||||
ARGS: "-rlgoDzvc -i --delete"
|
||||
- name: Deploy to server
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: easingthemes/ssh-deploy@main
|
||||
env:
|
||||
REMOTE_HOST: ${{ secrets.REMOTE_HOST }}
|
||||
REMOTE_USER: ${{ secrets.REMOTE_USER }}
|
||||
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
|
||||
TARGET: ${{ secrets.REMOTE_TARGET }}
|
||||
SOURCE: "docs/.vitepress/dist/"
|
||||
ARGS: "-rlgoDzvc -i --delete"
|
||||
|
||||
@ -1,32 +0,0 @@
|
||||
name: Weblate Pull Branch
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
pull_request_target:
|
||||
branches:
|
||||
- 'dev'
|
||||
types: [ closed ]
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
|
||||
jobs:
|
||||
weblate:
|
||||
runs-on: ubuntu-latest
|
||||
if: github.event.pull_request.merged == true || github.event.action == 'published' || github.event_name == 'workflow_dispatch'
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install wlc
|
||||
run: pip install wlc
|
||||
|
||||
- name: Update Repository
|
||||
env:
|
||||
WEBLATE_TOKEN: ${{ secrets.WEBLATE_TOKEN }}
|
||||
run: wlc --key $WEBLATE_TOKEN pull
|
||||
@ -1,86 +0,0 @@
|
||||
name: Synchronize Weblate Branch
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: '15 18 * * *'
|
||||
|
||||
env:
|
||||
DEVELOP_BRANCH: dev
|
||||
WEBLATE_BRANCH: weblate
|
||||
|
||||
jobs:
|
||||
check:
|
||||
name: Check Branches
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
behind: ${{ steps.check.outputs.behind }}
|
||||
ahead: ${{ steps.check.outputs.ahead }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.DEVELOP_BRANCH }}
|
||||
clean: false
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check branches
|
||||
id: check
|
||||
run: |
|
||||
git fetch --all
|
||||
git branch $WEBLATE_BRANCH origin/$WEBLATE_BRANCH
|
||||
echo "behind=$(git rev-list --count $WEBLATE_BRANCH..$DEVELOP_BRANCH)" >> $GITHUB_OUTPUT
|
||||
echo "ahead=$(git rev-list --count $DEVELOP_BRANCH..$WEBLATE_BRANCH)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Echo outputs
|
||||
run: |
|
||||
echo "behind: ${{ steps.check.outputs.behind }}"
|
||||
echo "ahead: ${{ steps.check.outputs.ahead }}"
|
||||
|
||||
force-update:
|
||||
name: Force Update Weblate Status
|
||||
runs-on: ubuntu-latest
|
||||
needs: check
|
||||
if: ${{ needs.check.outputs.behind > 0 }}
|
||||
env:
|
||||
WEBLATE_TOKEN: ${{ secrets.WEBLATE_TOKEN }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install wlc
|
||||
run: pip install wlc
|
||||
|
||||
- name: Update weblate repository
|
||||
run: wlc --key $WEBLATE_TOKEN pull
|
||||
|
||||
- name: Push weblate branch
|
||||
run: wlc --key $WEBLATE_TOKEN push
|
||||
|
||||
sync-branch:
|
||||
name: Sync Weblate Branch
|
||||
runs-on: ubuntu-latest
|
||||
needs: [check, force-update]
|
||||
if: ${{ needs.check.outputs.ahead > 0 && always() }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ env.DEVELOP_BRANCH }}
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Set up git
|
||||
run: |
|
||||
git config --global user.name 'Weblate'
|
||||
git config --global user.email 'weblate@nginxui.com'
|
||||
|
||||
- name: Push changes of weblate branch to develop branch
|
||||
run: |
|
||||
git fetch origin
|
||||
git merge --ff-only -- origin/${{ env.WEBLATE_BRANCH }}
|
||||
git push origin ${{ env.DEVELOP_BRANCH }}
|
||||
@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="database" uuid="31ab1005-9ff6-47e2-9df8-6c521ae42819">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/database.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
||||
@ -1,3 +0,0 @@
|
||||
[weblate]
|
||||
url = https://weblate.nginxui.com/api/
|
||||
translation = nginx-ui
|
||||
@ -1,156 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
"github.com/0xJacky/Nginx-UI/internal/passkey"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/google/uuid"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Status2FA struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
OTPStatus bool `json:"otp_status"`
|
||||
PasskeyStatus bool `json:"passkey_status"`
|
||||
}
|
||||
|
||||
func get2FAStatus(c *gin.Context) (status Status2FA) {
|
||||
// when accessing the node from the main cluster, there is no user in the context
|
||||
u, ok := c.Get("user")
|
||||
if ok {
|
||||
userPtr := u.(*model.User)
|
||||
status.OTPStatus = userPtr.EnabledOTP()
|
||||
status.PasskeyStatus = userPtr.EnabledPasskey() && passkey.Enabled()
|
||||
status.Enabled = status.OTPStatus || status.PasskeyStatus
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Get2FAStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, get2FAStatus(c))
|
||||
}
|
||||
|
||||
func SecureSessionStatus(c *gin.Context) {
|
||||
status2FA := get2FAStatus(c)
|
||||
if !status2FA.Enabled {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
ssid := c.GetHeader("X-Secure-Session-ID")
|
||||
if ssid == "" {
|
||||
ssid = c.Query("X-Secure-Session-ID")
|
||||
}
|
||||
if ssid == "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": false,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
u := api.CurrentUser(c)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": user.VerifySecureSessionID(ssid, u.ID),
|
||||
})
|
||||
}
|
||||
|
||||
func Start2FASecureSessionByOTP(c *gin.Context) {
|
||||
var json struct {
|
||||
OTP string `json:"otp"`
|
||||
RecoveryCode string `json:"recovery_code"`
|
||||
}
|
||||
if !api.BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
u := api.CurrentUser(c)
|
||||
if !u.EnabledOTP() {
|
||||
c.JSON(http.StatusBadRequest, gin.H{
|
||||
"message": "User has not configured OTP as 2FA",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if json.OTP == "" && json.RecoveryCode == "" {
|
||||
c.JSON(http.StatusBadRequest, LoginResponse{
|
||||
Message: "The user has enabled OTP as 2FA",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if err := user.VerifyOTP(u, json.OTP, json.RecoveryCode); err != nil {
|
||||
c.JSON(http.StatusBadRequest, LoginResponse{
|
||||
Message: "Invalid OTP or recovery code",
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
sessionId := user.SetSecureSessionID(u.ID)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": sessionId,
|
||||
})
|
||||
}
|
||||
|
||||
func BeginStart2FASecureSessionByPasskey(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
u := api.CurrentUser(c)
|
||||
options, sessionData, err := webauthnInstance.BeginLogin(u)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
passkeySessionID := uuid.NewString()
|
||||
cache.Set(passkeySessionID, sessionData, passkeyTimeout)
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": passkeySessionID,
|
||||
"options": options,
|
||||
})
|
||||
}
|
||||
|
||||
func FinishStart2FASecureSessionByPasskey(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
passkeySessionID := c.GetHeader("X-Passkey-Session-ID")
|
||||
sessionDataBytes, ok := cache.Get(passkeySessionID)
|
||||
if !ok {
|
||||
api.ErrHandler(c, fmt.Errorf("session not found"))
|
||||
return
|
||||
}
|
||||
sessionData := sessionDataBytes.(*webauthn.SessionData)
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
u := api.CurrentUser(c)
|
||||
credential, err := webauthnInstance.FinishLogin(u, *sessionData, c.Request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
rawID := strings.TrimRight(base64.StdEncoding.EncodeToString(credential.ID), "=")
|
||||
p := query.Passkey
|
||||
_, _ = p.Where(p.RawID.Eq(rawID)).Updates(&model.Passkey{
|
||||
LastUsedAt: time.Now().Unix(),
|
||||
})
|
||||
|
||||
sessionId := user.SetSecureSessionID(u.ID)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": sessionId,
|
||||
})
|
||||
}
|
||||
@ -1,195 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/api"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cosy"
|
||||
"github.com/0xJacky/Nginx-UI/internal/logger"
|
||||
"github.com/0xJacky/Nginx-UI/internal/passkey"
|
||||
"github.com/0xJacky/Nginx-UI/internal/user"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/0xJacky/Nginx-UI/query"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-webauthn/webauthn/webauthn"
|
||||
"github.com/google/uuid"
|
||||
"github.com/spf13/cast"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
const passkeyTimeout = 30 * time.Second
|
||||
|
||||
func buildCachePasskeyRegKey(id int) string {
|
||||
return fmt.Sprintf("passkey-reg-%d", id)
|
||||
}
|
||||
|
||||
func GetPasskeyConfigStatus(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"status": passkey.Enabled(),
|
||||
})
|
||||
}
|
||||
|
||||
func BeginPasskeyRegistration(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
|
||||
options, sessionData, err := webauthnInstance.BeginRegistration(u)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cache.Set(buildCachePasskeyRegKey(u.ID), sessionData, passkeyTimeout)
|
||||
|
||||
c.JSON(http.StatusOK, options)
|
||||
}
|
||||
|
||||
func FinishPasskeyRegistration(c *gin.Context) {
|
||||
cUser := api.CurrentUser(c)
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
sessionDataBytes, ok := cache.Get(buildCachePasskeyRegKey(cUser.ID))
|
||||
if !ok {
|
||||
api.ErrHandler(c, fmt.Errorf("session not found"))
|
||||
return
|
||||
}
|
||||
|
||||
sessionData := sessionDataBytes.(*webauthn.SessionData)
|
||||
credential, err := webauthnInstance.FinishRegistration(cUser, *sessionData, c.Request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
cache.Del(buildCachePasskeyRegKey(cUser.ID))
|
||||
|
||||
rawId := strings.TrimRight(base64.StdEncoding.EncodeToString(credential.ID), "=")
|
||||
passkeyName := c.Query("name")
|
||||
p := query.Passkey
|
||||
err = p.Create(&model.Passkey{
|
||||
UserID: cUser.ID,
|
||||
Name: passkeyName,
|
||||
RawID: rawId,
|
||||
Credential: credential,
|
||||
LastUsedAt: time.Now().Unix(),
|
||||
})
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
}
|
||||
|
||||
func BeginPasskeyLogin(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
options, sessionData, err := webauthnInstance.BeginDiscoverableLogin()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
sessionID := uuid.NewString()
|
||||
cache.Set(sessionID, sessionData, passkeyTimeout)
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"session_id": sessionID,
|
||||
"options": options,
|
||||
})
|
||||
}
|
||||
|
||||
func FinishPasskeyLogin(c *gin.Context) {
|
||||
if !passkey.Enabled() {
|
||||
api.ErrHandler(c, fmt.Errorf("WebAuthn settings are not configured"))
|
||||
return
|
||||
}
|
||||
sessionId := c.GetHeader("X-Passkey-Session-ID")
|
||||
sessionDataBytes, ok := cache.Get(sessionId)
|
||||
if !ok {
|
||||
api.ErrHandler(c, fmt.Errorf("session not found"))
|
||||
return
|
||||
}
|
||||
webauthnInstance := passkey.GetInstance()
|
||||
sessionData := sessionDataBytes.(*webauthn.SessionData)
|
||||
var outUser *model.User
|
||||
_, err := webauthnInstance.FinishDiscoverableLogin(
|
||||
func(rawID, userHandle []byte) (user webauthn.User, err error) {
|
||||
encodeRawID := strings.TrimRight(base64.StdEncoding.EncodeToString(rawID), "=")
|
||||
u := query.User
|
||||
logger.Debug("[WebAuthn] Discoverable Login", cast.ToInt(string(userHandle)))
|
||||
|
||||
p := query.Passkey
|
||||
_, _ = p.Where(p.RawID.Eq(encodeRawID)).Updates(&model.Passkey{
|
||||
LastUsedAt: time.Now().Unix(),
|
||||
})
|
||||
|
||||
outUser, err = u.FirstByID(cast.ToInt(string(userHandle)))
|
||||
return outUser, err
|
||||
}, *sessionData, c.Request)
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
b := query.BanIP
|
||||
clientIP := c.ClientIP()
|
||||
// login success, clear banned record
|
||||
_, _ = b.Where(b.IP.Eq(clientIP)).Delete()
|
||||
|
||||
logger.Info("[User Login]", outUser.Name)
|
||||
token, err := user.GenerateJWT(outUser)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, LoginResponse{
|
||||
Message: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, LoginResponse{
|
||||
Code: LoginSuccess,
|
||||
Message: "ok",
|
||||
Token: token,
|
||||
// SecureSessionID: secureSessionID,
|
||||
})
|
||||
}
|
||||
|
||||
func GetPasskeyList(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
p := query.Passkey
|
||||
passkeys, err := p.Where(p.UserID.Eq(u.ID)).Find()
|
||||
if err != nil {
|
||||
api.ErrHandler(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(passkeys) == 0 {
|
||||
passkeys = make([]*model.Passkey, 0)
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, passkeys)
|
||||
}
|
||||
|
||||
func UpdatePasskey(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
cosy.Core[model.Passkey](c).
|
||||
SetValidRules(gin.H{
|
||||
"name": "required",
|
||||
}).GormScope(func(tx *gorm.DB) *gorm.DB {
|
||||
return tx.Where("user_id", u.ID)
|
||||
}).Modify()
|
||||
}
|
||||
|
||||
func DeletePasskey(c *gin.Context) {
|
||||
u := api.CurrentUser(c)
|
||||
cosy.Core[model.Passkey](c).
|
||||
GormScope(func(tx *gorm.DB) *gorm.DB {
|
||||
return tx.Where("user_id", u.ID)
|
||||
}).PermanentlyDelete()
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,37 +0,0 @@
|
||||
import type { AuthenticationResponseJSON } from '@simplewebauthn/types'
|
||||
import http from '@/lib/http'
|
||||
|
||||
export interface TwoFAStatusResponse {
|
||||
enabled: boolean
|
||||
otp_status: boolean
|
||||
passkey_status: boolean
|
||||
}
|
||||
|
||||
const twoFA = {
|
||||
status(): Promise<TwoFAStatusResponse> {
|
||||
return http.get('/2fa_status')
|
||||
},
|
||||
start_secure_session_by_otp(passcode: string, recovery_code: string): Promise<{ session_id: string }> {
|
||||
return http.post('/2fa_secure_session/otp', {
|
||||
otp: passcode,
|
||||
recovery_code,
|
||||
})
|
||||
},
|
||||
secure_session_status(): Promise<{ status: boolean }> {
|
||||
return http.get('/2fa_secure_session/status')
|
||||
},
|
||||
begin_start_secure_session_by_passkey() {
|
||||
return http.get('/2fa_secure_session/passkey')
|
||||
},
|
||||
finish_start_secure_session_by_passkey(data: { session_id: string; options: AuthenticationResponseJSON }): Promise<{
|
||||
session_id: string
|
||||
}> {
|
||||
return http.post('/2fa_secure_session/passkey', data.options, {
|
||||
headers: {
|
||||
'X-Passkey-Session-Id': data.session_id,
|
||||
},
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
export default twoFA
|
||||
@ -1,36 +0,0 @@
|
||||
import type { RegistrationResponseJSON } from '@simplewebauthn/types'
|
||||
import http from '@/lib/http'
|
||||
import type { ModelBase } from '@/api/curd'
|
||||
|
||||
export interface Passkey extends ModelBase {
|
||||
name: string
|
||||
user_id: string
|
||||
raw_id: string
|
||||
}
|
||||
|
||||
const passkey = {
|
||||
begin_registration() {
|
||||
return http.get('/begin_passkey_register')
|
||||
},
|
||||
finish_registration(attestationResponse: RegistrationResponseJSON, passkeyName: string) {
|
||||
return http.post('/finish_passkey_register', attestationResponse, {
|
||||
params: {
|
||||
name: passkeyName,
|
||||
},
|
||||
})
|
||||
},
|
||||
get_list() {
|
||||
return http.get('/passkeys')
|
||||
},
|
||||
update(passkeyId: number, data: Passkey) {
|
||||
return http.post(`/passkeys/${passkeyId}`, data)
|
||||
},
|
||||
remove(passkeyId: number) {
|
||||
return http.delete(`/passkeys/${passkeyId}`)
|
||||
},
|
||||
get_config_status(): Promise<{ status: boolean }> {
|
||||
return http.get('/passkeys/config')
|
||||
},
|
||||
}
|
||||
|
||||
export default passkey
|
||||
@ -0,0 +1,78 @@
|
||||
<script setup lang="ts">
|
||||
import OTPInput from '@/components/OTPInput/OTPInput.vue'
|
||||
|
||||
const emit = defineEmits(['onSubmit'])
|
||||
|
||||
const refOTP = ref()
|
||||
const useRecoveryCode = ref(false)
|
||||
const passcode = ref('')
|
||||
const recoveryCode = ref('')
|
||||
|
||||
function clickUseRecoveryCode() {
|
||||
passcode.value = ''
|
||||
useRecoveryCode.value = true
|
||||
}
|
||||
|
||||
function clickUseOTP() {
|
||||
passcode.value = ''
|
||||
useRecoveryCode.value = false
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
emit('onSubmit', passcode.value, recoveryCode.value)
|
||||
}
|
||||
|
||||
function clearInput() {
|
||||
refOTP.value?.clearInput()
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
clearInput,
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="!useRecoveryCode">
|
||||
<p>{{ $gettext('Please enter the 2FA code:') }}</p>
|
||||
<OTPInput
|
||||
ref="refOTP"
|
||||
v-model="passcode"
|
||||
class="justify-center mb-6"
|
||||
@on-complete="onSubmit"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="mt-2 mb-4"
|
||||
>
|
||||
<p>{{ $gettext('Input the recovery code:') }}</p>
|
||||
<AInputGroup compact>
|
||||
<AInput v-model:value="recoveryCode" />
|
||||
<AButton
|
||||
type="primary"
|
||||
@click="onSubmit"
|
||||
>
|
||||
{{ $gettext('Recovery') }}
|
||||
</AButton>
|
||||
</AInputGroup>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center">
|
||||
<a
|
||||
v-if="!useRecoveryCode"
|
||||
@click="clickUseRecoveryCode"
|
||||
>{{ $gettext('Use recovery code') }}</a>
|
||||
<a
|
||||
v-else
|
||||
@click="clickUseOTP"
|
||||
>{{ $gettext('Use OTP') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
:deep(.ant-input-group.ant-input-group-compact) {
|
||||
display: flex;
|
||||
}
|
||||
</style>
|
||||
@ -1,63 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
|
||||
const props = defineProps<{
|
||||
time?: string | number
|
||||
}>()
|
||||
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
const text = ref('')
|
||||
|
||||
const time = computed(() => {
|
||||
if (!props.time)
|
||||
return ''
|
||||
|
||||
if (typeof props.time === 'number')
|
||||
return props.time
|
||||
|
||||
return Number.parseInt(props.time)
|
||||
})
|
||||
|
||||
let timer: NodeJS.Timeout
|
||||
let step: number = 1
|
||||
|
||||
async function computedText() {
|
||||
if (!time.value)
|
||||
return
|
||||
|
||||
// if time is not today, return the datetime
|
||||
const thatDay = dayjs.unix(time.value).format('YYYY-MM-DD')
|
||||
if (dayjs().format('YYYY-MM-DD') !== dayjs.unix(time.value).format('YYYY-MM-DD')) {
|
||||
clearInterval(timer)
|
||||
text.value = thatDay
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
text.value = dayjs.unix(time.value).fromNow()
|
||||
|
||||
clearInterval(timer)
|
||||
|
||||
timer = setInterval(computedText, step * 60 * 1000)
|
||||
|
||||
step += 5
|
||||
|
||||
if (step >= 60)
|
||||
step = 60
|
||||
}
|
||||
|
||||
onMounted(computedText)
|
||||
watch(() => props.time, computedText)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="reactive-time inline">
|
||||
{{ text }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
</style>
|
||||
@ -1,4 +0,0 @@
|
||||
export interface StdTableSlots {
|
||||
'append-search': ({}) => any
|
||||
actions: ({}: Record<string, any>) => any
|
||||
}
|
||||
@ -1,136 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { KeyOutlined } from '@ant-design/icons-vue'
|
||||
import { startAuthentication } from '@simplewebauthn/browser'
|
||||
import { message } from 'ant-design-vue'
|
||||
import OTPInput from '@/components/OTPInput/OTPInput.vue'
|
||||
import type { TwoFAStatusResponse } from '@/api/2fa'
|
||||
import twoFA from '@/api/2fa'
|
||||
import { useUserStore } from '@/pinia'
|
||||
|
||||
defineProps<{
|
||||
twoFAStatus: TwoFAStatusResponse
|
||||
}>()
|
||||
|
||||
const emit = defineEmits(['submitOTP', 'submitSecureSessionID'])
|
||||
|
||||
const user = useUserStore()
|
||||
const refOTP = ref()
|
||||
const useRecoveryCode = ref(false)
|
||||
const passcode = ref('')
|
||||
const recoveryCode = ref('')
|
||||
const passkeyLoading = ref(false)
|
||||
|
||||
function clickUseRecoveryCode() {
|
||||
passcode.value = ''
|
||||
useRecoveryCode.value = true
|
||||
}
|
||||
|
||||
function clickUseOTP() {
|
||||
passcode.value = ''
|
||||
useRecoveryCode.value = false
|
||||
}
|
||||
|
||||
function onSubmit() {
|
||||
emit('submitOTP', passcode.value, recoveryCode.value)
|
||||
}
|
||||
|
||||
function clearInput() {
|
||||
refOTP.value?.clearInput()
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
clearInput,
|
||||
})
|
||||
|
||||
async function passkeyAuthenticate() {
|
||||
passkeyLoading.value = true
|
||||
try {
|
||||
const begin = await twoFA.begin_start_secure_session_by_passkey()
|
||||
const asseResp = await startAuthentication(begin.options.publicKey)
|
||||
|
||||
const r = await twoFA.finish_start_secure_session_by_passkey({
|
||||
session_id: begin.session_id,
|
||||
options: asseResp,
|
||||
})
|
||||
|
||||
emit('submitSecureSessionID', r.session_id)
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
catch (e: any) {
|
||||
message.error($gettext(e.message ?? 'Server error'))
|
||||
}
|
||||
passkeyLoading.value = false
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (user.passkeyLoginAvailable)
|
||||
passkeyAuthenticate()
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div v-if="twoFAStatus.otp_status">
|
||||
<div v-if="!useRecoveryCode">
|
||||
<p>{{ $gettext('Please enter the OTP code:') }}</p>
|
||||
<OTPInput
|
||||
ref="refOTP"
|
||||
v-model="passcode"
|
||||
class="justify-center mb-6"
|
||||
@on-complete="onSubmit"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="mt-2 mb-4"
|
||||
>
|
||||
<p>{{ $gettext('Input the recovery code:') }}</p>
|
||||
<AInputGroup compact>
|
||||
<AInput v-model:value="recoveryCode" />
|
||||
<AButton
|
||||
type="primary"
|
||||
@click="onSubmit"
|
||||
>
|
||||
{{ $gettext('Recovery') }}
|
||||
</AButton>
|
||||
</AInputGroup>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-center">
|
||||
<a
|
||||
v-if="!useRecoveryCode"
|
||||
@click="clickUseRecoveryCode"
|
||||
>{{ $gettext('Use recovery code') }}</a>
|
||||
<a
|
||||
v-else
|
||||
@click="clickUseOTP"
|
||||
>{{ $gettext('Use OTP') }}</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-if="twoFAStatus.passkey_status"
|
||||
class="flex flex-col justify-center"
|
||||
>
|
||||
<ADivider v-if="twoFAStatus.otp_status">
|
||||
<div class="text-sm font-normal opacity-75">
|
||||
{{ $gettext('Or') }}
|
||||
</div>
|
||||
</ADivider>
|
||||
|
||||
<AButton
|
||||
:loading="passkeyLoading"
|
||||
@click="passkeyAuthenticate"
|
||||
>
|
||||
<KeyOutlined />
|
||||
{{ $gettext('Authenticate with a passkey') }}
|
||||
</AButton>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
:deep(.ant-input-group.ant-input-group-compact) {
|
||||
display: flex;
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
@ -1 +1 @@
|
||||
{"version":"2.0.0-beta.35","build_id":160,"total_build":364}
|
||||
{"version":"2.0.0-beta.28","build_id":149,"total_build":353}
|
||||
@ -1,118 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { startRegistration } from '@simplewebauthn/browser'
|
||||
import { message } from 'ant-design-vue'
|
||||
import passkey from '@/api/passkey'
|
||||
import { useUserStore } from '@/pinia'
|
||||
|
||||
const emit = defineEmits(['created'])
|
||||
|
||||
const user = useUserStore()
|
||||
const passkeyName = ref('')
|
||||
const addPasskeyModelOpen = ref(false)
|
||||
const passkeyEnabled = ref(false)
|
||||
|
||||
const regLoading = ref(false)
|
||||
async function registerPasskey() {
|
||||
regLoading.value = true
|
||||
try {
|
||||
const options = await passkey.begin_registration()
|
||||
|
||||
const attestationResponse = await startRegistration(options.publicKey)
|
||||
|
||||
await passkey.finish_registration(attestationResponse, passkeyName.value)
|
||||
|
||||
emit('created')
|
||||
|
||||
message.success($gettext('Register passkey successfully'))
|
||||
addPasskeyModelOpen.value = false
|
||||
|
||||
user.passkeyRawId = attestationResponse.rawId
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
catch (e: any) {
|
||||
message.error($gettext(e.message ?? 'Server error'))
|
||||
}
|
||||
regLoading.value = false
|
||||
}
|
||||
|
||||
function addPasskey() {
|
||||
addPasskeyModelOpen.value = true
|
||||
passkeyName.value = ''
|
||||
}
|
||||
|
||||
passkey.get_config_status().then(r => {
|
||||
passkeyEnabled.value = r.status
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<AButton @click="addPasskey">
|
||||
{{ $gettext('Add a passkey') }}
|
||||
</AButton>
|
||||
<AModal
|
||||
v-model:open="addPasskeyModelOpen"
|
||||
:title="$gettext('Add a passkey')"
|
||||
centered
|
||||
:mask="false"
|
||||
:mask-closable="!passkeyEnabled"
|
||||
:closable="!passkeyEnabled"
|
||||
:footer="passkeyEnabled ? undefined : false"
|
||||
:confirm-loading="regLoading"
|
||||
@ok="registerPasskey"
|
||||
>
|
||||
<AForm
|
||||
v-if="passkeyEnabled"
|
||||
layout="vertical"
|
||||
>
|
||||
<div>
|
||||
<AAlert
|
||||
class="mb-4"
|
||||
:message="$gettext('Tips')"
|
||||
type="info"
|
||||
>
|
||||
<template #description>
|
||||
<p>{{ $gettext('Please enter a name for the passkey you wish to create and click the OK button below.') }}</p>
|
||||
<p>{{ $gettext('If your browser supports WebAuthn Passkey, a dialog box will appear.') }}</p>
|
||||
<p>{{ $gettext('Follow the instructions in the dialog to complete the passkey registration process.') }}</p>
|
||||
</template>
|
||||
</AAlert>
|
||||
</div>
|
||||
<AFormItem :label="$gettext('Name')">
|
||||
<AInput v-model:value="passkeyName" />
|
||||
</AFormItem>
|
||||
</AForm>
|
||||
<div v-else>
|
||||
<AAlert
|
||||
class="mb-4"
|
||||
:message="$gettext('Warning')"
|
||||
type="warning"
|
||||
show-icon
|
||||
>
|
||||
<template #description>
|
||||
<p>{{ $gettext('You have not configured the settings of Webauthn, so you cannot add a passkey.') }}</p>
|
||||
<p>
|
||||
{{ $gettext('To ensure security, Webauthn configuration cannot be added through the UI. '
|
||||
+ 'Please manually configure the following in the app.ini configuration file and restart Nginx UI.') }}
|
||||
</p>
|
||||
<pre>[webauthn]
|
||||
# This is the display name
|
||||
RPDisplayName = Nginx UI
|
||||
# The domain name of Nginx UI
|
||||
RPID = localhost
|
||||
# The list of origin addresses
|
||||
RPOrigins = http://localhost:3002</pre>
|
||||
<p>{{ $gettext('Afterwards, refresh this page and click add passkey again.') }}</p>
|
||||
<p>
|
||||
{{ $gettext(`Due to the security policies of some browsers, you cannot use passkeys on non-HTTPS websites, except when running on localhost.`) }}
|
||||
</p>
|
||||
</template>
|
||||
</AAlert>
|
||||
</div>
|
||||
</AModal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
</style>
|
||||
@ -1,159 +0,0 @@
|
||||
<script setup lang="ts">
|
||||
import { message } from 'ant-design-vue'
|
||||
import { DeleteOutlined, EditOutlined, KeyOutlined } from '@ant-design/icons-vue'
|
||||
import dayjs from 'dayjs'
|
||||
import relativeTime from 'dayjs/plugin/relativeTime'
|
||||
import { formatDateTime } from '@/lib/helper'
|
||||
import type { Passkey } from '@/api/passkey'
|
||||
import passkey from '@/api/passkey'
|
||||
import ReactiveFromNow from '@/components/ReactiveFromNow/ReactiveFromNow.vue'
|
||||
import { useUserStore } from '@/pinia'
|
||||
import AddPasskey from '@/views/preference/components/AddPasskey.vue'
|
||||
|
||||
dayjs.extend(relativeTime)
|
||||
|
||||
const user = useUserStore()
|
||||
|
||||
const getListLoading = ref(true)
|
||||
const data = ref([]) as Ref<Passkey[]>
|
||||
const passkeyName = ref('')
|
||||
|
||||
function getList() {
|
||||
getListLoading.value = true
|
||||
passkey.get_list().then(r => {
|
||||
data.value = r
|
||||
}).catch((e: { message?: string }) => {
|
||||
message.error(e?.message ?? $gettext('Server error'))
|
||||
}).finally(() => {
|
||||
getListLoading.value = false
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
|
||||
const modifyIdx = ref(-1)
|
||||
function update(id: number, record: Passkey) {
|
||||
passkey.update(id, record).then(() => {
|
||||
getList()
|
||||
modifyIdx.value = -1
|
||||
message.success($gettext('Update successfully'))
|
||||
}).catch((e: { message?: string }) => {
|
||||
message.error(e?.message ?? $gettext('Server error'))
|
||||
})
|
||||
}
|
||||
|
||||
function remove(item: Passkey) {
|
||||
passkey.remove(item.id).then(() => {
|
||||
getList()
|
||||
message.success($gettext('Remove successfully'))
|
||||
|
||||
// if current passkey is removed, clear it from user store
|
||||
if (user.passkeyLoginAvailable && user.passkeyRawId === item.raw_id)
|
||||
user.passkeyRawId = ''
|
||||
}).catch((e: { message?: string }) => {
|
||||
message.error(e?.message ?? $gettext('Server error'))
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div>
|
||||
<h3>
|
||||
{{ $gettext('Passkey') }}
|
||||
</h3>
|
||||
<p>
|
||||
{{ $gettext('Passkeys are webauthn credentials that validate your identity using touch, '
|
||||
+ 'facial recognition, a device password, or a PIN. '
|
||||
+ 'They can be used as a password replacement or as a 2FA method.') }}
|
||||
</p>
|
||||
</div>
|
||||
<AList
|
||||
class="mt-4"
|
||||
bordered
|
||||
:data-source="data"
|
||||
>
|
||||
<template #header>
|
||||
<div class="flex items-center justify-between">
|
||||
<div class="font-bold">
|
||||
{{ $gettext('Your passkeys') }}
|
||||
</div>
|
||||
<AddPasskey @created="() => getList()" />
|
||||
</div>
|
||||
</template>
|
||||
<template #renderItem="{ item, index }">
|
||||
<AListItem>
|
||||
<AListItemMeta>
|
||||
<template #title>
|
||||
<div class="flex gap-2">
|
||||
<KeyOutlined />
|
||||
<div v-if="index !== modifyIdx">
|
||||
{{ item.name }}
|
||||
</div>
|
||||
<div v-else>
|
||||
<AInput v-model:value="passkeyName" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template #description>
|
||||
{{ $gettext('Created at') }}: {{ formatDateTime(item.created_at) }} · {{
|
||||
$gettext('Last used at') }}: <ReactiveFromNow :time="item.last_used_at" />
|
||||
</template>
|
||||
</AListItemMeta>
|
||||
<template #extra>
|
||||
<div v-if="modifyIdx !== index">
|
||||
<AButton
|
||||
type="link"
|
||||
size="small"
|
||||
@click="() => {
|
||||
modifyIdx = index
|
||||
passkeyName = item.name
|
||||
}"
|
||||
>
|
||||
<EditOutlined />
|
||||
</AButton>
|
||||
|
||||
<APopconfirm
|
||||
:title="$gettext('Are you sure to delete this passkey immediately?')"
|
||||
@confirm="() => remove(item)"
|
||||
>
|
||||
<AButton
|
||||
type="link"
|
||||
danger
|
||||
size="small"
|
||||
>
|
||||
<DeleteOutlined />
|
||||
</AButton>
|
||||
</APopconfirm>
|
||||
</div>
|
||||
<div v-else>
|
||||
<AButton
|
||||
size="small"
|
||||
@click="() => update(item.id, { ...item, name: passkeyName })"
|
||||
>
|
||||
{{ $gettext('Save') }}
|
||||
</AButton>
|
||||
|
||||
<AButton
|
||||
type="link"
|
||||
size="small"
|
||||
@click="() => {
|
||||
modifyIdx = -1
|
||||
passkeyName = item.name
|
||||
}"
|
||||
>
|
||||
{{ $gettext('Cancel') }}
|
||||
</AButton>
|
||||
</div>
|
||||
</template>
|
||||
</AListItem>
|
||||
</template>
|
||||
</AList>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
|
||||
</style>
|
||||
@ -0,0 +1 @@
|
||||
{"version":"2.0.0-beta.28","build_id":149,"total_build":353}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue