diff -urN postfixadmin-2.1.0/ADDITIONS/postfixadmin-domain-postdeletion.sh postfixadmin-2.1.0-arvin-martin/ADDITIONS/postfixadmin-domain-postdeletion.sh --- postfixadmin-2.1.0/ADDITIONS/postfixadmin-domain-postdeletion.sh 1970-01-01 01:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/ADDITIONS/postfixadmin-domain-postdeletion.sh 2007-06-25 22:00:04.000000000 +0200 @@ -0,0 +1,62 @@ +#!/bin/sh + +# Example script for removing a Maildir domain top-level folder +# from a Courier-IMAP virtual mail hierarchy. + +# The script only looks at argument 1, assuming that it +# indicates the relative name of a domain, such as +# "somedomain.com". If $basedir/somedomain.com exists, it will +# be removed. + +# The script will not actually delete the directory. I moves it +# to a special directory which may once in a while be cleaned up +# by the system administrator. + +# This script should be run as the user which owns the maildirs. If +# the script is actually run by the apache user (e.g. through PHP), +# then you could use "sudo" to grant apache the rights to run +# this script as the relevant user. +# Assume this script has been saved as +# /usr/local/bin/postfixadmin-domain-postdeletion.sh and has been +# made executable. Now, an example /etc/sudoers line: +# apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-domain-postdeletion.sh +# The line states that the apache user may run the script as the +# user "courier" without providing a password. + + +# Change this to where you keep your virtual mail users' maildirs. +basedir=/var/spool/maildirs + +# Change this to where you would like deleted maildirs to reside. +trashbase=/var/spool/deleted-maildirs + +if [ `echo $1 | fgrep '..'` ]; then + echo "First argument contained a double-dot sequence; bailing out." + exit 1 +fi + +if [ ! -e "$trashbase" ]; then + echo "trashbase '$trashbase' does not exist; bailing out." + exit 1 +fi + +trashdir="${trashbase}/`date +%F_%T`_$1" +domaindir="${basedir}/$1" + +if [ ! -e "$domaindir" ]; then + echo "Directory '$domaindir' does not exits; nothing to do." + exit 0; +fi +if [ ! -d "$domaindir" ]; then + echo "'$domaindir' is not a directory; bailing out." + exit 1 +fi +if [ -e "$trashdir" ]; then + echo "Directory '$trashdir' already exits; bailing out." + exit 1; +fi + +mv $domaindir $trashdir + +exit $? + diff -urN postfixadmin-2.1.0/ADDITIONS/postfixadmin-mailbox-postcreation.sh postfixadmin-2.1.0-arvin-martin/ADDITIONS/postfixadmin-mailbox-postcreation.sh --- postfixadmin-2.1.0/ADDITIONS/postfixadmin-mailbox-postcreation.sh 1970-01-01 01:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/ADDITIONS/postfixadmin-mailbox-postcreation.sh 2007-06-25 22:00:04.000000000 +0200 @@ -0,0 +1,63 @@ +#!/bin/sh + +# Example script for adding a Maildir to a Courier-IMAP virtual mail +# hierarchy. + +# The script only looks at argument 3, assuming that it +# indicates the relative name of a maildir, such as +# "somedomain.com/peter/". + +# This script should be run as the user which owns the maildirs. If +# the script is actually run by the apache user (e.g. through PHP), +# then you could use "sudo" to grant apache the rights to run +# this script as the relevant user. +# Assume this script has been saved as +# /usr/local/bin/postfixadmin-mailbox-postcreation.sh and has been +# made executable. Now, an example /etc/sudoers line: +# apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postcreation.sh +# The line states that the apache user may run the script as the +# user "courier" without providing a password. + + +# Change this to where you keep your virtual mail users' maildirs. +basedir=/var/spool/maildirs + +if [ ! -e "$basedir" ]; then + echo "basedir '$basedir' does not exist; bailing out." + exit 1 +fi + +if [ `echo $3 | fgrep '..'` ]; then + echo "An argument contained a double-dot sequence; bailing out." + exit 1 +fi + +maildir="${basedir}/$3" +parent=`dirname "$maildir"` +if [ ! -d "$parent" ]; then + if [ -e "$parent" ]; then + echo "Strainge - directory '$parent' exists, but is not a directory." + echo "Bailing out." + exit 1 + else + mkdir -p "${parent}" + if [ $? -ne 0 ]; then + echo "mkdir -p '$parent' returned non-zero; bailing out." + exit 1 + fi + fi +fi + +if [ -e "$maildir" ]; then + echo "Directory '$maildir' already exists! Bailing out" + exit 1 +fi + +maildirmake "$maildir" +if [ ! -d "$maildir" ]; then + echo "maildirmake didn't produce a directory" + echo "Bailing out." + exit 1 +fi + +exit 0 diff -urN postfixadmin-2.1.0/ADDITIONS/postfixadmin-mailbox-postdeletion.sh postfixadmin-2.1.0-arvin-martin/ADDITIONS/postfixadmin-mailbox-postdeletion.sh --- postfixadmin-2.1.0/ADDITIONS/postfixadmin-mailbox-postdeletion.sh 1970-01-01 01:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/ADDITIONS/postfixadmin-mailbox-postdeletion.sh 2007-06-25 22:00:04.000000000 +0200 @@ -0,0 +1,77 @@ +#!/bin/sh + +# Example script for removing a Maildir from a Courier-IMAP virtual mail +# hierarchy. + +# The script looks at arguments 1 and 2, assuming that they +# indicate username and domain, respectively. + +# The script will not actually delete the maildir. I moves it +# to a special directory which may once in a while be cleaned up +# by the system administrator. + +# This script should be run as the user which owns the maildirs. If +# the script is actually run by the apache user (e.g. through PHP), +# then you could use "sudo" to grant apache the rights to run +# this script as the relevant user. +# Assume this script has been saved as +# /usr/local/bin/postfixadmin-mailbox-postdeletion.sh and has been +# made executable. Now, an example /etc/sudoers line: +# apache ALL=(courier) NOPASSWD: /usr/local/bin/postfixadmin-mailbox-postdeletion.sh +# The line states that the apache user may run the script as the +# user "courier" without providing a password. + + +# Change this to where you keep your virtual mail users' maildirs. +basedir=/var/spool/maildirs + +# Change this to where you would like deleted maildirs to reside. +trashbase=/var/spool/deleted-maildirs + + +if [ ! -e "$trashbase" ]; then + echo "trashbase '$trashbase' does not exist; bailing out." + exit 1 +fi + +if [ `echo $1 | fgrep '..'` ]; then + echo "First argument contained a double-dot sequence; bailing out." + exit 1 +fi +if [ `echo $2 | fgrep '..'` ]; then + echo "First argument contained a double-dot sequence; bailing out." + exit 1 +fi + +subdir=`echo "$1" | sed 's/@.*//'` + +maildir="${basedir}/$2/${subdir}" +trashdir="${trashbase}/$2/`date +%F_%T`_${subdir}" + +parent=`dirname "$trashdir"` +if [ ! -d "$parent" ]; then + if [ -e "$parent" ]; then + echo "Strainge - directory '$parent' exists, but is not a directory." + echo "Bailing out." + exit 1 + else + mkdir -p "$parent" + if [ $? -ne 0 ]; then + echo "mkdir -p '$parent' returned non-zero; bailing out." + exit 1 + fi + fi +fi + +if [ ! -e "$maildir" ]; then + echo "maildir '$maildir' does not exist; nothing to do." + exit 1 +fi +if [ -e "$trashdir" ]; then + echo "trashdir '$trashdir' already exists; bailing out." + exit 1 +fi + +mv $maildir $trashdir + +exit $? diff -urN postfixadmin-2.1.0/ADDITIONS/README.TXT postfixadmin-2.1.0-arvin-martin/ADDITIONS/README.TXT --- postfixadmin-2.1.0/ADDITIONS/README.TXT 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/ADDITIONS/README.TXT 2007-06-25 22:00:04.000000000 +0200 @@ -37,3 +37,12 @@ - virtualmaildel.php by George Vieira Deletes all unused mailboxes + +- postfixadmin-mailbox-postcreation.sh +- postfixadmin-mailbox-postdeletion.sh +- postfixadmin-domain-postdeletion.sh +by Troels Arvin +Examples of scripts relevant to the optional +$CONF['mailbox_postcreation_script'], +$CONF['mailbox_postdeletion_script'] and +$CONF['domain_postdeletion_script'] configuration options. diff -urN postfixadmin-2.1.0/admin/backup.php postfixadmin-2.1.0-arvin-martin/admin/backup.php --- postfixadmin-2.1.0/admin/backup.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/backup.php 2007-06-25 22:00:04.000000000 +0200 @@ -21,6 +21,11 @@ require ("../functions.inc.php"); include ("../languages/" . check_language () . ".lang"); +if ('pgsql'==$CONF['database_type']) +{ + print '

Sorry: Backup is currently not supported for your DBMS.

'; +} + if ($_SERVER['REQUEST_METHOD'] == "GET") { umask (077); diff -urN postfixadmin-2.1.0/admin/create-admin.php postfixadmin-2.1.0-arvin-martin/admin/create-admin.php --- postfixadmin-2.1.0/admin/create-admin.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/create-admin.php 2007-06-25 22:00:04.000000000 +0200 @@ -103,4 +103,5 @@ include ("../templates/admin_create-admin.tpl"); include ("../templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/create-domain.php postfixadmin-2.1.0-arvin-martin/admin/create-domain.php --- postfixadmin-2.1.0/admin/create-domain.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/create-domain.php 2007-06-25 22:00:04.000000000 +0200 @@ -82,13 +82,15 @@ $fMailboxes = -1; $fMaxquota = -1; $fBackupmx = 1; + $sqlBackupmx = ('pgsql'==$CONF['database_type']) ? 'true' : 1; } else { $fBackupmx = 0; + $sqlBackupmx = ('pgsql'==$CONF['database_type']) ? 'false' : 0; } - $result = db_query ("INSERT INTO domain (domain,description,aliases,mailboxes,maxquota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,'$fTransport',$fBackupmx,NOW(),NOW())"); + $result = db_query ("INSERT INTO domain (domain,description,aliases,mailboxes,maxquota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,'$fTransport',$sqlBackupmx,NOW(),NOW())"); if ($result['rows'] != 1) { $tMessage = $PALANG['pAdminCreate_domain_result_error'] . "
($fDomain)
"; @@ -111,5 +113,6 @@ include ("../templates/admin_menu.tpl"); include ("../templates/admin_create-domain.tpl"); include ("../templates/footer.tpl"); +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ } ?> diff -urN postfixadmin-2.1.0/admin/create-mailbox.php postfixadmin-2.1.0-arvin-martin/admin/create-mailbox.php --- postfixadmin-2.1.0/admin/create-mailbox.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/create-mailbox.php 2007-06-25 22:00:04.000000000 +0200 @@ -63,7 +63,7 @@ $fPassword2 = escape_string ($_POST['fPassword2']); isset ($_POST['fName']) ? $fName = escape_string ($_POST['fName']) : $fName = "No Name"; $fDomain = escape_string ($_POST['fDomain']); - isset ($_POST['fQuota']) ? $fQuota = escape_string ($_POST['fQuota']) : $fQuota = "0"; + isset ($_POST['fQuota']) ? $fQuota = intval($_POST['fQuota']) : $fQuota = 0; isset ($_POST['fActive']) ? $fActive = escape_string ($_POST['fActive']) : $fActive = "1"; if (isset ($_POST['fMail'])) $fMail = escape_string ($_POST['fMail']); @@ -165,15 +165,22 @@ { $fActive = 0; } + $sqlActive=$fActive; + if ('pgsql'==$CONF['database_type']) + { + $sqlActive=($fActive) ? 'true' : 'false'; + } - $result = db_query ("INSERT INTO alias (address,goto,domain,created,modified,active) VALUES ('$fUsername','$fUsername','$fDomain',NOW(),NOW(),'$fActive')"); + if ('pgsql'==$CONF['database_type']) { $result=db_query("BEGIN"); } + + $result = db_query ("INSERT INTO alias (address,goto,domain,created,modified,active) VALUES ('$fUsername','$fUsername','$fDomain',NOW(),NOW(),'$sqlActive')"); if ($result['rows'] != 1) { $tDomain = $fDomain; $tMessage = $PALANG['pAlias_result_error'] . "
($fUsername -> $fUsername)
"; } - $result = db_query ("INSERT INTO mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$quota','$fDomain',NOW(),NOW(),'$fActive')"); + $result = db_query ("INSERT INTO mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir',$quota,'$fDomain',NOW(),NOW(),'$sqlActive')"); if ($result['rows'] != 1) { $tDomain = $fDomain; @@ -182,50 +189,87 @@ else { - db_log ($CONF['admin_email'], $fDomain, "create mailbox", $fUsername); - - $tDomain = $fDomain; - $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "
($fUsername"; - if ($CONF['generate_password'] == "YES") - { - $tMessage .= " / $fPassword)
"; - } - else + $error=TRUE; // Being pessimistic + if (mailbox_postcreation($fUsername,$fDomain,$maildir)) { - $tMessage .= ")
"; + if ('pgsql'==$CONF['database_type']) + { + $result=db_query("COMMIT"); + + /* should really not be possible: */ + if (!$result) die('COMMIT-query failed.'); + } + $error=FALSE; + } else { + $tMessage .= $PALANG['pCreate_mailbox_result_error'] . "
($fUsername)
"; + if ('pgsql'==$CONF['database_type']) + { + $result=db_query("ROLLBACK"); + + /* should really not be possible: */ + if (!$result) die('ROLLBACK-query failed.'); + } else { + /* + When we cannot count on transactions, we need to move forward, despite + the problems. + */ + $error=FALSE; + } } - - $tQuota = $CONF['maxquota']; - if ($fMail == "on") + if (!$error) { - $fTo = $fUsername; - $fFrom = $CONF['admin_email']; - $fHeaders = "To: " . $fTo . "\n"; - $fHeaders .= "From: " . $fFrom . "\n"; - - if (!empty ($PALANG['charset'])) - { - $fHeaders .= "Subject: " . encode_header ($PALANG['pSendmail_subject_text'], $PALANG['charset']) . "\n"; - $fHeaders .= "MIME-Version: 1.0\n"; - $fHeaders .= "Content-Type: text/plain; charset=" . $PALANG['charset'] . "\n"; - $fHeaders .= "Content-Transfer-Encoding: 8bit\n"; - } - else + db_log ($CONF['admin_email'], $fDomain, "create mailbox", $fUsername); + $tDomain = $fDomain; + + if (create_mailbox_subfolders($fUsername,$fPassword)) { - $fHeaders .= "Subject: " . $PALANG['pSendmail_subject_text'] . "\n\n"; + $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "
($fUsername"; + } else { + $tMessage = $PALANG['pCreate_mailbox_result_succes_nosubfolders'] . "
($fUsername"; } - - $fHeaders .= $CONF['welcome_text']; - if (!smtp_mail ($fTo, $fFrom, $fHeaders)) + if ($CONF['generate_password'] == "YES") { - $tMessage .= "
" . $PALANG['pSendmail_result_error'] . "
"; + $tMessage .= " / $fPassword)
"; } else { - $tMessage .= "
" . $PALANG['pSendmail_result_succes'] . "
"; + $tMessage .= ")
"; + } + + $tQuota = $CONF['maxquota']; + + if ($fMail == "on") + { + $fTo = $fUsername; + $fFrom = $CONF['admin_email']; + $fHeaders = "To: " . $fTo . "\n"; + $fHeaders .= "From: " . $fFrom . "\n"; + + if (!empty ($PALANG['charset'])) + { + $fHeaders .= "Subject: " . encode_header ($PALANG['pSendmail_subject_text'], $PALANG['charset']) . "\n"; + $fHeaders .= "MIME-Version: 1.0\n"; + $fHeaders .= "Content-Type: text/plain; charset=" . $PALANG['charset'] . "\n"; + $fHeaders .= "Content-Transfer-Encoding: 8bit\n"; + } + else + { + $fHeaders .= "Subject: " . $PALANG['pSendmail_subject_text'] . "\n\n"; + } + + $fHeaders .= $CONF['welcome_text']; + + if (!smtp_mail ($fTo, $fFrom, $fHeaders)) + { + $tMessage .= "
" . $PALANG['pSendmail_result_error'] . "
"; + } + else + { + $tMessage .= "
" . $PALANG['pSendmail_result_succes'] . "
"; + } } } } @@ -235,5 +279,6 @@ include ("../templates/admin_menu.tpl"); include ("../templates/create-mailbox.tpl"); include ("../templates/footer.tpl"); +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ } ?> diff -urN postfixadmin-2.1.0/admin/delete.php postfixadmin-2.1.0-arvin-martin/admin/delete.php --- postfixadmin-2.1.0/admin/delete.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/delete.php 2007-06-25 22:00:04.000000000 +0200 @@ -31,7 +31,11 @@ if (isset ($_GET['where'])) $fWhere = escape_string ($_GET['where']); if (isset ($_GET['delete'])) $fDelete = escape_string ($_GET['delete']); if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']); - + + if ($CONF['database_type'] == "pgsql") db_query('BEGIN'); + + $error=0; + if (empty ($fTable)) { $error = 1; @@ -39,7 +43,6 @@ if ($fTable == "domain") { - $result_domain = db_delete ("domain",$fWhere,$fDelete); $result_domain_admins = db_delete ("domain_admins",$fWhere,$fDelete); $result_alias = db_delete ("alias",$fWhere,$fDelete); $result_mailbox = db_delete ("mailbox",$fWhere,$fDelete); @@ -48,8 +51,9 @@ { $result_vacation = db_delete ("vacation",$fWhere,$fDelete); } + $result_domain = db_delete ("domain",$fWhere,$fDelete); - if (!($result_domain == 1) and ($result_domain_admins >= 0) and ($result_alias >= 0) and ($result_mailbox >= 0) and ($result_vacation >= 0)) + if (!$result_domain || !domain_postdeletion($fDelete)) { $error = 1; $tMessage = $PALANG['pAdminDelete_domain_error']; @@ -78,6 +82,7 @@ if ($fTable == "alias" or $fTable == "mailbox") { + if ($CONF['database_type'] == "pgsql") db_query('BEGIN'); $result = db_query ("DELETE FROM alias WHERE address='$fDelete' AND domain='$fDomain'"); if ($result['rows'] != 1) { @@ -90,26 +95,43 @@ db_log ($CONF['admin_email'], $fDomain, "delete alias", $fDelete); } - $result = db_query ("SELECT * FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); - if ($result['rows'] == 1) + if (!$error) { - $result = db_query ("DELETE FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); - if ($result['rows'] != 1) - { - $error = 1; - $tMessage = $PALANG['pDelete_delete_error'] . "$fDelete (mailbox)!"; - } - else + $result = db_query ("SELECT * FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); + if ($result['rows'] == 1) { - $url = "list-virtual.php?domain=$fDomain"; - db_query ("DELETE FROM vacation WHERE email='$fDelete' AND domain='$fDomain'"); - db_log ($CONF['admin_email'], $fDomain, "delete mailbox", $fDelete); + $result = db_query ("DELETE FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); + $postdel_res=mailbox_postdeletion($fDelete,$fDomain); + if ($result['rows'] != 1 || !$postdel_res) + { + $error = 1; + $tMessage = $PALANG['pDelete_delete_error'] . "$fDelete ("; + if (1!=$result['rows']) + { + $tMessage.='mailbox'; + if (!$postdel_res) $tMessage.=', '; + } + if (!$postdel_res) + { + $tMessage.='post-deletion'; + } + $tMessage.=')'; + } + else + { + $url = "list-virtual.php?domain=$fDomain"; + db_query ("DELETE FROM vacation WHERE email='$fDelete' AND domain='$fDomain'"); + db_log ($CONF['admin_email'], $fDomain, "delete mailbox", $fDelete); + } } } } - if ($error != 1) + if (1 == $error) { + if ('pgsql'==$CONF['database_type']) { db_query('ROLLBACK'); } + } else { + if ('pgsql'==$CONF['database_type']) { db_query('COMMIT'); } header ("Location: $url"); exit; } @@ -127,4 +149,5 @@ include ("../templates/message.tpl"); include ("../templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/edit-active-admin.php postfixadmin-2.1.0-arvin-martin/admin/edit-active-admin.php --- postfixadmin-2.1.0/admin/edit-active-admin.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/edit-active-admin.php 2007-06-25 22:00:04.000000000 +0200 @@ -25,8 +25,11 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { if (isset ($_GET['username'])) $fUsername = escape_string ($_GET['username']); - - $result = db_query ("UPDATE admin SET active=1-active WHERE username='$fUsername'"); + + $sqlSet='active=1-active'; + if ('pgsql'==$CONF['database_type']) $sqlSet='active=NOT active'; + + $result = db_query ("UPDATE admin SET $sqlSet,modified=NOW() WHERE username='$fUsername'"); if ($result['rows'] != 1) { $error = 1; @@ -52,4 +55,7 @@ include ("../templates/message.tpl"); include ("../templates/footer.tpl"); } + +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ + ?> diff -urN postfixadmin-2.1.0/admin/edit-active-domain.php postfixadmin-2.1.0-arvin-martin/admin/edit-active-domain.php --- postfixadmin-2.1.0/admin/edit-active-domain.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/edit-active-domain.php 2007-06-25 22:00:04.000000000 +0200 @@ -25,8 +25,11 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']); + + $sqlSet='active=1-active'; + if ('pgsql'==$CONF['database_type']) $sqlSet='active=NOT active'; - $result = db_query ("UPDATE domain SET active=1-active WHERE domain='$fDomain'"); + $result = db_query ("UPDATE domain SET $sqlSet,modified=NOW() WHERE domain='$fDomain'"); if ($result['rows'] != 1) { $error = 1; @@ -52,4 +55,6 @@ include ("../templates/message.tpl"); include ("../templates/footer.tpl"); } + +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/edit-active.php postfixadmin-2.1.0-arvin-martin/admin/edit-active.php --- postfixadmin-2.1.0/admin/edit-active.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/edit-active.php 2007-06-25 22:00:04.000000000 +0200 @@ -28,7 +28,12 @@ if (isset ($_GET['username'])) $fUsername = escape_string ($_GET['username']); if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']); - $result = db_query ("UPDATE mailbox SET active=1-active WHERE username='$fUsername' AND domain='$fDomain'"); + $query = "UPDATE mailbox SET active=1-active WHERE username='$fUsername' AND domain='$fDomain'"; + if ('pgsql'==$CONF['database_type']) + { + $query = "UPDATE mailbox SET active=NOT active WHERE username='$fUsername' AND domain='$fDomain'"; + } + $result = db_query ($query); if ($result['rows'] != 1) { $error = 1; @@ -58,4 +63,5 @@ include ("../templates/message.tpl"); include ("../templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/edit-admin.php postfixadmin-2.1.0-arvin-martin/admin/edit-admin.php --- postfixadmin-2.1.0/admin/edit-admin.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/edit-admin.php 2007-06-25 22:00:04.000000000 +0200 @@ -42,6 +42,7 @@ { $row = db_array ($result['result']); $tActive = $row['active']; + if ('pgsql'==$CONF['database_type']) $tActive=('t'==$tActive) ? TRUE:FALSE; } include ("../templates/header.tpl"); @@ -56,7 +57,9 @@ $fPassword = escape_string ($_POST['fPassword']); $fPassword2 = escape_string ($_POST['fPassword2']); - $fActive = escape_string ($_POST['fActive']); + + $fActive=(isset($_POST['fActive'])) ? escape_string ($_POST['fActive']) : FALSE; + if (isset ($_POST['fDomains'])) $fDomains = $_POST['fDomains']; @@ -65,7 +68,7 @@ if ($fPassword != $fPassword2) { $error = 1; - $tActive = escape_string ($_POST['fActive']); + $tActive = $fActive; $tDomains = escape_string ($_POST['fDomains']); $pAdminEdit_admin_password_text = $PALANG['pAdminEdit_admin_password_text_error']; } @@ -73,16 +76,18 @@ if ($error != 1) { + if ($fActive == "on") $fActive = 1; + $sqlActive=$fActive; + if ('pgsql'==$CONF['database_type']) $sqlActive=($fActive) ? 'true' : 'false'; + if (empty ($fPassword) and empty ($fPassword2)) { - if ($fActive == "on") $fActive = 1; - $result = db_query ("UPDATE admin SET modified=NOW(),active='$fActive' WHERE username='$username'"); + $result = db_query ("UPDATE admin SET modified=NOW(),active='$sqlActive' WHERE username='$username'"); } else { $password = pacrypt ($fPassword); - if ($fActive == "on") $fActive = 1; - $result = db_query ("UPDATE admin SET password='$password',modified=NOW(),active='$fActive' WHERE username='$username'"); + $result = db_query ("UPDATE admin SET password='$password',modified=NOW(),active='$sqlActive' WHERE username='$username'"); } if (sizeof ($fDomains) > 0) @@ -118,4 +123,5 @@ include ("../templates/admin_edit-admin.tpl"); include ("../templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/edit-domain.php postfixadmin-2.1.0-arvin-martin/admin/edit-domain.php --- postfixadmin-2.1.0/admin/edit-domain.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/edit-domain.php 2007-06-25 22:00:04.000000000 +0200 @@ -54,9 +54,13 @@ $domain = escape_string ($_GET['domain']); $fDescription = escape_string ($_POST['fDescription']); - $fAliases = escape_string ($_POST['fAliases']); - $fMailboxes = escape_string ($_POST['fMailboxes']); - if (isset ($_POST['fMaxquota'])) $fMaxquota = escape_string ($_POST['fMaxquota']); + $fAliases = intval($_POST['fAliases']); + $fMailboxes = intval($_POST['fMailboxes']); + if (isset ($_POST['fMaxquota'])) { + $fMaxquota = intval($_POST['fMaxquota']); + } else { + $fMaxquota = 0; + } if (isset ($_POST['fTransport'])) $fTransport = escape_string ($_POST['fTransport']); if (isset ($_POST['fBackupmx'])) $fBackupmx = escape_string ($_POST['fBackupmx']); if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']); @@ -67,15 +71,19 @@ $fMailboxes = -1; $fMaxquota = -1; $fBackupmx = 1; + $sqlBackupmx = ('pgsql'==$CONF['database_type']) ? 'true' : 1; } else { $fBackupmx = 0; + $sqlBackupmx = ('pgsql'==$CONF['database_type']) ? 'false' : 0; } if ($fActive == "on") { $fActive = 1; } - - $result = db_query ("UPDATE domain SET description='$fDescription',aliases='$fAliases',mailboxes='$fMailboxes',maxquota='$fMaxquota',transport='$fTransport',backupmx='$fBackupmx',active='$fActive',modified=NOW() WHERE domain='$domain'"); + $sqlActive=$fActive; + if ('pgsql'==$CONF['database_type']) $sqlActive = $fActive ? 'true':'false'; + + $result = db_query ("UPDATE domain SET description='$fDescription',aliases=$fAliases,mailboxes=$fMailboxes,maxquota=$fMaxquota,transport='$fTransport',backupmx='$sqlBackupmx',active='$sqlActive',modified=NOW() WHERE domain='$domain'"); if ($result['rows'] == 1) { header ("Location: list-domain.php"); @@ -90,4 +98,6 @@ include ("../templates/admin_edit-domain.tpl"); include ("../templates/footer.tpl"); } + +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/edit-mailbox.php postfixadmin-2.1.0-arvin-martin/admin/edit-mailbox.php --- postfixadmin-2.1.0/admin/edit-mailbox.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/edit-mailbox.php 2007-06-25 22:00:04.000000000 +0200 @@ -42,6 +42,10 @@ $tName = $row['name']; $tQuota = $row['quota'] / $CONF['quota_multiplier']; $tActive = $row['active']; + if ('pgsql'==$CONF['database_type']) + { + $tActive = ('t'==$row['active']) ? TRUE:FALSE; + } } else { @@ -66,7 +70,7 @@ $fPassword = escape_string ($_POST['fPassword']); $fPassword2 = escape_string ($_POST['fPassword2']); $fName = escape_string ($_POST['fName']); - if (isset ($_POST['fQuota'])) $fQuota = escape_string ($_POST['fQuota']); + if (isset ($_POST['fQuota'])) $fQuota = intval($_POST['fQuota']); if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']); if ($fPassword != $fPassword2) @@ -109,15 +113,20 @@ { $fActive = 0; } - + $sqlActive=$fActive; + if ('pgsql'==$CONF['database_type']) + { + $sqlActive = ($fActive) ? 'true' : 'false'; + } + if (empty ($fPassword) and empty ($fPassword2)) { - $result = db_query ("UPDATE mailbox SET name='$fName',quota='$quota',modified=NOW(),active='$fActive' WHERE username='$fUsername' AND domain='$fDomain'"); + $result = db_query ("UPDATE mailbox SET name='$fName',quota=$quota,modified=NOW(),active='$sqlActive' WHERE username='$fUsername' AND domain='$fDomain'"); } else { $password = pacrypt ($fPassword); - $result = db_query ("UPDATE mailbox SET password='$password',name='$fName',quota='$quota',modified=NOW(),active='$fActive' WHERE username='$fUsername' AND domain='$fDomain'"); + $result = db_query ("UPDATE mailbox SET password='$password',name='$fName',quota=$quota,modified=NOW(),active='$sqlActive' WHERE username='$fUsername' AND domain='$fDomain'"); } if ($result['rows'] != 1) @@ -138,4 +147,5 @@ include ("../templates/edit-mailbox.tpl"); include ("../templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/list-virtual.php postfixadmin-2.1.0-arvin-martin/admin/list-virtual.php --- postfixadmin-2.1.0/admin/list-virtual.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/list-virtual.php 2007-06-25 22:00:04.000000000 +0200 @@ -35,7 +35,7 @@ $page_size = $CONF['page_size']; if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']); - if (isset ($_GET['limit'])) $fDisplay = escape_string ($_GET['limit']); + if (isset ($_GET['limit'])) $fDisplay = intval ($_GET['limit']); if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) if (empty ($fDomain)) $fDomain = $list_domains[0]; @@ -45,27 +45,50 @@ if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $query = "SELECT address,goto,modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $page_size OFFSET $fDisplay"; + } } else { $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' AND NOT EXISTS(SELECT 1 FROM mailbox WHERE username=alias.address) ORDER BY address LIMIT $page_size OFFSET $fDisplay"; + } } - $result = db_query ("$query"); + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } - $result = db_query ("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); + $query = "SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $page_size OFFSET $fDisplay"; + } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } $tMailbox[] = $row; } } @@ -100,33 +123,56 @@ $page_size = $CONF['page_size']; $fDomain = escape_string ($_POST['fDomain']); - if (isset ($_POST['limit'])) $fDisplay = escape_string ($_POST['limit']); + if (isset ($_POST['limit'])) $fDisplay = intval ($_POST['limit']); $limit = get_domain_properties ($fDomain); if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $query = "SELECT address,goto,modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' ORDER BY alias.address LIMIT $page_size OFFSET $fDisplay"; + } } else { $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT alias.address,alias.goto,extract(epoch from alias.modified) as modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $page_size OFFSET $fDisplay"; + } } - $result = db_query ("$query"); + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } - $result = db_query ("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); + $query="SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"; + if ('pgsql'==$CONF['database_type']) + { + $query="SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $page_size OFFSET $fDisplay"; + } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } $tMailbox[] = $row; } } @@ -153,5 +199,6 @@ include ("../templates/admin_menu.tpl"); include ("../templates/admin_list-virtual.tpl"); include ("../templates/footer.tpl"); +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ } ?> diff -urN postfixadmin-2.1.0/admin/search.php postfixadmin-2.1.0-arvin-martin/admin/search.php --- postfixadmin-2.1.0/admin/search.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/search.php 2007-06-25 22:00:04.000000000 +0200 @@ -32,11 +32,19 @@ if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address"; + $query = "SELECT address,goto,modified,domain FROM alias WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract (epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address"; + } } else { $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%' AND NOT EXISTS(SELECT 1 FROM mailbox WHERE username=alias.address) ORDER BY address"; + } } $result = db_query ("$query"); @@ -45,15 +53,31 @@ { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified'] = gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } - $result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + $query = "SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; + } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + unset($row['uts_created']); + unset($row['uts_modified']); + } $tMailbox[] = $row; } } @@ -70,11 +94,19 @@ if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address"; + $query = "SELECT address,goto,modified,domain FROM alias WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract (epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address"; + } } else { $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT alias.address,alias.goto,extract(epoch from alias.modified) as modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address"; + } } $result = db_query ("$query"); @@ -83,15 +115,31 @@ { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified'] = gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } - $result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + $query = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; + } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + unset($row['uts_created']); + unset($row['uts_modified']); + } $tMailbox[] = $row; } } @@ -101,4 +149,5 @@ include ("../templates/admin_search.tpl"); include ("../templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/admin/viewlog.php postfixadmin-2.1.0-arvin-martin/admin/viewlog.php --- postfixadmin-2.1.0/admin/viewlog.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/admin/viewlog.php 2007-06-25 22:00:04.000000000 +0200 @@ -27,40 +27,35 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { - if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) $fDomain = $list_domains[0]; +} +else +{ + $fDomain = escape_string ($_POST['fDomain']); +} - $result = db_query ("SELECT * FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"); - if ($result['rows'] > 0) - { - while ($row = db_array ($result['result'])) - { - $tLog[] = $row; - } - } - - include ("../templates/header.tpl"); - include ("../templates/admin_menu.tpl"); - include ("../templates/viewlog.tpl"); - include ("../templates/footer.tpl"); +$query = "SELECT timestamp,username,domain,action,substring(data from 1 for 36) as data FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"; +if ('pgsql'==$CONF['database_type']) +{ + $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,substring(data from 1 for 36) as data FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"; } -if ($_SERVER['REQUEST_METHOD'] == "POST") +$result = db_query ($query); +if ($result['rows'] > 0) { - $fDomain = escape_string ($_POST['fDomain']); - - $result = db_query ("SELECT * FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"); - if ($result['rows'] > 0) + while ($row = db_array ($result['result'])) { - while ($row = db_array ($result['result'])) + if ('pgsql'==$CONF['database_type']) { - $tLog[] = $row; + $row['timestamp']=gmstrftime('%c %Z',$row['timestamp']); } + $tLog[] = $row; } - - include ("../templates/header.tpl"); - include ("../templates/admin_menu.tpl"); - include ("../templates/viewlog.tpl"); - include ("../templates/footer.tpl"); } + +include ("../templates/header.tpl"); +include ("../templates/admin_menu.tpl"); +include ("../templates/viewlog.tpl"); +include ("../templates/footer.tpl"); +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/config.inc.php.sample postfixadmin-2.1.0-arvin-martin/config.inc.php.sample --- postfixadmin-2.1.0/config.inc.php.sample 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/config.inc.php.sample 2007-06-25 22:00:04.000000000 +0200 @@ -139,6 +139,53 @@ Welcome to your new account. EOM; +// When creating mailboxes, check that the domain-part of the +// address is legal by performing a name server look-up. +$CONF['emailcheck_resolve_domain']='YES'; + +// Optional: +// Script to run after creation of mailboxes. +// Note that this may fail if PHP is run in "safe mode", or if +// operating system features (such as SELinux) or limitations +// prevent the web-server from executing external scripts. +// $CONF['mailbox_postcreation_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postcreation.sh'; + +// Optional: +// Script to run after deletion of mailboxes. +// Note that this may fail if PHP is run in "safe mode", or if +// operating system features (such as SELinux) or limitations +// prevent the web-server from executing external scripts. +// $CONF['mailbox_postdeletion_script']='sudo -u courier /usr/local/bin/postfixadmin-mailbox-postdeletion.sh'; + +// Optional: +// Script to run after deletion of domains. +// Note that this may fail if PHP is run in "safe mode", or if +// operating system features (such as SELinux) or limitations +// prevent the web-server from executing external scripts. +// $CONF['domain_postdeletion_script']='sudo -u courier /usr/local/bin/postfixadmin-domain-postdeletion.sh'; + +// Optional: +// Sub-folders which should automatically be created for new users. +// The sub-folders will also be subscribed to automatically. +// Will only work with IMAP server which implement sub-folders. +// Will not work with POP3. +// If you define create_mailbox_subdirs, then the +// create_mailbox_subdirs_host must also be defined. +// +// $CONF['create_mailbox_subdirs']=array('Spam'); +// $CONF['create_mailbox_subdirs_host']='localhost'; +// +// Normally, the TCP port number does not have to be specified. +// $CONF['create_mailbox_subdirs_hostport']=143; +// +// If you have trouble connecting to the IMAP-server, then specify +// a value for $CONF['create_mailbox_subdirs_hostoptions']. These +// are some examples to experiment with: +// $CONF['create_mailbox_subdirs_hostoptions']=array('notls'); +// $CONF['create_mailbox_subdirs_hostoptions']=array('novalidate-cert','norsh'); +// See also the "Optional flags for names" table at +// http://www.php.net/manual/en/function.imap-open.php + // // END OF CONFIG FILE // diff -urN postfixadmin-2.1.0/create-mailbox.php postfixadmin-2.1.0-arvin-martin/create-mailbox.php --- postfixadmin-2.1.0/create-mailbox.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/create-mailbox.php 2007-06-25 22:00:04.000000000 +0200 @@ -64,7 +64,7 @@ $fPassword2 = escape_string ($_POST['fPassword2']); $fName = escape_string ($_POST['fName']); $fDomain = escape_string ($_POST['fDomain']); - if (isset ($_POST['fQuota'])) $fQuota = escape_string ($_POST['fQuota']); + if (isset ($_POST['fQuota'])) $fQuota = intval ($_POST['fQuota']); if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']); if (isset ($_POST['fMail'])) $fMail = escape_string ($_POST['fMail']); @@ -176,27 +176,41 @@ { $fActive = 0; } + $sqlActive=$fActive; + if ('pgsql'==$CONF['database_type']) + { + $sqlActive=($fActive) ? 'true' : 'false'; + db_query('BEGIN'); + } - $result = db_query ("INSERT INTO alias (address,goto,domain,created,modified,active) VALUES ('$fUsername','$fUsername','$fDomain',NOW(),NOW(),'$fActive')"); + $result = db_query ("INSERT INTO alias (address,goto,domain,created,modified,active) VALUES ('$fUsername','$fUsername','$fDomain',NOW(),NOW(),'$sqlActive')"); if ($result['rows'] != 1) { $tDomain = $fDomain; $tMessage = $PALANG['pAlias_result_error'] . "
($fUsername -> $fUsername)
"; } - $result = db_query ("INSERT INTO mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$quota','$fDomain',NOW(),NOW(),'$fActive')"); - if ($result['rows'] != 1) + $result = db_query ("INSERT INTO mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$quota','$fDomain',NOW(),NOW(),'$sqlActive')"); + if ($result['rows'] != 1 || !mailbox_postcreation($fUsername,$fDomain,$maildir)) { $tDomain = $fDomain; $tMessage .= $PALANG['pCreate_mailbox_result_error'] . "
($fUsername)
"; + db_query('ROLLBACK'); } else { - + db_query('COMMIT'); db_log ($SESSID_USERNAME, $fDomain, "create mailbox", "$fUsername"); $tDomain = $fDomain; - $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "
($fUsername"; + + if (create_mailbox_subfolders($fUsername,$fPassword)) + { + $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "
($fUsername"; + } else { + $tMessage = $PALANG['pCreate_mailbox_result_succes_nosubfolders'] . "
($fUsername"; + } + if ($CONF['generate_password'] == "YES") { $tMessage .= " / $fPassword)
"; @@ -245,5 +259,6 @@ include ("./templates/menu.tpl"); include ("./templates/create-mailbox.tpl"); include ("./templates/footer.tpl"); +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ } ?> diff -urN postfixadmin-2.1.0/DATABASE_PGSQL.TXT postfixadmin-2.1.0-arvin-martin/DATABASE_PGSQL.TXT --- postfixadmin-2.1.0/DATABASE_PGSQL.TXT 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/DATABASE_PGSQL.TXT 2007-06-25 22:00:04.000000000 +0200 @@ -1,142 +1,154 @@ --- Postfix Admin Release 2.x -- ----------------------------------------------------------- --- --- Copyright (c) 2002 - 2005 High5! --- Created by: Mischa Peters --- --- This is the complete database structure for Postfix Admin. --- If you are installing from scratch you can use this file otherwise you --- need to use the TABLE_CHANGES.TXT or TABLE_BACKUP_MX.TXT that comes with Postfix Admin. --- --- There are 2 entries for a database user in the file. --- One you can use for Postfix and one for Postfix Admin. --- --- If you run this file twice (2x) you will get an error on the user creation in MySQL. --- To go around this you can either comment the lines below "USE MySQL" until "USE postfix". --- Or you can remove the users from the database and run it again. --- --- You can create the database from the shell with: --- creatuser -P postfix --- creatuser -P postfixadmin --- createdb postfix --- psql postfix --- postfix=# \i postfix.sql --- postfix=# \q --- exit --- --- Postfix / PgSQL - --- --- DROP TABLE admin,alias,domain,domain_admins,log,mailbox,vacation; --- - --- --- Table structure for table admin --- -CREATE TABLE "admin" ( - "username" character varying(255) NOT NULL default '', - "password" character varying(255) NOT NULL default '', - "created" timestamp with time zone default now(), - "modified" timestamp with time zone default now(), - "active" boolean NOT NULL default true, - Constraint "admin_key" Primary Key ("username") -); -COMMENT ON TABLE admin IS 'Postfix Admin - Virtual Admins'; --- --- Table structure for table alias --- -CREATE TABLE alias ( - address character varying(255) NOT NULL default '', - goto text NOT NULL, - domain character varying(255) NOT NULL default '', - created timestamp with time zone default now(), - modified timestamp with time zone default now(), - active boolean NOT NULL default true, --- PRIMARY KEY ("address"), --- KEY address ("address"), - Constraint "alias_key" Primary Key ("address") -); -COMMENT ON TABLE alias IS 'Postfix Admin - Virtual Aliases'; - --- --- Table structure for table domain --- -CREATE TABLE domain ( - domain character varying(255) NOT NULL default '', - description character varying(255) NOT NULL default '', - aliases integer NOT NULL default 0, - mailboxes integer NOT NULL default 0, - maxquota integer NOT NULL default 0, - transport character varying(255) default NULL, - backupmx boolean NOT NULL default false, - created timestamp with time zone default now(), - modified timestamp with time zone default now(), - active boolean NOT NULL default true, --- PRIMARY KEY ("domain"), --- KEY domain ("domain"), - Constraint "domain_key" Primary Key ("domain") -); -COMMENT ON TABLE domain IS 'Postfix Admin - Virtual Domains'; - --- --- Table structure for table domain_admins --- -CREATE TABLE domain_admins ( - username character varying(255) NOT NULL default '', - domain character varying(255) NOT NULL default '', - created timestamp with time zone default now(), - active boolean NOT NULL default true --- KEY username ("username") -); -COMMENT ON TABLE domain_admins IS 'Postfix Admin - Domain Admins'; - --- --- Table structure for table log --- -CREATE TABLE log ( - timestamp timestamp with time zone default now(), - username character varying(255) NOT NULL default '', - domain character varying(255) NOT NULL default '', - action character varying(255) NOT NULL default '', - data character varying(255) NOT NULL default '' --- KEY timestamp ("timestamp") -); -COMMENT ON TABLE log IS 'Postfix Admin - Log'; - --- --- Table structure for table mailbox --- -CREATE TABLE mailbox ( - username character varying(255) NOT NULL default '', - password character varying(255) NOT NULL default '', - name character varying(255) NOT NULL default '', - maildir character varying(255) NOT NULL default '', - quota integer NOT NULL default 0, - domain character varying(255) NOT NULL default '', - created timestamp with time zone default now(), - modified timestamp with time zone default now(), - active boolean NOT NULL default true, --- PRIMARY KEY ("username"), --- KEY username ("username"), - Constraint "mailbox_key" Primary Key ("username") -); -COMMENT ON TABLE mailbox IS 'Postfix Admin - Virtual Mailboxes'; - --- --- Table structure for table vacation --- -CREATE TABLE vacation ( - email character varying(255) NOT NULL default '', - subject character varying(255) NOT NULL default '', - body text NOT NULL, - cache text NOT NULL, - domain character varying(255) NOT NULL default '', - created timestamp with time zone default now(), - active boolean NOT NULL default true, --- PRIMARY KEY ("email"), --- KEY email ("email") - Constraint "vacation_key" Primary Key ("email") -); -COMMENT ON TABLE vacation IS 'Postfix Admin - Virtual Vacation'; - -GRANT SELECT,INSERT,UPDATE,DELETE ON admin,alias,domain,domain_admins,log,mailbox,vacation TO postfixadmin_user; +-- Postfix Admin Release 2.x -- +---------------------------------------------------------- +-- +-- Copyright (c) 2002 - 2005 High5! +-- Created by: Mischa Peters +-- +-- This is the complete database structure for Postfix Admin. +-- If you are installing from scratch you can use this file otherwise you +-- need to use the TABLE_CHANGES.TXT or TABLE_BACKUP_MX.TXT that comes with Postfix Admin. +-- +-- There are 2 entries for a database user in the file. +-- One you can use for Postfix and one for Postfix Admin. +-- +-- You can create the database from the shell with: +-- creatuser -P postfix +-- creatuser -P postfixadmin +-- creatuser -P vacation +-- createdb postfix +-- psql postfix +-- postfix=# \i postfix.sql +-- postfix=# \q +-- exit +-- +-- Postfix / PgSQL + +-- +DROP TABLE admin,alias,domain_admins,log,mailbox,vacation_notification,vacation,domain; +-- + +-- +-- Table structure for table domain +-- +CREATE TABLE domain ( + domain character varying(255) NOT NULL, + description character varying(255) NOT NULL default '', + aliases integer NOT NULL default 0, + mailboxes integer NOT NULL default 0, + maxquota integer NOT NULL default 0, + transport character varying(255) default NULL, + backupmx boolean NOT NULL default false, + created timestamp with time zone default now(), + modified timestamp with time zone default now(), + active boolean NOT NULL default true, + Constraint "domain_key" Primary Key ("domain") +); +CREATE INDEX domain_domain_active ON domain(domain,active); +COMMENT ON TABLE domain IS 'Postfix Admin - Virtual Domains'; + +-- +-- Table structure for table admin +-- +CREATE TABLE "admin" ( + "username" character varying(255) NOT NULL, + "password" character varying(255) NOT NULL default '', + "created" timestamp with time zone default now(), + "modified" timestamp with time zone default now(), + "active" boolean NOT NULL default true, + Constraint "admin_key" Primary Key ("username") +); +COMMENT ON TABLE admin IS 'Postfix Admin - Virtual Admins'; +-- +-- Table structure for table alias +-- +CREATE TABLE alias ( + address character varying(255) NOT NULL, + goto text NOT NULL, + domain character varying(255) NOT NULL REFERENCES domain, + created timestamp with time zone default now(), + modified timestamp with time zone default now(), + active boolean NOT NULL default true, + Constraint "alias_key" Primary Key ("address") +); +CREATE INDEX alias_address_active ON alias(address,active); +COMMENT ON TABLE alias IS 'Postfix Admin - Virtual Aliases'; + +-- +-- Table structure for table domain_admins +-- +CREATE TABLE domain_admins ( + username character varying(255) NOT NULL, + domain character varying(255) NOT NULL REFERENCES domain, + created timestamp with time zone default now(), + active boolean NOT NULL default true +); +COMMENT ON TABLE domain_admins IS 'Postfix Admin - Domain Admins'; + +-- +-- Table structure for table log +-- +CREATE TABLE log ( + timestamp timestamp with time zone default now(), + username character varying(255) NOT NULL default '', + domain character varying(255) NOT NULL default '', + action character varying(255) NOT NULL default '', + data text NOT NULL default '' +); +COMMENT ON TABLE log IS 'Postfix Admin - Log'; + +-- +-- Table structure for table mailbox +-- +CREATE TABLE mailbox ( + username character varying(255) NOT NULL, + password character varying(255) NOT NULL default '', + name character varying(255) NOT NULL default '', + maildir character varying(255) NOT NULL default '', + quota integer NOT NULL default 0, + domain character varying(255) NOT NULL REFERENCES domain, + created timestamp with time zone default now(), + modified timestamp with time zone default now(), + active boolean NOT NULL default true, + Constraint "mailbox_key" Primary Key ("username") +); +CREATE INDEX mailbox_username_active ON mailbox(username,active); +COMMENT ON TABLE mailbox IS 'Postfix Admin - Virtual Mailboxes'; + +CREATE TABLE vacation ( + email character varying(255) PRIMARY KEY, + subject character varying(255) NOT NULL, + body text NOT NULL, + "domain" character varying(255) NOT NULL REFERENCES "domain", + created timestamp with time zone DEFAULT now(), + active boolean DEFAULT true NOT NULL +); +CREATE INDEX vacation_email_active ON vacation(email,active); + +CREATE TABLE vacation_notification ( + on_vacation character varying(255) NOT NULL REFERENCES vacation(email) ON DELETE CASCADE, + notified character varying(255) NOT NULL, + notified_at timestamp with time zone NOT NULL DEFAULT now(), + CONSTRAINT vacation_notification_pkey primary key(on_vacation,notified) +); +-- Note: It's important the the primary key constraint on vacation_notification +-- be given a name which includes the '_pkey' substring (default PostgreSQL naming +-- for primary keys). The vacation-script looks for this substring to +-- distinguish between an acceptable and non-acceptable error. + + +GRANT + SELECT,INSERT,UPDATE,DELETE +ON + admin, + alias, + domain, + domain_admins, + log, + mailbox, + vacation +TO postfixadmin; + +GRANT SELECT ON alias,domain,mailbox TO postfix; + +GRANT SELECT ON vacation TO vacation; +GRANT SELECT,INSERT,DELETE ON vacation_notification TO vacation; diff -urN postfixadmin-2.1.0/delete.php postfixadmin-2.1.0-arvin-martin/delete.php --- postfixadmin-2.1.0/delete.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/delete.php 2007-06-25 22:00:04.000000000 +0200 @@ -37,7 +37,7 @@ } else { - + if ($CONF['database_type'] == "pgsql") db_query('BEGIN'); $result = db_query ("DELETE FROM alias WHERE address='$fDelete' AND domain='$fDomain'"); if ($result['rows'] != 1) { @@ -46,7 +46,7 @@ } else { - db_log ($SESSID_USERNAME, $fDomain, "delete alias", $fDelete); + if ($CONF['database_type'] != "pgsql") db_log ($SESSID_USERNAME, $fDomain, "delete alias", $fDelete); } $result = db_query ("SELECT * FROM mailbox WHERE username='$fDelete' AND domain='$fDomain'"); @@ -56,20 +56,34 @@ if ($result['rows'] != 1) { $error = 1; + $tMessage = $PALANG['pDelete_delete_error'] . "$fDelete (mailbox)!"; } else { db_query ("DELETE FROM vacation WHERE email='$fDelete' AND domain='$fDomain'"); - db_log ($SESSID_USERNAME, $fDomain, "delete mailbox", $fDelete); + if ($CONF['database_type'] != "pgsql") db_log ($SESSID_USERNAME, $fDomain, "delete mailbox", $fDelete); } } } - if ($error != 1) + if ($error!=1) $postdel=mailbox_postdeletion($fDelete,$fDomain); + + if ($error != 1 && $postdel) { + if ($CONF['database_type'] == "pgsql") { + db_query('COMMIT'); + db_log ($SESSID_USERNAME, $fDomain, "delete alias", $fDelete); + db_log ($SESSID_USERNAME, $fDomain, "delete mailbox", $fDelete); + } header ("Location: overview.php?domain=$fDomain"); exit; + } else { + if (!$postdel) + { + $tMessage = $PALANG['pDelete_delete_error'] . "$fDelete (physical mail)!"; + } + if ($CONF['database_type'] == "pgsql") db_query('ROLLBACK'); } include ("./templates/header.tpl"); @@ -85,4 +99,5 @@ include ("./templates/message.tpl"); include ("./templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/edit-active.php postfixadmin-2.1.0-arvin-martin/edit-active.php --- postfixadmin-2.1.0/edit-active.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/edit-active.php 2007-06-25 22:00:04.000000000 +0200 @@ -37,7 +37,8 @@ } else { - $result = db_query ("UPDATE mailbox SET active=1-active WHERE username='$fUsername' AND domain='$fDomain'"); + $setSql=('pgsql'==$CONF['database_type']) ? 'active=NOT active' : 'active=1-active'; + $result = db_query ("UPDATE mailbox SET $setSql WHERE username='$fUsername' AND domain='$fDomain'"); if ($result['rows'] != 1) { $error = 1; @@ -68,4 +69,5 @@ include ("./templates/message.tpl"); include ("./templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/edit-mailbox.php postfixadmin-2.1.0-arvin-martin/edit-mailbox.php --- postfixadmin-2.1.0/edit-mailbox.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/edit-mailbox.php 2007-06-25 22:00:04.000000000 +0200 @@ -46,6 +46,7 @@ $tName = $row['name']; $tQuota = $row['quota'] / $CONF['quota_multiplier']; $tActive = $row['active']; + if ('pgsql'==$CONF['database_type']) $tActive = ('t'==$row['active']) ? 1 : 0; } } else @@ -123,15 +124,17 @@ { $fActive = 0; } - + $sqlActive=$fActive; + if ('pgsql'==$CONF['database_type']) $sqlActive=($fActive) ? 'true':'false'; + if (empty ($fPassword) and empty ($fPassword2)) { - $result = db_query ("UPDATE mailbox SET name='$fName',quota='$quota',modified=NOW(),active='$fActive' WHERE username='$fUsername' AND domain='$fDomain'"); + $result = db_query ("UPDATE mailbox SET name='$fName',quota=$quota,modified=NOW(),active=$sqlActive WHERE username='$fUsername' AND domain='$fDomain'"); } else { $password = pacrypt ($fPassword); - $result = db_query ("UPDATE mailbox SET password='$password',name='$fName',quota='$quota',modified=NOW(),active='$fActive' WHERE username='$fUsername' AND domain='$fDomain'"); + $result = db_query ("UPDATE mailbox SET password='$password',name='$fName',quota=$quota,modified=NOW(),active=$sqlActive WHERE username='$fUsername' AND domain='$fDomain'"); } if ($result['rows'] != 1) @@ -152,4 +155,5 @@ include ("./templates/edit-mailbox.tpl"); include ("./templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/functions.inc.php postfixadmin-2.1.0-arvin-martin/functions.inc.php --- postfixadmin-2.1.0/functions.inc.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/functions.inc.php 2007-06-25 22:00:04.000000000 +0200 @@ -106,6 +106,41 @@ // function check_email ($email) { + global $CONF; + + if ( + isset($CONF['emailcheck_resolve_domain']) + && 'YES'==$CONF['emailcheck_resolve_domain'] + && 'WINDOWS'!=(strtoupper(substr(php_uname('s'), 0, 7))) + ) { + // Perform non-domain-part sanity checks + if (!preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '[^@]+$/i', trim ($email))) + { + return false; + } + + // Determine domain name + $matches=array(); + if (!preg_match('|@(.+)$|',$email,$matches)) + { + return false; + } + $domain=$matches[1]; + + // Look for an AAAA, A, or MX record for the domain + + // AAAA (IPv6) is only available in PHP v. >= 5 + if (version_compare(phpversion(), "5.0.0", ">=")) + { + if (checkdnsrr($domain,'AAAA')) return true; + } + + if (checkdnsrr($domain,'A')) return true; + if (checkdnsrr($domain,'MX')) return true; + + return false; + } + if (preg_match ('/^[-!#$%&\'*+\\.\/0-9=?A-Z^_{|}~]+' . '@' . '([-0-9A-Z]+\.)+' . '([0-9A-Z]){2,4}$/i', trim ($email))) { return true; @@ -150,7 +185,7 @@ { global $CONF; $list = array (); - + $result = db_query ("SELECT COUNT(*) FROM alias WHERE domain='$domain'"); $row = db_row ($result['result']); $list['alias_count'] = $row[0]; @@ -167,7 +202,19 @@ $list['alias_count'] = $list['alias_count']; } - $result = db_query ("SELECT * FROM domain WHERE domain='$domain'"); + $sql="SELECT * FROM domain WHERE domain='$domain'"; + if ('pgsql'==$CONF['database_type']) + { + $sql=" + SELECT + *, + EXTRACT(epoch FROM created) AS uts_created, + EXTRACT(epoch FROM modified) AS uts_modified + FROM domain + WHERE domain='$domain' + "; + } + $result = db_query ($sql); $row = db_array ($result['result']); $list['description'] = $row['description']; $list['aliases'] = $row['aliases']; @@ -181,23 +228,10 @@ if ($CONF['database_type'] == "pgsql") { - if ($row['active'] == "t") - { - $list['active'] = 1; - } - else - { - $list['active'] = 0; - } - - if ($row['backupmx'] == "t") - { - $list['backupmx'] = 1; - } - else - { - $list['backupmx'] = 0; - } + $list['active']=('t'==$row['active']) ? 1 : 0; + $list['backupmx']=('t'==$row['backupmx']) ? 1 : 0; + $list['created']= gmstrftime('%c %Z',$row['uts_created']); + $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); } else { @@ -325,14 +359,25 @@ // function list_domains_for_admin ($username) { + global $CONF; $list = array (); - $result = db_query ("SELECT * FROM domain LEFT JOIN domain_admins ON domain.domain=domain_admins.domain WHERE domain_admins.username='$username' AND domain.active='1' AND domain.backupmx='0' ORDER BY domain_admins.domain"); + $query = "SELECT * FROM domain LEFT JOIN domain_admins ON domain.domain=domain_admins.domain WHERE domain_admins.username='$username' AND domain.active='1' AND domain.backupmx='0' ORDER BY domain_admins.domain"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT * FROM domain LEFT JOIN domain_admins ON domain.domain=domain_admins.domain WHERE domain_admins.username='$username' AND domain.active=true AND domain.backupmx=false ORDER BY domain_admins.domain"; + } + $result = db_query ($query); if ($result['rows'] > 0) { $i = 0; while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['active'] = ('t'==$row['active'] ? 1 : 0); + $row['backupmx'] = ('t'==$row['backupmx'] ? 1 : 0); + } $list[$i] = $row['domain']; $i++; } @@ -437,17 +482,35 @@ // Call: get_admin_properties (string admin) function get_admin_properties ($username) { + global $CONF; $list = array (); $result = db_query ("SELECT COUNT(*) FROM domain_admins WHERE username='$username'"); $row = db_row ($result['result']); $list['domain_count'] = $row[0]; - - $result = db_query ("SELECT * FROM admin WHERE username='$username'"); + + $sql = "SELECT * FROM admin WHERE username='$username'"; + if ('pgsql'==$CONF['database_type']) { + $sql=" + SELECT + *, + EXTRACT(epoch FROM created) AS uts_created, + EXTRACT (epoch FROM modified) AS uts_modified + FROM admin + WHERE username='$username' + "; + } + + $result = db_query ($sql); $row = db_array ($result['result']); $list['created'] = $row['created']; $list['modified'] = $row['modified']; $list['active'] = $row['active']; + if ('pgsql'==$CONF['database_type']) { + $list['active'] = ('t'==$row['active']) ? 1 : 0; + $list['created']= gmstrftime('%c %Z',$row['uts_created']); + $list['modified']= gmstrftime('%c %Z',$row['uts_modified']); + } return $list; } @@ -856,10 +919,10 @@ if ($CONF['database_type'] == "pgsql") { - if (function_exists ("pg_connect")) + if (function_exists ("pg_pconnect")) { $connect_string = "host=" . $CONF['database_host'] . " dbname=" . $CONF['database_name'] . " user=" . $CONF['database_user'] . " password=" . $CONF['database_password']; - $link = @pg_connect ($connect_string) or die ("

DEBUG INFORMATION:
Connect: " . pg_last_error () . "$DEBUG_TEXT"); + $link = @pg_pconnect ($connect_string) or die ("

DEBUG INFORMATION:
Connect: " . pg_last_error () . "$DEBUG_TEXT"); } else { @@ -916,12 +979,6 @@ if ($CONF['database_type'] == "mysqli") $result = @mysqli_query ($link, $query) or die ("

DEBUG INFORMATION:
Invalid query: " . mysqli_error() . "$DEBUG_TEXT"); if ($CONF['database_type'] == "pgsql") { - if (eregi ("LIMIT", $query)) - { - $search = "/LIMIT (\w+), (\w+)/"; - $replace = "LIMIT \$2 OFFSET \$1"; - $query = preg_replace ($search, $replace, $query); - } $result = @pg_query ($link, $query) or die ("

DEBUG INFORMATION:
Invalid query: " . pg_last_error() . "$DEBUG_TEXT"); } @@ -1046,4 +1103,208 @@ } } +/* + Called after a mailbox has been created in the DBMS. + Returns: boolean. +*/ +function mailbox_postcreation($username,$domain,$maildir) +{ + if (empty($username) || empty($domain) || empty($maildir)) + { + trigger_error('In '.__FUNCTION__.': empty username, domain and/or maildir parameter',E_USER_ERROR); + return FALSE; + } + + global $CONF; + $confpar='mailbox_postcreation_script'; + + if (!isset($CONF[$confpar]) || empty($CONF[$confpar])) return TRUE; + + $cmdarg1=escapeshellarg($username); + $cmdarg2=escapeshellarg($domain); + $cmdarg3=escapeshellarg($maildir); + $command=$CONF[$confpar]." $cmdarg1 $cmdarg2 $cmdarg3"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) + { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + print '

WARNING: Problems running mailbox postcreation script!

'; + return FALSE; + } + + return TRUE; +} + +/* + Called after a mailbox has been deleted in the DBMS. + Returns: boolean. +*/ +function mailbox_postdeletion($username,$domain) +{ + global $CONF; + $confpar='mailbox_postdeletion_script'; + + if (!isset($CONF[$confpar]) || empty($CONF[$confpar])) + { + return true; + } + + if (empty($username) || empty($domain)) + { + print '

Warning: empty username and/or domain parameter.

'; + return false; + } + + $cmdarg1=escapeshellarg($username); + $cmdarg2=escapeshellarg($domain); + $command=$CONF[$confpar]." $cmdarg1 $cmdarg2"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) + { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + print '

WARNING: Problems running mailbox postdeletion script!

'; + return FALSE; + } + + return TRUE; +} + +/* + Called after a domain has been deleted in the DBMS. + Returns: boolean. +*/ +function domain_postdeletion($domain) +{ + global $CONF; + $confpar='domain_postdeletion_script'; + + if (!isset($CONF[$confpar]) || empty($CONF[$confpar])) + { + return true; + } + + if (empty($domain)) + { + print '

Warning: empty domain parameter.

'; + return false; + } + + $cmdarg1=escapeshellarg($domain); + $command=$CONF[$confpar]." $cmdarg1"; + $retval=0; + $output=array(); + $firstline=''; + $firstline=exec($command,$output,$retval); + if (0!=$retval) + { + error_log("Running $command yielded return value=$retval, first line of output=$firstline"); + print '

WARNING: Problems running domain postdeletion script!

'; + return FALSE; + } + + return TRUE; +} + +/* + Called by mailbox_postcreation() after a mailbox has been + created. Immediately returns, unless configuration indicates + that one or more sub-folders should be created. + + Triggers E_USER_ERROR if configuration error is detected. + + If IMAP login fails, the problem is logged to the system log + (such as /var/log/httpd/error_log), and the function returns + FALSE. + + Returns FALSE on all other errors, or TRUE if everything + succeeds. + + Doesn't clean up, if only some of the folders could be + created. +*/ +function create_mailbox_subfolders($login,$cleartext_password) +{ + global $CONF; + + if (empty($login)) + { + trigger_error('In '.__FUNCTION__.': empty $login',E_USER_ERROR); + return FALSE; + } + + if (!isset($CONF['create_mailbox_subdirs']) || empty($CONF['create_mailbox_subdirs'])) return TRUE; + + if (!is_array($CONF['create_mailbox_subdirs'])) + { + trigger_error('create_mailbox_subdirs must be an array',E_USER_ERROR); + return FALSE; + } + + if (!isset($CONF['create_mailbox_subdirs_host']) || empty($CONF['create_mailbox_subdirs_host'])) + { + trigger_error('An IMAP/POP server host ($CONF["create_mailbox_subdirs_host"]) must be configured, if sub-folders are to be created',E_USER_ERROR); + return FALSE; + } + + $s_host=$CONF['create_mailbox_subdirs_host']; + $s_options=''; + $s_port=''; + + if ( + isset($CONF['create_mailbox_subdirs_hostoptions']) + && !empty($CONF['create_mailbox_subdirs_hostoptions']) + ) { + if (!is_array($CONF['create_mailbox_subdirs_hostoptions'])) + { + trigger_error('The $CONF["create_mailbox_subdirs_hostoptions"] parameter must be an array',E_USER_ERROR); + return FALSE; + } + foreach ($CONF['create_mailbox_subdirs_hostoptions'] as $o) + { + $s_options.='/'.$o; + } + } + + if (isset($CONF['create_mailbox_subdirs_hostport']) && !empty($CONF['create_mailbox_subdirs_hostport'])) + { + $s_port=$CONF['create_mailbox_subdirs_hostport']; + if (intval($s_port)!=$s_port) + { + trigger_error('The $CONF["create_mailbox_subdirs_hostport"] parameter must be an integer',E_USER_ERROR); + return FALSE; + } + $s_port=':'.$s_port; + } + + $s='{'.$s_host.$s_port.$s_options.'}'; + + $i=@imap_open($s,$login,$cleartext_password); + if (FALSE==$i) + { + error_log('Could not log into IMAP/POP server: '.imap_last_error()); + return FALSE; + } + + foreach($CONF['create_mailbox_subdirs'] as $f) + { + $f='{'.$s_host.'}INBOX.'.$f; + $res=imap_createmailbox($i,$f); + if (!$res) { + @imap_close($i); + return FALSE; + } + @imap_subscribe($i,$f); + } + + @imap_close($i); + return TRUE; +} + +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/languages/da.lang postfixadmin-2.1.0-arvin-martin/languages/da.lang --- postfixadmin-2.1.0/languages/da.lang 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/languages/da.lang 2007-06-25 22:00:04.000000000 +0200 @@ -64,6 +64,7 @@ $PALANG['pOverview_get_modified'] = 'Senest rettet'; $PALANG['pDelete_delete_error'] = 'Kan ikke slette denne post '; +$PALANG['pDelete_postdelete_error'] = 'Kunne ikke fjerne postkassen '; $PALANG['pDelete_domain_error'] = 'Dette domæne er ikke dit '; $PALANG['pCreate_alias_welcome'] = 'Opret nyt alias til dit domæne.'; @@ -77,7 +78,7 @@ $PALANG['pCreate_alias_goto_text_error'] = 'Hvor emailen skal videresendes til.
Modtageradressen er ikke gyldig!'; $PALANG['pCreate_alias_result_error'] = 'Kan ikke tilføje aliaset til alias-tabellen!'; $PALANG['pCreate_alias_result_succes'] = 'Aliaset er blevet tilføjet til alias-tabellen!'; -$PALANG['pCreate_alias_catchall_text'] = 'For at oprette et stjerne-alias, brug en "*" som alias.
For dom%aelig;ne til domæne-viderestilling brug "*@domain.tld" som modtager.'; +$PALANG['pCreate_alias_catchall_text'] = 'For at oprette et stjerne-alias, brug en "*" som alias.
For domæne til domæne-viderestilling brug "*@domain.tld" som modtager.'; $PALANG['pEdit_alias_welcome'] = 'Rediger et alias for dit domæne.
En modtager pr. linie.'; $PALANG['pEdit_alias_address'] = 'Alias'; @@ -104,10 +105,11 @@ $PALANG['pCreate_mailbox_quota_text'] = 'MB'; $PALANG['pCreate_mailbox_quota_text_error'] = 'MB
Den ønskede kvota er for høj!'; $PALANG['pCreate_mailbox_active'] = 'Aktiv'; -$PALANG['pCreate_mailbox_mail'] = 'Opret postboks'; +$PALANG['pCreate_mailbox_mail'] = 'Send velkomsthilsen'; $PALANG['pCreate_mailbox_button'] = 'Tilføj postboks'; $PALANG['pCreate_mailbox_result_error'] = 'Kan ikke tilføje postboksen til postboks-tabellen!'; $PALANG['pCreate_mailbox_result_succes'] = 'Postboksen er tilføjet til postboks-tabellen!'; +$PALANG['pCreate_mailbox_result_succes_nosubfolders'] = 'Postkassen er tilføjet, men ingen (eller kun dele) af de foruddefinerede underfoldere kunne oprettes.'; $PALANG['pEdit_mailbox_welcome'] = 'Rediger en postboks til dit domæne.'; $PALANG['pEdit_mailbox_username'] = 'Brugernavn'; @@ -243,6 +245,8 @@ $PALANG['pAdminCreate_admin_result_succes'] = 'Administrator er tilføjet!'; $PALANG['pAdminCreate_admin_address'] = 'Domæne'; +$PALANG['pAdminDelete_domain_error'] = 'Kunne ikke fjerne domænet!'; + $PALANG['pAdminEdit_admin_welcome'] = 'Rediger en domæneadministrator'; $PALANG['pAdminEdit_admin_username'] = 'Administrator'; $PALANG['pAdminEdit_admin_password'] = 'Kodeord'; @@ -278,7 +282,7 @@ I nødstilfælde kan kontaktes. EOM; $PALANG['pUsersVacation_button_away'] = 'Tager afsted'; -$PALANG['pUsersVacation_button_back'] = 'Kommer tilbage'; +$PALANG['pUsersVacation_button_back'] = 'Er kommet tilbage'; $PALANG['pUsersVacation_result_error'] = 'Kan ikke opdatere dine autosvar indstillinger!'; $PALANG['pUsersVacation_result_succes'] = 'Dit autosvar er fjernet!'; diff -urN postfixadmin-2.1.0/languages/en.lang postfixadmin-2.1.0-arvin-martin/languages/en.lang --- postfixadmin-2.1.0/languages/en.lang 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/languages/en.lang 2007-06-25 22:00:04.000000000 +0200 @@ -64,6 +64,7 @@ $PALANG['pOverview_get_modified'] = 'Last Modified'; $PALANG['pDelete_delete_error'] = 'Unable to delete the entry '; +$PALANG['pDelete_postdelete_error'] = 'Unable to remove mailbox '; $PALANG['pDelete_domain_error'] = 'This domain is not yours '; $PALANG['pCreate_alias_welcome'] = 'Create a new alias for your domain.'; @@ -104,10 +105,11 @@ $PALANG['pCreate_mailbox_quota_text'] = 'MB'; $PALANG['pCreate_mailbox_quota_text_error'] = 'MB
The quota that you specified is to high!'; $PALANG['pCreate_mailbox_active'] = 'Active'; -$PALANG['pCreate_mailbox_mail'] = 'Create mailbox'; +$PALANG['pCreate_mailbox_mail'] = 'Send Welcome mail'; $PALANG['pCreate_mailbox_button'] = 'Add Mailbox'; $PALANG['pCreate_mailbox_result_error'] = 'Unable to add the mailbox to the mailbox table!'; $PALANG['pCreate_mailbox_result_succes'] = 'The mailbox has been added to the mailbox table!'; +$PALANG['pCreate_mailbox_result_succes_nosubfolders'] = 'The mailbox has been added to the mailbox table, but none (or only some) of the predefined sub-folders could be created'; $PALANG['pEdit_mailbox_welcome'] = 'Edit a mailbox for your domain.'; $PALANG['pEdit_mailbox_username'] = 'Username'; @@ -214,6 +216,8 @@ $PALANG['pAdminCreate_domain_result_error'] = 'Unable to add domain!'; $PALANG['pAdminCreate_domain_result_succes'] = 'Domain has been added!'; +$PALANG['pAdminDelete_domain_error'] = 'Unable to remove domain!'; + $PALANG['pAdminEdit_domain_welcome'] = 'Edit a domain'; $PALANG['pAdminEdit_domain_domain'] = 'Domain'; $PALANG['pAdminEdit_domain_description'] = 'Description'; diff -urN postfixadmin-2.1.0/overview.php postfixadmin-2.1.0-arvin-martin/overview.php --- postfixadmin-2.1.0/overview.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/overview.php 2007-06-25 22:00:30.000000000 +0200 @@ -34,6 +34,8 @@ $tAlias = array(); $tMailbox = array(); +$limit = get_domain_properties ($fDomain); + if ($_SERVER['REQUEST_METHOD'] == "GET") { $fDisplay = 0; @@ -42,17 +44,26 @@ if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']); if (isset ($_GET['limit'])) $fDisplay = escape_string ($_GET['limit']); + $limitSql=('pgsql'==$CONF['database_type']) ? "$page_size OFFSET $fDisplay" : "$fDisplay, $page_size"; + if (check_owner ($SESSID_USERNAME, $fDomain)) { - $limit = get_domain_properties ($fDomain); if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $query = "SELECT address,goto,modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $limitSql"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $limitSql"; + } } else { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $limitSql"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' AND NOT EXISTS(SELECT 1 FROM mailbox WHERE username=alias.address) ORDER BY address LIMIT $limitSql"; + } } $result = db_query ("$query"); @@ -60,15 +71,32 @@ { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } - $result = db_query ("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); + $query = "SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; + } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + unset($row['uts_created']); + unset($row['uts_modified']); + } $tMailbox[] = $row; } } @@ -116,15 +144,23 @@ { $fDomain = escape_string ($_POST['fDomain']); - $limit = get_domain_properties ($fDomain); - + $limitSql=('pgsql'==$CONF['database_type']) ? "$page_size OFFSET $fDisplay" : "$fDisplay, $page_size"; + if ($CONF['alias_control'] == "YES") { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias WHERE alias.domain='$fDomain' ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $query = "SELECT address,goto,modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $limitSql"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' ORDER BY address LIMIT $limitSql"; + } } else { - $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $fDisplay, $page_size"; + $query = "SELECT alias.address,alias.goto,alias.modified FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.domain='$fDomain' AND mailbox.maildir IS NULL ORDER BY alias.address LIMIT $limitSql"; + if ('pgsql'==$CONF['database_type']) + { + $query="SELECT address,goto,extract(epoch from modified) as modified FROM alias WHERE domain='$fDomain' AND NOT EXISTS(SELECT 1 FROM mailbox WHERE username=alias.address) ORDER BY address LIMIT $limitSql"; + } } $result = db_query ("$query"); @@ -132,15 +168,27 @@ { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) $row['modified']=gmstrftime('%c %Z',$row['modified']); $tAlias[] = $row; } } - $result = db_query ("SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $fDisplay, $page_size"); + $query = "SELECT * FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE domain='$fDomain' ORDER BY username LIMIT $limitSql"; + } + $result = db_query ($query); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + } $tMailbox[] = $row; } } @@ -169,4 +217,5 @@ include ("./templates/overview.tpl"); include ("./templates/footer.tpl"); } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/search.php postfixadmin-2.1.0-arvin-martin/search.php --- postfixadmin-2.1.0/search.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/search.php 2007-06-25 22:00:04.000000000 +0200 @@ -35,10 +35,18 @@ if ($CONF['alias_control'] == "YES") { $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address"; + } } else { $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%'AND NOT EXISTS(SELECT 1 FROM mailbox WHERE username=alias.address) ORDER BY address"; + } } $result = db_query ("$query"); @@ -49,18 +57,36 @@ { if (check_owner ($SESSID_USERNAME, $row['domain'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } $tAlias[] = $row; } } } - $result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + $query = ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; + } + + $result = db_query ("$query"); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { if (check_owner ($SESSID_USERNAME, $row['domain'])) { + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + unset($row['uts_created']); + unset($row['uts_modified']); + } $tMailbox[] = $row; } } @@ -79,10 +105,18 @@ if ($CONF['alias_control'] == "YES") { $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias WHERE alias.address LIKE '%$fSearch%' OR alias.goto LIKE '%$fSearch%' ORDER BY alias.address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%' OR goto LIKE '%$fSearch%' ORDER BY address"; + } } else { $query = "SELECT alias.address,alias.goto,alias.modified,alias.domain FROM alias LEFT JOIN mailbox ON alias.address=mailbox.username WHERE alias.address LIKE '%$fSearch%' AND mailbox.maildir IS NULL ORDER BY alias.address"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT address,goto,extract(epoch from modified) as modified,domain FROM alias WHERE address LIKE '%$fSearch%'AND NOT EXISTS(SELECT 1 FROM mailbox WHERE username=alias.address) ORDER BY address"; + } } $result = db_query ("$query"); @@ -93,19 +127,37 @@ { if (check_owner ($SESSID_USERNAME, $row['domain'])) { - $tAlias[] = $row; + if ('pgsql'==$CONF['database_type']) + { + $row['modified']=gmstrftime('%c %Z',$row['modified']); + } + $tAlias[] = $row; } } } - $result = db_query ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + $query = ("SELECT * FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"); + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT *,extract(epoch from created) as uts_created,extract(epoch from modified) as uts_modified FROM mailbox WHERE username LIKE '%$fSearch%' ORDER BY username"; + } + + $result = db_query ("$query"); if ($result['rows'] > 0) { while ($row = db_array ($result['result'])) { if (check_owner ($SESSID_USERNAME, $row['domain'])) { - $tMailbox[] = $row; + if ('pgsql'==$CONF['database_type']) + { + $row['created']=gmstrftime('%c %Z',$row['uts_created']); + $row['modified']=gmstrftime('%c %Z',$row['uts_modified']); + $row['active']=('t'==$row['active']) ? 1 : 0; + unset($row['uts_created']); + unset($row['uts_modified']); + } + $tMailbox[] = $row; } } } diff -urN postfixadmin-2.1.0/templates/admin_list-virtual.tpl postfixadmin-2.1.0-arvin-martin/templates/admin_list-virtual.tpl --- postfixadmin-2.1.0/templates/admin_list-virtual.tpl 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/templates/admin_list-virtual.tpl 2007-06-25 22:00:04.000000000 +0200 @@ -104,4 +104,5 @@ } print "\n"; } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/templates/admin_menu.tpl postfixadmin-2.1.0-arvin-martin/templates/admin_menu.tpl --- postfixadmin-2.1.0/templates/admin_menu.tpl 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/templates/admin_menu.tpl 2007-06-25 22:00:04.000000000 +0200 @@ -4,7 +4,9 @@
  • +
  • +
  • @@ -21,4 +23,5 @@ include ("../motd-admin.txt"); print ""; } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/templates/create-mailbox.tpl postfixadmin-2.1.0-arvin-martin/templates/create-mailbox.tpl --- postfixadmin-2.1.0/templates/create-mailbox.tpl 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/templates/create-mailbox.tpl 2007-06-25 22:00:04.000000000 +0200 @@ -55,7 +55,7 @@ - + />   diff -urN postfixadmin-2.1.0/templates/overview.tpl postfixadmin-2.1.0-arvin-martin/templates/overview.tpl --- postfixadmin-2.1.0/templates/overview.tpl 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/templates/overview.tpl 2007-06-25 22:00:04.000000000 +0200 @@ -136,4 +136,5 @@ } print "\n"; } +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/users/login.php postfixadmin-2.1.0-arvin-martin/users/login.php --- postfixadmin-2.1.0/users/login.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/users/login.php 2007-06-25 22:00:04.000000000 +0200 @@ -36,13 +36,23 @@ $fUsername = escape_string ($_POST['fUsername']); $fPassword = escape_string ($_POST['fPassword']); - $result = db_query ("SELECT password FROM mailbox WHERE username='$fUsername' AND active='1'"); + $query = "SELECT password FROM mailbox WHERE username='$fUsername' AND active='1'"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT password FROM mailbox WHERE username='$fUsername' AND active=true"; + } + $result = db_query ($query); if ($result['rows'] == 1) { $row = db_array ($result['result']); $password = pacrypt ($fPassword, $row['password']); - $result = db_query ("SELECT * FROM mailbox WHERE username='$fUsername' AND password='$password' AND active='1'"); + $query = "SELECT * FROM mailbox WHERE username='$fUsername' AND password='$password' AND active='1'"; + if ('pgsql'==$CONF['database_type']) + { + $query = "SELECT * FROM mailbox WHERE username='$fUsername' AND password='$password' AND active=true"; + } + $result = db_query ($query); if ($result['rows'] != 1) { $error = 1; @@ -69,5 +79,6 @@ include ("../templates/header.tpl"); include ("../templates/users_login.tpl"); include ("../templates/footer.tpl"); -} +} +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/viewlog.php postfixadmin-2.1.0-arvin-martin/viewlog.php --- postfixadmin-2.1.0/viewlog.php 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/viewlog.php 2007-06-25 22:00:04.000000000 +0200 @@ -29,56 +29,43 @@ if ($_SERVER['REQUEST_METHOD'] == "GET") { if ((is_array ($list_domains) and sizeof ($list_domains) > 0)) $fDomain = $list_domains[0]; +} elseif ($_SERVER['REQUEST_METHOD'] == "POST") { + $fDomain = escape_string ($_POST['fDomain']); +} else { + die('Unknown request method'); +} - if (!check_owner ($SESSID_USERNAME, $fDomain)) - { - $error = 1; - $tMessage = $PALANG['pViewlog_result_error']; - } - - if ($error != 1) - { - $result = db_query ("SELECT * FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"); - if ($result['rows'] > 0) - { - while ($row = db_array ($result['result'])) - { - $tLog[] = $row; - } - } - } - - include ("./templates/header.tpl"); - include ("./templates/menu.tpl"); - include ("./templates/viewlog.tpl"); - include ("./templates/footer.tpl"); +if (!check_owner ($SESSID_USERNAME, $fDomain)) +{ + $error = 1; + $tMessage = $PALANG['pViewlog_result_error']; } -if ($_SERVER['REQUEST_METHOD'] == "POST") +if ($error != 1) { - $fDomain = escape_string ($_POST['fDomain']); - - if (!check_owner ($SESSID_USERNAME, $fDomain)) + $query = "SELECT timestamp,username,domain,action,substring(data from 1 for 36) as data FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"; + if ('pgsql'==$CONF['database_type']) { - $error = 1; - $tMessage = $PALANG['pViewlog_error']; + $query = "SELECT extract(epoch from timestamp) as timestamp,username,domain,action,substring(data from 1 for 36) as data FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"; } - - if ($error != 1) + $result=db_query($query); + if ($result['rows'] > 0) { - $result = db_query ("SELECT * FROM log WHERE domain='$fDomain' ORDER BY timestamp DESC LIMIT 10"); - if ($result['rows'] > 0) + while ($row = db_array ($result['result'])) { - while ($row = db_array ($result['result'])) + if ('pgsql'==$CONF['database_type']) { - $tLog[] = $row; + $row['timestamp']=gmstrftime('%c %Z',$row['timestamp']); } + $tLog[] = $row; } } - - include ("./templates/header.tpl"); - include ("./templates/menu.tpl"); - include ("./templates/viewlog.tpl"); - include ("./templates/footer.tpl"); } + +include ("./templates/header.tpl"); +include ("./templates/menu.tpl"); +include ("./templates/viewlog.tpl"); +include ("./templates/footer.tpl"); + +/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */ ?> diff -urN postfixadmin-2.1.0/VIRTUAL_VACATION/mail-filter postfixadmin-2.1.0-arvin-martin/VIRTUAL_VACATION/mail-filter --- postfixadmin-2.1.0/VIRTUAL_VACATION/mail-filter 2005-01-07 00:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/VIRTUAL_VACATION/mail-filter 2007-06-25 22:00:04.000000000 +0200 @@ -1,5 +1,5 @@ #!/bin/sh -FILTER_DIR=/home/vacation +FILTER_DIR=/var/spool/vacation SENDMAIL="/usr/sbin/sendmail -i" EX_TEMPFAIL=75 EX_UNAVAILABLE=69 @@ -10,7 +10,7 @@ cat > in.$$ || { echo Cannot save mail to file; exit $EX_TEMPFAIL; } -/home/vacation/vacation.pl < in.$$ || { echo Message content rejected; exit $EX_UNAVAILABLE; } +/usr/local/bin/vacation.pl < in.$$ || { echo Message content rejected; exit $EX_UNAVAILABLE; } $SENDMAIL "$@" < in.$$ diff -urN postfixadmin-2.1.0/VIRTUAL_VACATION/vacation-pgsql.pl postfixadmin-2.1.0-arvin-martin/VIRTUAL_VACATION/vacation-pgsql.pl --- postfixadmin-2.1.0/VIRTUAL_VACATION/vacation-pgsql.pl 1970-01-01 01:00:00.000000000 +0100 +++ postfixadmin-2.1.0-arvin-martin/VIRTUAL_VACATION/vacation-pgsql.pl 2007-06-25 22:00:04.000000000 +0200 @@ -0,0 +1,326 @@ +#!/usr/bin/perl -w +# +# Virtual Vacation 3.1 +# by Mischa Peters +# Copyright (c) 2002 - 2005 High5! +# License Info: http://www.postfixadmin.com/?file=LICENSE.TXT +# +# Additions: +# 2004/07/13 David Osborn +# strict, processes domain level aliases, more +# subroutines, send reply from original to address +# +# 2004/11/09 David Osborn +# Added syslog support +# Slightly better logging which includes messageid +# Avoid infinite loops with domain aliases +# +# 2005-01-19 Troels Arvin +# PostgreSQL-version. +# Normalized DB schema from one vacation table ("vacation") +# to two ("vacation", "vacation_notification"). Uses +# referential integrity CASCADE action to simplify cleanup +# when a user is no longer on vacation. +# Inserting variables into queries stricly by prepare() +# to try to avoid SQL injection. +# International characters are now handled well. +# +# 2005-01-21 Troels Arvin +# Uses the Email::Valid package to avoid sending notices +# to obviously invalid addresses. +# +# +# Requirements: +# You need to have the DBD::Pg perl-module installed. +# On Fedora Core Linux, e.g., this entails installing the +# libdbi-dbd-pgsql and perl-DBD-Pg-1.22-1 packages. +# +# Note: When you use this module, you may start seeing error messages +# like "Cannot insert a duplicate key into unique index +# vacation_notification_pkey" in your system logs. This is expected +# behavior, and not an indication of trouble (see the "already_notified" +# subroutine for an explanation). +# +# You must also have the Email::Valid and MIME-tools perl-packages +# installed. They are available in some package collections, under the +# names 'perl-Email-Valid' and 'perl-MIME-tools', respectively. +# One such package collection (for Linux) is: +# http://dag.wieers.com/home-made/apt/packages.php +# +use DBI; +use MIME::Words qw(:all); +use Email::Valid; +use strict; +my $db_host; # leave alone + +# ========== begin configuration ========== + +# IMPORTANT: If you put passwords into this script, then remember +# to restrict access to the script, so that only the vacation user +# kan read it. + +my $db_type = 'Pg'; +# $db_host = 'localhost'; # Uncomment (and adjust, if needed) your DB + # host-name here, if you want to connect via + # a TCP socket +my $db_user = 'vacation'; # What DB-user to connect as +my $db_pass = ''; # What password (if any) to connect with +my $db_name = 'postfix'; # Name of database to use + +my $sendmail = "/usr/sbin/sendmail"; + +my $charset = 'ISO-8859-1'; # Character set of vacation messages. + +#my $logfile = "/tmp/vacation-log"; +my $logfile=''; +my $syslog = 1; # 1 if log entries should be sent to syslog + +#my $debugfile = "/tmp/vacation-debug"; # Specify a file name here for example: /tmp/vacation.debug +my $debugfile=''; + +# =========== end configuration =========== + + +my $dbh; +if (defined($db_host)) { + $dbh = DBI->connect("DBI:$db_type:dbname=$db_name;host=$db_host","$db_user", "$db_pass", { RaiseError => 1 }); +} else { + $dbh = DBI->connect("DBI:$db_type:dbname=$db_name","$db_user", "$db_pass", { RaiseError => 1 }); +} + +if (!$dbh) { + panic("Could not connect to database"); + exit(0); +} + +# used to detect infinite address lookup loops +my $loopcount=0; + +sub do_debug { + my ($in1, $in2, $in3, $in4, $in5, $in6) = @_; + if ( $debugfile ) { + my $date; + open (DEBUG, ">> $debugfile") or die ("Unable to open debug file"); + chop ($date = `date "+%Y/%m/%d %H:%M:%S"`); + print DEBUG "====== $date ======\n"; + printf DEBUG "%s | %s | %s | %s | %s | %s\n", $in1, $in2, $in3, $in4, $in5, $in6; + close (DEBUG); + } +} + +sub already_notified { + my ($to, $from) = @_; + my $query = qq{INSERT into vacation_notification (on_vacation,notified) values (?,?)}; + my $stm = $dbh->prepare($query); + if (!$stm) { + do_log('',$to,$from,'','',"Could not prepare query $query"); + return 1; + } + $stm->{'PrintError'} = 0; + $stm->{'RaiseError'} = 0; + if (!$stm->execute($to,$from)) { + my $e=$dbh->errstr; + + # Violation of a primay key constraint may happen here, and that's + # fine. All other error conditions are not fine, however. + if (!$e =~ /_pkey/) { + do_log('',$to,$from,'','',"Unexpected error: '$e' from query '$query'"); + } + return 1; + } + return 0; +} + +sub do_log { + my ($messageid, $to, $from, $subject, $logmessage) = @_; + my $date; + if ( $syslog ) { + open (SYSLOG, "|/usr/bin/logger -p mail.info -t Vacation") or die ("Unable to open logger"); + if ($logmessage) { + printf SYSLOG "Orig-To: %s From: %s MessageID: %s Subject: %s. Log message: $%s", $to, $from, $messageid, $subject, $logmessage; + } else { + printf SYSLOG "Orig-To: %s From: %s MessageID: %s Subject: %s", $to, $from, $messageid, $subject; + } + close (SYSLOG); + } + if ( $logfile ) { + open (LOG, ">> $logfile") or die ("Unable to open log file"); + chop ($date = `date "+%Y/%m/%d %H:%M:%S"`); + if ($logmessage) { + print LOG "$date: To: $to From: $from Subject: $subject MessageID: $messageid. Log message: $logmessage\n"; + } else { + print LOG "$date: To: $to From: $from Subject: $subject MessageID: $messageid\n"; + } + close (LOG); + } +} + +sub do_mail { + my ($from, $to, $plainsubject, $body) = @_; + my $subject = encode_mimewords($plainsubject); + + open (MAIL, "| $sendmail -t -f $from") or die ("Unable to open sendmail"); + print MAIL "From: $from\n"; + print MAIL "To: $to\n"; + print MAIL "Subject: $subject\n"; + print MAIL "MIME-Version: 1.0\n"; + print MAIL "Content-Type: text/plain; charset=\"$charset\"\n"; + print MAIL "Precedence: junk\n"; + print MAIL "X-Loop: Postfix Admin Virtual Vacation\n\n"; + print MAIL "$body"; + close (MAIL); +} + +sub panic { + my ($arg) = @_; + do_log('','','','','',"$arg"); + exit(0); +} + +sub panic_prepare { + my ($arg) = @_; + do_log('','','','','',"Could not prepare '$arg'"); + exit(0); +} + +sub panic_execute { + my ($arg,$param) = @_; + do_log('','','','','',"Could not execute '$arg' with parameters $param"); + exit(0); +} + +sub find_real_address { + my ($email) = @_; + if (++$loopcount > 20) { + do_log ("find_real_address loop!", "currently: $email", "ERROR", "ERROR"); + panic("possible infinite loop in find_real_address for <$email>. Check for alias loop\n"); + } + my $realemail; + my $query = qq{SELECT email FROM vacation WHERE email=? and active=true}; + my $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($email) or panic_execute($query,"email='$email'"); + my $rv = $stm->rows; + + # Recipient has vacation + if ($rv == 1) { + $realemail = $email; + } else { + $query = qq{SELECT goto FROM alias WHERE address=?}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($email) or panic_execute($query,"address='$email'"); + $rv = $stm->rows; + + # Recipient is an alias, check if mailbox has vacation + if ($rv == 1) { + my @row = $stm->fetchrow_array; + my $alias = $row[0]; + $query = qq{SELECT email FROM vacation WHERE email=? and active=true}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($alias) or panic_prepare($query,"email='$alias'"); + $rv = $stm->rows; + + # Alias has vacation + if ($rv == 1) { + $realemail = $alias; + } + + # We still have to look for domain level aliases... + } else { + my ($user, $domain) = split(/@/, $email); + $query = qq{SELECT goto FROM alias WHERE address=?}; + $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute("\@$domain") or panic_execute($query,"address='\@$domain'"); + $rv = $stm->rows; + + # The receipient has a domain level alias + if ($rv == 1) { + my @row = $stm->fetchrow_array; + my $wildcard_dest = $row[0]; + my ($wilduser, $wilddomain) = split(/@/, $wildcard_dest); + + # Check domain alias + if ($wilduser) { + ($rv, $realemail) = find_real_address ($wildcard_dest); + } else { + my $new_email = $user . '@' . $wilddomain; + ($rv, $realemail) = find_real_address ($new_email); + } + } + } + } + return ($rv, $realemail); +} + +sub send_vacation_email { + my ($email, $orig_subject, $orig_from, $orig_to, $orig_messageid) = @_; + my $query = qq{SELECT subject,body FROM vacation WHERE email=?}; + my $stm = $dbh->prepare($query) or panic_prepare($query); + $stm->execute($email) or panic_execute($query,"email='$email'"); + my $rv = $stm->rows; + if ($rv == 1) { + my @row = $stm->fetchrow_array; + if (already_notified($email, $orig_from)) { return; } + do_debug ("[SEND RESPONSE] for $orig_messageid:\n", "FROM: $email (orig_to: $orig_to)\n", "TO: $orig_from\n", "SUBJECT: $orig_subject\n", "VACATION SUBJECT: $row[0]\n", "VACATION BODY: $row[1]\n"); + do_mail ($orig_to, $orig_from, $row[0], $row[1]); + do_log ($orig_messageid, $orig_to, $orig_from, $orig_subject); + } + +} + +########################### main ################################# + +my ($from, $to, $cc, $subject, $messageid); + +$subject=''; + +# Take headers apart +while () { + last if (/^$/); + if (/^from:\s+(.*)\n$/i) { $from = $1; } + if (/^to:\s+(.*)\n$/i) { $to = $1; } + if (/^cc:\s+(.*)\n$/i) { $cc = $1; } + if (/^subject:\s+(.*)\n$/i) { $subject = $1; } + if (/^message-id:\s+(.*)\n$/i) { $messageid = $1; } + if (/^precedence:\s+(bulk|list|junk)/i) { exit (0); } + if (/^x-loop:\s+postfix\ admin\ virtual\ vacation/i) { exit (0); } +} + +# If either From: or To: are not set, exit +if (!$from || !$to || !$messageid) { exit (0); } + +$from = lc ($from); + +if (!Email::Valid->address($from,-mxcheck => 1)) { exit(0); } + +# Check if it's an obvious sender, exit +if ($from =~ /([\w\-.%]+\@[\w.-]+)/) { $from = $1; } +if ($from eq "" || $from =~ /^owner-|-(request|owner)\@|^(mailer-daemon|postmaster)\@/i) { exit (0); } + +# Strip To: and Cc: and push them in array +my @strip_cc_array; +my @strip_to_array = split(/, */, lc ($to) ); +if (defined $cc) { @strip_cc_array = split(/, */, lc ($cc) ); } +push (@strip_to_array, @strip_cc_array); + +my @search_array; + +# Strip email address from headers +for (@strip_to_array) { + if ($_ =~ /([\w\-.%]+\@[\w.-]+)/) { + push (@search_array, $1); + do_debug ("[STRIP RECIPIENTS]: ", $messageid, $1, "-", "-", "-"); + } +} + +# Search for email address which has vacation +for (@search_array) { + my ($rv, $email) = find_real_address ($_); + if ($rv == 1) { + do_debug ("[FOUND VACATION]: ", $messageid, $from, $to, $email, $subject); + send_vacation_email( $email, $subject, $from, $to, $messageid); + } +} + +0; + +#/* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */