On 3 May 2004, at 21:57, Sean Robertson wrote:

I need to be able to send the commands from a PHP script.  There is no
way that I know of to handle the login and execute commends on the HTML
pages from a PHP script.

If you are absolutely bound and determined to use PHP for doing your list admin via the Mailman admin web GUI and the standard Mailman web GUI cannot meet your needs then you can drive the standard Mailman admin GUI by screen scraping. You could certainly do it with Python and I see no in-principle reason why you cannot do it with PHP. A quick web search threw up the CURL client support library for use with PHP which, at first glance, looks like it may be man enough for the job:


http://ca.php.net/manual/en/ref.curl.php

Mailman's web GUI uses cookie authentication and your code has to understand how to do that but it is not rocket science.

The main issue is being able to extract Set-cookie: headers from responses and add Cookie: headers to requests.

As an example, the crude Python code fragment below will login to a Mailman web GUI and extract a list's basic membership admin HTML page.

But be aware of how vulnerable your PHP code is going to be to changes in the Mailman interface, even if it is extremely well thought out. But this is true of all screen scrapers.

Python code fragment follows
----------------------------

import httplib
import urllib
# hardwired list admin password - awful security
parms = urllib.urlencode({'adminpw': 'yourpassword', 'admlogin': 'Let me in...'})
hdrs = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/html"}
conn = httplib.HTTPConnection('server.yourdomain.com:80')
# This request should 'log us in' and get Mailman to return the authentication
# cookie with the list's general options page
conn.request('POST', '/mailman/admin/listname', parms, hdrs)
resp = conn.getresponse()
print resp.status, resp.reason # should be 200 and OK
data = resp.read()
# data now contains the HTML of the list's General options page
conn.close()
# Get the cookie set by Mailman
scookie = resp.getheader('set-cookie')
# Extract the cookie value to return with next request
cookie = scookie.split(';')[0].strip()
nhdrs = {"Accept": "text/html", 'Cookie': cookie}
conn = httplib.HTTPConnection('server.yourdomain.com:80')
# Now get the Membership list page for the list
conn.request('GET', '/mailman/admin/listname/members', None, nhdrs)
resp = conn.getresponse()
print resp.status, resp.reason # should be 200 and OK
data = resp.read()
# data now contains the HTML of the list's Membership List page
conn.close()
...
and so on
...




------------------------------------------------------
Mailman-Users mailing list
[EMAIL PROTECTED]
http://mail.python.org/mailman/listinfo/mailman-users
Mailman FAQ: http://www.python.org/cgi-bin/faqw-mm.py
Searchable Archives: http://www.mail-archive.com/mailman-users%40python.org/

Reply via email to