* @author Brady Miller * @copyright Copyright (c) 2010-2016 Rod Roark * @copyright Copyright (c) 2018 Brady Miller * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3 */ require_once('../globals.php'); use OpenEMR\Common\Acl\AclMain; use OpenEMR\Common\Csrf\CsrfUtils; use OpenEMR\Common\Twig\TwigContainer; use OpenEMR\Core\Header; if (!AclMain::aclCheckCore('admin', 'super')) { echo (new TwigContainer(null, $GLOBALS['kernel']))->getTwig()->render('core/unauthorized.html.twig', ['pageTitle' => xl("File management")]); exit; } $imagedir = "$OE_SITE_DIR/images"; $educationdir = "$OE_SITE_DIR/documents/education"; if (!empty($_POST['bn_save'])) { //verify csrf if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) { CsrfUtils::csrfNotVerified(); } /** This is a feature that allows editing of configuration files. Uncomment this at your own risk, since it is considered a critical security vulnerability if OpenEMR is not configured correctly. // Prepare array of names of editable files, relative to the site directory. $my_files = array( 'config.php', 'faxcover.txt', 'faxtitle.eps', 'referral_template.html', 'statement.inc.php', 'letter_templates/custom_pdf.php', ); // Append LBF plugin filenames to the array. $lres = sqlStatement('SELECT grp_form_id FROM layout_group_properties ' . "WHERE grp_form_id LIKE 'LBF%' AND grp_group_id = '' AND grp_activity = 1 ORDER BY grp_seq, grp_title"); while ($lrow = sqlFetchArray($lres)) { $option_id = $lrow['grp_form_id']; // should start with LBF $my_files[] = "LBF/$option_id.plugin.php"; } $form_filename = $_REQUEST['form_filename']; // Sanity check to prevent evildoing. if (!in_array($form_filename, $my_files)) { $form_filename = ''; } $filepath = "$OE_SITE_DIR/$form_filename"; if ($form_filename) { // Textareas, at least in Firefox, return a \r\n at the end of each line // even though only \n was originally there. For consistency with // normal OpenEMR usage we translate those back. file_put_contents($filepath, str_replace( "\r\n", "\n", $_POST['form_filedata'] )); $form_filename = ''; } */ // Handle image uploads. if (is_uploaded_file($_FILES['form_image']['tmp_name']) && $_FILES['form_image']['size']) { $form_dest_filename = $_POST['form_dest_filename']; if ($form_dest_filename == '') { $form_dest_filename = $_FILES['form_image']['name']; } $form_dest_filename = basename($form_dest_filename); if ($form_dest_filename == '') { die(xlt('Cannot find a destination filename')); } $path_parts = pathinfo($form_dest_filename); if (!in_array(strtolower($path_parts['extension']), array('gif','jpg','jpe','jpeg','png','svg'))) { die(xlt('Only images files are accepted')); } $imagepath = "$imagedir/$form_dest_filename"; // If the site's image directory does not yet exist, create it. if (!is_dir($imagedir)) { mkdir($imagedir); } if (is_file($imagepath)) { unlink($imagepath); } $tmp_name = $_FILES['form_image']['tmp_name']; if (!move_uploaded_file($_FILES['form_image']['tmp_name'], $imagepath)) { die(xlt('Unable to create') . " '" . text($imagepath) . "'"); } } // Handle PDF uploads for patient education. if (is_uploaded_file($_FILES['form_education']['tmp_name']) && $_FILES['form_education']['size']) { $form_dest_filename = $_FILES['form_education']['name']; $form_dest_filename = strtolower(basename($form_dest_filename)); if (substr($form_dest_filename, -4) != '.pdf') { die(xlt('Filename must end with ".pdf"')); } $educationpath = "$educationdir/$form_dest_filename"; // If the site's education directory does not yet exist, create it. if (!is_dir($educationdir)) { mkdir($educationdir); } if (is_file($educationpath)) { unlink($educationpath); } $tmp_name = $_FILES['form_education']['tmp_name']; if (!move_uploaded_file($tmp_name, $educationpath)) { die(text(xl('Unable to create') . " '$educationpath'")); } } } /** * Thumbnails generator * generating thumbnail image to all images files from documents table */ if (isset($_POST['generate_thumbnails'])) { //verify csrf if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) { CsrfUtils::csrfNotVerified(); } $thumb_generator = new ThumbnailGenerator(); $results = $thumb_generator->generate_all(); $thumbnail_msg = "

" . xlt('Generated thumbnail(s)') . " : " . text($results['sum_success']) . "

"; $thumbnail_msg .= "

" . xlt('Failed to generate') . " : " . text($results['sum_failed']) . "

"; foreach ($results['failed'] as $key => $file) { $num = $key + 1; $thumbnail_msg .= "

" . text($num) . ". " . text($file) . "

"; } } else { $count_not_generated = ThumbnailGenerator::count_not_generated(); $thumbnail_msg = "

" . xlt('Files with empty thumbnail') . ": " . text($count_not_generated) . "

"; } /** * White list files. * Security feature that enable to upload only file with mime-type from white list. * Important to prevention upload of virus script. * Dependence - turn on global setting 'secure_upload' */ if ($GLOBALS['secure_upload']) { $mime_types = array('image/*', 'text/*', 'audio/*', 'video/*'); // Get cURL resource $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => 'https://cdn.rawgit.com/jshttp/mime-db/master/db.json', CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_TIMEOUT => 5 )); // Send the request & save response to $resp $resp = curl_exec($curl); $httpinfo = curl_getinfo($curl); if ($resp && $httpinfo['http_code'] == 200 && $httpinfo['content_type'] == 'application/json;charset=utf-8') { $all_mime_types = json_decode($resp, true); foreach ($all_mime_types as $name => $value) { $mime_types[] = $name; } } else { error_log('Get list of mime-type error: "' . errorLogEscape(curl_error($curl)) . '" - Code: ' . errorLogEscape(curl_errno($curl))); $mime_types_list = array( 'application/pdf', 'image/jpeg', 'image/png', 'image/gif', 'application/msword', 'application/vnd.oasis.opendocument.spreadsheet', 'text/plain' ); $mime_types = array_merge($mime_types, $mime_types_list); } curl_close($curl); if (isset($_POST['submit_form'])) { //verify csrf if (!CsrfUtils::verifyCsrfToken($_POST["csrf_token_form"])) { CsrfUtils::csrfNotVerified(); } $new_white_list = empty($_POST['white_list']) ? array() : $_POST['white_list']; // truncate white list from list_options table sqlStatement("DELETE FROM `list_options` WHERE `list_id` = 'files_white_list'"); foreach ($new_white_list as $mimetype) { sqlStatement("INSERT INTO `list_options` (`list_id`, `option_id`, `title`, `activity`) VALUES ('files_white_list', ?, ?, 1)", array($mimetype, $mimetype)); } $white_list = $new_white_list; } else { $white_list = array(); $lres = sqlStatement("SELECT option_id FROM list_options WHERE list_id = 'files_white_list' AND activity = 1"); while ($lrow = sqlFetchArray($lres)) { $white_list[] = $lrow['option_id']; } } } ?> <?php echo xlt('File management'); ?>

:   :
:  
' />