Skip to content

Commit adf6f80

Browse files
committed
feat(modules): retrieve nginx modules status
1 parent 5b0cbf9 commit adf6f80

File tree

12 files changed

+288
-30
lines changed

12 files changed

+288
-30
lines changed

api/nginx/modules.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package nginx
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/0xJacky/Nginx-UI/internal/nginx"
7+
"github.com/gin-gonic/gin"
8+
)
9+
10+
func GetModules(c *gin.Context) {
11+
modules := nginx.GetModules()
12+
modulesList := make([]nginx.Module, 0, modules.Len())
13+
for _, module := range modules.AllFromFront() {
14+
modulesList = append(modulesList, module)
15+
}
16+
c.JSON(http.StatusOK, modulesList)
17+
}

api/nginx/router.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,6 @@ func InitRouter(r *gin.RouterGroup) {
2727
// Performance optimization endpoints
2828
r.GET("nginx/performance", GetPerformanceSettings)
2929
r.POST("nginx/performance", UpdatePerformanceSettings)
30+
31+
r.GET("nginx/modules", GetModules)
3032
}

app/src/api/ngx.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ export interface NginxPerfOpt {
104104
proxy_cache: ProxyCacheConfig
105105
}
106106

107+
export interface NgxModule {
108+
name: string
109+
params?: string
110+
dynamic: boolean
111+
loaded: boolean
112+
}
113+
107114
const ngx = {
108115
build_config(ngxConfig: NgxConfig) {
109116
return http.post('/ngx/build_config', ngxConfig)
@@ -152,6 +159,10 @@ const ngx = {
152159
update_performance(params: NginxPerfOpt): Promise<NginxConfigInfo> {
153160
return http.post('/nginx/performance', params)
154161
},
162+
163+
get_modules(): Promise<NgxModule[]> {
164+
return http.get('/nginx/modules')
165+
},
155166
}
156167

157168
export default ngx

app/src/layouts/SideBar.vue

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
<script setup lang="ts">
2+
import type { NgxModule } from '@/api/ngx'
23
import type { IconComponentProps } from '@ant-design/icons-vue/es/components/Icon'
34
import type { AntdIconType } from '@ant-design/icons-vue/lib/components/AntdIcon'
45
import type { Key } from 'ant-design-vue/es/_util/type'
5-
import type { ComputedRef, Ref } from 'vue'
6-
import EnvIndicator from '@/components/EnvIndicator/EnvIndicator.vue'
7-
import Logo from '@/components/Logo/Logo.vue'
6+
import ngx from '@/api/ngx'
7+
import EnvIndicator from '@/components/EnvIndicator'
8+
import Logo from '@/components/Logo'
9+
import { useGlobalStore } from '@/pinia/moudule/global'
810
import { routes } from '@/routes'
911
1012
const route = useRoute()
@@ -47,6 +49,19 @@ interface Sidebar {
4749
children: Sidebar[]
4850
}
4951
52+
const globalStore = useGlobalStore()
53+
const { modules, modulesMap } = storeToRefs(globalStore)
54+
55+
onMounted(() => {
56+
ngx.get_modules().then(r => {
57+
modules.value = r
58+
modulesMap.value = r.reduce((acc, m) => {
59+
acc[m.name] = m
60+
return acc
61+
}, {} as Record<string, NgxModule>)
62+
})
63+
})
64+
5065
const visible: ComputedRef<Sidebar[]> = computed(() => {
5166
const res: Sidebar[] = [];
5267
@@ -56,6 +71,11 @@ const visible: ComputedRef<Sidebar[]> = computed(() => {
5671
return
5772
}
5873
74+
if (s.meta && s.meta.modules && s.meta.modules?.length > 0
75+
&& !s.meta.modules.every(m => modulesMap.value[m]?.loaded)) {
76+
return
77+
}
78+
5979
const t: Sidebar = {
6080
path: s.path,
6181
name: s.name as string,
@@ -69,6 +89,11 @@ const visible: ComputedRef<Sidebar[]> = computed(() => {
6989
return
7090
}
7191
92+
if (c.meta && c.meta.modules && c.meta.modules?.length > 0
93+
&& !c.meta.modules.every(m => modulesMap.value[m]?.loaded)) {
94+
return
95+
}
96+
7297
t.children.push((c as unknown as Sidebar))
7398
})
7499
res.push(t)

app/src/pinia/moudule/global.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { NgxModule } from '@/api/ngx'
12
import type { NginxStatus } from '@/constants'
23
import { defineStore } from 'pinia'
34

@@ -15,8 +16,14 @@ export const useGlobalStore = defineStore('global', () => {
1516
index_scanning: false,
1617
auto_cert_processing: false,
1718
})
19+
20+
const modules = ref<NgxModule[]>([])
21+
const modulesMap = ref<Record<string, NgxModule>>({})
22+
1823
return {
1924
nginxStatus,
2025
processingStatus,
26+
modules,
27+
modulesMap,
2128
}
2229
})

app/src/routes/modules/streams.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const streamsRoutes: RouteRecordRaw[] = [
99
meta: {
1010
name: () => $gettext('Manage Streams'),
1111
icon: ShareAltOutlined,
12+
modules: ['stream'],
1213
},
1314
},
1415
{
@@ -19,6 +20,7 @@ export const streamsRoutes: RouteRecordRaw[] = [
1920
name: () => $gettext('Edit Stream'),
2021
hiddenInSidebar: true,
2122
lastRouteName: 'Manage Streams',
23+
modules: ['stream'],
2224
},
2325
},
2426
]

app/src/routes/type.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ declare module 'vue-router' {
1717
status_code?: number
1818
error?: () => string
1919
lastRouteName?: string
20+
modules?: string[]
2021
}
2122
}

internal/kernel/boot.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/0xJacky/Nginx-UI/internal/helper"
2020
"github.com/0xJacky/Nginx-UI/internal/mcp"
2121
"github.com/0xJacky/Nginx-UI/internal/passkey"
22+
"github.com/0xJacky/Nginx-UI/internal/self_check"
2223
"github.com/0xJacky/Nginx-UI/internal/validation"
2324
"github.com/0xJacky/Nginx-UI/model"
2425
"github.com/0xJacky/Nginx-UI/query"
@@ -43,6 +44,7 @@ func Boot(ctx context.Context) {
4344
InitNodeSecret,
4445
InitCryptoSecret,
4546
validation.Init,
47+
self_check.Init,
4648
func() {
4749
InitDatabase(ctx)
4850
cache.Init(ctx)

internal/nginx/config_args.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,17 @@ func getNginxV() string {
4949
return string(out)
5050
}
5151

52+
// getNginxT executes nginx -T and returns the output
53+
func getNginxT() string {
54+
exePath := getNginxExePath()
55+
out, err := execCommand(exePath, "-T")
56+
if err != nil {
57+
logger.Error(err)
58+
return ""
59+
}
60+
return out
61+
}
62+
5263
// Resolves relative paths by joining them with the nginx executable directory on Windows
5364
func resolvePath(path string) string {
5465
if path == "" {

0 commit comments

Comments
 (0)