Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/283 history #333

Merged
merged 8 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lam-packaging/debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -1184,3 +1184,6 @@ templates/lib/extra/friendlyCaptcha B
templates/lib/400_Sortable*.js B RubaXa, owenm
templates/lib/extra/jstree/* B 2014 Ivan Bozhanov
style/jstree/* B 2014 Ivan Bozhanov
templates/lib/extra/qrcode/* B 2009 Kazuhiko Arase
templates/lib/extra/tabulator/* B 2024 Oliver Folkerd
style/tabulator/* B 2024 Oliver Folkerd
1 change: 1 addition & 0 deletions lam/HISTORY
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ June 2024 8.8
- LAM Pro:
-> Request access: request data can be imported and exported as part of configuration
-> Request access: added $$approveLink$$ and $$rejectLink$$ in approval mails
-> Request access: added history (283)


16.03.2024 8.7
Expand Down
3 changes: 3 additions & 0 deletions lam/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -1183,3 +1183,6 @@ templates/lib/extra/friendlyCaptcha B
templates/lib/400_Sortable*.js B RubaXa, owenm
templates/lib/extra/jstree/* B 2014 Ivan Bozhanov
style/jstree/* B 2014 Ivan Bozhanov
templates/lib/extra/qrcode/* B 2009 Kazuhiko Arase
templates/lib/extra/tabulator/* B 2024 Oliver Folkerd
style/tabulator/* B 2024 Oliver Folkerd
34 changes: 34 additions & 0 deletions lam/docs/manual-sources/chapter-configuration.xml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,40 @@
</screenshot></para>
</section>

<section id="confMainGlobalCron">
<title>Module settings and global cron job (LAM Pro)</title>

<para>The global cron job is used to perform cleanup tasks.</para>

<para><emphasis role="bold">Note: This is only needed when you use the
"Request access" module. If you do not use this module you do not need
to run the global cron job.</emphasis></para>

<para>Cleanup actions</para>

<itemizedlist>
<listitem>
<para>Request access</para>

<itemizedlist>
<listitem>
<para>Expiration of open requests (using "Request expiration
period")</para>
</listitem>

<listitem>
<para>Cleanup request history (using "History retention
period")</para>
</listitem>
</itemizedlist>
</listitem>
</itemizedlist>

<screenshot>
<graphic fileref="images/configGeneral11.png"/>
</screenshot>
</section>

<section>
<title>Change master password</title>

Expand Down
15 changes: 15 additions & 0 deletions lam/docs/manual-sources/chapter-installation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,21 @@
version. Unless explicitly noticed there is no need to install an
intermediate release.</para>

<section>
<title>8.7 -&gt; 8.8</title>

<para>LAM Pro:</para>

<itemizedlist>
<listitem>
<para>Request access: please run the <link
linkend="confMainGlobalCron">new global cron job</link> to remove
requests that are too old. The time limit can be configured in
LAM's main configuration.</para>
</listitem>
</itemizedlist>
</section>

<section>
<title>8.6 -&gt; 8.7</title>

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lam/help/help.inc
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,9 @@ $helpArray = [
"293" => ["Headline" => _('Database type'),
"Text" => _('Please select the type of database to use for all configuration data. Please install PHP MySQL PDO extension for MySQL support.')
],
"294" => ["Headline" => _('Cron command'),
"Text" => _('Run this for global cleanup tasks. See manual for details.')
],
// 300 - 399
// profile/PDF editor, file upload
"301" => ["Headline" => _("RDN identifier"),
Expand Down
40 changes: 40 additions & 0 deletions lam/lib/baseModule.inc
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,46 @@ abstract class baseModule {
return $messages;
}

/**
* Returns a list of config options for LAM's main configuration.
*
* @param array $currentSettings current settings
* @return htmlElement[] config options
*/
public function getGlobalConfigOptions(array $currentSettings): array {
return [];
}

/**
* Checks the global config options.
*
* @param string[] $messages info messages can be added here
* @param string[] $errors error messages can be added here
* @param array $options config options
*/
public function checkGlobalConfigOptions(array &$options, array &$messages, array &$errors): void {
// to be implemented by modules if needed
}

/**
* Specifies if the module supports global cron job actions.
*
* @return bool supports cron
*/
public function supportsGlobalCronJob(): bool {
return false;
}

/**
* Runs any global cron actions.
*
* @param bool $isDryRun dry-run active
* @throws LAMException error during execution
*/
public function runGlobalCronActions(bool $isDryRun): void {
// needs to be implemented by submodule if needed
}

/**
* Returns a hashtable with all entries that may be printed out in the PDF.
*
Expand Down
30 changes: 29 additions & 1 deletion lam/lib/config.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3145,6 +3145,9 @@ class LAMCfgMain {
/** database password */
public $configDatabasePassword = '';

/** database password */
private $moduleSettings = '';

/** list of data fields to save in config file */
private $settings = ["password", "default", "sessionTimeout", "hideLoginErrorDetails",
"logLevel", "logDestination", "allowedHosts", "passwordMinLength",
Expand All @@ -3158,7 +3161,7 @@ class LAMCfgMain {
'mailAttribute', 'mailBackupAttribute',
'configDatabaseType',
'configDatabaseServer', 'configDatabasePort', 'configDatabaseName', 'configDatabaseUser',
'configDatabasePassword'
'configDatabasePassword', 'moduleSettings'
];

/** persistence settings are always stored on local file system */
Expand Down Expand Up @@ -3187,6 +3190,7 @@ class LAMCfgMain {
$this->logDestination = "SYSLOG";
$this->allowedHosts = "";
$this->allowedHostsSelfService = '';
$this->moduleSettings = '';
try {
$this->reload();
} catch (LAMException $e) {
Expand Down Expand Up @@ -3548,6 +3552,9 @@ class LAMCfgMain {
if (!in_array("configDatabasePassword", $saved)) {
array_push($file_array, "configDatabasePassword: " . $this->configDatabasePassword . "\n");
}
if (!in_array("moduleSettings", $saved)) {
array_push($file_array, "moduleSettings: " . $this->moduleSettings . "\n");
}

$file = @fopen($this->conffile, "w");
if ($file) {
Expand Down Expand Up @@ -3916,4 +3923,25 @@ class LAMCfgMain {
return self::MAIL_BACKUP_ATTRIBUTE_DEFAULT;
}

/**
* Returns a list of module settings.
*
* @return array module settings
*/
public function getModuleSettings(): array {
if (empty($this->moduleSettings)) {
return [];
}
return json_decode(base64_decode($this->moduleSettings), true);
}

/**
* Sets the module settings.
*
* @param array $settings module settings
*/
public function setModuleSettings(array $settings): void {
$this->moduleSettings = base64_encode(json_encode($settings));
}

}
69 changes: 69 additions & 0 deletions lam/lib/cronGlobal.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
namespace LAM\Cron;
use Exception;
use LAM\DB\CronDatabase;
use LAMCfgMain;
use LAMConfig;
use LAMException;
use PDOException;
use Ldap;
use LAM\JOB\JobResultLog;
use ServerProfilePersistenceManager;

/*

This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2024 Roland Gruber

*/

/**
* Global cron job for LAM.
*
* @package jobs
* @author Roland Gruber
*/

/** access to configuration data */
include_once(__DIR__ . "/config.inc");
/** access to ldap data */
include_once(__DIR__ . "/ldap.inc");
/** access to modules */
include_once(__DIR__ . "/modules.inc");

// check parameters
$isDryRun = (isset($argv[2]) && ($argv[2] == '--dryRun')) ? true : false;

$_SESSION['cfgMain'] = new LAMCfgMain();

if ($isDryRun) {
echo "Dry run: no changes, only logging.\n";
}

// execute jobs
$errorsOccurred = false;
$allModules = getAllModules();
foreach ($allModules as $module) {
if (!$module->supportsGlobalCronJob()) {
continue;
}
try {
if ($isDryRun) {
echo "Started actions for " . $module->get_alias() . "\n";
}
logNewMessage(LOG_NOTICE, 'Started actions for ' . $module->get_alias());
$module->runGlobalCronActions($isDryRun);
if ($isDryRun) {
echo "Finished actions for " . $module->get_alias() . "\n";
}
logNewMessage(LOG_NOTICE, 'Finished actions for ' . $module->get_alias());
}
catch (Exception $e) {
$errorsOccurred = true;
echo "Error in " . $module->get_alias() . ': ' . $e->getMessage() . "\n" . $e->getTraceAsString() . "\n";
}
}
if ($errorsOccurred) {
echo "Problems occurred during cron execution\n";
die(1);
}
13 changes: 13 additions & 0 deletions lam/lib/cronGlobal.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

dir=`dirname $0`

if [ -x /usr/bin/php ]; then
# delimiter must be added to support arguments starting with "--"
/usr/bin/php -f $dir/cronGlobal.inc delimiter $*
exit $?
fi

echo "No PHP executable found"

exit 1
101 changes: 101 additions & 0 deletions lam/lib/html.inc
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,107 @@ class htmlTable extends htmlElement {

}

/**
* Table component for client-side controlled data tables.
*/
class htmlDataTable extends htmlElement {

public const DATA_AJAX_URL = 'ajaxurl';
public const DATA_TOKEN_NAME = 'tokenname';
public const DATA_TOKEN_VALUE = 'tokenvalue';
public const DATA_ACTION = 'action';
public const DATA_OK_TEXT = 'oktext';

private string $id;
private int $height;
private array $columns;

/**
* Constructor
*
* @param string $id table ID
* @param htmlDataTableColumn[] $columns columns
* @param int $height table height
*/
public function __construct(string $id, array $columns, int $height = 300) {
$this->id = htmlspecialchars($id);
$this->height = $height;
$this->columns = $columns;
}

/**
* @inheritDoc
*/
function generateHTML($module, $input, $values, $restricted, $scope) {
echo '<link href="../../style/tabulator/tabulator.css" rel="stylesheet">';
echo '<script type="text/javascript" src="../../templates/lib/extra/tabulator/tabulator.js.js"></script>';
echo '<div id="' . $this->id . '" class="lam-data-table" ' . $this->getDataAttributesAsString() . '></div>';
$columnOptions = [];
foreach ($this->columns as $column) {
$headerFilter = $column->filterable ? ', headerFilter: "input"' : '';
$columnOptions[] = '{
title: "' . $column->label . '",
field: "' . $column->name . '",
formatter: "textarea"
' . $headerFilter . '
}';
}
$columnsCode = implode(', ', $columnOptions);
echo '<script type="text/javascript">
window.lam.datatable.init("' . $this->id . '", new Tabulator("#' . $this->id . '", {
height: ' . $this->height . ',
layout: "fitColumns",
pagination:"local",
paginationSize:50,
paginationSizeSelector:[50, 100, 250, 500],
columns: [' . $columnsCode . '],
data: [],
locale: "en-gb",
langs: {
"en-gb": {
"pagination": {
"page_size": "",
"page_title": "",
"first": "↤",
"first_title": "",
"last": "↦",
"last_title": "",
"prev": "←",
"prev_title": "",
"next": "→",
"next_title": ""
}
}
}
}));
</script>';
return [];
}

}

/**
* Column for data table.
*/
class htmlDataTableColumn {

public string $label;
public string $name;
public bool $filterable;

/**
* @param string $label
* @param string $name
* @param bool $filterable
*/
public function __construct(string $label, string $name, bool $filterable = true) {
$this->label = htmlspecialchars($label);
$this->name = htmlspecialchars($name);
$this->filterable = $filterable;
}

}

/**
* A standard input field.
*
Expand Down
Loading
Loading