.BANCHO. Add Sentry to IRC server
This commit is contained in:
parent
95df629e1c
commit
a89ad31017
|
@ -60,7 +60,8 @@ class config:
|
||||||
self.config.get("debug","time")
|
self.config.get("debug","time")
|
||||||
|
|
||||||
self.config.get("sentry","enable")
|
self.config.get("sentry","enable")
|
||||||
self.config.get("sentry","dns")
|
self.config.get("sentry","banchodns")
|
||||||
|
self.config.get("sentry","ircdns")
|
||||||
|
|
||||||
self.config.get("discord","enable")
|
self.config.get("discord","enable")
|
||||||
self.config.get("discord","boturl")
|
self.config.get("discord","boturl")
|
||||||
|
@ -106,7 +107,8 @@ class config:
|
||||||
|
|
||||||
self.config.add_section("sentry")
|
self.config.add_section("sentry")
|
||||||
self.config.set("sentry", "enable", "0")
|
self.config.set("sentry", "enable", "0")
|
||||||
self.config.set("sentry", "dns", "")
|
self.config.set("sentry", "banchodns", "")
|
||||||
|
self.config.set("sentry", "ircdns", "")
|
||||||
|
|
||||||
self.config.add_section("discord")
|
self.config.add_section("discord")
|
||||||
self.config.set("discord", "enable", "0")
|
self.config.set("discord", "enable", "0")
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import sys
|
import sys
|
||||||
|
import traceback
|
||||||
import socket
|
import socket
|
||||||
import select
|
import select
|
||||||
import time
|
import time
|
||||||
|
@ -8,6 +9,7 @@ from helpers import logHelper as log
|
||||||
|
|
||||||
from objects import glob
|
from objects import glob
|
||||||
from helpers import chatHelper as chat
|
from helpers import chatHelper as chat
|
||||||
|
import raven
|
||||||
|
|
||||||
class Client:
|
class Client:
|
||||||
"""
|
"""
|
||||||
|
@ -575,6 +577,10 @@ class Server:
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start IRC server main loop"""
|
"""Start IRC server main loop"""
|
||||||
|
# Sentry
|
||||||
|
if glob.sentry == True:
|
||||||
|
sentryClient = raven.Client(glob.conf.config["sentry"]["ircdns"])
|
||||||
|
|
||||||
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
serversocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||||
try:
|
try:
|
||||||
|
@ -586,41 +592,45 @@ class Server:
|
||||||
lastAliveCheck = time.time()
|
lastAliveCheck = time.time()
|
||||||
|
|
||||||
# Main server loop
|
# Main server loop
|
||||||
while True:
|
try:
|
||||||
(iwtd, owtd, ewtd) = select.select(
|
while True:
|
||||||
[serversocket] + [x.socket for x in self.clients.values()],
|
(iwtd, owtd, ewtd) = select.select(
|
||||||
[x.socket for x in self.clients.values()
|
[serversocket] + [x.socket for x in self.clients.values()],
|
||||||
if x.writeBufferSize() > 0],
|
[x.socket for x in self.clients.values()
|
||||||
[],
|
if x.writeBufferSize() > 0],
|
||||||
2)
|
[],
|
||||||
|
2)
|
||||||
|
|
||||||
# Handle incoming connections
|
# Handle incoming connections
|
||||||
for x in iwtd:
|
for x in iwtd:
|
||||||
if x in self.clients:
|
if x in self.clients:
|
||||||
self.clients[x].readSocket()
|
self.clients[x].readSocket()
|
||||||
else:
|
else:
|
||||||
(conn, addr) = x.accept()
|
(conn, addr) = x.accept()
|
||||||
try:
|
|
||||||
self.clients[conn] = Client(self, conn)
|
|
||||||
log.info("[IRC] Accepted connection from {}:{}".format(addr[0], addr[1]))
|
|
||||||
except socket.error as e:
|
|
||||||
try:
|
try:
|
||||||
conn.close()
|
self.clients[conn] = Client(self, conn)
|
||||||
except:
|
log.info("[IRC] Accepted connection from {}:{}".format(addr[0], addr[1]))
|
||||||
pass
|
except socket.error as e:
|
||||||
|
try:
|
||||||
|
conn.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
# Handle outgoing connections
|
# Handle outgoing connections
|
||||||
for x in owtd:
|
for x in owtd:
|
||||||
if x in self.clients: # client may have been disconnected
|
if x in self.clients: # client may have been disconnected
|
||||||
self.clients[x].writeSocket()
|
self.clients[x].writeSocket()
|
||||||
|
|
||||||
# Make sure all IRC clients are still connected
|
|
||||||
now = time.time()
|
|
||||||
if lastAliveCheck + 10 < now:
|
|
||||||
for client in list(self.clients.values()):
|
|
||||||
client.checkAlive()
|
|
||||||
lastAliveCheck = now
|
|
||||||
|
|
||||||
|
# Make sure all IRC clients are still connected
|
||||||
|
now = time.time()
|
||||||
|
if lastAliveCheck + 10 < now:
|
||||||
|
for client in list(self.clients.values()):
|
||||||
|
client.checkAlive()
|
||||||
|
lastAliveCheck = now
|
||||||
|
except:
|
||||||
|
log.error("[IRC] Unknown error!\n```\n{}\n{}```".format(sys.exc_info(), traceback.format_exc()))
|
||||||
|
if glob.sentry == True:
|
||||||
|
sentryClient.captureException()
|
||||||
|
|
||||||
def main(port=6667):
|
def main(port=6667):
|
||||||
glob.ircServer = Server(port)
|
glob.ircServer = Server(port)
|
||||||
|
|
|
@ -4,7 +4,6 @@ from objects import tokenList
|
||||||
from objects import channelList
|
from objects import channelList
|
||||||
from objects import matchList
|
from objects import matchList
|
||||||
from objects import fileLocks
|
from objects import fileLocks
|
||||||
from raven import Client
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("version") as f:
|
with open("version") as f:
|
||||||
|
|
32
pep.py
32
pep.py
|
@ -154,6 +154,22 @@ if __name__ == "__main__":
|
||||||
if glob.debug == True:
|
if glob.debug == True:
|
||||||
consoleHelper.printColored("[!] Warning! Server running in debug mode!", bcolors.YELLOW)
|
consoleHelper.printColored("[!] Warning! Server running in debug mode!", bcolors.YELLOW)
|
||||||
|
|
||||||
|
# Make app
|
||||||
|
application = make_app()
|
||||||
|
|
||||||
|
# Set up sentry
|
||||||
|
try:
|
||||||
|
glob.sentry = generalFunctions.stringToBool(glob.conf.config["sentry"]["enable"])
|
||||||
|
if glob.sentry == True:
|
||||||
|
application.sentry_client = AsyncSentryClient(glob.conf.config["sentry"]["banchodns"], release=glob.VERSION)
|
||||||
|
else:
|
||||||
|
consoleHelper.printColored("[!] Warning! Sentry logging is disabled!", bcolors.YELLOW)
|
||||||
|
except:
|
||||||
|
consoleHelper.printColored("[!] Error while starting sentry client! Please check your config.ini and run the server again", bcolors.RED)
|
||||||
|
|
||||||
|
# Cloudflare memes
|
||||||
|
glob.cloudflare = generalFunctions.stringToBool(glob.conf.config["server"]["cloudflare"])
|
||||||
|
|
||||||
# IRC start message and console output
|
# IRC start message and console output
|
||||||
glob.irc = generalFunctions.stringToBool(glob.conf.config["irc"]["enable"])
|
glob.irc = generalFunctions.stringToBool(glob.conf.config["irc"]["enable"])
|
||||||
if glob.irc == True:
|
if glob.irc == True:
|
||||||
|
@ -174,22 +190,6 @@ if __name__ == "__main__":
|
||||||
except:
|
except:
|
||||||
consoleHelper.printColored("[!] Invalid server port! Please check your config.ini and run the server again", bcolors.RED)
|
consoleHelper.printColored("[!] Invalid server port! Please check your config.ini and run the server again", bcolors.RED)
|
||||||
|
|
||||||
# Make app
|
|
||||||
application = make_app()
|
|
||||||
|
|
||||||
# Set up sentry
|
|
||||||
try:
|
|
||||||
glob.sentry = generalFunctions.stringToBool(glob.conf.config["sentry"]["enable"])
|
|
||||||
if glob.sentry == True:
|
|
||||||
application.sentry_client = AsyncSentryClient(glob.conf.config["sentry"]["dns"], release=glob.VERSION)
|
|
||||||
else:
|
|
||||||
consoleHelper.printColored("[!] Warning! Sentry logging is disabled!", bcolors.YELLOW)
|
|
||||||
except:
|
|
||||||
consoleHelper.printColored("[!] Error while starting sentry client! Please check your config.ini and run the server again", bcolors.RED)
|
|
||||||
|
|
||||||
# Cloudflare memes
|
|
||||||
glob.cloudflare = generalFunctions.stringToBool(glob.conf.config["server"]["cloudflare"])
|
|
||||||
|
|
||||||
# Server start message and console output
|
# Server start message and console output
|
||||||
log.logMessage("Server started!", discord=True, of="info.txt", stdout=False)
|
log.logMessage("Server started!", discord=True, of="info.txt", stdout=False)
|
||||||
consoleHelper.printColored("> Tornado listening for HTTP(s) clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)
|
consoleHelper.printColored("> Tornado listening for HTTP(s) clients on 127.0.0.1:{}...".format(serverPort), bcolors.GREEN)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user