From 94ebf0a452ac1afe4e6653dd266f755b175f58f0 Mon Sep 17 00:00:00 2001 From: wanglei <34475144@qq.com> Date: Wed, 15 Oct 2025 10:35:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=8E=A5=E5=8F=A3=E5=B9=B6?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E5=B0=86=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E6=94=BE=E5=88=B0=E9=85=8D=E7=BD=AE=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/nginx.conf | 133 +----------------------------------- conf/system/user.conf | 4 ++ src/api/api.lua | 30 ++++++-- src/api/system/user.lua | 14 ---- src/config/config.lua | 2 +- src/service/system/user.lua | 15 ---- src/test/test.lua | 5 ++ 7 files changed, 37 insertions(+), 166 deletions(-) create mode 100644 conf/system/user.conf create mode 100644 src/test/test.lua diff --git a/conf/nginx.conf b/conf/nginx.conf index 4751128..b6c330c 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -7,9 +7,10 @@ events { } http { - lua_package_path 'src/?/?.lua;src/?.lua;src/share/?/?.lua;src/share/?.lua;/home/frankly/work/AuthPlatform/src/share/lib/?/?.lub;/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth/?.lua;/home/frankly/work/AuthPlatform/src/share/?/?.lub;/home/frankly/work/AuthPlatform/src/share/?.lua;;'; - lua_package_cpath 'src/share/lib/?.so;;'; + lua_package_path '$profix/src/?/?.lua;$profix/src/?.lua;;'; + lua_package_cpath '$profix/src/share/lib/?.so;;'; + include system/user.conf # Path of the file with trusted CA certificates. #lua_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt; @@ -24,133 +25,5 @@ http { log_not_found off; access_log off; } - - #API接口文件 - location /api { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua'; - } - - #测试相关插件接口 - location /testTree { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testRadixtree.lua'; - } - location /testSQL { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testPostgres.lua'; - } - location /testRedis { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testRedis.lua'; - } - location /testObj { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testObjClass.lua'; - } - location /testWsdl { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWebService.lua'; - } - location /wsdl { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testWsdl.lua'; - } - location /jsonSchema { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testJsonSchema.lua'; - } - location /testOrm { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/test/testOrm.lua'; - } - location /checkip { - content_by_lua_block { - local ipmatcher = require("resty.ipmatcher") - local client_ip = ngx.var.remote_addr - ngx.say(ipmatcher.new({"127.0.0.1", "192.168.0.11/16"}).match(client_ip)) - } - } - - location /t { - rewrite_by_lua_block { - - local aes = require "resty.aes" - local str = require "resty.string" - local cjson = require('cjson') - local key = "aaaaaaaaaaaaaaaa" - local text = "7614463 1574189821 175.168.224.225" - local length = 16 - local count = string.len(text) - local add = length - (count % length) - local tail_str='\0' - for i=1,add-1 do - tail_str=tail_str .. '\0' - end - text = text .. tail_str - ngx.say(text) - -- 创建 AES 对象 - local aes_128_cbc = aes:new(key, nil, aes.cipher(128, "cbc"), {iv=key}) - -- 加密数据 - local encrypted, err = aes_128_cbc:encrypt(text) - if not encrypted then - ngx.log(ngx.ERR, "Failed to encrypt: ", err) - return ngx.exit(500) - end - ngx.say(str.to_hex(encrypted)) - - local crc_32s, crc_32l - crc_32s = ngx.crc32_short(str) - crc_32l = ngx.crc32_long(str) - --local hmac = ngx.hmac_sha1(key, str) - local md5 = ngx.md5(str) - local md5_bin = ngx.md5_bin(str) - local sha1_bin = ngx.sha1_bin(str) - ngx.say("crc_32_short: ", crc_32s, ", crc_32_long: ", crc_32l) - ngx.say("hmac: ", ngx.encode_base64(hmac)) - ngx.say("md5: ", md5, ", md5_bin: ", ngx.encode_base64(md5_bin)) - ngx.say("sha1_bin: ", ngx.encode_base64(sha1_bin)) - - -- 将加密后的数据转换为十六进制字符串以便于查看或传输 - local encrypted_hex = cjson.encode({iv = ngx.encode_base64(iv), ciphertext = ngx.encode_base64(encrypted)}) - ngx.say("Encrypted: ", encrypted_hex) - } - } - } - server { - listen 1443 ssl; #修改端口443 - server_name 127.0.0.1; - - set $oauth_client_id '01234567-89ab-cdef-0123-456789abcdef'; - set $oauth_client_secret 'very-top-secret-password'; - set $oauth_redirect_uri '/_oauth/callback'; - set $oauth_oaas_uri 'https://127.0.0.1/oauth'; - - ssl_certificate /home/frankly/work/server.crt; - ssl_certificate_key /home/frankly/work/server.key; - - ssl_session_cache shared:SSL:1m; - ssl_session_timeout 5m; - - ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #֧支持TLS协议 - - ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #支持的加密算法 - ssl_prefer_server_ciphers on; - - location /_oauth/login { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-login.lua'; - } - - location /_oauth/callback { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-redirect-handler.lua'; - } - - location /_oauth/logout { - content_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-logout.lua'; - } - - location /_proxy { - access_by_lua_file '/home/frankly/work/AuthPlatform/src/share/lib/ngx-oauth-proxy.lua'; - - rewrite ^/_proxy/(.*)$ /$1 break; - ##proxy_pass https://resource-provider; - } - - # 错误页处理 - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root html; - } } } \ No newline at end of file diff --git a/conf/system/user.conf b/conf/system/user.conf new file mode 100644 index 0000000..837330c --- /dev/null +++ b/conf/system/user.conf @@ -0,0 +1,4 @@ +#API接口文件 +location /api { + content_by_lua_file '/home/frankly/work/AuthPlatform/src/api/api.lua'; +} \ No newline at end of file diff --git a/src/api/api.lua b/src/api/api.lua index 4727234..d39d955 100644 --- a/src/api/api.lua +++ b/src/api/api.lua @@ -3,19 +3,18 @@ --- Created by admin. --- DateTime: 2025/9/24 15:29 --- +local radix = require("resty.radixtree") local function say_hello(req) ngx.say("Hello, World!") end local function get_user(req) - ngx.say("call get_user") local user_id = req.args.id or "unknown" ngx.say("User ID: " .. user_id) end local function get_id(req) - ngx.say("call get_id") local args = req.get_uri_args() -- 获取单个参数 local id = args["id"] -- 值为 "john" @@ -37,14 +36,33 @@ local function test(req) end local routes = { - ["/hello"] = say_hello, - ["/user"] = get_user, - ["/userid"] = get_id, + { + paths = { "/login/*action" }, + metadata = { "metadata /login/action" }, + methods = { "GET", "POST", "PUT" }, + remote_addrs = { "127.0.0.1", "192.168.0.0/16", "::1", "fe80::/32" } + }, + { + paths = { "/user/:name" }, + metadata = { "metadata /user/name" }, + methods = { "GET" }, + }, + { + paths = { "/admin/:name", "/superuser/:name" }, + metadata = { "metadata /admin/name" }, + methods = { "GET", "POST", "PUT" }, + filter_fun = function(vars, opts) + return vars["arg_access"] == "admin" + end + } } local function handle_request() + --获取接口请求的方法 local request_method = ngx.var.request_method - local args = nil + ngx.say(request_method) + + local args = ngx.var.get_uri_args ngx.say(request_method) local uri = ngx.var.request_uri diff --git a/src/api/system/user.lua b/src/api/system/user.lua index 791840a..ba1578a 100644 --- a/src/api/system/user.lua +++ b/src/api/system/user.lua @@ -16,19 +16,5 @@ conn:connect(function(err) print("Error connecting to database: ", err) else print("Connected to the PostgreSQL server.") - - -- 执行一个简单的查询 - conn:query("SELECT version()") - :on_data(function(row) - print("Database Version: ", row[1]) - end) - :on_error(function(err) - print("Query Error: ", err) - end) - :on_finish(function() - print("Query finished.") - -- 关闭连接 - conn:close() - end) end end) \ No newline at end of file diff --git a/src/config/config.lua b/src/config/config.lua index 25b5b2e..83210f6 100644 --- a/src/config/config.lua +++ b/src/config/config.lua @@ -19,7 +19,7 @@ return { HOST = "127.0.0.1", -- postgres host PORT = 5432, -- postgres port USERNAME = "postgres", - PASSWORD = "123456", -- postgres password + PASSWORD = "1qaz2wsx", -- postgres password DATABASE = "postgres" } } \ No newline at end of file diff --git a/src/service/system/user.lua b/src/service/system/user.lua index 2de12c0..55a52d5 100644 --- a/src/service/system/user.lua +++ b/src/service/system/user.lua @@ -17,18 +17,3 @@ conn:connect(function(err) print("Connected to the PostgreSQL server.") end end) - --- 执行一个简单的查询 - -conn:query("SELECT version()") - :on_data(function(row) - print("Database Version: ", row[1]) -end) - :on_error(function(err) - print("Query Error: ", err) -end) - :on_finish(function() - print("Query finished.") - -- 关闭连接 - conn:close() -end) \ No newline at end of file diff --git a/src/test/test.lua b/src/test/test.lua new file mode 100644 index 0000000..79aa0ba --- /dev/null +++ b/src/test/test.lua @@ -0,0 +1,5 @@ +--- +--- Generated by EmmyLua(https://github.com/EmmyLua) +--- Created by admin. +--- DateTime: 2025/10/15 09:12 +--- \ No newline at end of file