From 529303f22cbd326ae2397272eb8d0ee6d87e0e88 Mon Sep 17 00:00:00 2001 From: Brian Lycett Date: Mon, 11 Apr 2022 15:40:15 +0100 Subject: [PATCH] Functionality to upload binary files and display them in the form it's a JPEG. Added a new page to download existing binary content. --- README.md | 4 +- www/account_manager/download.php | 41 ++++++++ www/account_manager/new_user.php | 42 +++++--- www/account_manager/show_group.php | 21 +++- www/account_manager/show_user.php | 18 +++- www/includes/ldap_functions.inc.php | 11 +-- www/includes/web_functions.inc.php | 147 ++++++++++++++++++---------- 7 files changed, 200 insertions(+), 84 deletions(-) create mode 100644 www/account_manager/download.php diff --git a/README.md b/README.md index 13d7fba..2689181 100644 --- a/README.md +++ b/README.md @@ -344,11 +344,13 @@ LDAP_ACCOUNT_ADDITIONAL_ATTRIBUTES=mailAlias+:Email aliases" ### Binary attributes -If you have an attribute that stores the contents of a binary file (for example, a JPEG) then you can add a `^` to the end of the attribute name. This will modify the form so that this attribute has an upload button. If a file has already been uploaded then a link to view or download the file will be shown. For example, to allow you to set a user's photo: +If you have an attribute that stores the contents of a binary file (for example, a JPEG) then you can add a `^` to the end of the attribute name. This will modify the form so that this attribute has an upload button. If a JPEG has already been uploaded then it will display the image. Otherwise the mime-type is displayed and there's a link for downloading the file. For example, to allow you to set a user's photo: ``` LDAP_ACCOUNT_ADDITIONAL_ATTRIBUTES=jpegPhoto^:Photograph" ``` +The maximum filesize you can upload is 2MB. + ### Caveat diff --git a/www/account_manager/download.php b/www/account_manager/download.php new file mode 100644 index 0000000..04734b4 --- /dev/null +++ b/www/account_manager/download.php @@ -0,0 +1,41 @@ + diff --git a/www/account_manager/new_user.php b/www/account_manager/new_user.php index 545dcb8..6ea5502 100644 --- a/www/account_manager/new_user.php +++ b/www/account_manager/new_user.php @@ -13,26 +13,27 @@ if (! array_key_exists($LDAP['account_attribute'], $attribute_map)) { } if ( isset($_POST['setup_admin_account']) ) { - $admin_setup = TRUE; - validate_setup_cookie(); - set_page_access("setup"); + $admin_setup = TRUE; - $completed_action="${SERVER_PATH}log_in"; - $page_title="New administrator account"; + validate_setup_cookie(); + set_page_access("setup"); - render_header("$ORGANISATION_NAME account manager - setup administrator account", FALSE); + $completed_action="${SERVER_PATH}log_in"; + $page_title="New administrator account"; + + render_header("$ORGANISATION_NAME account manager - setup administrator account", FALSE); } else { - set_page_access("admin"); + set_page_access("admin"); - $completed_action="${THIS_MODULE_PATH}/"; - $page_title="New account"; - $admin_setup = FALSE; + $completed_action="${THIS_MODULE_PATH}/"; + $page_title="New account"; + $admin_setup = FALSE; - render_header("$ORGANISATION_NAME account manager"); - render_submenu(); + render_header("$ORGANISATION_NAME account manager"); + render_submenu(); } $invalid_password = FALSE; @@ -49,6 +50,17 @@ $new_account_r = array(); foreach ($attribute_map as $attribute => $attr_r) { + if (isset($_FILES[$attribute]['size']) and $_FILES[$attribute]['size'] > 0) { + + $this_attribute = array(); + $this_attribute['count'] = 1; + $this_attribute[0] = file_get_contents($_FILES[$attribute]['tmp_name']); + $$attribute = $this_attribute; + $new_account_r[$attribute] = $this_attribute; + unset($new_account_r[$attribute]['count']); + + } + if (isset($_POST[$attribute])) { $this_attribute = array(); @@ -323,7 +335,7 @@ $tabindex=1;
-
+ @@ -335,8 +347,8 @@ $tabindex=1; if (isset($attr_r['onkeyup'])) { $onkeyup = $attr_r['onkeyup']; } else { $onkeyup = ""; } if ($attribute == $LDAP['account_attribute']) { $label = "$label*"; } if (isset($$attribute)) { $these_values=$$attribute; } else { $these_values = array(); } - if (isset($attr_r['multiple'])) { $multiple = $attr_r['multiple']; } else { $multiple = FALSE; } - render_attribute_fields($attribute,$label,$these_values,$onkeyup,$multiple,$tabindex); + if (isset($attr_r['inputtype'])) { $inputtype = $attr_r['inputtype']; } else { $inputtype = ""; } + render_attribute_fields($attribute,$label,$these_values,"",$onkeyup,$inputtype,$tabindex); $tabindex++; } ?> diff --git a/www/account_manager/show_group.php b/www/account_manager/show_group.php index 586a042..3bf63d1 100644 --- a/www/account_manager/show_group.php +++ b/www/account_manager/show_group.php @@ -40,6 +40,8 @@ if ($ENFORCE_SAFE_SYSTEM_NAMES == TRUE and !preg_match("/$USERNAME_REGEX/",$grou ###################################################################################### $initialise_group = FALSE; +$create_group_message = "Add members to create the new group"; + $attribute_map = $LDAP['default_group_attribute_map']; if (isset($LDAP['group_additional_attributes'])) { $attribute_map = ldap_complete_attribute_array($attribute_map,$LDAP['group_additional_attributes']); @@ -51,7 +53,7 @@ $this_group = array(); if (isset($_POST['new_group'])) { $new_group = TRUE; $current_members = array(); - $full_dn = "Add members to create the new group"; + $full_dn = $create_group_message; $has_been = ""; } elseif (isset($_POST['initialise_group'])) { @@ -78,6 +80,17 @@ foreach ($attribute_map as $attribute => $attr_r) { $$attribute = array(); } + if (isset($_FILES[$attribute]['size']) and $_FILES[$attribute]['size'] > 0) { + + $this_attribute = array(); + $this_attribute['count'] = 1; + $this_attribute[0] = file_get_contents($_FILES[$attribute]['tmp_name']); + $$attribute = $this_attribute; + $to_update[$attribute] = $this_attribute; + unset($to_update[$attribute]['count']); + + } + if (isset($_POST[$attribute])) { $this_attribute = array(); @@ -305,7 +318,7 @@ ldap_close($ldap_connection);

(admin group)" ; } ?>

- /groups.php" method="post"> +
/groups.php" method="post" enctype="multipart/form-data">