mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-10-06 19:59:42 +07:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 72c7014e03 | |||
| 9d36ce5c78 | |||
| 941c4765f8 | |||
| b2ddd6f395 | |||
| 79a4456a73 | |||
| ee03f5401b | |||
| e4d7296154 | |||
| cb86b0862a | |||
| 86d42e7363 | |||
| 1567f7d9d7 | |||
| 50ff1c7fc3 | |||
| e265ce3f9c | |||
| 3750dfee56 | |||
| 44e51057d8 | |||
| 939f966173 | |||
| ec9cc6c24e | |||
| 946e3dba59 |
+2
-1
@@ -41,6 +41,7 @@ linux-amd64-nextzenos-user-service-v1.2.4.tar.gz
|
|||||||
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
|
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
|
||||||
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
|
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
|
||||||
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
|
dist/casaos-user-service-amd64_linux_amd64_v1/build/sysroot/usr/bin/casaos-user-service
|
||||||
|
.env
|
||||||
.vscode/launch.json
|
.vscode/launch.json
|
||||||
dist/metadata.json
|
dist/metadata.json
|
||||||
|
*.gz
|
||||||
|
|||||||
Vendored
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
"type": "go",
|
"type": "go",
|
||||||
"debugAdapter": "dlv-dap",
|
"debugAdapter": "dlv-dap",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"port": 34933,
|
"port": 2345,
|
||||||
"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"
|
||||||
|
|||||||
@@ -12,14 +12,18 @@ CUR_DIR=$(PWD)
|
|||||||
CUR_TAG ?= $(shell git describe --tags --match '*.*.*' | sort -V | tail -n1 | sed 's/-[0-9]*-g[0-9a-f]*//')
|
CUR_TAG ?= $(shell git describe --tags --match '*.*.*' | sort -V | tail -n1 | sed 's/-[0-9]*-g[0-9a-f]*//')
|
||||||
PREV_TAG ?= $(shell git describe --tags --match '*.*.*' | sort -V | head -n2 | tail -n1 | sed 's/-[0-9]*-g[0-9a-f]*//')
|
PREV_TAG ?= $(shell git describe --tags --match '*.*.*' | sort -V | head -n2 | tail -n1 | sed 's/-[0-9]*-g[0-9a-f]*//')
|
||||||
ARCHIVE_PATH=buildzip
|
ARCHIVE_PATH=buildzip
|
||||||
PACKAGE_NAME=$(OS)-$(ARCHITECHTURE)-nextzenos-user-service-$(TAG)
|
ifeq ($(TAG),)
|
||||||
|
PACKAGE_NAME := $(OS)-$(ARCHITECHTURE)-nextzenos-user-service
|
||||||
|
else
|
||||||
|
PACKAGE_NAME := $(OS)-$(ARCHITECHTURE)-nextzenos-user-service-$(TAG)
|
||||||
|
endif
|
||||||
COMMIT_MESSAGE ?="update"
|
COMMIT_MESSAGE ?="update"
|
||||||
build_service:
|
build_service:
|
||||||
$(GORELEASERBUILD) --clean --snapshot -f .goreleaser.debug.yaml --id $(SERVICE)-$(ARCHITECHTURE)
|
$(GORELEASERBUILD) --clean --snapshot -f .goreleaser.debug.yaml --id $(SERVICE)-$(ARCHITECHTURE)
|
||||||
|
|
||||||
package:
|
package:
|
||||||
cp -f $(CUR_DIR)/dist/$(SERVICE)-$(ARCHITECHTURE)_$(OS)_$(ARCHITECHTURE)_$(VERSION)/$(BIN_PATH)/$(SERVICE) $(CUR_DIR)/$(BIN_PATH) \
|
cp $(CUR_DIR)/dist/$(SERVICE)-$(ARCHITECHTURE)_$(OS)_$(ARCHITECHTURE)_$(VERSION)/$(BIN_PATH)/$(SERVICE) $(CUR_DIR)/$(BIN_PATH) \
|
||||||
&& tar -czvf $(PACKAGE_NAME).tar.gz $(CUR_DIR)/$(BUILD_PATH)
|
&& tar -czvf $(PACKAGE_NAME).tar.gz $(BUILD_PATH)
|
||||||
|
|
||||||
archive_package:
|
archive_package:
|
||||||
@mkdir -p $(CUR_DIR)/$(ARCHIVE_PATH)/$(CUR_TAG)
|
@mkdir -p $(CUR_DIR)/$(ARCHIVE_PATH)/$(CUR_TAG)
|
||||||
@@ -37,7 +41,6 @@ remove_tag:
|
|||||||
@${GIT} tag -d ${CUR_TAG}
|
@${GIT} tag -d ${CUR_TAG}
|
||||||
@${GIT} push ${GIT_REMOTE} -d ${CUR_TAG}
|
@${GIT} push ${GIT_REMOTE} -d ${CUR_TAG}
|
||||||
check_tag:
|
check_tag:
|
||||||
@echo "Previous tag: $(PREV_TAG)";
|
|
||||||
@echo "Current tag: $(CUR_TAG)";
|
@echo "Current tag: $(CUR_TAG)";
|
||||||
push_release_all:
|
push_release_all:
|
||||||
${GORELEASER} release --clean -f .goreleaser.yaml
|
${GORELEASER} release --clean -f .goreleaser.yaml
|
||||||
|
|||||||
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
Regular → Executable
+21
-3
@@ -7,6 +7,24 @@ LogSaveName = user-service
|
|||||||
LogFileExt = log
|
LogFileExt = log
|
||||||
DBPath = /var/lib/casaos/db
|
DBPath = /var/lib/casaos/db
|
||||||
UserDataPath = /var/lib/casaos
|
UserDataPath = /var/lib/casaos
|
||||||
OMVServer = http://10.0.0.4:1081/rpc.php
|
|
||||||
SecretKey = N1PCdw3M2B1TfJhoaY2mL736p2vCUc47
|
[oidc]
|
||||||
AuthentikServer = http://10.0.0.26:9000
|
AuthServer = https://account.nextzenvn.com
|
||||||
|
ClientID = WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz
|
||||||
|
ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fPi6B9IFe3aDBo8x
|
||||||
|
AuthURL = https://account.nextzenvn.com/application/o/nextzenos/
|
||||||
|
CallbackURL = https://home.nextzenvn.com/v1/users/oidc/callback
|
||||||
|
|
||||||
|
[nextweb]
|
||||||
|
Server = http://127.0.0.1:10086
|
||||||
|
UserName = nextzen
|
||||||
|
Password = Smartyourlife123@*
|
||||||
|
EntranceCode =
|
||||||
|
|
||||||
|
[default-app]
|
||||||
|
NextFireWall = NextFirewall-https://firewall.nextzenvn.com-https://cdn.nextzenos.com/CDN/Images/raw/commit/ded8610b855ac31cb08514460e78b93fff9ea127/NextFirewall/nextfirewall.png-DefaultApp-running
|
||||||
|
NextWeb = NextWeb-https://web.nextzenvn.com-https://cdn.nextzenos.com/CDN/Images/raw/commit/c68656087a0387281a1345ff78c89eb36cb925a4/NextWeb/nextweb.png-DefaultApp-running
|
||||||
|
AccountCenter = AccountCenter-https://account.nextzenvn.com-https://cdn.nextzenos.com/CDN/Images/raw/commit/f8c809f8ade653db6cec0915d1e7fadfcdb15241/AccountManager/account.png-DefaultApp-running
|
||||||
|
NextVPN = NextVPN-https://vpn.nextzenvn.com-https://cdn.nextzenos.com/CDN/Images/raw/commit/f5507a5bfa811eae29b67b1f1fc5ac5d8fc5c3e8/NextVPN/nextvpn.png-DefaultApp-running
|
||||||
|
NextNAS = NextNAS-https://nas.nextzenvn.com-https://cdn.nextzenos.com/CDN/Images/raw/commit/0693ac3497cb5c46b7e797ec7afb511fdb5d8804/NextNAS/nextnas.jpg-DefaultApp-running
|
||||||
|
NextDNS = NextDNS-https://dns.nextzenvn.com-https://cdn.nextzenos.com/CDN/Images/raw/commit/874a16e2647e8633f60845dd2d770bbd4aaccfd4/NextDNS/nextdns.png-DefaultApp-running
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
After=casaos-message-bus.service
|
||||||
|
ConditionFileNotEmpty=/etc/casaos/user-service.conf
|
||||||
|
Description=CasaOS User Service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStartPre=/usr/bin/casaos-user-service -v
|
||||||
|
ExecStart=/usr/bin/casaos-user-service -c /etc/casaos/user-service.conf
|
||||||
|
PIDFile=/var/run/casaos/user-service.pid
|
||||||
|
Restart=always
|
||||||
|
Type=notify
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
[Unit]
|
||||||
|
After=casaos-message-bus.service
|
||||||
|
Description=CasaOS User Service
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
ExecStartPre=/usr/bin/casaos-user-service -v
|
||||||
|
ExecStart=/usr/bin/casaos-user-service -c /etc/casaos/user-service.conf
|
||||||
|
PIDFile=/var/run/casaos/user-service.pid
|
||||||
|
Restart=always
|
||||||
|
Type=notify
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
Regular → Executable
Regular → Executable
@@ -2,8 +2,6 @@ module github.com/KaySar12/NextZen-UserService
|
|||||||
|
|
||||||
go 1.21
|
go 1.21
|
||||||
|
|
||||||
toolchain go1.22.0
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/KaySar12/NextZen-Common v1.0.0-alpha6
|
github.com/KaySar12/NextZen-Common v1.0.0-alpha6
|
||||||
github.com/coreos/go-oidc/v3 v3.11.0
|
github.com/coreos/go-oidc/v3 v3.11.0
|
||||||
@@ -11,6 +9,7 @@ require (
|
|||||||
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
|
||||||
github.com/gin-contrib/gzip v0.0.6
|
github.com/gin-contrib/gzip v0.0.6
|
||||||
|
github.com/gin-contrib/sessions v1.0.1
|
||||||
github.com/gin-gonic/gin v1.10.0
|
github.com/gin-gonic/gin v1.10.0
|
||||||
github.com/glebarez/sqlite v1.8.0
|
github.com/glebarez/sqlite v1.8.0
|
||||||
github.com/labstack/echo/v4 v4.12.0
|
github.com/labstack/echo/v4 v4.12.0
|
||||||
@@ -48,7 +47,10 @@ require (
|
|||||||
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
|
||||||
github.com/google/go-cmp v0.6.0 // indirect
|
github.com/google/go-cmp v0.6.0 // indirect
|
||||||
github.com/google/uuid v1.3.0 // indirect
|
github.com/google/uuid v1.3.0 // indirect
|
||||||
|
github.com/gorilla/context v1.1.2 // indirect
|
||||||
github.com/gorilla/mux v1.8.0 // indirect
|
github.com/gorilla/mux v1.8.0 // indirect
|
||||||
|
github.com/gorilla/securecookie v1.1.2 // indirect
|
||||||
|
github.com/gorilla/sessions v1.2.2 // indirect
|
||||||
github.com/invopop/yaml v0.2.0 // indirect
|
github.com/invopop/yaml v0.2.0 // indirect
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
github.com/jinzhu/now v1.1.5 // indirect
|
github.com/jinzhu/now v1.1.5 // indirect
|
||||||
|
|||||||
@@ -34,6 +34,8 @@ github.com/getkin/kin-openapi v0.117.0 h1:QT2DyGujAL09F4NrKDHJGsUoIprlIcFVHWDVDc
|
|||||||
github.com/getkin/kin-openapi v0.117.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc=
|
github.com/getkin/kin-openapi v0.117.0/go.mod h1:l5e9PaFUo9fyLJCPGQeXI2ML8c3P8BHOEV2VaAVf/pc=
|
||||||
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
|
||||||
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
|
||||||
|
github.com/gin-contrib/sessions v1.0.1 h1:3hsJyNs7v7N8OtelFmYXFrulAf6zSR7nW/putcPEHxI=
|
||||||
|
github.com/gin-contrib/sessions v1.0.1/go.mod h1:ouxSFM24/OgIud5MJYQJLpy6AwxQ5EYO9yLhbtObGkM=
|
||||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||||
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
|
github.com/gin-gonic/gin v1.8.1/go.mod h1:ji8BvRH1azfM+SYow9zQ6SZMvR8qOMZHmsCuWR9tTTk=
|
||||||
@@ -80,12 +82,20 @@ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
|||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
|
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26 h1:Xim43kblpZXfIBQsbuBVKCudVG457BR2GZFIz3uw3hQ=
|
||||||
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
github.com/google/pprof v0.0.0-20221118152302-e6195bd50e26/go.mod h1:dDKJzRmX4S37WGHujM7tX//fmj1uioxKzKxz3lo4HJo=
|
||||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
|
github.com/gorilla/context v1.1.2 h1:WRkNAv2uoa03QNIc1A6u4O7DAGMUVoopZhkiXWA2V1o=
|
||||||
|
github.com/gorilla/context v1.1.2/go.mod h1:KDPwT9i/MeWHiLl90fuTgrt4/wPcv75vFAZLaOOcbxM=
|
||||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
|
github.com/gorilla/securecookie v1.1.2 h1:YCIWL56dvtr73r6715mJs5ZvhtnY73hBvEF8kXD8ePA=
|
||||||
|
github.com/gorilla/securecookie v1.1.2/go.mod h1:NfCASbcHqRSY+3a8tlWJwsQap2VX5pwzwo4h3eOamfo=
|
||||||
|
github.com/gorilla/sessions v1.2.2 h1:lqzMYz6bOfvn2WriPUjNByzeXIlVzURcPmgMczkmTjY=
|
||||||
|
github.com/gorilla/sessions v1.2.2/go.mod h1:ePLdVu+jbEgHH+KWw8I1z2wqd0BAdAQh/8LRvBeoNcQ=
|
||||||
github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
github.com/invopop/yaml v0.1.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
||||||
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
|
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
|
||||||
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
_ "embed"
|
_ "embed"
|
||||||
|
"encoding/json"
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
@@ -21,9 +22,11 @@ import (
|
|||||||
"github.com/KaySar12/NextZen-Common/utils/logger"
|
"github.com/KaySar12/NextZen-Common/utils/logger"
|
||||||
"github.com/KaySar12/NextZen-UserService/codegen/message_bus"
|
"github.com/KaySar12/NextZen-UserService/codegen/message_bus"
|
||||||
"github.com/KaySar12/NextZen-UserService/common"
|
"github.com/KaySar12/NextZen-UserService/common"
|
||||||
|
model2 "github.com/KaySar12/NextZen-UserService/model"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/sqlite"
|
"github.com/KaySar12/NextZen-UserService/pkg/sqlite"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/utils/encryption"
|
"github.com/KaySar12/NextZen-UserService/pkg/utils/encryption"
|
||||||
|
"github.com/KaySar12/NextZen-UserService/pkg/utils/file"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/utils/random"
|
"github.com/KaySar12/NextZen-UserService/pkg/utils/random"
|
||||||
"github.com/KaySar12/NextZen-UserService/route"
|
"github.com/KaySar12/NextZen-UserService/route"
|
||||||
"github.com/KaySar12/NextZen-UserService/service"
|
"github.com/KaySar12/NextZen-UserService/service"
|
||||||
@@ -122,13 +125,27 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
// create default app path
|
||||||
|
defaultDir := config.AppInfo.UserDataPath + "/" + "default"
|
||||||
|
if err := file.IsNotExistMkDir(defaultDir); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
appData := convertMapToSlice(config.DefaultAppInfo.Apps)
|
||||||
|
initApp, err := json.Marshal(appData)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := file.WriteToPath(initApp, defaultDir, "link.json"); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
apiPaths := []string{
|
apiPaths := []string{
|
||||||
"/v1/users",
|
"/v1/users",
|
||||||
|
"/v1/1panel",
|
||||||
route.V2APIPath,
|
route.V2APIPath,
|
||||||
route.V2DocPath,
|
route.V2DocPath,
|
||||||
"/" + jwt.JWKSPath,
|
"/" + jwt.JWKSPath,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, v := range apiPaths {
|
for _, v := range apiPaths {
|
||||||
err = service.MyService.Gateway().CreateRoute(&model.Route{
|
err = service.MyService.Gateway().CreateRoute(&model.Route{
|
||||||
Path: v,
|
Path: v,
|
||||||
@@ -183,7 +200,15 @@ func main() {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func convertMapToSlice(appsMap map[string]model2.AppInfo) []model2.AppInfo {
|
||||||
|
appsSlice := make([]model2.AppInfo, 0, len(appsMap))
|
||||||
|
|
||||||
|
for _, app := range appsMap {
|
||||||
|
appsSlice = append(appsSlice, app)
|
||||||
|
}
|
||||||
|
|
||||||
|
return appsSlice
|
||||||
|
}
|
||||||
func writeAddressFile(runtimePath string, filename string, address string) (string, error) {
|
func writeAddressFile(runtimePath string, filename string, address string) (string, error) {
|
||||||
err := os.MkdirAll(runtimePath, 0o755)
|
err := os.MkdirAll(runtimePath, 0o755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+26
-3
@@ -10,11 +10,34 @@ type APPModel struct {
|
|||||||
LogFileExt string
|
LogFileExt string
|
||||||
UserDataPath string
|
UserDataPath string
|
||||||
DBPath string
|
DBPath string
|
||||||
OMVServer string
|
|
||||||
AuthentikServer string
|
|
||||||
SecretKey string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type OIDCModel struct {
|
||||||
|
AuthServer string
|
||||||
|
ClientID string
|
||||||
|
ClientSecret string
|
||||||
|
AuthURL string
|
||||||
|
CallbackURL string
|
||||||
|
}
|
||||||
|
|
||||||
|
type NextWebModel struct {
|
||||||
|
Server string
|
||||||
|
UserName string
|
||||||
|
Password string
|
||||||
|
EntranceCode string
|
||||||
|
}
|
||||||
|
|
||||||
|
type DefaultModel struct {
|
||||||
|
Apps map[string]AppInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInfo struct {
|
||||||
|
Hostname string `json:"hostname,omitempty"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Icon string `json:"icon,omitempty"`
|
||||||
|
AppType string `json:"app_type,omitempty"`
|
||||||
|
Status string `json:"status,omitempty"`
|
||||||
|
}
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Success int `json:"success" example:"200"`
|
Success int `json:"success" example:"200"`
|
||||||
Message string `json:"message" example:"ok"`
|
Message string `json:"message" example:"ok"`
|
||||||
|
|||||||
+44
-1
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/KaySar12/NextZen-Common/utils/constants"
|
"github.com/KaySar12/NextZen-Common/utils/constants"
|
||||||
"github.com/KaySar12/NextZen-UserService/model"
|
"github.com/KaySar12/NextZen-UserService/model"
|
||||||
@@ -24,7 +25,22 @@ var (
|
|||||||
LogSaveName: "user",
|
LogSaveName: "user",
|
||||||
LogFileExt: "log",
|
LogFileExt: "log",
|
||||||
}
|
}
|
||||||
|
OIDCInfo = &model.OIDCModel{
|
||||||
|
AuthServer: "",
|
||||||
|
ClientID: "",
|
||||||
|
ClientSecret: "",
|
||||||
|
AuthURL: "",
|
||||||
|
CallbackURL: "",
|
||||||
|
}
|
||||||
|
NextWebInfo = &model.NextWebModel{
|
||||||
|
Server: "",
|
||||||
|
UserName: "",
|
||||||
|
Password: "",
|
||||||
|
EntranceCode: "",
|
||||||
|
}
|
||||||
|
DefaultAppInfo = &model.DefaultModel{
|
||||||
|
Apps: map[string]model.AppInfo{},
|
||||||
|
}
|
||||||
Cfg *ini.File
|
Cfg *ini.File
|
||||||
ConfigFilePath string
|
ConfigFilePath string
|
||||||
)
|
)
|
||||||
@@ -60,10 +76,37 @@ func InitSetup(config string, sample string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mapTo("oidc", OIDCInfo)
|
||||||
|
mapTo("nextweb", NextWebInfo)
|
||||||
mapTo("common", CommonInfo)
|
mapTo("common", CommonInfo)
|
||||||
mapTo("app", AppInfo)
|
mapTo("app", AppInfo)
|
||||||
|
mapToDefaultApp("default-app", DefaultAppInfo)
|
||||||
|
fmt.Println(DefaultAppInfo)
|
||||||
}
|
}
|
||||||
|
func mapToDefaultApp(section string, v interface{}) {
|
||||||
|
sectionData := Cfg.Section(section)
|
||||||
|
dm, ok := v.(*model.DefaultModel)
|
||||||
|
if !ok {
|
||||||
|
log.Fatal("Invalid type passed to mapToDefaultApp")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Iterate through all keys in the section
|
||||||
|
for key, value := range sectionData.KeysHash() {
|
||||||
|
// Split the value string into components (Name, URL, Icon)
|
||||||
|
parts := strings.Split(value, "-")
|
||||||
|
if len(parts) == 5 {
|
||||||
|
dm.Apps[key] = model.AppInfo{
|
||||||
|
Name: parts[0],
|
||||||
|
Hostname: parts[1],
|
||||||
|
Icon: parts[2],
|
||||||
|
AppType: parts[3],
|
||||||
|
Status: parts[4],
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.Printf("Invalid app info format for key: %s, value: %s", key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
func SaveSetup(config string) {
|
func SaveSetup(config string) {
|
||||||
reflectFrom("common", CommonInfo)
|
reflectFrom("common", CommonInfo)
|
||||||
reflectFrom("app", AppInfo)
|
reflectFrom("app", AppInfo)
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
||||||
|
"gopkg.in/ini.v1"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
Cfg *ini.File
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
var err error
|
||||||
|
Cfg, err = ini.Load(config.UserServiceConfigFilePath)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func WriteMapToConfig(configData map[string]string, section string) {
|
||||||
|
sectionData := Cfg.Section(section)
|
||||||
|
for key, value := range sectionData.KeysHash() {
|
||||||
|
if value != configData[key] {
|
||||||
|
sectionData.Key(key).SetValue(configData[key])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
err := Cfg.SaveTo(config.UserServiceConfigFilePath)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Failed to save file:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -15,15 +15,14 @@ import (
|
|||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// We're using a 32 byte long secret key.
|
// We're using a 32 byte long secret key.
|
||||||
// This is probably something you generate first
|
// This is probably something you generate first
|
||||||
// then put into and environment variable.
|
// then put into and environment variable.
|
||||||
secretKey string = config.AppInfo.SecretKey
|
// secretKey string = config.AppInfo.SecretKey
|
||||||
|
secretKey string = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetMD5ByStr(str string) string {
|
func GetMD5ByStr(str string) string {
|
||||||
|
|||||||
+24
-3
@@ -9,6 +9,8 @@ import (
|
|||||||
v1 "github.com/KaySar12/NextZen-UserService/route/v1"
|
v1 "github.com/KaySar12/NextZen-UserService/route/v1"
|
||||||
"github.com/KaySar12/NextZen-UserService/service"
|
"github.com/KaySar12/NextZen-UserService/service"
|
||||||
"github.com/gin-contrib/gzip"
|
"github.com/gin-contrib/gzip"
|
||||||
|
"github.com/gin-contrib/sessions"
|
||||||
|
"github.com/gin-contrib/sessions/cookie"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -18,12 +20,16 @@ func InitRouter() *gin.Engine {
|
|||||||
r.Use(v1.CheckOIDCInit())
|
r.Use(v1.CheckOIDCInit())
|
||||||
r.Use(gzip.Gzip(gzip.DefaultCompression))
|
r.Use(gzip.Gzip(gzip.DefaultCompression))
|
||||||
|
|
||||||
|
store := cookie.NewStore([]byte("secret"))
|
||||||
|
sessionMiddleware := sessions.Sessions("1Panel", store)
|
||||||
|
r.Use(sessionMiddleware)
|
||||||
// check if environment variable is set
|
// check if environment variable is set
|
||||||
if ginMode, success := os.LookupEnv("GIN_MODE"); success {
|
if ginMode, success := os.LookupEnv("GIN_MODE"); success {
|
||||||
gin.SetMode(ginMode)
|
gin.SetMode(ginMode)
|
||||||
} else {
|
} else {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.ReleaseMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
go v1.InitOIDC()
|
go v1.InitOIDC()
|
||||||
r.POST("/v1/users/register", v1.PostUserRegister)
|
r.POST("/v1/users/register", v1.PostUserRegister)
|
||||||
r.POST("/v1/users/login", v1.PostUserLogin)
|
r.POST("/v1/users/login", v1.PostUserLogin)
|
||||||
@@ -33,7 +39,7 @@ func InitRouter() *gin.Engine {
|
|||||||
r.POST("/v1/users/refresh", v1.PostUserRefreshToken)
|
r.POST("/v1/users/refresh", v1.PostUserRefreshToken)
|
||||||
r.GET("/v1/users/image", v1.GetUserImage)
|
r.GET("/v1/users/image", v1.GetUserImage)
|
||||||
r.GET("/v1/users/:username", v1.GetUserInfoByUsername)
|
r.GET("/v1/users/:username", v1.GetUserInfoByUsername)
|
||||||
r.GET("/v1/users/status", v1.GetUserStatus) // init/check
|
r.GET("/v1/users/status", v1.InitializedUser) //init
|
||||||
r.POST("/v1/users/oidc/login", v1.OIDCLogin)
|
r.POST("/v1/users/oidc/login", v1.OIDCLogin)
|
||||||
r.GET("/v1/users/oidc/callback", v1.OIDCCallback)
|
r.GET("/v1/users/oidc/callback", v1.OIDCCallback)
|
||||||
r.GET("/v1/users/oidc/profile", v1.OIDCProfile)
|
r.GET("/v1/users/oidc/profile", v1.OIDCProfile)
|
||||||
@@ -43,8 +49,14 @@ func InitRouter() *gin.Engine {
|
|||||||
r.GET("/v1/users/oidc/health", v1.OIDCHealthCheck)
|
r.GET("/v1/users/oidc/health", v1.OIDCHealthCheck)
|
||||||
r.GET("/v1/users/oidc/settings", v1.GetOIDCSettings)
|
r.GET("/v1/users/oidc/settings", v1.GetOIDCSettings)
|
||||||
r.POST("/v1/users/oidc/saveSettings", v1.SaveOIDCSettings)
|
r.POST("/v1/users/oidc/saveSettings", v1.SaveOIDCSettings)
|
||||||
r.GET("/v1/users/1panel/health", v1.OnePanelHealthCheck)
|
r.GET("/v1/1panel/health", v1.OnePanelHealthCheck)
|
||||||
r.POST("/v1/users/1panel/login", v1.OnePanelLogin)
|
// r.POST("/v1/1panel/login", v1.OnePanelLogin)
|
||||||
|
// r.POST("/v1/1panel/app/search", v1.ExternalAPIMiddleware, v1.OnePanelLogin)
|
||||||
|
// r.POST("/v1/1panel/website/search", v1.ExternalAPIMiddleware, v1.OnePanelLogin)
|
||||||
|
r.POST("/v1/1panel/website/create", v1.ExternalAPIMiddleware, v1.OnePanelCreateWebsite)
|
||||||
|
r.POST("/v1/1panel/website/delete", v1.ExternalAPIMiddleware, v1.OnePanelDeleteWebsite)
|
||||||
|
r.POST("/v1/1panel/website/update-proxy", v1.ExternalAPIMiddleware, v1.OnePanelUpdateProxyWebsite)
|
||||||
|
r.POST("/v1/1panel/website/update", v1.ExternalAPIMiddleware, v1.OnePanelUpdateWebsite)
|
||||||
v1Group := r.Group("/v1")
|
v1Group := r.Group("/v1")
|
||||||
|
|
||||||
v1Group.Use(jwt.JWT(
|
v1Group.Use(jwt.JWT(
|
||||||
@@ -54,6 +66,15 @@ func InitRouter() *gin.Engine {
|
|||||||
},
|
},
|
||||||
))
|
))
|
||||||
{
|
{
|
||||||
|
// v1OnePanel := v1Group.Group("/1panel")
|
||||||
|
// v1OnePanel.Use()
|
||||||
|
// {
|
||||||
|
// r.GET("/health", v1.OnePanelHealthCheck)
|
||||||
|
// r.POST("/login", v1.OnePanelLogin)
|
||||||
|
// r.POST("/app/search", v1.ExternalAPIMiddleware, v1.OnePanelLogin)
|
||||||
|
// r.POST("/website/search", v1.ExternalAPIMiddleware, v1.OnePanelLogin)
|
||||||
|
// r.POST("/website/create", v1.ExternalAPIMiddleware, v1.OnePanelCreateWebsite)
|
||||||
|
// }
|
||||||
v1UsersGroup := v1Group.Group("/users")
|
v1UsersGroup := v1Group.Group("/users")
|
||||||
v1UsersGroup.Use()
|
v1UsersGroup.Use()
|
||||||
{
|
{
|
||||||
|
|||||||
+765
-54
@@ -7,13 +7,13 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
json2 "encoding/json"
|
json2 "encoding/json"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
|
||||||
url2 "net/url"
|
url2 "net/url"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@@ -31,11 +31,13 @@ import (
|
|||||||
"github.com/KaySar12/NextZen-UserService/model"
|
"github.com/KaySar12/NextZen-UserService/model"
|
||||||
"github.com/KaySar12/NextZen-UserService/model/system_model"
|
"github.com/KaySar12/NextZen-UserService/model/system_model"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
||||||
|
cfg "github.com/KaySar12/NextZen-UserService/pkg/utils/config"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/utils/encryption"
|
"github.com/KaySar12/NextZen-UserService/pkg/utils/encryption"
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/utils/file"
|
"github.com/KaySar12/NextZen-UserService/pkg/utils/file"
|
||||||
"github.com/KaySar12/NextZen-UserService/service"
|
"github.com/KaySar12/NextZen-UserService/service"
|
||||||
model2 "github.com/KaySar12/NextZen-UserService/service/model"
|
model2 "github.com/KaySar12/NextZen-UserService/service/model"
|
||||||
"github.com/coreos/go-oidc/v3/oidc"
|
"github.com/coreos/go-oidc/v3/oidc"
|
||||||
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
uuid "github.com/satori/go.uuid"
|
uuid "github.com/satori/go.uuid"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
@@ -45,17 +47,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
//authServer = "http://10.0.0.26:9000"
|
authServer string
|
||||||
authServer = "http://accessmanager.local"
|
clientID string
|
||||||
clientID = "6KwKSxLCtaQ4r6HoAn3gdNMbNOAf75j3SejLIAx7"
|
clientSecret string
|
||||||
clientSecret = "PE05fcDP4qESUmyZ1TNYpZNBxRPq70VpFI81vehsoJ6WhGz5yPXMljrFrOdMRdRhrYmF03fHWTZHgO9ZdNENrLN13BzL8CAgtEkTsyjXfgx9GvISheIjYfpSfvo219fL"
|
authURL string
|
||||||
authURL = "http://accessmanager.local/application/o/nextzenos-oidc/"
|
callbackURL string
|
||||||
//authURL = "http://10.0.0.26:9000/application/o/nextzenos-oidc/"
|
|
||||||
callbackURL = "http://nextzenos.local/v1/users/oidc/callback"
|
|
||||||
//callbackURL = "http://172.20.60.244:8080/v1/users/oidc/callback"
|
|
||||||
onePanelServer = "http://172.20.60.244:13000"
|
|
||||||
onePanelName = "nextzen"
|
|
||||||
onePanelPassword = "Smartyourlife123@*"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type OIDCSetting struct {
|
type OIDCSetting struct {
|
||||||
@@ -117,25 +113,86 @@ func PostUserRegister(c *gin.Context) {
|
|||||||
|
|
||||||
var limiter = rate.NewLimiter(rate.Every(time.Minute), 5)
|
var limiter = rate.NewLimiter(rate.Every(time.Minute), 5)
|
||||||
|
|
||||||
// @Summary login
|
// TODO Cant call login every request(using for testing only)
|
||||||
// @Produce application/json
|
func ExternalAPIMiddleware(c *gin.Context) {
|
||||||
// @Accept application/json
|
session := sessions.Default(c)
|
||||||
// @Tags user
|
if err := OnePanelLogin(c); err != nil {
|
||||||
// @Param user_name query string true "User name"
|
c.JSON(http.StatusUnauthorized, model.Result{
|
||||||
// @Param pwd query string true "password"
|
Success: common_err.SERVICE_ERROR,
|
||||||
// @Success 200 {string} string "ok"
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
// @Router /user/login [post]
|
})
|
||||||
func OnePanelLogin(c *gin.Context) {
|
c.Abort()
|
||||||
var cred = model2.OnePanelCredentials{
|
return
|
||||||
Name: onePanelName,
|
}
|
||||||
Password: onePanelPassword,
|
sessionId := session.Get("psession")
|
||||||
|
|
||||||
|
if sessionId == nil {
|
||||||
|
c.JSON(http.StatusInternalServerError, model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add sessionId to the request's Cookie header
|
||||||
|
c.Request.Header.Set("Cookie", "psession="+sessionId.(string))
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
func OnePanelLogin(c *gin.Context) error {
|
||||||
|
cred := model2.OnePanelCredentials{
|
||||||
|
Name: config.NextWebInfo.UserName,
|
||||||
|
Password: config.NextWebInfo.Password,
|
||||||
IgnoreCaptcha: true,
|
IgnoreCaptcha: true,
|
||||||
Captcha: "",
|
Captcha: "",
|
||||||
CaptchaID: "",
|
CaptchaID: "",
|
||||||
AuthMethod: "session",
|
AuthMethod: "session",
|
||||||
Language: "en",
|
Language: "en",
|
||||||
}
|
}
|
||||||
response, cookies, err := service.MyService.OnePanel().Login(cred, "http://172.20.60.244:13000")
|
|
||||||
|
response, cookies, err := service.MyService.OnePanel().Login(cred, config.NextWebInfo.Server, config.NextWebInfo.EntranceCode)
|
||||||
|
fmt.Println(response)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("NextWeb login failed", zap.Error(err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
session := sessions.Default(c)
|
||||||
|
for _, cookie := range cookies {
|
||||||
|
session.Set(cookie.Name, cookie.Value)
|
||||||
|
session.Options(sessions.Options{
|
||||||
|
MaxAge: 3600, // 12hrs
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
if err := session.Save(); err != nil {
|
||||||
|
logger.Error("Failed to save session", zap.Error(err))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func OnePanelUpdateProxyWebsite(c *gin.Context) {
|
||||||
|
json := make(map[string]string)
|
||||||
|
c.ShouldBind(&json)
|
||||||
|
domain := json["domain"]
|
||||||
|
port := json["port"]
|
||||||
|
hostname := json["hostname"]
|
||||||
|
protocol := json["protocol"]
|
||||||
|
var searchParam model2.SearchWebsiteRequest
|
||||||
|
searchParam.Name = domain
|
||||||
|
searchParam.Page = 1
|
||||||
|
searchParam.PageSize = 1
|
||||||
|
searchParam.OrderBy = "created_at"
|
||||||
|
searchParam.Order = "null"
|
||||||
|
searchParam.WebsiteGroupID = 0
|
||||||
|
headers := make(map[string]string)
|
||||||
|
for key, value := range c.Request.Header {
|
||||||
|
headers[key] = value[0]
|
||||||
|
}
|
||||||
|
var search model2.SearchWebsiteResponse
|
||||||
|
search, err := service.MyService.OnePanel().SearchWebsite(searchParam, config.NextWebInfo.Server, headers)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(common_err.SERVICE_ERROR,
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
model.Result{
|
model.Result{
|
||||||
@@ -143,8 +200,563 @@ func OnePanelLogin(c *gin.Context) {
|
|||||||
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
for _, cookie := range cookies {
|
if search.Data.Total > 0 {
|
||||||
c.SetCookie(cookie.Name, cookie.Value, 3600, "/", "", false, true)
|
var proxy model2.ProxyWebsiteRequest
|
||||||
|
proxy.ID = search.Data.Items[0].ID
|
||||||
|
var proxyResult model2.ProxyWebsiteResponse
|
||||||
|
proxyResult, err := service.MyService.OnePanel().GetProxyWebsite(proxy, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
updateProxy := model2.ProxyDetail{}
|
||||||
|
updateProxy = proxyResult.Data[0]
|
||||||
|
updateProxy.Operate = "edit"
|
||||||
|
updateProxy.ProxyPass = protocol + "://" + hostname + ":" + port
|
||||||
|
updateProxyResult, err := service.MyService.OnePanel().UpdateProxyWebsite(updateProxy, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
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.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SUCCESS,
|
||||||
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
|
Data: updateProxyResult,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SUCCESS,
|
||||||
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
func OnePanelUpdateWebsite(c *gin.Context) {
|
||||||
|
json := make(map[string]string)
|
||||||
|
c.ShouldBind(&json)
|
||||||
|
domain := json["domain"]
|
||||||
|
port := json["port"]
|
||||||
|
protocol := json["protocol"]
|
||||||
|
hostname := json["hostname"]
|
||||||
|
sslProvider := json["sslProvider"]
|
||||||
|
headers := make(map[string]string)
|
||||||
|
for key, value := range c.Request.Header {
|
||||||
|
headers[key] = value[0]
|
||||||
|
}
|
||||||
|
var searchParam model2.SearchWebsiteRequest
|
||||||
|
searchParam.Name = domain
|
||||||
|
searchParam.Page = 1
|
||||||
|
searchParam.PageSize = 1
|
||||||
|
searchParam.OrderBy = "created_at"
|
||||||
|
searchParam.Order = "null"
|
||||||
|
searchParam.WebsiteGroupID = 0
|
||||||
|
search, err := service.MyService.OnePanel().SearchWebsite(searchParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if search.Data.Total > 0 {
|
||||||
|
//TODO get Website ProxyData
|
||||||
|
var proxy model2.ProxyWebsiteRequest
|
||||||
|
proxy.ID = search.Data.Items[0].ID
|
||||||
|
var proxyResult model2.ProxyWebsiteResponse
|
||||||
|
proxyResult, err := service.MyService.OnePanel().GetProxyWebsite(proxy, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
//TODO Update Website Proxies (update root)
|
||||||
|
updateProxy := model2.ProxyDetail{}
|
||||||
|
updateProxy = proxyResult.Data[0]
|
||||||
|
|
||||||
|
updateProxy.Operate = "edit"
|
||||||
|
updateProxy.ProxyPass = "http://" + hostname + ":" + port
|
||||||
|
updateProxyResult, err := service.MyService.OnePanel().UpdateProxyWebsite(updateProxy, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fmt.Println(updateProxyResult)
|
||||||
|
sslId := -1
|
||||||
|
acmeId := 0
|
||||||
|
var validSSL bool
|
||||||
|
var searchSSLParam model2.SearchSSLRequest
|
||||||
|
if sslProvider == "selfSigned" {
|
||||||
|
searchSSLParam.AcmeAccountID = strconv.Itoa(acmeId)
|
||||||
|
}
|
||||||
|
searchSSLParam.Page = 0
|
||||||
|
searchSSLParam.PageSize = 0
|
||||||
|
searchSSL, err := service.MyService.OnePanel().SearchWebsiteSSl(searchSSLParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, item := range searchSSL.Data {
|
||||||
|
if item.Provider == sslProvider && item.PrimaryDomain == domain && item.Status == "ready" {
|
||||||
|
sslId = item.ID
|
||||||
|
validSSL = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if search.Data.Items[0].Protocol != protocol && protocol == "http" {
|
||||||
|
//TODO disable HTTPS
|
||||||
|
if sslId > 0 {
|
||||||
|
var updateHttps, err = UpdateWebsiteHttps(false, acmeId, sslId, search.Data.Items[0].ID, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fmt.Println(updateHttps)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sslId < 0 {
|
||||||
|
//TODO create new SSL if not exist
|
||||||
|
if sslProvider == "http" {
|
||||||
|
sslId, err = OnePanelApplyWebsiteSSl(domain, search.Data.Items[0].ID, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if sslId > 0 {
|
||||||
|
validSSL, err = checkGlobalSSLStatus(sslId, headers, domain, 10)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to upgrade %s from http to https", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sslId, err = IssueSelfSignedCert(domain, search.Data.Items[0].ID, headers, 3)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
validSSL = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sslId < 0 || !validSSL {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to Create SSL or domain %s is invalid to create global SSL", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
updateHttps, err := UpdateWebsiteHttps(true, acmeId, sslId, search.Data.Items[0].ID, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fmt.Println(updateHttps)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func OnePanelCreateWebsite(c *gin.Context) {
|
||||||
|
json := make(map[string]string)
|
||||||
|
c.ShouldBind(&json)
|
||||||
|
domain := json["domain"]
|
||||||
|
port := json["port"]
|
||||||
|
protocol := json["protocol"]
|
||||||
|
hostname := json["hostname"]
|
||||||
|
sslProvider := json["sslProvider"]
|
||||||
|
var website model2.CreateWebsiteRequest
|
||||||
|
website.PrimaryDomain = domain
|
||||||
|
website.Type = "proxy"
|
||||||
|
website.Alias = domain
|
||||||
|
website.AppType = "installed"
|
||||||
|
website.WebSiteGroupID = 2
|
||||||
|
website.Proxy = "http://" + hostname + ":" + port
|
||||||
|
portInt, err := strconv.ParseInt(port, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error converting port to integer: %v", err)
|
||||||
|
|
||||||
|
}
|
||||||
|
website.Port = portInt
|
||||||
|
website.ProxyProtocol = "http"
|
||||||
|
website.ProxyAddress = hostname + ":" + port
|
||||||
|
website.RuntimeType = "php"
|
||||||
|
headers := make(map[string]string)
|
||||||
|
for key, value := range c.Request.Header {
|
||||||
|
headers[key] = value[0]
|
||||||
|
}
|
||||||
|
var searchParam model2.SearchWebsiteRequest
|
||||||
|
searchParam.Name = website.PrimaryDomain
|
||||||
|
searchParam.Page = 1
|
||||||
|
searchParam.PageSize = 1
|
||||||
|
searchParam.OrderBy = "created_at"
|
||||||
|
searchParam.Order = "null"
|
||||||
|
searchParam.WebsiteGroupID = 0
|
||||||
|
search, err := service.MyService.OnePanel().SearchWebsite(searchParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if search.Data.Total == 0 {
|
||||||
|
response, err := service.MyService.OnePanel().CreateWebsite(website, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
search, err := service.MyService.OnePanel().SearchWebsite(searchParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if protocol == "https" {
|
||||||
|
//TODO Find SSL
|
||||||
|
var validSSL bool
|
||||||
|
var searchSSL model2.SearchSSLRequest
|
||||||
|
searchSSL.Page = 0
|
||||||
|
searchSSL.PageSize = 0
|
||||||
|
sslId := -1
|
||||||
|
ssl, err := service.MyService.OnePanel().SearchWebsiteSSl(searchSSL, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, item := range ssl.Data {
|
||||||
|
if item.PrimaryDomain == domain && item.Provider == sslProvider && item.Status == "ready" {
|
||||||
|
sslId = item.ID
|
||||||
|
validSSL = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sslId < 0 {
|
||||||
|
if sslProvider == "http" {
|
||||||
|
sslId, err = OnePanelApplyWebsiteSSl(domain, search.Data.Items[0].ID, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to upgrade %s from http to https", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if sslId > 0 {
|
||||||
|
validSSL, err = checkGlobalSSLStatus(sslId, headers, domain, 10)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to upgrade %s from http to https", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
sslId, err = IssueSelfSignedCert(domain, search.Data.Items[0].ID, headers, 3)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to upgrade %s from http to https", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
validSSL = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if sslId < 0 || !validSSL {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to Create SSL or domain %s is invalid to create global SSL", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// TODO Enable HTTPS
|
||||||
|
var searchAcme model2.AcmeSearchRequest
|
||||||
|
acmeId := 0
|
||||||
|
searchAcme.Page = 1
|
||||||
|
searchAcme.PageSize = 1000
|
||||||
|
if sslProvider == "http" {
|
||||||
|
acme, err := service.MyService.OnePanel().AcmeAccountSearch(searchAcme, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
acmeId = acme.Data.Items[0].ID
|
||||||
|
}
|
||||||
|
search, err := service.MyService.OnePanel().SearchWebsite(searchParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
updateWebsite, err := UpdateWebsiteHttps(true, acmeId, sslId, search.Data.Items[0].ID, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if updateWebsite.Code < 200 || updateWebsite.Code > 300 {
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.COMMAND_ERROR_INVALID_OPERATION,
|
||||||
|
Message: fmt.Sprintf("Fail to upgrade %s from http to https", domain),
|
||||||
|
Data: false,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SUCCESS,
|
||||||
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
|
Data: response,
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SUCCESS,
|
||||||
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func checkGlobalSSLStatus(sslId int, headers map[string]string, domain string, retries int) (bool, error) {
|
||||||
|
if retries <= 0 {
|
||||||
|
return false, errors.New("timeout waiting for SSL certificate to become ready")
|
||||||
|
}
|
||||||
|
|
||||||
|
sslDetail, err := service.MyService.OnePanel().GetSSLDetail(sslId, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
if sslDetail.Data.Status == "ready" {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
if sslDetail.Data.Status == "applyError" {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
time.Sleep(3 * time.Second)
|
||||||
|
|
||||||
|
return checkGlobalSSLStatus(sslId, headers, domain, retries-1)
|
||||||
|
}
|
||||||
|
func IssueSelfSignedCert(domain string, websiteId int, headers map[string]string, maxAttempts int) (int, error) {
|
||||||
|
if maxAttempts <= 0 {
|
||||||
|
return 0, errors.New("maximum attempts reached")
|
||||||
|
}
|
||||||
|
var searchSelfSignedCert model2.SelfSignedCertSearchRequest
|
||||||
|
searchSelfSignedCert.Page = 1
|
||||||
|
searchSelfSignedCert.PageSize = 1000
|
||||||
|
selfsignedCert, err := service.MyService.OnePanel().SelfSignedCertSearch(searchSelfSignedCert, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if selfsignedCert.Data.Total == 0 {
|
||||||
|
var createParam model2.CreateSelfSignedCertRequest
|
||||||
|
createParam.Name = "nextweb"
|
||||||
|
createParam.KeyType = "P256"
|
||||||
|
createParam.CommonName = "nextweb"
|
||||||
|
createParam.Country = "VN"
|
||||||
|
createParam.Organization = "nextweb"
|
||||||
|
createParam.OrganizationUint = "nextweb"
|
||||||
|
createParam.Province = "HaDong"
|
||||||
|
createParam.City = "HaNoi"
|
||||||
|
createNewSelfSignCert, err := service.MyService.OnePanel().CreateSelfSignedCert(createParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
fmt.Println(createNewSelfSignCert)
|
||||||
|
return IssueSelfSignedCert(domain, websiteId, headers, maxAttempts-1)
|
||||||
|
} else {
|
||||||
|
var issueSelfSignedCertReq model2.SelfSignedIssueRequest
|
||||||
|
issueSelfSignedCertReq.KeyType = "P256"
|
||||||
|
issueSelfSignedCertReq.Domains = domain
|
||||||
|
issueSelfSignedCertReq.ID = selfsignedCert.Data.Items[0].ID
|
||||||
|
issueSelfSignedCertReq.Time = 10
|
||||||
|
issueSelfSignedCertReq.Unit = "year"
|
||||||
|
issueSelfSignedCertReq.PushDir = false
|
||||||
|
issueSelfSignedCertReq.Dir = ""
|
||||||
|
issueSelfSignedCertReq.AutoRenew = true
|
||||||
|
issueSelfSignedCertReq.Description = ""
|
||||||
|
issueSelfSignedCertReq.ExecShell = false
|
||||||
|
issueSelfSignedCertReq.Shell = ""
|
||||||
|
issueSelfSignedCertRes, err := service.MyService.OnePanel().IssueSelfSignedCert(issueSelfSignedCertReq, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
fmt.Println(issueSelfSignedCertRes)
|
||||||
|
var searchSSL model2.SearchSSLRequest
|
||||||
|
searchSSL.Page = 0
|
||||||
|
searchSSL.PageSize = 0
|
||||||
|
ssl, err := service.MyService.OnePanel().SearchWebsiteSSl(searchSSL, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
for _, item := range ssl.Data {
|
||||||
|
if item.PrimaryDomain == domain {
|
||||||
|
return item.ID, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func OnePanelApplyWebsiteSSl(domain string, websiteId int, headers map[string]string) (int, error) {
|
||||||
|
var searchAcme model2.AcmeSearchRequest
|
||||||
|
searchAcme.Page = 1
|
||||||
|
searchAcme.PageSize = 10000
|
||||||
|
acme, err := service.MyService.OnePanel().AcmeAccountSearch(searchAcme, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if acme.Data.Total > 0 {
|
||||||
|
var createSSL model2.CreateSSLRequest
|
||||||
|
createSSL.ID = 1
|
||||||
|
createSSL.PrimaryDomain = domain
|
||||||
|
createSSL.OtherDomains = ""
|
||||||
|
createSSL.Provider = "http"
|
||||||
|
createSSL.WebsiteID = websiteId
|
||||||
|
createSSL.AcmeAccountID = acme.Data.Items[0].ID
|
||||||
|
createSSL.AutoRenew = true
|
||||||
|
createSSL.KeyType = "P256"
|
||||||
|
createSSL.PushDir = false
|
||||||
|
createSSL.Dir = ""
|
||||||
|
createSSL.Description = ""
|
||||||
|
createSSL.DisableCNAME = false
|
||||||
|
createSSL.Nameserver1 = ""
|
||||||
|
createSSL.Nameserver2 = ""
|
||||||
|
createSSL.ExecShell = false
|
||||||
|
createSSL.Shell = ""
|
||||||
|
createSSLRes, err := service.MyService.OnePanel().ApplyWebsiteSSl(createSSL, config.NextWebInfo.Server, headers)
|
||||||
|
return createSSLRes.Data.ID, err
|
||||||
|
}
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
func UpdateWebsiteHttps(enable bool, acmeAccountID int, websiteSSLID int, websiteId int, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
var updateConfig model2.WebsiteHttpsConfigRequest
|
||||||
|
updateConfig.AcmeAccountID = acmeAccountID
|
||||||
|
updateConfig.Enable = enable
|
||||||
|
updateConfig.WebsiteSSLID = websiteSSLID
|
||||||
|
updateConfig.WebsiteID = websiteId
|
||||||
|
updateConfig.Type = "existed"
|
||||||
|
updateConfig.ImportType = "paste"
|
||||||
|
updateConfig.PrivateKey = ""
|
||||||
|
updateConfig.Certificate = ""
|
||||||
|
updateConfig.PrivateKeyPath = ""
|
||||||
|
updateConfig.HTTPConfig = "HTTPToHTTPS"
|
||||||
|
updateConfig.Hsts = true
|
||||||
|
updateConfig.Algorithm = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:!aNULL:!eNULL:!EXPORT:!DSS:!DES:!RC4:!3DES:!MD5:!PSK:!KRB5:!SRP:!CAMELLIA:!SEED"
|
||||||
|
updateConfig.SSLProtocol = append(updateConfig.SSLProtocol, "TLSv1.3", "TLSv1.2", "TLSv1.1", "TLSv1")
|
||||||
|
updateWebsite, err := service.MyService.OnePanel().UpdateWebsiteProtocol(updateConfig, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, err
|
||||||
|
}
|
||||||
|
return updateWebsite, nil
|
||||||
|
}
|
||||||
|
func OnePanelDeleteWebsite(c *gin.Context) {
|
||||||
|
json := make(map[string]string)
|
||||||
|
c.ShouldBind(&json)
|
||||||
|
domain := json["domain"]
|
||||||
|
deleteSSL, err := strconv.ParseBool(json["deleteSSL"])
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
test := json["deleteSSL"]
|
||||||
|
fmt.Println(test)
|
||||||
|
var searchParam model2.SearchWebsiteRequest
|
||||||
|
searchParam.Name = domain
|
||||||
|
searchParam.Page = 1
|
||||||
|
searchParam.PageSize = 1
|
||||||
|
searchParam.OrderBy = "created_at"
|
||||||
|
searchParam.Order = "null"
|
||||||
|
searchParam.WebsiteGroupID = 0
|
||||||
|
headers := make(map[string]string)
|
||||||
|
for key, value := range c.Request.Header {
|
||||||
|
headers[key] = value[0]
|
||||||
|
}
|
||||||
|
search, err := service.MyService.OnePanel().SearchWebsite(searchParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if search.Data.Total > 0 {
|
||||||
|
var delete model2.DeleteWebsiteRequest
|
||||||
|
delete.ID = search.Data.Items[0].ID
|
||||||
|
delete.DeleteApp = false
|
||||||
|
delete.DeleteBackup = false
|
||||||
|
delete.ForceDelete = false
|
||||||
|
response, err := service.MyService.OnePanel().DeleteWebsite(delete, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
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.SUCCESS,
|
c.JSON(common_err.SUCCESS,
|
||||||
model.Result{
|
model.Result{
|
||||||
@@ -152,6 +764,51 @@ func OnePanelLogin(c *gin.Context) {
|
|||||||
Message: common_err.GetMsg(common_err.SUCCESS),
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
Data: response,
|
Data: response,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
if deleteSSL {
|
||||||
|
var searchSSLParam model2.SearchSSLRequest
|
||||||
|
searchSSLParam.AcmeAccountID = ""
|
||||||
|
searchSSLParam.Page = 0
|
||||||
|
searchSSLParam.PageSize = 0
|
||||||
|
searchSSL, err := service.MyService.OnePanel().SearchWebsiteSSl(searchSSLParam, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if len(searchSSL.Data) > 0 {
|
||||||
|
var deleleSSL model2.DeleteSSLRequest
|
||||||
|
for _, ssl := range searchSSL.Data {
|
||||||
|
if ssl.PrimaryDomain == domain {
|
||||||
|
deleleSSL.Ids = append(deleleSSL.Ids, ssl.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(deleleSSL.Ids) > 0 {
|
||||||
|
deleteResult, err := service.MyService.OnePanel().DeleteWebsiteSSL(deleleSSL, config.NextWebInfo.Server, headers)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
fmt.Println(deleteResult)
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SUCCESS,
|
||||||
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.JSON(common_err.SUCCESS,
|
||||||
|
model.Result{
|
||||||
|
Success: common_err.SUCCESS,
|
||||||
|
Message: common_err.GetMsg(common_err.SUCCESS),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
func PostUserLogin(c *gin.Context) {
|
func PostUserLogin(c *gin.Context) {
|
||||||
if !limiter.Allow() {
|
if !limiter.Allow() {
|
||||||
@@ -235,7 +892,7 @@ var oidcInit bool
|
|||||||
func InitOIDC() {
|
func InitOIDC() {
|
||||||
const (
|
const (
|
||||||
maxSleep = 60 * time.Second
|
maxSleep = 60 * time.Second
|
||||||
minSleep = 10 * time.Second
|
minSleep = 3 * time.Second
|
||||||
maxRetryBackoff = 5 // Cap retry backoff to 5 attempts
|
maxRetryBackoff = 5 // Cap retry backoff to 5 attempts
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -260,9 +917,11 @@ func InitOIDC() {
|
|||||||
oidcInit = true
|
oidcInit = true
|
||||||
failCount = 0
|
failCount = 0
|
||||||
successCount++
|
successCount++
|
||||||
|
// TODO will enable in production
|
||||||
// Exponential backoff with a cap
|
// Exponential backoff with a cap
|
||||||
sleepTime = minSleep * time.Duration(successCount)
|
sleepTime = minSleep * time.Duration(successCount)
|
||||||
if sleepTime > maxSleep {
|
if sleepTime > maxSleep {
|
||||||
|
// TODO will enable in production
|
||||||
sleepTime = maxSleep
|
sleepTime = maxSleep
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,6 +932,7 @@ func InitOIDC() {
|
|||||||
// Exponential backoff with a cap
|
// Exponential backoff with a cap
|
||||||
sleepTime = minSleep * time.Duration(failCount)
|
sleepTime = minSleep * time.Duration(failCount)
|
||||||
if failCount > maxRetryBackoff {
|
if failCount > maxRetryBackoff {
|
||||||
|
// TODO will enable in production
|
||||||
sleepTime = minSleep * time.Duration(maxRetryBackoff)
|
sleepTime = minSleep * time.Duration(maxRetryBackoff)
|
||||||
}
|
}
|
||||||
log.Printf("OIDC initialization failed: %v. Retrying in %v", err, sleepTime)
|
log.Printf("OIDC initialization failed: %v. Retrying in %v", err, sleepTime)
|
||||||
@@ -287,7 +947,7 @@ func CheckOIDCInit() gin.HandlerFunc {
|
|||||||
return func(c *gin.Context) {
|
return func(c *gin.Context) {
|
||||||
if !oidcInit {
|
if !oidcInit {
|
||||||
log.Println("Provider is Offline")
|
log.Println("Provider is Offline")
|
||||||
c.JSON(http.StatusServiceUnavailable, model.Result{Success: common_err.OIDC_OFFLINE, Message: "Authentik Server is Offline"})
|
//c.JSON(http.StatusServiceUnavailable, model.Result{Success: common_err.OIDC_OFFLINE, Message: "Authentik Server is Offline"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Next()
|
c.Next()
|
||||||
@@ -303,6 +963,12 @@ func OIDC() error {
|
|||||||
authServer = authentik.Issuer
|
authServer = authentik.Issuer
|
||||||
authURL = authentik.AuthUrl
|
authURL = authentik.AuthUrl
|
||||||
callbackURL = authentik.CallbackUrl
|
callbackURL = authentik.CallbackUrl
|
||||||
|
} else {
|
||||||
|
clientID = config.OIDCInfo.ClientID
|
||||||
|
clientSecret = config.OIDCInfo.ClientSecret
|
||||||
|
authServer = config.OIDCInfo.AuthServer
|
||||||
|
authURL = config.OIDCInfo.AuthURL
|
||||||
|
callbackURL = config.OIDCInfo.CallbackURL
|
||||||
}
|
}
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
provider, err := oidc.NewProvider(ctx, authURL)
|
provider, err := oidc.NewProvider(ctx, authURL)
|
||||||
@@ -315,7 +981,6 @@ func OIDC() error {
|
|||||||
RedirectURL: callbackURL,
|
RedirectURL: callbackURL,
|
||||||
Endpoint: provider.Endpoint(),
|
Endpoint: provider.Endpoint(),
|
||||||
Scopes: []string{oidc.ScopeOpenID, "profile", "email", "offline_access", "goauthentik.io/api"},
|
Scopes: []string{oidc.ScopeOpenID, "profile", "email", "offline_access", "goauthentik.io/api"},
|
||||||
//add offline access for refresh token
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -442,28 +1107,27 @@ func OIDCValidateToken(c *gin.Context) {
|
|||||||
var validateToken model2.AuthentikToken
|
var validateToken model2.AuthentikToken
|
||||||
validateToken, err = service.MyService.Authentik().ValidateToken(clientID, clientSecret, accessToken, authServer)
|
validateToken, err = service.MyService.Authentik().ValidateToken(clientID, clientSecret, accessToken, authServer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(http.StatusUnauthorized, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !validateToken.Active {
|
if !validateToken.Active {
|
||||||
c.JSON(http.StatusUnauthorized, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
|
||||||
}
|
}
|
||||||
func OIDCLogout(c *gin.Context) {
|
func OIDCLogout(c *gin.Context) {
|
||||||
json := make(map[string]string)
|
// json := make(map[string]string)
|
||||||
c.ShouldBind(&json)
|
// c.ShouldBind(&json)
|
||||||
flow := "/if/flow/default-authentication-flow/"
|
// flow := "/if/flow/default-authentication-flow/"
|
||||||
next := "/application/o/authorize/"
|
// next := "/application/o/authorize/"
|
||||||
|
// client := "client_id=" + clientID
|
||||||
client := "client_id=" + clientID
|
// redirect_uri := "&redirect_uri=" + url.QueryEscape(callbackURL)
|
||||||
redirect_uri := "&redirect_uri=" + url.QueryEscape(callbackURL)
|
// response_type := "&response_type=code"
|
||||||
response_type := "&response_type=code"
|
// scope := "&scope=openid+profile+email+" + url.QueryEscape("goauthentik.io/api")
|
||||||
scope := "&scope=openid+profile+email+" + url.QueryEscape("goauthentik.io/api")
|
// state := "&state=" + url.QueryEscape("/#/profile")
|
||||||
state := "&state=" + url.QueryEscape("/#/profile")
|
//fullURL := authServer + flow + "?" + "next=" + url.QueryEscape(next+"?"+client+redirect_uri+response_type+scope+state)
|
||||||
fullURL := authServer + flow + "?" + "next=" + url.QueryEscape(next+"?"+client+redirect_uri+response_type+scope+state)
|
fullURL := "https://home.nextzenvn.com/outpost.goauthentik.io/sign_out"
|
||||||
|
|
||||||
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN), Data: fullURL})
|
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN), Data: fullURL})
|
||||||
}
|
}
|
||||||
func OIDCProfile(c *gin.Context) {
|
func OIDCProfile(c *gin.Context) {
|
||||||
@@ -534,7 +1198,7 @@ func determineUserRole(isSuperuser bool) string {
|
|||||||
return "user"
|
return "user"
|
||||||
}
|
}
|
||||||
func OnePanelHealthCheck(c *gin.Context) {
|
func OnePanelHealthCheck(c *gin.Context) {
|
||||||
status, err := service.MyService.OnePanel().HealthCheck(onePanelServer)
|
status, err := service.MyService.OnePanel().HealthCheck(config.NextWebInfo.Server)
|
||||||
if err != nil || status == "Offline" {
|
if err != nil || status == "Offline" {
|
||||||
c.JSON(http.StatusOK, model.Result{Success: common_err.OIDC_OFFLINE, Message: common_err.GetMsg(common_err.OIDC_OFFLINE), Data: "Offline"})
|
c.JSON(http.StatusOK, model.Result{Success: common_err.OIDC_OFFLINE, Message: common_err.GetMsg(common_err.OIDC_OFFLINE), Data: "Offline"})
|
||||||
return
|
return
|
||||||
@@ -986,7 +1650,6 @@ func GetUserCustomConf(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
id := c.GetHeader("user_id")
|
id := c.GetHeader("user_id")
|
||||||
|
|
||||||
user := service.MyService.User().GetUserInfoById(id)
|
user := service.MyService.User().GetUserInfoById(id)
|
||||||
// user := service.MyService.User().GetUserInfoByUsername(Username)
|
// user := service.MyService.User().GetUserInfoByUsername(Username)
|
||||||
if user.Id == 0 {
|
if user.Id == 0 {
|
||||||
@@ -994,14 +1657,23 @@ func GetUserCustomConf(c *gin.Context) {
|
|||||||
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, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
filePath := config.AppInfo.UserDataPath + "/" + id + "/" + name + ".json"
|
if name == "default-app" {
|
||||||
|
filePath := config.AppInfo.UserDataPath + "/default/link.json"
|
||||||
data := file.ReadFullFile(filePath)
|
data := file.ReadFullFile(filePath)
|
||||||
if !gjson.ValidBytes(data) {
|
if !gjson.ValidBytes(data) {
|
||||||
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: string(data)})
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: string(data)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
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))})
|
||||||
|
} else {
|
||||||
|
filePath := config.AppInfo.UserDataPath + "/" + id + "/" + name + ".json"
|
||||||
|
data := file.ReadFullFile(filePath)
|
||||||
|
if !gjson.ValidBytes(data) {
|
||||||
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: string(data)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(common_err.SUCCESS, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: json2.RawMessage(string(data))})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1023,9 +1695,40 @@ func PostUserCustomConf(c *gin.Context) {
|
|||||||
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, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, _ := io.ReadAll(c.Request.Body)
|
data, err := io.ReadAll(c.Request.Body)
|
||||||
|
if err != nil {
|
||||||
|
logger.Error("Failed to read request body", zap.Error(err))
|
||||||
|
c.JSON(common_err.SERVICE_ERROR, model.Result{
|
||||||
|
Success: common_err.SERVICE_ERROR,
|
||||||
|
Message: common_err.GetMsg(common_err.SERVICE_ERROR),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if name == "default-app" {
|
||||||
|
var appInfos []model.AppInfo
|
||||||
|
err := json.Unmarshal([]byte(data), &appInfos)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
configData := formatAppInfosToMap(appInfos)
|
||||||
|
cfg.WriteMapToConfig(configData, name)
|
||||||
|
}()
|
||||||
|
filePath := config.AppInfo.UserDataPath + "/default"
|
||||||
|
if err := file.IsNotExistMkDir(filePath); err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := file.WriteToPath(data, filePath, "link.json"); err != nil {
|
||||||
|
c.JSON(common_err.SERVICE_ERROR,
|
||||||
|
model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
filePath := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id)
|
filePath := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id)
|
||||||
|
|
||||||
if err := file.IsNotExistMkDir(filePath); err != nil {
|
if err := file.IsNotExistMkDir(filePath); err != nil {
|
||||||
c.JSON(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)})
|
model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||||
@@ -1037,7 +1740,7 @@ func PostUserCustomConf(c *gin.Context) {
|
|||||||
model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
model.Result{Success: common_err.SERVICE_ERROR, Message: common_err.GetMsg(common_err.SERVICE_ERROR)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if name == "system" {
|
if name == "system" {
|
||||||
dataMap := make(map[string]string, 1)
|
dataMap := make(map[string]string, 1)
|
||||||
dataMap["system"] = string(data)
|
dataMap["system"] = string(data)
|
||||||
@@ -1049,11 +1752,19 @@ func PostUserCustomConf(c *gin.Context) {
|
|||||||
if response.StatusCode() != http.StatusOK {
|
if response.StatusCode() != http.StatusOK {
|
||||||
logger.Error("failed to publish event to message bus", zap.String("status", response.Status()), zap.Any("response", response))
|
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))})
|
||||||
}
|
}
|
||||||
|
func formatAppInfosToMap(appInfos []model.AppInfo) map[string]string {
|
||||||
|
formattedMap := make(map[string]string)
|
||||||
|
for _, appInfo := range appInfos {
|
||||||
|
formattedString := fmt.Sprintf("%s-%s-%s-%s-%s",
|
||||||
|
appInfo.Name, appInfo.Hostname, appInfo.Icon, appInfo.AppType, appInfo.Status)
|
||||||
|
formattedMap[appInfo.Name] = formattedString
|
||||||
|
}
|
||||||
|
return formattedMap
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: delete user custom config
|
* @description: delete user custom config
|
||||||
@@ -1346,7 +2057,7 @@ func DeleteUserAll(c *gin.Context) {
|
|||||||
// })
|
// })
|
||||||
// }
|
// }
|
||||||
|
|
||||||
func GetUserStatus(c *gin.Context) {
|
func InitializedUser(c *gin.Context) {
|
||||||
data := make(map[string]interface{}, 2)
|
data := make(map[string]interface{}, 2)
|
||||||
key := uuid.NewV4().String()
|
key := uuid.NewV4().String()
|
||||||
service.UserRegisterHash[key] = key
|
service.UserRegisterHash[key] = key
|
||||||
|
|||||||
+453
-3
@@ -2,6 +2,7 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -11,9 +12,24 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type OnePanelService interface {
|
type OnePanelService interface {
|
||||||
Login(m model2.OnePanelCredentials, baseURL string) (model2.LoginResponse, []*http.Cookie, error)
|
Login(m model2.OnePanelCredentials, baseURL string, entranceCode string) (model2.LoginResponse, []*http.Cookie, error)
|
||||||
Logout(m model2.OnePanelCredentials, baseURL string) (model2.LogoutResponse, error)
|
Logout(m model2.OnePanelCredentials, baseURL string) (model2.LogoutResponse, error)
|
||||||
HealthCheck(baseURL string) (string, error)
|
HealthCheck(baseURL string) (string, error)
|
||||||
|
SearchInstalledApp(p model2.InstalledAppRequest, baseURL string) (model2.InstalledAppResponse, error)
|
||||||
|
SearchWebsite(m model2.SearchWebsiteRequest, baseUrl string, headers map[string]string) (model2.SearchWebsiteResponse, error)
|
||||||
|
CreateWebsite(m model2.CreateWebsiteRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error)
|
||||||
|
DeleteWebsite(m model2.DeleteWebsiteRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error)
|
||||||
|
GetProxyWebsite(m model2.ProxyWebsiteRequest, baseUrl string, headers map[string]string) (model2.ProxyWebsiteResponse, error)
|
||||||
|
UpdateProxyWebsite(m model2.ProxyDetail, baseUrl string, headers map[string]string) (model2.GenericResponse, error)
|
||||||
|
AcmeAccountSearch(m model2.AcmeSearchRequest, baseUrl string, headers map[string]string) (model2.AcmeSearchResponse, error)
|
||||||
|
SelfSignedCertSearch(m model2.SelfSignedCertSearchRequest, baseUrl string, headers map[string]string) (model2.SelfSignedCertSearchResponse, error)
|
||||||
|
IssueSelfSignedCert(m model2.SelfSignedIssueRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error)
|
||||||
|
CreateSelfSignedCert(m model2.CreateSelfSignedCertRequest, baseUrl string, headers map[string]string) (model2.CreateSelfSignedCertResponse, error)
|
||||||
|
ApplyWebsiteSSl(m model2.CreateSSLRequest, baseUrl string, headers map[string]string) (model2.CreateSSLResponse, error)
|
||||||
|
SearchWebsiteSSl(m model2.SearchSSLRequest, baseUrl string, headers map[string]string) (model2.SearchSSLResponse, error)
|
||||||
|
UpdateWebsiteProtocol(m model2.WebsiteHttpsConfigRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error)
|
||||||
|
DeleteWebsiteSSL(m model2.DeleteSSLRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error)
|
||||||
|
GetSSLDetail(sslId int, baseUrl string, headers map[string]string) (model2.SSLDetail, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -23,7 +39,441 @@ var (
|
|||||||
type onePanelService struct {
|
type onePanelService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *onePanelService) Login(m model2.OnePanelCredentials, baseURL string) (model2.LoginResponse, []*http.Cookie, error) {
|
func (o *onePanelService) GetSSLDetail(sslId int, baseUrl string, headers map[string]string) (model2.SSLDetail, error) {
|
||||||
|
path := baseUrl + fmt.Sprintf("/api/v1/websites/ssl/%d", sslId)
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", path, nil)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SSLDetail{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SSLDetail{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.SSLDetail{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.SSLDetail
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.SSLDetail{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) DeleteWebsiteSSL(m model2.DeleteSSLRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/ssl/del"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.GenericResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) UpdateWebsiteProtocol(m model2.WebsiteHttpsConfigRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
path := baseUrl + fmt.Sprintf("/api/v1/websites/%d/https", m.WebsiteID)
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.GenericResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) SelfSignedCertSearch(m model2.SelfSignedCertSearchRequest, baseUrl string, headers map[string]string) (model2.SelfSignedCertSearchResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/ca/search"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SelfSignedCertSearchResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.SelfSignedCertSearchResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SelfSignedCertSearchResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.SelfSignedCertSearchResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.SelfSignedCertSearchResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.SelfSignedCertSearchResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) CreateSelfSignedCert(m model2.CreateSelfSignedCertRequest, baseUrl string, headers map[string]string) (model2.CreateSelfSignedCertResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/ca"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.CreateSelfSignedCertResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.CreateSelfSignedCertResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.CreateSelfSignedCertResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.CreateSelfSignedCertResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.CreateSelfSignedCertResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.CreateSelfSignedCertResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) IssueSelfSignedCert(m model2.SelfSignedIssueRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/ca/obtain"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.GenericResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) SearchWebsiteSSl(m model2.SearchSSLRequest, baseUrl string, headers map[string]string) (model2.SearchSSLResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/ssl/search"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SearchSSLResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.SearchSSLResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SearchSSLResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.SearchSSLResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.SearchSSLResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.SearchSSLResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) ApplyWebsiteSSl(m model2.CreateSSLRequest, baseUrl string, headers map[string]string) (model2.CreateSSLResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/ssl"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.CreateSSLResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.CreateSSLResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.CreateSSLResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.CreateSSLResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.CreateSSLResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.CreateSSLResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) AcmeAccountSearch(m model2.AcmeSearchRequest, baseUrl string, headers map[string]string) (model2.AcmeSearchResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/acme/search"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.AcmeSearchResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.AcmeSearchResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.AcmeSearchResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.AcmeSearchResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.AcmeSearchResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.AcmeSearchResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) UpdateProxyWebsite(m model2.ProxyDetail, baseUrl string, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/proxies/update"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.GenericResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (o *onePanelService) GetProxyWebsite(m model2.ProxyWebsiteRequest, baseUrl string, headers map[string]string) (model2.ProxyWebsiteResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/proxies"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.ProxyWebsiteResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.ProxyWebsiteResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.ProxyWebsiteResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.ProxyWebsiteResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.ProxyWebsiteResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.ProxyWebsiteResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) SearchWebsite(m model2.SearchWebsiteRequest, baseUrl string, headers map[string]string) (model2.SearchWebsiteResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/search"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SearchWebsiteResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.SearchWebsiteResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.SearchWebsiteResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.SearchWebsiteResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.SearchWebsiteResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.SearchWebsiteResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) CreateWebsite(m model2.CreateWebsiteRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.GenericResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) DeleteWebsite(m model2.DeleteWebsiteRequest, baseUrl string, headers map[string]string) (model2.GenericResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/del"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
// Add headers to the request
|
||||||
|
for key, value := range headers {
|
||||||
|
req.Header.Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.GenericResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.GenericResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) SearchInstalledApp(m model2.InstalledAppRequest, baseUrl string) (model2.InstalledAppResponse, error) {
|
||||||
|
path := baseUrl + "/api/v1/websites/search"
|
||||||
|
reqBody, err := json.Marshal(m)
|
||||||
|
if err != nil {
|
||||||
|
return model2.InstalledAppResponse{}, fmt.Errorf("error marshaling request body: %v", err)
|
||||||
|
}
|
||||||
|
req, err := http.NewRequest("POST", path, bytes.NewReader(reqBody))
|
||||||
|
// req.AddCookie()
|
||||||
|
if err != nil {
|
||||||
|
return model2.InstalledAppResponse{}, fmt.Errorf("error creating request: %v", err)
|
||||||
|
}
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return model2.InstalledAppResponse{}, fmt.Errorf("error making request: %v", err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
|
return model2.InstalledAppResponse{}, fmt.Errorf("HTTP error: %s", resp.Status)
|
||||||
|
}
|
||||||
|
var result model2.InstalledAppResponse
|
||||||
|
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||||
|
return model2.InstalledAppResponse{}, fmt.Errorf("error decoding response: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
func (o *onePanelService) Login(m model2.OnePanelCredentials, baseURL string, entranceCode string) (model2.LoginResponse, []*http.Cookie, error) {
|
||||||
path := baseURL + prefixV1 + "/auth/login"
|
path := baseURL + prefixV1 + "/auth/login"
|
||||||
|
|
||||||
// Create the request body by marshaling the credentials into JSON
|
// Create the request body by marshaling the credentials into JSON
|
||||||
@@ -38,7 +488,7 @@ func (o *onePanelService) Login(m model2.OnePanelCredentials, baseURL string) (m
|
|||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", "application/json")
|
req.Header.Set("Content-Type", "application/json")
|
||||||
req.Header.Set("Accept", "application/json")
|
req.Header.Set("Accept", "application/json")
|
||||||
|
req.Header.Set("Entrancecode", base64.StdEncoding.EncodeToString([]byte(entranceCode)))
|
||||||
// Reuse the HTTP client (consider making it a field in onePanelService)
|
// Reuse the HTTP client (consider making it a field in onePanelService)
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|||||||
@@ -40,6 +40,10 @@ func (a *authentikService) UpdateSettings(m model2.AuthentikCredentialsDBModel)
|
|||||||
var existing model2.AuthentikCredentialsDBModel
|
var existing model2.AuthentikCredentialsDBModel
|
||||||
result := a.db.First(&existing)
|
result := a.db.First(&existing)
|
||||||
if result.Error != nil {
|
if result.Error != nil {
|
||||||
|
if result.Error.Error() == "record not found" {
|
||||||
|
a.db.Create(&m)
|
||||||
|
return existing, nil
|
||||||
|
}
|
||||||
return existing, result.Error
|
return existing, result.Error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type InstalledAppRequest struct {
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"pageSize"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Tags []interface{} `json:"tags"`
|
||||||
|
Update bool `json:"update"`
|
||||||
|
Sync bool `json:"sync"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type InstalledAppResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
Items []struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
AppID int `json:"appID"`
|
||||||
|
AppDetailID int `json:"appDetailID"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
HTTPPort int `json:"httpPort"`
|
||||||
|
HTTPSPort int `json:"httpsPort"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
CanUpdate bool `json:"canUpdate"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
AppName string `json:"appName"`
|
||||||
|
Ready int `json:"ready"`
|
||||||
|
Total int `json:"total"`
|
||||||
|
AppKey string `json:"appKey"`
|
||||||
|
AppType string `json:"appType"`
|
||||||
|
AppStatus string `json:"appStatus"`
|
||||||
|
DockerCompose string `json:"dockerCompose"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
App struct {
|
||||||
|
Website string `json:"website"`
|
||||||
|
Document string `json:"document"`
|
||||||
|
Github string `json:"github"`
|
||||||
|
} `json:"app"`
|
||||||
|
} `json:"items"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,340 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type CreateSSLRequest struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
OtherDomains string `json:"otherDomains"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
WebsiteID int `json:"websiteId"`
|
||||||
|
AcmeAccountID int `json:"acmeAccountId"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
DisableCNAME bool `json:"disableCNAME"`
|
||||||
|
SkipDNS bool `json:"skipDNS"`
|
||||||
|
Nameserver1 string `json:"nameserver1"`
|
||||||
|
Nameserver2 string `json:"nameserver2"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateSSLResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
OtherDomains string `json:"otherDomains"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
AcmeAccountID int `json:"acmeAccountId"`
|
||||||
|
DNSAccountID int `json:"dnsAccountId"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
Apply bool `json:"apply"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
DisableCNAME bool `json:"disableCNAME"`
|
||||||
|
SkipDNS bool `json:"skipDNS"`
|
||||||
|
Nameserver1 string `json:"nameserver1"`
|
||||||
|
Nameserver2 string `json:"nameserver2"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
type CreateSelfSignedCertRequest struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
CommonName string `json:"commonName"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
OrganizationUint string `json:"organizationUint"`
|
||||||
|
Province string `json:"province"`
|
||||||
|
City string `json:"city"`
|
||||||
|
}
|
||||||
|
type CreateSelfSignedCertResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
CommonName string `json:"commonName"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
OrganizationUint string `json:"organizationUint"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
Province string `json:"province"`
|
||||||
|
City string `json:"city"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
type SelfSignedIssueRequest struct {
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
Domains string `json:"domains"`
|
||||||
|
ID int `json:"id"`
|
||||||
|
Time int `json:"time"`
|
||||||
|
Unit string `json:"unit"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
}
|
||||||
|
type AcmeSearchRequest struct {
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"pageSize"`
|
||||||
|
}
|
||||||
|
type SelfSignedCertSearchRequest struct {
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"pageSize"`
|
||||||
|
}
|
||||||
|
type SearchSSLRequest struct {
|
||||||
|
AcmeAccountID string `json:"acmeAccountID"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"pageSize"`
|
||||||
|
}
|
||||||
|
type SearchSSLResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
Pem string `json:"pem"`
|
||||||
|
Domains string `json:"domains"`
|
||||||
|
CertURL string `json:"certURL"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
DNSAccountID int `json:"dnsAccountId"`
|
||||||
|
AcmeAccountID int `json:"acmeAccountId"`
|
||||||
|
CaID int `json:"caId"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
ExpireDate time.Time `json:"expireDate"`
|
||||||
|
StartDate time.Time `json:"startDate"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
SkipDNS bool `json:"skipDNS"`
|
||||||
|
Nameserver1 string `json:"nameserver1"`
|
||||||
|
Nameserver2 string `json:"nameserver2"`
|
||||||
|
DisableCNAME bool `json:"disableCNAME"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
AcmeAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
EabKid string `json:"eabKid"`
|
||||||
|
EabHmacKey string `json:"eabHmacKey"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
} `json:"acmeAccount"`
|
||||||
|
DNSAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
} `json:"dnsAccount"`
|
||||||
|
Websites interface{} `json:"websites"`
|
||||||
|
LogPath string `json:"logPath"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
type WebsiteHttpsConfigRequest struct {
|
||||||
|
AcmeAccountID int `json:"acmeAccountID"`
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
WebsiteID int `json:"websiteId"`
|
||||||
|
WebsiteSSLID int `json:"websiteSSLId"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ImportType string `json:"importType"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
Certificate string `json:"certificate"`
|
||||||
|
PrivateKeyPath string `json:"privateKeyPath"`
|
||||||
|
CertificatePath string `json:"certificatePath"`
|
||||||
|
HTTPConfig string `json:"httpConfig"`
|
||||||
|
Hsts bool `json:"hsts"`
|
||||||
|
Algorithm string `json:"algorithm"`
|
||||||
|
SSLProtocol []string `json:"SSLProtocol"`
|
||||||
|
}
|
||||||
|
type AcmeSearchResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
Items []AcmeAccount `json:"items"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
type SelfSignedCertSearchResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
Items []struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Csr string `json:"csr"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
CommonName string `json:"commonName"`
|
||||||
|
Country string `json:"country"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
OrganizationUint string `json:"organizationUint"`
|
||||||
|
Province string `json:"province"`
|
||||||
|
City string `json:"city"`
|
||||||
|
} `json:"items"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
type DeleteSSLRequest struct {
|
||||||
|
Ids []int `json:"ids"`
|
||||||
|
}
|
||||||
|
type WebsiteDetail struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Protocol string `json:"protocol"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Alias string `json:"alias"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
HTTPConfig string `json:"httpConfig"`
|
||||||
|
ExpireDate time.Time `json:"expireDate"`
|
||||||
|
Proxy string `json:"proxy"`
|
||||||
|
ProxyType string `json:"proxyType"`
|
||||||
|
SiteDir string `json:"siteDir"`
|
||||||
|
ErrorLog bool `json:"errorLog"`
|
||||||
|
AccessLog bool `json:"accessLog"`
|
||||||
|
DefaultServer bool `json:"defaultServer"`
|
||||||
|
IPV6 bool `json:"IPV6"`
|
||||||
|
Rewrite string `json:"rewrite"`
|
||||||
|
WebSiteGroupID int `json:"webSiteGroupId"`
|
||||||
|
WebSiteSSLID int `json:"webSiteSSLId"`
|
||||||
|
RuntimeID int `json:"runtimeID"`
|
||||||
|
AppInstallID int `json:"appInstallId"`
|
||||||
|
FtpID int `json:"ftpId"`
|
||||||
|
User string `json:"user"`
|
||||||
|
Group string `json:"group"`
|
||||||
|
Domains interface{} `json:"domains"`
|
||||||
|
WebSiteSSL WebsiteSSL `json:"webSiteSSL"`
|
||||||
|
}
|
||||||
|
type WebsiteSSL struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
Pem string `json:"pem"`
|
||||||
|
Domains string `json:"domains"`
|
||||||
|
CertURL string `json:"certURL"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
DNSAccountID int `json:"dnsAccountId"`
|
||||||
|
AcmeAccountID int `json:"acmeAccountId"`
|
||||||
|
CaID int `json:"caId"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
ExpireDate time.Time `json:"expireDate"`
|
||||||
|
StartDate time.Time `json:"startDate"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
SkipDNS bool `json:"skipDNS"`
|
||||||
|
Nameserver1 string `json:"nameserver1"`
|
||||||
|
Nameserver2 string `json:"nameserver2"`
|
||||||
|
DisableCNAME bool `json:"disableCNAME"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
AcmeAccount AcmeAccount `json:"acmeAccount"`
|
||||||
|
DNSAccount DNSAccount `json:"dnsAccount"`
|
||||||
|
Websites interface{} `json:"websites"`
|
||||||
|
}
|
||||||
|
type AcmeAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
EabKid string `json:"eabKid"`
|
||||||
|
EabHmacKey string `json:"eabHmacKey"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
}
|
||||||
|
type DNSAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SSLDetail struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
Pem string `json:"pem"`
|
||||||
|
Domains string `json:"domains"`
|
||||||
|
CertURL string `json:"certURL"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
DNSAccountID int `json:"dnsAccountId"`
|
||||||
|
AcmeAccountID int `json:"acmeAccountId"`
|
||||||
|
CaID int `json:"caId"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
ExpireDate time.Time `json:"expireDate"`
|
||||||
|
StartDate time.Time `json:"startDate"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
SkipDNS bool `json:"skipDNS"`
|
||||||
|
Nameserver1 string `json:"nameserver1"`
|
||||||
|
Nameserver2 string `json:"nameserver2"`
|
||||||
|
DisableCNAME bool `json:"disableCNAME"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
AcmeAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
EabKid string `json:"eabKid"`
|
||||||
|
EabHmacKey string `json:"eabHmacKey"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
} `json:"acmeAccount"`
|
||||||
|
DNSAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
} `json:"dnsAccount"`
|
||||||
|
Websites interface{} `json:"websites"`
|
||||||
|
LogPath string `json:"logPath"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
@@ -0,0 +1,195 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
type SearchWebsiteRequest struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"pageSize"`
|
||||||
|
OrderBy string `json:"orderBy"`
|
||||||
|
Order string `json:"order"`
|
||||||
|
WebsiteGroupID int `json:"websiteGroupId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SearchWebsiteResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
Items []struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
Protocol string `json:"protocol"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Alias string `json:"alias"`
|
||||||
|
Remark string `json:"remark"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
ExpireDate time.Time `json:"expireDate"`
|
||||||
|
SitePath string `json:"sitePath"`
|
||||||
|
AppName string `json:"appName"`
|
||||||
|
RuntimeName string `json:"runtimeName"`
|
||||||
|
SslExpireDate time.Time `json:"sslExpireDate"`
|
||||||
|
SslStatus string `json:"sslStatus"`
|
||||||
|
AppInstallID int `json:"appInstallId"`
|
||||||
|
RuntimeType string `json:"runtimeType"`
|
||||||
|
} `json:"items"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type CreateWebsiteRequest struct {
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
Alias string `json:"alias,omitempty"`
|
||||||
|
Remark string `json:"remark,omitempty"`
|
||||||
|
AppType string `json:"appType,omitempty"`
|
||||||
|
WebSiteGroupID int64 `json:"webSiteGroupId,omitempty"`
|
||||||
|
OtherDomains string `json:"otherDomains,omitempty"`
|
||||||
|
Proxy string `json:"proxy,omitempty"`
|
||||||
|
Appinstall struct {
|
||||||
|
AppID int64 `json:"appId,omitempty"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
AppDetailID int64 `json:"appDetailId,omitempty"`
|
||||||
|
Params struct{} `json:"params,omitempty"`
|
||||||
|
Version string `json:"version,omitempty"`
|
||||||
|
Appkey string `json:"appkey,omitempty"`
|
||||||
|
Advanced bool `json:"advanced,omitempty"`
|
||||||
|
CPUQuota int64 `json:"cpuQuota,omitempty"`
|
||||||
|
MemoryLimit int64 `json:"memoryLimit,omitempty"`
|
||||||
|
MemoryUnit string `json:"memoryUnit,omitempty"`
|
||||||
|
ContainerName string `json:"containerName,omitempty"`
|
||||||
|
AllowPort bool `json:"allowPort,omitempty"`
|
||||||
|
} `json:"appinstall,omitempty"`
|
||||||
|
IPV6 bool `json:"IPV6,omitempty"`
|
||||||
|
EnableFtp bool `json:"enableFtp,omitempty"`
|
||||||
|
FtpUser string `json:"ftpUser,omitempty"`
|
||||||
|
FtpPassword string `json:"ftpPassword,omitempty"`
|
||||||
|
ProxyType string `json:"proxyType,omitempty"`
|
||||||
|
Port int64 `json:"port,omitempty"`
|
||||||
|
ProxyProtocol string `json:"proxyProtocol,omitempty"`
|
||||||
|
ProxyAddress string `json:"proxyAddress,omitempty"`
|
||||||
|
RuntimeType string `json:"runtimeType,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DeleteWebsiteRequest struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
DeleteApp bool `json:"deleteApp"`
|
||||||
|
DeleteBackup bool `json:"deleteBackup"`
|
||||||
|
ForceDelete bool `json:"forceDelete"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type GenericResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProxyWebsiteRequest struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProxyWebsiteResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data []ProxyDetail `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProxyDetail struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
Operate string `json:"operate"`
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
Cache bool `json:"cache"`
|
||||||
|
CacheTime int `json:"cacheTime"`
|
||||||
|
CacheUnit string `json:"cacheUnit"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Modifier string `json:"modifier"`
|
||||||
|
Match string `json:"match"`
|
||||||
|
ProxyPass string `json:"proxyPass"`
|
||||||
|
ProxyHost string `json:"proxyHost"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
FilePath string `json:"filePath"`
|
||||||
|
Replaces struct {
|
||||||
|
} `json:"replaces"`
|
||||||
|
Sni bool `json:"sni"`
|
||||||
|
ProxyProtocol string `json:"proxyProtocol"`
|
||||||
|
ProxyAddress string `json:"proxyAddress"`
|
||||||
|
}
|
||||||
|
type WebsiteHttpsRequest struct {
|
||||||
|
AcmeAccountID int `json:"acmeAccountID"`
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
WebsiteID int `json:"websiteId"`
|
||||||
|
WebsiteSSLID int `json:"websiteSSLId"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
ImportType string `json:"importType"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
Certificate string `json:"certificate"`
|
||||||
|
PrivateKeyPath string `json:"privateKeyPath"`
|
||||||
|
CertificatePath string `json:"certificatePath"`
|
||||||
|
HTTPConfig string `json:"httpConfig"`
|
||||||
|
Hsts bool `json:"hsts"`
|
||||||
|
Algorithm string `json:"algorithm"`
|
||||||
|
SSLProtocol []string `json:"SSLProtocol"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebsiteHttpsResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
HTTPConfig string `json:"httpConfig"`
|
||||||
|
SSL struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
PrimaryDomain string `json:"primaryDomain"`
|
||||||
|
PrivateKey string `json:"privateKey"`
|
||||||
|
Pem string `json:"pem"`
|
||||||
|
Domains string `json:"domains"`
|
||||||
|
CertURL string `json:"certURL"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Provider string `json:"provider"`
|
||||||
|
Organization string `json:"organization"`
|
||||||
|
DNSAccountID int `json:"dnsAccountId"`
|
||||||
|
AcmeAccountID int `json:"acmeAccountId"`
|
||||||
|
CaID int `json:"caId"`
|
||||||
|
AutoRenew bool `json:"autoRenew"`
|
||||||
|
ExpireDate time.Time `json:"expireDate"`
|
||||||
|
StartDate time.Time `json:"startDate"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
PushDir bool `json:"pushDir"`
|
||||||
|
Dir string `json:"dir"`
|
||||||
|
Description string `json:"description"`
|
||||||
|
SkipDNS bool `json:"skipDNS"`
|
||||||
|
Nameserver1 string `json:"nameserver1"`
|
||||||
|
Nameserver2 string `json:"nameserver2"`
|
||||||
|
DisableCNAME bool `json:"disableCNAME"`
|
||||||
|
ExecShell bool `json:"execShell"`
|
||||||
|
Shell string `json:"shell"`
|
||||||
|
AcmeAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
URL string `json:"url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
EabKid string `json:"eabKid"`
|
||||||
|
EabHmacKey string `json:"eabHmacKey"`
|
||||||
|
KeyType string `json:"keyType"`
|
||||||
|
} `json:"acmeAccount"`
|
||||||
|
DNSAccount struct {
|
||||||
|
ID int `json:"id"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
UpdatedAt time.Time `json:"updatedAt"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
} `json:"dnsAccount"`
|
||||||
|
Websites interface{} `json:"websites"`
|
||||||
|
} `json:"SSL"`
|
||||||
|
SSLProtocol []string `json:"SSLProtocol"`
|
||||||
|
Algorithm string `json:"algorithm"`
|
||||||
|
Hsts bool `json:"hsts"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
+7
-5
@@ -9,7 +9,6 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/KaySar12/NextZen-UserService/pkg/config"
|
|
||||||
"github.com/KaySar12/NextZen-UserService/service/model"
|
"github.com/KaySar12/NextZen-UserService/service/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -36,7 +35,8 @@ func (o *omvService) LoginSession(username string, password string) (string, []*
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
response, err := http.Post(config.AppInfo.OMVServer, "application/json", responseBody)
|
// response, err := http.Post(config.AppInfo.OMVServer, "application/json", responseBody)
|
||||||
|
response, err := http.Post("", "application/json", responseBody)
|
||||||
cookies := response.Cookies()
|
cookies := response.Cookies()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Print(err.Error())
|
fmt.Print(err.Error())
|
||||||
@@ -55,7 +55,8 @@ func (o *omvService) Logout(sessionID string) (string, error) {
|
|||||||
"params": nil,
|
"params": nil,
|
||||||
})
|
})
|
||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
req, err := http.NewRequest("POST", config.AppInfo.OMVServer, responseBody)
|
//req, err := http.NewRequest("POST", config.AppInfo.OMVServer, responseBody)
|
||||||
|
req, err := http.NewRequest("POST", "", responseBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error creating request: %v", err)
|
return "", fmt.Errorf("error creating request: %v", err)
|
||||||
}
|
}
|
||||||
@@ -89,7 +90,7 @@ func (o *omvService) AuthUser(username string, password string, sessionID string
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
req, err := http.NewRequest("POST", config.AppInfo.OMVServer, responseBody)
|
req, err := http.NewRequest("POST", "", responseBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error creating request: %v", err)
|
return "", fmt.Errorf("error creating request: %v", err)
|
||||||
}
|
}
|
||||||
@@ -125,7 +126,8 @@ func (o *omvService) GetUser(username string, sessionID string) (string, error)
|
|||||||
responseBody := bytes.NewBuffer(postBody)
|
responseBody := bytes.NewBuffer(postBody)
|
||||||
|
|
||||||
// Create HTTP request and set session ID header
|
// Create HTTP request and set session ID header
|
||||||
req, err := http.NewRequest("POST", config.AppInfo.OMVServer, responseBody)
|
// req, err := http.NewRequest("POST", config.AppInfo.OMVServer, responseBody)
|
||||||
|
req, err := http.NewRequest("POST", "", responseBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("error creating request: %v", err)
|
return "", fmt.Errorf("error creating request: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ type UserService interface {
|
|||||||
DeleteAllUser()
|
DeleteAllUser()
|
||||||
GetUserInfoByUserName(userName string) (m model.UserDBModel)
|
GetUserInfoByUserName(userName string) (m model.UserDBModel)
|
||||||
GetAllUserName() (list []model.UserDBModel)
|
GetAllUserName() (list []model.UserDBModel)
|
||||||
|
|
||||||
GetKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey)
|
GetKeyPair() (*ecdsa.PrivateKey, *ecdsa.PublicKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user