leonam-carlos

Laragon - index.php personalized

Mar 6th, 2021
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.68 KB | None | 0 0
  1. <?php
  2.  
  3. # Directory Index (dirindex.php)
  4. #
  5. # Reads the current directory's content and displays it as
  6. # HTML.  Useful if file listing is denied by the web server
  7. # configuration.
  8. #
  9. # Installation:
  10. # - Put in any directory you like on your PHP-capable webspace.
  11. # - Rename to 'index.php' if you like it to get called if no
  12. #   file is specified in the URL (e.g. www.example.com/files/).
  13. # - Fit the design to your needs just using HTML and CSS.
  14. #
  15. # Changes since original release (25-Mar-2002):
  16. # - simplified and modernized markup and styles (HTML5, CSS3,
  17. #   list instead of table)
  18. # - more functional programming approach
  19. # - improved configurability
  20. # - escaping of HTML characters
  21. # - license changed from GPL to MIT
  22. # - requires PHP 5.3.0 or later
  23. #
  24. # Version: 25-May-2011
  25. # Copyright (c) 2002, 2011 Jochen Kupperschmidt <http://homework.nwsnet.de/>
  26. # Released under the terms of the MIT license
  27. # <http://www.opensource.org/licenses/mit-license.php>
  28.  
  29.  
  30. ### configuration
  31.  
  32. # Show the local path. Disable this for security reasons.
  33. define('SHOW_PATH', TRUE);
  34.  
  35. # Show a link to the parent directory ('..').
  36. define('SHOW_PARENT_LINK', TRUE);
  37.  
  38. # Show "hidden" directories and files, i.e. those whose names
  39. # start with a dot.
  40. define('SHOW_HIDDEN_ENTRIES', FALSE);
  41.  
  42. ### /configuration
  43.  
  44.  
  45. function get_grouped_entries($path) {
  46.     list($dirs, $files) = collect_directories_and_files($path);
  47.     $dirs = filter_directories($dirs);
  48.     $files = filter_files($files);
  49.     return array_merge(
  50.         array_fill_keys($dirs, TRUE),
  51.         array_fill_keys($files, FALSE));
  52. }
  53.  
  54. function collect_directories_and_files($path) {
  55.     # Retrieve directories and files inside the given path.
  56.    # Also, `scandir()` already sorts the directory entries.
  57.    $entries = scandir($path);
  58.     return array_partition($entries, function($entry) {
  59.         return is_dir($entry);
  60.     });
  61. }
  62.  
  63. function array_partition($array, $predicate_callback) {
  64.     # Partition elements of an array into two arrays according
  65.    # to the boolean result from evaluating the predicate.
  66.    $results = array_fill_keys(array(1, 0), array());
  67.     foreach ($array as $element) {
  68.         array_push(
  69.             $results[(int) $predicate_callback($element)],
  70.             $element);
  71.     }
  72.     return array($results[1], $results[0]);
  73. }
  74.  
  75. function filter_directories($dirs) {
  76.     # Exclude directories. Adjust as necessary.
  77.    return array_filter($dirs, function($dir) {
  78.         return $dir != '.'  # current directory
  79.            && (SHOW_PARENT_LINK || $dir != '..') # parent directory
  80.            && !is_hidden($dir);
  81.     });
  82. }
  83.  
  84. function filter_files($files) {
  85.     # Exclude files. Adjust as necessary.
  86.    return array_filter($files, function($file) {
  87.         return !is_hidden($file)
  88.             && substr($file, -4) != '.php'
  89.             && substr($file, -3) != '.7z';  # PHP scripts
  90.    });
  91. }
  92.  
  93. function is_hidden($entry) {
  94.     return !SHOW_HIDDEN_ENTRIES
  95.         && substr($entry, 0, 1) == '.'  # Name starts with a dot.
  96.        && $entry != '.'  # Ignore current directory.
  97.        && $entry != '..';  # Ignore parent directory.
  98. }
  99.  
  100. $path = __DIR__ . '/';
  101. $entries = get_grouped_entries($path);
  102.  
  103.  
  104.   if (!empty($_GET['q'])) {
  105.     switch ($_GET['q']) {
  106.       case 'info':
  107.         phpinfo();
  108.         exit;
  109.       break;
  110.     }
  111.   }
  112. ?>
  113. <!DOCTYPE html>
  114. <html>
  115.  
  116. <head>
  117.     <title>Laragon</title>
  118.     <link href="https://fonts.googleapis.com/css?family=Karla:400" rel="stylesheet" type="text/css">
  119.     <style>
  120.         html,
  121.         body {
  122.             height: 100%;
  123.         }
  124.  
  125.         body {
  126.             margin: 0;
  127.             padding: 0;
  128.             width: 100%;
  129.             display: table;
  130.             font-weight: 100;
  131.             font-family: 'Karla';
  132.         }
  133.  
  134.         .container {
  135.             text-align: center;
  136.             display: table-cell;
  137.             vertical-align: middle;
  138.         }
  139.  
  140.         .content {
  141.             text-align: center;
  142.             display: inline-block;
  143.         }
  144.  
  145.         .title {
  146.             font-size: 96px;
  147.         }
  148.  
  149.         .opt {
  150.             margin-top: 30px;
  151.         }
  152.  
  153.         .opt a {
  154.             text-decoration: none;
  155.             font-size: 150%;
  156.         }
  157.  
  158.         a:hover {
  159.             color: red;
  160.         }
  161.     </style>
  162.     <style>
  163.         body {
  164.             background-color: #eeeeee;
  165.             font-family: Verdana, Arial, sans-serif;
  166.             font-size: 90%;
  167.             margin: 4em 0;
  168.         }
  169.  
  170.         article,
  171.         footer {
  172.             display: block;
  173.             margin: 0 auto;
  174.             width: 480px;
  175.         }
  176.  
  177.         a {
  178.             color: #004466;
  179.             text-decoration: none;
  180.         }
  181.  
  182.         a:hover {
  183.             text-decoration: underline;
  184.         }
  185.  
  186.         a:visited {
  187.             color: #666666;
  188.         }
  189.  
  190.         article {
  191.             background-color: #ffffff;
  192.             border: #cccccc solid 1px;
  193.             -moz-border-radius: 11px;
  194.             -webkit-border-radius: 11px;
  195.             border-radius: 11px;
  196.             padding: 0 1em;
  197.         }
  198.  
  199.         h1 {
  200.             font-size: 140%;
  201.         }
  202.  
  203.         ol {
  204.             line-height: 1.4em;
  205.             list-style-type: disc;
  206.         }
  207.  
  208.         li.directory a:before {
  209.             content: '[ ';
  210.         }
  211.  
  212.         li.directory a:after {
  213.             content: ' ]';
  214.         }
  215.  
  216.         footer {
  217.             font-size: 70%;
  218.             text-align: center;
  219.         }
  220.     </style>
  221. </head>
  222.  
  223. <body>
  224.     <div class="container">
  225.         <div class="content">
  226.             <div class="title" title="Laragon">Laragon</div>
  227.             <div class="info"><br />
  228.                 <?php print($_SERVER['SERVER_SOFTWARE']); ?><br />
  229.                 PHP version: <?php print phpversion(); ?> <span><a title="phpinfo()" href="/?q=info">info</a></span><br />
  230.                 Document Root: <?php print ($_SERVER['DOCUMENT_ROOT']); ?><br />
  231.             </div>
  232.             <div class="opt">
  233.                 <div><a title="Getting Started" href="https://laragon.org/docs">Getting Started</a></div>
  234.             </div>
  235.         </div>
  236.     </div>
  237.     <div>
  238.         <article>
  239.             <h1>Content of <?php echo SHOW_PATH ? '<em>' . $path . '</em>' : 'this directory'; ?></h1>
  240.             <ol>
  241.                 <?php
  242.             foreach ($entries as $entry => $is_dir) {
  243.               $class_name = $is_dir ? 'directory' : 'file';
  244.               $escaped_entry = htmlspecialchars($entry);
  245.               printf('        <li class="%s"><a href="%s">%s</a></li>' . "\n",
  246.                 $class_name, $escaped_entry, $escaped_entry);
  247.             }
  248.           ?>
  249.             </ol>
  250.         </article>
  251.     </div>
  252. </body>
  253.  
  254. </html>
Advertisement
Add Comment
Please, Sign In to add comment