diff --git a/index.php b/index.php --- a/index.php +++ b/index.php @@ -192,8 +192,18 @@ if ($_debug) { $vacation_db_file = sprintf('%s/%s', $home, $VACATION_DB_FILE); $forward_file = sprintf('%s/%s', $home, $FORWARD_FILE); $forward_active = test_readable($forward_file, $user); + +$user_alias = ''; +$vacation_args = Array(); +if (array_key_exists($user, $USER_ALIASES)) { + $user_alias = $USER_ALIASES[$user]; + $vacation_args[] = '-a'; + $vacation_args[] = $user_alias; +} +$vacation_args[] = $user; + $forward_settings = Array( - '\\'.$user, '', sprintf($VACATION_FORWARD_ENTRY, $user)); + '\\'.$user, '', sprintf($VACATION_FORWARD_ENTRY, implode(' ', $vacation_args))); if ($forward_active) { $forward_settings = cat_file($forward_file, $user); @@ -203,6 +213,8 @@ if ($forward_active) $forward_settings[2] = $forward_settings[1]; $forward_settings[1] = ''; } + // refresh vacation command +# $forward_settings[2] = sprintf($VACATION_FORWARD_ENTRY, implode(' ', $vacation_args)); } $vacation_setup_raw = isset($_REQUEST["raw"]); @@ -253,6 +265,8 @@ if ( !$vacation_refresh && !$vacation_cl $vacation_forward_to = vacation_find_forward($vacation_headers); } } +// remove domain suffix +$vacation_forward_to = preg_replace('/@.*$/', '', $vacation_forward_to); // -------------------------------------------------- // |||:sec:||| Set vacation(1) parameters @@ -276,9 +290,10 @@ if ($vacation_setup || $vacation_setup_r if ($vacation_forward_to == $user) { $vacation_forward_to = ''; } + $forward_settings = Array( '\\'.$user, $vacation_forward_to, - sprintf($VACATION_FORWARD_ENTRY, $user)); + sprintf($VACATION_FORWARD_ENTRY, implode(' ', $vacation_args))); if ( $vacation_setup_raw ) { $vacation_msg = isset($_REQUEST['message']) ? trim($_REQUEST['message']) : ''; @@ -298,8 +313,17 @@ if ($vacation_setup || $vacation_setup_r while (True) { if ($vacation_del_log) { system(sprintf( - '%s -u %s %s %s -i', - $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD)); + '%s -u %s %s %s %s', + $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_INIT_OPTS)); + $vacation_excl_pipe = popen(sprintf( + '%s -u %s %s %s %s', + $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_EXLCUDE_OPTS), + 'w'); + fwrite($vacation_excl_pipe, sprintf("%s%s\n", $user, $DOMAIN_SUFFIX)); + if (!empty($user_alias)) { + fwrite($vacation_excl_pipe, sprintf("%s%s\n", $user_alias, $DOMAIN_SUFFIX)); + } + pclose($vacation_excl_pipe); break; } @@ -337,14 +361,27 @@ if ($vacation_setup || $vacation_setup_r // Initialize vacation(1) if necessary. if (!test_readable($vacation_db_file, $user)) { system(sprintf( - '%s -u %s %s %s -i', - $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD)); + '%s -u %s %s %s %s', + $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_INIT_OPTS)); + $vacation_excl_pipe = popen(sprintf( + '%s -u %s %s %s %s', + $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_EXLCUDE_OPTS), + 'w'); + fwrite($vacation_excl_pipe, sprintf("%s%s\n", $user, $DOMAIN_SUFFIX)); + if (!empty($user_alias)) { + fwrite($vacation_excl_pipe, sprintf("%s%s\n", $user_alias, $DOMAIN_SUFFIX)); + } + pclose($vacation_excl_pipe); } // Write or remove .forward file if ($forward_active) { + $expanded_forward_settings = $forward_settings; + if (!empty($expanded_forward_settings[1])) { + $expanded_forward_settings[1] .= $DOMAIN_SUFFIX; + } $use_fs = Array(); - foreach ($forward_settings as $fs) { + foreach ($expanded_forward_settings as $fs) { if (empty($fs)) { continue; } @@ -356,10 +393,27 @@ if ($vacation_setup || $vacation_setup_r 'w'); fwrite($forward_file_pipe, implode(", ", $use_fs)."\n"); pclose($forward_file_pipe); + if (!empty($VACATION_FORWARD_EXT_ENTRY)) { + foreach ($FORWARD_EXTENSIONS as $fe) { + $cmd = sprintf( + '%s -u %s %s %s %s%s', + $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $forward_file, $fe); + $forward_file_pipe = popen($cmd, 'w'); + fwrite($forward_file_pipe, $VACATION_FORWARD_EXT_ENTRY."\n"); + pclose($forward_file_pipe); + } + } } else { system(sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $RM_CMD, $forward_file)); + if (!empty($VACATION_FORWARD_EXT_ENTRY)) { + foreach ($FORWARD_EXTENSIONS as $fe) { + system(sprintf( + '%s -u %s %s %s %s%s', + $SUDO_CMD, $user, $SUDO_OPT_H, $RM_CMD, $forward_file, $fe)); + } + } } break; }