2007-03-24 08:27:00 +01:00
< ? php
2007-09-30 17:53:54 +02:00
/**
* Postfix Admin
*
* LICENSE
* This source file is subject to the GPL license that is bundled with
* this package in the file LICENSE . TXT .
*
* Further details on the project are available at :
* http :// www . postfixadmin . com or http :// postfixadmin . sf . net
*
* @ version $Id $
* @ license GNU GPL v2 or later .
*
* File : list - virtual . php
* List virtual users for a domain .
*
2007-12-02 14:59:33 +01:00
* Template File : list - virtual . php
2007-09-30 17:53:54 +02:00
*
* Template Variables :
*
* tMessage
* tAlias
* tMailbox
*
* Form POST \ GET Variables :
*
* fDomain
* fDisplay
*/
2007-10-31 19:24:40 +01:00
require_once ( 'common.php' );
2007-09-22 12:54:00 +02:00
2008-01-03 22:50:39 +01:00
2007-11-03 23:24:34 +01:00
authentication_require_role ( 'admin' );
2007-03-24 08:27:00 +01:00
2009-07-19 14:25:47 +02:00
$fDomain = false ;
2007-11-25 01:35:13 +01:00
$SESSID_USERNAME = authentication_get_username ();
2007-11-03 23:24:34 +01:00
if ( authentication_has_role ( 'global-admin' )) {
2009-04-18 21:38:20 +02:00
$list_domains = list_domains ();
$is_superadmin = 1 ;
2007-11-03 23:24:34 +01:00
} else {
2009-04-18 21:38:20 +02:00
$list_domains = list_domains_for_admin ( authentication_get_username ());
$is_superadmin = 0 ;
2007-11-03 23:24:34 +01:00
}
2007-06-20 00:38:05 +02:00
2007-03-24 08:27:00 +01:00
$tAlias = array ();
$tMailbox = array ();
2007-08-13 23:26:54 +02:00
$fDisplay = 0 ;
$page_size = $CONF [ 'page_size' ];
2007-03-24 08:27:00 +01:00
if ( $_SERVER [ 'REQUEST_METHOD' ] == " GET " )
{
2009-04-18 21:38:20 +02:00
if ( isset ( $_GET [ 'domain' ])) $fDomain = escape_string ( $_GET [ 'domain' ]);
if ( isset ( $_GET [ 'limit' ])) $fDisplay = intval ( $_GET [ 'limit' ]);
2010-12-16 00:41:40 +01:00
$search = escape_string ( safeget ( 'search' ));
2007-08-13 23:26:54 +02:00
}
else
{
2009-04-18 21:38:20 +02:00
if ( isset ( $_POST [ 'fDomain' ])) $fDomain = escape_string ( $_POST [ 'fDomain' ]);
if ( isset ( $_POST [ 'limit' ])) $fDisplay = intval ( $_POST [ 'limit' ]);
2010-12-16 00:41:40 +01:00
$search = escape_string ( safepost ( 'search' ));
2007-08-13 23:26:54 +02:00
}
2007-11-03 23:24:34 +01:00
if ( count ( $list_domains ) == 0 ) {
2009-04-18 21:38:20 +02:00
# die("no domains");
merged most bugfix changes between 2.3 release and SVN r791 to
2.3 branch
- merged: SVN r745, r746, r747, r748, r749, r750, r752, r754, r756,
r767, r770, r771, r772, r773, r774, r777, r778, r779, r789, r790
- r763 partly merged (except smarty part)
- r787 - only part a) merged
- see CHANGELOG.txt changes ;-) or SVN log for details
ToDo: display alias targets for mailboxes (r751 and r787 part b)
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/branches/postfixadmin-2.3@792 a1433add-5e2c-0410-b055-b7f2511e0802
2009-12-28 22:24:38 +01:00
flash_error ( $PALANG [ 'invalid_parameter' ] );
2009-04-18 21:38:20 +02:00
header ( " Location: list-domain.php " ); # no domains (for this admin at least) - redirect to domain list
merged most bugfix changes between 2.3 release and SVN r791 to
2.3 branch
- merged: SVN r745, r746, r747, r748, r749, r750, r752, r754, r756,
r767, r770, r771, r772, r773, r774, r777, r778, r779, r789, r790
- r763 partly merged (except smarty part)
- r787 - only part a) merged
- see CHANGELOG.txt changes ;-) or SVN log for details
ToDo: display alias targets for mailboxes (r751 and r787 part b)
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/branches/postfixadmin-2.3@792 a1433add-5e2c-0410-b055-b7f2511e0802
2009-12-28 22:24:38 +01:00
exit ;
}
if (( is_array ( $list_domains ) and sizeof ( $list_domains ) > 0 )) {
if ( empty ( $fDomain )) {
$fDomain = $list_domains [ 0 ];
}
2007-11-03 23:24:34 +01:00
}
2007-03-24 08:27:00 +01:00
merged most bugfix changes between 2.3 release and SVN r791 to
2.3 branch
- merged: SVN r745, r746, r747, r748, r749, r750, r752, r754, r756,
r767, r770, r771, r772, r773, r774, r777, r778, r779, r789, r790
- r763 partly merged (except smarty part)
- r787 - only part a) merged
- see CHANGELOG.txt changes ;-) or SVN log for details
ToDo: display alias targets for mailboxes (r751 and r787 part b)
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/branches/postfixadmin-2.3@792 a1433add-5e2c-0410-b055-b7f2511e0802
2009-12-28 22:24:38 +01:00
if ( ! in_array ( $fDomain , $list_domains )) {
flash_error ( $PALANG [ 'invalid_parameter' ] );
header ( " Location: list-domain.php " ); # invalid domain, or not owned by this admin
exit ;
}
2007-03-24 08:27:00 +01:00
merged most bugfix changes between 2.3 release and SVN r791 to
2.3 branch
- merged: SVN r745, r746, r747, r748, r749, r750, r752, r754, r756,
r767, r770, r771, r772, r773, r774, r777, r778, r779, r789, r790
- r763 partly merged (except smarty part)
- r787 - only part a) merged
- see CHANGELOG.txt changes ;-) or SVN log for details
ToDo: display alias targets for mailboxes (r751 and r787 part b)
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/branches/postfixadmin-2.3@792 a1433add-5e2c-0410-b055-b7f2511e0802
2009-12-28 22:24:38 +01:00
if ( ! check_owner ( authentication_get_username (), $fDomain )) {
flash_error ( $PALANG [ 'invalid_parameter' ] . " If you see this message, please open a bugreport " ); # this check is most probably obsoleted by the in_array() check above
2009-04-18 21:38:20 +02:00
header ( " Location: list-domain.php " ); # domain not owned by this admin
exit ( 0 );
2007-11-03 23:24:34 +01:00
}
2007-08-13 23:29:33 +02:00
merged most bugfix changes between 2.3 release and SVN r791 to
2.3 branch
- merged: SVN r745, r746, r747, r748, r749, r750, r752, r754, r756,
r767, r770, r771, r772, r773, r774, r777, r778, r779, r789, r790
- r763 partly merged (except smarty part)
- r787 - only part a) merged
- see CHANGELOG.txt changes ;-) or SVN log for details
ToDo: display alias targets for mailboxes (r751 and r787 part b)
git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/branches/postfixadmin-2.3@792 a1433add-5e2c-0410-b055-b7f2511e0802
2009-12-28 22:24:38 +01:00
// store fDomain in $_SESSION so after adding/editing aliases/mailboxes we can
// take the user back to the appropriate domain listing. (see templates/menu.php)
if ( $fDomain ) {
$_SESSION [ 'list_virtual_sticky_domain' ] = $fDomain ;
}
2010-12-16 00:41:40 +01:00
#
# alias domain
#
# TODO: add search support for alias domains
2008-07-27 21:06:55 +02:00
if ( boolconf ( 'alias_domain' )) {
2009-04-18 21:38:20 +02:00
# Alias-Domains
# first try to get a list of other domains pointing
# to this currently chosen one (aka. alias domains)
$query = " SELECT $table_alias_domain .alias_domain, $table_alias_domain .target_domain, $table_alias_domain .modified, $table_alias_domain .active FROM $table_alias_domain WHERE target_domain=' $fDomain ' ORDER BY $table_alias_domain .alias_domain LIMIT $fDisplay , $page_size " ;
if ( 'pgsql' == $CONF [ 'database_type' ])
{
$query = " SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE target_domain=' $fDomain ' ORDER BY alias_domain LIMIT $page_size OFFSET $fDisplay " ;
}
$result = db_query ( $query );
$tAliasDomains = array ();
if ( $result [ 'rows' ] > 0 )
{
while ( $row = db_array ( $result [ 'result' ]))
{
if ( 'pgsql' == $CONF [ 'database_type' ])
{
$row [ 'modified' ] = gmstrftime ( '%c %Z' , $row [ 'modified' ]);
$row [ 'active' ] = ( 't' == $row [ 'active' ]) ? 1 : 0 ;
}
$tAliasDomains [] = $row ;
}
}
# now let's see if the current domain itself is an alias for another domain
$query = " SELECT $table_alias_domain .alias_domain, $table_alias_domain .target_domain, $table_alias_domain .modified, $table_alias_domain .active FROM $table_alias_domain WHERE alias_domain=' $fDomain ' " ;
if ( 'pgsql' == $CONF [ 'database_type' ])
{
$query = " SELECT alias_domain,target_domain,extract(epoch from modified) as modified,active FROM $table_alias_domain WHERE alias_domain=' $fDomain ' " ;
}
$result = db_query ( $query );
$tTargetDomain = " " ;
if ( $result [ 'rows' ] > 0 )
{
if ( $row = db_array ( $result [ 'result' ]))
{
if ( 'pgsql' == $CONF [ 'database_type' ])
{
$row [ 'modified' ] = gmstrftime ( '%c %Z' , $row [ 'modified' ]);
$row [ 'active' ] = ( 't' == $row [ 'active' ]) ? 1 : 0 ;
}
$tTargetDomain = $row ;
}
}
2008-05-21 23:05:48 +02:00
}
2010-12-16 00:41:40 +01:00
#
# aliases
#
if ( $search == " " ) {
$sql_domain = " $table_alias .domain=' $fDomain ' " ;
$sql_where = " " ;
} else {
$sql_domain = db_in_clause ( " $table_alias .domain " , $list_domains );
$sql_where = " AND ( address LIKE '% $search %' OR goto LIKE '% $search %' ) " ;
}
2009-03-08 22:16:41 +01:00
$query = " SELECT $table_alias .address,
2009-04-18 21:38:20 +02:00
$table_alias . goto ,
$table_alias . modified ,
$table_alias . active
FROM $table_alias LEFT JOIN $table_mailbox ON $table_alias . address = $table_mailbox . username
2010-12-16 00:41:40 +01:00
WHERE ( $sql_domain AND $table_mailbox . maildir IS NULL $sql_where )
2009-04-18 21:38:20 +02:00
ORDER BY $table_alias . address LIMIT $fDisplay , $page_size " ;
2007-08-13 23:29:33 +02:00
if ( 'pgsql' == $CONF [ 'database_type' ])
{
2010-12-16 00:41:40 +01:00
# TODO: is the different query for pgsql really needed? The mailbox query below also works with both...
2009-04-18 21:38:20 +02:00
$query = " SELECT address,
goto ,
2010-12-16 00:41:40 +01:00
modified ,
2009-04-18 21:38:20 +02:00
active
2009-05-08 01:23:21 +02:00
FROM $table_alias
2010-12-16 00:41:40 +01:00
WHERE $sql_domain AND NOT EXISTS ( SELECT 1 FROM $table_mailbox WHERE username = $table_alias . address $sql_where )
2009-04-18 21:38:20 +02:00
ORDER BY address LIMIT $page_size OFFSET $fDisplay " ;
2007-08-13 23:29:33 +02:00
}
2010-12-16 00:41:40 +01:00
2007-08-13 23:29:33 +02:00
$result = db_query ( $query );
if ( $result [ 'rows' ] > 0 )
{
2009-04-18 21:38:20 +02:00
while ( $row = db_array ( $result [ 'result' ]))
{
if ( 'pgsql' == $CONF [ 'database_type' ])
2009-05-08 01:23:21 +02:00
{
2009-04-18 21:38:20 +02:00
//. at least in my database, $row['modified'] already looks like : 2009-04-11 21:38:10.75586+01,
// while gmstrftime expects an integer value. strtotime seems happy though.
//$row['modified']=gmstrftime('%c %Z',$row['modified']);
$row [ 'modified' ] = date ( 'Y-m-d H:i' , strtotime ( $row [ 'modified' ]));
$row [ 'active' ] = ( 't' == $row [ 'active' ]) ? 1 : 0 ;
}
$tAlias [] = $row ;
}
2007-08-13 23:29:33 +02:00
}
2007-03-24 08:27:00 +01:00
2010-12-16 00:41:40 +01:00
#
# mailboxes
#
$display_mailbox_aliases = boolconf ( 'alias_control_admin' );
# build the sql query
$sql_select = " SELECT $table_mailbox .* " ;
$sql_from = " FROM $table_mailbox " ;
$sql_join = " " ;
$sql_where = " WHERE " ;
$sql_order = " ORDER BY $table_mailbox .username " ;
$sql_limit = " LIMIT $page_size OFFSET $fDisplay " ;
if ( $search == " " ) {
$sql_where .= " $table_mailbox .domain=' $fDomain ' " ;
} else {
$sql_where .= db_in_clause ( " $table_mailbox .domain " , $list_domains ) . " " ;
$sql_where .= " AND ( $table_mailbox .username LIKE '% $search %' OR $table_mailbox .name LIKE '% $search %' " ;
if ( $display_mailbox_aliases ) {
$sql_where .= " OR $table_alias .goto LIKE '% $search %' " ;
}
$sql_where .= " ) " ; # $search is already escaped
2007-08-13 23:29:33 +02:00
}
2010-12-16 00:41:40 +01:00
if ( $display_mailbox_aliases ) {
$sql_select .= " , $table_alias .goto " ;
$sql_join .= " LEFT JOIN $table_alias ON $table_mailbox .username= $table_alias .address " ;
}
if ( boolconf ( 'vacation_control_admin' )) {
$sql_select .= " , $table_vacation .active AS v_active " ;
$sql_join .= " LEFT JOIN $table_vacation ON $table_mailbox .username= $table_vacation .email " ;
}
if ( boolconf ( 'used_quotas' ) && boolconf ( 'new_quota_table' )) {
$sql_select .= " , $table_quota2 .bytes as current " ;
$sql_join .= " LEFT JOIN $table_quota2 ON $table_mailbox .username= $table_quota2 .username " ;
}
if ( boolconf ( 'used_quotas' ) && ( ! boolconf ( 'new_quota_table' ) ) ) {
$sql_select .= " , $table_quota .current " ;
$sql_join .= " LEFT JOIN $table_quota ON $table_mailbox .username= $table_quota .username " ;
$sql_where .= " AND ( $table_quota .path='quota/storage' OR $table_quota .path IS NULL ) " ;
2007-08-13 23:29:33 +02:00
}
2010-12-16 00:41:40 +01:00
$query = " $sql_select\n $sql_from\n $sql_join\n $sql_where\n $sql_order\n $sql_limit " ;
2007-08-13 23:29:33 +02:00
$result = db_query ( $query );
2010-12-16 00:41:40 +01:00
2007-08-13 23:29:33 +02:00
if ( $result [ 'rows' ] > 0 )
{
2011-10-08 00:58:38 +02:00
$delimiter = preg_quote ( $CONF [ 'recipient_delimiter' ], " / " );
$goto_single_rec_del = " " ;
2009-04-18 21:38:20 +02:00
while ( $row = db_array ( $result [ 'result' ]))
{
2010-12-16 00:41:40 +01:00
if ( $display_mailbox_aliases ) {
$goto_split = explode ( " , " , $row [ 'goto' ]);
$row [ 'goto_mailbox' ] = 0 ;
$row [ 'goto_other' ] = array ();
foreach ( $goto_split as $goto_single ) {
2011-10-08 00:58:38 +02:00
if ( ! empty ( $CONF [ 'recipient_delimiter' ])) {
$goto_single_rec_del = preg_replace ( '/' . $delimiter . '[^' . $delimiter . '@]*@/' , " @ " , $goto_single );
}
if ( $goto_single == $row [ 'username' ] || $goto_single_rec_del == $row [ 'username' ]) { # delivers to mailbox
2010-12-16 00:41:40 +01:00
$row [ 'goto_mailbox' ] = 1 ;
} elseif ( boolconf ( 'vacation' ) && strstr ( $goto_single , '@' . $CONF [ 'vacation_domain' ]) ) { # vacation alias - TODO: check for full vacation alias
# skip the vacation alias, vacation status is detected otherwise
} else { # forwarding to other alias
$row [ 'goto_other' ][] = $goto_single ;
}
}
}
2009-04-18 21:38:20 +02:00
if ( 'pgsql' == $CONF [ 'database_type' ])
{
// XXX
$row [ 'modified' ] = date ( 'Y-m-d H:i' , strtotime ( $row [ 'modified' ]));
$row [ 'created' ] = date ( 'Y-m-d H:i' , strtotime ( $row [ 'created' ]));
$row [ 'active' ] = ( 't' == $row [ 'active' ]) ? 1 : 0 ;
if ( $row [ 'v_active' ] == NULL ) {
$row [ 'v_active' ] = 'f' ;
}
$row [ 'v_active' ] = ( 't' == $row [ 'v_active' ]) ? 1 : 0 ;
}
$tMailbox [] = $row ;
}
2007-08-13 23:29:33 +02:00
}
2007-10-02 13:57:28 +02:00
$tCanAddAlias = false ;
$tCanAddMailbox = false ;
2010-12-16 00:41:40 +01:00
# TODO: needs reworking for $search...
2007-10-02 13:57:28 +02:00
$limit = get_domain_properties ( $fDomain );
if ( isset ( $limit )) {
2009-04-18 21:38:20 +02:00
if ( $fDisplay >= $page_size ) {
$tDisplay_back_show = 1 ;
$tDisplay_back = $fDisplay - $page_size ;
}
if (( $limit [ 'alias_count' ] > $page_size ) or ( $limit [ 'mailbox_count' ] > $page_size )) {
$tDisplay_up_show = 1 ;
2009-05-08 01:23:21 +02:00
}
2009-04-18 21:38:20 +02:00
if ((( $fDisplay + $page_size ) < $limit [ 'alias_count' ]) or
(( $fDisplay + $page_size ) < $limit [ 'mailbox_count' ]))
{
$tDisplay_next_show = 1 ;
$tDisplay_next = $fDisplay + $page_size ;
}
if ( $limit [ 'aliases' ] == 0 ) {
$tCanAddAlias = true ;
}
elseif ( $limit [ 'alias_count' ] < $limit [ 'aliases' ]) {
$tCanAddAlias = true ;
}
if ( $limit [ 'mailboxes' ] == 0 ) {
$tCanAddMailbox = true ;
}
elseif ( $limit [ 'mailbox_count' ] < $limit [ 'mailboxes' ]) {
$tCanAddMailbox = true ;
}
2007-08-13 23:29:33 +02:00
}
2007-03-24 08:27:00 +01:00
2007-12-02 17:54:15 +01:00
// this is why we need a proper template layer.
$fDomain = htmlentities ( $fDomain , ENT_QUOTES );
2007-12-02 14:59:33 +01:00
include ( " templates/header.php " );
include ( " templates/menu.php " );
include ( " templates/list-virtual.php " );
include ( " templates/footer.php " );
2007-03-24 08:27:00 +01:00
2009-05-08 01:23:21 +02:00
/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
2007-03-24 08:27:00 +01:00
?>