Commit 5de09ff4 authored by Jean Michel Rouly's avatar Jean Michel Rouly
Browse files

Removed old dead code.

parent 8eca846e
<h3>~About~</h3>
<p>
Mason Go is a product of the George Mason University
<a href="http://srct.gmu.edu">Student-Run Computing and Technology</a>
organization. Go provides Mason-branded URL shortening for administration,
ULife groups, and student organizations. Access is moderated by SRCT
administrators.
</p>
<p>
You can <a href="/signup">sign up</a> for use.
<br/><br/>
</p>
<hr/>
<div id="signoff">
A project of
<a href="http://srct.gmu.edu/">GMU SRCT</a>.
<a href="http://www.apache.org/licenses/LICENSE-2.0">Some rights reserved</a>.
<br/><br />
%{logout}%
</div>
</div>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http") +
"://golem.srct.gmu.edu/analytics//";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', 1]);
var d=document, g=d.createElement('script'),
s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js';
s.parentNode.insertBefore(g,s);
})();
</script>
<noscript><p><img
src="http://golem.srct.gmu.edu/analytics/piwik.php?idsite=1"
style="border:0" alt="" /></p></noscript>
<!-- End Piwik Code -->
</body>
</html>
function expand( id ) {
var box = document.getElementById( id );
if( box.style.display=="none" ) {
box.style.display="block";
} else {
box.style.display="none";
}
}
/*
* ########################################################################
* ########################################################################
* ######## ########
* ######## ########
* ######## Project: GO - URL Shorterner ########
* ######## File: style.css ########
* ######## Date: 2013.10.29 ########
* ######## Author: Michel Rouly ########
* ######## ########
* ######## Style sheet for entire web application. Modify ########
* ######## any design changes here. ########
* ######## ########
* ######## ########
* ########################################################################
* ########################################################################
*/
/**** CONTAINER STYLES ****/
body { /* HTML body */
/* background: #FFCC33; */
background: #EFEFEF;
}
#box { /* Main content holder */
color: #383838;
width: 500px;
margin: auto;
padding: 20px;
border-radius: 15px;
background-color: #EFEF88;
/* background-color: #FFCC33; */
/* background-color: #EFEFEF; */
text-align: center;
font-family: 'Carrois Gothic', sans-serif;
}
#tagline {
/* text-align: right; */
font-size: .81em;
}
#signoff { /* Footer of the page */
color: #000000;
text-align: center;
font-size: .6em;
font-style: italic;
}
#mylinks {
width: inherit;
margin: auto;
table-layout: fixed;
/*height: 500px;
border: 1px solid #000000;
overflow-y: auto;*/
}
#mylinks p {
/* border-left: 5px solid #464646; */
border: 1px dashed #000000;
text-align: left;
padding-bottom: 5px;
padding-top: 5px;
padding-left: 10px;
padding-right: 10px;
word-wrap: break-word;
white-space: normal;
}
#mylinks p:hover {
background-color: #FDFDB8;
/* border-left: 5px solid #898989; */
}
/**** PAGE COMPONENT STYLES ****/
p, tr {
font-size: .8em;
}
a {
text-decoration: none;
}
/**** HEADER STYLES ****/
h1 { /* Main page title */
font-size: 3em;
margin-bottom: 0px;
color: #006633;
}
h1 a {
color: inherit;
text-decoration: none;
}
h2 { /* Per-page headings */
color: inherit;
font-size: 1.5em;
}
hr { /* Page title and footer seperators */
color: #006633;
background-color: #006633;
height: 2px;
width: 50%;
border: 0px;
}
/**** FORM COMPONENT STYLES ****/
label {
color: #565656;
cursor: pointer;
font-weight: bold;
text-transform: uppercase;
}
.sublabel {
font-size: .8em;
}
input, textarea {
color: #9a9a9a;
cursor: pointer;
border: 0px solid #343434;
border-radius: 5px;
background-color: #FDFDB8;
/* background-color: #FFCC33; */
padding: 5px;
}
textarea {
width: 75%;
height: 75px;
}
input:focus {
color: #000000;
}
input[type="submit"] {
color: #000000;
background-color: #E86847;
border: 0px;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
Go Url Shortener
</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="http://fonts.googleapis.com/css?family=Carrois+Gothic" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="/static/style.css" />
<link rel="icon" type="image/jpg" href="/static/favicon.ico" />
<script type="text/javascript" src="/static/go.js"></script>
</head>
<body>
<div id="box">
<h1><a href="/">Go (URL Shortener)</a></h1>
<p id="tagline">
[ <a href="/about">What is Go?</a> ]
%{mylinks}%
</p>
<hr/>
import ldap
import site
site.addsitedir('/srv/http/go/wsgi')
import library
import goconfig
def application(environ, start_response):
user_logged_in = library.user_logged_in( environ )
top = library.get_top( user_logged_in )
bottom = library.get_bottom( user_logged_in )
f = open(goconfig.doc_root + "/static/about.part", "r")
about = f.read()
f.close()
response = top + about + bottom
status = '200 OK'
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(response)))]
start_response(status, response_headers)
return [response]
from cgi import parse_qs, escape
import site
site.addsitedir('/srv/http/go/wsgi')
import library
import goconfig
def application(environ, start_response):
if( not library.user_logged_in( environ ) ):
status = '303 See other'
response_headers = [('Location', '/login')]
start_response(status, response_headers)
return ['Redirecting to login . . .']
if not (environ["REQUEST_METHOD"] == "GET"):
status = '303 See other'
response_headers = [('Location', '/')]
start_response(status, response_headers)
return ['Redirecting to index . . .']
body = []
# Grab user data.
data = parse_qs(environ['QUERY_STRING'])
short_url = data.get("u", [''])[0]
short_url = escape(short_url)
username = library.get_username( environ )
links = library.get_links( username )
if links is not None:
for link in links:
(link_id, _, link_short_url, _, _, _) = link
if short_url == link_short_url:
library.delete_url( link_id )
status = '303 See other'
response_headers = [('Location', '/mylinks')]
start_response(status, response_headers)
return ['Redirecting to mylinks . . .']
##############################
# Site configuration variables
#
# These variables configure how the website is structured.
##############################
# doc_root: Describes where the website's root directory is.
doc_root = "/srv/http"
# domain: This is the domain the website is being hosted at.
# do not include a final slash.
domain = "www.example.com"
##############################
# Database connection variables
#
# These variables configure how the website connects
# to the required database.
##############################
# sql_domain: The location of the SQL database to connect to.
sql_domain = "localhost"
# sql_usr: The username to use with this SQL database.
sql_usr = "go-user"
# sql_pasw: The plaintext password used to connec to the SQL database.
sql_pasw = "go-password"
# sql_db: The SQL database or schema name to which to connect.
sql_db = "go"
# sql_url_table: The SQL table storing the URL listing.
sql_url_table = "urls"
# sql_usr_table: The SQL table storing the active users.
sql_usr_table = "usrs"
# sql_registration_table: The SQL table storing registered users.
sql_registration_table = "registered"
#ldap_domain: The location of the LDAP database to connect to.
ldap_domain = "ldap://ldap.example.com:port"
##############################
# Behaviour configuration variables
#
# These variables define various system behaviors, such
# as global limits or values.
##############################
# min_url_len: This is the minimum required length of
# a "short url" or url identifier.
min_url_len = 5
# piwik: Enable piwik analytics & tracking.
piwik = False
# piwik_tracking_api_url: If Piwik is enabled, point this to the tracking server.
piwik_tracking_api_url = "http://www.example.com/analytics/piwik.php"
# piwik_site_id: The Piwik SITE_ID global variable.
piwik_site_id = 1
# piwik_token_auth: The private Piwik tracking token auth. Currently
# disabled.
piwik_token_auth = ""
import re
import urllib
import time
import site
site.addsitedir('/srv/http/go/wsgi')
import library
import goconfig
url_regex = re.compile(
r'^(?:http|ftp)s?://' # http:// or https://
r'(?:(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?)|' #domain...
r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})' # ...or ip
r'(?::\d+)?' # optional port
r'(?:/?|[/?]\S+)$', re.IGNORECASE)
short_regex = re.compile(
r'^[a-z0-9]+$', re.IGNORECASE)
def application(environ, start_response):
if( not library.user_logged_in( environ ) ):
status = '303 See other'
response_headers = [('Location', '/login')]
start_response(status, response_headers)
return ['Redirecting to login . . .']
body = []
url_form = """
<h3>~Shorten URL~</h3>
<form action="/" method="post" target="_self">
<label for="long-url">Long URL</label>
<br /><br />
<input type="text" id="long-url" name="long-url" value="http://" />
<br /><br />
<label for="short-url">Short URL (Optional)</label>
<br /><br />
<input type="text" id="short-url" name="short-url" value="" />
<br /><br />
<label>Expiration (Optional)</label>
<br /><br />
<input type="radio" name="expiration" value="day" id="day" />
<label for="day" class="sublabel">1 Day</label>
<input type="radio" name="expiration" value="week" id="week" />
<label for="week" class="sublabel">1 Week</label>
<input type="radio" name="expiration" value="month" id="month" />
<label for="month" class="sublabel">1 Month</label>
<input type="radio" name="expiration" value="never" id="never"
checked="checked" />
<label for="never" class="sublabel">Never</label>
<br /><br />
<input type="submit" name="submit" value="SHORTEN" />
<br /><br />
</form>
"""
if not (environ["REQUEST_METHOD"] == "POST"):
body = []
body.append( url_form )
else:
body = []
error = []
# Grab user data, cut off non-relevant fields.
data = environ['wsgi.input']
data = library.parse_data( data )
# Store parsed user data in these handy variables.
long_url = data["long-url"]
expiration = data["expiration"]
try:
short_url = data["short-url"]
except KeyError:
pass
if len(short_url) == 0:
short_url = library.generate_short_url( long_url )
while library.short_url_exists( short_url ):
short_url = library.generate_short_url( long_url )
# Prepend the long_url with a protocol if it doesn't have one.
if not (long_url.startswith("http") or long_url.startswith("ftp")):
long_url = "http://" + long_url
# Un-quote the url for storage, if it's quoted.
long_url = urllib.unquote( long_url )
short_url = urllib.unquote( short_url )
# Parse the expiration date.
today = int(time.time())
if expiration is None:
end_stamp = today
elif expiration == "never":
end_stamp = 0
elif expiration == "month":
end_stamp = today + 2629740
elif expiration == "week":
end_stamp = today + 604800
elif expiration == "day":
end_stamp = today + 86400
else:
end_stamp = today
# Add error messages if any are found.
if re.match(url_regex, long_url) is None:
error.append("<p>You entered an invalid long url!</p>")
if len( short_url ) < goconfig.min_url_len:
error.append("<p>The identifier must be at least ")
error.append(str(goconfig.min_url_len) + " characters.</p>")
if re.match(short_regex, short_url) == None:
error.append("<p>The identifier can contain only letters and numbers.</p>")
if library.short_url_exists( short_url ):
error.append("<p>The identifier already exists in the database!</p>")
if len(error) > 0: # at least one error found
body = ["<h3>~Error~</h3>"]
body.extend( error )
body.append('<input type="submit" value="BACK" ')
body.append('onclick="history.back()" /><br /><br />')
else: # no error found
# insert the longurl-shorturl pairing in the database.
library.register_url( long_url, short_url, end_stamp, environ )
display_short = goconfig.domain + "/" + short_url
body = ["<h3>~Success~</h3>"]
body.append(
'<p><em>Original URL:</em> <a href="%s">%s</a></p>' %
(long_url, long_url))
body.append(
'<p><em>Shortened URL:</em> <a href="/%s">%s</a></p>' %
(short_url, display_short))
user_logged_in = library.user_logged_in( environ )
top = library.get_top( user_logged_in )
bottom = library.get_bottom( user_logged_in )
body = ''.join( body )
response = top + body + bottom
status = '200 OK'
response_headers = [('Content-type', 'text/html'),
('Content-Length', str(len(response)))]
start_response(status, response_headers)
return [response]
from cgi import escape
import random
import time
import math
import site
import MySQLdb
import Cookie
import cookielib
import hashlib
import ldap
site.addsitedir('/srv/http/go/wsgi')
import goconfig
# Extract the value of the cookie if one is set.
def get_cookie_value( environ ):
cookie = Cookie.SimpleCookie()
# if the environment contains a cookie, check it out
if environ.has_key('HTTP_COOKIE'):
# load the cookie we found
cookie.load(environ['HTTP_COOKIE']);
if cookie.has_key('user'):
user_hash = cookie['user'].value
return escape(user_hash)
return None
# Determine if a user is appropriately validated through LDAP.
def user_logged_in( environ ):
user_hash = get_cookie_value(environ)
if( user_hash is not None ):
# see if it's in the database
mdb,cursor = connect_to_mysql()
sql = """SELECT count(*) FROM `%s` WHERE `user_hash`=%s;"""
cursor.execute( sql, (goconfig.sql_usr_table, user_hash) )
((num_rows,),) = cursor.fetchall()
mdb.commit()
mdb.close()
return num_rows > 0
return False
def get_username( environ ):
user_hash = get_cookie_value( environ )
username = None
if( user_hash is not None ):
mdb,cursor = connect_to_mysql()
try:
sql = """SELECT `user` FROM `%s` WHERE `user_hash`=%s;"""
cursor.execute( sql, (goconfig.sql_usr_table, user_hash ) )
((username,),) = cursor.fetchall()
mdb.commit()
finally:
mdb.close()
return username
def user_approved( username ):
mdb,cursor = connect_to_mysql()
sql = """SELECT `approved` FROM `%s` WHERE `user`=%s;"""
cursor.execute( sql, (goconfig.sql_registration_table, username) )
((approved,),) = cursor.fetchall()
mdb.commit()
mdb.close()
if approved == 1:
return True
else:
return False
# Determine if the user has posting permissions via the registration
# datbase.
def user_registered( username ):
mdb,cursor = connect_to_mysql()
sql = """SELECT count(*) FROM `%s` WHERE `user`=%s;"""
cursor.execute( sql, (goconfig.sql_registration_table, username) )
((num_rows,),) = cursor.fetchall()
mdb.commit()
mdb.close()