mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-12 19:05:55 +02:00
enhance: error handler for execShell
This commit is contained in:
parent
08bfa6b221
commit
831e90b14b
12 changed files with 3755 additions and 106 deletions
|
@ -45,11 +45,13 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^4.5.0",
|
"@vitejs/plugin-vue": "^4.5.0",
|
||||||
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
"@vitejs/plugin-vue-jsx": "^3.1.0",
|
||||||
|
"@vue-macros/volar": "^0.17.4",
|
||||||
"@vue/compiler-sfc": "^3.3.9",
|
"@vue/compiler-sfc": "^3.3.9",
|
||||||
"ace-builds": "^1.31.2",
|
"ace-builds": "^1.31.2",
|
||||||
"less": "^4.2.0",
|
"less": "^4.2.0",
|
||||||
"typescript": "^5.3.2",
|
"typescript": "^5.3.2",
|
||||||
"unplugin-vue-components": "^0.25.2",
|
"unplugin-vue-components": "^0.25.2",
|
||||||
|
"unplugin-vue-macros": "^2.7.0",
|
||||||
"vite": "^5.0.2",
|
"vite": "^5.0.2",
|
||||||
"vite-plugin-html": "^3.2.0",
|
"vite-plugin-html": "^3.2.0",
|
||||||
"vite-svg-loader": "^5.1.0",
|
"vite-svg-loader": "^5.1.0",
|
||||||
|
|
3682
frontend/pnpm-lock.yaml
generated
Normal file
3682
frontend/pnpm-lock.yaml
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -120,16 +120,12 @@ const callback = () => {
|
||||||
}
|
}
|
||||||
instance?.updateOptions?.(chartOptions)
|
instance?.updateOptions?.(chartOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
watch(theme, callback)
|
watch(theme, callback)
|
||||||
// watch(series, () => {
|
|
||||||
// instance?.updateSeries(series)
|
|
||||||
// })
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<VueApexCharts type="area" height="200" :options="chartOptions" :series="series" ref="chart"/>
|
<!-- Use theme as key to rerender the chart when theme changes to prevent style issues -->
|
||||||
|
<VueApexCharts :key="theme" type="area" height="200" :options="chartOptions" :series="series" ref="chart"/>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -48,6 +48,7 @@
|
||||||
border: 1px solid var(--vp-input-border-color);
|
border: 1px solid var(--vp-input-border-color);
|
||||||
background-color: var(--vp-input-switch-bg-color);
|
background-color: var(--vp-input-switch-bg-color);
|
||||||
transition: border-color 0.25s !important;
|
transition: border-color 0.25s !important;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.VPSwitch:hover {
|
.VPSwitch:hover {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":"2.0.0-beta.4","build_id":25,"total_build":229}
|
{"version":"2.0.0-beta.4","build_id":30,"total_build":234}
|
|
@ -20,6 +20,27 @@
|
||||||
"@/*": [
|
"@/*": [
|
||||||
"./src/*"
|
"./src/*"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"types": [
|
||||||
|
"unplugin-vue-macros/macros-global",
|
||||||
|
],
|
||||||
|
"vueCompilerOptions": {
|
||||||
|
"plugins": [
|
||||||
|
"@vue-macros/volar/export-render",
|
||||||
|
"@vue-macros/volar/export-expose",
|
||||||
|
"@vue-macros/volar/export-props"
|
||||||
|
],
|
||||||
|
"vueMacros": {
|
||||||
|
"exportExpose": {
|
||||||
|
"include": ["**/export-expose/**"]
|
||||||
|
},
|
||||||
|
"exportProps": {
|
||||||
|
"include": ["**/export-props/**"]
|
||||||
|
},
|
||||||
|
"exportRender": {
|
||||||
|
"include": ["**/export-render/**"]
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
{"version":"2.0.0-beta.4","build_id":25,"total_build":229}
|
{"version":"2.0.0-beta.4","build_id":30,"total_build":234}
|
|
@ -7,6 +7,7 @@ import {fileURLToPath, URL} from 'url'
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx'
|
import vueJsx from '@vitejs/plugin-vue-jsx'
|
||||||
import vitePluginBuildId from 'vite-plugin-build-id'
|
import vitePluginBuildId from 'vite-plugin-build-id'
|
||||||
import svgLoader from 'vite-svg-loader'
|
import svgLoader from 'vite-svg-loader'
|
||||||
|
import VueMacros from 'unplugin-vue-macros/vite'
|
||||||
|
|
||||||
// https://vitejs.dev/config/
|
// https://vitejs.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
@ -26,11 +27,17 @@ export default defineConfig({
|
||||||
'.less'
|
'.less'
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
plugins: [vue(), vueJsx(), vitePluginBuildId(), svgLoader(),
|
plugins: [vitePluginBuildId(), svgLoader(),
|
||||||
Components({
|
Components({
|
||||||
resolvers: [AntDesignVueResolver({importStyle: false})],
|
resolvers: [AntDesignVueResolver({importStyle: false})],
|
||||||
directoryAsNamespace: true
|
directoryAsNamespace: true
|
||||||
}),
|
}),
|
||||||
|
VueMacros({
|
||||||
|
plugins: {
|
||||||
|
vue: vue(),
|
||||||
|
vueJsx: vueJsx(),
|
||||||
|
},
|
||||||
|
}),
|
||||||
createHtmlPlugin({
|
createHtmlPlugin({
|
||||||
minify: true,
|
minify: true,
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -147,11 +147,7 @@ func AddConfig(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := nginx.Reload()
|
output := nginx.Reload()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
|
@ -196,11 +192,8 @@ func EditConfig(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := nginx.Reload()
|
output := nginx.Reload()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if nginx.GetLogLevel(output) >= nginx.Warn {
|
if nginx.GetLogLevel(output) >= nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
|
|
|
@ -271,11 +271,8 @@ func SaveDomain(c *gin.Context) {
|
||||||
enabledConfigFilePath = nginx.GetConfPath("sites-enabled", name)
|
enabledConfigFilePath = nginx.GetConfPath("sites-enabled", name)
|
||||||
if helper.FileExists(enabledConfigFilePath) {
|
if helper.FileExists(enabledConfigFilePath) {
|
||||||
// Test nginx configuration
|
// Test nginx configuration
|
||||||
output, err := nginx.TestConf()
|
output := nginx.TestConf()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
|
@ -284,11 +281,7 @@ func SaveDomain(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err = nginx.Reload()
|
output = nginx.Reload()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
@ -322,10 +315,7 @@ func EnableDomain(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test nginx config, if not pass then disable the site.
|
// Test nginx config, if not pass then disable the site.
|
||||||
output, err := nginx.TestConf()
|
output := nginx.TestConf()
|
||||||
if err != nil {
|
|
||||||
_ = os.Remove(enabledConfigFilePath)
|
|
||||||
}
|
|
||||||
|
|
||||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||||
_ = os.Remove(enabledConfigFilePath)
|
_ = os.Remove(enabledConfigFilePath)
|
||||||
|
@ -335,7 +325,7 @@ func EnableDomain(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, _ = nginx.Reload()
|
output = nginx.Reload()
|
||||||
|
|
||||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
@ -374,7 +364,7 @@ func DisableDomain(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
output, _ := nginx.Reload()
|
output := nginx.Reload()
|
||||||
|
|
||||||
if nginx.GetLogLevel(output) > nginx.Warn {
|
if nginx.GetLogLevel(output) > nginx.Warn {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
|
|
@ -63,12 +63,7 @@ func NginxStatus(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ReloadNginx(c *gin.Context) {
|
func ReloadNginx(c *gin.Context) {
|
||||||
output, err := nginx.Reload()
|
output := nginx.Reload()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
"level": nginx.GetLogLevel(output),
|
"level": nginx.GetLogLevel(output),
|
||||||
|
@ -76,12 +71,7 @@ func ReloadNginx(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNginx(c *gin.Context) {
|
func TestNginx(c *gin.Context) {
|
||||||
output, err := nginx.TestConf()
|
output := nginx.TestConf()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
"level": nginx.GetLogLevel(output),
|
"level": nginx.GetLogLevel(output),
|
||||||
|
@ -89,12 +79,7 @@ func TestNginx(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RestartNginx(c *gin.Context) {
|
func RestartNginx(c *gin.Context) {
|
||||||
output, err := nginx.Restart()
|
output := nginx.Restart()
|
||||||
if err != nil {
|
|
||||||
ErrHandler(c, err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"message": output,
|
"message": output,
|
||||||
"level": nginx.GetLogLevel(output),
|
"level": nginx.GetLogLevel(output),
|
||||||
|
|
|
@ -8,79 +8,51 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
func execShell(cmd string) (out string, err error) {
|
func execShell(cmdArgs ...string) (out string) {
|
||||||
bytes, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
|
cmd := []string{"-c"}
|
||||||
|
cmd = append(cmd, cmdArgs...)
|
||||||
|
|
||||||
|
bytes, err := exec.Command("/bin/sh", cmd...).CombinedOutput()
|
||||||
out = string(bytes)
|
out = string(bytes)
|
||||||
|
if err != nil {
|
||||||
|
out += " " + err.Error()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConf() (string, error) {
|
func TestConf() (out string) {
|
||||||
if settings.NginxSettings.TestConfigCmd != "" {
|
if settings.NginxSettings.TestConfigCmd != "" {
|
||||||
out, err := execShell(settings.NginxSettings.TestConfigCmd)
|
out = execShell(settings.NginxSettings.TestConfigCmd)
|
||||||
|
|
||||||
if err != nil {
|
return
|
||||||
logger.Error(err)
|
|
||||||
return out, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := exec.Command("nginx", "-t").CombinedOutput()
|
out = execShell("nginx", "-t")
|
||||||
if err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
return string(out), err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(out), nil
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Reload() (string, error) {
|
func Reload() (out string) {
|
||||||
if settings.NginxSettings.ReloadCmd != "" {
|
if settings.NginxSettings.ReloadCmd != "" {
|
||||||
out, err := execShell(settings.NginxSettings.ReloadCmd)
|
out = execShell(settings.NginxSettings.ReloadCmd)
|
||||||
|
return
|
||||||
if err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
return out, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
|
|
||||||
} else {
|
|
||||||
out, err := exec.Command("nginx", "-s", "reload").CombinedOutput()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
return string(out), err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(out), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out = execShell("nginx", "-s", "reload")
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Restart() (string, error) {
|
func Restart() (out string) {
|
||||||
if settings.NginxSettings.RestartCmd != "" {
|
if settings.NginxSettings.RestartCmd != "" {
|
||||||
out, err := execShell(settings.NginxSettings.RestartCmd)
|
out = execShell(settings.NginxSettings.RestartCmd)
|
||||||
|
|
||||||
if err != nil {
|
return
|
||||||
logger.Error(err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return out, nil
|
|
||||||
} else {
|
|
||||||
|
|
||||||
out, err := exec.Command("nginx", "-s", "reopen").CombinedOutput()
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
logger.Error(err)
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(out), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
out = execShell("nginx", "-s", "reopen")
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetConfPath(dir ...string) string {
|
func GetConfPath(dir ...string) string {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue