Skip to content

Commit

Permalink
AuthMail and AuthLdapReplicate Twig UI
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 authored Nov 13, 2024
1 parent 42b861f commit 8b888a6
Show file tree
Hide file tree
Showing 8 changed files with 166 additions and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ The present file will list all changes made to the project; according to the
- `Toolbox::logError()`
- `Toolbox::logNotice()`
- `Toolbox::logWarning()`
- `Toolbox::showMailServerConfig()`
- `Toolbox::sodiumDecrypt()`
- `Toolbox::sodiumEncrypt()`
- `Toolbox::unclean_cross_side_scripting_deep()`
Expand Down
2 changes: 1 addition & 1 deletion src/AuthLDAP.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ public function showFormReplicatesConfig()
'test' => '',
],
'formatters' => [
'timeout' => 'number',
'timeout' => 'integer',
'test' => 'raw_html'
],
'entries' => $entries,
Expand Down
30 changes: 5 additions & 25 deletions src/AuthLdapReplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* ---------------------------------------------------------------------
*/

use Glpi\Application\View\TemplateRenderer;

/**
* Class used to manage LDAP replicate config
*/
Expand Down Expand Up @@ -80,31 +82,9 @@ public function prepareInputForUpdate($input)
*/
public static function addNewReplicateForm($target, $master_id)
{
echo "<form action='$target' method='post' name='add_replicate_form' id='add_replicate_form'>";
echo "<div class='center'>";
echo "<table class='tab_cadre_fixe'>";

echo "<tr><th colspan='5'>" . __('Add a LDAP directory replica') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='center'>" . __('Name') . "</td>";
echo "<td class='center'>" . __('Server') . "</td>";
echo "<td class='center'>" . _n('Port', 'Ports', 1) . "</td>";
echo "<td class='center'>" . __('Timeout') . "</td><td></td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td class='center'><input type='text' class='form-control' name='name'></td>";
echo "<td class='center'><input type='text' class='form-control' name='host'></td>";
echo "<td class='center'><input type='text' class='form-control' name='port'></td>";
echo "<td class='center'>";
Dropdown::showNumber('timeout', ['value' => 10,
'min' => 1,
'max' => 30,
'step' => 1,
'toadd' => [0 => __('No timeout')]
TemplateRenderer::getInstance()->display('pages/setup/authentication/ldap_replicate.html.twig', [
'target' => $target,
'authldaps_id' => $master_id,
]);
echo "</td>";
echo "<td class='center'><input type='hidden' name='next' value='extauth_ldap'>";
echo "<input type='hidden' name='authldaps_id' value='$master_id'>";
echo "<input type='submit' name='add_replicate' value='" . _sx('button', 'Add') . "' class='btn btn-primary'></td>";
echo "</tr></table></div>";
Html::closeForm();
}
}
96 changes: 41 additions & 55 deletions src/AuthMail.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* ---------------------------------------------------------------------
*/

use Glpi\Application\View\TemplateRenderer;

/**
* Class used to manage Auth mail config
*/
Expand Down Expand Up @@ -183,47 +185,14 @@ public function rawSearchOptions()
*/
public function showForm($ID, array $options = [])
{
if (!Config::canUpdate()) {
if (!$this->can($ID, UPDATE)) {
return false;
}
if (empty($ID)) {
$this->getEmpty();
} else {
$this->getFromDB($ID);
}

$options['colspan'] = 1;
$this->showFormHeader($options);

echo "<tr class='tab_bg_1'><td>" . __('Name') . "</td>";
echo "<td><input class='form-control' type='text' name='name' value='" . $this->fields["name"] . "'>";
echo "</td></tr>";

echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Active') . "</td>";
echo "<td colspan='3'>";
Dropdown::showYesNo('is_active', $this->fields['is_active']);
echo "</td></tr>";

echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Email domain Name (users email will be login@domain)') . "</td>";
echo "<td><input class='form-control' type='text' name='host' value='" . $this->fields["host"] . "'>";
echo "</td></tr>";

Toolbox::showMailServerConfig($this->fields["connect_string"]);

echo "<tr class='tab_bg_1'><td>" . __('Comments') . "</td>";
echo "<td>";
echo "<textarea class='form-control' name='comment'>" . $this->fields["comment"] . "</textarea>";
if ($ID > 0) {
echo "<br>";
//TRANS: %s is the datetime of update
printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"]));
}

echo "</td></tr>";

$this->showFormButtons($options);
TemplateRenderer::getInstance()->display('pages/setup/authentication/mail.html.twig', [
'item' => $this,
'params' => $options
]);
}

/**
Expand All @@ -236,23 +205,40 @@ public function showFormTestMail()
$ID = $this->getField('id');

if ($this->getFromDB($ID)) {
echo "<form method='post' action='" . $this->getFormURL() . "'>";
echo "<input type='hidden' name='imap_string' value=\"" . $this->fields['connect_string'] . "\">";
echo "<div class='center'><table class='tab_cadre'>";
echo "<tr><th colspan='2'>" . __('Test connection to email server') . "</th></tr>";

echo "<tr class='tab_bg_2'><td class='center'>" . __('Login') . "</td>";
echo "<td><input class='form-control' type='text' name='imap_login' value=''></td></tr>";

echo "<tr class='tab_bg_2'><td class='center'>" . __('Password') . "</td>";
echo "<td><input class='form-control' type='password' name='imap_password' value=''
autocomplete='new-password'></td></tr>";

echo "<tr class='tab_bg_2'><td class='center' colspan='2'>";
echo "<input type='submit' name='test' class='btn btn-primary' value=\"" . _sx('button', 'Test') . "\">" .
"</td>";
echo "</tr></table></div>";
Html::closeForm();
$twig_params = [
'title' => __('Test connection to email server'),
'login' => __('Login'),
'password' => __('Password'),
'test' => _x('button', 'Test'),
];
// language=Twig
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
{% import 'components/form/fields_macros.html.twig' as fields %}
<form method="post" action="{{ 'AuthMail'|itemtype_form_path }}" data-submit-once>
<div class="text-center d-flex flex-column">
<div>
<h1 class="fs-2">{{ title }}</h1>
</div>
{{ fields.textField('imap_login', '', login, {
full_width: true,
additional_attributes: {
autocomplete: 'username'
}
}) }}
{{ fields.passwordField('imap_password', '', password, {
full_width: true,
clearable: false,
additional_attributes: {
autocomplete: 'password'
}
}) }}
<div>
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}">
<button type="submit" name="test" class="btn btn-primary">{{ test }}</button>
</div>
</div>
</form>
TWIG, $twig_params);
}
}

Expand Down
23 changes: 0 additions & 23 deletions src/Toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -1769,29 +1769,6 @@ public static function parseMailServerConnectString($value, $forceport = false)
return $tab;
}


/**
* Display a mail server configuration form
*
* @param string $value host connect string ex {localhost:993/imap/ssl}INBOX
*
* @return string type of the server (imap/pop)
**/
public static function showMailServerConfig($value)
{
if (!Config::canUpdate()) {
return '';
}

$tab = Toolbox::parseMailServerConnectString($value);
TemplateRenderer::getInstance()->display('pages/setup/mailcollector/server_config_fields.html.twig', [
'connect_opts' => $tab,
'host' => $value
]);
return $tab['type'];
}


/**
* @param array $input
*
Expand Down
69 changes: 69 additions & 0 deletions templates/pages/setup/authentication/ldap_replicate.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{#
# ---------------------------------------------------------------------
#
# GLPI - Gestionnaire Libre de Parc Informatique
#
# http://glpi-project.org
#
# @copyright 2015-2024 Teclib' and contributors.
# @copyright 2003-2014 by the INDEPNET Development Team.
# @licence https://www.gnu.org/licenses/gpl-3.0.html
#
# ---------------------------------------------------------------------
#
# LICENSE
#
# This file is part of GLPI.
#
# 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 <https://www.gnu.org/licenses/>.
#
# ---------------------------------------------------------------------
#}

{% import 'components/form/fields_macros.html.twig' as fields %}

<form action="{{ target }}" method="post">
<div class="d-flex">
{{ fields.textField('name', '', __('Name'), {
field_class: 'col-3',
label_class: 'col-4',
input_class: 'col-8',
}) }}
{{ fields.textField('host', '', __('Server'), {
field_class: 'col-3',
label_class: 'col-4',
input_class: 'col-8',
}) }}
{{ fields.numberField('port', '', _n('Port', 'Ports', 1), {
field_class: 'col-3',
label_class: 'col-4',
input_class: 'col-8',
}) }}
{{ fields.dropdownNumberField('timeout', 10, __('Timeout'), {
min: 1,
max: 30,
toadd: {
0: __('No timeout')
},
field_class: 'col-3',
label_class: 'col-4',
input_class: 'col-8',
}) }}
</div>
<div class="d-flex flex-row-reverse">
<input type="hidden" name="authldaps_id" value="{{ authldaps_id }}">
<input type="hidden" name="_glpi_csrf_token" value="{{ csrf_token() }}">
<button type="submit" name="add_replicate" class="btn btn-primary">{{ _x('button', 'Add') }}</button>
</div>
</form>
44 changes: 44 additions & 0 deletions templates/pages/setup/authentication/mail.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{#
# ---------------------------------------------------------------------
#
# GLPI - Gestionnaire Libre de Parc Informatique
#
# http://glpi-project.org
#
# @copyright 2015-2024 Teclib' and contributors.
# @copyright 2003-2014 by the INDEPNET Development Team.
# @licence https://www.gnu.org/licenses/gpl-3.0.html
#
# ---------------------------------------------------------------------
#
# LICENSE
#
# This file is part of GLPI.
#
# 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 <https://www.gnu.org/licenses/>.
#
# ---------------------------------------------------------------------
#}

{% extends 'generic_show_form.html.twig' %}
{% import 'components/form/fields_macros.html.twig' as fields %}

{% block more_fields %}
{{ fields.textField('host', item.fields['host'], __('Email domain Name (users email will be login@domain)')) }}
{% set connect_opts = call('Toolbox::parseMailServerConnectString', [item.fields['connect_string']]) %}
{{ include('pages/setup/mailcollector/server_config_fields.html.twig', {
'connect_opts': connect_opts,
'host': item.fields['connect_string']
}) }}
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
{% endif %}

{{ fields.textField('server_port', connect_opts['port'], __('Port (optional)')) }}
{{ fields.htmlField('', host, __('Connection string'), {
add_field_class: 'fw-bold'
}) }}
{% if host is not empty %}
{{ fields.htmlField('', host, __('Connection string'), {
add_field_class: 'fw-bold'
}) }}
{% endif %}

0 comments on commit 8b888a6

Please sign in to comment.