mirror of
https://github.com/KaySar12/NextZen-UserService.git
synced 2025-06-27 19:35:10 +07:00
update code : add Default App initialize
This commit is contained in:
parent
79a4456a73
commit
b2ddd6f395
@ -11,12 +11,21 @@ UserDataPath = /var/lib/casaos
|
|||||||
[oidc]
|
[oidc]
|
||||||
AuthServer = https://account.nextzenvn.com
|
AuthServer = https://account.nextzenvn.com
|
||||||
ClientID = WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz
|
ClientID = WzN5QB9e0LfCSAYTB542RLpIGKcAWNNZgVbeTLaz
|
||||||
ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fPi6B9IFe3aDBo8x
|
ClientSecret = D1mbEz1VHkPnhvMGPfj5aAmjOuZ1ZIYGm7qAReMCivdXwiQ60BJoa4cpdX5m9Z5aKgtR8d56xgmYAy7TR86MEV6zJXfjxy2lf0TTAPXc8ftEcst8fP
|
||||||
|
i6B9IFe3aDBo8x
|
||||||
AuthURL = https://account.nextzenvn.com/application/o/nextzenos/
|
AuthURL = https://account.nextzenvn.com/application/o/nextzenos/
|
||||||
CallbackURL = https://home.nextzenvn.com/v1/users/oidc/callback
|
CallbackURL = https://home.nextzenvn.com/v1/users/oidc/callback
|
||||||
|
|
||||||
[nextweb]
|
[nextweb]
|
||||||
Server = https://127.0.0.1:10086
|
Server = http://127.0.0.1:10086
|
||||||
UserName = nextzen
|
UserName = nextzen
|
||||||
Password = Smartyourlife123@*
|
Password = Smartyourlife123@*
|
||||||
EntranceCode =
|
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
|
26
main.go
26
main.go
@ -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,7 +125,19 @@ 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",
|
"/v1/1panel",
|
||||||
@ -130,6 +145,7 @@ func main() {
|
|||||||
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,
|
||||||
@ -184,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,6 +26,18 @@ type NextWebModel struct {
|
|||||||
Password string
|
Password string
|
||||||
EntranceCode 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"`
|
||||||
|
@ -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"
|
||||||
@ -37,7 +38,9 @@ var (
|
|||||||
Password: "",
|
Password: "",
|
||||||
EntranceCode: "",
|
EntranceCode: "",
|
||||||
}
|
}
|
||||||
|
DefaultAppInfo = &model.DefaultModel{
|
||||||
|
Apps: map[string]model.AppInfo{},
|
||||||
|
}
|
||||||
Cfg *ini.File
|
Cfg *ini.File
|
||||||
ConfigFilePath string
|
ConfigFilePath string
|
||||||
)
|
)
|
||||||
@ -77,9 +80,33 @@ func InitSetup(config string, sample string) {
|
|||||||
mapTo("nextweb", NextWebInfo)
|
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)
|
||||||
|
@ -1581,7 +1581,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 {
|
||||||
@ -1589,14 +1588,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))})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1619,8 +1627,20 @@ func PostUserCustomConf(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
data, _ := io.ReadAll(c.Request.Body)
|
data, _ := io.ReadAll(c.Request.Body)
|
||||||
|
if name == "default-app" {
|
||||||
|
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)})
|
||||||
@ -1632,7 +1652,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)
|
||||||
|
Loading…
Reference in New Issue
Block a user