102 Commits

Author SHA1 Message Date
hoangvv f0d6780c12 update 2024-07-01 11:56:38 +07:00
hoangvv 2e845d29b7 suppport multiple users 2024-07-01 04:01:09 +07:00
hoangvv 11de9608cd update 2024-06-29 12:31:55 +07:00
hoangvv 4e1321db6d update UserStatus function 2024-06-29 12:26:04 +07:00
hoangvv cd28792c15 Merge remote-tracking branch 'casaos/main' into version-1.1 2024-06-02 22:33:23 +07:00
CorrectRoad 5cf4ed5424 chore: bump version to 0.4.8 (#43) 2024-03-26 11:35:25 +08:00
CorrectRoad dd927fe1c8 Merge pull request from GHSA-hcw2-2r9c-gc6p 2024-03-12 18:17:46 +08:00
CorrectRoad 9c261dd8df feat:clean login limit after login successful (#42) 2024-03-11 17:29:22 +08:00
Link 7bd0df6441 add gpu number 2024-03-01 09:09:05 +00:00
hoangvv f1b7e28a14 update 2024-02-21 12:06:40 +07:00
CorrectRoadH 62006f61b5 Merge pull request from GHSA-c69x-5xmw-v44x
* feat: limit too many login request

* fix: fix error rate limt

---------

Signed-off-by: CorrectRoadH <a778917369@gmail.com>
2024-02-05 14:15:00 +08:00
CorrectRoadH c75063d7ca Merge pull request from GHSA-c967-2652-gfjm
* fix: fix username enumeration

* fix typo msg type

* fix: recovery error patch

* fix: recovery error patch

---------

Signed-off-by: CorrectRoadH <a778917369@gmail.com>
2024-02-05 14:13:58 +08:00
Link 6738be00df update sum 2024-02-04 08:43:07 +00:00
Link 3db4be01c4 Send notification 2024-02-04 08:15:37 +00:00
Link 2fdbdcf1ec Adding Absolute Path Determination 2024-02-04 06:36:38 +00:00
link 3f4558e23c Merge pull request from GHSA-h5gf-cmm8-cg7c 2024-02-04 11:08:01 +08:00
link 4d2b65e34c add user avatar 2024-01-11 09:21:47 +00:00
link fd925df5d1 remove cache 2024-01-11 07:01:22 +00:00
link 2c1a72c5e5 jump local-storage:raid_status event 2024-01-09 02:41:43 +00:00
link cd06d3ca37 Merge branch 'main' of https://github.com/IceWhaleTech/CasaOS-UserService 2024-01-04 04:02:54 +00:00
link dc6cf30f7d update avatar 2024-01-04 04:02:51 +00:00
Link 6267b241a0 update user avatar cache 2024-01-04 03:08:50 +00:00
link b65d1350e3 add get avatar function 2024-01-02 06:20:48 +00:00
link 3eaceda8d1 update avatar 2023-12-29 15:21:06 +00:00
link e6c78401e7 update go sum 2023-12-29 08:06:22 +00:00
Link 8093de59ad update common 2023-12-28 11:34:09 +00:00
Link 5f166b9d3c add user avatar 2023-11-27 08:56:29 +00:00
Link 869aa367f9 update goreleaser 2023-11-20 10:10:44 +00:00
Link 527e583f22 update goreleaser 2023-11-20 10:05:22 +00:00
Link 9c9a30c028 uodate releaser 2023-11-20 10:00:15 +00:00
Tiger Wang 9a986a60ad create default config if it does not already exist (#39) 2023-07-31 17:18:09 +08:00
raller1028 f626b02570 Update release.yml (#38)
Signed-off-by: raller1028 <57336867+raller1028@users.noreply.github.com>
2023-07-14 16:46:26 +08:00
raller1028 f4e5706935 Update push_test_server.yml (#37)
Signed-off-by: raller1028 <57336867+raller1028@users.noreply.github.com>
2023-07-14 16:45:34 +08:00
Tiger Wang 97c42efa71 fix extra content in the response body when JWT is invalid (#36)
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-04-24 18:22:18 -04:00
Tiger Wang a2a23d1541 bump version from 0.4.3 to 0.4.4
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-04-22 14:03:04 +00:00
Tiger Wang 28b9015f29 use formal JWT validation (#35) 2023-04-22 00:46:18 -04:00
Tiger Wang 7ef878cb1a upgrade dependencies (#34)
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-03-25 23:27:34 -04:00
Tiger Wang 6dfbf0eba9 update github workflow with newer version of different actions (#33) 2023-03-21 22:57:30 -04:00
zhanghengxin f5fcd9ed92 🎨: Add openapi. (#32)
Signed-off-by: zhanghengxin <812718649@qq.com>
2023-03-15 14:07:38 -04:00
raller1028 ac34a1356d Update push_test_server.yml
Signed-off-by: raller1028 <57336867+raller1028@users.noreply.github.com>
2023-03-02 15:49:35 +08:00
raller1028 b7cc389ef9 Update push_test_server.yml
Signed-off-by: raller1028 <57336867+raller1028@users.noreply.github.com>
2023-02-21 16:49:30 +08:00
raller1028 f4dda2d6dd Update push_test_server.yml
Signed-off-by: raller1028 <57336867+raller1028@users.noreply.github.com>
2023-02-17 13:40:26 +08:00
Tiger Wang f054c5340e bump version from 0.4.1 to 0.4.2
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-02-09 19:46:34 -05:00
Tiger Wang 76adb01211 fix installation issue for Mint Linux (#31)
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-02-09 19:45:39 -05:00
link 3f89c925f2 Create push_test_server.yml
Signed-off-by: link <a624669980@163.com>
2023-01-31 18:27:49 +08:00
Tiger Wang 0d57552952 fix wrong checksum.txt gets uploaded to OSS
Signed-off-by: Tiger Wang <tigerwang@outlook.com>
2023-01-19 17:05:39 +00:00
Tiger Wang 4fc80b5a1e enable code coverage (#30) 2023-01-17 12:38:22 -05:00
link 13b6091c79 update migration tool url 2023-01-05 03:36:45 +00:00
Tiger Wang 856c5aeb48 add upx as part of building step to shrink the size of binary files (#28) 2022-12-29 18:19:49 -05:00
LinkLeong 8c960524e0 add error log 2022-12-07 03:56:35 +00:00
link 6b1d67efb1 Dependency (#27) 2022-12-07 11:01:33 +08:00
Tiger Wang cbaba50f6f update deepmap/oapi-codegen from v0.12.2 to v0.12.4 (openapi) 2022-12-07 02:23:38 +00:00
Tiger Wang 2acf34b224 fix sqlite db lock by reducing maximum open connections to 1 (#26) 2022-12-02 17:14:57 -05:00
Tiger Wang e2f9de8d4c add .goreleaser.debug.yaml for debugging 2022-12-02 18:23:24 +00:00
Tiger Wang a7aec4cc5b add missing go generate to build process 2022-12-01 18:29:58 -05:00
link 98a35cb107 add message_bus service dependency (#25) 2022-12-01 17:17:44 +08:00
Tiger Wang f6ad3aa89a replace CGO implementation of sqlite with an implementation in pure Go (#24) 2022-11-30 00:07:36 -05:00
link dab1fdd6be Event retention (#23)
Signed-off-by: link <a624669980@163.com>
2022-11-30 12:16:11 +08:00
Tiger Wang b41ab1ecce remove "-snapshot" from package naming 2022-11-29 17:51:12 +00:00
Ns2Kracy a45ded5088 added arch support (#22) 2022-11-29 10:31:12 -05:00
Tiger Wang 36f4943020 bump version from 0.3.8 to 0.4.0 2022-11-28 16:43:08 +00:00
Tiger Wang a50025f316 update go.sum 2022-11-25 17:06:38 -05:00
Tiger Wang 8512876392 update CasaOS-Common 2022-11-25 17:03:55 -05:00
Tiger Wang 23d3c28288 add restrictive license check to gorelease workflow (#21) 2022-11-10 19:40:11 -05:00
Tiger Wang 12b047295e fix potential goroutine leak due to http request without a timeout (#20) 2022-11-03 18:07:11 -04:00
Tiger Wang e2d9ecf229 bump version and cleanup migration tool for previous version (#19) 2022-11-02 11:05:42 -04:00
link 7da057088c Update release.yml
Signed-off-by: link <a624669980@163.com>
2022-10-31 14:43:36 +08:00
Tiger Wang 2866ad73b5 change to use CasaOS-Common for calling gateway (#18) 2022-10-28 17:28:04 -04:00
link f112ed1783 Update release.yml
Signed-off-by: link <a624669980@163.com>
2022-10-26 17:09:42 +08:00
link 1813afe0ae Update release.yml
Signed-off-by: link <a624669980@163.com>
2022-10-26 17:05:01 +08:00
Tiger Wang 86a8c845c6 use $BASH instead of $SHELL in setup and cleanup script in case of running under non-bash shell. (#17)
fixes https://github.com/IceWhaleTech/CasaOS/issues/572
2022-10-21 13:41:41 -04:00
Tiger Wang 06ec3d5142 add cleanup script for future uninstall modularization (#16) 2022-10-20 21:07:35 -04:00
Tiger Wang 58a10d2200 fix incorrect version reference 2022-09-28 17:38:35 -04:00
Tiger Wang 0d7fee0cb1 fix gosec G114/G112 2022-09-28 17:30:34 -04:00
Tiger Wang 8fcaee063d add go test to goreleaser 2022-09-25 23:10:17 -04:00
Tiger Wang 71e4f36c42 wip (#15) 2022-09-16 14:48:38 +08:00
Tiger Wang (王豫) 58ce3d1210 fix migration from v0.3.5 (#14) 2022-09-09 09:00:49 -04:00
Tiger Wang 828fd3b8f5 cleanup mod 2022-09-06 23:17:09 +00:00
Tiger Wang (王豫) ace8e30dfb fix service startup issue (#13)
- update service to be ready only when initialization is completed
- remove starting service within setup script (let calling script to start the service instead)
2022-09-06 19:13:00 -04:00
Tiger Wang 931d466df6 minor code cleanup 2022-09-01 23:09:54 +00:00
Tiger Wang e141c51b93 bump version to v0.3.6 2022-09-01 17:37:38 +00:00
Tiger Wang 7b3bdbbf8a cleanup setup and migration scripts 2022-09-01 17:34:37 +00:00
Tiger Wang (王豫) 38fee52518 add migration versioning (#12) 2022-08-31 23:58:59 -04:00
Tiger Wang (王豫) 6c73a4be13 fix migration from v0.3.3 (#11) 2022-08-31 17:56:39 -04:00
Tiger Wang (王豫) 9afe211d90 fix migration from 0.3.5.1 (#10) 2022-08-31 00:29:50 -04:00
Tiger Wang (王豫) 44ca8efc0d update CasaOS-Common (#9) 2022-08-30 00:27:38 -04:00
Tiger Wang (王豫) 675ecb55f7 add migration logic for 0.2.x (#8) 2022-08-28 20:40:51 -04:00
Tiger Wang (王豫) 5417c6b94b use middlewares from CasaOS-Common (#7) 2022-08-25 17:36:24 -04:00
Tiger Wang (王豫) 8d9c3f987d fix migration not working for LEGACY_WITHOUT_VERSION (#6) 2022-08-23 22:55:46 -04:00
Tiger Wang 210aa979f5 bump version 2022-08-24 01:27:48 +00:00
Tiger Wang 44780ac1b4 bump version in migration.list 2022-08-22 21:33:25 +00:00
Tiger Wang (王豫) acdbb326bc change to static linking when building so older Linux distributions are supported (#5) 2022-08-22 17:22:27 -04:00
Tiger Wang (王豫) 8b2af35f39 add incrementation migration logic (#4) 2022-08-15 18:58:08 -04:00
Tiger Wang 2493e91ce8 build fix 2022-08-12 04:18:09 +00:00
Tiger Wang (王豫) 0b66fd838f add migration from versions 0.3.3, 0.3.4, 0.3.5 (#3) 2022-08-12 00:07:50 -04:00
Tiger Wang 52d38428b6 update README.md 2022-08-08 16:46:43 +00:00
Tiger Wang c1272b4b30 fixed goreleaser badge 2022-08-07 03:16:12 +00:00
Tiger Wang fe354dfa7f removed branch trigger from GitHub workflow 2022-08-07 02:58:00 +00:00
Tiger Wang 1d1a15a221 updated README.md 2022-08-07 02:54:31 +00:00
Tiger Wang (王豫) 7792496f2d (#2)
- added workflow for releasing
2022-08-06 22:52:14 -04:00
Tiger Wang (王豫) e2b617e510 (#1)
- refactored User service from IceWhaleTech/CasaOS as first modularized service
2022-08-04 19:14:53 -04:00
Tiger Wang (王豫) a71dd10757 Initial commit 2022-07-22 11:11:34 -04:00
26 changed files with 631 additions and 30 deletions
+28
View File
@@ -0,0 +1,28 @@
name: Collect Code Coverage
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.20"
- name: Go Generate
run: go generate
- name: Run coverage
run: go test -race -failfast -coverprofile=coverage.txt -covermode=atomic -v ./...
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
+38
View File
@@ -0,0 +1,38 @@
name: publish npm
on:
push:
tags:
- v*.*.*
workflow_dispatch:
permissions:
contents: write
jobs:
publish-npm:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
registry-url: https://registry.npmjs.org/
- name: Get version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//}
- name: Set version
run: |
apt install jq
jq '.version="${{ steps.get_version.outputs.VERSION }}"' package.json > package.json.new
mv package.json.new package.json
- name: Generate SDK
run: |
npm cache clean --force
npm install @openapitools/openapi-generator-cli -g
make build
- run: npm i
- run: npm run start
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
+75
View File
@@ -0,0 +1,75 @@
name: Auto Publish Website
on:
push:
branches:
- main
permissions:
contents: write
jobs:
goreleaser:
runs-on: ubuntu-22.04
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: isntall git
run: sudo apt install --yes git
- name: git global
run: sudo git config --global --add safe.directory '*'
-
name: Fetch all tags
run: sudo git fetch --force --tags
- name: set version
run: sudo git tag v99.99.99-alpha
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
version: 1.14.1
args: release --rm-dist --snapshot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
- name: remove migration file
run: find . -type f \( -name '*migration*' \) -delete
- name: install sshpass
run: sudo apt install sshpass --yes
- name: ZeroTier
uses: zerotier/github-action@v1.0.1
with:
network_id: ${{ secrets.ZEROTIER_NETWORK_ID }}
auth_token: ${{ secrets.ZEROTIER_CENTRAL_TOKEN }}
- name: ping host
shell: bash
run: |
count=10
while ! ping -c 1 10.147.18.11 ; do
echo "waiting..." ;
sleep 1 ;
let count=count-1
done
echo "ping success"
- name: copy tar to target host
shell: bash
run: |
sshpass -p "${{ secrets.ssh_password }}" scp -r -o StrictHostKeyChecking=no -P 22 ./dist/*.gz root@10.147.18.11:/var/www/download
echo "ping success"
- name: send message
run: |
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"text","content":{"text":"CasaOS-User updated"}}' ${{ secrets.SSH_ROBOT_URL }}
+17
View File
@@ -0,0 +1,17 @@
name: goreleaser
on:
push:
tags:
- v*.*.*
permissions:
contents: write
jobs:
call-workflow-passing-data:
uses: IceWhaleTech/github/.github/workflows/go_release.yml@main
with:
project-name: CasaOS-UserService
file-name: casaos-user-service
secrets:
OSS_KEY_ID: ${{ secrets.OSS_KEY_ID }}
OSS_KEY_SECRET: ${{ secrets.OSS_KEY_SECRET }}
+33
View File
@@ -0,0 +1,33 @@
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# IDE
.vscode/
target/
dist/
__debug_bin
codegen/
node_modules/
dist/
.idea
.package-lock.json
*.sh
build/scripts/setup/service.d/user-service/ubuntu/setup-user-service.sh
linux-amd64-nextzenos-user-service-v1.3.tar.gz
build/sysroot/usr/bin/casaos-user-service
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
/build/scripts/setup
+1 -1
View File
@@ -6,7 +6,7 @@
"type": "go", "type": "go",
"debugAdapter": "dlv-dap", "debugAdapter": "dlv-dap",
"request": "launch", "request": "launch",
"port": 2345, "port": 2346,
"host": "127.0.0.1", "host": "127.0.0.1",
"mode": "exec", "mode": "exec",
"program": "${workspaceFolder}/dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service" "program": "${workspaceFolder}/dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service"
@@ -0,0 +1 @@
../setup-user-service.sh
@@ -0,0 +1,22 @@
#!/bin/bash
set -e
readonly APP_NAME="casaos-user-service"
readonly APP_NAME_SHORT="user-service"
# copy config files
readonly CONF_PATH=/etc/casaos
readonly CONF_FILE=${CONF_PATH}/${APP_NAME_SHORT}.conf
readonly CONF_FILE_SAMPLE=${CONF_PATH}/${APP_NAME_SHORT}.conf.sample
if [ ! -f "${CONF_FILE}" ]; then \
echo "Initializing config file..."
cp -v "${CONF_FILE_SAMPLE}" "${CONF_FILE}"; \
fi
systemctl daemon-reload
# enable service (without starting)
echo "Enabling service..."
systemctl enable --force --no-ask-password "${APP_NAME}.service"
@@ -0,0 +1 @@
../setup-user-service.sh
@@ -0,0 +1 @@
../debian/setup-user-service.sh
@@ -0,0 +1,48 @@
#!/bin/bash
set -e
readonly APP_NAME_SHORT=user-service
__get_setup_script_directory_by_os_release() {
pushd "$(dirname "${BASH_SOURCE[0]}")/../service.d/${APP_NAME_SHORT}" &>/dev/null
{
# shellcheck source=/dev/null
{
source /etc/os-release
{
pushd "${ID}"/"${VERSION_CODENAME}" &>/dev/null
} || {
pushd "${ID}" &>/dev/null
} || {
[[ -n ${ID_LIKE} ]] && for ID in ${ID_LIKE}; do
pushd "${ID}" >/dev/null && break
done
} || {
echo "Unsupported OS: ${ID} ${VERSION_CODENAME} (${ID_LIKE})"
exit 1
}
pwd
popd &>/dev/null
} || {
echo "Unsupported OS: unknown"
exit 1
}
}
popd &>/dev/null
}
SETUP_SCRIPT_DIRECTORY=$(__get_setup_script_directory_by_os_release)
readonly SETUP_SCRIPT_DIRECTORY
readonly SETUP_SCRIPT_FILENAME="cleanup-${APP_NAME_SHORT}.sh"
readonly SETUP_SCRIPT_FILEPATH="${SETUP_SCRIPT_DIRECTORY}/${SETUP_SCRIPT_FILENAME}"
echo "🟩 Running ${SETUP_SCRIPT_FILENAME}..."
$BASH "${SETUP_SCRIPT_FILEPATH}" "${BUILD_PATH}"
@@ -0,0 +1,109 @@
#!/bin/bash
set -e
readonly CASA_EXEC=casaos-user-service
readonly CASA_SERVICE=casaos-user-service.service
CASA_SERVICE_PATH=$(systemctl show ${CASA_SERVICE} --no-pager --property FragmentPath | cut -d'=' -sf2)
readonly CASA_SERVICE_PATH
CASA_CONF=$( grep -i ExecStart= "${CASA_SERVICE_PATH}" | cut -d'=' -sf2 | cut -d' ' -sf3)
if [[ -z "${CASA_CONF}" ]]; then
CASA_CONF=/etc/casaos/user-service.conf
fi
CASA_DB_PATH=$( (grep -i dbpath "${CASA_CONF}" || echo "/var/lib/casaos/db") | cut -d'=' -sf2 | xargs )
readonly CASA_DB_PATH
CASA_DB_FILE=${CASA_DB_PATH}/user-service.db
readonly aCOLOUR=(
'\e[38;5;154m' # green | Lines, bullets and separators
'\e[1m' # Bold white | Main descriptions
'\e[90m' # Grey | Credits
'\e[91m' # Red | Update notifications Alert
'\e[33m' # Yellow | Emphasis
)
Show() {
# OK
if (($1 == 0)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# FAILED
elif (($1 == 1)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# INFO
elif (($1 == 2)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# NOTICE
elif (($1 == 3)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
fi
}
Warn() {
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
}
trap 'onCtrlC' INT
onCtrlC() {
echo -e "${COLOUR_RESET}"
exit 1
}
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then
Show 2 "${CASA_EXEC} is not detected, exit the script."
exit 1
fi
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete user database? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_USER_DATABASE=true
break
;;
[nN][oO] | [nN])
REMOVE_USER_DATABASE=false
break
;;
*)
echo -e " ${aCOLOUR[3]}Invalid input, please try again.${COLOUR_RESET}"
;;
esac
done
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete user directory? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_USER_DIRECTORY=true
break
;;
[nN][oO] | [nN])
REMOVE_USER_DIRECTORY=false
break
;;
*)
echo -e " ${aCOLOUR[3]}Invalid input, please try again.${COLOUR_RESET}"
;;
esac
done
Show 2 "Stopping ${CASA_SERVICE}..."
systemctl disable --now "${CASA_SERVICE}" || Show 3 "Failed to disable ${CASA_SERVICE}"
rm -rvf "$(which ${CASA_EXEC})" || Show 3 "Failed to remove ${CASA_EXEC}"
rm -rvf "${CASA_CONF}" || Show 3 "Failed to remove ${CASA_CONF}"
if [[ "${REMOVE_USER_DATABASE}" == true ]]; then
rm -rvf "${CASA_DB_FILE}" || Show 3 "Failed to remove ${CASA_DB_FILE}"
fi
if [[ "${REMOVE_USER_DIRECTORY}" == true ]]; then
Show 2 "Removing user directories..."
rm -rvf /var/lib/casaos/[1-9]*
fi
@@ -0,0 +1 @@
../cleanup-user-service.sh
@@ -0,0 +1,109 @@
#!/bin/bash
set -e
readonly CASA_EXEC=casaos-user-service
readonly CASA_SERVICE=casaos-user-service.service
CASA_SERVICE_PATH=$(systemctl show ${CASA_SERVICE} --no-pager --property FragmentPath | cut -d'=' -sf2)
readonly CASA_SERVICE_PATH
CASA_CONF=$( grep -i ExecStart= "${CASA_SERVICE_PATH}" | cut -d'=' -sf2 | cut -d' ' -sf3)
if [[ -z "${CASA_CONF}" ]]; then
CASA_CONF=/etc/casaos/user-service.conf
fi
CASA_DB_PATH=$( (grep -i dbpath "${CASA_CONF}" || echo "/var/lib/casaos/db") | cut -d'=' -sf2 | xargs )
readonly CASA_DB_PATH
CASA_DB_FILE=${CASA_DB_PATH}/user-service.db
readonly aCOLOUR=(
'\e[38;5;154m' # green | Lines, bullets and separators
'\e[1m' # Bold white | Main descriptions
'\e[90m' # Grey | Credits
'\e[91m' # Red | Update notifications Alert
'\e[33m' # Yellow | Emphasis
)
Show() {
# OK
if (($1 == 0)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} OK $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# FAILED
elif (($1 == 1)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[3]}FAILED$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# INFO
elif (($1 == 2)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[0]} INFO $COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
# NOTICE
elif (($1 == 3)); then
echo -e "${aCOLOUR[2]}[$COLOUR_RESET${aCOLOUR[4]}NOTICE$COLOUR_RESET${aCOLOUR[2]}]$COLOUR_RESET $2"
fi
}
Warn() {
echo -e "${aCOLOUR[3]}$1$COLOUR_RESET"
}
trap 'onCtrlC' INT
onCtrlC() {
echo -e "${COLOUR_RESET}"
exit 1
}
if [[ ! -x "$(command -v ${CASA_EXEC})" ]]; then
Show 2 "${CASA_EXEC} is not detected, exit the script."
exit 1
fi
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete user database? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_USER_DATABASE=true
break
;;
[nN][oO] | [nN])
REMOVE_USER_DATABASE=false
break
;;
*)
echo -e " ${aCOLOUR[3]}Invalid input, please try again.${COLOUR_RESET}"
;;
esac
done
while true; do
echo -n -e " ${aCOLOUR[4]}Do you want delete user directory? Y/n :${COLOUR_RESET}"
read -r input
case $input in
[yY][eE][sS] | [yY])
REMOVE_USER_DIRECTORY=true
break
;;
[nN][oO] | [nN])
REMOVE_USER_DIRECTORY=false
break
;;
*)
echo -e " ${aCOLOUR[3]}Invalid input, please try again.${COLOUR_RESET}"
;;
esac
done
Show 2 "Stopping ${CASA_SERVICE}..."
systemctl disable --now "${CASA_SERVICE}" || Show 3 "Failed to disable ${CASA_SERVICE}"
rm -rvf "$(which ${CASA_EXEC})" || Show 3 "Failed to remove ${CASA_EXEC}"
rm -rvf "${CASA_CONF}" || Show 3 "Failed to remove ${CASA_CONF}"
if [[ "${REMOVE_USER_DATABASE}" == true ]]; then
rm -rvf "${CASA_DB_FILE}" || Show 3 "Failed to remove ${CASA_DB_FILE}"
fi
if [[ "${REMOVE_USER_DIRECTORY}" == true ]]; then
Show 2 "Removing user directories..."
rm -rvf /var/lib/casaos/[1-9]*
fi
@@ -0,0 +1 @@
../debian/cleanup-user-service.sh
@@ -0,0 +1 @@
../../debian/bullseye/cleanup-user-service.sh
+2 -1
View File
@@ -1,3 +1,4 @@
package common package common
const Version = "0.4.4" const Version = "1.3.0"
const SERVICENAME = "CasaOS-UserService"
+1 -1
View File
@@ -1 +1 @@
[{"name":"build/sysroot/usr/bin/casaos-user-service","path":"dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service","goos":"linux","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"casaos-user-service","Ext":"","ID":"casaos-user-service-amd64"}}] [{"name":"metadata.json","path":"dist/metadata.json","internal_type":30,"type":"Metadata"},{"name":"build/sysroot/usr/bin/casaos-user-service","path":"dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service","goos":"linux","goarch":"amd64","goamd64":"v1","internal_type":4,"type":"Binary","extra":{"Binary":"casaos-user-service","Ext":"","ID":"casaos-user-service-amd64"}}]
Binary file not shown.
+4 -1
View File
@@ -67,6 +67,7 @@ changelog:
- '^docs:' - '^docs:'
- '^test:' - '^test:'
sort: asc sort: asc
format: '{{ .SHA }}: {{ .Message }} ({{ with .AuthorUsername }}@{{ . }}{{ else }}{{ .AuthorName }} <{{ .AuthorEmail }}>{{ end }})'
dist: dist dist: dist
env_files: env_files:
github_token: ~/.config/goreleaser/github_token github_token: ~/.config/goreleaser/github_token
@@ -115,7 +116,7 @@ announce:
linkedin: linkedin:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}' message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
telegram: telegram:
message_template: '{{ .ProjectName }} {{ mdv2escape .Tag }} is out! Check it out at {{ mdv2escape .ReleaseURL }}' message_template: '{{ mdv2escape .ProjectName }} {{ mdv2escape .Tag }} is out{{ mdv2escape "!" }} Check it out at {{ mdv2escape .ReleaseURL }}'
parse_mode: MarkdownV2 parse_mode: MarkdownV2
webhook: webhook:
message_template: '{ "message": "{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}"}' message_template: '{ "message": "{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}"}'
@@ -123,6 +124,8 @@ announce:
opencollective: opencollective:
title_template: '{{ .Tag }}' title_template: '{{ .Tag }}'
message_template: '{{ .ProjectName }} {{ .Tag }} is out!<br/>Check it out at <a href="{{ .ReleaseURL }}">{{ .ReleaseURL }}</a>' message_template: '{{ .ProjectName }} {{ .Tag }} is out!<br/>Check it out at <a href="{{ .ReleaseURL }}">{{ .ReleaseURL }}</a>'
bluesky:
message_template: '{{ .ProjectName }} {{ .Tag }} is out! Check it out at {{ .ReleaseURL }}'
git: git:
tag_sort: -version:refname tag_sort: -version:refname
github_urls: github_urls:
+1 -1
View File
@@ -1 +1 @@
{"project_name":"casaos-user-service","tag":"v0.4.5","previous_tag":"v0.4.4-alpha7","version":"0.4.6","commit":"4d2b65e34c6d01800273009d60756205c08cb0c3","date":"2024-02-02T15:35:39.294862443+07:00","runtime":{"goos":"linux","goarch":"amd64"}} {"project_name":"casaos-user-service","tag":"v1.0.0","previous_tag":"","version":"1.0.1","commit":"11de9608cd1105075bc3ac12d2130eb30d3c8004","date":"2024-07-01T02:10:13.880324864+07:00","runtime":{"goos":"linux","goarch":"amd64"}}
+3 -3
View File
@@ -1,9 +1,9 @@
module github.com/KaySar12/NextZen-UserService module github.com/IceWhaleTech/CasaOS-UserService
go 1.20 go 1.20
require ( require (
github.com/KaySar12/NextZen-Common v1.0.1 github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha12
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
github.com/deepmap/oapi-codegen v1.12.4 github.com/deepmap/oapi-codegen v1.12.4
github.com/getkin/kin-openapi v0.117.0 github.com/getkin/kin-openapi v0.117.0
@@ -15,6 +15,7 @@ require (
github.com/tidwall/gjson v1.14.4 github.com/tidwall/gjson v1.14.4
go.uber.org/zap v1.24.0 go.uber.org/zap v1.24.0
golang.org/x/net v0.17.0 golang.org/x/net v0.17.0
golang.org/x/time v0.3.0
gopkg.in/ini.v1 v1.67.0 gopkg.in/ini.v1 v1.67.0
gorm.io/gorm v1.25.0 gorm.io/gorm v1.25.0
) )
@@ -75,7 +76,6 @@ require (
golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect
golang.org/x/sys v0.14.0 // indirect golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
+3 -2
View File
@@ -1,5 +1,5 @@
github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha3 h1:5E5LAqi2uXpOZqcPOgQ4m6d9MagYyfhKIFXnzd8s3W4= github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha12 h1:TikSpmsMOxKufqoq8Q4K3PLh8zIKFrRtLH4JDIG+910=
github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha3/go.mod h1:2IuYyy5qW1BE6jqC6M+tOU+WtUec1K565rLATBJ9p/0= github.com/IceWhaleTech/CasaOS-Common v0.4.8-alpha12/go.mod h1:2IuYyy5qW1BE6jqC6M+tOU+WtUec1K565rLATBJ9p/0=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk= github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ= github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk= github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
@@ -240,6 +240,7 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU= gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU=
gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
modernc.org/libc v1.22.4 h1:wymSbZb0AlrjdAVX3cjreCHTPCpPARbQXNz6BHPzdwQ= modernc.org/libc v1.22.4 h1:wymSbZb0AlrjdAVX3cjreCHTPCpPARbQXNz6BHPzdwQ=
modernc.org/libc v1.22.4/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY= modernc.org/libc v1.22.4/go.mod h1:jj+Z7dTNX8fBScMVNRAYZ/jF91K8fdT2hYMThc3YjBY=
modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ=
+19
View File
@@ -3,6 +3,7 @@
package main package main
import ( import (
"context"
_ "embed" _ "embed"
"flag" "flag"
"fmt" "fmt"
@@ -18,6 +19,7 @@ import (
util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http" util_http "github.com/IceWhaleTech/CasaOS-Common/utils/http"
"github.com/IceWhaleTech/CasaOS-Common/utils/jwt" "github.com/IceWhaleTech/CasaOS-Common/utils/jwt"
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" "github.com/IceWhaleTech/CasaOS-Common/utils/logger"
"github.com/IceWhaleTech/CasaOS-UserService/codegen/message_bus"
"github.com/IceWhaleTech/CasaOS-UserService/common" "github.com/IceWhaleTech/CasaOS-UserService/common"
"github.com/IceWhaleTech/CasaOS-UserService/pkg/config" "github.com/IceWhaleTech/CasaOS-UserService/pkg/config"
"github.com/IceWhaleTech/CasaOS-UserService/pkg/sqlite" "github.com/IceWhaleTech/CasaOS-UserService/pkg/sqlite"
@@ -154,6 +156,23 @@ func main() {
go route.EventListen() go route.EventListen()
logger.Info("User service is listening...", zap.Any("address", listener.Addr().String()), zap.String("filepath", addressFilePath)) logger.Info("User service is listening...", zap.Any("address", listener.Addr().String()), zap.String("filepath", addressFilePath))
var events []message_bus.EventType
events = append(events, message_bus.EventType{Name: "zimaos:user:save_config", SourceID: common.SERVICENAME, PropertyTypeList: []message_bus.PropertyType{}})
// register at message bus
for i := 0; i < 10; i++ {
response, err := service.MyService.MessageBus().RegisterEventTypesWithResponse(context.Background(), events)
if err != nil {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.Error(err))
}
if response != nil && response.StatusCode() != http.StatusOK {
logger.Error("error when trying to register one or more event types - some event type will not be discoverable", zap.String("status", response.Status()), zap.String("body", string(response.Body)))
}
if response.StatusCode() == http.StatusOK {
break
}
time.Sleep(time.Second)
}
s := &http.Server{ s := &http.Server{
Handler: mux, Handler: mux,
ReadHeaderTimeout: 5 * time.Second, // fix G112: Potential slowloris attack (see https://github.com/securego/gosec) ReadHeaderTimeout: 5 * time.Second, // fix G112: Potential slowloris attack (see https://github.com/securego/gosec)
+90 -20
View File
@@ -1,6 +1,7 @@
package v1 package v1
import ( import (
"context"
"crypto/ecdsa" "crypto/ecdsa"
"encoding/base64" "encoding/base64"
json2 "encoding/json" json2 "encoding/json"
@@ -13,13 +14,16 @@ import (
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"regexp"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"github.com/IceWhaleTech/CasaOS-Common/external"
"github.com/IceWhaleTech/CasaOS-Common/utils/common_err" "github.com/IceWhaleTech/CasaOS-Common/utils/common_err"
"github.com/IceWhaleTech/CasaOS-Common/utils/jwt" "github.com/IceWhaleTech/CasaOS-Common/utils/jwt"
"github.com/IceWhaleTech/CasaOS-Common/utils/logger" "github.com/IceWhaleTech/CasaOS-Common/utils/logger"
"github.com/IceWhaleTech/CasaOS-UserService/common"
"github.com/IceWhaleTech/CasaOS-UserService/model" "github.com/IceWhaleTech/CasaOS-UserService/model"
"github.com/IceWhaleTech/CasaOS-UserService/model/system_model" "github.com/IceWhaleTech/CasaOS-UserService/model/system_model"
"github.com/IceWhaleTech/CasaOS-UserService/pkg/config" "github.com/IceWhaleTech/CasaOS-UserService/pkg/config"
@@ -29,6 +33,7 @@ import (
uuid "github.com/satori/go.uuid" uuid "github.com/satori/go.uuid"
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"go.uber.org/zap" "go.uber.org/zap"
"golang.org/x/time/rate"
"github.com/IceWhaleTech/CasaOS-UserService/service" "github.com/IceWhaleTech/CasaOS-UserService/service"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
@@ -43,6 +48,7 @@ func PostUserRegister(c *gin.Context) {
username := json["username"] username := json["username"]
pwd := json["password"] pwd := json["password"]
key := json["key"] key := json["key"]
role := json["role"]
if _, ok := service.UserRegisterHash[key]; !ok { if _, ok := service.UserRegisterHash[key]; !ok {
c.JSON(common_err.CLIENT_ERROR, c.JSON(common_err.CLIENT_ERROR,
model.Result{Success: common_err.KEY_NOT_EXIST, Message: common_err.GetMsg(common_err.KEY_NOT_EXIST)}) model.Result{Success: common_err.KEY_NOT_EXIST, Message: common_err.GetMsg(common_err.KEY_NOT_EXIST)})
@@ -69,8 +75,8 @@ func PostUserRegister(c *gin.Context) {
user := model2.UserDBModel{} user := model2.UserDBModel{}
user.Username = username user.Username = username
user.Password = encryption.GetMD5ByStr(pwd) user.Password = encryption.GetMD5ByStr(pwd)
user.Role = "admin" user.Role = role
// user.Role = "user"
user = service.MyService.User().CreateUser(user) user = service.MyService.User().CreateUser(user)
if user.Id == 0 { if user.Id == 0 {
c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)}) c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
@@ -81,6 +87,8 @@ func PostUserRegister(c *gin.Context) {
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)}) c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS)})
} }
var limiter = rate.NewLimiter(rate.Every(time.Minute), 5)
// @Summary login // @Summary login
// @Produce application/json // @Produce application/json
// @Accept application/json // @Accept application/json
@@ -90,6 +98,15 @@ func PostUserRegister(c *gin.Context) {
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /user/login [post] // @Router /user/login [post]
func PostUserLogin(c *gin.Context) { func PostUserLogin(c *gin.Context) {
if !limiter.Allow() {
c.JSON(common_err.TOO_MANY_REQUEST,
model.Result{
Success: common_err.TOO_MANY_LOGIN_REQUESTS,
Message: common_err.GetMsg(common_err.TOO_MANY_LOGIN_REQUESTS),
})
return
}
json := make(map[string]string) json := make(map[string]string)
c.ShouldBind(&json) c.ShouldBind(&json)
@@ -108,15 +125,18 @@ func PostUserLogin(c *gin.Context) {
user := service.MyService.User().GetUserAllInfoByName(username) user := service.MyService.User().GetUserAllInfoByName(username)
if user.Id == 0 { if user.Id == 0 {
c.JSON(common_err.CLIENT_ERROR, c.JSON(common_err.CLIENT_ERROR,
model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)}) model.Result{Success: common_err.USER_NOT_EXIST_OR_PWD_INVALID, Message: common_err.GetMsg(common_err.USER_NOT_EXIST_OR_PWD_INVALID)})
return return
} }
if user.Password != encryption.GetMD5ByStr(password) { if user.Password != encryption.GetMD5ByStr(password) {
c.JSON(common_err.CLIENT_ERROR, c.JSON(common_err.CLIENT_ERROR,
model.Result{Success: common_err.PWD_INVALID, Message: common_err.GetMsg(common_err.PWD_INVALID)}) model.Result{Success: common_err.USER_NOT_EXIST_OR_PWD_INVALID, Message: common_err.GetMsg(common_err.USER_NOT_EXIST_OR_PWD_INVALID)})
return return
} }
// clean limit
limiter = rate.NewLimiter(rate.Every(time.Minute), 5)
privateKey, _ := service.MyService.User().GetKeyPair() privateKey, _ := service.MyService.User().GetKeyPair()
token := system_model.VerifyInformation{} token := system_model.VerifyInformation{}
@@ -255,7 +275,7 @@ func PutUserInfo(c *gin.Context) {
user := service.MyService.User().GetUserInfoById(id) user := service.MyService.User().GetUserInfoById(id)
if user.Id == 0 { if user.Id == 0 {
c.JSON(common_err.SERVICE_ERROR, c.JSON(common_err.SERVICE_ERROR,
model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)}) model.Result{Success: common_err.USER_NOT_EXIST_OR_PWD_INVALID, Message: common_err.GetMsg(common_err.USER_NOT_EXIST_OR_PWD_INVALID)})
return return
} }
if len(json.Username) > 0 { if len(json.Username) > 0 {
@@ -507,6 +527,20 @@ func PostUserCustomConf(c *gin.Context) {
return return
} }
if name == "system" {
dataMap := make(map[string]string, 1)
dataMap["system"] = string(data)
response, err := service.MyService.MessageBus().PublishEventWithResponse(context.Background(), common.SERVICENAME, "zimaos:user:save_config", dataMap)
if err != nil {
logger.Error("failed to publish event to message bus", zap.Error(err), zap.Any("event", string(data)))
return
}
if response.StatusCode() != http.StatusOK {
logger.Error("failed to publish event to message bus", zap.String("status", response.Status()), zap.Any("response", response))
}
}
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json2.RawMessage(string(data))}) c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json2.RawMessage(string(data))})
} }
@@ -658,23 +692,35 @@ func GetUserImage(c *gin.Context) {
c.JSON(http.StatusNotFound, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) c.JSON(http.StatusNotFound, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return return
} }
if !file.Exists(filePath) { absFilePath, err := filepath.Abs(filepath.Clean(filePath))
if err != nil {
c.JSON(http.StatusNotFound, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
if !file.Exists(absFilePath) {
c.JSON(http.StatusNotFound, model.Result{Success: common_err.FILE_DOES_NOT_EXIST, Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST)}) c.JSON(http.StatusNotFound, model.Result{Success: common_err.FILE_DOES_NOT_EXIST, Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST)})
return return
} }
if !strings.Contains(filePath, config.AppInfo.UserDataPath) { if !strings.Contains(absFilePath, config.AppInfo.UserDataPath) {
c.JSON(http.StatusNotFound, model.Result{Success: common_err.INSUFFICIENT_PERMISSIONS, Message: common_err.GetMsg(common_err.INSUFFICIENT_PERMISSIONS)}) c.JSON(http.StatusNotFound, model.Result{Success: common_err.INSUFFICIENT_PERMISSIONS, Message: common_err.GetMsg(common_err.INSUFFICIENT_PERMISSIONS)})
return return
} }
fileTmp, _ := os.Open(filePath) matched, err := regexp.MatchString(`^/var/lib/casaos/\d`, absFilePath)
defer fileTmp.Close() if err != nil {
c.JSON(http.StatusNotFound, model.Result{Success: common_err.INSUFFICIENT_PERMISSIONS, Message: common_err.GetMsg(common_err.INSUFFICIENT_PERMISSIONS)})
return
}
if !matched {
c.JSON(http.StatusNotFound, model.Result{Success: common_err.INSUFFICIENT_PERMISSIONS, Message: common_err.GetMsg(common_err.INSUFFICIENT_PERMISSIONS)})
return
}
fileName := path.Base(filePath) fileName := path.Base(absFilePath)
// @tiger - RESTful 规范下不应该返回文件本身内容,而是返回文件的静态URL,由前端去解析 // @tiger - RESTful 规范下不应该返回文件本身内容,而是返回文件的静态URL,由前端去解析
c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url2.PathEscape(fileName)) c.Header("Content-Disposition", "attachment; filename*=utf-8''"+url2.PathEscape(fileName))
c.File(filePath) c.File(absFilePath)
} }
func DeleteUserImage(c *gin.Context) { func DeleteUserImage(c *gin.Context) {
@@ -764,18 +810,42 @@ func DeleteUserAll(c *gin.Context) {
// @Security ApiKeyAuth // @Security ApiKeyAuth
// @Success 200 {string} string "ok" // @Success 200 {string} string "ok"
// @Router /sys/init/check [get] // @Router /sys/init/check [get]
// func GetUserStatus(c *gin.Context) {
// data := make(map[string]interface{}, 2)
// if service.MyService.User().GetUserCount() > 0 {
// data["initialized"] = true
// data["key"] = ""
// } else {
// key := uuid.NewV4().String()
// service.UserRegisterHash[key] = key
// data["key"] = key
// data["initialized"] = false
// }
// gpus, err := external.NvidiaGPUInfoList()
// if err != nil {
// logger.Error("NvidiaGPUInfoList error", zap.Error(err))
// }
// data["gpus"] = len(gpus)
// c.JSON(common_err.SUCCESS,
// model.Result{
// Success: common_err.SUCCESS,
// Message: common_err.GetMsg(common_err.SUCCESS),
// Data: data,
// })
// }
func GetUserStatus(c *gin.Context) { func GetUserStatus(c *gin.Context) {
data := make(map[string]interface{}, 2) data := make(map[string]interface{}, 2)
key := uuid.NewV4().String()
if service.MyService.User().GetUserCount() > 0 { service.UserRegisterHash[key] = key
data["initialized"] = true data["key"] = key
data["key"] = "" data["initialized"] = true
} else { gpus, err := external.NvidiaGPUInfoList()
key := uuid.NewV4().String() if err != nil {
service.UserRegisterHash[key] = key logger.Error("NvidiaGPUInfoList error", zap.Error(err))
data["key"] = key
data["initialized"] = false
} }
data["gpus"] = len(gpus)
c.JSON(common_err.SUCCESS, c.JSON(common_err.SUCCESS,
model.Result{ model.Result{
Success: common_err.SUCCESS, Success: common_err.SUCCESS,
+22
View File
@@ -2,6 +2,8 @@ package service
import ( import (
"github.com/IceWhaleTech/CasaOS-Common/external" "github.com/IceWhaleTech/CasaOS-Common/external"
"github.com/IceWhaleTech/CasaOS-UserService/codegen/message_bus"
"github.com/IceWhaleTech/CasaOS-UserService/pkg/config"
"gorm.io/gorm" "gorm.io/gorm"
) )
@@ -10,6 +12,7 @@ var MyService Repository
type Repository interface { type Repository interface {
Gateway() external.ManagementService Gateway() external.ManagementService
User() UserService User() UserService
MessageBus() *message_bus.ClientWithResponses
Event() EventService Event() EventService
} }
@@ -43,3 +46,22 @@ func (c *store) Gateway() external.ManagementService {
func (c *store) User() UserService { func (c *store) User() UserService {
return c.user return c.user
} }
func (c *store) MessageBus() *message_bus.ClientWithResponses {
client, _ := message_bus.NewClientWithResponses("", func(c *message_bus.Client) error {
// error will never be returned, as we always want to return a client, even with wrong address,
// in order to avoid panic.
//
// If we don't avoid panic, message bus becomes a hard dependency, which is not what we want.
messageBusAddress, err := external.GetMessageBusAddress(config.CommonInfo.RuntimePath)
if err != nil {
c.Server = "message bus address not found"
return nil
}
c.Server = messageBusAddress
return nil
})
return client
}