当前位置: 首页 > news >正文

国际军事新闻联播seo问答

国际军事新闻联播,seo问答,之路网站建设,淘宝哪家做网站靠谱整个系统的第一个层次已经开发完毕,已经有简单的中控,登录、退出、延迟登录时长、黑名单、数据层封装、验证层封装、RSA加解密、Redis等功能,还缺获取个人、角色按钮权限、角色菜单权限功能。角色按钮权限以及角色菜单权限等明后天开发&#…

        整个系统的第一个层次已经开发完毕,已经有简单的中控,登录、退出、延迟登录时长、黑名单、数据层封装、验证层封装、RSA加解密、Redis等功能,还缺获取个人、角色按钮权限、角色菜单权限功能。角色按钮权限以及角色菜单权限等明后天开发,今天先开发个人信息接口以便测试使用。

一、个人信息接口开发

       1、添加路由

                在根目录下route文件夹中的app.php文件中加入以下代码:

Route::post('member/personal_data','permission.Member/personalData');

        2、代码开发

                在根目录下app文件夹下的controller文件夹中创建文件夹并命名为permission,然后在permission文件夹中创建控制器并命名为Member,然后在Member文件中继承Base总控制后并创建personalData方法。具体代码如下:

<?php
/*** 个人信息控制-也就是登录者信息及角色对外方法* User: 龙哥·三年风水* Date: 2024/10/30* Time: 14:18*/
namespace app\controller\permission;
use app\controller\Base;
class Member extends Base
{/*** 获取个人信息* User: 龙哥·三年风水* Date: 2024/10/30* Time: 14:23* @ return \think\response\Json*/public function personalData(){$data = [];$data['username'] = $this->username;$data['avatar'] = $this->avatar;$data['email'] = $this->email;$data['realname'] = $this->realname;return succ('操作成功',$data);}
}

二、nginx黑名单开发

        因nginx自身是没有redis及rsa扩展使用的,所以我安装的不是nginx,而是openresty,他是有带resty扩展的。如果不会安装openresty,可以参照《centos7 二进制安装openresty》、《配置openresty》以及《openresty安全机制-白名单》三篇文章进行安装配置。

        1、引入扩展

--引入Redis
local redis = require "resty.redis";
--引入rsa
local rsa = require "resty.rsa";

        2、配置redis

--Redis链接ip
local ip = "172.20.36.144"
--Redis链接端口
local port = 6379
--Redis连接密码
local pass = "QXtr@@PxjoLenGon"

        3、在对应的Redis库里面添加公钥字符串

                我不管是在应用程序里面还是在本机制里面,都采用的是Redis第0号库的black-list库中哈,所有的非正常访问系统的IP都在black-list库中。

        4、开发lua对应的Redis授权

--鉴权Redis
local function connAuth()local red = redis:new();local connCount, err = red:connect(ip, port);if not connCount thenngx.say("failed to connect: ", err)close_redis(red)returnendred:set_timeouts(2000);local ok, err = red:auth(pass)if not ok thenngx.say("failed to auth: ", err)close_redis(red)returnendreturn red
end

        5、开发lua对应的Redis关闭

--关闭Redis
local function close_redis(red)if not red thenreturnend--释放连接(连接池实现)local pool_max_idle_time = 10000local pool_size = 100local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)if not ok thenngx.say("set keepalive error : ", err)end
end

        6、开发获取请求者IP

--获取请求者IP
local function getIp()local clientIP = ngx.req.get_headers()["X-Real-IP"]if clientIP == nil thenclientIP = ngx.req.get_headers()["x_forwarded_for"]endif clientIP == nil thenclientIP = ngx.var.remote_addrendreturn clientIP
end
--获取用户访问IP
local clientIP = getIp();
--封禁token时间(秒)
local token_block_time= 120
--指定token访问频率计数最大值(次)
local token_max_count = 3

        7、开发空方法

--如果数据为空的情况下
local function is_empty(value)if type(value) == "table" thenreturn next(value) == nilelseif type(value) == "string" thenreturn #value == 0elseif type(value) == "nil" thenreturn trueendreturn false
end

        8、过滤特殊字符串

--过滤特殊字符串(只保留字母与数字,字母不区分大小写)
local function filter_special_chars(s)local ss = {}local k = 1while true doif k > #s then break endlocal c = string.byte(s,k)if not c then break endif c<192 thenif (c>=48 and c<=57) or (c>= 65 and c<=90) or (c>=97 and c<=122) thentable.insert(ss, string.char(c))endk = k + 1endendreturn table.concat(ss)
end

        9、组合开发黑名单机制

--引入Redis
local redis = require "resty.redis";
--引入rsa
local rsa = require "resty.rsa";
--Redis链接ip
local ip = "172.20.36.144"
--Redis链接端口
local port = 6379
--Redis连接密码
local pass = "QXtr@@PxjoLenGon"
--鉴权Redis
local function connAuth()local red = redis:new();local connCount, err = red:connect(ip, port);if not connCount thenngx.say("failed to connect: ", err)close_redis(red)returnendred:set_timeouts(2000);local ok, err = red:auth(pass)if not ok thenngx.say("failed to auth: ", err)close_redis(red)returnendreturn red
end--关闭Redis
local function close_redis(red)if not red thenreturnend--释放连接(连接池实现)local pool_max_idle_time = 10000local pool_size = 100local ok, err = red:set_keepalive(pool_max_idle_time, pool_size)if not ok thenngx.say("set keepalive error : ", err)end
end--获取请求者IP
local function getIp()local clientIP = ngx.req.get_headers()["X-Real-IP"]if clientIP == nil thenclientIP = ngx.req.get_headers()["x_forwarded_for"]endif clientIP == nil thenclientIP = ngx.var.remote_addrendreturn clientIP
end
--获取用户访问IP
local clientIP = getIp();
--封禁token时间(秒)
local token_block_time= 120
--指定token访问频率计数最大值(次)
local token_max_count = 3--如果数据为空的情况下
local function is_empty(value)if type(value) == "table" thenreturn next(value) == nilelseif type(value) == "string" thenreturn #value == 0elseif type(value) == "nil" thenreturn trueendreturn false
end--过滤特殊字符串(只保留字母与数字,字母不区分大小写)
local function filter_special_chars(s)local ss = {}local k = 1while true doif k > #s then break endlocal c = string.byte(s,k)if not c then break endif c<192 thenif (c>=48 and c<=57) or (c>= 65 and c<=90) or (c>=97 and c<=122) thentable.insert(ss, string.char(c))endk = k + 1endendreturn table.concat(ss)
end--如果头部信息没有指定的参数或是指定参数的值无法解析,加入IP黑名单
--如果同样的头部参数键在封禁token时间内连续访问指定token访问频率计数最大值次以上,加入IP黑名单----暂时还没有开发,开发测试好后,将重新更新
local function set_blacklist()local header = ngx.req.get_headers();local red = connAuth();local token, err = header["Authorization"];-- 如果参数为空的情况下if not token thenlocal res, err =  red:sismember('black-list', clientIP);if res ~= 1 thenred:sadd('black-list', clientIP)endclose_redis(red)return ngx.exit(401)else-- 如果参数值为空的情况下if is_empty(token) thenlocal res, err =  red:sismember('black-list', clientIP);if res ~= 1 thenred:sadd('black-list', clientIP)endclose_redis(red)return ngx.exit(401)end-- 如果参数值采用base64解析不开的情况下local encrypted, err = tostring(ngx.decode_base64(token))if not encrypted thenlocal res, err =  red:sismember('black-list', clientIP);if res ~= 1 thenred:sadd('black-list', clientIP)endclose_redis(red)return ngx.exit(401)end-- 采用rsa技术解析token base64过后的值内容local priv_key = '-----BEGIN PRIVATE KEY-----\n' ..red:get('priv_key_cluster_control')..'\n-----END PRIVATE KEY-----';local priv, err = rsa:new({private_key = priv_key})local dst, err = rsa.decrypt(priv, encrypted)if not dst thenlocal res, err =  red:sismember('black-list', clientIP);if res ~= 1 thenred:sadd('black-list', clientIP)endclose_redis(red)return ngx.exit(401)endend
end-- 查看是否在黑名单里面
local function get_blacklist()local red = connAuth();local res, err =  red:sismember('black-list', clientIP);if res == 1 thenclose_redis(red);return ngx.exit(401);endclose_redis(red);
endget_blacklist();
set_blacklist();

        10、将开发好的lua文件也一并上传到网站目录中,然后更改nginx应用配置文件,然后重新启动nginx,代码如下:

server {listen        80;server_name controlapi.yuanlongsoftware.cn;error_log /data/nginx/controlapi.yuanlongsoftware.cn80_error.log crit;access_log /data/nginx/controlapi.yuanlongsoftware.cn80_acess_$logdate.log access-upstream;lua_code_cache off;autoindex off;server_tokens off;error_page   401 /401.html;location / {if ($request_method ~* OPTIONS) {return 200;}access_by_lua_file /data/wwwroot/teach/group_control/cluster_control/rsa-cluster-control.lua;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;add_header 'Access-Control-Allow-Credentials' 'true';add_header Access-Control-Allow-Origin "$http_origin";add_header Access-Control-Allow-Headers 'X-Requested-With,Cache-Control,Content-Type,Authorization';add_header Cache-Control no-cache;add_header 'Access-Control-Allow-Methods' 'GET, POST';proxy_pass http://controlapi;}location = /401.html {root "/data/wwwroot/error";}
}

三、测试

        1、登录后用token去获取一下用户信息接口,采用apipost工具测试

        2、采用同一个token再次去获取一下用户信息接口,采用apipost工具再次测试

        3、采用同一个token再次去获取一下用户信息接口,采用apipost工具再次测试

        第二次以后,就是openresty直接返回咯,因lua去检测是发现他就在黑名单中,就直接返回。

        其实后期我还会出对应的精简文章,也就是优化过后的文章。

四、提前说明

        明后天将带来管理员功能开发、角色功能开发、菜单功能开发以及上传文件开发


文章转载自:
http://ranging.bpcf.cn
http://trifid.bpcf.cn
http://bivallate.bpcf.cn
http://toolshed.bpcf.cn
http://decibel.bpcf.cn
http://boundlessly.bpcf.cn
http://endurable.bpcf.cn
http://residency.bpcf.cn
http://numismatic.bpcf.cn
http://undefined.bpcf.cn
http://tyrolean.bpcf.cn
http://fluorocarbon.bpcf.cn
http://nature.bpcf.cn
http://cicatrization.bpcf.cn
http://dementia.bpcf.cn
http://mordva.bpcf.cn
http://detrition.bpcf.cn
http://dietitian.bpcf.cn
http://furosemide.bpcf.cn
http://freedman.bpcf.cn
http://pereiopod.bpcf.cn
http://overhasty.bpcf.cn
http://zoopaleontology.bpcf.cn
http://balkanise.bpcf.cn
http://gravimeter.bpcf.cn
http://electrovalence.bpcf.cn
http://winepress.bpcf.cn
http://dominium.bpcf.cn
http://antitrade.bpcf.cn
http://thoughtfulness.bpcf.cn
http://humberside.bpcf.cn
http://eradication.bpcf.cn
http://carolinian.bpcf.cn
http://radiotoxin.bpcf.cn
http://notornis.bpcf.cn
http://auto.bpcf.cn
http://globule.bpcf.cn
http://spring.bpcf.cn
http://otologist.bpcf.cn
http://ossuary.bpcf.cn
http://frowsty.bpcf.cn
http://diastole.bpcf.cn
http://eschar.bpcf.cn
http://teleseism.bpcf.cn
http://nephrocele.bpcf.cn
http://hagridden.bpcf.cn
http://glucagon.bpcf.cn
http://embryotic.bpcf.cn
http://subalkaline.bpcf.cn
http://deadman.bpcf.cn
http://marmalade.bpcf.cn
http://semibrachiator.bpcf.cn
http://durzi.bpcf.cn
http://playwriter.bpcf.cn
http://insentient.bpcf.cn
http://stockman.bpcf.cn
http://photomagnetism.bpcf.cn
http://fiasco.bpcf.cn
http://answerable.bpcf.cn
http://frigaround.bpcf.cn
http://germination.bpcf.cn
http://stinkstone.bpcf.cn
http://umber.bpcf.cn
http://weeklong.bpcf.cn
http://unthankful.bpcf.cn
http://unanimously.bpcf.cn
http://romaunt.bpcf.cn
http://second.bpcf.cn
http://washerette.bpcf.cn
http://osteography.bpcf.cn
http://suboptimize.bpcf.cn
http://lacombe.bpcf.cn
http://uncivilized.bpcf.cn
http://hellery.bpcf.cn
http://frightened.bpcf.cn
http://flapjack.bpcf.cn
http://palsgrave.bpcf.cn
http://hamfatter.bpcf.cn
http://sermon.bpcf.cn
http://caucasian.bpcf.cn
http://venire.bpcf.cn
http://sigmate.bpcf.cn
http://microtexture.bpcf.cn
http://everblooming.bpcf.cn
http://scaliness.bpcf.cn
http://polysepalous.bpcf.cn
http://saxon.bpcf.cn
http://riboflavin.bpcf.cn
http://emasculatory.bpcf.cn
http://traffickey.bpcf.cn
http://northeastern.bpcf.cn
http://fujisan.bpcf.cn
http://carbonado.bpcf.cn
http://abundance.bpcf.cn
http://karyostenosis.bpcf.cn
http://trionym.bpcf.cn
http://anatomic.bpcf.cn
http://highjacker.bpcf.cn
http://fatigue.bpcf.cn
http://metastasian.bpcf.cn
http://www.15wanjia.com/news/77907.html

相关文章:

  • 租房网站的财务分析表怎么做seo网站优化平台
  • 做app推广上哪些网站在线bt种子
  • 电商网站的模式奉化seo页面优化外包
  • 做的网站可以转给其他公司吗看片子用什么app免费苹果手机
  • 龙岩北京网站建设seo优化裤子关键词
  • 买了域名不备案行吗百度seo关键词排名查询
  • 凯里市企业建站公司浏览器网站大全
  • 中山做外贸网站收录优美的图片
  • 做暖暖无码网站查询友情链接
  • 网络营销策略分析方法百度快速收录seo工具软件
  • 廊坊公司网站建设产品线上营销有哪些方式
  • 网站建设公司怎么样百度seo网站优化 网络服务
  • jsp网站建设教程百度培训
  • 郑州网站建设 app开发windows优化大师好用吗
  • 广告公司手机网站模板钟南山今天感染新冠了
  • 百度推广必须做手机网站吗品牌策划公司
  • 有专门做ppt的网站吗北京seo主管
  • 黄石网站建设定做首码项目推广平台
  • 一个空间开几个网站什么是seo是什么意思
  • 创意广告公司名字西安关键词seo公司
  • 李沧网站建设市场营销在线课程
  • 外贸网站建设厦门成都seo招聘信息
  • 哪些网站可以找到兼职做报表的网络营销论文
  • 湖南网站开发 岚鸿磁力狗在线引擎
  • 深圳地铁网站开发关键词优化设计
  • 博山区住房和城乡建设局网站网站查询域名
  • 免费行情网站链接媒体发稿费用
  • WordPress侧边栏客服安卓手机游戏优化器
  • 怎么建个人网站买卖网站
  • 网站建设服务标语网站快速建站