diff --git a/debian/control b/debian/control index 7ebef571..9ec3766e 100644 --- a/debian/control +++ b/debian/control @@ -7,7 +7,7 @@ Maintainer: Benjamin Renard 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 diff --git a/doc/mkdocs.yml b/doc/mkdocs.yml index 8aa63272..a3b68d44 100644 --- a/doc/mkdocs.yml +++ b/doc/mkdocs.yml @@ -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 diff --git a/doc/src/conf/LSobject/LSattribute/LSattr_html/LSattr_html_gpg_pub_key.md b/doc/src/conf/LSobject/LSattribute/LSattr_html/LSattr_html_gpg_pub_key.md new file mode 100644 index 00000000..082667b6 --- /dev/null +++ b/doc/src/conf/LSobject/LSattribute/LSattr_html/LSattr_html_gpg_pub_key.md @@ -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. diff --git a/doc/src/conf/LSobject/LSattribute/check_data/gpg_pub_key.md b/doc/src/conf/LSobject/LSattribute/check_data/gpg_pub_key.md new file mode 100644 index 00000000..54c9a52c --- /dev/null +++ b/doc/src/conf/LSobject/LSattribute/check_data/gpg_pub_key.md @@ -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. diff --git a/src/css/default/LSformElement_gpg_pub_key.css b/src/css/default/LSformElement_gpg_pub_key.css new file mode 100644 index 00000000..e6a1233a --- /dev/null +++ b/src/css/default/LSformElement_gpg_pub_key.css @@ -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); + } +} diff --git a/src/includes/class/class.LSattr_html_gpg_pub_key.php b/src/includes/class/class.LSattr_html_gpg_pub_key.php new file mode 100644 index 00000000..eaa5eb7b --- /dev/null +++ b/src/includes/class/class.LSattr_html_gpg_pub_key.php @@ -0,0 +1,32 @@ + + */ +class LSattr_html_gpg_pub_key extends LSattr_html { + + var $LSformElement_type = 'gpg_pub_key'; + +} diff --git a/src/includes/class/class.LSformElement_gpg_pub_key.php b/src/includes/class/class.LSformElement_gpg_pub_key.php new file mode 100644 index 00000000..88695571 --- /dev/null +++ b/src/includes/class/class.LSformElement_gpg_pub_key.php @@ -0,0 +1,110 @@ + + */ + +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.") +); diff --git a/src/includes/class/class.LSformRule_gpg_pub_key.php b/src/includes/class/class.LSformRule_gpg_pub_key.php new file mode 100644 index 00000000..2b64b78a --- /dev/null +++ b/src/includes/class/class.LSformRule_gpg_pub_key.php @@ -0,0 +1,58 @@ + + */ +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.") +); diff --git a/src/includes/js/LSformElement_gpg_pub_key.js b/src/includes/js/LSformElement_gpg_pub_key.js new file mode 100644 index 00000000..22f652bd --- /dev/null +++ b/src/includes/js/LSformElement_gpg_pub_key.js @@ -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(); +}); diff --git a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo index 79ab9d4e..4c3d2f1f 100644 Binary files a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo and b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.mo differ diff --git a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po index 686decfe..c48f2132 100644 --- a/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po +++ b/src/lang/fr_FR.UTF8/LC_MESSAGES/ldapsaisie.po @@ -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 \n" "Language-Team: LdapSaisie \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 "

Mail initialy intended for %s.

" msgstr "

Mail initialement adressé à %s.

" -#: 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 "

%s: %s

" msgstr "

%s: %s

" -#: 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" diff --git a/src/lang/ldapsaisie.pot b/src/lang/ldapsaisie.pot index 996df7ed..1da8c40b 100644 --- a/src/lang/ldapsaisie.pot +++ b/src/lang/ldapsaisie.pot @@ -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 "

Mail initialy intended for %s.

" 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 "

%s: %s

" 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 "" diff --git a/src/templates/default/LSformElement_gpg_pub_key.tpl b/src/templates/default/LSformElement_gpg_pub_key.tpl new file mode 100644 index 00000000..cebea848 --- /dev/null +++ b/src/templates/default/LSformElement_gpg_pub_key.tpl @@ -0,0 +1,7 @@ +
    + {foreach from=$values_txt item=value} +
  • {include file="ls:$fieldTemplate"}
  • + {foreachelse} +
  • {include file="ls:$fieldTemplate"}
  • + {/foreach} +
diff --git a/src/templates/default/LSformElement_gpg_pub_key_field.tpl b/src/templates/default/LSformElement_gpg_pub_key_field.tpl new file mode 100644 index 00000000..2104e676 --- /dev/null +++ b/src/templates/default/LSformElement_gpg_pub_key_field.tpl @@ -0,0 +1,16 @@ +{if $freeze} + {if $value.fingerprint} + {tr msg="Fingerprint:"} + + {$value.fingerprint|escape:"htmlall"} + +

{$value.value|escape:"htmlall"}

+ {elseif $value} + {tr msg="Invalid value"} +

{$value.value|escape:"htmlall"}

+ {else} + {$noValueTxt|escape:"htmlall"} + {/if} +{else} + +{/if} diff --git a/src/tmp/.gitignore b/src/tmp/.gitignore index b00e673f..3fb9bd73 100644 --- a/src/tmp/.gitignore +++ b/src/tmp/.gitignore @@ -1,3 +1,5 @@ *.php *.tmp *.log +*.kbx +*.gpg