Browse Source

feat: 新增ngx_access模块

tuon 1 year ago
parent
commit
e3c3880f6a

+ 14 - 0
src/config/nginx_form.json

@@ -79,6 +79,13 @@
       "required": false,
       "description": "gzip"
     },
+    {
+      "title": "Access",
+      "key": "access",
+      "type": "access",
+      "required": false,
+      "description": "deny or allow,白名单或者黑名单访问限制"
+    },
     {
       "type": "auth",
       "title": "鉴权",
@@ -453,6 +460,13 @@
           "description": "单位为秒(s), 0表示不限制",
           "min": 0
         },
+        {
+          "title": "Access",
+          "key": "http.access",
+          "type": "access",
+          "required": false,
+          "description": "deny or allow,白名单或者黑名单访问限制"
+        },
         {
           "key": "http.proxy_settings",
           "title": "代理设置",

+ 28 - 0
src/pages/nginx/components/access/config.json

@@ -0,0 +1,28 @@
+{
+  "form": [
+    {
+      "title": "Allow/Deny",
+      "type": "array",
+      "key": "access",
+      "hideLabel": true,
+      "required": false,
+      "items": [
+        {
+          "title": "Allow/Deny",
+          "type": "select",
+          "key": "type",
+          "option": ["allow","deny"],
+          "width": 120,
+          "description": "允许或者拒绝,eg. deny  192.168.1.1;\n    allow 192.168.1.0/24;\n    allow 10.1.1.0/16;\n    allow 2001:0db8::/32;\n    deny  all;"
+        },
+        {
+          "title": "address|CIDR|unix|all",
+          "type": "string",
+          "width": 250,
+          "key": "address",
+          "description": "The rules are checked in sequence until the first match is found. In this example, access is allowed only for IPv4 networks 10.1.1.0/16 and 192.168.1.0/24 excluding the address 192.168.1.1, and for IPv6 network 2001:0db8::/32. In case of a lot of rules, the use of the ngx_http_geo_module module variables is preferable."
+        }
+      ]
+    }
+  ]
+}

+ 30 - 0
src/pages/nginx/components/access/index.less

@@ -0,0 +1,30 @@
+.ngx-access-input{
+  display: flex;
+  flex-direction: row;
+  align-items: center;
+  .less-values{
+    max-width: 250px;
+    overflow: hidden;
+    display: inline-block;
+    line-height: 32px;
+    height: 32px;
+    text-overflow: ellipsis;
+    white-space: nowrap;
+  }
+}
+
+
+
+.more-conf-popover{
+  .ant-popover-inner-content{
+    width: 100%;
+    padding: 5px;
+  }
+  .access-more-values.ant-input{
+    min-width: 250px;
+    color: #333333;
+    border: none;
+    cursor: text;
+  }
+
+}

+ 55 - 0
src/pages/nginx/components/access/index.tsx

@@ -0,0 +1,55 @@
+/**
+ * @author tuonian
+ * @date 2023/7/31
+ */
+import {IContentProps, NgxBasicInput, registerInput} from "../basic";
+import {AutoTypeInputProps} from "planning-tools";
+
+import CFG from './config.json'
+import {Input, Popover} from "antd";
+import './index.less'
+
+export const AccessInput = (props: AutoTypeInputProps)=>{
+
+    const renderMoreContent = (lines?: string[])=>{
+        if (!lines?.length){
+            return <span>无配置</span>
+        }
+        return (<Input.TextArea className="access-more-values"
+                                rows={Math.min(10,lines.length)}
+                                disabled value={lines.join('\n')} />)
+    }
+
+    const renderContent = (props: IContentProps) => {
+
+        const lines = renderLines(props.data)
+
+        return (
+            <div className="ngx-access-input">
+                <Popover
+                    overlayClassName="more-conf-popover"
+                    destroyTooltipOnHide content={()=>renderMoreContent(lines)}>
+                    <span className="less-values">{lines.length ? lines.join(' ; ') : '无配置'}</span>
+                </Popover>
+            </div>
+        )
+    }
+
+    const renderLines = (values: any)=>{
+        console.log('renderLines',values)
+        const results: string[] = [];
+        if (Array.isArray(values?.access)){
+            values.access.forEach((item: any)=>{
+                results.push(`${item.type}    ${item.address};`)
+            })
+        }
+        return results
+    }
+
+    return <NgxBasicInput renderLines={renderLines}
+                          columns={CFG.form}
+                          labelCol={4}
+                          content={renderContent} {...props}/>
+}
+
+registerInput('access',AccessInput)

+ 1 - 0
src/pages/nginx/components/index.ts

@@ -7,3 +7,4 @@ import './proxypass'
 import './proxypass/stream.tsx'
 import './error'
 import './cors'
+import './access'

+ 7 - 0
src/pages/nginx/components/location/config.json

@@ -162,6 +162,13 @@
       "description": "跨域配置,可以通过该配置项解决前端跨域问题",
       "required": false
     },
+    {
+      "title": "Access",
+      "key": "access",
+      "type": "access",
+      "required": false,
+      "description": "deny or allow,白名单或者黑名单访问限制"
+    },
     {
       "type": "auth",
       "title": "鉴权",