[merged intrusion checks from prod Panu Kalliokoski **20050623140520 Keywords: Patches applied: * atehwa@sange.fi--2005/piki--prod--1--patch-1 merged editor changes from maim * atehwa@sange.fi--2005/piki--prod--1--patch-2 advertise RSS feed * atehwa@sange.fi--2005/piki--prod--1--patch-3 accommodated to new oiva * atehwa@sange.fi--2005/piki--prod--1--patch-4 more sanity checks * atehwa@sange.fi--2005/piki--prod--1--patch-5 samankaltaisuustarkistus * atehwa@sange.fi--2005/piki--prod--1--patch-6 Written to be prettier (?) * atehwa@sange.fi--2005/piki--prod--1--patch-7 link throttling (atehwa@sange.fi--2005/piki--intl--1--patch-2) ] { hunk ./piki.py 2 +# -*- coding: latin-1 -*- hunk ./piki.py 35 +from sets import Set hunk ./piki.py 56 +link_re = re.compile(r"(http|ftp|mailto|nntp|news):") hunk ./piki.py 103 + print """""" % get_scriptname() hunk ./piki.py 206 +def no_nonempty_common_lines(t1, t2): + common_lines = Set(t1.split('\n')).intersection(Set(t2.split('\n'))) + nonempty_common_lines = filter(lambda x: x, common_lines) + return not nonempty_common_lines + +def too_much_new_links(t1, t2): + new_lines = Set(t1.split('\n')).difference(Set(t2.split('\n'))) + count = 0 + for line in new_lines: + count = count + len(link_re.findall(line)) + return count > 2 + hunk ./piki.py 220 + status_map = { None: 'no', False: 'ok', True: 'confl' } hunk ./piki.py 224 - try: savetext = norm_ws( form['savetext'].value ) - except KeyError: savetext = '' - try: oldtext = norm_ws( urlunquote( form['oldtext'].value )) - except KeyError: oldtext = '' - status_map = { None: 'no', False: 'ok', True: 'confl' } + problem = None + try: + savetext = norm_ws( form['savetext'].value ) + oldtext = norm_ws( urlunquote( form['oldtext'].value )) + except KeyError: problem = "Fix your calibration." + else: + if no_nonempty_common_lines(savetext, oldtext): + problem = "Too painful change." + if too_much_new_links(savetext, oldtext): + problem = "Don't be quite so pushy." + if problem: + emit_header() + print "

Boo! %s

" % problem + return + hunk ./piki.py 642 - + hunk ./piki.py 644 - umask(002) + umask(000) }