Skip to content

Commit 2649b71

Browse files
committed
feat: introducing streams management pages #166
1 parent 9c16b55 commit 2649b71

File tree

32 files changed

+3170
-606
lines changed

32 files changed

+3170
-606
lines changed

api/sites/domain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ func GetDomain(c *gin.Context) {
147147
c.Set("maybe_error", "")
148148

149149
certInfoMap := make(map[int]*cert.Info)
150-
for serverIdx, server := range nginxConfig.Servers {
150+
151+
for serverIdx, server := range nginxConfig.Servers {
151152
for _, directive := range server.Directives {
152153
if directive.Directive == "ssl_certificate" {
153154

api/streams/advance.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package streams
2+
3+
import (
4+
"github.com/0xJacky/Nginx-UI/api"
5+
"github.com/0xJacky/Nginx-UI/internal/nginx"
6+
"github.com/0xJacky/Nginx-UI/query"
7+
"github.com/gin-gonic/gin"
8+
"net/http"
9+
)
10+
11+
func AdvancedEdit(c *gin.Context) {
12+
var json struct {
13+
Advanced bool `json:"advanced"`
14+
}
15+
16+
if !api.BindAndValid(c, &json) {
17+
return
18+
}
19+
20+
name := c.Param("name")
21+
path := nginx.GetConfPath("streams-available", name)
22+
23+
s := query.Site
24+
25+
_, err := s.Where(s.Path.Eq(path)).FirstOrCreate()
26+
if err != nil {
27+
api.ErrHandler(c, err)
28+
return
29+
}
30+
31+
_, err = s.Where(s.Path.Eq(path)).Update(s.Advanced, json.Advanced)
32+
33+
if err != nil {
34+
api.ErrHandler(c, err)
35+
return
36+
}
37+
38+
c.JSON(http.StatusOK, gin.H{
39+
"message": "ok",
40+
})
41+
42+
}

api/streams/duplicate.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package streams
2+
3+
import (
4+
"github.com/0xJacky/Nginx-UI/api"
5+
"github.com/0xJacky/Nginx-UI/internal/helper"
6+
"github.com/0xJacky/Nginx-UI/internal/nginx"
7+
"github.com/gin-gonic/gin"
8+
"net/http"
9+
)
10+
11+
func Duplicate(c *gin.Context) {
12+
// Source name
13+
name := c.Param("name")
14+
15+
// Destination name
16+
var json struct {
17+
Name string `json:"name" binding:"required"`
18+
}
19+
20+
if !api.BindAndValid(c, &json) {
21+
return
22+
}
23+
24+
src := nginx.GetConfPath("streams-available", name)
25+
dst := nginx.GetConfPath("streams-available", json.Name)
26+
27+
if helper.FileExists(dst) {
28+
c.JSON(http.StatusNotAcceptable, gin.H{
29+
"message": "File exists",
30+
})
31+
return
32+
}
33+
34+
_, err := helper.CopyFile(src, dst)
35+
36+
if err != nil {
37+
api.ErrHandler(c, err)
38+
return
39+
}
40+
41+
c.JSON(http.StatusOK, gin.H{
42+
"dst": dst,
43+
})
44+
}

api/streams/router.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package streams
2+
3+
import "github.com/gin-gonic/gin"
4+
5+
func InitRouter(r *gin.RouterGroup) {
6+
r.GET("streams", GetStreams)
7+
r.GET("stream/:name", GetStream)
8+
r.POST("stream/:name", SaveStream)
9+
r.POST("stream/:name/enable", EnableStream)
10+
r.POST("stream/:name/disable", DisableStream)
11+
r.POST("stream/:name/advance", AdvancedEdit)
12+
r.DELETE("stream/:name", DeleteStream)
13+
r.POST("stream/:name/duplicate", Duplicate)
14+
}

0 commit comments

Comments
 (0)