shell脚本 微信/钉钉验证登录服务器
2024-10-20 16:29:21
一.简介
登录用户需要二次验证码进行验证
可以配合 监控用户登录,发送通知给企业微信/钉钉 来使用
脚本放到/etc/profile.d/ 目录,登录的时候自动触发
二.微信脚本
1.需要修改CropID、Secret、 local int AppID 、local UserID 、local PartyID 五项内容
#!/bin/bash
#微信配置
CropID='ww022xxxxxxxx'
Secret='RauJ_-t-LxBhfEN7g1shxxxxxxxxxxxx'
APIURL=https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$CropID&corpsecret=$Secret
TOKEN=$(/usr/bin/curl -s -G $APIURL | awk -F\ '{print $10}')
POSTURL=https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=$TOKEN
function body() {
local int AppID=1000004
local UserID=xxxx
local PartyID=2
printf '{\n'
printf '\ttouser: '$UserID\,\n
printf '\ttoparty: '$PartyID\,\n
printf '\tmsgtype: text,\n'
printf '\tagentid: '$AppID\,\n
printf '\ttext: {\n'
printf '\t\tcontent: '$Msg\\n
printf '\t},\n'
printf '\tsafe:0\n'
printf '}\n'
}
Status=who am i | awk '{print $NF}' | sed 's/(//g' | sed 's/)//g'
if [ -n $Status ]; then
Msg=有用户上线请注意:\n主机名:hostname\n主机ip:ifconfig ens33 | grep inet | awk 'NR==1{ print $2}'\n登录用户:whoami\n地址来源:$Status
/usr/bin/curl -s --data-ascii $(body xxxxxx $2) $POSTURL 2>&1 > /dev/null
fi
2.钉钉脚本修改内容 Dingding_Url
#!/bin/bash
###############################
# 2020-3-26 #
# #
# 通过钉钉接口发送验证码二次验证 #
###############################
trap 1
read -p 请输入你的钉钉手机号: user
if [ ${#user} -ne 11 ]; then
echo 请出入有效手机号码
sleep 1
logout
fi
#钉钉配置
Dingding_Url=https://oapi.dingtalk.com/robot/send?access_token=
Status=who am i | awk '{print $NF}' | sed 's/(//g' | sed 's/)//g'
if [ -n $Status ]; then
RANDOM=$(date +%s)
echo $RANDOM >/tmp/pass.txt
PASS=tail -n 1 /tmp/pass.txt
Msg=你的验证码是:$PASS
curl ${Dingding_Url} -H 'Content-Type: application/json' -d
{
'msgtype': 'text',
'text': {'content': '${Msg}\n'},
'at': {'atMobiles': [ '${user}' ], 'isAtAll': false}
} > /dev/null 2>&1
trap 2
read -p 请输入验证码: code
if [ $code != xuewenlong ] && [ $code != $PASS ]; then
echo 验证码验证失败!!!
sleep 1
logout
else
echo Welcome to shvm01 System
fi
fi
最新文章
- OpenGL快问快答
- 关于MVC EF架构及Repository模式的一点心得
- 第七章:利用AdaBoost元算法提高分类性能
- 根据键盘调整textField(多个)位置使其不会被键盘挡住
- jq实现点击弹出框代码
- WorldChat.lua --世界聊天
- mysql 5.6并行复制事件分发机制
- paip.指针 引用 c++ java的使用总结.
- mysql导入导出
- CSS skills: 3) show sub-navigate items when mouse hove on nav-item
- 我的第一篇——nginx+naxsi总结篇1
- C#DbHelperOra,Oracle数据库帮助类 (转载)
- phpcms v9 表单向导里添加图片字段,提示会话过期,请重新登陆
- C# - 使用皮肤
- awk统计文本里某一列重复出现的次数
- HTTP二、HTTP请求处理过程的七个步骤
- linux 命令 — download
- 我的微软最有价值专家(Microsoft MVP)之路
- Webserver管理系列:6、网络和共享中心的安全配置
- python locust 性能测试:locust安装和一些参数介绍
热门文章
- Python 爬取 拉钩
- 基于ambari搭建hadoop生态圈大数据组件
- Python介绍和安装
- [cf1137F]Matches Are Not a Child's Pla
- [atARC121F]Logical Operations on Tree
- [cf1184E]Daleks' Invasion
- CSS-sprit 雪碧图
- Redis分布式缓存剖析及大厂面试精髓v6.2.6
- python中else的三种用法
- IDEA 配置背景颜色(豆沙绿)