# HG changeset patch # User haftmann # Date 1146642309 -7200 # Node ID 273d2c9866fdd2be8e16b9100a50b2db7f6849f5 # Parent 4103954f3668c60afc014a58a7dcb7295af85d70 improvments in mail obfuscator diff -r 4103954f3668 -r 273d2c9866fd Admin/website/README --- a/Admin/website/README Wed May 03 05:56:11 2006 +0200 +++ b/Admin/website/README Wed May 03 09:45:09 2006 +0200 @@ -53,7 +53,7 @@ You may add arbitrary files to the dir structure, but adhere to the following: * use XHTML, not loose HTML * only structural markup; if you need layout effects, use CSS - (browse the exiting files to get some inspirations) + (browse the existing files to get some inspirations) * any files ending with .html are considered as HTML files and are implicitly processed by the preprocessing layer * for HTML includes, it is most convenient to name them *.include.html to @@ -67,7 +67,7 @@ in abc/def/itsme.html: becomes: - Further, targets are checked for existance. + Further, targets are checked for existence. This is a simple yet powerful thing easing to keep the pages consistent. * for the semantics of the processing instructions, see build/pypager.py source code diff -r 4103954f3668 -r 273d2c9866fd Admin/website/build/make_dep.bash --- a/Admin/website/build/make_dep.bash Wed May 03 05:56:11 2006 +0200 +++ b/Admin/website/build/make_dep.bash Wed May 03 09:45:09 2006 +0200 @@ -55,5 +55,5 @@ echo "DEP_ALLHTML=$allhtml" >> "$DEP_FILE" echo >> "$DEP_FILE" echo 'allsite: $(DEP_ALLHTML) $(DEP_ALLSTATIC)' >> "$DEP_FILE" -echo ' $(PYTHON) build/obfusmail.py --dtd="dtd/" --dstroot="$(OUTPUTROOT)" --dstdir="img"' "$allhtml" >> "$DEP_FILE" +echo ' $(PYTHON) build/obfusmail.py --dtd="dtd/"' "$allhtml" >> "$DEP_FILE" echo ".PHONY: allsite" >> "$DEP_FILE" diff -r 4103954f3668 -r 273d2c9866fd Admin/website/build/obfusmail.py --- a/Admin/website/build/obfusmail.py Wed May 03 05:56:11 2006 +0200 +++ b/Admin/website/build/obfusmail.py Wed May 03 09:45:09 2006 +0200 @@ -31,11 +31,12 @@ pass - def __init__(self, dtd, mails): + def __init__(self, dtd, filename, mails): super(FindHandler, self).__init__(self.DevZero(), outputEncoding, dtd) + self.filename = filename + self.mails = mails self.pending_mail = None - self.mails = mails def startElement(self, name, attrs): @@ -51,7 +52,7 @@ if self.pending_mail is not None: if self.currentContent() != self.pending_mail: raise Exception("Inconsistent mail address: '%s' vs. '%s'" % (self.currentContent(), self.pending_mail)) - self.mails[self.pending_mail] = True + self.mails[(self.filename, self.pending_mail)] = True self.pending_mail = None super(FindHandler, self).endElement(name) @@ -61,9 +62,10 @@ class ReplaceHandler(TransformerHandler): - def __init__(self, out, dtd, mails): + def __init__(self, out, dtd, filename, mails): super(ReplaceHandler, self).__init__(out, outputEncoding, dtd) + self.filename = filename self.pending_mail = None self.mails = mails @@ -82,7 +84,7 @@ if name == u'a': if self.pending_mail is not None: self.flushCharacterBuffer() - self._out.write(self.mails[self.pending_mail]) + self._out.write(self.mails[(self.filename, self.pending_mail)]) self.pending_mail = None return @@ -97,21 +99,25 @@ pass -def obfuscate(mailaddr, dsturl, dstfile): +def obfuscate(mailaddr, htmlfile): def mk_line(s): return u"document.write('%s');" % s.replace("'", "\\'") def mk_script(s): - return u'' % s + return u'' % s + def cmd(s): + print "[shell cmd] %s" % s + n = os.system(s) + if n != 0: + raise Exception("shell cmd error: %s" % n) name, host = mailaddr.split("@", 2) imgname = (name + "_" + host).replace(".", "_"). replace("?", "_") + ".png" - imgfile = path.join(dstfile, imgname) - os.system("convert label:'%s' '%s'" % (mailaddr, imgfile)) + imgfile = path.join(path.split(htmlfile)[0], imgname) + cmd("convert label:'%s' '%s'" % (mailaddr, imgfile)) mailsimple = u"{%s} AT [%s]" % (name, host) - imgurl = posixpath.join(dsturl, imgname) mailscript = u" ".join(map(mk_line, [''])); - mailimg = '%s' % (quoteattr(imgurl), quoteattr(mailsimple)) + mailimg = '%s' % (quoteattr(imgname), quoteattr(mailsimple)) return (mk_script(mailscript) + mailimg + mk_script(mk_line(""))) @@ -124,14 +130,6 @@ description = '''Protecting mail adresses in html files by obfuscating''', add_help_option = True, ) - cmdlineparser.add_option("-d", "--dstroot", - action="store", dest="dstroot", - type="string", default=".", - help="root destination of generated images", metavar='location') - cmdlineparser.add_option("-D", "--dstdir", - action="store", dest="dstdir", - type="string", default=".", - help="root destination of generated images", metavar='location') cmdlineparser.add_option("-t", "--dtd", action="store", dest="dtd", type="string", default=".", @@ -143,20 +141,20 @@ mails = {} for filename in filenames: istream = open(filename, 'r') - findhandler = FindHandler(options.dtd, mails) + findhandler = FindHandler(options.dtd, filename, mails) parseWithER(istream, findhandler) istream.close() # transform mails mails_subst = {} - for mail in mails.keys(): - mails_subst[mail] = obfuscate(mail, options.dstdir, path.join(options.dstroot, options.dstdir)) + for filename, mail in mails.iterkeys(): + mails_subst[(filename, mail)] = obfuscate(mail, filename) # transform pages for filename in filenames: istream = StringIO(open(filename, 'r').read()) ostream = open(filename, 'wb') - replacehandler = ReplaceHandler(ostream, options.dtd, mails_subst) + replacehandler = ReplaceHandler(ostream, options.dtd, filename, mails_subst) parseWithER(istream, replacehandler) ostream.close() istream.close()