diff options
Diffstat (limited to 'cgi/weabot.py')
-rwxr-xr-x | cgi/weabot.py | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/cgi/weabot.py b/cgi/weabot.py index dfa9de6..ff6debc 100755 --- a/cgi/weabot.py +++ b/cgi/weabot.py @@ -38,6 +38,7 @@ class weabot(object): logging.basicConfig(filename='weabot.log', format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG) self.environ = environ + self.ip = self.environ["HTTP_X_REAL_IP"] if self.environ["PATH_INFO"].startswith("/weabot.py/"): self.environ["PATH_INFO"] = self.environ["PATH_INFO"][11:] @@ -87,7 +88,7 @@ class weabot(object): if board: if board['board_type'] == 1: info = {} - info['host'] = self.environ["REMOTE_ADDR"] + info['host'] = self.ip info['name'] = self.formdata.get('fielda', '') info['email'] = self.formdata.get('fieldb', '') info['message'] = self.formdata.get('message', '') @@ -144,7 +145,7 @@ class weabot(object): raise UserError("El request está incompleto.") # let's get all the POST data we need - ip = self.environ["REMOTE_ADDR"] + ip = self.ip boarddir = self.formdata.get('board') parent = self.formdata.get('parent') trap1 = self.formdata.get('name', '') @@ -263,7 +264,7 @@ class weabot(object): caught = True # Redirect to ban page if user is banned - if Settings.ENABLE_BANS and addressIsBanned(self.environ['REMOTE_ADDR'], board["dir"], blind_only=True): + if Settings.ENABLE_BANS and addressIsBanned(self.ip, board["dir"], blind_only=True): raise UserError('<meta http-equiv="refresh" content="0; url=/cgi/banned/%s">' % board["dir"]) if len(path_split) > 4 and path_split[4] and board['board_type'] == 1: @@ -293,7 +294,7 @@ class weabot(object): # Report post, check if they are enabled # Can't report if banned caught = True - ip = self.environ["REMOTE_ADDR"] + ip = self.ip boarddir = path_split[2] postid = int(path_split[3]) reason = self.formdata.get('reason') @@ -327,7 +328,7 @@ class weabot(object): self.output += '<html xmlns="http://www.w3.org/1999/xhtml"><meta http-equiv="refresh" content="0;url=%s" /><body><p>...</p></body></html>' % url elif path_split[1] == "banned": OpenDb() - bans = FetchAll("SELECT * FROM `bans` WHERE INET6_ATON(%s) BETWEEN `ipstart` AND `ipend`", (self.environ["REMOTE_ADDR"],)) + bans = FetchAll("SELECT * FROM `bans` WHERE INET6_ATON(%s) BETWEEN `ipstart` AND `ipend`", (self.ip,)) if bans: for ban in bans: if ban["boards"]: @@ -349,7 +350,7 @@ class weabot(object): 'reason': ban['reason'], 'added': formatTimestamp(ban["added"]), 'expire': expire, - 'ip': self.environ["REMOTE_ADDR"], + 'ip': self.ip, 'ipstr': ban['ipstr'], } self.output = renderTemplate( @@ -370,7 +371,7 @@ class weabot(object): board = setBoard(path_split[2]) # Redirect to ban page if user is banned - if Settings.ENABLE_BANS and addressIsBanned(self.environ['REMOTE_ADDR'], board["dir"], blind_only=True): + if Settings.ENABLE_BANS and addressIsBanned(self.ip, board["dir"], blind_only=True): raise UserError('<meta http-equiv="refresh" content="0; url=/cgi/banned/%s">' % board["dir"]) self.output = dynamicRead(int(path_split[3]), path_split[4]) @@ -379,8 +380,7 @@ class weabot(object): OpenDb() try: board = setBoard(self.formdata["board"]) - message = format_post( - self.formdata["message"], self.environ["REMOTE_ADDR"], self.formdata["parentid"]) + message = format_post(self.formdata["message"], self.ip, self.formdata["parentid"]) self.output = message except Exception as messagez: self.output = "Error: " + \ @@ -972,7 +972,7 @@ class weabot(object): UpdateDb("INSERT INTO `reports` (board, postid, parentid, link, ip, reason, repip, timestamp, timestamp_formatted) " + "VALUES (%s, %s, %s, %s, %s, %s, INET6_ATON(%s), %s, %s)", - (board["dir"], post['id'], post['parentid'], link, post['ip'], message, self.environ["REMOTE_ADDR"], t, formatTimestamp(t))) + (board["dir"], post['id'], post['parentid'], link, post['ip'], message, self.ip, t, formatTimestamp(t))) self.output = renderTemplate("report.html", {'finished': True}) def stats(self): @@ -982,7 +982,7 @@ class weabot(object): try: with open('stats.json', 'r') as f: out = json.load(f) - except ValueError: + except (ValueError, FileNotFoundError): out = {'t': 0} regenerated = False |