mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-03-18 11:02:09 +00:00
feat: add hostname api
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .aggregate import *
|
||||
from .dashboard import IndexApi
|
||||
from .health import PrometheusMetricsApi, HealthCheckView
|
||||
from .search import GlobalSearchView
|
||||
from .search import GlobalSearchView
|
||||
from .hostname import HostnameView
|
||||
|
||||
17
apps/jumpserver/api/hostname.py
Normal file
17
apps/jumpserver/api/hostname.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import status
|
||||
from rest_framework.permissions import AllowAny
|
||||
|
||||
|
||||
## 此 api 返回 /etc/hostname 的值, 可以匿名访问
|
||||
class HostnameView(APIView):
|
||||
permission_classes = (AllowAny,)
|
||||
|
||||
def get(self, request):
|
||||
try:
|
||||
with open('/etc/hostname', 'r') as f:
|
||||
hostname = f.read().strip() or "Unknown"
|
||||
return Response({"hostname": hostname})
|
||||
except Exception as e:
|
||||
return Response({"error": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
@@ -66,6 +66,7 @@ urlpatterns = [
|
||||
path('api/v1/', include(api_v1)),
|
||||
path('api/health/', api.HealthCheckView.as_view(), name="health"),
|
||||
path('api/v1/health/', api.HealthCheckView.as_view(), name="health_v1"),
|
||||
path('api/v1/hostname/', api.HostnameView.as_view(), name="hostname"),
|
||||
# External apps url
|
||||
path('core/auth/captcha/', include('captcha.urls')),
|
||||
path('core/', include(app_view_patterns)),
|
||||
|
||||
Reference in New Issue
Block a user