Unverified Commit ba0e8d78 authored by Jan Harasym's avatar Jan Harasym Committed by Jan Harasym
Browse files

Use environment variables and set USERMODE +B

parent e7cd1c49
#irc bot for mumble registation written in python3
import socket #for sockets
import sys #for exit
import time
#!/usr/bin/env python
"""
IRC Bot for registering IRC users with mumble's authentication backend
"""
from os import getenv
from sys import exit
import socket
import ssl
import re
# import time
# import re
import string
import random
import urllib.request
......@@ -17,20 +21,20 @@ def randompassword():
# irc server config
host="irc.darkscience.net"
port = 6697
botnick = "mumblebot"
nick = "mumblebot"
channel = "#voicechat"
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error as msg:
print('Failed to create socket. Error code: ' + str(msg[0]) + ' , Error message : ' + msg[1])
sys.exit();
exit(1)
try:
s.connect((host, port))
except socket.error:
print('Failed to connect to irc server')
sys.exit();
exit(1)
#warning: only use for testing to allow for self signed certs. This will disable SSL verification
#ctx = ssl.create_default_context()
......@@ -39,36 +43,42 @@ except socket.error:
irc = ssl.wrap_socket(s)
#irc.send(bytes("PASS " + password + "\n", 'utf-8'))
irc.send(bytes("USER "+ botnick +" "+ botnick +" "+ botnick +" :Mumble Bot\n", 'utf-8')) #user authentication
irc.send(bytes("NICK "+ botnick +"\n", 'utf-8'))
masterpassword = "thisneedstobelongandrandom"
mumbleserveraddress="domain.com"
registationlocation="/registration"
irc.send(bytes("USER {0} {0} {0} :Mumble Bot\n".format(nick), 'utf-8'))
irc.send(bytes("NICK " + nick + "\n", 'utf-8'))
masterpassword = getenv('BOT_PASSWORD', "thisneedstobelongandrandom")
mumbleserveraddress = getenv('MUMBLE_SERVER', 'domain.com')
registationlocation = "/registration"
registeringusers = []
joined = False
print("Connected to IRC server")
while True: #puts it in a loop
text=irc.recv(2040).decode("utf-8") #receive the text
print(text) #print text to console
while True:
data = irc.recv(1024).decode("utf-8")
if not data:
break
if text.find('PING') != -1: #check if 'PING' is found
text = data.decode("utf-8")
print(text)
if text.find('PING') != -1:
sendstring = 'PONG ' + text.split()[1] + '\r\n'
irc.send(bytes(sendstring, 'utf-8')) #returnes 'PONG' back to the server (prevents pinging out!)
if text.find(':NickServ!NickServ@services.darkscience.net') != -1 and joined == False:
irc.send(bytes("JOIN "+ channel +"\r\n", 'utf-8'))
joined=True
irc.send(bytes(sendstring, 'utf-8'))
if text.find(':NickServ!NickServ@services.darkscience.net') != -1 \
and joined is False:
irc.send(bytes("MODE +B +" + nick, 'utf-8')) # DS requires this
irc.send(bytes("JOIN " + channel + "\r\n", 'utf-8'))
joined = True
if text.find('PRIVMSG #voicechat :!register') != -1:
split_text = text.split("!")
nick = split_text[0].strip(':')
irc.send(bytes("PRIVMSG NickServ :ACC "+ nick + "\r\n", 'utf-8'))
irc.send(bytes("PRIVMSG NickServ :ACC " + nick + "\r\n", 'utf-8'))
registeringusers.append(nick)
for user in registeringusers:
if text.find(":NickServ!NickServ@services.darkscience.net NOTICE " + botnick + " :" + user + " ACC") != -1:
if text.find(":NickServ!NickServ@services.darkscience.net NOTICE " + nick + " :" + user + " ACC") != -1:
accstring = text.split(":")[2].strip()
if accstring == (user + " ACC 3"):
userpassword = randompassword()
fp = urllib.request.urlopen("https://" + mumbleserveraddress+ registationlocation +"?username=" + user + "&password="+hashlib.sha1(userpassword.encode()).hexdigest() + "&serverpassd=" + masterpassword)
fp = urllib.request.urlopen("https://" + mumbleserveraddress + registationlocation + "?username=" + user + "&password="+hashlib.sha1(userpassword.encode()).hexdigest() + "&serverpassd=" + masterpassword)
mybytes = fp.read()
response = mybytes.decode("utf8")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment