当前位置:   article > 正文

Python SQLite3 安装 OpenVP* Web管理后台_sqlite web管理

sqlite web管理

一、安装相关

yum install gcc gcc-c++ openssl openssl-devel pam-devel sqlite-devel

二、安装 Openvpn 服务器端

CentOS 7 安装 OpenVP*_tom.ma的博客-CSDN博客

三、添加 SQLite 认证

 1、下载

https://download.csdn.net/download/mshxuyi/87354476

  1. git clone https://gitee.com/mshxuyi/pam_sqlite3.git
  2. cd pam_sqlite3
  3. make
  4. cp pam_sqlite3.so /lib64/security/

2、添加 pam 认证文件

  1. vim /etc/pam.d/openvpn
  2. auth required pam_sqlite3.so db=/etc/openvpn/openvpn.db table=t_user user=username passwd=password expire=expire crypt=1
  3. account required pam_sqlite3.so db=/etc/openvpn/openvpn.db table=t_user user=username passwd=password expire=expire crypt=1

3、配置服务器

  1. vim /etc/openvpn/server.conf
  2. # 最后添加
  3. verify-client-cert none
  4. username-as-common-name
  5. plugin /usr/lib64/openvpn/plugins/openvpn-plugin-auth-pam.so openvpn
  6. script-security 3
  7. client-connect /etc/openvpn/server/connect.py
  8. client-disconnect /etc/openvpn/server/disconnect.py

4、配置客户端

  1. client
  2. dev tun
  3. proto tcp
  4. remote 192.168.1.71 1194
  5. resolv-retry infinite
  6. nobind
  7. persist-key
  8. persist-tun
  9. ca ca.crt
  10. # 注释这两行
  11. ;cert tomma.crt
  12. ;key tomma.key
  13. remote-cert-tls server
  14. tls-auth ta.key 1
  15. cipher AES-256-GCM
  16. comp-lzo
  17. verb 3
  18. auth-nocache
  19. # 加入这一行,使用用户名密码登录openvpn服务器
  20. auth-user-pass

 5、安装 python 相关

  1. # 安装 python3
  2. yum install python36 -y
  3. # 安装相关服务
  4. # Tornado:python编写的web服务器兼web应用框架
  5. # Peewee :Peewee是一个简单小巧的Python ORM框架
  6. pip3 install peewee tornado

 6、下载 openvpn-web

https://download.csdn.net/download/mshxuyi/87354473

 7、导入数据库

  1. cd /opt
  2. git clone https://gitee.com/mshxuyi/openvpn_web.git
  3. cd openvpn_web
  4. sqlite3 /etc/openvpn/openvpn.db < model/openvpn.sql

 8、新建 自动生成 logs 脚本,注意这两个文件设置执行权限

  1. vim /etc/openvpn/server/connect.py
  2. #!/usr/bin/python
  3. import os
  4. import time
  5. import sqlite3
  6. username = os.environ['common_name']
  7. trusted_ip = os.environ['trusted_ip']
  8. trusted_port = os.environ['trusted_port']
  9. local = os.environ['ifconfig_local']
  10. remote = os.environ['ifconfig_pool_remote_ip']
  11. timeunix= os.environ['time_unix']
  12. logintime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
  13. conn = sqlite3.connect("/etc/openvpn/openvpn.db")
  14. cursor = conn.cursor()
  15. query = "insert into t_logs(username, timeunix, trusted_ip, trusted_port, local, remote, logintime) values('%s','%s', '%s', '%s', '%s', '%s', '%s')" % (username, timeunix, trusted_ip, trusted_port, local, remote, logintime)
  16. cursor.execute(query)
  17. conn.commit()
  18. conn.close()
  1. vim /etc/openvpn/server/disconnect.py
  2. #!/usr/bin/python
  3. import os
  4. import time
  5. import sqlite3
  6. username = os.environ['common_name']
  7. trusted_ip = os.environ['trusted_ip']
  8. received = os.environ['bytes_received']
  9. sent = os.environ['bytes_sent']
  10. logouttime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time()))
  11. conn = sqlite3.connect("/etc/openvpn/openvpn.db")
  12. cursor = conn.cursor()
  13. query = "update t_logs set logouttime='%s', received='%s', sent= '%s' where username = '%s' and trusted_ip = '%s'" % (logouttime, received, sent, username, trusted_ip)
  14. cursor.execute(query)
  15. conn.commit()
  16. conn.close()
  1. chmod +x /etc/openvpn/server/connect.py
  2. chmod +x /etc/openvpn/server/disconnect.py

9、启动脚本

  1. # 重启 vpn
  2. systemctl start openvpn@server.service
  3. # 开启防火墙
  4. -A INPUT -p tcp -m state --state NEW -m tcp --dport 8000 -j ACCEPT
  5. # 启动
  6. python3 myapp.py &

10、进入后台

http://192.168.1.113:8000/login  账号:admin  密码:123456

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/739243
推荐阅读
相关标签
  

闽ICP备14008679号