Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patched telegram issues #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions openvpn-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -518,28 +518,42 @@ verb 3" > /etc/openvpn/server/client-common.txt
read -p "What is the group ID ? : " telegram_group_id
touch /usr/bin/ovpn-client-connect /usr/bin/ovpn-client-disconnect
pip3 install python-telegram-bot
echo '#!/usr/bin/env python3' > /usr/bin/ovpn-client-connect
echo 'import telegram' >> /usr/bin/ovpn-client-connect
echo 'import os' >> /usr/bin/ovpn-client-connect
echo "bot = telegram.Bot(token='$telegram_bot_token')" >> /usr/bin/ovpn-client-connect
echo "server_ip = os.popen('curl ifconfig.me').read()" >> /usr/bin/ovpn-client-connect
echo "client_name = str(os.getenv('common_name'))" >> /usr/bin/ovpn-client-connect
echo "client_real_ip = str(os.getenv('trusted_ip'))" >> /usr/bin/ovpn-client-connect
echo "client_virtual_ip = str(os.getenv('ifconfig_pool_remote_ip'))" >> /usr/bin/ovpn-client-connect
echo 'message = "*[OpenVPN Server : " + server_ip + "]* client *" + client_name + "* is connected (is *" + client_real_ip + "* and has *" + client_virtual_ip + "*)"' >> /usr/bin/ovpn-client-connect
echo "bot.send_message('$telegram_group_id', message, parse_mode=telegram.ParseMode.MARKDOWN)" >> /usr/bin/ovpn-client-connect
echo '#!/usr/bin/env python3' > /usr/bin/ovpn-client-disconnect
echo 'import telegram' >> /usr/bin/ovpn-client-disconnect
echo 'import os' >> /usr/bin/ovpn-client-disconnect
echo "bot = telegram.Bot(token='$telegram_bot_token')" >> /usr/bin/ovpn-client-disconnect
echo "server_ip = os.popen('curl ifconfig.me').read()" >> /usr/bin/ovpn-client-disconnect
echo "client_name = str(os.getenv('common_name'))" >> /usr/bin/ovpn-client-disconnect
echo "client_real_ip = str(os.getenv('trusted_ip'))" >> /usr/bin/ovpn-client-disconnect
echo "client_virtual_ip = str(os.getenv('ifconfig_pool_remote_ip'))" >> /usr/bin/ovpn-client-disconnect
echo 'message = "*[OpenVPN Server : " + server_ip + "]* client *" + client_name + "* has disconnected (was *" + client_real_ip + "* and had *" + client_virtual_ip + "*")' >> /usr/bin/ovpn-client-disconnect
echo "bot.send_message('$telegram_group_id', message, parse_mode=telegram.ParseMode.MARKDOWN)" >> /usr/bin/ovpn-client-disconnect
cat << EOF | sed 's/$telegram_bot_token/'$telegram_bot_token'/g' | sed 's/$telegram_group_id/'$telegram_group_id'/g' > /usr/bin/ovpn-client-connect
#!/usr/bin/env python3
import requests
import os
botToken = '$telegram_bot_token'
server_ip = os.popen('curl ifconfig.me').read()
client_name = str(os.getenv('common_name'))
client_real_ip = str(os.getenv('trusted_ip'))
client_virtual_ip = str(os.getenv('ifconfig_pool_remote_ip'))
message = "*[OpenVPN Server : " + server_ip + "]* client *" + client_name + "* is connected (is *" + client_real_ip + "* and has *" + client_virtual_ip + "*)"
message = message.replace(".","\\.")
message = message.replace("(","\\(")
message = message.replace(")","\\)")
postBody = {"chat_id":"$telegram_group_id","text":message, "parse_mode":"MarkdownV2"}
url = "https://api.telegram.org/bot" + botToken + "/sendMessage"
x = requests.post(url, json = postBody)
EOF
cat << EOF | sed 's/$telegram_bot_token/'$telegram_bot_token'/g' | sed 's/$telegram_group_id/'$telegram_group_id'/g' > /usr/bin/ovpn-client-disconnect
#!/usr/bin/env python3
import requests
import os
botToken = '$telegram_bot_token'
server_ip = os.popen('curl ifconfig.me').read()
client_name = str(os.getenv('common_name'))
client_real_ip = str(os.getenv('trusted_ip'))
client_virtual_ip = str(os.getenv('ifconfig_pool_remote_ip'))
message = "*[OpenVPN Server : " + server_ip + "]* client *" + client_name + "* has disconnected (was *" + client_real_ip + "* and had *" + client_virtual_ip + "*)"
message = message.replace(".","\\.")
message = message.replace("(","\\(")
message = message.replace(")","\\)")
postBody = {"chat_id":"$telegram_group_id","text":message, "parse_mode":"MarkdownV2"}
url = "https://api.telegram.org/bot" + botToken + "/sendMessage"
x = requests.post(url, json = postBody)
EOF
chown nobody:root /usr/bin/ovpn-client-connect /usr/bin/ovpn-client-disconnect
chmod +x nobody:root /usr/bin/ovpn-client-connect /usr/bin/ovpn-client-disconnect
chmod +x /usr/bin/ovpn-client-connect /usr/bin/ovpn-client-disconnect
echo "script-security 2" >> /etc/openvpn/server/server.conf
echo "client-connect /usr/bin/ovpn-client-connect" >> /etc/openvpn/server/server.conf
echo "client-disconnect /usr/bin/ovpn-client-disconnect" >> /etc/openvpn/server/server.conf
Expand Down