2021-09-26 02:35:02 +00:00
|
|
|
package route
|
|
|
|
|
|
|
|
import (
|
2022-10-20 06:25:26 +00:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/middleware"
|
|
|
|
"github.com/IceWhaleTech/CasaOS-Common/utils/jwt"
|
2021-09-27 06:17:36 +00:00
|
|
|
"github.com/IceWhaleTech/CasaOS/pkg/config"
|
|
|
|
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
|
2022-06-29 03:09:58 +00:00
|
|
|
|
2022-01-28 07:34:32 +00:00
|
|
|
"github.com/gin-contrib/gzip"
|
2021-09-26 02:35:02 +00:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2021-10-22 08:49:09 +00:00
|
|
|
func InitRouter() *gin.Engine {
|
2022-10-20 06:25:26 +00:00
|
|
|
ginMode := gin.ReleaseMode
|
|
|
|
if config.ServerInfo.RunMode != "" {
|
|
|
|
ginMode = config.ServerInfo.RunMode
|
|
|
|
}
|
|
|
|
if os.Getenv(gin.EnvGinMode) != "" {
|
|
|
|
ginMode = os.Getenv(gin.EnvGinMode)
|
|
|
|
}
|
|
|
|
gin.SetMode(ginMode)
|
2021-09-26 02:35:02 +00:00
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
r := gin.New()
|
|
|
|
r.Use(gin.Recovery())
|
2021-09-26 02:35:02 +00:00
|
|
|
r.Use(middleware.Cors())
|
2022-01-28 07:34:32 +00:00
|
|
|
r.Use(gzip.Gzip(gzip.DefaultCompression))
|
2022-10-20 06:25:26 +00:00
|
|
|
if ginMode != gin.ReleaseMode {
|
|
|
|
r.Use(middleware.WriteLog())
|
|
|
|
}
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-09-06 06:28:49 +00:00
|
|
|
// r.StaticFS("/ui", http.FS(web.Static))
|
|
|
|
// r.GET("/", WebUIHome)
|
2022-06-29 03:09:58 +00:00
|
|
|
// r.StaticFS("/assets", http.Dir("./static/assets"))
|
|
|
|
// r.StaticFile("/favicon.ico", "./static/favicon.ico")
|
2021-09-27 06:17:36 +00:00
|
|
|
//r.GET("/", func(c *gin.Context) {
|
|
|
|
// c.Redirect(http.StatusMovedPermanently, "ui/")
|
|
|
|
//})
|
2021-09-26 02:35:02 +00:00
|
|
|
|
2022-09-06 06:28:49 +00:00
|
|
|
// r.POST("/v1/users/register", v1.PostUserRegister)
|
|
|
|
// r.POST("/v1/users/login", v1.PostUserLogin)
|
|
|
|
// r.GET("/v1/users/name", v1.GetUserAllUsername) //all/name
|
|
|
|
// r.POST("/v1/users/refresh", v1.PostUserRefreshToken)
|
|
|
|
// // No short-term modifications
|
|
|
|
// r.GET("/v1/users/image", v1.GetUserImage)
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-09-06 06:28:49 +00:00
|
|
|
// r.GET("/v1/users/status", v1.GetUserStatus) //init/check
|
2022-10-20 06:25:26 +00:00
|
|
|
// r.GET("/v1/guide/check", v1.GetGuideCheck) // /v1/sys/guide_check
|
2022-07-22 03:02:11 +00:00
|
|
|
r.GET("/v1/sys/debug", v1.GetSystemConfigDebug) // //debug
|
|
|
|
|
|
|
|
r.GET("/v1/sys/socket-port", v1.GetSystemSocketPort) //sys/socket_port
|
2022-07-29 08:23:53 +00:00
|
|
|
r.GET("/v1/sys/version/check", v1.GetSystemCheckVersion)
|
2022-10-20 06:25:26 +00:00
|
|
|
r.GET("/ping", func(ctx *gin.Context) {
|
|
|
|
ctx.String(200, "pong")
|
|
|
|
})
|
2021-09-26 02:35:02 +00:00
|
|
|
v1Group := r.Group("/v1")
|
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
v1Group.Use(jwt.ExceptLocalhost())
|
2021-09-26 02:35:02 +00:00
|
|
|
{
|
2022-09-06 06:28:49 +00:00
|
|
|
// v1UsersGroup := v1Group.Group("/users")
|
|
|
|
// v1UsersGroup.Use()
|
|
|
|
// {
|
|
|
|
// v1UsersGroup.GET("/current", v1.GetUserInfo)
|
|
|
|
// v1UsersGroup.PUT("/current", v1.PutUserInfo)
|
|
|
|
// v1UsersGroup.PUT("/current/password", v1.PutUserPassword)
|
|
|
|
|
|
|
|
// v1UsersGroup.GET("/current/custom/:key", v1.GetUserCustomConf)
|
|
|
|
// v1UsersGroup.POST("/current/custom/:key", v1.PostUserCustomConf)
|
|
|
|
// v1UsersGroup.DELETE("/current/custom/:key", v1.DeleteUserCustomConf)
|
|
|
|
|
|
|
|
// v1UsersGroup.POST("/current/image/:key", v1.PostUserUploadImage)
|
|
|
|
// v1UsersGroup.PUT("/current/image/:key", v1.PutUserImage)
|
|
|
|
// //v1UserGroup.POST("/file/image/:key", v1.PostUserFileImage)
|
|
|
|
// v1UsersGroup.DELETE("/current/image", v1.DeleteUserImage)
|
|
|
|
|
|
|
|
// //v1UserGroup.PUT("/avatar", v1.PutUserAvatar)
|
|
|
|
// //v1UserGroup.GET("/avatar", v1.GetUserAvatar)
|
|
|
|
// v1UsersGroup.DELETE("/:id", v1.DeleteUser)
|
|
|
|
// v1UsersGroup.GET("/:username", v1.GetUserInfoByUsername)
|
|
|
|
// v1UsersGroup.DELETE("", v1.DeleteUserAll)
|
|
|
|
// }
|
2021-10-22 08:49:09 +00:00
|
|
|
|
2022-07-22 03:02:11 +00:00
|
|
|
v1AppsGroup := v1Group.Group("/apps")
|
|
|
|
v1AppsGroup.Use()
|
|
|
|
{
|
2022-10-20 06:25:26 +00:00
|
|
|
v1AppsGroup.GET("", v1.AppList) // list
|
2022-07-22 03:02:11 +00:00
|
|
|
v1AppsGroup.GET("/:id", v1.AppInfo)
|
|
|
|
}
|
|
|
|
v1ContainerGroup := v1Group.Group("/container")
|
|
|
|
v1ContainerGroup.Use()
|
|
|
|
{
|
2022-10-20 06:25:26 +00:00
|
|
|
|
2022-07-22 03:02:11 +00:00
|
|
|
v1ContainerGroup.GET("", v1.MyAppList) ///my/list
|
|
|
|
v1ContainerGroup.GET("/usage", v1.AppUsageList)
|
|
|
|
v1ContainerGroup.GET("/:id", v1.ContainerUpdateInfo) ///update/:id/info
|
|
|
|
v1ContainerGroup.GET("/:id/logs", v1.ContainerLog) // /app/logs/:id
|
2022-10-20 06:25:26 +00:00
|
|
|
v1ContainerGroup.GET("/networks", v1.GetDockerNetworks) // app/install/config
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
v1ContainerGroup.GET("/:id/state", v1.GetContainerState) // app/state/:id ?state=install_progress
|
2022-07-22 03:02:11 +00:00
|
|
|
// there are problems, temporarily do not deal with
|
2022-10-20 06:25:26 +00:00
|
|
|
v1ContainerGroup.GET("/:id/terminal", v1.DockerTerminal) // app/terminal/:id
|
|
|
|
v1ContainerGroup.POST("", v1.InstallApp) // app/install
|
|
|
|
// v1ContainerGroup.GET("/:id", v1.ContainerInfo) // /app/info/:id
|
2022-07-22 03:02:11 +00:00
|
|
|
|
|
|
|
v1ContainerGroup.PUT("/:id", v1.UpdateSetting) ///update/:id/setting
|
|
|
|
|
|
|
|
v1ContainerGroup.PUT("/:id/state", v1.ChangAppState) // /app/state/:id
|
2022-10-20 06:25:26 +00:00
|
|
|
v1ContainerGroup.DELETE("/:id", v1.UnInstallApp) // app/uninstall/:id
|
|
|
|
// Not used
|
2022-07-22 03:02:11 +00:00
|
|
|
v1ContainerGroup.PUT("/:id/latest", v1.PutAppUpdate)
|
2022-10-20 06:25:26 +00:00
|
|
|
// Not used
|
2022-07-22 03:02:11 +00:00
|
|
|
v1ContainerGroup.POST("/share", v1.ShareAppFile)
|
2022-10-20 06:25:26 +00:00
|
|
|
v1ContainerGroup.GET("/info", v1.GetDockerDaemonConfiguration)
|
|
|
|
v1ContainerGroup.PUT("/info", v1.PutDockerDaemonConfiguration)
|
2021-10-27 09:27:46 +00:00
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2022-07-22 03:02:11 +00:00
|
|
|
v1AppCategoriesGroup := v1Group.Group("/app-categories")
|
|
|
|
v1AppCategoriesGroup.Use()
|
2021-09-26 02:35:02 +00:00
|
|
|
{
|
2022-07-22 03:02:11 +00:00
|
|
|
v1AppCategoriesGroup.GET("", v1.CategoryList)
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
v1SysGroup := v1Group.Group("/sys")
|
|
|
|
v1SysGroup.Use()
|
|
|
|
{
|
2022-10-20 06:25:26 +00:00
|
|
|
v1SysGroup.GET("/version", v1.GetSystemCheckVersion) // version/check
|
2022-07-29 08:23:53 +00:00
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
v1SysGroup.POST("/update", v1.SystemUpdate)
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
v1SysGroup.GET("/hardware", v1.GetSystemHardwareInfo) // hardware/info
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
v1SysGroup.GET("/wsssh", v1.WsSsh)
|
2022-07-22 03:02:11 +00:00
|
|
|
v1SysGroup.POST("/ssh-login", v1.PostSshLogin)
|
2022-10-20 06:25:26 +00:00
|
|
|
// v1SysGroup.GET("/config", v1.GetSystemConfig) //delete
|
|
|
|
// v1SysGroup.POST("/config", v1.PostSetSystemConfig)
|
|
|
|
v1SysGroup.GET("/logs", v1.GetCasaOSErrorLogs) // error/logs
|
|
|
|
// v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)//delete
|
|
|
|
// v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)//delete
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-06-13 12:43:19 +00:00
|
|
|
v1SysGroup.POST("/stop", v1.PostKillCasaOS)
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-06-13 12:43:19 +00:00
|
|
|
v1SysGroup.GET("/utilization", v1.GetSystemUtilization)
|
2022-07-22 03:02:11 +00:00
|
|
|
// v1SysGroup.GET("/cpu", v1.GetSystemCupInfo)
|
|
|
|
// v1SysGroup.GET("/mem", v1.GetSystemMemInfo)
|
|
|
|
// v1SysGroup.GET("/disk", v1.GetSystemDiskInfo)
|
|
|
|
// v1SysGroup.GET("/network", v1.GetSystemNetInfo)
|
|
|
|
|
|
|
|
v1SysGroup.GET("/server-info", nil)
|
|
|
|
v1SysGroup.PUT("/server-info", nil)
|
|
|
|
v1SysGroup.GET("/apps-state", v1.GetSystemAppsStatus)
|
2022-10-20 06:25:26 +00:00
|
|
|
// v1SysGroup.GET("/port", v1.GetCasaOSPort)
|
|
|
|
// v1SysGroup.PUT("/port", v1.PutCasaOSPort)
|
2022-09-06 06:28:49 +00:00
|
|
|
v1SysGroup.GET("/proxy", v1.GetSystemProxy)
|
2022-07-22 03:02:11 +00:00
|
|
|
}
|
|
|
|
v1PortGroup := v1Group.Group("/port")
|
|
|
|
v1PortGroup.Use()
|
|
|
|
{
|
2022-10-20 06:25:26 +00:00
|
|
|
v1PortGroup.GET("/", v1.GetPort) // app/port
|
|
|
|
v1PortGroup.GET("/state/:port", v1.PortCheck) // app/check/:port
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2021-09-26 02:35:02 +00:00
|
|
|
v1FileGroup := v1Group.Group("/file")
|
|
|
|
v1FileGroup.Use()
|
|
|
|
{
|
2022-10-20 06:25:26 +00:00
|
|
|
v1FileGroup.GET("", v1.GetDownloadSingleFile) // download/:path
|
2022-07-22 03:02:11 +00:00
|
|
|
v1FileGroup.POST("", v1.PostCreateFile)
|
|
|
|
v1FileGroup.PUT("", v1.PutFileContent)
|
|
|
|
v1FileGroup.PUT("/name", v1.RenamePath)
|
2022-10-20 06:25:26 +00:00
|
|
|
// file/rename
|
|
|
|
v1FileGroup.GET("/content", v1.GetFilerContent) // file/read
|
2022-07-22 03:02:11 +00:00
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
// File uploads need to be handled separately, and will not be modified here
|
2021-09-26 02:35:02 +00:00
|
|
|
v1FileGroup.POST("/upload", v1.PostFileUpload)
|
2022-03-09 08:37:03 +00:00
|
|
|
v1FileGroup.GET("/upload", v1.GetFileUpload)
|
2022-10-20 06:25:26 +00:00
|
|
|
// v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
2022-07-22 03:02:11 +00:00
|
|
|
v1FolderGroup := v1Group.Group("/folder")
|
|
|
|
v1FolderGroup.Use()
|
|
|
|
{
|
|
|
|
v1FolderGroup.PUT("/name", v1.RenamePath)
|
|
|
|
v1FolderGroup.GET("", v1.DirPath) ///file/dirpath
|
|
|
|
v1FolderGroup.POST("", v1.MkdirAll) ///file/mkdir
|
|
|
|
}
|
|
|
|
v1BatchGroup := v1Group.Group("/batch")
|
|
|
|
v1BatchGroup.Use()
|
2021-09-26 02:35:02 +00:00
|
|
|
{
|
|
|
|
|
2022-10-20 06:25:26 +00:00
|
|
|
v1BatchGroup.DELETE("", v1.DeleteFile) // file/delete
|
2022-07-22 03:02:11 +00:00
|
|
|
v1BatchGroup.DELETE("/:id/task", v1.DeleteOperateFileOrDir)
|
2022-10-20 06:25:26 +00:00
|
|
|
v1BatchGroup.POST("/task", v1.PostOperateFileOrDir) // file/operate
|
2022-07-22 03:02:11 +00:00
|
|
|
v1BatchGroup.GET("", v1.GetDownloadFile)
|
|
|
|
}
|
|
|
|
v1ImageGroup := v1Group.Group("/image")
|
|
|
|
v1ImageGroup.Use()
|
|
|
|
{
|
|
|
|
v1ImageGroup.GET("", v1.GetFileImage)
|
|
|
|
}
|
2022-08-15 03:37:21 +00:00
|
|
|
v1SambaGroup := v1Group.Group("/samba")
|
|
|
|
v1SambaGroup.Use()
|
|
|
|
{
|
|
|
|
v1ConnectionsGroup := v1SambaGroup.Group("/connections")
|
|
|
|
v1ConnectionsGroup.Use()
|
|
|
|
{
|
|
|
|
v1ConnectionsGroup.GET("", v1.GetSambaConnectionsList)
|
|
|
|
v1ConnectionsGroup.POST("", v1.PostSambaConnectionsCreate)
|
|
|
|
v1ConnectionsGroup.DELETE("/:id", v1.DeleteSambaConnections)
|
|
|
|
}
|
|
|
|
v1SharesGroup := v1SambaGroup.Group("/shares")
|
|
|
|
v1SharesGroup.Use()
|
|
|
|
{
|
|
|
|
v1SharesGroup.GET("", v1.GetSambaSharesList)
|
|
|
|
v1SharesGroup.POST("", v1.PostSambaSharesCreate)
|
|
|
|
v1SharesGroup.DELETE("/:id", v1.DeleteSambaShares)
|
|
|
|
v1SharesGroup.GET("/status", v1.GetSambaStatus)
|
|
|
|
}
|
2022-03-09 08:37:03 +00:00
|
|
|
}
|
2022-10-20 06:25:26 +00:00
|
|
|
v1NotifyGroup := v1Group.Group("/notify")
|
|
|
|
v1NotifyGroup.Use()
|
|
|
|
{
|
|
|
|
v1NotifyGroup.POST("/:path", v1.PostNotifyMessage)
|
|
|
|
// merge to system
|
|
|
|
v1NotifyGroup.POST("/system_status", v1.PostSystemStatusNotify)
|
|
|
|
}
|
2021-09-26 02:35:02 +00:00
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|