#!/hmt/sirius1/prv0/kd/fdc/bin.linux/wermit + # # Kermit script to make pages that are like the file lists you # get when you follow an FTP link to a directory, where you can click # on individual files to see or download them. FTP was "deprecated" # by Google (in Chrome) and Mozilla (in Firefox) in March-April 2021, # this is my response. A similar program was needed on the Panix end # to install the file-list pages there and link to them from the Panix # Kermit archive page. # # Frank da Cruz, 1 May 2021 .destdir = ~/p/archives/ # Macro to write HTML header for a file-list page def MAKEHEADER { fwrite /line \%1 {} fwrite /line \%1 {} fwrite /line \%1 {} fwrite /line \%1 {} fwrite /line \%1 {} fwrite /line \%1 {\m(name)} fwrite /line \%1 {} fwrite /line \%1 {

File list: \m(name)

} fwrite /line \%1 {
}
}

# Macro to convert a plain-text directory listing into a Web page with links
def MAKEHTML {
    local line
    fopen /read \%f \m(destdir)\m(name).txt    # Open directory listing file
    if fail exit 1 "FAILED: fopen /read \m(name).txt"
    fopen /write \%o \m(destdir)\m(name).html  # Create HTML version of it
    if fail exit 1 "FAILED: fopen /write \m(name).html"
    makeheader \%o                             # Put the html header
    while true {                               # Loop through the files 
        fread /line \%f line                   # Read a line from the listing
        if fail break
        if not def line continue               # (shouldn't happen)
        if \findex(\32->\32,\m(line)) continue # Skip symlinks
        undef fn
        .fn := \fword(\m(line),5,\32,ALL)      # Get filename
        if not def fn exit 1 "No filename found in line: \m(line)"
        # Convert the filename into a link
        .link := 
        .link := \m(link)\m(fn)
        .line := \freplace(\m(line),\m(fn),\m(link))
        fwrite /line \%o \m(line)
    }
    fwrite /line \%o "
" # Finish the HTML page fwrite /line \%o "
" fwrite /line \%o "" fwrite /line \%o "" fclose \%f # Close directory listing file fclose \%o # Close HTML page } # MAIN PROGRAM... .\%n = 0 # Archive counter cd ~/web/ # CD to Columbia Kermit website if fail exit 1 FAILED: cd ~/web/ fopen /read \%c archive.html # Open the Columbia archive page if fail exit 1 FAILED: fopen /read archive.html fopen /write \%x \m(destdir)index.html # Create an index file for the result if fail exit 1 FAILED: fopen /write \m(destdir)index.html .name = Index to archive file lists makeheader \%x # Main loop - read archive file, get file-list for each archive, # get directory listing of it, and then call the functions above to # convert it into a web page with links to each file. while 1 { fread /line \%c line # Read a line from the archive page if fail break # End of file .\%9 := \findex(>file list<,\m(line)) # Look for ">file list<" if not \%9 .\%9 := \findex(>file list<,\m(line)) # or ">file list<" if not \%9 continue incr \%n # Gone one, count it .\%8 := \frindex(ftp://,\m(line)) # Look for beginning of URL if not \%8 exit 1 "Can't find ftp:// in \m(line)" .url := \s(line[\%8_\%9-2]) # Isolate the URL show mac url .\%7 := \frindex(edu/kermit,\m(url)) .path := \s(url[\%7+11:]) # Get the path for this archive member if equ "\fright(\m(path),1)" "/" .path := \fstripn(\m(path),1) show mac path cd ~/web/ftp/\m(path) # CD to it if fail exit 1 "FAILED: cd ~/web/ftp/\m(path)" .name := \freplace(\m(path),/,-) # Change path to a name show mac name dir /output:\m(destdir)\m(name).txt # Get a directory listing for it makehtml # Convert to directory listing to html fwrite /line \%x \m(name).html } fclose \%c # Close Columbia archive file fwrite /line \%x "
" # Put ending on index file fwrite /line \%x "" fwrite /line \%x "" fclose \%x # Close index file chmod 644 \m(destdir)* # Make everything readable exit 0 File-list pages: \%n ; Local Variables: ; comment-column:40 ; comment-start:"# " ; End: