Skip to content

mxm, IT's mad science

Sections
Personal tools
You are here: Home » Products » Open Source » mxm Proxy Tool
Downloads
You can download mxm products here.

Due to it's technical and international nature, this section is in english.

Max M Has a blog too.

og er glad for mad

 

mxm Proxy Tool

The mxmProxyTool is a Zope tool that fetches content from an external web source. The content can then be inserted in a page template or dtml page on your own site. Generally speaking, it makes it possible to browse another website, inside the look and feel of your own. It is thought of as a quick and dirty way to integrate external websites with a Zope site.

Simple Usage

You install the tool in the root of your site. Then you make a zpt page that can render the content.

This is the most simple example (simple_proxy.pt):

        <html>
          <body>
                <div tal:content="structure here/mxm_proxytool/browse">
                Proxy content
                </div>
          </body>
        </html>

If you try and render that page in Zope by going to:

        http://www.example.com/simple_proxy

it will show an empty page, as it has no proxy_url.

We can send it a proxy url via the query string:

        http://www.example.com/simple_proxy?mxm_proxy_url=http://slashdot.org

The content of slashdot org will then be rendered in your site. If you click on any of the links on that page, you will continue to browse the site through your page.

WARNING: You must be carefull!

If you use this tool incorrectly, other people can make their own content look like yours. Eg. they can put a credit card payment form into your layout. With an url that comes from you.

So you really must use the allowed_urls flter to make a filter of legal urls that the proxy should show content from.

allowed_urls is a regex for allowed proxy_urls. A regex for allwing all content from slashdot.org could look like this:

        http://slashdot.org(.*?)

So a safer example would look like this:

        <div tal:define="proxy here/mxm_proxytool;"
             tal:content="structure python:proxy.browse(allowed_urls='http://slashdot.org(.*?)')">
        </div>

Tips! If you want to render content inside Plone, you need to convert it to Unicode, so that Plone can encode it as utf-8. So assuming that the site you are proxying is using latin-1 encoding, you can do it like this:

        tal:content="structure python:unicode(proxy.browse(url, allowed_urls='http://slashdot.org(.*?)'), 'latin-1')">

Complete example of browsing slashdot.org. Using slashdot.org as a default url. Meaning that you don't have to pass the initial proxy_url in the query string. You can just enter:

        http://www.example.com/slashdot_proxy

slashdot_proxy.pt:

        <html>
          <head>
            <title>Slashdot</title>
          </head>
          <body>

            <div tal:define="proxy here/mxm_proxytool;
                             url python:request.get(proxy.MXM_PROXY_URL_NAME, 'http://slashdot.org/')"
                tal:content="structure python:unicode(proxy.browse(url, allowed_urls='http://slashdot.org(.*?)'), 'latin-1')">
            </div>

API

mxm Proxy Tool has the following api:

        def browse(proxy_url='', allowed_urls='', data=None, bodyonly=1):
            """
            Returns the content of a webpage and rewrite links
            proxy_url: the page content should be fetched from
            allowed_urls: A regex string showing allowed url patterns
            data: a data dict like defined in pythons urlopen()
            bodyonly: if true it only shows content from inside the <body></body> 
            tags
            """

        def urlopen(url, data=None):
            """
            opens a page and returns the content. Can also be used for logging in to 
            a site with cookie based authentication.

            This is the actual workhorse ot the tool. It also saves and 
            loads cookies for logged in users, so they can browse sites that 
            requires a login, or other cookies.
            """

        def getSoup(content):
            """
            Parses html content with BeautifulSoup. Nice for external methods Check 
            the web for documentation.
            http://www.crummy.com/software/BeautifulSoup/
            """

        def filterBody(source):
            "Returns content between html body tags"

Problems

Try contacting me at maxm@mxm.dk. No promises though.

License

GPL

Requirements

If you log on to a site that needs cookies, you need to use ClientCookie I have had success with

ClientCookie-0.4.19.tar.gz

"1.0.0" didn't work.

Just install it in /lib/python/ or somewhere else in Zopes Python path.

Download

mxmProxyTool.1.1.0.tar.gz

Created by maxm
Last modified 2005-01-14 02:51 PM

Java Applets

Posted by Anonymous User at 2006-05-14 06:06 AM
Will this work with a site that serves up Java applets? I'm looking for a way to group a bunch of small, Java applet-based sites together.

Thanks!

pman

zpt files...?

Posted by Anonymous User at 2007-02-16 02:19 AM
This looks perfect for what I am after - we have a corporate address book in domino, and I am trying to bring this in to a proof-of-concept plone site. It looks like the proxytool is going to work wonders...

The only problem is, I can't figure out how to create a zpt file and edit it. Any pointers?

problems in 2.5.3

Posted by Anonymous User at 2007-08-13 02:41 PM
I have used mxmproxytool in a 2.1 site with great success. After upgrading to 2.5.3, mxmproxytool does not work. There is just a blank page, no errors thrown. Has the product been tested with 2.5.3?