added directory index needed for porteus config to boot master
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 19 Nov 2021 11:10:02 +0000 (12:10 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 19 Nov 2021 11:10:02 +0000 (12:10 +0100)
lib/PXElator/httpd.pm

index 6f72a5a..a59124d 100644 (file)
@@ -92,6 +92,26 @@ sub static {
 
        my $full = "$server::base_dir/tftp/$path";
 
+       if ( $path ne '/' && -d $full ) {
+
+               # redirect directory to end with /
+               if ( $path !~ m{/$} ) {
+                       print $client "HTTP/1.0 301 Moved Permanently\r\nLocation: $path/\r\n\r\n";
+                       close($client);
+                       return 1;
+               }
+
+               # display directory index
+               print $client "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nConnection: close\r\n\r\n";
+               print $client qq{<ul>\n};
+               foreach my $path ( map { s{$full/}{}; $_ } glob "$full/*" ) {
+                       print $client qq{<li><a href="$path">$path</a></li>\n};
+               }
+               print $client qq{</ul>\n};
+               close($client);
+               return 1;
+       }
+
        return if ! -f $full;
 
        return if $full =~ m{\.ico$};