.htaccess AddDescription in Abyss Webserver

 
Post new topic   Reply to topic    Aprelium Forum Index -> General Questions
View previous topic :: View next topic  
Author Message
tfh
-


Joined: 03 May 2020
Posts: 112
Location: Netherlands

PostPosted: Wed Feb 03, 2021 1:42 pm    Post subject: .htaccess AddDescription in Abyss Webserver Reply with quote

I've already asked this @Aprelium priority support, but since after 2 months there still is no answer, I've decided to ask it here.

I have a special sub-domain which can be used for MSX computers to connect to. To supply information about the files which get requested, in each directory I have an .htaccess file with contents like this:

AddDescription "A B C - Al Alamiah (1989) Arabic Computers Only" ABC-ArabicComputersOnly.rom
AddDescription "A B C - Al Alamiah (1989) Arabic Computers Only" ABC-ArabicComputersOnly-a1.rom
AddDescription "A Life M36 Planet - Pixel (1987) Bug Fix and New Font / Translated into English" ALifeM36Planet-BugFixandNewFontTranslatedintoEnglish{4}.rom
AddDescription "A Life M36 Planet - Pixel (1987) Bug Fix / Translated into English" ALifeM36Planet-BugFixTranslatedintoEnglish{4}.rom
AddDescription "A Life M36 Planet - Pixel (1987) No Bug Fix / Translated into English" ALifeM36Planet-NoBugFixTranslatedintoEnglish{4}.rom
AddDescription "A Life M36 Planet - Pixel (1987)" ALifeM36Planet{4}.rom
AddDescription "A.E. - Programmers 3 (1983)" AE.rom

In the end, the contents of each directory must be presentend as a Fancy Listing from Apache with the added info, so it will look like this:



The resulting code should look like this:



Does anyone have an idea on how to accomplish this?
_________________
https://www.arnauddeklerk.com
https://www.file-hunter.com
Back to top View user's profile Send private message Visit poster's website
tfh
-


Joined: 03 May 2020
Posts: 112
Location: Netherlands

PostPosted: Sun Feb 07, 2021 8:12 pm    Post subject: Reply with quote

In the meantime the support team of Aprelium has supplied me with a great working script, tailored to my needs:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
  <HEAD>
   <TITLE>Index of <?php echo $_POST['path']; ?></TITLE>
  </HEAD>
<BODY>
<h2>msx.file-hunter.com Gr8net Server</h2>
<pre><a href="#">Name</a>                    <a href="#">Last modified</a>     <a href="#">Size</a>  <a href="#">Description</a><hr>
<?php
         function format_size($a) {
             $unit = array("B","K","M","G","T");
             $c = 0;
            
             while (($a>=1024) && ($c < (count($unit)-2))) {
                 $c++;
                 $a = (int)($a / 1024);
             }
            
            if (($a > 999) && ($c < (count($unit)-2))) {
               $c++;
               $a = (int)($a / 1024) + 1;
            }
            
             return $a . $unit[min($c, count($unit)-1)];
         }
         
         function format_to_width($s, $w) {
            if (strlen($s) > $w)
               return substr($s, 0, $w - 1) . "";
            else
               return $s;
         }
         
         $r = @file($_SERVER["REDIRECT_SCRIPT_FILENAME"] . ".htaccess");
         
         $t = array();
         
          if ($r) {
            foreach ($r as $k) {
               $k = str_getcsv(
                  $k, # Input line
                  ' ',   # Delimiter
                  '"\'',   # Enclosure
                  '\\'   # Escape char
               );
               if (($k[0] == "AddDescription") && (count($k) > 2)) {
                  for ($i = 2; $i < count($k); $i++) {
                     $pattern = (strpos($k[$i], '/') === false ? "*" : "*/" ) . $k[$i] ;
                     $t[$pattern] = $k[1];
                  }
               }
            };
         }

           /* Split and get the lines */
           $lines = explode("\n", $_POST['files']);
   
           /* For each line do... */
           foreach ($lines as $line)
           {
             /* Split the line and get the file information */
             list($name, $url, $size, $date, $mimetype) = explode("\t", $line);

             if ($mimetype == "")
               $mimetype = "Directory";

             if ($name == "../") {
            $name = "Parent Directory";
            $date = str_repeat(" ", 19);
            $size = "-";
         }
         else
            $size = format_size($size);
               
             $description = "";
             
             foreach ($t as $p => $d) {
             if (fnmatch($p, $name)) {
               $description = $d;
               break;
            }
          }

          $name = format_to_width($name,23);
   
             echo "<A HREF=\"$url\">" . htmlentities($name) .
                       "</A>" . str_repeat(" ", 24 - strlen($name))  . substr($date, 0, -3) . "  " . str_pad($size, 4, " ", STR_PAD_LEFT) . "  " . htmlentities(format_to_width($description, 64)) . chr(10);
           }
        ?>
<hr></pre></BODY></HTML>

Everyones need may differ, but I thought I'd post it here for others to use as well.

Thanks to the Aprelium team for their support.
_________________
https://www.arnauddeklerk.com
https://www.file-hunter.com
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> General Questions All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group