PDA

View Full Version : pw2db.pl replacement script


catdude
14th January 2008, 20:35
I initially installed the pw2db.pl script that I found recommended on one of threads in this forum. For those who don't use it, it's a script that builds Courier's userdb table from the contents of the /etc/passwd and /etc/shadow files.

The stock version works well enough, but has some limitations that bit me: if you have some long domain names, pw2db.pl maps the system user to a trucated e-mail address, not the full e-mail address. And if you use a user prefix of WEBID instead of DOMAIN, it get's really confused :)

I wrote a replacement for this script. You can find it at http://www.iowatelecom.net/~mahoneyf/scripts. It's written in Python, so you'll need to have python installed. It also reads ISPConfig's database to build user e-mail addresses, so you also need to have the MySQLdb python module (http://sourceforge.net/projects/mysql-python) installed.

Falko and Till, I am querying isp_isp_web, isp_isp_user, and isp_dep to get the information I need. In my query I'm hard-coding "child_doctype_id = 1014" when I'm looking for isp_isp_user records and "parent_doctype_id = 1013" when I'm linking to isp_web records. Is it safe to do this, or should I actually go to the trouble of doing a lookup against "doctype" to determine the doctype_id for "isp_user" and "isp"web"?

Also, the query I use to determine the domain name for a given user is:
"SELECT web_domain FROM isp_isp_web, isp_dep, \
isp_isp_user WHERE user_username = <sys user name> AND \
isp_dep.child_doc_id = isp_isp_user.doc_id AND \
isp_dep.child_doctype_id = 1014 AND \
isp_dep.parent_doc_id = isp_isp_web.doc_id AND \
isp_dep.parent_doctype_id = 1013"
The query I use to determine the user name part of the e-mail address is:
"SELECT user_email FROM isp_isp_user \
WHERE user_username = '<sys user name>'"
Can you confirm that are indeed the proper queries to be using for these purposes?

till
15th January 2008, 09:10
Is it safe to do this, or should I actually go to the trouble of doing a lookup against "doctype" to determine the doctype_id for "isp_user" and "isp"web"?

Thats safe, the docytpe ID's will not change in future. The queries look fine.