Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM debian:buster

RUN apt update && apt install -y python3-pip
RUN pip3 install gunicorn
RUN pip3 install Django
RUN pip3 install perimeterx-python-3-wsgi

WORKDIR /tmp/px
CMD ["/tmp/px/scripts/run_gunicorn.sh"]
4 changes: 4 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This is an example demonstrating PerimeterX Python 3 Middleware usage.

Please review and adjust `sampleSite/wsgi.py` file (replace `REPLACE` placeholders with the real values).
Then run `run_docker.sh` script, web server will be listening on `8080` port.
31 changes: 31 additions & 0 deletions example/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# [START django_app]
runtime: python3
api_version: 1
threadsafe: yes

handlers:
- url: /static
static_dir: static/
- url: .*
script: sampleSite.wsgi.application

env_variables:
GAE_USE_SOCKETS_HTTPLIB: 'true'

libraries:
- name: pycrypto
version: "2.6"
- name: ssl
version: "2.7.11"

# Google App Engine limits application deployments to 10,000 uploaded files per
# version. The skip_files section allows us to skip virtual environment files
# to meet this requirement. The first 5 are the default regular expressions to
# skip, while the last one is for all env/ files.
skip_files:
- ^(.*/)?#.*#$
- ^(.*/)?.*~$
- ^(.*/)?.*\.py[co]$
- ^(.*/)?.*/RCS/.*$
- ^(.*/)?\..*$
- ^env/.*$
20 changes: 20 additions & 0 deletions example/appengine_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2015 Google Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START vendor]
import os
from google.appengine.ext import vendor

vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
# [END vendor]
6 changes: 6 additions & 0 deletions example/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Django==1.11.17
gunicorn==19.9.0
requests==2.18.2
Werkzeug==0.14.1
pystache==0.5.4
requests-toolbelt==0.7.0
9 changes: 9 additions & 0 deletions example/run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash
NAME=px_python3_wsgi

docker rm -v -f $NAME || true
docker build -t $NAME -f Dockerfile .
docker run \
-v $(pwd)/:/tmp/px \
-p 8080:8080 \
-it --name $NAME $NAME
Empty file added example/sampleSite/__init__.py
Empty file.
92 changes: 92 additions & 0 deletions example/sampleSite/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"""
Django settings for sampleSite project.

Generated by 'django-admin startproject' using Django 1.9.4.

For more information on this file, see
https://docs.djangoproject.com/en/1.9/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/1.9/ref/settings/
"""

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'REPLACE'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'sampleSite'
]

MIDDLEWARE_CLASSES = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'sampleSite.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'sampleSite.wsgi.application'

CSRF_COOKIE_SECURE = False

# Internationalization
# https://docs.djangoproject.com/en/1.9/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = 'static'
115 changes: 115 additions & 0 deletions example/sampleSite/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
body {
background-color: #848484;
}

.container {
margin-top:150px;
}

.box {
margin: 0 auto;
padding-top:20px;
text-align: center;
color: white;
width:350px;
background-color: black;
border-radius: 12px;
height: 350px;
box-shadow: 3px 3px 3px #ED1C24;
}

.login-box {
margin: 0 auto;
padding-top:20px;
text-align: center;
color: white;
background-color: black;
border-radius: 12px;
box-shadow: 3px 3px 3px #ED1C24;
}

#logout {
margin-top:120px;
}

#logout a {
color:black;
text-decoration: none;
}

.form-signin
{
max-width: 330px;
padding: 15px;
margin: 0 auto;
}
.form-signin .form-signin-heading, .form-signin .checkbox
{
margin-bottom: 10px;
}
.form-signin .checkbox
{
font-weight: normal;
}
.form-signin .form-control
{
position: relative;
font-size: 16px;
height: auto;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.form-signin .form-control:focus
{
z-index: 2;
}
.form-signin input[type="text"]
{
margin-bottom: -1px;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}
.form-signin input[type="password"]
{
margin-bottom: 10px;
border-top-left-radius: 0;
border-top-right-radius: 0;
}
.account-wall
{
margin-top: 20px;
padding: 40px 0px 20px 0px;
background-color: black;
-moz-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
border-radius: 12px;
}
.login-title
{
color: white;
font-size: 18px;
font-weight: 400;
display: block;
}
.profile-img
{
width: 96px;
height: 96px;
margin: 0 auto 10px;
display: block;
-moz-border-radius: 50%;
-webkit-border-radius: 50%;
border-radius: 50%;
}
.need-help
{
margin-top: 10px;
}
.new-account
{
display: block;
margin-top: 10px;
}
88 changes: 88 additions & 0 deletions example/sampleSite/templates/fp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<!DOCTYPE html>
<html>
<head>
<title>PerimeterX Python WSGI SDK Sample</title>
<link
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous"
/>
<link href="static/style.css" rel="stylesheet" type="text/css" />
<script
src="http://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"
></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-4 col-sm-offset-4">
<div class="login-box">
<h1 class="text-center login-title">
Welcome to PerimeterX Python Sample
</h1>
<div class="account-wall">
<img
id="logo-global"
src="https://d33wubrfki0l68.cloudfront.net/01fd73d62a06a98fef9632d73ad9ff2dbba47a19/76105/img/logo.svg"
alt=""
style="width:200px;"
/><br />
<h3 style="color:white; text-align:center">Login</h3>
<form class="form-signin" method="post" action="/login/">
<input
type="text"
class="form-control"
name="username"
id="name"
placeholder="Username"
required
autofocus
/>
<input
type="password"
class="form-control"
name="password"
id="password"
placeholder="Password"
required
/>
<button
class="btn btn-lg btn-danger btn-block"
type="submit"
name="submit"
style="background-color:#ED1C24"
>
Sign in
</button>
<span id="error" style="color:#ED1C24"></span><br />
<span style="color:white; font-size:11px;"
>Username: pxUser, Password: 1234</span
>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
<script type="text/javascript">
(function() {
window._pxAppId = "PXPdORIcsb";
// Custom parameters
// window._pxParam1 = "<param1>";
var p = document.getElementsByTagName("script")[0],
s = document.createElement("script");
s.async = 1;
s.src = "/PdORIcsb/init.js";
p.parentNode.insertBefore(s, p);
})();
</script>
<noscript>
<div style="position:fixed; top:0; left:0;" width="1" height="1">
<img src="/PdORIcsb/xhr/api/v1/collector/noScript.gif?appId=PXPdORIcsb" />
</div>
</noscript>
</html>
Loading