#!/usr/local/env python3
import os.path
def remove_user():
all_user = os.listdir(ccd_dir)
for u in all_user:
per_file = os.path.join(ccd_dir, u)
if u.endswith(_client):
print(f"跳過刪除${per_file}")
else:
os.remove(per_file)
def create_user():
for i in user_list:
print(i)
c_id = i.split(:)[0]
user = i.split(:)[1]
template_format = user_template.format(c_id)
path_join = os.path.join(ccd_dir, user)
with open(path_join, a) as f:
f.write(template_format)
if __name__ == __main__:
user_list = [
"31:chenhui",
"32:huxinyan",
"33:linhuipeng",
"34:liuchao",
"35:liuzhixing",
"36:sunxiangxiang",
"37:wangzhiwei",
"38:yanmingshun",
"39:zhangdipeng",
"40:zhaotongzhou",
"41:zhujia",
"42:yangjia",
"53:lijiachun",
"56:gaoxirui",
"57:xiekai",
"58:suyingying",
"59:yangke",
"61:zhengchengzhi",
"62:zhangqiang",
"63:shipengyu",
"64:houqinghua",
"65:zhangru",
"66:luoqiangqiang",
"72:hhjie",
]
user_template = """ifconfig-push 10.158.99.{0} 255.255.255.0
push "route 10.77.10.0 255.255.255.0 vpn_gateway"
push "route 192.178.0.0 255.255.255.0 vpn_gateway"
push "route 10.128.78.0 255.255.255.128 vpn_gateway"
push "route 10.15.107.0 255.255.255.0 vpn_gateway"
push "route 172.18.100.0 255.255.255.0 vpn_gateway"
"""
ccd_dir = "/Users/hhjie/gitlab.hhjie.top/hhjie/hhjie-devops/scripts/rebuild_openvpn_user/ccd"
remove_user()
create_user()