最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

0基礎上手python、PHP編程,域自助服務臺,具備第三方APP提醒,自助改密解鎖等功能

2023-06-11 21:36 作者:王忘杰-王土狗  | 我要投稿


王工自研域自助服務臺架構(gòu)圖,具備長期未改密企業(yè)微信提醒、自助改密解鎖等功能
全面對標寧盾微軟AD自助修改密碼解決方案
https://www.nington.com/solution-adpassword/
每年可為公司節(jié)省5W-10W元

說明
王工域控為windows2022,Self Service Password搭建在OracleLinux8上,python版本為python3最新版本,PHP為OracleLinux8默認源中的PHP7

預覽
通知改密

自助改密

架構(gòu)解析:
1、域控上域賬戶維護pager屬性(尋呼機),修改為企業(yè)微信ID
2、域控運行掃描腳本,通過計算上次修改密碼時間,超過指定日期,進行企業(yè)微信提醒;如果未維護pager屬性,寫入日志
3、Self Service Password域控自助服務臺二次開發(fā),改為企業(yè)微信接收驗證碼改密
4、進行企業(yè)微信提醒時,先查詢redis緩存,如果access_token不存在,則獲取一次,如果存在,直接使用,緩存5400秒自動過期。
5、建立企業(yè)微信應用,可參考我的zabbix文章

搭建前提
1、已維護域控pager屬性為企業(yè)微信userid,此信息需要企業(yè)微信管理員后臺查詢。
2、已正確部署Self Service Password,可以看我之前的文章。
3、已部署redis,建議使用docker部署,一定要設置redis密碼
4、已為php增加php-redis擴展

docker一鍵部署redis
紅帽系系統(tǒng)默認為podman替代docker

podman pull redis
podman run --restart=always -p 6379:6379 --name myredis -d redis ?--requirepass passwd@123

掃描腳本:
掃描腳本同樣有兩部分組成,第一部分是powershell腳本,用于獲取域用戶信息
可指定OU、可自定義要獲取的用戶屬性,生成的文件放在C盤根目錄下1.txt,與python腳本對應
adgetuser.ps1

Get-ADUser -Filter 'Name -like "*"' -SearchBase "OU=測試組,OU=用戶OU,DC=90apt,DC=com" -Properties * | Select-Object name,passwordlastset,pager > c:/1.txt

運行結(jié)果


name ? passwordlastset ? ? pager ? ? ?
---- ? --------------- ? ? ----- ? ? ?
王忘杰1 ? 2023/5/18 16:39:05 ?WangWangJie1 ? ?
王忘杰2 2022/9/26 16:50:41 ?WangWangJie2

第二部分是掃描通知腳本,由主python文件和配置文件ad.config組成,運行后生成errlog.txt日志文件
ad.config

屬性說明
corpid:
appsecret:
agentid:
content:內(nèi)容1
content1:內(nèi)容2
content2:內(nèi)容3
admin:閑置屬性
ip:redis地址
port:redis端口
passwd:redis密碼
passwddate:密碼多少天未修改進行提醒

{
"corpid" : "xxxx",
"appsecret" : "xxxx",
"agentid" : "xxxx",
"content" : "親愛的 ",
"content1" : " 域用戶 :\n您的計算機域賬戶已經(jīng)超過 ",
"content2" : " 天沒有修改密碼了(電腦登錄密碼),請您立即更改。\n重置密碼過程請遵循以下原則:\n○密碼長度最少 8 位;\n○密碼中不可出現(xiàn)公司和本人中英文拼寫\n○密碼符合復雜性需求(大寫字母、小寫字母、數(shù)字和符號四種中必須有三種)\n操作方式:\n您可以通過 自助密碼服務臺http://xx/修改密碼,在公司內(nèi)網(wǎng)中,手機、筆記本、臺式機均可訪問",
"admin" : "xxxx",
"ip" : "xxxx",
"port" : "xxxx",
"passwd" : "xxxx",
"passwddate" : xx
}

主python文件

import requests,json,redis,time,logging
from datetime import datetime, timedelta

def get_weixintoken():
? #獲取微信token
? token_url = 'https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=' + config[0] + '&corpsecret=' + config[1]
? req = requests.get(token_url)
? accesstoken = req.json()['access_token']
? return accesstoken

def get_redistoken():
? readredis = redis.Redis(connection_pool=redis.ConnectionPool(host=config[7],port=config[8],password=config[9],decode_responses=True))
? if readredis.get('key') == None:
? ? ?readredis.set('key', get_weixintoken(),ex=5400)
? ? ?return (readredis.get('key'))
? else:
? ? ?return readredis.get('key')

def post_weixin(userweixin,content):
? body = {
? ? ?"touser": userweixin,
? ? ?"msgtype": "text",
? ? ?"agentid": config[2],
? ? ?"text": {
? ? ? ? "content": content
? ? ?}
? }
? postweixin = requests.post(
? ? ?'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='+get_redistoken(),data=json.dumps(body))
? return(postweixin.text)

def get_config():
? config = json.loads(open("ad.config", encoding='utf-8').read())
? return [config['corpid'],config['appsecret'],config['agentid'],config['content'],config['content1'],config['content2'],config['admin'],config['ip'],config['port'],config['passwd'],config['passwddate']]

def user_check():
? f = open("C:\\1.txt", "r", encoding='utf-16')
? lines = f.readlines()
? f = open('errlog.txt', 'w')
? for line in lines:
? ? ?try:
? ? ? ? x = line.replace("/", "-")
? ? ? ? y = x.split()
? ? ? ? time_1 = y[1]
? ? ? ? time_2 = time.strftime("%Y-%m-%d", time.localtime())
? ? ? ? time_1_struct = datetime.strptime(time_1, "%Y-%m-%d")
? ? ? ? time_2_struct = datetime.strptime(time_2, "%Y-%m-%d")
? ? ? ? day = (time_2_struct - time_1_struct).days
? ? ? ? userweixin = y[3]
? ? ? ? username= y[0]
? ? ? ? if day > config[10]:
? ? ? ? ? ?day = str(day)
? ? ? ? ? ?time.sleep(1)
? ? ? ? ? ?try:
? ? ? ? ? ? ? post = post_weixin(userweixin,config[3]+username+config[4]+day+config[5])
? ? ? ? ? ? ? postjson=json.loads(post)
? ? ? ? ? ? ? if postjson['errmsg'] != "ok":
? ? ? ? ? ? ? ? ?f.write("發(fā)送失敗,可能微信號錯誤 " + userweixin+"\n")

? ? ? ? ? ?except :
? ? ? ? ? ? ? None

? ? ? ? else:
? ? ? ? ? ?None
? ? ?except:
? ? ? ? f.write("沒有微信號 "+ line)
? f.close()



config = get_config()
#post_weixin()
user_check()

腳本使用
編譯為EXE文件,和ad.config,放在域控服務器通過定時任務運行即可。

Self Service Password企業(yè)微信腳本
項目目錄/usr/share/self-service-password/
配置文件/usr/share/self-service-password/conf/config.inc.local.php
配置文件中修改短信通知方式

## SMS
# Use sms
$use_sms = true;
# SMS method (mail, api)
$sms_method = "api";
$sms_api_lib = "lib/weixin.inc.php";
# GSM number attribute
$sms_attributes = array( "pager" );

編寫企業(yè)微信通知腳本
/usr/share/self-service-password/lib/weixin.inc.php

<?php
//連接本地的 Redis 服務
function get_token(){
? ? ? ?$redis = new Redis();
? ? ? ?$redis->connect('修改用自己的IP地址', 修改用自己的端口);
? ? ? ?$redis->auth('修改用自己的redis密碼');
? ? ? ?$key = $redis->get("key");
? ? ? ?if ($key)
? ? ? ?{
? ? ? ? ? ? ? ?return $key;
? ? ? ?}
? ? ? ?else
? ? ? ?{
? ? ? ? ? ? ? ?$url='https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=修改用自己的&corpsecret=修改用自己的';
? ? ? ? ? ? ? ?$jsondb = file_get_contents($url);
? ? ? ? ? ? ? ?$jsondb = json_decode($jsondb, true);
? ? ? ? ? ? ? ?$key = $jsondb['access_token'];
? ? ? ? ? ? ? ?$redis->set("key", $key);
? ? ? ? ? ? ? ?$redis->expire("key", 5400);
? ? ? ? ? ? ? ?return $key;
? ? ? ?}
}

function send_sms_by_api($mobile, $message) {
? ? ? ?$postdata = array(
? ?'touser' => "$mobile",
? ?'msgtype' => 'text',
? ?'agentid' => '修改用自己的',
? ? ? ?'text' => array(
? ? ? ?'content' => "$message"
? ? ? ?)

? ? ? ?);

? ?$ch = curl_init();
? ?curl_setopt($ch, CURLOPT_URL, 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=' . get_token());
? ?curl_setopt($ch, CURLOPT_POST, true);
? ?curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postdata));
? ?curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
? ?curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
? ?curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
? ?$errmsg = json_decode(curl_exec($ch))->errmsg;
? ? ? ?if ($errmsg=="ok")
? ? ? ?{
? ? ? ? ? ? ? ?return 1;
? ? ? ?}
? ? ? ?else
? ? ? ?{
? ? ? ? ? ? ? ?return 0;
? ? ? ?}


}

?>

修改中文顯示
比如把短信修改成企業(yè)微信,可直接修改語言文件

/usr/share/self-service-password/lang/zh-CN.inc.php

PHP安裝redis擴展

總結(jié)
簡單



0基礎上手python、PHP編程,域自助服務臺,具備第三方APP提醒,自助改密解鎖等功能的評論 (共 條)

分享到微博請遵守國家法律
会宁县| 婺源县| 洞头县| 浦城县| 绥芬河市| 新邵县| 马边| 云龙县| 三台县| 六盘水市| 广汉市| 封开县| 湘乡市| 全南县| 汝南县| 鸡东县| 镇沅| 三原县| 蕉岭县| 象山县| 车险| 容城县| 荔波县| 分宜县| 平陆县| 昭通市| 武平县| 襄樊市| 久治县| 汉寿县| 武平县| 清原| 云阳县| 临夏县| 南昌县| 图木舒克市| 宁夏| 旌德县| 胶州市| 永城市| 寿宁县|