issue Issue 1474 attachment: addrinfo.patch, thanks Jonathan

This commit is contained in:
mdipierro
2013-05-03 21:42:17 -05:00
parent e7f2e494af
commit 95adb233f7
4 changed files with 25 additions and 15 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.4.6-stable+timestamp.2013.05.03.21.36.38
Version 2.4.6-stable+timestamp.2013.05.03.21.41.37
+3 -5
View File
@@ -95,7 +95,7 @@ from settings import global_settings
from validators import CRYPT
from cache import CacheInRam
from html import URL, xmlescape
from utils import is_valid_ip_address
from utils import is_valid_ip_address, getipaddrinfo
from rewrite import load, url_in, THREAD_LOCAL as rwthread, \
try_rewrite_on_error, fixup_missing_path_info
import newcron
@@ -471,13 +471,11 @@ def wsgibase(environ, responder):
local_hosts.add(socket.gethostname())
local_hosts.add(fqdn)
local_hosts.update([
ip[4][0] for ip in socket.getaddrinfo(
fqdn, 0)])
ip[4][0] for ip in getipaddrinfo(fqdn)])
if env.server_name:
local_hosts.add(env.server_name)
local_hosts.update([
ip[4][0] for ip in socket.getaddrinfo(
env.server_name, 0)])
ip[4][0] for ip in getipaddrinfo(env.server_name)])
except (socket.gaierror, TypeError):
pass
global_settings.local_hosts = list(local_hosts)
+17 -3
View File
@@ -295,14 +295,28 @@ def is_valid_ip_address(address):
return True
def is_loopback_ip_address(ip):
"""Determines whether the IP address appears to be a loopback address.
def is_loopback_ip_address(ip=None, addrinfo=None):
"""
Determines whether the address appears to be a loopback address.
This assumes that the IP is valid. The IPv6 check is limited to '::1'.
"""
if addrinfo: # see socket.getaddrinfo() for layout of addrinfo tuple
if addrinfo[0] == socket.AF_NET or addrinfo[0] == socket.AF_INET6:
ip = addrinfo[4]
if not ip:
return False
if ip.count('.') == 3: # IPv4
if isinstance(ip, basestring) and ip.count('.') == 3: # IPv4
return ip.startswith('127') or ip.startswith('::ffff:127')
return ip == '::1' # IPv6
def getipaddrinfo(host):
"""
Filter out non-IP and bad IP addresses from getaddrinfo
"""
return [addrinfo for addrinfo in socket.getaddrinfo(host, None)
if (addrinfo[0] == socket.AF_INET or addrinfo[0] == socket.AF_INET6)
and isinstance(addrinfo[4][0], basestring)]
+4 -6
View File
@@ -15,7 +15,6 @@ import cStringIO
import time
import thread
import threading
import re
import os
import socket
import signal
@@ -25,10 +24,10 @@ import newcron
import getpass
import main
from fileutils import w2p_pack, read_file, write_file, create_welcome_w2p
from fileutils import read_file, write_file, create_welcome_w2p
from settings import global_settings
from shell import run, test
from utils import is_valid_ip_address, is_loopback_ip_address
from utils import is_valid_ip_address, is_loopback_ip_address, getipaddrinfo
try:
import Tkinter
@@ -338,7 +337,6 @@ class web2pyDialog(object):
self.tb = None
def update_schedulers(self, start=False):
x = 0
apps = []
available_apps = [arq for arq in os.listdir('applications/')]
available_apps = [arq for arq in available_apps
@@ -942,8 +940,8 @@ def console():
try:
options.ips = list(set([
ip[4][0] for ip in socket.getaddrinfo(socket.getfqdn(), 0)
if not is_loopback_ip_address(ip[4][0])]))
addrinfo[4][0] for addrinfo in getipaddrinfo(socket.getfqdn())
if not is_loopback_ip_address(addrinfo=addrinfo)]))
except socket.gaierror:
options.ips = []