mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
Fix .js mime issues in windows
This commit is contained in:
parent
08b54b5bbb
commit
8a7f7672d9
7 changed files with 149 additions and 97 deletions
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="footer center">
|
<div class="footer center">
|
||||||
Copyright © 2020 - {{ thisYear }} 0xJacky
|
Copyright © 2020 - {{ thisYear }} Nginx UI
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
<p>Yet another WebUI for Nginx</p>
|
<p>Yet another WebUI for Nginx</p>
|
||||||
<p>Version: {{ version }} ({{ build_id }})</p>
|
<p>Version: {{ version }} ({{ build_id }})</p>
|
||||||
<h3>项目组</h3>
|
<h3>项目组</h3>
|
||||||
<p>Designer:<a href="https://jackyu.cn/">@0xJacky</a></p>
|
<p><a href="https://jackyu.cn/">@0xJacky</a></p>
|
||||||
|
<p><a href="https://blog.kugeek.com/">@Hintay</a></p>
|
||||||
<h3>技术栈</h3>
|
<h3>技术栈</h3>
|
||||||
<p>Go</p>
|
<p>Go</p>
|
||||||
<p>Gin</p>
|
<p>Gin</p>
|
||||||
|
@ -15,7 +16,7 @@
|
||||||
<p>Websocket</p>
|
<p>Websocket</p>
|
||||||
<h3>开源协议</h3>
|
<h3>开源协议</h3>
|
||||||
<p>GNU General Public License v2.0</p>
|
<p>GNU General Public License v2.0</p>
|
||||||
<p>Copyright © 2020 - {{ this_year }} 0xJacky </p>
|
<p>Copyright © 2020 - {{ this_year }} Nginx UI </p>
|
||||||
</a-card>
|
</a-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":"1.1.0","build_id":4,"total_build":21}
|
{"version":"1.1.0","build_id":5,"total_build":22}
|
27
go.mod
27
go.mod
|
@ -1,6 +1,6 @@
|
||||||
module github.com/0xJacky/Nginx-UI
|
module github.com/0xJacky/Nginx-UI
|
||||||
|
|
||||||
go 1.16
|
go 1.17
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
github.com/dgrijalva/jwt-go v3.2.0+incompatible
|
||||||
|
@ -21,3 +21,28 @@ require (
|
||||||
gorm.io/driver/sqlite v1.1.4
|
gorm.io/driver/sqlite v1.1.4
|
||||||
gorm.io/gorm v1.21.14
|
gorm.io/gorm v1.21.14
|
||||||
)
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/StackExchange/wmi v1.2.1 // indirect
|
||||||
|
github.com/cenkalti/backoff/v4 v4.1.0 // indirect
|
||||||
|
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||||
|
github.com/go-ole/go-ole v1.2.5 // indirect
|
||||||
|
github.com/golang/protobuf v1.3.4 // indirect
|
||||||
|
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||||
|
github.com/jinzhu/now v1.1.2 // indirect
|
||||||
|
github.com/json-iterator/go v1.1.9 // indirect
|
||||||
|
github.com/leodido/go-urn v1.2.0 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.12 // indirect
|
||||||
|
github.com/mattn/go-sqlite3 v1.14.5 // indirect
|
||||||
|
github.com/miekg/dns v1.1.40 // indirect
|
||||||
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
|
github.com/modern-go/reflect2 v1.0.1 // indirect
|
||||||
|
github.com/tklauser/go-sysconf v0.3.7 // indirect
|
||||||
|
github.com/tklauser/numcpus v0.2.3 // indirect
|
||||||
|
github.com/ugorji/go/codec v1.1.7 // indirect
|
||||||
|
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect
|
||||||
|
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect
|
||||||
|
golang.org/x/text v0.3.4 // indirect
|
||||||
|
gopkg.in/square/go-jose.v2 v2.5.1 // indirect
|
||||||
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
|
)
|
||||||
|
|
84
server/router/middleware.go
Normal file
84
server/router/middleware.go
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
"github.com/0xJacky/Nginx-UI/frontend"
|
||||||
|
"github.com/0xJacky/Nginx-UI/server/model"
|
||||||
|
"github.com/gin-contrib/static"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"io/fs"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"path"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func authRequired() gin.HandlerFunc {
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
token := c.GetHeader("Authorization")
|
||||||
|
if token == "" {
|
||||||
|
tmp, _ := base64.StdEncoding.DecodeString(c.Query("token"))
|
||||||
|
token = string(tmp)
|
||||||
|
if token == "" {
|
||||||
|
c.JSON(http.StatusForbidden, gin.H{
|
||||||
|
"message": "auth fail",
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
n := model.CheckToken(token)
|
||||||
|
|
||||||
|
if n < 1 {
|
||||||
|
c.JSON(http.StatusForbidden, gin.H{
|
||||||
|
"message": "auth fail",
|
||||||
|
})
|
||||||
|
c.Abort()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type serverFileSystemType struct {
|
||||||
|
http.FileSystem
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f serverFileSystemType) Exists(prefix string, _path string) bool {
|
||||||
|
_, err := f.Open(path.Join(prefix, _path))
|
||||||
|
return err == nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustFS(dir string) (serverFileSystem static.ServeFileSystem) {
|
||||||
|
|
||||||
|
sub, err := fs.Sub(frontend.DistFS, path.Join("dist", dir))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
serverFileSystem = serverFileSystemType{
|
||||||
|
http.FS(sub),
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// tryStatic Static returns a middleware handler that serves static files in the given directory.
|
||||||
|
func tryStatic(urlPrefix string, fs static.ServeFileSystem) gin.HandlerFunc {
|
||||||
|
fileserver := http.FileServer(fs)
|
||||||
|
if urlPrefix != "" {
|
||||||
|
fileserver = http.StripPrefix(urlPrefix, fileserver)
|
||||||
|
}
|
||||||
|
return func(c *gin.Context) {
|
||||||
|
if fs.Exists(urlPrefix, c.Request.URL.Path) {
|
||||||
|
fileserver.ServeHTTP(c.Writer, c.Request)
|
||||||
|
if strings.Contains(c.Request.URL.Path, ".js") {
|
||||||
|
c.Writer.Header().Set("content-type", "application/javascript")
|
||||||
|
}
|
||||||
|
c.Abort()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,78 +2,19 @@ package router
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/base64"
|
|
||||||
"github.com/0xJacky/Nginx-UI/frontend"
|
|
||||||
api2 "github.com/0xJacky/Nginx-UI/server/api"
|
api2 "github.com/0xJacky/Nginx-UI/server/api"
|
||||||
"github.com/0xJacky/Nginx-UI/server/model"
|
|
||||||
"github.com/gin-contrib/static"
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"io/fs"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func authRequired() gin.HandlerFunc {
|
|
||||||
return func(c *gin.Context) {
|
|
||||||
token := c.GetHeader("Authorization")
|
|
||||||
if token == "" {
|
|
||||||
tmp, _ := base64.StdEncoding.DecodeString(c.Query("token"))
|
|
||||||
token = string(tmp)
|
|
||||||
if token == "" {
|
|
||||||
c.JSON(http.StatusForbidden, gin.H{
|
|
||||||
"message": "auth fail",
|
|
||||||
})
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
n := model.CheckToken(token)
|
|
||||||
|
|
||||||
if n < 1 {
|
|
||||||
c.JSON(http.StatusForbidden, gin.H{
|
|
||||||
"message": "auth fail",
|
|
||||||
})
|
|
||||||
c.Abort()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
c.Next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type serverFileSystemType struct {
|
|
||||||
http.FileSystem
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f serverFileSystemType) Exists(prefix string, path string) bool {
|
|
||||||
_, err := f.Open(filepath.Join(prefix, path))
|
|
||||||
return err == nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func mustFS(dir string) (serverFileSystem static.ServeFileSystem) {
|
|
||||||
|
|
||||||
sub, err := fs.Sub(frontend.DistFS, filepath.Join("dist", dir))
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Println(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
serverFileSystem = serverFileSystemType{
|
|
||||||
http.FS(sub),
|
|
||||||
}
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func InitRouter() *gin.Engine {
|
func InitRouter() *gin.Engine {
|
||||||
r := gin.New()
|
r := gin.New()
|
||||||
r.Use(gin.Logger())
|
r.Use(gin.Logger())
|
||||||
|
|
||||||
r.Use(gin.Recovery())
|
r.Use(gin.Recovery())
|
||||||
|
|
||||||
r.Use(static.Serve("/", mustFS("")))
|
r.Use(tryStatic("/", mustFS("")))
|
||||||
|
|
||||||
r.NoRoute(func(c *gin.Context) {
|
r.NoRoute(func(c *gin.Context) {
|
||||||
accept := c.Request.Header.Get("Accept")
|
accept := c.Request.Header.Get("Accept")
|
||||||
|
|
|
@ -1,52 +1,53 @@
|
||||||
package tool
|
package tool
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNginxConf(filePath string) error {
|
func TestNginxConf(filePath string) error {
|
||||||
out, err := exec.Command("nginx", "-t").CombinedOutput()
|
out, err := exec.Command("nginx", "-t").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
output := string(out)
|
output := string(out)
|
||||||
log.Println(output)
|
log.Println(output)
|
||||||
if strings.Contains(output, "failed") {
|
if strings.Contains(output, "failed") {
|
||||||
return errors.New(output)
|
return errors.New(output)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReloadNginx() string {
|
func ReloadNginx() string {
|
||||||
out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
|
out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
output := string(out)
|
output := string(out)
|
||||||
log.Println(output)
|
log.Println(output)
|
||||||
|
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetNginxConfPath(dir string) string {
|
func GetNginxConfPath(dir string) string {
|
||||||
out, err := exec.Command("nginx", "-V").CombinedOutput()
|
out, err := exec.Command("nginx", "-V").CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Println(err)
|
||||||
}
|
return ""
|
||||||
// fmt.Printf("%s\n", out)
|
}
|
||||||
|
// fmt.Printf("%s\n", out)
|
||||||
|
|
||||||
r, _ := regexp.Compile("--conf-path=(.*)/(.*.conf)")
|
r, _ := regexp.Compile("--conf-path=(.*)/(.*.conf)")
|
||||||
|
|
||||||
confPath := r.FindStringSubmatch(string(out))[1]
|
confPath := r.FindStringSubmatch(string(out))[1]
|
||||||
|
|
||||||
// fmt.Println(confPath)
|
// fmt.Println(confPath)
|
||||||
|
|
||||||
return filepath.Join(confPath, dir)
|
return filepath.Join(confPath, dir)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue