增加root_token查询
This commit is contained in:
11
README.md
11
README.md
@@ -30,10 +30,13 @@ or
|
||||
```
|
||||
wget https://github.com/mirrors2/opencatd-open/raw/main/docker/docker-compose.yml
|
||||
```
|
||||
## reset root token
|
||||
```
|
||||
docker exec -it opencatd-open ./opencatd reset_root
|
||||
```
|
||||
## 支持的命令
|
||||
>获取 root 的 token
|
||||
- `docker exec opencatd-open opencatd root_token`
|
||||
|
||||
>重置 root 的 token
|
||||
- `docker exec opencatd-open opencatd reset_root`
|
||||
|
||||
|
||||
## Q&A
|
||||
关于证书?
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
FROM golang:1.19.7-alpine as builder
|
||||
LABEL anther="github.com/Sakurasan"
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update && apk --no-cache add openssl make cmake upx
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk --no-cache add make cmake upx
|
||||
WORKDIR /build
|
||||
COPY . /build
|
||||
ENV GO111MODULE=on
|
||||
@@ -12,9 +12,10 @@ FROM alpine:latest AS runner
|
||||
# 设置alpine 时间为上海时间
|
||||
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && apk update && apk --no-cache add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
|
||||
&& echo "Asia/Shanghai" > /etc/timezone \
|
||||
&& apk del tzdata && export GIN_MODE=release
|
||||
# RUN apk update && apk --no-cache add openssl libgcc libstdc++ binutils
|
||||
WORKDIR /app
|
||||
COPY --from=builder /build/bin/opencatd /app/opencatd
|
||||
ENV GIN_MODE=release
|
||||
ENV PATH=$PATH:/app
|
||||
EXPOSE 80
|
||||
ENTRYPOINT ["/app/opencatd"]
|
||||
5
makefile
5
makefile
@@ -24,11 +24,12 @@ build:
|
||||
upx -9 bin/opencatd
|
||||
|
||||
.PHONY:docker
|
||||
# build docker images
|
||||
docker:
|
||||
docker run --privileged --rm tonistiigi/binfmt --install all
|
||||
docker buildx create --use --name xbuilder
|
||||
docker buildx create --use --name xbuilder --driver docker-container
|
||||
docker buildx inspect xbuilder --bootstrap
|
||||
docker buildx build --platform linux/amd64,linux/arm64 -t mirrors2/opencatd:latest . --push
|
||||
docker buildx build --platform linux/amd64,linux/arm64 -t mirrors2/opencatd:latest -f docker/Dockerfile . --push
|
||||
|
||||
.PHONY: clean
|
||||
# clean
|
||||
|
||||
39
opencat.go
39
opencat.go
@@ -9,19 +9,44 @@ import (
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
args := os.Args[1:]
|
||||
if len(args) > 0 && args[0] == "reset_root" {
|
||||
log.Println("reset root token...")
|
||||
ntoken := uuid.NewString()
|
||||
if err := store.UpdateUser(uint(1), ntoken); err != nil {
|
||||
log.Fatalln(err)
|
||||
if len(args) > 0 {
|
||||
switch args[0] {
|
||||
case "reset_root":
|
||||
log.Println("reset root token...")
|
||||
if _, err := store.GetUserByID(uint(1)); err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
log.Println("请在opencat(或其他APP)客户端完成team初始化")
|
||||
return
|
||||
} else {
|
||||
log.Fatalln(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
ntoken := uuid.NewString()
|
||||
if err := store.UpdateUser(uint(1), ntoken); err != nil {
|
||||
log.Fatalln(err)
|
||||
return
|
||||
}
|
||||
log.Println("new root token:", ntoken)
|
||||
return
|
||||
case "root_token":
|
||||
log.Println("reset root token...")
|
||||
if user, err := store.GetUserByID(uint(1)); err != nil {
|
||||
log.Fatalln(err)
|
||||
return
|
||||
} else {
|
||||
log.Println("root token:", user.Token)
|
||||
return
|
||||
}
|
||||
default:
|
||||
return
|
||||
}
|
||||
log.Println("new root token:", ntoken)
|
||||
return
|
||||
|
||||
}
|
||||
port := os.Getenv("PORT")
|
||||
r := gin.Default()
|
||||
|
||||
Reference in New Issue
Block a user