Add LSattr_html_gpg_pub_key & LSformRule_gpg_pub_key

This commit is contained in:
Benjamin Renard 2024-02-28 18:14:03 +01:00
parent d26c52400e
commit 171161ae18
Signed by: bn8
GPG key ID: 3E2E1CE1907115BC
15 changed files with 362 additions and 34 deletions

2
debian/control vendored
View file

@ -7,7 +7,7 @@ Maintainer: Benjamin Renard <brenard@easter-eggs.com>
Package: ldapsaisie
Architecture: all
Depends: apache2 | httpd, php-ldap | php5-ldap, php-fpm | libapache2-mod-php5 | libapache2-mod-php | php5-cli | php-cli, smarty | smarty3, php-net-ldap2, php-console-table
Recommends: php-mbstring, php-phpseclib, php-unidecode, php-zxcvbn, php-ftp, php-mail, php-mail-mime, php-html2text
Recommends: php-mbstring, php-phpseclib, php-unidecode, php-zxcvbn, php-ftp, php-mail, php-mail-mime, php-html2text, php-gnupg
Description: web based interface for managing LDAP servers content
LdapSaisie is a Web application developed to manage LDAP directory.
It has been written in PHP / JavaScript and is published under the

View file

@ -97,6 +97,7 @@ nav:
- Introduction: conf/LSobject/LSattribute/LSattr_html/index.md
- boolean: conf/LSobject/LSattribute/LSattr_html/LSattr_html_boolean.md
- date: conf/LSobject/LSattribute/LSattr_html/LSattr_html_date.md
- gpg_pub_key: conf/LSobject/LSattribute/LSattr_html/LSattr_html_gpg_pub_key.md
- image: conf/LSobject/LSattribute/LSattr_html/LSattr_html_image.md
- jsonCompositeAttribute: conf/LSobject/LSattribute/LSattr_html/LSattr_html_jsonCompositeAttribute.md
- labeledValue: conf/LSobject/LSattribute/LSattr_html/LSattr_html_labeledValue.md
@ -127,6 +128,7 @@ nav:
- differentPassword: conf/LSobject/LSattribute/check_data/differentPassword.md
- email: conf/LSobject/LSattribute/check_data/email.md
- filesize: conf/LSobject/LSattribute/check_data/filesize.md
- gpg_pub_key: conf/LSobject/LSattribute/check_data/gpg_pub_key.md
- imagefile: conf/LSobject/LSattribute/check_data/imagefile.md
- imagesize: conf/LSobject/LSattribute/check_data/imagesize.md
- inarray: conf/LSobject/LSattribute/check_data/inarray.md

View file

@ -0,0 +1,4 @@
# LSattr_html_gpg_pub_key
Ce type est utilisé pour la gestion des attributs dont la valeur est une clef publique GPG. Il
permet dans l'interface, d'avoir un affichage adapté à ce type de donnée.

View file

@ -0,0 +1,4 @@
# gpg_pub_key
Cette règle vérifie que la valeur est une clé publique GPG. Pour cela, la clé est importée dans un
_keyring_ GnuPG.

View file

@ -0,0 +1,34 @@
/*
* LSformElement_gpg_pub_key
*/
.LSformElement_gpg_pub_key_value {
display: none;
width: 30em;
font-style: italic;
font-family: courier;
background-color: #b5e4f6;
border: 1px solid #ccc;
overflow: auto;
}
.LSformElement_gpg_pub_key_short_display {
font-style: italic;
font-family: courier;
cursor: pointer;
}
textarea.LSformElement_gpg_pub_key {
height: 10em;
}
@media (max-width: 1024px) {
.LSformElement_gpg_pub_key_value {
width: 40vw;
}
}
@media (max-width: 400px) {
.LSformElement_gpg_pub_key_value {
width: calc(100% - 1em);
}
}

View file

@ -0,0 +1,32 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* https://ldapsaisie.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* HTML attribute type for GPG public key
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSattr_html_gpg_pub_key extends LSattr_html {
var $LSformElement_type = 'gpg_pub_key';
}

View file

@ -0,0 +1,110 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* https://ldapsaisie.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* Form element for GPG public key
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformElement_gpg_pub_key extends LSformElement {
var $template = 'LSformElement_gpg_pub_key.tpl';
var $fieldTemplate = 'LSformElement_gpg_pub_key_field.tpl';
/**
* Parse one value
*
* @param string $value The value to parse
* @param boolean $details Enable/disable details return (optional, default: true)
*
* @return array|string Parsed value as array is $details is enabled, the raw value otherwise
*/
public function parseValue($value, $details=true) {
if (!$details)
return $value;
if (function_exists('gnupg_init')) {
// @phpstan-ignore-next-line
$res = gnupg_init(["home_dir" => LS_TMP_DIR_PATH]);
$info = gnupg_import($res, $value);
}
else {
LSerror :: addErrorCode('LSformElement_gpg_pub_key_01');
$info = false;
}
if (
is_array($info)
// @phpstan-ignore-next-line
&& ($info['imported'] + $info['unchanged']) != 1
)
$info = false;
return array(
'fingerprint' => is_array($info)?$info["fingerprint"]:null,
'value' => $value
);
}
/**
* Retourne les infos d'affichage de l'élément
*
* Cette méthode retourne les informations d'affichage de l'élement
*
* @return array
*/
public function getDisplay(){
LStemplate :: addCssFile('LSformElement_gpg_pub_key.css');
$return = $this -> getLabelInfos();
$params = array();
if (!$this -> isFreeze()) {
$params['values_txt'] = $this -> values;
}
else {
LStemplate :: addJSscript('LSformElement_gpg_pub_key.js');
LStemplate :: addHelpInfo(
'LSformElement_gpg_pub_key',
array(
'display' => _("Display the full key.")
)
);
$values_txt = array();
foreach ($this -> values as $value) {
$parsedValue = $this -> parseValue($value);
$values_txt[] = $parsedValue;
}
$params['values_txt'] = $values_txt;
$params['invalidValueTxt'] = _('Invalid value');
}
$return['html'] = $this -> fetchTemplate(NULL, $params);
return $return;
}
}
/*
* Error Codes
*/
LSerror :: defineError('LSformElement_gpg_pub_key_01',
___("LSformElement_gpg_pub_key: PHP GnuPG extension is missing, can't parse value.")
);

View file

@ -0,0 +1,58 @@
<?php
/*******************************************************************************
* Copyright (C) 2007 Easter-eggs
* https://ldapsaisie.org
*
* Author: See AUTHORS file in top-level directory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/
/**
* LSformRule to check GPG public key
*
* @author Benjamin Renard <brenard@easter-eggs.com>
*/
class LSformRule_gpg_pub_key extends LSformRule {
/**
* Validate SSH public key value
*
* @param string $value The value to validate
* @param array $options Validation options
* @param LSformElement &$formElement The related formElement object
*
* @return boolean true if the value is valide, false if not
*/
public static function validate($value, $options, &$formElement) {
if (!function_exists('gnupg_init')) {
LSerror :: addErrorCode('LSformRule_gpg_pub_key_01');
return false;
}
// @phpstan-ignore-next-line
$res = gnupg_init(["home_dir" => LS_TMP_DIR_PATH]);
$info = gnupg_import($res, $value);
// @phpstan-ignore-next-line
return is_array($info) && ($info['imported'] + $info['unchanged']) == 1 && $info['fingerprint'];
}
}
/*
* Error Codes
*/
LSerror :: defineError('LSformRule_gpg_pub_key_01',
___("LSformRule_gpg_pub_key: PHP GnuPG extension is missing, can't validate value.")
);

View file

@ -0,0 +1,23 @@
var LSformElement_gpg_pub_key = new Class({
initialize: function(){
$$('span.LSformElement_gpg_pub_key_short_display').each(function(span) {
span.addEvent('click',this.onShortDisplayClick.bind(this,span));
varLSdefault.addHelpInfo(span,'LSformElement_gpg_pub_key','display');
}, this);
},
onShortDisplayClick: function(span) {
var p = span.getParent().getFirst('p.LSformElement_gpg_pub_key_value');
if (typeof(p)) {
if (p.getStyle('display')=='none') {
p.setStyle('display','block');
}
else {
p.setStyle('display',' none');
}
}
}
});
window.addEvent(window.ie ? 'load' : 'domready', function() {
varLSformElement_gpg_pub_key = new LSformElement_gpg_pub_key();
});

View file

@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: LdapSaisie\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2024-02-22 15:25+0100\n"
"PO-Revision-Date: 2024-02-28 18:00+0100\n"
"Last-Translator: Benjamin Renard <brenard@easter-eggs.com>\n"
"Language-Team: LdapSaisie <ldapsaisie-users@lists.labs.libre-entreprise."
"org>\n"
@ -269,16 +269,16 @@ msgstr ""
"MAIL : Une erreur est survenue en enregistrant vos modifications sur ce "
"modèle."
#: includes/addons/LSaddons.mail.php:158 includes/addons/LSaddons.mail.php:568
#: includes/addons/LSaddons.mail.php:158 includes/addons/LSaddons.mail.php:573
msgid "Email templates"
msgstr "Modèles de courriels"
#: includes/addons/LSaddons.mail.php:206
#: includes/addons/LSaddons.mail.php:208
#, php-format
msgid "</hr><p><small>Mail initialy intended for %s.</small></p>"
msgstr "</hr><p><small>Mail initialement adressé à %s.</small></p>"
#: includes/addons/LSaddons.mail.php:207
#: includes/addons/LSaddons.mail.php:209
#, php-format
msgid ""
"\n"
@ -291,12 +291,12 @@ msgstr ""
"\n"
"Mail initialement adressé à %s."
#: includes/addons/LSaddons.mail.php:235
#: includes/addons/LSaddons.mail.php:238
#, php-format
msgid "<p><small>%s: %s</small></p>"
msgstr "<p><small>%s: %s</small></p>"
#: includes/addons/LSaddons.mail.php:236
#: includes/addons/LSaddons.mail.php:239
#, php-format
msgid ""
"\n"
@ -305,22 +305,22 @@ msgstr ""
"\n"
"%s: %s"
#: includes/addons/LSaddons.mail.php:458
#: includes/addons/LSaddons.mail.php:463
msgid "An exception occured forging message from email template '%{template}'"
msgstr ""
"Une exception est survenue en générant le message à partir du modèle de "
"courriel '%{template}'"
#: includes/addons/LSaddons.mail.php:498
#: includes/addons/LSaddons.mail.php:503
msgid "Email template: %{name}"
msgstr "Modèle de courriel : %{name}"
#: includes/addons/LSaddons.mail.php:508 includes/addons/LSaddons.mail.php:524
#: includes/addons/LSaddons.mail.php:542
#: includes/addons/LSaddons.mail.php:513 includes/addons/LSaddons.mail.php:529
#: includes/addons/LSaddons.mail.php:547
msgid "Your changes have been saved."
msgstr "Vos modifications ont été enregistrées."
#: includes/addons/LSaddons.mail.php:560
#: includes/addons/LSaddons.mail.php:565
#: includes/addons/LSaddons.showSupportInfo.php:78
#: includes/addons/LSaddons.accesslog.php:248
#: includes/addons/LSaddons.showTechInfo.php:117
@ -813,8 +813,10 @@ msgstr ""
#: includes/class/class.LSformRule.php:89
#: includes/class/class.LSformRule.php:292
#: includes/class/class.LSformElement_gpg_pub_key.php:90
#: includes/class/class.LSattr_html_date.php:47
#: includes/class/class.LSattr_html_select_list.php:63
#: templates/default/LSformElement_gpg_pub_key_field.tpl:9
msgid "Invalid value"
msgstr "Valeur invalide"
@ -1070,6 +1072,7 @@ msgstr ""
"formater la valeur de l'attribut LDAP."
#: includes/class/class.LSformElement_ssh_key.php:83
#: includes/class/class.LSformElement_gpg_pub_key.php:80
msgid "Display the full key."
msgstr "Affichier la clé en entier."
@ -2084,6 +2087,13 @@ msgstr ""
"LSrelation : Des paramètres sont manquants dans l'appel des méthodes de "
"manipulation des relations standards (méthode : %{meth})."
#: includes/class/class.LSformElement_gpg_pub_key.php:103
msgid ""
"LSformElement_gpg_pub_key: PHP GnuPG extension is missing, can't parse value."
msgstr ""
"LSformElement_gpg_pub_key : L'extension PHP GnuPG n'est pas installée, "
"impossible d'analyser la valeur."
#: includes/class/class.LSformRule_password.php:58
msgid "Password is too long (maximum: %{maxLength})."
msgstr "Le mot de passe est trop long (maximum : %{maxLength})."
@ -3286,6 +3296,13 @@ msgstr "Erreur inconnue"
msgid "Unknown error : %{error}"
msgstr "Erreur inconnue : %{error}"
#: includes/class/class.LSformRule_gpg_pub_key.php:55
msgid ""
"LSformRule_gpg_pub_key: PHP GnuPG extension is missing, can't validate value."
msgstr ""
"LSformRule_gpg_pub_key : L'extension PHP GnuPG n'est pas installée, "
"impossible de valider la valeur."
#: includes/class/class.LSsearchEntry.php:213 includes/routes.php:1211
#: includes/routes.php:1305 includes/routes.php:1452
msgid "View"
@ -3643,6 +3660,10 @@ msgstr "Erreurs"
msgid "File"
msgstr "Fichier"
#: templates/default/LSformElement_gpg_pub_key_field.tpl:3
msgid "Fingerprint:"
msgstr "Empreinte :"
#: templates/default/login.tpl:34
msgid "Forgot your password ?"
msgstr "Mot de passe perdu ?"
@ -3727,20 +3748,20 @@ msgstr "Aucun objet importé"
msgid "No value"
msgstr "Aucune valeur"
#: templates/default/email_template.tpl:30
#: templates/default/email_template.tpl:29
msgid ""
"No writable path to save your changes on the HTML message of this template."
msgstr ""
"Aucun emplacement accessible en écriture pour enregistrer vos modifications "
"sur le contenu HTML de ce modèle."
#: templates/default/email_template.tpl:25
#: templates/default/email_template.tpl:24
msgid "No writable path to save your changes on the subject of this template."
msgstr ""
"Aucun emplacement accessible en écriture pour enregistrer vos modifications "
"sur le sujet de ce modèle."
#: templates/default/email_template.tpl:35
#: templates/default/email_template.tpl:34
msgid ""
"No writable path to save your changes on the text message of this template."
msgstr ""
@ -3828,7 +3849,7 @@ msgstr "Résultat"
msgid "Right inherited from all connected users profile"
msgstr "Droit hérité du profile \"Tous les utilisateurs connectés\""
#: templates/default/email_template.tpl:40
#: templates/default/email_template.tpl:39
msgid "Save"
msgstr "Enregistrer"
@ -3837,8 +3858,7 @@ msgid "Show/hide menu"
msgstr "Afficher/cacher le menu"
#: templates/default/email_templates.tpl:8
#: templates/default/email_template.tpl:9
#: templates/default/email_template.tpl:22 templates/default/LSmail.tpl:21
#: templates/default/email_template.tpl:9 templates/default/LSmail.tpl:21
msgid "Subject"
msgstr "Sujet"

View file

@ -205,16 +205,16 @@ msgstr ""
msgid "MAIL: An error occured saving your changes on this template."
msgstr ""
#: includes/addons/LSaddons.mail.php:158 includes/addons/LSaddons.mail.php:568
#: includes/addons/LSaddons.mail.php:158 includes/addons/LSaddons.mail.php:573
msgid "Email templates"
msgstr ""
#: includes/addons/LSaddons.mail.php:206
#: includes/addons/LSaddons.mail.php:208
#, php-format
msgid "</hr><p><small>Mail initialy intended for %s.</small></p>"
msgstr ""
#: includes/addons/LSaddons.mail.php:207
#: includes/addons/LSaddons.mail.php:209
#, php-format
msgid ""
"\n"
@ -223,32 +223,32 @@ msgid ""
"Mail initialy intended for %s."
msgstr ""
#: includes/addons/LSaddons.mail.php:235
#: includes/addons/LSaddons.mail.php:238
#, php-format
msgid "<p><small>%s: %s</small></p>"
msgstr ""
#: includes/addons/LSaddons.mail.php:236
#: includes/addons/LSaddons.mail.php:239
#, php-format
msgid ""
"\n"
"%s: %s"
msgstr ""
#: includes/addons/LSaddons.mail.php:458
#: includes/addons/LSaddons.mail.php:463
msgid "An exception occured forging message from email template '%{template}'"
msgstr ""
#: includes/addons/LSaddons.mail.php:498
#: includes/addons/LSaddons.mail.php:503
msgid "Email template: %{name}"
msgstr ""
#: includes/addons/LSaddons.mail.php:508 includes/addons/LSaddons.mail.php:524
#: includes/addons/LSaddons.mail.php:542
#: includes/addons/LSaddons.mail.php:513 includes/addons/LSaddons.mail.php:529
#: includes/addons/LSaddons.mail.php:547
msgid "Your changes have been saved."
msgstr ""
#: includes/addons/LSaddons.mail.php:560
#: includes/addons/LSaddons.mail.php:565
#: includes/addons/LSaddons.showSupportInfo.php:78
#: includes/addons/LSaddons.accesslog.php:248
#: includes/addons/LSaddons.showTechInfo.php:117
@ -688,8 +688,10 @@ msgstr ""
#: includes/class/class.LSformRule.php:89
#: includes/class/class.LSformRule.php:292
#: includes/class/class.LSformElement_gpg_pub_key.php:90
#: includes/class/class.LSattr_html_date.php:47
#: includes/class/class.LSattr_html_select_list.php:63
#: templates/default/LSformElement_gpg_pub_key_field.tpl:9
msgid "Invalid value"
msgstr ""
@ -919,6 +921,7 @@ msgid ""
msgstr ""
#: includes/class/class.LSformElement_ssh_key.php:83
#: includes/class/class.LSformElement_gpg_pub_key.php:80
msgid "Display the full key."
msgstr ""
@ -1745,6 +1748,11 @@ msgid ""
"standard relations (Method : %{meth})."
msgstr ""
#: includes/class/class.LSformElement_gpg_pub_key.php:103
msgid ""
"LSformElement_gpg_pub_key: PHP GnuPG extension is missing, can't parse value."
msgstr ""
#: includes/class/class.LSformRule_password.php:58
msgid "Password is too long (maximum: %{maxLength})."
msgstr ""
@ -2793,6 +2801,11 @@ msgstr ""
msgid "Unknown error : %{error}"
msgstr ""
#: includes/class/class.LSformRule_gpg_pub_key.php:55
msgid ""
"LSformRule_gpg_pub_key: PHP GnuPG extension is missing, can't validate value."
msgstr ""
#: includes/class/class.LSsearchEntry.php:213 includes/routes.php:1211
#: includes/routes.php:1305 includes/routes.php:1452
msgid "View"
@ -3128,6 +3141,10 @@ msgstr ""
msgid "File"
msgstr ""
#: templates/default/LSformElement_gpg_pub_key_field.tpl:3
msgid "Fingerprint:"
msgstr ""
#: templates/default/login.tpl:34
msgid "Forgot your password ?"
msgstr ""
@ -3212,16 +3229,16 @@ msgstr ""
msgid "No value"
msgstr ""
#: templates/default/email_template.tpl:30
#: templates/default/email_template.tpl:29
msgid ""
"No writable path to save your changes on the HTML message of this template."
msgstr ""
#: templates/default/email_template.tpl:25
#: templates/default/email_template.tpl:24
msgid "No writable path to save your changes on the subject of this template."
msgstr ""
#: templates/default/email_template.tpl:35
#: templates/default/email_template.tpl:34
msgid ""
"No writable path to save your changes on the text message of this template."
msgstr ""
@ -3307,7 +3324,7 @@ msgstr ""
msgid "Right inherited from all connected users profile"
msgstr ""
#: templates/default/email_template.tpl:40
#: templates/default/email_template.tpl:39
msgid "Save"
msgstr ""
@ -3316,8 +3333,7 @@ msgid "Show/hide menu"
msgstr ""
#: templates/default/email_templates.tpl:8
#: templates/default/email_template.tpl:9
#: templates/default/email_template.tpl:22 templates/default/LSmail.tpl:21
#: templates/default/email_template.tpl:9 templates/default/LSmail.tpl:21
msgid "Subject"
msgstr ""

View file

@ -0,0 +1,7 @@
<ul class='LSform{if $multiple && !$freeze} LSformElement_multiple'{/if}' id='{$attr_name|escape:"quotes"}'>
{foreach from=$values_txt item=value}
<li>{include file="ls:$fieldTemplate"}</li>
{foreachelse}
<li>{include file="ls:$fieldTemplate"}</li>
{/foreach}
</ul>

View file

@ -0,0 +1,16 @@
{if $freeze}
{if $value.fingerprint}
{tr msg="Fingerprint:"}
<span class='LSformElement_gpg_pub_key_short_display' title='{$span_title|escape:"htmlall"}'>
{$value.fingerprint|escape:"htmlall"}
</span>
<p class='LSformElement_gpg_pub_key_value'>{$value.value|escape:"htmlall"}</p>
{elseif $value}
<span class='LSformElement_gpg_pub_key_short_display'>{tr msg="Invalid value"}</span>
<p class='LSformElement_gpg_pub_key_value'>{$value.value|escape:"htmlall"}</p>
{else}
{$noValueTxt|escape:"htmlall"}
{/if}
{else}
<textarea name='{$attr_name|escape:"quotes"}[]' class='LSform LSformElement_gpg_pub_key'>{$value|escape:"htmlall"}</textarea>
{/if}

2
src/tmp/.gitignore vendored
View file

@ -1,3 +1,5 @@
*.php
*.tmp
*.log
*.kbx
*.gpg