// Sponsored by WIEDENMANN SEILE GMBH, http://www.wiedenmannseile.de // // This file is part of Wiedenmann Vacation. // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published // by the Free Software Foundation; either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see , // or write to Wolfgang Scherer, // $_REQUEST['_DEBUG_'] = 1; // -------------------------------------------------- // |||:sec:||| Configuration // -------------------------------------------------- require_once(dirname(__FILE__) . '/lib/util.php'); require_once(dirname(__FILE__) . '/lib/template.php'); // _DEBUG_ = 1 normal debugging // _DEBUG_ = 2 turn off administrator rights // _DEBUG_ = 3 provoke error #1 // _DEBUG_ = 4 provoke error #2 if (isset($_REQUEST['_DEBUG_'])) { $_debug = $_REQUEST['_DEBUG_']; if (empty($_debug)) { $_debug = 1; } } else { $_debug = 0; } //$stderr = fopen('php://stderr', 'w'); // file_put_contents('/tmp/xxxxxxx', 'check'); // system('touch /tmp/xxxxxx1'); // -------------------------------------------------- // |||:sec:||| Setup // -------------------------------------------------- if (isset($_SERVER["REMOTE_USER"])) { $remote_user = $_SERVER["REMOTE_USER"]; } else { $remote_user = ''; } if (isset($_REQUEST["user"])) { $request_user = $_REQUEST["user"]; } else { $request_user = ''; } $is_admin = in_array($remote_user, $ADMIN_USERS); if ($_debug > 1) { $is_admin = False; } // $is_admin = False; // |:debug:| $users = get_users(); $user_names = array_keys($users); if (!$is_admin) { $user = $remote_user; } else { $user = $request_user; if (empty($user)) { $user = $remote_user; } } // -------------------------------------------------- // |||:sec:||| HTML Header // -------------------------------------------------- $title = get_text('title'); $css = ' div.error { margin-bottom: 10px; } span.label { width: 100px; display: inline-block; vertical-align: top; } hr.sep { width: 550px; text-align: left; margin-left: 0; } #body, #copyright-notice { width: 550px; margin: 10px auto; position:relative; } #body { text-align: left; } #copyright-notice { text-align: center; font-size: 8pt; } h4._more, h4._less { cursor: pointer; } h4._more:after { content: "..."; font-weight: bold; padding-left: 4px; } h4._less:before { content: "^"; font-weight: bold; padding-right: 4px; } '; $headers = ''; $script =' jQuery(document).ready(function(){ $("#expert-mode").click(function(ev) { ev.preventDefault(); var jthis = $(this); var contents = jthis.next(); if (contents.is(":visible")) { jthis.addClass("_more"); jthis.removeClass("_less"); contents.hide(); } else { jthis.removeClass("_more"); jthis.addClass("_less"); contents.show(); } return false; }).click(); }); '; echo substitute_elements( $HEAD, Array( 'title' => trim($title), 'css' => trim($css), 'headers' => trim($headers), 'script' => trim($script), )); hl($title); // -------------------------------------------------- // |||:sec:||| Error handling (User) // -------------------------------------------------- if ($_debug > 2) { $user = ''; // error #1 } if ($_debug > 3) { $user = 'unknown'; // error #2 } if (empty($user)) { error_msg(get_text('error_no_user')); echo $FOOT; exit(0); } if (!$is_admin && !in_array($user, $user_names)) { error_msg(sprintf('%s (%s)!', get_text('error_unknown_user'), $user)); echo $FOOT; exit(0); } // -------------------------------------------------- // |||:sec:||| Setup HOME/vacation(1) // -------------------------------------------------- $home = $users[$user][1]; if ($_debug) { echo ('
'."\n");            // |:debug:|
    echo ('user: ' . $user . "\n");
    echo ('home: ' . $home . "\n");
    echo ('
'."\n"); } $vacation_msg_in_file = sprintf('%s/%s', $home, $VACATION_MSG_IN_FILE); $vacation_msg_file = sprintf('%s/%s', $home, $VACATION_MSG_FILE); $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, implode(' ', $vacation_args))); if ($forward_active) { $forward_settings = cat_file($forward_file, $user); $lines = explode("\n", $forward_settings); $forward_settings = preg_split('/, */', $lines[0]); if (count($forward_settings) < 3) { $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"]); $vacation_clear = isset($_REQUEST['clear']); if ($vacation_clear || !test_readable($vacation_msg_in_file, $user)) { // Reset to default $vacation_msg = get_text('vacation'); $vacation_parts = vacation_split($vacation_msg, False); $vacation_subject = $vacation_parts[0]; $vacation_body = $vacation_parts[2]; $vacation_msg = vacation_join($vacation_subject, $vacation_body); $vacation_setup_raw = False; } else { $vacation_msg = cat_file($vacation_msg_in_file, $user); } $message_parts = message_split($vacation_msg); $message_headers = $message_parts[0]; $message_body = $message_parts[1]; $x_wsv_format = header_field_body($message_headers, 'x-wsv-format'); if ( $x_wsv_format == 'raw' ) { $x_wsv_raw = True; } else { $x_wsv_raw = False; } if ( $x_wsv_raw ) { $vacation_headers = $message_headers; $vacation_body = $message_body; $vacation_subject = header_field_body($vacation_headers, 'subject'); } else { $vacation_parts = vacation_split($vacation_msg, True); $vacation_subject = $vacation_parts[0]; $vacation_headers = $vacation_parts[1]; $vacation_body = $vacation_parts[2]; } $vacation_refresh = isset($_REQUEST['refresh']); $vacation_forward_to = ''; if ( !$vacation_refresh && !$vacation_clear && isset($_REQUEST['forward']) ) { $vacation_forward_to = $_REQUEST['forward']; } else { $vacation_forward_to = $forward_settings[1]; $vacation_forward_to = preg_replace('/^\\\\/', '', $vacation_forward_to); if (empty($vacation_forward_to)) { $vacation_forward_to = vacation_find_forward($vacation_headers); } } // remove domain suffix $vacation_forward_to = preg_replace('/@.*$/', '', $vacation_forward_to); // -------------------------------------------------- // |||:sec:||| Set vacation(1) parameters // -------------------------------------------------- $vacation_setup = isset($_REQUEST['save']); if ( $vacation_setup ) { // |:check:| redundant? $vacation_setup_raw = False; } $vacation_del_log = isset($_REQUEST['delete']); if ( $vacation_del_log ) { if ( !isset($_REQUEST['subject']) ) { $vacation_setup_raw = True; } } if ($vacation_setup || $vacation_setup_raw || $vacation_del_log) { $forward_active = isset($_REQUEST['active']); // validate forward to if ($vacation_forward_to == $user) { $vacation_forward_to = ''; } $forward_settings = Array( '\\'.$user, $vacation_forward_to, sprintf($VACATION_FORWARD_ENTRY, implode(' ', $vacation_args))); if ( $vacation_setup_raw ) { $vacation_msg = isset($_REQUEST['message']) ? trim($_REQUEST['message']) : ''; $message_parts = message_split($vacation_msg); $vacation_headers = header_clean($message_parts[0]); $vacation_body = $message_parts[1]; $vacation_subject = header_field_body($vacation_headers, 'subject'); header_set($vacation_headers, 'X-WSV-Format: raw'); $x_wsv_raw = True; } else { $vacation_subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : ''; $vacation_body = isset($_REQUEST['body']) ? trim($_REQUEST['body']) : ''; $vacation_headers = Array(); $x_wsv_raw = False; } while (True) { if ($vacation_del_log) { $cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_INIT_OPTS); // fprintf($stderr, "\$cmd: %s
\n", $cmd); system($cmd); $pipe_cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_EXLCUDE_OPTS); // fprintf($stderr, "\$pipe_cmd: %s
\n", $pipe_cmd); $vacation_excl_pipe = popen($pipe_cmd, '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; } if (empty ($vacation_subject)) { error_msg(get_text('error_no_subject')); break; } if (!$is_admin && !empty($vacation_forward_to) && !in_array($vacation_forward_to, $user_names)) { error_msg(sprintf('%s (%s)!', get_text('error_unknown_forward'), $vacation_forward_to)); break; } // Actually set it // Prepare vacation(1) message if (!empty($vacation_forward_to)) { header_set($vacation_headers, sprintf('X-WSV-Forward-To: %s', $vacation_forward_to)); } if ( $vacation_setup_raw ) { $vacation_msg = message_join($vacation_headers, $vacation_body); // echo "
"; // |:debug:|
            // var_dump($vacation_headers);
            // var_dump($vacation_body);
            // echo $vacation_msg;
            // echo "
"; } else { $vacation_msg = vacation_join($vacation_subject, $vacation_body, $vacation_headers); } $pipe_cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $vacation_msg_in_file); // fprintf($stderr, "\$pipe_cmd: %s
\n", $pipe_cmd); $vacation_msg_pipe = popen($pipe_cmd, 'w'); fwrite($vacation_msg_pipe, $vacation_msg); pclose($vacation_msg_pipe); $pipe_cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $vacation_msg_file); // fprintf($stderr, "\$pipe_cmd: %s
\n", $pipe_cmd); $vacation_msg_pipe = popen($pipe_cmd, 'w'); if (!$FOOTER || $vacation_setup_raw || $x_wsv_raw) { $full_msg = $vacation_msg; } else { $full_msg = rtrim(rtrim($vacation_msg)."\n".$FOOTER)."\n"; } fwrite($vacation_msg_pipe, $full_msg); pclose($vacation_msg_pipe); // Initialize vacation(1) if necessary. if (!test_readable($vacation_db_file, $user)) { $cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_INIT_OPTS); // fprintf($stderr, "\$cmd: %s
\n", $cmd); system($cmd); $pipe_cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD, $VACATION_EXLCUDE_OPTS); // fprintf($stderr, "\$pipe_cmd: %s
\n", $pipe_cmd); $vacation_excl_pipe = popen($pipe_cmd, '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 ($expanded_forward_settings as $fs) { if (empty($fs)) { continue; } $use_fs[] = $fs; } $pipe_cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $forward_file); // fprintf($stderr, "\$pipe_cmd: %s
\n", $pipe_cmd); $forward_file_pipe = popen($pipe_cmd, 'w'); fwrite($forward_file_pipe, implode(", ", $use_fs)."\n"); pclose($forward_file_pipe); if (!empty($VACATION_FORWARD_EXT_ENTRY)) { foreach ($FORWARD_EXTENSIONS as $fe) { $pipe_cmd = sprintf( '%s -u %s %s %s %s%s', $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $forward_file, $fe); // fprintf($stderr, "\$pipe_cmd: %s
\n", $pipe_cmd); $forward_file_pipe = popen($pipe_cmd, 'w'); fwrite($forward_file_pipe, $VACATION_FORWARD_EXT_ENTRY."\n"); pclose($forward_file_pipe); } } } else { $cmd = sprintf( '%s -u %s %s %s %s', $SUDO_CMD, $user, $SUDO_OPT_H, $RM_CMD, $forward_file); // fprintf($stderr, "\$cmd: %s
\n", $cmd); system($cmd); 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, $RM_CMD, $forward_file, $fe); // fprintf($stderr, "\$cmd: %s
\n", $cmd); system($cmd); } } } break; } } // echo ('
'."\n");            // |:debug:|
// echo ($vacation_forward_to);
// var_dump($forward_settings);
// echo ('
'."\n"); // -------------------------------------------------- // |||:sec:||| User Interface // -------------------------------------------------- $form = Array(); //$form[] = '
'; $form[] = '
'; $form[] = '
'; if ($_debug) { $form[] = sprintf( '', $_debug); } // Retrieval $form[] = ''; $form[] = sprintf('', get_text('refresh')); $form[] = sprintf('
', get_text('clear')); $form[] = '
'; // column names $form[] = '
'; $trow = Array(); $trow[] = get_text('user'); $trow[] = get_text('forward_to'); $trow[] = get_text('active'); $form[] = sprintf('', implode($trow, ' ', implode($trow, '
 %s 
 ')); $trow = Array(); // user $user_control = Array(); if ($is_admin) { $user_control[] = ''; $user_control = implode($user_control, "\n"); } else { $user_control = sprintf( '%s', $user, $user); } $trow[] = $user_control; // forward $user_control = Array(); $user_control[] = ''; $user_control = implode($user_control, "\n"); $trow[] = $user_control; // active checkbox $user_control = Array(); if ($forward_active) { $active_checked = ' checked="checked"'; } else { $active_checked = ''; } $user_control[] = sprintf('
', $active_checked); $user_control = implode($user_control, "\n"); $trow[] = $user_control; $form[] = sprintf('
%s
')); $form[] = '

'; $text_rows = 10; // $text_rows = 3; // |:debug:| if ( !$x_wsv_raw ) { $form[] = sshl(get_text('automatic_mode')); // subject $form[] = sprintf('%s*:', get_text('subject')); $form[] = ( '
'); // message $form[] = sprintf('%s*:', get_text('body')); $form[] = ( '
'); // actions $form[] = '
'; $form[] = ' '; $form[] = sprintf('', get_text('save')); //$form[] = ' ' . get_text('enable_encoding'); $form[] = '
'; } if ($x_wsv_raw || $EXPERT_ENABLED) { if ( $x_wsv_raw ) { $text_rows = 15; $id = null; } else { $text_rows = 5; $id = 'expert-mode'; } $form[] = sshl(get_text('expert_mode'), $id); # $form[] = sshl(''.get_text('expert_mode').'', 'expert-mode-head'); $form[] = '
'; // raw message $form[] = sprintf('%s*:', get_text('message')); $form[] = ( '
'); $form[] = ' '; $form[] = ( '' . get_text('explain_expert') .'
'); $form[] = '
'; $form[] = ' '; $form[] = sprintf('', get_text('save')); //$form[] = ' ' . get_text('disable_encoding'); $form[] = '
'; $form[] = '
'; } //$form[] = ' '; $form[] = ( '*' . get_text('explain_subject') .'
'); // -------------------------------------------------- // |||:sec:||| Vacation History // -------------------------------------------------- $vacation_list_cmd = sprintf( '%s -u %s %s %s -l', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD); // echo ('
'."\n");
// echo ($vacation_list_cmd);
// echo ('
'."\n"); // fprintf($stderr, "\$vacation_list_cmd: %s
\n", $vacation_list_cmd); $vacation_ausgabe = popen ($vacation_list_cmd, 'r'); $vacation_list = stream_get_contents($vacation_ausgabe); pclose($vacation_ausgabe); if (!empty ($vacation_list)) { $form[] = shl(get_text('reply_history')); // $form[] = '
'; $form[] = '
';
    $form[] = $vacation_list;
    $form[] = '
'; $form[] = '
'; $form[] = ' '; $form[] = sprintf('
', get_text('delete')); if ($is_admin) { $form[] = ('
'); } } else { $form[] = shl(get_text('reply_history_empty')); } $form[] = '
'; $form[] = '
'; echo implode($form, "\n"); // -------------------------------------------------- // |||:sec:||| Administrator Manual // -------------------------------------------------- if ($is_admin) { echo shl(get_text('manual_headline')); echo (sprintf('%s
'."\n", get_text('manual_link'), get_text('manual'))); } // -------------------------------------------------- // |||:sec:||| Debug // -------------------------------------------------- if ($_debug) { echo "
\n";                 // |:debug:|
    echo "\$_REQUEST: \n";
    var_dump($_REQUEST);
    echo "
\n"; echo "\$_SERVER: \n"; echo "
\n";                 // |:debug:|
    var_dump($_SERVER);
    echo "
\n"; } echo $FOOT; // // :ide-menu: Emacs IDE Menu - Buffer @BUFFER@ // . M-x `eIDE-menu' ()(eIDE-menu "z") // :ide: COMPILE: PHP _DEBUG_=2 _DEBUG_TEST_=2 // . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) " _DEBUG_=2 _DEBUG_TEST_=2")) // :ide: QUO: $this-> // . (insert "$this->" ) // :ide: COMPILE: PHP w/o args // . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) "")) // :ide: COMPILE: PHP _DEBUG_=1 _DEBUG_TEST_=1 // . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) " _DEBUG_=1 _DEBUG_TEST_=1")) // // Local Variables: // mode: php // End: ?>