[papert] r139 committed - anti-spam measures, other things

70 views
Skip to first unread message

codesite...@google.com

unread,
Apr 29, 2010, 9:26:35 AM4/29/10
to paper...@googlegroups.com
Revision: 139
Author: keknehv
Date: Thu Apr 29 06:25:43 2010
Log: anti-spam measures, other things

http://code.google.com/p/papert/source/detail?r=139

Added:
/trunk/moderate.html.tmpl
/trunk/moderate.py
/trunk/static/error.txt
Modified:
/trunk/app.yaml
/trunk/index.html.tmpl
/trunk/index.py
/trunk/static/papert.css

=======================================
--- /dev/null
+++ /trunk/moderate.html.tmpl Thu Apr 29 06:25:43 2010
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<title>papert: logo in your browser (MODERATE)</title>
+<link rel="icon" href="/favicon.ico" />
+</head>
+<body>
+
+<a href="{{login_url}}">login</a><br>
+
+?filter_string=blahblah&amp;delete=1<br>
+
+<table border="1">
+{% for item in items %}
+<tr>
+<td>{{item.date}}</td>
+<td>{{item.hash}}</td>
+<td>{{item.code|escape}}</td>
+</tr>
+{% endfor %}
+</table>
+
+</body>
+</html>
=======================================
--- /dev/null
+++ /trunk/moderate.py Thu Apr 29 06:25:43 2010
@@ -0,0 +1,53 @@
+"""$Id: index.py 133 2009-03-26 15:31:38Z thomas.figg $"""
+import os
+import base64
+import hashlib
+import datetime
+
+from google.appengine.ext.webapp import template
+from google.appengine.ext import webapp
+from google.appengine.ext.webapp.util import run_wsgi_app
+from google.appengine.ext import db
+from google.appengine.api import images
+from google.appengine.api import memcache
+from google.appengine.api import users
+
+class LogoProgram(db.Model):
+ code = db.TextProperty()
+ img = db.BlobProperty()
+ date = db.DateTimeProperty(auto_now_add=True)
+ hash = db.StringProperty()
+
+class Moderate(webapp.RequestHandler):
+ def get(self):
+ login_url = users.create_login_url("/moderate")
+
+ values = dict(login_url=login_url)
+
+ if users.is_current_user_admin():
+ values["items"] = db.GqlQuery("SELECT * FROM LogoProgram WHERE
img = null").fetch(10000)
+
+ fstring = self.request.get("filter_string", None)
+
+ if fstring:
+ values["items"] = filter(lambda x: fstring in x.code,
values["items"])
+
+ if int(self.request.get("delete", 0)):
+ for item in values["items"]:
+ try:
+ item.delete()
+ except db.InternalError:
+ pass
+ else:
+ values["items"] = ["please log in as an admin"]
+
+ page =
os.path.join(os.path.dirname(__file__), 'moderate.html.tmpl')
+ self.response.out.write(template.render(page, values))
+
+application = webapp.WSGIApplication([('/moderate', Moderate)],debug=True)
+
+def main():
+ run_wsgi_app(application)
+
+if __name__ == "__main__":
+ main()
=======================================
--- /dev/null
+++ /trunk/static/error.txt Thu Apr 29 06:25:43 2010
@@ -0,0 +1,1 @@
+there was a problem saving your program
=======================================
--- /trunk/app.yaml Tue Apr 27 04:15:12 2010
+++ /trunk/app.yaml Thu Apr 29 06:25:43 2010
@@ -11,9 +11,12 @@
static_files: static/favicon.ico
upload: static/favicon.ico

-- url: /help.txt
- static_files: static/help.txt
- upload: static/help.txt
+- url: /error
+ static_files: static/error.txt
+ upload: static/error.txt
+
+- url: /moderate
+ script: moderate.py

- url: /.*
script: index.py
=======================================
--- /trunk/index.html.tmpl Tue Apr 27 04:15:12 2010
+++ /trunk/index.html.tmpl Thu Apr 29 06:25:43 2010
@@ -12,7 +12,7 @@
<script type="text/javascript" src="/static/init.js"></script>

</head>
-<body onload="init('canvas','turtle','input','oldcode', 'textOutput');
clearcanvas(); run(5,false);">
+<body onload="init('canvas','turtle','input','oldcode', 'textOutput');
clearcanvas(); run(1,false);">

<div id="main">
<form id="input" action="/" method="post" onSubmit="this.img.value =
canvas.toDataURL().replace('data:image/png;base64,','')">
@@ -86,7 +86,7 @@
<li><a href="?newer={{next_date|escape}}#recent">&lt;</li>
{% endif %}
{% for item in recent %}
-<li><a href="/{{item|escape}}"><img src="/{{item|escape}}.png"
height="125" width="125" alt="" /></a></li>
+<li><a href="/{{item}}{% if older %}?older={{older|escape}}{% endif %}{%
if newer %}?newer={{newer|escape}}{% endif %}"><img src="/{{item}}.png"
height="125" width="125" alt="" /></a></li>
{% endfor %}
{% if last_date %}
<li><a href="?older={{last_date|escape}}#recent">&gt;</a></li>
=======================================
--- /trunk/index.py Thu Mar 26 08:31:38 2009
+++ /trunk/index.py Thu Apr 29 06:25:43 2010
@@ -1,7 +1,7 @@
"""$Id$"""
import os
import base64
-import sha
+import hashlib
import datetime

from google.appengine.ext.webapp import template
@@ -64,31 +64,33 @@


if older or newer:
- if older:
- browse_date =
datetime.datetime.strptime(older,"%Y-%m-%dT%H:%M:%S")
- recent = LogoProgram.all().filter('date <',
browse_date).order('-date').fetch(5)
- else:
- browse_date =
datetime.datetime.strptime(newer,"%Y-%m-%dT%H:%M:%S")
- recent = LogoProgram.all().filter('date >',
browse_date).order('date').fetch(5)
- if recent:
- recent.reverse()
- if recent:
- values['recent'] = [program.hash for program in
recent]
- values['last_date'] =
recent[-1].date.strftime("%Y-%m-%dT%H:%M:%S")
- values['next_date'] =
recent[0].date.strftime("%Y-%m-%dT%H:%M:%S")
+ if older:
+ browse_date =
datetime.datetime.strptime(older,"%Y-%m-%dT%H:%M:%S")
+ recent = LogoProgram.all().filter('date <',
browse_date).order('-date').fetch(5)
+ values['older'] = older
+ elif newer:
+ browse_date =
datetime.datetime.strptime(newer,"%Y-%m-%dT%H:%M:%S")
+ recent = LogoProgram.all().filter('date >',
browse_date).order('date').fetch(5)
+ recent.reverse()
+ values['newer'] = newer
+ if recent:
+ values['recent'] = [program.hash for program in recent]
+ values['last_date'] =
recent[-1].date.strftime("%Y-%m-%dT%H:%M:%S")
+ values['next_date'] =
recent[0].date.strftime("%Y-%m-%dT%H:%M:%S")
else:
- recent = memcache.get("recent_scripts")
- last_date = memcache.get("last_script_date")
- if recent is None or last_date is None:
+ recent = memcache.get("recent_progs")
+ last_date = memcache.get("last_prog_date")
+
+ if not (recent and last_date):
recent = LogoProgram.all().order('-date').fetch(5)
if recent:
last_date =
recent[-1].date.strftime("%Y-%m-%dT%H:%M:%S")
recent = [program.hash for program in recent]
- memcache.set("recent_scripts", recent)
- memcache.set("last_script_date", last_date)
- if recent and last_date:
- values['recent'] = recent
- values['last_date'] = last_date
+ memcache.set_multi({"recent_progs": recent,
+ "last_prog_date": last_date},
time=3600)
+
+ values['recent'] = recent
+ values['last_date'] = last_date

page =
os.path.join(os.path.dirname(__file__), 'index.html.tmpl')
self.response.out.write(template.render(page, values))
@@ -97,8 +99,13 @@
code = self.request.get('code',None)
img = self.request.get('img',"")

+ # simple antispam
+ if sum(x in code.lower() for x in ('href=', 'url=', 'link=')) > 2:
+ self.redirect("/error")
+ return
+
if code.strip():
- hash =
base64.b64encode(sha.sha(code.strip()).digest()[:6], "-_")
+ hash =
base64.b64encode(hashlib.sha1(code.strip()).digest()[:6], "-_")
if not LogoProgram.all().filter('hash =', hash).get():
program = LogoProgram()
program.code = code
@@ -108,6 +115,9 @@
img = images.Image(img)
img.resize(125, 125)
program.img = img.execute_transforms()
+ else:
+ self.redirect("/error")
+ return
program.put()
memcache.set("program: %s" % hash, program)
memcache.delete("recent")
=======================================
--- /trunk/static/papert.css Tue Apr 27 04:15:12 2010
+++ /trunk/static/papert.css Thu Apr 29 06:25:43 2010
@@ -77,7 +77,7 @@
#notes {
clear: left;
width: 100%;
- height: 100%;
+ height: 1000px;
}

#footer{

--
You received this message because you are subscribed to the Google Groups "papertlogo" group.
To post to this group, send email to paper...@googlegroups.com.
To unsubscribe from this group, send email to papertlogo+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/papertlogo?hl=en.

Reply all
Reply to author
Forward
0 new messages