diff --git a/gluon/packages/dal b/gluon/packages/dal index 0dc5befb..50f8dafd 160000 --- a/gluon/packages/dal +++ b/gluon/packages/dal @@ -1 +1 @@ -Subproject commit 0dc5befbe5d63adc6493b0600ed1ef8642ac6693 +Subproject commit 50f8dafdff6f04a3f5edce7807aef89a32ff516f diff --git a/gluon/validators.py b/gluon/validators.py index 2afeedc4..10dc5b7f 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -3482,7 +3482,7 @@ class IS_IPV6(Validator): from gluon.contrib import ipaddr as ipaddress try: - ip = ipaddress.IPv6Address(value) + ip = ipaddress.IPv6Address(value.decode('utf-8')) ok = True except ipaddress.AddressValueError: return (value, translate(self.error_message)) @@ -3494,7 +3494,7 @@ class IS_IPV6(Validator): self.subnets = [self.subnets] for network in self.subnets: try: - ipnet = ipaddress.IPv6Network(network) + ipnet = ipaddress.IPv6Network(network.decode('utf-8')) except (ipaddress.NetmaskValueError, ipaddress.AddressValueError): return (value, translate('invalid subnet provided')) if ip in ipnet: @@ -3703,20 +3703,22 @@ class IS_IPADDRESS(Validator): def __call__(self, value): try: - import ipaddress + from ipaddress import ip_address as IPAddress + from ipaddress import IPv6Address, IPv4Address except ImportError: - from gluon.contrib import ipaddr as ipaddress + from gluon.contrib.ipaddr import (IPAddress, IPv4Address, + IPv6Address) try: - ip = ipaddress.IPAddress(value) - except ValueError, e: + ip = IPAddress(value.decode('utf-8')) + except ValueError: return (value, translate(self.error_message)) - if self.is_ipv4 and isinstance(ip, ipaddress.IPv6Address): + if self.is_ipv4 and isinstance(ip, IPv6Address): retval = (value, translate(self.error_message)) - elif self.is_ipv6 and isinstance(ip, ipaddress.IPv4Address): + elif self.is_ipv6 and isinstance(ip, IPv4Address): retval = (value, translate(self.error_message)) - elif self.is_ipv4 or isinstance(ip, ipaddress.IPv4Address): + elif self.is_ipv4 or isinstance(ip, IPv4Address): retval = IS_IPV4( minip=self.minip, maxip=self.maxip, @@ -3726,7 +3728,7 @@ class IS_IPADDRESS(Validator): is_automatic=self.is_automatic, error_message=self.error_message )(value) - elif self.is_ipv6 or isinstance(ip, ipaddress.IPv6Address): + elif self.is_ipv6 or isinstance(ip, IPv6Address): retval = IS_IPV6( is_private=self.is_private, is_link_local=self.is_link_local, diff --git a/scripts/setup-web2py-nginx-uwsgi-centos7.sh b/scripts/setup-web2py-nginx-uwsgi-centos7.sh new file mode 100644 index 00000000..a6b62152 --- /dev/null +++ b/scripts/setup-web2py-nginx-uwsgi-centos7.sh @@ -0,0 +1,235 @@ +#!/bin/bash + +# This script will install web2py with nginx+uwsgi on centos 7 +# This script is based on excellent tutorial by Justin Ellingwood on +# https://www.digitalocean.com/community/tutorials/how-to-deploy-web2py-python-applications-with-uwsgi-and-nginx-on-centos-7 + +# +# Phase 1: First, let's ask a few things +# + +read -p "Enter username under which web2py will be installed [web2py]: " USERNAME +USERNAME=${USERNAME:-web2py} + +read -p "Enter path where web2py will be installed [/opt/web2py_apps]: " WEB2PY_PATH +WEB2PY_PATH=${WEB2PY_PATH:-/opt/web2py_apps} + +read -p "Web2py subdirectory will be called: [web2py]: " WEB2PY_APP +WEB2PY_APP=${WEB2PY_APP:-web2py} + +read -p "Enter your web2py admin password: " WEB2PY_PASS + +read -p "Enter your domain name: " YOUR_SERVER_DOMAIN + +# open new user +useradd -d $WEB2PY_PATH $USERNAME + +# if it's not already open, let's create a directory for web2py +mkdir -p $WEB2PY_PATH + +# now let's create a self signed certificate +cd $WEB2PY_PATH + +openssl req -x509 -new -newkey rsa:4096 -days 3652 -nodes -keyout $WEB2PY_APP.key -out $WEB2PY_APP.crt + +# +# phase 2: That was all the input that we needed so let's install the components +# + +echo "Installing necessary components" + +# Verify packages are up to date +yum -y upgrade + +# Install required packages +yum install -y epel-release +yum install -y python-devel python-pip gcc nginx wget unzip python-psycopg2 MySQL-python + +# download and unzip web2py + +echo "Downloading web2py" + +cd $WEB2PY_PATH +wget http://web2py.com/examples/static/web2py_src.zip +unzip web2py_src.zip +rm web2py_src.zip + +# preparing wsgihandler +chown -R $USERNAME.$USERNAME $WEB2PY_PATH/$WEB2PY_APP +mv $WEB2PY_PATH/$WEB2PY_APP/handlers/wsgihandler.py $WEB2PY_PATH/$WEB2PY_APP + +# now let's install uwsgi + +pip install uwsgi + +# preparing directories +mkdir -p /etc/uwsgi/sites +mkdir -p /var/log/uwsgi +mkdir -p /etc/nginx/ssl/ + +# +# Phase 3: Ok, everything is installed now so we'll configure things +# + +# Create configuration file for uwsgi in /etc/uwsgi/$WEB2PY_APP.ini +echo '[uwsgi] +chdir = WEB2PY_PATH_PLACEHOLDER/WEB2PY_APP_PLACEHOLDER +module = wsgihandler:application + +master = true +processes = 5 + +uid = USERNAME_PLACEHOLDER +socket = /run/uwsgi/WEB2PY_APP_PLACEHOLDER.sock +chown-socket = USERNAME_PLACEHOLDER:nginx +chmod-socket = 660 +vacuum = true +' >/etc/uwsgi/sites/$WEB2PY_APP.ini + +sed -i "s@WEB2PY_PATH_PLACEHOLDER@$WEB2PY_PATH@" /etc/uwsgi/sites/$WEB2PY_APP.ini +sed -i "s@WEB2PY_APP_PLACEHOLDER@$WEB2PY_APP@" /etc/uwsgi/sites/$WEB2PY_APP.ini +sed -i "s@USERNAME_PLACEHOLDER@$USERNAME@" /etc/uwsgi/sites/$WEB2PY_APP.ini + +# Create a daemon configuration file for uwsgi +cat > /etc/systemd/system/uwsgi.service < /etc/nginx/nginx.conf <