support jobs

This commit is contained in:
Roland Gruber 2015-06-16 18:59:56 +00:00
parent 75155bbf38
commit dc10196c35
5 changed files with 96 additions and 13 deletions

View File

@ -1758,6 +1758,15 @@ abstract class baseModule {
return true;
}
/**
* Returns a list of jobs that can be run.
*
* @param LAMConfig $config configuration
*/
public function getSupportedJobs(&$config) {
return array();
}
// helper functions

View File

@ -521,6 +521,10 @@ class LAMConfig {
private $jobsBindPassword = null;
/** database for jobs */
private $jobsDatabase = null;
/** random job token */
private $jobToken = null;
/** job configuration */
private $jobSettings = array();
/** List of all settings in config file */
private $settings = array("ServerURL", "useTLS", "followReferrals", 'pagedResults', "Passwd", "Admins", "treesuffix",
@ -528,7 +532,7 @@ class LAMConfig {
"modules", "activeTypes", "types", "tools", "accessLevel", 'loginMethod', 'loginSearchSuffix',
'loginSearchFilter', 'searchLimit', 'lamProMailFrom', 'lamProMailReplyTo', 'lamProMailSubject',
'lamProMailText', 'lamProMailIsHTML', 'lamProMailAllowAlternateAddress', 'httpAuthentication', 'loginSearchDN',
'loginSearchPassword', 'timeZone', 'jobsBindUser', 'jobsBindPassword', 'jobsDatabase');
'loginSearchPassword', 'timeZone', 'jobsBindUser', 'jobsBindPassword', 'jobsDatabase', 'jobToken', 'jobs');
/**
@ -561,7 +565,7 @@ class LAMConfig {
$file = @fopen($conffile, "r");
if (!$file) return false; // abort if file is not readable
while (!feof($file)) {
$line = fgets($file, 100000);
$line = fgets($file, 1000000);
$line = trim($line); // remove spaces at the beginning and end
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
// search keywords
@ -587,6 +591,12 @@ class LAMConfig {
$pos = strpos($option, ":");
$this->toolSettings[substr($option, 0, $pos)] = substr($option, $pos + 2);
}
// job settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "jobs: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->jobSettings[substr($option, 0, $pos)] = explode(LAMConfig::LINE_SEPARATOR, substr($option, $pos + 2));
}
// general settings
else {
$this->$keyword = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
@ -638,7 +648,7 @@ class LAMConfig {
$file_array = array();
// read config file
while (!feof($file)) {
array_push($file_array, fgets($file, 1024));
array_push($file_array, fgets($file, 1000000));
}
fclose($file);
// generate new configuration file
@ -679,6 +689,15 @@ class LAMConfig {
$file_array[$i] = "tools: " . $name . ": " . $this->toolSettings[$name] . "\n";
$mod_saved[] = $name; // mark keyword as saved
}
// job settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "jobs: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$name = substr($option, 0, $pos);
if (!isset($this->jobSettings[$name])) continue;
$file_array[$i] = "jobs: " . $name . ": " . implode(LAMConfig::LINE_SEPARATOR, $this->jobSettings[$name]) . "\n";
$mod_saved[] = $name; // mark keyword as saved
}
// general settings
else {
$file_array[$i] = $keyword . ": " . $this->$keyword . "\n";
@ -723,6 +742,7 @@ class LAMConfig {
if (!in_array("jobsBindPassword", $saved)) array_push($file_array, "\n" . "jobsBindPassword: " . $this->jobsBindPassword . "\n");
if (!in_array("jobsBindUser", $saved)) array_push($file_array, "\n" . "jobsBindUser: " . $this->jobsBindUser . "\n");
if (!in_array("jobsDatabase", $saved)) array_push($file_array, "\n" . "jobsDatabase: " . $this->jobsDatabase . "\n");
if (!in_array("jobToken", $saved)) array_push($file_array, "\n" . "jobToken: " . $this->getJobToken() . "\n");
// check if all module settings were added
$m_settings = array_keys($this->moduleSettings);
for ($i = 0; $i < sizeof($m_settings); $i++) {
@ -744,6 +764,13 @@ class LAMConfig {
array_push($file_array, "tools: " . $tool_settings[$i] . ": " . $this->toolSettings[$tool_settings[$i]] . "\n");
}
}
// check if all job settings were added
$jobSettings = array_keys($this->jobSettings);
for ($i = 0; $i < sizeof($jobSettings); $i++) {
if (!in_array($jobSettings[$i], $mod_saved)) {
array_push($file_array, "jobs: " . $jobSettings[$i] . ": " . implode(LAMConfig::LINE_SEPARATOR, $this->jobSettings[$jobSettings[$i]]) . "\n");
}
}
$file = @fopen($conffile, "w");
$saveResult = LAMConfig::SAVE_OK;
if ($file) {
@ -1658,6 +1685,41 @@ class LAMConfig {
$this->jobsDatabase = $jobsDatabase;
}
/**
* Sets the settings for the jobs.
*
* @param array $settings list of job settings array(name => value)
* @return boolean true if $settings has correct format
*/
public function setJobSettings($settings) {
if (!is_array($settings)) {
return false;
}
$this->jobSettings = $settings;
return true;
}
/**
* Returns a list of saved job settings.
*
* @return array list of settings: array(name => value)
*/
public function getJobSettings() {
return $this->jobSettings;
}
/**
* Returns the job token.
*
* @return String job token
*/
public function getJobToken() {
if (empty($this->jobToken)) {
$this->jobToken = getRandomNumber();
}
return $this->jobToken;
}
}

View File

@ -980,7 +980,7 @@ class htmlButton extends htmlElement {
}
$id = ' id="btn_' . preg_replace('/[^a-zA-Z0-9_-]/', '', $this->name) . '"';
if ($this->isImageButton) {
echo '<input type="submit" ' . $id . ' value=" "' . $name . $fieldTabIndex . $style . $class . $title . $disabled . '>';
echo '<input type="submit" ' . $id . ' value=" "' . $name . $onClick . $fieldTabIndex . $style . $class . $title . $disabled . '>';
}
else {
echo '<button' . $id . $name . $fieldTabIndex . $type . $onClick . $style . $class . $title . $disabled . '>' . $this->value . '</button>';

View File

@ -4,7 +4,7 @@ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2010 Cedric Dugas and Olivier Refalo
2011 - 2013 Roland Gruber
2011 - 2015 Roland Gruber
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
@ -30,7 +30,6 @@ if (strtolower(session_module_name()) == 'files') {
session_save_path(dirname(__FILE__) . '/../../sess');
}
// start empty session and change ID for security reasons
@session_start();
setlanguage();

View File

@ -208,14 +208,16 @@ function profileShowDeleteDialog(title, okText, cancelText, scope, selectFieldNa
* Shows a simple dialog.
*
* @param title dialog title
* @param okText text for Ok button
* @param okText text for Ok button (optional, submits form)
* @param cancelText text for Cancel button
* @param formID form ID
* @param dialogDivID ID of div that contains dialog content
*/
function showSimpleDialog(title, okText, cancelText, formID, dialogDivID) {
var buttonList = {};
if (okText) {
buttonList[okText] = function() { document.forms[formID].submit(); };
}
buttonList[cancelText] = function() { jQuery(this).dialog("close"); };
jQuery('#' + dialogDivID).dialog({
modal: true,
@ -324,11 +326,7 @@ function showConfirmationDialog(title, okText, cancelText, dialogDiv, formName,
if (resultField) {
jQuery('#' + resultField).val('ok');
};
var inputs = jQuery('#' + dialogDiv + ' :input');
inputs.each(function() {
jQuery(this).appendTo(document.forms[formName]);
});
document.forms[formName].submit();
appendDialogInputsToFormAndSubmit(dialogDiv, formName);
};
buttonList[cancelText] = function() {
if (resultField) {
@ -345,6 +343,21 @@ function showConfirmationDialog(title, okText, cancelText, dialogDiv, formName,
});
}
/**
* Appends the input fields of a dialog back to the form and submits it.
*
* @param dialogDiv ID of dialog div
* @param formName name of form
*/
function appendDialogInputsToFormAndSubmit(dialogDiv, formName) {
var inputs = jQuery('#' + dialogDiv + ' :input');
inputs.each(function() {
jQuery(this).addClass('hidden');
jQuery(this).appendTo(document.forms[formName]);
});
document.forms[formName].submit();
}
/**
* Shows a simple confirmation dialog.
* If the user presses Cancel then the current action is stopped (event.preventDefault()).