Skip to content

Commit

Permalink
hmm
Browse files Browse the repository at this point in the history
  • Loading branch information
fuktommy committed Feb 2, 2024
1 parent c328ba9 commit 92a5734
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2005-2022 shinGETsu Project.
Copyright (c) 2005-2024 shinGETsu Project.
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
1 change: 1 addition & 0 deletions doc/sample.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

[Network]
# Bind Address(Default: *)
# :: for ipv6
bind_addr:

# Listening TCP port.
Expand Down
10 changes: 6 additions & 4 deletions shingetsu/LightCGIHTTPServer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tiny HTTP server supporting threading CGI.
"""
#
# Copyright (c) 2005-2023 shinGETsu Project.
# Copyright (c) 2005-2024 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,6 +29,7 @@
import copy
import os
import re
import socket
import sys
import urllib.parse
import http.server
Expand Down Expand Up @@ -105,6 +106,9 @@ def is_cgi(self):

def address_string(self):
host, port = self.client_address[:2]
m = re.search(r'^::ffff:([\d.]+)$', host)
if m:
return m.group(1)
return host

def log_request(self, code='-', size='-'):
Expand Down Expand Up @@ -265,6 +269,4 @@ def copyfile(self, source, outputfile):


class HTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
#XXX ThreadingMixIn of Python 3.7.3 does not release threads from its thread list
#XXX https://github.com/python/cpython/pull/13893
block_on_close = False
address_family = socket.AF_INET6
6 changes: 4 additions & 2 deletions shingetsu/basecgi.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'''Base CGI module.
'''
#
# Copyright (c) 2005-2015 shinGETsu Project.
# Copyright (c) 2005-2024 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -29,6 +29,8 @@
import os
import sys

from . import util

__all__ = ['CGI']


Expand Down Expand Up @@ -106,7 +108,7 @@ def start(self):
self.run()
except (IOError, socket.error, socket.timeout) as strerror:
self.stderr.write("%s: %s\n" %
(self.environ['REMOTE_ADDR'], strerror))
(util.get_http_remote_addr(self.environ), strerror))

def run(self):
"""Main routine for CGI."""
Expand Down
2 changes: 1 addition & 1 deletion shingetsu/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Saku Configuration.
"""
#
# Copyright (c) 2005-2023 shinGETsu Project.
# Copyright (c) 2005-2024 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
8 changes: 6 additions & 2 deletions shingetsu/mch/datd.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""2ch like dat interface
"""
#
# Copyright (c) 2014,2015 shinGETsu Project.
# Copyright (c) 2014-2024 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -32,6 +32,7 @@
from wsgiref.headers import Headers
from email import utils as eutils
import collections
import socket
import socketserver

from shingetsu import cache
Expand Down Expand Up @@ -60,6 +61,9 @@
def dat_app(env, resp):
# utils.log('dat_app')
addr = env.get('REMOTE_ADDR', '')
m = re.search(r'^::ffff:([\d.]+)$', addr)
if m:
addr = m.group(1)
env['shingetsu.isadmin'] = bool(config.re_admin.match(addr))
env['shingetsu.isfriend'] = bool(config.re_friend.match(addr))
env['shingetsu.isvisitor'] = bool(config.re_visitor.match(addr))
Expand Down Expand Up @@ -291,7 +295,7 @@ def run(self):
utils.log('use wsgiref')
class Server(socketserver.ThreadingMixIn,
simple_server.WSGIServer):
pass
address_family = socket.AF_INET6
_server = simple_server.make_server('', self._port, dat_app,
server_class=Server)
_server.serve_forever()
Expand Down
5 changes: 3 additions & 2 deletions shingetsu/mch/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""2ch like post
"""
#
# Copyright (c) 2014-2023 shinGETsu Project.
# Copyright (c) 2014-2024 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -38,6 +38,7 @@
from shingetsu import updatequeue
from shingetsu import template
from shingetsu import config
from shingetsu import util

from . import dat
from . import utils
Expand Down Expand Up @@ -121,7 +122,7 @@ def post_comment_app(env, resp):
# utils.log('post_comment_app')
subject, name, mail, body, datkey = _get_comment_data(env)

info = {'host': env.get('REMOTE_ADDR', ''),
info = {'host': util.get_http_remote_addr(env),
'name': name,
'mail': mail,
'body': body}
Expand Down
1 change: 1 addition & 0 deletions shingetsu/mch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from shingetsu import title
from shingetsu import tag
from shingetsu import util


def log(s, *args, **kwds):
Expand Down
4 changes: 2 additions & 2 deletions shingetsu/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ def __init__(self, nodestr=None, host="", port="", path=""):
raise NodeError('bad format')
self.nodestr = nodestr.replace('+', '/')
elif ':' in host:
self.nodestr = '[%s]:%d%s' % (host, port, re.sub(r"\+", "/", path))
self.nodestr = '[%s]:%s%s' % (host, str(port), re.sub(r"\+", "/", path))
else:
self.nodestr = '%s:%d%s' % (host, port, re.sub(r"\+", "/", path))
self.nodestr = '%s:%s%s' % (host, str(port), re.sub(r"\+", "/", path))
self.isv6 = self.nodestr.startswith('[')

def __str__(self):
Expand Down
12 changes: 11 additions & 1 deletion shingetsu/util.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Utilities.
"""
#
# Copyright (c) 2014 shinGETsu Project.
# Copyright (c) 2014-2024 shinGETsu Project.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand All @@ -28,6 +28,7 @@

import hashlib
import os.path
import re
import sys
from . import config

Expand Down Expand Up @@ -76,6 +77,15 @@ def opentext(path, mode='r'):
newline=newline)

def get_http_remote_addr(env):
addr = get_http_remote_addr_from_env(env)
if not addr:
return addr
m = re.search(r'^::ffff:([\d.]+)$', addr)
if m:
return m.group(1)
return addr

def get_http_remote_addr_from_env(env):
if not config.use_x_forwarded_for:
return env['REMOTE_ADDR']
else:
Expand Down

0 comments on commit 92a5734

Please sign in to comment.