Changeset - r42:e7c378036e33
[Not reviewed]
default
0 1 0
Wolfgang Scherer (ws) - 7 years ago 2018-02-28 15:34:15
wolfgang.scherer@gmx.de
index.php: quoting for final message fixed.
1 file changed with 13 insertions and 10 deletions:
index.php
13
10
0 comments (0 inline, 0 general)
index.php
Show inline comments
 
@@ -251,227 +251,230 @@ if ( $x_wsv_raw )
 
    $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<br>\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<br>\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
 

	
 
        if (!$FOOTER || $vacation_setup_raw || $x_wsv_raw) {
 
            $vacation_body_full = $vacation_body;
 
        } else {
 
            $vacation_body_full = str_replace("\n", "\r\n", str_replace("\r", "", rtrim(rtrim($vacation_body)."\n\n".$FOOTER)));
 
        }
 

	
 
        // 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);
 
            $vacation_msg_in = message_join($vacation_headers, $vacation_body);
 
            $vacation_msg = message_join($vacation_headers, $vacation_body_full);
 
            // echo "<pre>"; // |:debug:|
 
            // var_dump($vacation_headers);
 
            // var_dump($vacation_body);
 
            // echo $vacation_msg;
 
            // echo "</pre>";
 
        } else {
 
            $vacation_msg = vacation_join($vacation_subject, $vacation_body, $vacation_headers);
 
            $vacation_msg_in = vacation_join($vacation_subject, $vacation_body, $vacation_headers);
 
            $vacation_msg = vacation_join($vacation_subject, $vacation_body_full, $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<br>\n", $pipe_cmd);
 

	
 
        $vacation_msg_pipe = popen($pipe_cmd, 'w');
 
        fwrite($vacation_msg_pipe, $vacation_msg);
 
        fwrite($vacation_msg_pipe, $vacation_msg_in);
 
        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<br>\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);
 
        fwrite($vacation_msg_pipe, $vacation_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<br>\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<br>\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<br>\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<br>\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<br>\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<br>\n", $cmd);
 
                    system($cmd);
 
                }
 
            }
 
        }
 
        break;
 
    }
 
}
 

	
 
// echo ('<pre>'."\n");            // |:debug:|
 
// echo ($vacation_forward_to);
 
// var_dump($forward_settings);
 
// echo ('</pre>'."\n");
 

	
 
// --------------------------------------------------
 
// |||:sec:||| User Interface
 
// --------------------------------------------------
 

	
 
$form = Array();
 
//$form[] = '<hr class="sep"/>';
 
$form[] = '<form action="index.php" method="post">';
 
$form[] = '<div>';
 

	
 
if ($_debug) {
 
    $form[] = sprintf(
 
        '<input type="hidden" name="_DEBUG_" value="%s" />', $_debug);
 
}
 

	
 
// Retrieval
 
$form[] = '<span class="label">';
 
$form[] = sprintf('<input type="submit" name="refresh" value="%s" />', get_text('refresh'));
 
$form[] = sprintf('<br /><input type="submit" name="clear" value="%s" />', get_text('clear'));
 
@@ -492,193 +495,193 @@ if ($_debug) {
 
if ($is_admin) {
 
    $user_control[] = '<select name="user">';
 
    foreach ($user_names as $sel_user) {
 
        if ($sel_user == $user) {
 
            $selected = ' selected="selected"';
 
        } else {
 
            $selected = '';
 
        }
 
        $user_control[] = sprintf('<option%s>%s</option>', $selected, $sel_user);
 
    }
 
    $user_control[] = '</select>';
 
    $user_control = implode($user_control, "\n");
 
} else {
 
    $user_control = sprintf(
 
        '<input type="hidden" name="user" value="%s" />%s', $user, $user);
 
}
 
$trow[] = $user_control;
 

	
 
// forward
 
$user_control = Array();
 
$user_control[] = '<select name="forward">';
 
$user_control[] = sprintf('<option value="">%s</option>', get_text('none'));
 
$selected = '';
 
foreach ($user_names as $sel_user) {
 
    if (!$is_admin && $sel_user == $user) {
 
        continue;
 
    }
 
    if ($sel_user == $vacation_forward_to) {
 
        $selected = ' selected="selected"';
 
    } else {
 
        $selected = '';
 
    }
 
    $user_control[] = sprintf('<option%s>%s</option>', $selected, $sel_user);
 
}
 
$user_control[] = '</select>';
 
$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('<input type="checkbox" name="active" value="active"%s /><br />',
 
                          $active_checked);
 
$user_control = implode($user_control, "\n");
 
$trow[] = $user_control;
 

	
 
$form[] = sprintf('<tr><td style="text-align: center;">%s</td></tr>', implode($trow, '</td><td style="text-align: center;">'));
 
$form[] = '</table></div><br />';
 

	
 
$text_rows = 10;
 
// $text_rows = 3;                // |:debug:|
 

	
 
if ( !$x_wsv_raw )
 
{
 
    $form[] = sshl(get_text('automatic_mode'));
 

	
 
    // subject
 
    $form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('subject'));
 
    $form[] = (
 
        '<input type="text" name="subject" value="' . htmlspecialchars($vacation_subject, ENT_COMPAT, "UTF-8")
 
        .'" size="49" style="width: 440px;" /><br />');
 

	
 
    // message
 
    $form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('body'));
 
    $form[] = (
 
        '<textarea name="body" cols="56" rows="'.$text_rows.'"'
 
        .' style="vertical-align: top; width: 440px;">' . htmlspecialchars($vacation_body, ENT_NOQUOTES, "UTF-8") . '</textarea><br />');
 

	
 
    // actions
 
    $form[] = '<hr class="sep"/>';
 
    $form[] = '<span class="label">&nbsp;</span>';
 
    $form[] = sprintf('<input type="submit" name="save" value="%s" />', get_text('save'));
 
    //$form[] = ' ' . get_text('enable_encoding');
 
    $form[] = '<hr class="sep"/>';
 
}
 

	
 
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('<a href="#">'.get_text('expert_mode').'</a>', 'expert-mode-head');
 
    $form[] = '<div>';
 
    // raw message
 
    $form[] = sprintf('<span class="label">%s<sup>*</sup>:</span>', get_text('message'));
 
    $form[] = (
 
        '<textarea name="message" cols="56" rows="'.$text_rows.'"'
 
        .' style="vertical-align: top; width: 440px;">' . htmlspecialchars($vacation_msg, ENT_NOQUOTES, "UTF-8") . '</textarea><br />');
 
        .' style="vertical-align: top; width: 440px;">' . htmlspecialchars($vacation_msg_in, ENT_NOQUOTES, "UTF-8") . '</textarea><br />');
 

	
 
    $form[] = '<span class="label">&nbsp;</span>';
 
    $form[] = (
 
        '<span style="display: inline-block; width: 440px; margin-top: 5px; font-size: 8pt;">'
 
        . get_text('explain_expert')
 
        .'</span><br />');
 

	
 
    $form[] = '<hr class="sep"/>';
 
    $form[] = '<span class="label">&nbsp;</span>';
 
    $form[] = sprintf('<input type="submit" name="raw" value="%s" />', get_text('save'));
 
    //$form[] = ' ' . get_text('disable_encoding');
 
    $form[] = '<hr class="sep"/>';
 
    $form[] = '</div>';
 

	
 
}
 

	
 
//$form[] = '<span class="label">&nbsp;</span>';
 
$form[] = (
 
    '<span style="display: inline-block; width: 550px;"><sup>*</sup>'
 
    . get_text('explain_subject')
 
    .'</span><br />');
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Vacation History
 
// --------------------------------------------------
 

	
 
$vacation_list_cmd = sprintf(
 
    '%s -u %s %s %s -l', $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD);
 
// echo ('<pre>'."\n");
 
// echo ($vacation_list_cmd);
 
// echo ('</pre>'."\n");
 
// fprintf($stderr, "\$vacation_list_cmd: %s<br>\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[] = '<hr class="sep"/>';
 
    $form[] = '<pre>';
 
    $form[] = $vacation_list;
 
    $form[] = '</pre>';
 
    $form[] = '<hr class="sep"/>';
 
    $form[] = '<span class="label">&nbsp;</span>';
 
    $form[] = sprintf('<input type="submit" name="delete" value="%s" /><br />', get_text('delete'));
 
    if ($is_admin) {
 
        $form[] = ('<hr class="sep"/>');
 
    }
 
} else {
 
    $form[] = shl(get_text('reply_history_empty'));
 
}
 

	
 
$form[] = '</div>';
 
$form[] = '</form>';
 
echo implode($form, "\n");
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Administrator Manual
 
// --------------------------------------------------
 

	
 
if ($is_admin) {
 
    echo shl(get_text('manual_headline'));
 
    echo (sprintf('<a href="%s">%s</a><br />'."\n", get_text('manual_link'), get_text('manual')));
 
}
 

	
 
// --------------------------------------------------
 
// |||:sec:||| Debug
 
// --------------------------------------------------
 

	
 
if ($_debug) {
 
    echo "<pre>\n";                 // |:debug:|
 
    echo "\$_REQUEST: \n";
 
    var_dump($_REQUEST);
 
    echo "</pre>\n";
 

	
 
    echo "\$_SERVER: \n";
 
    echo "<pre>\n";                 // |:debug:|
 
    var_dump($_SERVER);
 
    echo "</pre>\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
0 comments (0 inline, 0 general)