#!/sw/local/bin/python # This cgi - script will collect information about where a user found my # web - page, and then send him to the page. # variables imported from the form is # name The (optional) name of the user # email The (optional) e-mail of the user # url The referring URL # comment An (optional) comment. import cgi, string, sys MAILTO="forsberg@lysator.liu.se" def standard_header(title): print "Content-type: text/html" print print "%s" % title def standard_footer(name, email): print '
' print '%(name)s' % vars() print "" form=cgi.FieldStorage() if not form.has_key("url"): standard_header("Oops.. no URL given") print "Hmm.. you should at least give me an URL.. anyway" print ", go back and give me the information, or proceed to the" print " new URL of the page: http://www.lysator.liu.se/~forsberg/linux/" standard_footer("Erik Forsberg", "forsberg@lysator.liu.se") sys.exit(0) print "Content-type: text/html" print "Location: http://www.lysator.liu.se/~forsberg/linux/" print print print "Moved.." print "

This page has moved, please visit the new location at" print " http://www.lysator.liu.se/~forsberg/linux/" standard_footer("Erik Forsberg", "forsberg@lysator.liu.se") import smtplib, socket mailsend = smtplib.SMTP('mailhost.lysator.liu.se') msg = "Subject: URLpek: " + form["url"].value + "\n\nHmm.. en trevlig besökare har påpekat:\n\nUrl: " + form["url"].value if form.has_key("name"): msg = msg + "\nNamn: " + form["name"].value if form.has_key("email"): fromstr=form["email"].value msg = msg + "\nMail: " + form["email"].value else: fromstr="urlmoj@hanna.lysator.liu.se" if form.has_key("comment"): msg = msg + "\nComment: " + form["comment"].value toaddr=string.splitfields(MAILTO, ' ') mailsend.sendmail(fromstr, toaddr, msg) mailsend.quit()