<?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"];
$remote_user = '';
if (isset($_REQUEST["user"])) {
$request_user = $_REQUEST["user"];
$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;
$user = $request_user;
if (empty($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 {
margin: 10px auto;
position:relative;
#body {
#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: "^";
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();
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
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));
// |||: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;
$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;
$x_wsv_raw = False;
if ( $x_wsv_raw )
$vacation_headers = $message_headers;
$vacation_body = $message_body;
$vacation_subject = header_field_body($vacation_headers, 'subject');
$vacation_parts = vacation_split($vacation_msg, True);
$vacation_headers = $vacation_parts[1];
$vacation_refresh = isset($_REQUEST['refresh']);
$vacation_forward_to = '';
if ( !$vacation_refresh && !$vacation_clear && isset($_REQUEST['forward']) ) {
$vacation_forward_to = $_REQUEST['forward'];
$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_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) {
'\\'.$user, $vacation_forward_to,
sprintf($VACATION_FORWARD_ENTRY, $user));
if ( $vacation_setup_raw ) {
$vacation_msg = isset($_REQUEST['message']) ? trim($_REQUEST['message']) : '';
$vacation_headers = header_clean($message_parts[0]);
$vacation_body = $message_parts[1];
header_set($vacation_headers, 'X-WSV-Format: raw');
$vacation_subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
$vacation_body = isset($_REQUEST['body']) ? trim($_REQUEST['body']) : '';
$vacation_headers = Array();
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'));
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));
// 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));
$vacation_msg = message_join($vacation_headers, $vacation_body);
// echo "<pre>"; // |:debug:|
// var_dump($vacation_headers);
// var_dump($vacation_body);
// echo $vacation_msg;
// echo "</pre>";
$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)) {
// 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(
$SUDO_CMD, $user, $SUDO_OPT_H, $WRITE_TO_CMD, $forward_file),
fwrite($forward_file_pipe, implode(", ", $use_fs)."\n");
pclose($forward_file_pipe);
$SUDO_CMD, $user, $SUDO_OPT_H, $RM_CMD, $forward_file));
// 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>';
$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;"> %s </th></tr>', implode($trow, ' </th><th style="text-align: center;"> '));
// 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"';
$selected = '';
$user_control[] = sprintf('<option%s>%s</option>', $selected, $sel_user);
$user_control[] = '</select>';
$user_control = implode($user_control, "\n");
$user_control = sprintf(
'<input type="hidden" name="user" value="%s" />%s', $user, $user);
$trow[] = $user_control;
// forward
$user_control[] = '<select name="forward">';
$user_control[] = sprintf('<option value="">%s</option>', get_text('none'));
Status change: