// $_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');
// --------------------------------------------------
// |||: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;
}
$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 = '
span.label {
width: 100px;
display: inline-block;
}
hr.sep {
width: 550px;
text-align: left;
margin-left: 0;
}
';
echo substitute_elements(
$HEAD, Array(
'title' => $title,
'css' => $css,
));
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_no_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_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 = file_exists($forward_file);
$forward_settings = Array(
'\\'.$user, '', sprintf($VACATION_FORWARD_ENTRY, $user));
if ($forward_active)
{
$forward_settings = file_get_contents($forward_file);
$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_forward = $forward_settings[1];
$vacation_forward = preg_replace('/^\\\\/', '', $vacation_forward);
if (!file_exists($vacation_msg_file)) {
$vacation_msg = get_text('vacation');
} else {
$vacation_msg = file_get_contents($vacation_msg_file);
}
$lines = explode("\n", $vacation_msg);
$vacation_subject = array_shift($lines);
$vacation_subject = preg_replace('/^[Ss]ubject: */', '', $vacation_subject);
while (True) {
$line = array_shift($lines);
if (empty($line)) {
break;
}
}
$vacation_body = implode($lines, "\n");
// --------------------------------------------------
// |||:sec:||| Set vacation(1) parameters
// --------------------------------------------------
$vacation_setup = isset($_REQUEST['setzen']);
$vacation_clear = isset($_REQUEST['loeschen']);
if ($vacation_setup || $vacation_clear) {
$forward_active = isset($_REQUEST['aktiv']);
$vacation_forward = isset($_REQUEST['forward']) ? $_REQUEST['forward'] : '';
if ($vacation_forward == $user) {
$vacation_forward = '';
}
$vacation_subject = isset($_REQUEST['subject']) ? trim($_REQUEST['subject']) : '';
$vacation_body = isset($_REQUEST['body']) ? trim($_REQUEST['body']) : '';
$forward_settings = Array(
'\\'.$user, $vacation_forward,
sprintf($VACATION_FORWARD_ENTRY, $user));
while (True) {
if ($vacation_clear) {
system(sprintf(
'%s -u %s %s %s -i',
$SUDO_CMD, $SUDO_OPT_H, $user, $VACATION_CMD));
break;
}
if (empty ($vacation_subject)) {
error_msg(get_text('error_no_subject'));
break;
}
// Actually set it
// If not active, remove "Vertretung"
if (!$forward_active) {
$vacation_forward = '';
}
$forward_settings = Array(
'\\'.$user, $vacation_forward,
sprintf($VACATION_FORWARD_ENTRY, $user));
// Prepare vacation(1) message
$vacation_msg = sprintf(
"Subject: %s\n\n%s\n", $vacation_subject, $vacation_body);
$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 (!file_exists($vacation_db_file)) {
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 /bin/rm -f %s',
$SUDO_CMD, $user, $SUDO_OPT_H, $forward_file));
}
break;
}
}
// echo (''."\n"); // |:debug:|
// echo ($vacation_forward);
// var_dump($forward_settings);
// echo ('
'."\n");
// --------------------------------------------------
// |||:sec:||| User Interface
// --------------------------------------------------
$form = Array();
//$form[] = '
';
$form[] = '';
echo implode($form, "\n");
// --------------------------------------------------
// |||:sec:||| Administrator Manual
// --------------------------------------------------
if ($is_admin) {
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:
?>