设为首页 收藏本站
查看: 952|回复: 0

[经验分享] linux下的开源open v p n的自动化新建用户并发送邮件的shell脚本

[复制链接]

尚未签到

发表于 2019-1-27 15:22:05 | 显示全部楼层 |阅读模式
  PS: 所有v p n的字样全部屏蔽成了***了,真恶心

  由于商业版的ssl***等设备价格较贵,不如开源的来的方便,且能自己能通过脚本来减轻自己的工作,只需要在企业内部搭建好服务器后,在出口防火墙做外网映射即可,具体的安装步骤不介绍了。

  本脚本包含自动新建账号、证书并发送到用户的邮箱中,用户名以邮箱的前缀命名

  daily=`date +%Y%m%d-%H%M`   
confdir="/etc/open***/config"   

  #open***的配置目录,该下面有server.crt ca.crt ca.key psw-file server.conf等文件


  workdir="/home/appadm/open***-2.4.4"    #open***解压后的目录,主要会用到easy-rsa/2.0下的目录
userdir="/home/appadm/×××User"     #将生成的用户信息拷贝到该目录下
adduser() {
##################账号密码创建#############
####if账号不存在则新建,else返回已存在#####
read -p "Please input username need to be added: " acc
usermail=$acc@qq.cn
userchallpass=$usermail
if [[ ! -e $workdir/easy-rsa/2.0/keys/${acc}.crt ]];then
   cd $workdir/easy-rsa/2.0/
   ./vars
   sleep 2
   source ./vars
   sleep 2
############以下为证书生成###############
expect -c "
spawn $workdir/easy-rsa/2.0/build-key $acc
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"$usermail\r\"}
        }
expect {
        \"*\" {send \"$userchallpass\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }
expect {
        \"*\" {send \"y\r\"}
        }
expect {
        \"*\" {send \"y\r\"}
        }
expect {
        \"*\" {send \"\r\"}
        }

expect eof "
##########################################
     mkdir -p $userdir/$acc
     cd $workdir/easy-rsa/2.0/keys
     cp ${acc}.crt ${acc}.key ta.key ca.crt $userdir/$acc
     cp ${acc}.* $userdir/keys
     cd $userdir
     cp client.conf ./$acc/${acc}.o***
     cd ./$acc
     sed -i "s/cert client.crt/cert ${acc}.crt/g" ./$acc.o***
     sed -i "s/key client.key/key ${acc}.key/g" ./$acc.o***
  
     tar -zcvf ./${acc}.tar.gz ${acc}.crt ${acc}.key ${acc}.o*** ta.key ca.crt
     echo -e "\033[32m Cert user $acc has been created \033[0m"
     cp $confdir/psw-file $confdir/psw-file.bak
     if [[ `cat $confdir/psw-file | grep "$acc"` == "" ]];then
        accpass=`> $confdir/psw-file
     fi
     echo -e "\033[32m Now $acc userid and password has been generated \033[0m"
else
   echo -e "\033[33m User $acc exists\033[0m"
fi
   echo -e "Here is user's certificate:$userdir/$acc\n"
   sleep 1
   echo -e "Here is user's account and password:$confdir/psw-file\n"
##############以下为open***账号密码证书以及客户端自动发送##################################################
   userpass=`more $confdir/psw-file  | grep $acc | awk '{print $2}'`
   to=$usermail
   #to="xxxxxx@qq.cn"
   secr="xxxxx@qq.cn"
   subject="$acc's open*** information"
   body="Hello,your open*** account is:  $acc,and your password is:  $userpass"
   /app/comm/sendEmail-v1.56/sendEmail -f xx@xx.cn -t "$to"  -bcc "$secr" -s smtp.exmail.qq.com -u "$subject" \
  -a "$userdir/$acc/$acc.tar.gz" "$userdir/open***-install-2.4.4-I601.exe" "$userdir/open***-readme.docx"\
-o message-content-type=html -o message-charset=utf8 -xu xxwxx@xxxxx.cn-xp "Sg5d_JE9xVDtPkdz" -m "$body" &>>/tmp/open***mail.log
########################################################################################################################
cd /home/appadm
./useforopen***.sh
}
#############################以下为删除用户######################################################################################
deluser() {
   read -p "Input the username want to delete: " deluser
   cd $workdir/easy-rsa/2.0/
   ./vars
   sleep 1
   source ./vars
   sleep 1
   ./revoke-full $deluser &>> /tmp/open***log.txt
   sleep 2
   if [[ `more /tmp/open***log.txt|grep "Already revoked"` != "" ]];then
       echo -e "\033[31m Do nothing,user $deluser has been eliminated before\033[0m"
   elif [[ `more /tmp/open***log.txt|grep "Error opening "$deluser".crt "$deluser".crt"` != "" ]];then
       echo -e "\033[31m User $deluser not exist \033[0m"
   else
       cp $confdir/psw-file $confdir/psw-file.bak"$daily"
       echo -e "\033[44;37m Now backup the lastest user account \033[0m"
       sleep 1
       sed -i "/^$deluser.*/d" $confdir/psw-file
       echo -e "\033[44;37m Now delete use $deluser and password \033[0m"
       sleep 1
       cd $userdir
       mv $deluser ./deleteuser
#       cd $workdir/easy-rsa/2.0/keys
#       mv "$deluser".* $workdir/user/deleteuser
       echo -e "\033[44;37m User $deluser disappeared now\033[0m"
       cd $confdir
       ./restartopen***.sh
  fi
cd /home/appadm
./useforopen***.sh
}
################################################################
echo -e "
        ##########################################
        ### 1. create a new user                                            ###
        ### 2. delete an unused  user                                   ###
        ### 3. exit                                                                  ###
        ##########################################"
  
read -p "Input your choice: " choice
case $choice in
    "1")
        adduser
        ;;
    "2")
        deluser
        ;;
    "3")
        exit 0
        ;;
     *)
        echo "Usage $0 {1|2|3}"
        ;;
esac






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-668356-1-1.html 上篇帖子: 五分钟利用docker搭建好open***服务环境 下篇帖子: centos6.5 Open×××服务搭建部署,访问内网服务器
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表