Commit 0cd74bff authored by Côme Chilliet's avatar Côme Chilliet
Browse files

Merge branch '6061-adapt-plugins-code-to-changes-on-error-system' into '1.4-dev'

Resolve "Adapt plugins code to changes on error system"

See merge request fusiondirectory/fd-plugins!744
parents f47b8388 db8ac6ac
......@@ -166,7 +166,8 @@ class argonautAction extends ManagementDialog
$o_queue = new supportDaemon();
$o_queue->append($this);
if ($o_queue->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($o_queue->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($o_queue->get_error()));
$error->display();
}
$this->parent->closeDialogs();
}
......
......@@ -112,19 +112,16 @@ class argonautImportFile extends simplePlugin
return;
} elseif (isset($_POST['start_import'])) {
$events = $this->events;
$error = FALSE;
$failed = FALSE;
foreach ($events as $event) {
if (!empty($event['ERROR'])) {
$error = TRUE;
$failed = TRUE;
break;
}
}
if ($error) {
msg_dialog::display(
_('Import'),
_('Fix the errors in your CSV file first'),
ERROR_DIALOG
);
if ($failed) {
$error = new FusionDirectoryError(htmlescape(_('Fix the errors in your CSV file first')));
$error->display();
} else {
$success = 0;
$fail = 0;
......@@ -138,14 +135,15 @@ class argonautImportFile extends simplePlugin
}
$this->parent->o_queue->append_call($event['HEADER'], [$event['MAC']], $data);
if ($this->parent->o_queue->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($this->parent->o_queue->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($this->parent->o_queue->get_error()));
$error->display();
$fail++;
} else {
unset($events[$key]);
$success++;
}
}
msg_dialog::display(_('Import'), sprintf(_('Import complete: %s events successfully send, %s failed'), $success, $fail), INFO_DIALOG);
msg_dialog::display(_('Import'), htmlescape(sprintf(_('Import complete: %s events successfully send, %s failed'), $success, $fail)), INFO_DIALOG);
$this->events = $events;
}
}
......@@ -157,7 +155,8 @@ class argonautImportFile extends simplePlugin
/* Some file checks */
$lines = preg_split('/\n/', $str);
if (empty($str) || !count($lines)) {
msg_dialog::display(_('Import'), msgPool::incorrectUpload(_('file is empty')), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::incorrectUpload(_('file is empty')));
$error->display();
return;
}
......
......@@ -226,12 +226,18 @@ class argonautQueue extends management
}
}
if (count($nodelete)) {
msg_dialog::display(_('Remove'),
sprintf(_('The following jobs couldn\'t be deleted, they have to be aborted: %s'),
'<br/>'.msgPool::buildList($nodelete)), INFO_DIALOG);
msg_dialog::display(
_('Remove'),
sprintf(
htmlescape(_('The following jobs couldn\'t be deleted, they have to be aborted: %s')),
'<br/>'.msgPool::buildList($nodelete)
),
INFO_DIALOG
);
}
if (count($disallowed)) {
msg_dialog::display(_('Permission'), msgPool::permDelete($disallowed), INFO_DIALOG);
$error = new FusionDirectoryPermissionError(msgPool::permDelete($disallowed));
$error->display();
}
// We've at least one entry to delete.
......@@ -292,7 +298,7 @@ class argonautQueue extends management
$this->o_queue->append_call('wakeup', $macs, []);
if ($this->o_queue->is_error()) {
msg_dialog::display(_('Info'), sprintf(_('%s'), $this->o_queue->get_error()), INFO_DIALOG);
msg_dialog::display(_('Info'), htmlescape($this->o_queue->get_error()), INFO_DIALOG);
}
// Removing the task.
$this->o_queue->remove_entries($taskids);
......@@ -313,7 +319,7 @@ class argonautQueue extends management
{
if (count($action['targets']) == 1) {
$entry = $this->listing->getEntry($action['targets'][0]);
msg_dialog::display(_('Error detail'), $entry['ERROR']);
msg_dialog::display(_('Error detail'), htmlescape($entry['ERROR']), INFO_DIALOG);
}
}
......@@ -345,7 +351,8 @@ class argonautQueue extends management
/* Tell the daemon that we want to update some entries */
if (count($update_ids)) {
if (!$this->o_queue->process_entries_now($update_ids)) {
msg_dialog::display(_('Error'), sprintf(_('Cannot update queue entries.')), ERROR_DIALOG);
$error = new FusionDirectoryError(htmlescape(_('Cannot update queue entries.')));
$error->display();
return FALSE;
}
}
......
......@@ -58,7 +58,7 @@ class ArgonautQueueColumn extends Column
if (!empty($targetdn) && !empty($targettype)) {
return objects::link($targetdn, $targettype, '', $text, TRUE);
} else {
return htmlentities($text, ENT_COMPAT, 'UTF-8');
return htmlescape($text);
}
}
......@@ -77,14 +77,14 @@ class ArgonautQueueColumn extends Column
$str = mb_substr($str, 0, 18).'...';
}
$str = htmlentities($str, ENT_COMPAT, 'UTF-8');
$str = htmlescape($str);
if (isset($infos['listimg']) && !empty($infos['listimg'])) {
$str = $infos['listimg']."&nbsp;".$str;
}
}
if ($progress) {
$str .= "&nbsp;(".htmlentities($progress, ENT_COMPAT, 'UTF-8')."%)";
$str .= "&nbsp;(".htmlescape($progress)."%)";
}
return $str;
}
......@@ -95,7 +95,7 @@ class ArgonautQueueColumn extends Column
if (!empty($periodic) && !preg_match('/none/i', $periodic)) {
$tmp = explode('_', $periodic);
if (count($tmp) == 2) {
$period = htmlentities($tmp[0], ENT_COMPAT, 'UTF-8').'&nbsp;'.htmlentities(_($tmp[1]), ENT_COMPAT, 'UTF-8');
$period = htmlescape($tmp[0]).'&nbsp;'.htmlescape(_($tmp[1]));
}
}
return $period;
......@@ -104,23 +104,23 @@ class ArgonautQueueColumn extends Column
static function filterSchedule (string $stamp): string
{
if ($stamp == '19700101000000') {
return _('immediately');
return htmlescape(_('immediately'));
} else {
return date('d.m.Y H:i:s', strtotime($stamp));
return htmlescape(date('d.m.Y H:i:s', strtotime($stamp)));
}
}
static function filterStatus (int $row, string $status, string $substatus): string
{
if ($status == 'waiting') {
$status = '<img class="center" src="geticon.php?context=status&icon=task-waiting&size=16" alt="clock"/>&nbsp;'._('Waiting');
$status = '<img class="center" src="geticon.php?context=status&amp;icon=task-waiting&amp;size=16" alt="clock"/>&nbsp;'.htmlescape(_('Waiting'));
}
if ($status == 'error') {
$status = '<input class="center" type="image" src="geticon.php?context=status&icon=task-failure&size=16" title="'._('Show error').'" '.
'name="listing_showError_'.$row.'" style="padding:1px"/>'._('Error');
$status = '<input class="center" type="image" src="geticon.php?context=status&amp;icon=task-failure&amp;size=16" title="'.htmlescape(_('Show error')).'" '.
'name="listing_showError_'.$row.'" style="padding:1px"/>'.htmlescape(_('Error'));
}
if ($status == 'processed') {
$status = '<img class="center" src="geticon.php?context=status&icon=task-complete&size=16" alt=""/>&nbsp;'._('Processed');
$status = '<img class="center" src="geticon.php?context=status&amp;icon=task-complete&amp;size=16" alt=""/>&nbsp;'.htmlescape(_('Processed'));
}
/* Special handling for all entries that have
......@@ -129,7 +129,7 @@ class ArgonautQueueColumn extends Column
if ($status == 'processing' && $substatus) {
$status = $substatus;
} elseif ($status == 'processing') {
$status = preg_replace('/ /', '&nbsp;', _('in progress'));
$status = preg_replace('/ /', '&nbsp;', htmlescape(_('in progress')));
}
return $status;
......
......@@ -63,7 +63,8 @@ class argonautQueueFilter extends managementFilter
$argonautEntries = $this->parent->o_queue->get_queued_entries($event_tags, 0, 9999999, 'id');
if ($this->parent->o_queue->is_error()) {
msg_dialog::display(_('Error'), sprintf(_('Cannot load queue entries: <br/><br/>%s'), $this->parent->o_queue->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($this->parent->o_queue->get_error()));
$error->display();
return [[], []];
}
......
<div id="{$sectionId}" class="plugin-section fullwidth">
<span class="legend">
{$section}
{if $sectionIcon}<img src="{$sectionIcon|escape}" alt=""/>{/if}{$section|escape}
</span>
<div>
{if $attributes.events|@count == 0}
......@@ -23,10 +23,10 @@
<tbody>
{foreach from=$attributes.events item=event}
<tr>
<td>{$event.TIMESTAMP}</td>
<td>{$event.MAC}</td>
<td>{$event.HEADER}</td>
<td>{$event.OGROUP}</td>
<td>{$event.TIMESTAMP|escape}</td>
<td>{$event.MAC|escape}</td>
<td>{$event.HEADER|escape}</td>
<td>{$event.OGROUP|escape}</td>
{if $event.ERROR}
<td style="background-color: #F0BBBB;"><b>{$event.ERROR}</b></td>
{else}
......
......@@ -127,15 +127,15 @@ class argonautFuseConfig extends simpleService
function check (): array
{
$message = parent::check();
$errors = parent::check();
foreach ($this->plugin as $plugin) {
if ($plugin->is_account) {
$message = array_merge($message, $plugin->check());
$errors = array_merge($errors, $plugin->check());
}
}
return $message;
return $errors;
}
function set_acl_category (string $cat)
......
......@@ -27,11 +27,12 @@ class CertificateOrderedArrayAttribute extends OrderedArrayAttribute
$img = $this->renderInputField(
'image', $id.'_download_'.$key,
[
'src' => 'geticon.php?context=actions&amp;icon=document-save&amp;size=16',
'src' => 'geticon.php?context=actions&icon=document-save&size=16',
'title' => _('Download'),
'alt' => _('Download'),
'class' => 'center'
]
],
FALSE
).$img;
$nbicons++;
......
......@@ -228,8 +228,13 @@ class mailMethodCyrus extends mailMethod
}
if (!imap_set_quota($this->imap_handle, $this->account_id, $this->quotaValue)) {
msg_dialog::display(_("IMAP error"), sprintf(_("Cannot modify IMAP mailbox quota: %s"),
'<br><br><i>'.imap_last_error().'</i>'), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Cannot modify IMAP mailbox quota: %s'),
imap_last_error()
))
);
$error->display();
@DEBUG(DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, "<b>".$this->account_id.": (".$debug_number.")</b>",
"<b>IMAP: Set account quota</b> on server '".$this->parent->gosaMailServer."' <b>".imap_last_error()."</b>");
return FALSE;
......@@ -304,9 +309,14 @@ class mailMethodCyrus extends mailMethod
return FALSE;
}
} else {
msg_dialog::display(_("Mail info"),
sprintf(_("LDAP entry has been removed but cyrus mailbox (%s) is kept.\nPlease delete it manually!"),
$this->account_id), INFO_DIALOG);
msg_dialog::display(
_('Mail info'),
nl2br(htmlescape(sprintf(
_("LDAP entry has been removed but cyrus mailbox (%s) is kept.\nPlease delete it manually!"),
$this->account_id
))),
INFO_DIALOG
);
}
return TRUE;
}
......
......@@ -68,7 +68,8 @@ class DebconfEntriesAttribute extends CompositeAttribute
//~ 'owners'
//~ 'template'
} else {
msg_dialog::display(_("Error"), _("There is no template for this profile"), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape(_('There is no template for this profile')));
$error->display();
}
}
}
......@@ -82,9 +83,15 @@ class DebconfEntriesAttribute extends CompositeAttribute
$dn = "cn=$cn,ou=questions,".$this->plugin->dn;
$ldap->cat($dn, ["objectClass"]);
if ($ldap->count() != 1) {
msg_dialog::display(_("Error"),
sprintf(_("Can't find entry %s in LDAP for profile %s"), $cn, $this->plugin->dn),
ERROR_DIALOG);
$error = new SimplePluginError(
$this,
htmlescape(sprintf(
_('Can\'t find entry %s in LDAP for profile %s'),
$cn,
$this->plugin->dn
))
);
$error->display();
} else {
$attrs = [
'value' => [$attribute->getValue()],
......@@ -135,13 +142,17 @@ class DebconfImportAttribute extends FileAttribute
$ldap->import_complete_ldif($str, FALSE, FALSE);
$this->plugin->initially_was_account = TRUE;
} catch (FusionDirectoryException $e) {
msg_dialog::display(_('LDAP error'), $e->getMessage(), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape($e->getMessage()), 0, $e);
$error->display();
}
} else {
msg_dialog::display(_("LDIF error"), "Could not found template name in the ldif ".
"was expecting ou=<b>name</b>,ou=templates,".
get_ou("debconfRDN").$config->current['BASE'],
ERROR_DIALOG);
$error = new SimplePluginError(
$this,
"Could not find template name in the ldif ".
"was expecting ou=<b>name</b>,ou=templates,".
htmlescape(get_ou("debconfRDN").$config->current['BASE'])
);
$error->display();
}
}
......
<div id="{$sectionId}" class="plugin-section{$sectionClasses}">
<span class="legend">
{$section}
{if $sectionIcon}<img src="{$sectionIcon|escape}" alt=""/>{/if}{$section|escape}
</span>
<div>
{if $attributes.dump}
......
......@@ -118,11 +118,12 @@ class DhcpSectionsAttribute extends DialogOrderedArrayAttribute
$img = $this->renderInputField(
'image', $id.'_insertDHCP_'.$key,
[
'src' => 'geticon.php?context=actions&amp;icon=document-new&amp;size=16',
'src' => 'geticon.php?context=actions&icon=document-new&size=16',
'title' => _('Insert new DHCP section'),
'alt' => _('Insert new DHCP section'),
'class' => 'center',
]
],
FALSE
).$img;
$nbicons++;
......@@ -254,7 +255,10 @@ class DhcpSectionsAttribute extends DialogOrderedArrayAttribute
return $error;
}
if (empty($this->value) || empty($this->dhcpObjectCache[$this->value[0][0]]['cn']) || ($this->dhcpObjectCache[$this->value[0][0]]['cn'][0] == '')) {
return msgPool::required(_('Name'));
return new SimplePluginCheckError(
$this,
msgPool::required(_('Name'))
);
}
}
......@@ -429,7 +433,8 @@ class DhcpSectionsAttribute extends DialogOrderedArrayAttribute
}
/* That should not happen... */
msg_dialog::display(_('Error'), _('The DHCP configuration set is unkown. Please contact your system administrator.'), ERROR_DIALOG);
$error = new SimplePluginError($this, htmlescape(_('The DHCP configuration set is unkown. Please contact your system administrator.')));
$error->display();
return '';
}
......
......@@ -131,7 +131,11 @@ class dhcpConfiguration extends simplePlugin
/* Save dhcp settings */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
$ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
try {
$ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
} catch (FusionDirectoryError $error) {
return [$error];
}
$cache = $this->attributesAccess['dhcpSections']->getCache();
$errors = [];
$new = ($this->orig_dn == 'new');
......@@ -148,7 +152,13 @@ class dhcpConfiguration extends simplePlugin
$ldap->rmdir_recursive($dn);
if (!$ldap->success()) {
$this->ldap_error = $ldap->get_error();
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$dn,
LDAP_DEL,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
}
......@@ -201,13 +211,25 @@ class dhcpConfiguration extends simplePlugin
$ldap->modify($attrs);
if (!$ldap->success()) {
$this->ldap_error = $ldap->get_error();
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$dn,
LDAP_MOD,
$ldap->get_error(),
$ldap->get_errno()
);
}
} else {
$ldap->add($attrs);
if (!$ldap->success()) {
$this->ldap_error = $ldap->get_error();
$errors[] = msgPool::ldaperror($ldap->get_error(), $dn, LDAP_ADD, get_class());
$errors[] = new SimplePluginLdapError(
$this,
$dn,
LDAP_ADD,
$ldap->get_error(),
$ldap->get_errno()
);
}
}
}
......
......@@ -78,7 +78,7 @@ class dhcpHost extends dhcpPlugin
function check (): array
{
$messages = parent::check();
$errors = parent::check();
$dn = $this->dn;
if (($dn == '') || ($dn == 'new')) {
$dn = $this->compute_dn();
......@@ -87,16 +87,22 @@ class dhcpHost extends dhcpPlugin
foreach ($this->dhcpStatements as $statement) {
if (preg_match('/^fixed-address (.+)$/', $statement, $m)) {
if (!tests::is_ip($m[1])) {
$messages[] = sprintf(_('"%s" is not a valid IP address.'), $m[1]);
$errors[] = new SimplePluginCheckError(
$this,
htmlescape(sprintf(_('"%s" is not a valid IP address.'), $m[1]))
);
} else {
$error = $this->parentPlugin->attributesAccess['dhcpSections']->isIpInParentSubnet($dn, $m[1]);
if ($error !== TRUE) {
$messages[] = $error;
$errors[] = new SimplePluginCheckError(
$this,
htmlescape($error)
);
}
}
}
}
return $messages;
return $errors;
}
}
......@@ -255,12 +255,18 @@ class DhcpHostsAttribute extends OrderedArrayAttribute
return $error;
} else {
if (!is_array($this->value)) {
return sprintf(_('The value for multivaluated field "%s" is not an array'), $this->getLabel());
return new SimplePluginCheckError(
$this,
SimplePluginCheckError::invalidValue(_('Value is not an array'))
);
}
foreach ($this->value as $value) {
$error = dhcpSystem::dhcpIsIpInSubnet($this->nodesCache[$value[0]], $value[2]);
if ($error !== TRUE) {
return $error;
return new SimplePluginCheckError(
$this,
htmlescape($error)
);
}
}
}
......
......@@ -416,7 +416,10 @@ class DnsRecordAttribute extends CompositeAttribute
$reverse = $this->attributes[2]->getValue();
if (!static::matchReverseZone($type, $ip, $reverse)) {
return _('The entered IP does not match the selected reverse zone');
return new SimplePluginCheckError(
$this,
htmlescape(_('The entered IP does not match the selected reverse zone'))
);
}
}
}
......
......@@ -76,16 +76,28 @@ class dnsManagement extends management
list ($fqdn) = explode(' ', $entry['sOARecord'][0]);
$servers = static::findServerByFQDN($fqdn, $zoneDn);
if (count($servers) > 1) {
msg_dialog::display(_('Could not run ldap2zone'), _('More than one server matches the SOA'), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Could not run ldap2zone: %s'),
_('More than one server matches the SOA')
))
);
$error->display();
} elseif (count($servers) == 0) {
msg_dialog::display(_('Could not run ldap2zone'), sprintf(_('Could not find the primary server "%s"'), $fqdn), ERROR_DIALOG);
$error = new FusionDirectoryError(
htmlescape(sprintf(
_('Could not run ldap2zone: %s'),
sprintf(_('Could not find the primary server "%s"'), $fqdn)
))
);
$error->display();
} else {
$serverTabs = objects::open(key($servers), 'server');
if ($serverTabs->by_object['argonautClient']->is_account) {
$s_daemon = new supportDaemon();
if ($s_daemon->is_error()) {
msg_dialog::display(_('Could not run ldap2zone'), msgPool::siError($s_daemon->get_error()), ERROR_DIALOG
);
$error = new FusionDirectoryError(msgPool::siError($s_daemon->get_error()));
$error->display();
} else {
$target = $serverTabs->getBaseObject()->macAddress;
if (is_array($target)) {
......@@ -94,13 +106,15 @@ class dnsManagement extends management
$zoneName = $entry['zoneName'];
$s_daemon->append_call('Ldap2Zone.start', $target, ['args' => [$zoneName]]);
if ($s_daemon->is_error()) {
msg_dialog::display(_('Could not get run ldap2zone'), msgPool::siError($s_daemon->get_error()), ERROR_DIALOG);
$error = new FusionDirectoryError(msgPool::siError($s_daemon->get_error()));
$error->display();
} else {
msg_dialog::display(_('Ldap2zone'), sprintf(_('Ldap2Zone called for zone "%s"'), $zoneName), INFO_DIALOG);
msg_dialog::display(_('Ldap2zone'), htmlescape(sprintf(_('Ldap2Zone called for zone "%s"'), $zoneName)), INFO_DIALOG);