|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +define('PMA_SSL_DIR', $_ENV['PMA_SSL_DIR'] ?? '/etc/phpmyadmin/ssl'); |
| 5 | + |
| 6 | +/** |
| 7 | + * Helper function to decode and save multiple SSL files from base64. |
| 8 | + * |
| 9 | + * @param string $base64_string The base64 encoded string containing multiple SSL files separated by commas. |
| 10 | + * If no commas are present, the entire string is treated as a single file. |
| 11 | + * @param string $prefix The prefix to use for the generated SSL file names. |
| 12 | + * @param string $extension The file extension to use for the generated SSL files. |
| 13 | + * @return string A comma-separated list of paths to the generated SSL files. |
| 14 | + */ |
| 15 | +function decodeAndSaveSslFiles(string $base64_string, string $prefix, string $extension): array { |
| 16 | + // Ensure the output directory exists |
| 17 | + if (!is_dir(PMA_SSL_DIR)) { |
| 18 | + mkdir(PMA_SSL_DIR, 0755, true); |
| 19 | + } |
| 20 | + |
| 21 | + // Split the base64 string into an array of files |
| 22 | + $files = strpos($base64_string, ',') !== false ? explode(',', $base64_string) : [$base64_string]; |
| 23 | + $counter = 1; |
| 24 | + $ssl_files = []; |
| 25 | + |
| 26 | + // Process each file |
| 27 | + foreach ($files as $file) { |
| 28 | + $output_file = PMA_SSL_DIR . "/pma-ssl-$prefix-$counter.$extension"; |
| 29 | + |
| 30 | + // Write the decoded file to the output directory |
| 31 | + if (file_put_contents($output_file, base64_decode($file)) === false) { |
| 32 | + echo 'Failed to write to ' . $output_file; |
| 33 | + exit(1); |
| 34 | + } |
| 35 | + |
| 36 | + // Add the output file path to the list |
| 37 | + $ssl_files[] = $output_file; |
| 38 | + $counter++; |
| 39 | + } |
| 40 | + |
| 41 | + // Return a comma-separated list of the generated file paths |
| 42 | + return implode(',', $ssl_files); |
| 43 | +} |
0 commit comments