Changeset - r36:bc316cd848df
[Not reviewed]
default
0 1 0
root@mecki.wiedenmann-seile.de - 12 years ago 2013-06-17 13:34:11
root@mecki.wiedenmann-seile.de
* index.php: disable permission tests.
1 file changed with 2 insertions and 2 deletions:
0 comments (0 inline, 0 general)
index.php
Show inline comments
 
<?php // -*- php -*-
 
// Copyright (C) 2012, Wolfgang Scherer, <Wolfgang.Scherer at gmx.de>
 
// 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 <http://www.gnu.org/licenses/>,
 
// or write to Wolfgang Scherer, <Wolfgang.Scherer at gmx.de>
 

	
 
// $_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;
 
}
 

	
 
file_put_contents('/tmp/xxxxxxx', 'check');
 
system('touch /tmp/xxxxxx1');
 
// 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 class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>';
 

	
 
$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 ('<pre>'."\n");            // |:debug:|
 
    echo ('user: ' . $user . "\n");
 
    echo ('home: ' . $home . "\n");
 
    echo ('</pre>'."\n");
 
}
 

	
 
$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);
 
$forward_settings = Array(
 
    '\\'.$user, '', sprintf($VACATION_FORWARD_ENTRY, $user));
 
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] = '';
 
    }
 
}
 

	
 
$vacation_setup_raw = isset($_REQUEST["raw"]);
 
$vacation_clear = isset($_REQUEST['clear']);
 
if ($vacation_clear || !test_readable($vacation_msg_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_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);
 
    }
 
}
 

	
 
// --------------------------------------------------
 
// |||: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, $user));
 

	
 
    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) {
 
            system(sprintf(
 
                       '%s -u %s %s %s -i',
 
                       $SUDO_CMD, $user, $SUDO_OPT_H, $VACATION_CMD));
 
            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 "<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_pipe = popen(sprintf(
 
                  '%s -u %s %s %s %s',
 
                  $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $vacation_msg_file),
 
            'w');
 
        fwrite($vacation_msg_pipe, $vacation_msg);
 
        pclose($vacation_msg_pipe);
 

	
 
        // 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));
 
        }
 

	
 
        // Write or remove .forward file
 
        if ($forward_active) {
 
            $use_fs = Array();
 
            foreach ($forward_settings as $fs) {
 
                if (empty($fs)) {
 
                    continue;
 
                }
 
                $use_fs[] = $fs;
 
            }
 
            $forward_file_pipe = popen(sprintf(
 
                      '%s -u %s %s %s %s',
 
                      $SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $forward_file),
 
                'w');
 
            fwrite($forward_file_pipe, implode(", ", $use_fs)."\n");
 
            pclose($forward_file_pipe);
 
        } else {
 
            system(sprintf(
 
                       '%s -u %s %s %s %s',
 
                       $SUDO_CMD, $user, $SUDO_OPT_H, $RM_CMD, $forward_file));
 
        }
 
        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'));
 
$form[] = '</span>';
 

	
 
// column names
 
$form[] = '<div style="display: inline-block; padding: 0; margin: 0;"><table border="0" cellspacing="0" cellpadding="2" style="width: 445px; vertical-align: top;">';
 
$trow = Array();
 
$trow[] = get_text('user');
 
$trow[] = get_text('forward_to');
 
$trow[] = get_text('active');
 
$form[] = sprintf('<tr><th style="text-align: center;">&nbsp;%s&nbsp;</th></tr>', implode($trow, '&nbsp;</th><th style="text-align: center;">&nbsp;'));
 

	
 
$trow = Array();
 

	
 
// user
 
$user_control = Array();
 
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 />');
 

	
 
    $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");
 
$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
 
// . (compile (concat "php " (file-name-nondirectory (buffer-file-name)) " _DEBUG_=1 _DEBUG_TEST_=1"))
 

	
 
//
 
// Local Variables:
 
// mode: php
 
// End:
 
?>
0 comments (0 inline, 0 general)