add http check

This commit is contained in:
Your Name
2021-07-03 17:16:52 +02:00
parent 7cc02fc0a4
commit 11c5bd67b3

View File

@@ -58,11 +58,17 @@ class WorkerJob():
self.country = country self.country = country
self.isoldies = oldies self.isoldies = oldies
def connect_socket(self): def connect_socket(self, checktype):
srvname = random.choice(config.servers).strip() if checktype == 'irc':
srvname = random.choice(config.servers).strip()
use_ssl = random.choice([0,1]) if config.watchd.use_ssl == 2 else config.watchd.use_ssl
server_port = 6697 if use_ssl else 6667
elif checktype == 'http':
srvname = random.choice( ['www.facebook.com', 'www.reddit.com', 'www.twitter.com'] )
use_ssl = random.choice([0,1]) if config.watchd.use_ssl == 2 else config.watchd.use_ssl
server_port = 443 if use_ssl else 80
protos = ['http', 'socks5', 'socks4'] if self.proto is None else [self.proto] protos = ['http', 'socks5', 'socks4'] if self.proto is None else [self.proto]
use_ssl = random.choice([0,1]) if config.watchd.use_ssl == 2 else config.watchd.use_ssl
server_port = 6697 if use_ssl else 6667
fail_inc = 1 fail_inc = 1
@@ -77,7 +83,6 @@ class WorkerJob():
if not srv: continue if not srv: continue
duration = time.time() duration = time.time()
#rocksock.RocksockProxyFromURL('socks4://%s' % torhost),
proxies = [ proxies = [
rocksock.RocksockProxyFromURL('socks5://%s' % torhost), rocksock.RocksockProxyFromURL('socks5://%s' % torhost),
rocksock.RocksockProxyFromURL('%s://%s' % (proto, self.proxy)), rocksock.RocksockProxyFromURL('%s://%s' % (proto, self.proxy)),
@@ -86,7 +91,10 @@ class WorkerJob():
try: try:
sock = rocksock.Rocksock(host=srv, port=server_port, ssl=use_ssl, proxies=proxies, timeout=config.watchd.timeout) sock = rocksock.Rocksock(host=srv, port=server_port, ssl=use_ssl, proxies=proxies, timeout=config.watchd.timeout)
sock.connect() sock.connect()
sock.send('NICK\n') if checktype == 'irc':
sock.send('NICK\n')
elif checktype == 'http':
sock.send('HEAD / HTTP/1.0\r\nHost: %s\r\n\r\n' % srvname)
return sock, proto, duration, torhost, srvname, 0 return sock, proto, duration, torhost, srvname, 0
except rocksock.RocksockException as e: except rocksock.RocksockException as e:
if config.watchd.debug: if config.watchd.debug:
@@ -123,17 +131,19 @@ class WorkerJob():
def run(self): def run(self):
self.checktime = int(time.time()) self.checktime = int(time.time())
checktype = config.watchd.checktype
sock, proto, duration, tor, srv, failinc = self.connect_socket() sock, proto, duration, tor, srv, failinc = self.connect_socket(checktype)
if not sock: if not sock:
self.failcount += failinc self.failcount += failinc
return return
try: try:
recv = sock.recv(6) recv = sock.recv(-1)
#recv = sock.recvline() #print(recv)
regex = '^(:|NOTICE|ERROR)' if checktype == 'irc' else '(X-FB-Debug|x-clacks-overhead|x-connection-hash):'
# good data # good data
if re.match('^(:|NOTICE|ERROR)', recv, re.IGNORECASE): if (checktype == 'irc' and re.match(regex, recv, re.IGNORECASE)) or (checktype == 'http' and re.finditer(regex, recv, re.MULTILINE)):
duration = (time.time() - duration) duration = (time.time() - duration)
if geolite and not self.country or self.country == 'unknown' or self.country == 'N/A': if geolite and not self.country or self.country == 'unknown' or self.country == 'N/A':