feat: inspect configurations #69
parent
561771cf10
commit
768da42e35
File diff suppressed because one or more lines are too long
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
{"version":"1.7.2","build_id":73,"total_build":143}
|
||||
{"version":"1.7.4","build_id":76,"total_build":146}
|
||||
@ -0,0 +1,64 @@
|
||||
<script setup lang="ts">
|
||||
import ngx from '@/api/ngx'
|
||||
import {useGettext} from 'vue3-gettext'
|
||||
import {ref} from 'vue'
|
||||
import logLevel from '@/views/config/constants'
|
||||
import Template from '@/views/template/Template.vue'
|
||||
|
||||
const {$gettext} = useGettext()
|
||||
|
||||
const data = ref({
|
||||
level: 0,
|
||||
message: ''
|
||||
})
|
||||
|
||||
test()
|
||||
|
||||
function test() {
|
||||
ngx.test().then(r => {
|
||||
data.value = r
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
test
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<a-card class="inspect-container" :title="$gettext('Inspect Configurations')">
|
||||
<a-alert :message="$gettext('Configuration file is test successful')" type="success"
|
||||
show-icon v-if="data?.level<logLevel.Debug"/>
|
||||
<a-alert
|
||||
:message="$gettext('Warning')"
|
||||
type="warning"
|
||||
show-icon
|
||||
v-else-if="data?.level===logLevel.Warn"
|
||||
>
|
||||
<template #description>
|
||||
{{ data.message }}
|
||||
</template>
|
||||
</a-alert>
|
||||
|
||||
<a-alert
|
||||
:message="$gettext('Error')"
|
||||
type="error"
|
||||
show-icon
|
||||
v-else-if="data?.level>logLevel.Warn"
|
||||
>
|
||||
<template #description>
|
||||
{{ data.message }}
|
||||
</template>
|
||||
</a-alert>
|
||||
</a-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.inspect-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
:deep(.ant-alert-description) {
|
||||
white-space: pre-line;
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,17 @@
|
||||
import {createEnum} from '@/lib/helper'
|
||||
|
||||
// refer to https://nginx.org/en/docs/ngx_core_module.html#error_log
|
||||
// nginx log level: debug, info, notice, warn, error, crit, alert, or emerg
|
||||
|
||||
const logLevel = createEnum({
|
||||
Debug: [0, 'debug'],
|
||||
Info: [1, 'info'],
|
||||
Notice: [2, 'notice'],
|
||||
Warn: [3, 'warn'],
|
||||
Error: [4, 'error'],
|
||||
Crit: [5, 'crit'],
|
||||
Alert: [6, 'alert'],
|
||||
Emerg: [7, 'emerg']
|
||||
})
|
||||
|
||||
export default logLevel
|
||||
@ -1 +1 @@
|
||||
{"version":"1.7.2","build_id":73,"total_build":143}
|
||||
{"version":"1.7.4","build_id":76,"total_build":146}
|
||||
@ -1,65 +1,67 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"strings"
|
||||
"github.com/0xJacky/Nginx-UI/server/pkg/nginx"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func BuildNginxConfig(c *gin.Context) {
|
||||
var ngxConf nginx.NgxConfig
|
||||
if !BindAndValid(c, &ngxConf) {
|
||||
return
|
||||
}
|
||||
c.Set("maybe_error", "nginx_config_syntax_error")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": ngxConf.BuildConfig(),
|
||||
})
|
||||
var ngxConf nginx.NgxConfig
|
||||
if !BindAndValid(c, &ngxConf) {
|
||||
return
|
||||
}
|
||||
c.Set("maybe_error", "nginx_config_syntax_error")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": ngxConf.BuildConfig(),
|
||||
})
|
||||
}
|
||||
|
||||
func TokenizeNginxConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("maybe_error", "nginx_config_syntax_error")
|
||||
ngxConfig := nginx.ParseNgxConfigByContent(json.Content)
|
||||
c.Set("maybe_error", "nginx_config_syntax_error")
|
||||
ngxConfig := nginx.ParseNgxConfigByContent(json.Content)
|
||||
|
||||
c.JSON(http.StatusOK, ngxConfig)
|
||||
c.JSON(http.StatusOK, ngxConfig)
|
||||
|
||||
}
|
||||
|
||||
func FormatNginxConfig(c *gin.Context) {
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
var json struct {
|
||||
Content string `json:"content" binding:"required"`
|
||||
}
|
||||
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
if !BindAndValid(c, &json) {
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("maybe_error", "nginx_config_syntax_error")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": nginx.FmtCode(json.Content),
|
||||
})
|
||||
c.Set("maybe_error", "nginx_config_syntax_error")
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"content": nginx.FmtCode(json.Content),
|
||||
})
|
||||
}
|
||||
|
||||
func ReloadNginx(c *gin.Context) {
|
||||
output := nginx.Reload()
|
||||
output := nginx.Reload()
|
||||
|
||||
if output != "" && strings.Contains(output, "error") {
|
||||
c.JSON(http.StatusInternalServerError, gin.H{
|
||||
"message": output,
|
||||
})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": output,
|
||||
"level": nginx.GetLogLevel(output),
|
||||
})
|
||||
}
|
||||
|
||||
func TestNginx(c *gin.Context) {
|
||||
output := nginx.TestConf()
|
||||
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "ok",
|
||||
})
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": output,
|
||||
"level": nginx.GetLogLevel(output),
|
||||
})
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package nginx
|
||||
|
||||
import "strings"
|
||||
|
||||
// refer to https://nginx.org/en/docs/ngx_core_module.html#error_log
|
||||
// nginx log level: debug, info, notice, warn, error, crit, alert, or emerg
|
||||
|
||||
const (
|
||||
Debug = iota
|
||||
Info
|
||||
Notice
|
||||
Warn
|
||||
Error
|
||||
Crit
|
||||
Alert
|
||||
Emerg
|
||||
)
|
||||
|
||||
var logLevel = [...]string{
|
||||
"debug", "info", "notice", "warn", "error", "crit", "alert", "emerg",
|
||||
}
|
||||
|
||||
func GetLogLevel(output string) int {
|
||||
for k, v := range logLevel {
|
||||
if strings.Contains(output, v) {
|
||||
return k
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
Loading…
Reference in New Issue