#!/usr/bin/awk -f #/afs/tu-chemnitz.de/gnu/@sys/bin/gawk -f # CGI-Anfrage: Auflistung des Inhaltes einer .ZIP.Datei function SetDefaults( pairs) { DefaultUser="heha"; # falls Benutzername weggelassen wird (kürzere URL) DefaultCP="auto"; # "ainv" ist wohl Unsinn! if (ENVIRON["HTTP_ACCEPT_LANGUAGE"] ~ "de") Lang="de"; split(ENVIRON["QUERY_STRING"],pairs,"&"); FirstQuery=pairs[1]; if (pairs[2]~/^lang=/) { Lang=substr(pairs[2],6,2); ForceLang="&" pairs[2]; # fortan immer an URL anhängen } } function unescape(s) { # Plus zu Leerzeichen wandeln; %xx-Escapes zurückwandeln # Moderne Browser schicken standardmäßig UTF-8, wenn Umlaute eingegeben werden # Bestens: Alle Links müssen %xx-Codes statt Umlaute enthalten Result=""; for (i=0; iBOM, typischerweise GCC-Quelletxte)"; if (s1 == "ok") return "Datei sei OEM-kodiert (CP437)"; if (s1 == "ak") return "Errate Kodierung (entweder OEM oder ANSI; UTF-8 und UTF-16 wird automatisch erkannt)"; if (s1 == "ik") return "Errate Kodierung mit inversem Ergebnis"; if (s1 == "wk") return "Datei sei ANSI-kodiert (CP1252)"; if (s1 == "ec") return "Vorgefundene Kodierung"; if (s1 == "ecgi")return "Fehler bei CGI-Anfrage"; if (s1 == "msg") return "Meldung"; if (s1 == "hack")return "Hack-Versuch abgelehnt!" if (s1 == "con") return "Inhalt von "; if (s1 == "vz") return "Verzeichnisse zuerst"; if (s1 == "grp") return "\\1.\\2"; if (s1 == "n") return "Dateiname"; if (s1 == "e") return "Erw"; if (s1 == "m") return "Zuletzt geändert"; if (s1 == "s") return "Größe"; if (s1 == "d") return "Beschreibung"; if (s1 == "u") return "(unsortiert)"; if (s1 == "v") return "Verzeichnis"; if (s1 == "st") return "Starten"; if (s1 == "an") return "Ansehen"; if (s1 == "hw") return "Hineinwechseln"; if (s1 == "hl") return "Herunterladen"; if (s1 == "da") return "Dateien"; if (s1 == "so") return "Sortieren oder Sortierrichtung umkehren"; if (s1 == "pk") return "In PDF konvertieren und anzeigen"; if (s1 == "ub") return "unkomprimierte Bytes"; if (s1 == "bom") return "BOM?"; if (s1 == "sc") return "Skript"; if (s1 == "fi") return "Datei"; if (s1 == "qt") return "Quelltext"; if (s1 == "bd") return "Verzeichnis betrachten, das das Archiv enthält"; if (s1 == "zd") return "Archiv (ZIP-Datei) herunterladen"; if (s1 == "br") return "Archiv (ZIP-Datei) betrachten"; if (s1 == "bz") return "Verzeichnisebene im Archiv betrachten"; if (s1 == "cd") return "Das Verzeichnis das Sie gerade hier sehen"; if (s1 == "cf") return "Die Datei, die Sie gerade hier sehen, herunterladen"; if (s1 == "au") return "[Download]"; if (s1 == "mt") return "Sie benötigen eine geeignete Verknüpfung für den MIME-Typ "; if (s1 == "upi") return "Ungültige PATH_INFO!
\n"\ "(Ein .zip muss in der URL enthalten sein!)
\n"\ "Verwendung: /~%s/viewzip.cgi/~username/pfad_zum_zip/zipdatei.zip/"; if (s1 == "ezip")return "Ungültige oder leere .ZIP-Datei (%s)!
\n"\ "Mögliche Ursachen:\n"\ "Kommando: „%s“"; if (s1 == "foot")return "Generiert durch ein "\ "awk-Skript von Henrik Haftmann
"; }else{ if (s1 == "ASM") return "Assembler source (mostly 80x86)"; if (s1 == "INC") return "Assembler include file"; if (s1 == "A51") return "Assembler source (Keil 8051 or ASEM51)"; if (s1 == "I51") return "Assembler Include-Datei (Keil 8051 or ASEM51)"; if (s1 == "S51") return "Assembler source (Wickenhäuser 8051)"; if (s1 == "A90") return "Assembler source (Atmel AVR: AT90, ATtiny, ATmega)"; if (s1 == "I90") return "Assembler include file (Atmel AVR: AT90, ATtiny, ATmega)"; if (s1 == "A16") return "Assembler source (Microchip PIC)"; if (s1 == "S") return "Assembler source (Gnu-C or gas)"; if (s1 == "I16") return "Assembler include file (Microchip PIC)"; if (s1 == "PAS") return "Pascal source"; if (s1 == "FRM") return "VisualBasic source"; if (s1 == "FRX") return "VisualBasic form"; if (s1 == "DPR") return "Delphi project (source)"; if (s1 == "C") return "C source"; if (s1 == "CPP") return "C++ source"; if (s1 == "DLL") return "Dynamic Link library (Windows)"; if (s1 == "386") return "Virtual Device Driver (Windows 3.x)"; if (s1 == "VXD") return "Virtual Device Driver (Windows 9x)"; if (s1 == "DRV") return "Device Driver (Windows)"; if (s1 == "SYS") return "Device Driver (DOS oder Windows NT)"; if (s1 == "COM") return "DOS or Z80 program"; if (s1 == "EXE") return "DOS, OS/2, or Windows program"; if (s1 == "BAT") return "DOS batch program"; if (s1 == "DEB") return "Input for DEBUG"; if (s1 == "TXT") return "Text file"; if (s1 == "HEX") return "Intel HEX file (microcontroller program)"; if (s1 == "EEP") return "Intel-HEX-Datei (mikrocontroller EEPROM data)"; if (s1 == "IIC") return "Binary data for serial EEPROM"; if (s1 == "PKG") return "AIS packet list"; if (s1 == "TXW") return "KC85 WordPro text file"; if (s1 == "M") return "Matlab script"; if (s1 == "DSP") return "Visual C++ project"; if (s1 == "VCPROJ") return "Visual Studio C++ project"; if (s1 == "DSW") return "Visual C++ workplace"; if (s1 == "SLN") return "Visual Studio C++ workplace"; if (s1 == "MAK") return "Makefile"; if (s1 == "KCC") return "KC85 machine programm"; if (s1 == "SSS") return "KC85 BASIC program (tokenized)"; if (s1 == "DIZ") return "Distribution information"; if (s1 == "HLP") return "Windows Help"; if (s1 == "RES") return "Binary resource"; if (s1 == "ICO") return "Windows Icon"; if (s1 == "PS") return "PostScript (silkscreen?)"; if (s1 == "PSZ") return "PostScript, zipped (silkscreen?)"; if (s1 == "SCH") return "Schematic (Eagle or UltiCap)"; if (s1 == "GER") return "PostScript (Schematic)"; if (s1 == "GEZ") return "PostScript (Schematic, zipped)"; if (s1 == "BRD") return "Eagle PCB"; if (s1 == "ULP") return "Eagle PCB User Language Program"; if (s1 == "DDF") return "UltiBoard PCB"; if (s1 == "FOL") return "PostScript (PCB)"; if (s1 == "FOZ") return "PostScript (PCB, zipped)"; if (s1 == "GIF") return "Picture (drawing/screenshot)"; if (s1 == "PNG") return "Picture (drawing/screenshot)"; if (s1 == "JPG") return "Picture (photographic)"; if (s1 == "MANIFEST") return "Manifest file (Windows XP)"; if (s1 == "PDF") return "useless PostScript"; if (s1 == "VI") return "LabVIEW Virtual Instrument file (binary)"; if (s1 == "X") return "Linker script for gcc"; if (s1 == "HTM") return "Hypertext"; if (s1 == "WMF") return "Windows Meta File (scalable vector graphics)"; if (s1 == "EMF") return "Enhanced Meta File (scalable vector graphics)"; if (s1 == "CER") return "Certificate"; if (s1 == "-f") return " file"; if (s1 == "ln") return "Show line numbers"; if (s1 == "uf") return "Wrong umlauts?"; if (s1 == "nk") return "Assume file is UTF-8 encoded (without BOM, mostly GCC source files)"; if (s1 == "ok") return "Assume file is OEM (CP437) encoded"; if (s1 == "ak") return "Guess file encoding (either OEM or ANSI; UTF-8 and UTF-16 is auto-detected)"; if (s1 == "ik") return "Guess file encoding and inverse result"; if (s1 == "wk") return "Assume file is ANSI (CP1252) encoded"; if (s1 == "ec") return "Detected encoding"; if (s1 == "ecgi")return "Erraneous CGI request"; if (s1 == "msg") return "Message"; if (s1 == "hack")return "Hacking rejected!"; if (s1 == "con") return "Content of "; if (s1 == "vz") return "Directories on top"; if (s1 == "grp") return "\\1,\\2"; if (s1 == "n") return "Filename"; if (s1 == "e") return "Ext"; if (s1 == "m") return "Last modified"; if (s1 == "s") return "Size"; if (s1 == "d") return "Description"; if (s1 == "u") return "(unsorted)"; if (s1 == "v") return "Directory"; if (s1 == "st") return "Start"; if (s1 == "an") return "View"; if (s1 == "hw") return "Enter subdirectory"; if (s1 == "hl") return "Download"; if (s1 == "da") return "files"; if (s1 == "so") return "Sort or reverse-sort this column"; if (s1 == "pk") return "Convert to PDF on-the-fly and show it"; if (s1 == "ub") return "uncompressed bytes"; if (s1 == "bom") return "BOM?"; if (s1 == "sc") return "Skript file:"; if (s1 == "fi") return "File:"; if (s1 == "qt") return "Source file:"; if (s1 == "bd") return "Browse directory containing archive (zipfile)"; if (s1 == "zd") return "Download archive (zipfile)"; if (s1 == "br") return "Browse archive (zipfile)"; if (s1 == "bz") return "Browse directory level in archive file"; if (s1 == "cd") return "The directory level you see here"; if (s1 == "cf") return "Download the file you see here"; if (s1 == "au") return "[Download]"; if (s1 == "mt") return "You need a shell link to MIME type "; if (s1 == "upi") return "Invalid PATH_INFO!
\n"\ "(A .zip string must be in the URL!)
\n"\ "Usage: /~%s/viewzip.cgi/~username/path_to_zip/zipfile.zip/"; if (s1 == "ezip")return "Invalid or empty .ZIP file (%s)!
\n"\ "Possible reasons:\n"\ "Command: “%s”"; if (s1 == "foot")return "Generated by an "\ "awk script by Henrik Haftmann
"; } } function Desc(s, s1,s2) { if (s ~ /\/$/) return s("v"); s1=toupper(s); sub(/^.+[/.]/,"",s1); if (s1 == "MAKEFILE") s1 = "MAK"; s2=s(s1); if (s2) return s2; if(s1~/^HTML?$/) return s("HTM"); return s1 s("-f"); } function guck(s) { # ermittelt anhand des Dateinamens s den nötigen Betrachter-Typ mimetype=""; s1=toupper(s); sub(/^.+\//,"",s1); if (s1 == "MAKEFILE") return "MAK"; if (s1 ~ /^(README|LIESMICH|DIRINFO|FILELIST)$/) return "TXT"; sub(/^.+\./,"",s1); if (s1 ~ /^(ASM|INC|A51|I51|S51|A90|I90|A16|I16|S)$/) return "ASM"; if (s1 ~ /^(PAS|DPR)$/) return "PAS"; if (s1 ~ /^(BAS|FRM)$/) return "BAS"; if (s1 ~ /^(C|RC)$/) return "C"; if (s1 ~ /^(CPP|CC|CXX|C\+\+|H|X)$/) return "CPP"; if (s1 ~ /^(TXT|PKG|DOC|DIZ|LST|DEB)$/) return "TXT"; if (s1 == "TXW") return "TXW"; if (s1 ~ /^(MANIFEST|VCPROJ)$/) return "XML"; if (s1 ~ /^(SCH|DDF)$/) return "ULT"; if (s1 == "ULP") return "ULP"; if (s1 == "DEF") return "DEF"; if (s1 ~ /^(MAK|DSP|DSW|AWK|SLN)$/) return "MAK"; if (s1 ~ /^(HPJ|INI|INF|REG)$/) return "INI"; if (s1 ~ /^(HEX|EEP)$/) return "HEX"; if (s1 == "BAT") return "BAT"; if (s1 == "M") return "MAT"; if (s1 == "HLP") {mimetype="application/x-ms-winhelp"; return "HLP";} if (s1 == "RES") {mimetype="application/x-resource-workshop"; return "RES";} if (s1~/^(PS|PSZ|GER|GEZ|FOL|FOZ)$/) {mimetype="application/postscript"; return "PS";} if (s1~/^HTML?$/){mimetype="text/html"; return "HTM";} if (s1 ~ /^(COM|EXE|DLL|DRV|SYS|VXD|386|TBL|FRX|CER)$/) return "X"; if (s1 == "ICO") return "ICO"; if (s1 == "PCX") return "PCX"; if (s1 == "GIF") return "GIF"; if (s1 == "PNG") return "PNG"; if (s1 == "JPG") return "JPG"; return ""; } function isupper(str) { # liefert TRUE wenn str nirgends Kleinbuchstaben hat return (str==toupper(str)); } function swapcase(str) { return (str!=toupper(str) ? toupper(str) : tolower(str)); } function mkzipdate(datum,uhrzeit, dat,z) { # ZIP-Datum und Uhrzeit in fortlaufende, sortierbare Nummer umwandeln split(datum,dat,"-"); split(uhrzeit,z,":"); if (dat[3]<100) dat[3]+=1900; if (dat[3]<1980) dat[3]+=100; return dat[3] dat[1] dat[2] z[1] z[2]; } function extractor(aus) { # Ermittelt aus das gewünschte Sortierkriterium if (suche[1] ~ /[Ss]/) return aus[1]; # Größe if (suche[1] ~ /[Mm]/) return aus[2]; # Zeit if (suche[1] ~ /[Dd]/) return aus[5]; # Beschreibung if (suche[1] ~ /[Ee]/) return gensub(/^.*[/.]/,"",1,aus[4]); # Ext if (suche[1] ~ /[Nn]/) return aus[4]; return 0; } function comparer(rechts,links, raus,laus,Result) { # Routine für qsort() split(rechts,raus); split(links,laus); if ((suche[1] ~ /[a-z]/) && ((raus[4] ~ /\/$/) != (laus[4] ~ /\/$/))) { return (raus[4] ~ /\/$/); } Result=(extractor(raus)%s%s",\ (krit==toupper(suche[1])) ? "" : "",\ (suche[1]==tolower(suche[1])) ? tolower(krit) : krit,\ antisuche(krit),\ ForceLang, text,\ (krit==toupper(suche[1])) ? "" : ""); } # "swap" und "qsort" aus dem Buch "Kalteis: awk, Franzis Verlag" function swap(A,i,j, t) { t=A[i]; A[i]=A[j]; A[j]=t; } function qsort(A,left,right, i,last) { if (left>=right) return; last=left; for (i=left+1; i<=right; i++) { if (comparer(A[i],A[left])) swap(A,++last,i); } swap(A,left,last); qsort(A,left,last-1); qsort(A,last+1,right); } function Fehler(s) { # Fehler (als richtiges text/html) zum Client ausgeben und Programmende printf("Content-type: text/html; charset=utf-8\n\n"); printf("%s\n\n",s("ecgi")); printf("

%s

\n",s("ecgi")); printf("%s: %s

\n",s("msg"),s); printf("\n"); exit(1); } function mysplit(s,t,n, i,k) { #wie split(), jedoch mit n=Maximalindex des entstehenden Arrays for (i=1; i" urls[i] "/"; } if (trail) { s = s "" urls[i] ""; }else{ s = s "" urls[i] ""; } s = s "\"""; return s; } function MakeUrlTrail( i,k,urls,s,t,d) { s=""; t=""; k=split(trail,urls,"/"); if (k>1 && urls[k]=="") { # Nachlaufenden Backslash nicht zum Aufteilen heranziehen k--; urls[k] = urls[k] "/"; # urls-Array "korrigieren" } for (i=1; i" urls[i] "/"; } if (urls[k] ~ /\/$/) s = s "" urls[k] ""; else{ t = t Esc(urls[i]) s = s "" urls[i] ""; } return s; } # Radiobutton ausgeben function Radio(convcode,strcode, fname) { fname=gensub(/^.*\//,"",0,trail); if (substr(suche[1],1,4)==convcode) { printf("%s
\n",s(strcode)); }else{ printf("",\ fname, convcode, ForceLang, suche[2]); printf("%s
\n",\ fname, convcode, suche[2], ForceLang, s(strcode)); } } # Checkbox (Zeilennummern) ausgeben function CheckLn( fname,checkstate) { fname=gensub(/^.*\//,"",0,trail); checkstate = suche[1] ~ /n$/; printf("%s\n",\ (checkstate ? " checked" : ""),\ fname,checkstate ? gensub(/n$/,"",0,suche[1]) : suche[1] "n",suche[2],ForceLang,\ s("ln")); } ######################### # Syntax-Hervorhebungen # ######################### function PAS(void) { if (inside_comment==1) { if (sub(/^[^}]*}/,"&")) { inside_comment=0; } }else if (inside_comment==2) { if (sub(/^([^*]|\*[^)])*\*?\*\)/,"&")) { inside_comment=0; } } if (inside_comment) return; #nichts umfärben! if (inside_asm) { if (sub(/\/,"&")) inside_asm=0; } sub(/\/\/.*$/,"&"); gsub(/{(|[^$}][^}]*)}/,"&"); gsub(/{\$[^}]*}/,"&"); if (sub(/{[^}]*$/,"&")) { inside_comment=1; } if (sub(/\(\*([^*]|\*[^)]|\*$)*$/,"&")) { inside_comment=2; } if (sub(/\/,"&")) { if (!sub(/\/,"&")) inside_asm=1; } if (inside_asm<2) { gsub(/\<(absolute|abstract|array|as|and|asm|assembler|break|begin|case|cdecl|class|const|constructor|continue|destructor|div|do|downto|else|end\.?|except|exports?|external|far|file|finalization|finally|for|function|goto|if|implementation|in|index|inherited|inline|interface|label|library|mod|name|near|nil|not|object|of|or|override|packed|pascal|procedure|program|record|repeat|return|set|sh[lr]|sizeof|stdcall|string|then|to|try|type|unit|until|uses|var|virtual|while|with|xor)\>/,"&"); } match($0,/(function|procedure)<\/B>[ \t]+([A-Z_][0-9A-Z_]*)\>/); if (RSTART) { pro=gensub(/.*[ \t]+/,"","",substr($0,RSTART,RLENGTH)); if (!asso[pro]) { sub("\\<" pro "\\>","&"); if (linklist) linklist = linklist "|"; linklist = linklist pro; asso[pro]=1; }else{ gsub("\\<(" linklist ")\\>", "&"); } }else{ gsub("\\<(" linklist ")\\>", "&"); } if (inside_asm==1) inside_asm++; gsub(/'[^']*'/,"&"); if (inside_asm) return; #keine Zahlen in ASM hervorheben $0=gensub(/(\W)([#-]?(\$[0-9a-f]+|[0-9]+(\.[0-9]+)?(e([-+]?[0-9]+))?))/,"\\1\\2","g"); } function CPP(cppflag) { if (inside_comment==1) { #Gewöhnlicher /* */ Kommentar if (sub(/^([^*]|\*[^/])*\*\//,"&")) { inside_comment=0; } }else if (inside_comment==2) { #String-Zeilenfortsetzung (igitt!) if (sub(/^([^"]|\\")*("|[^\\]$)/,"&")) { inside_comment=0; } }else if (inside_comment==3) { #define-Zeilenfortsetzung (naja) if (cppflag<2) { if (sub(/[^\\]$/,"&")) inside_comment=0; }else{ if (sub(/^\W*$/,"&")) inside_comment=0; } } if (inside_comment) return; #nichts einfärben! sub(/\/\/.*$/,"&"); gsub(/\/\*([^*]|\*[^/])*\*\//,"&"); if (sub(/\/\*([^*]|\*[^/])*$/,"&")) { inside_comment=1; } if (sub(/"([^"]|\\")*\\$/,"&")) { inside_comment=2; } if (sub(/^#[^/]*/,"&")) { if (cppflag==2 || !sub(/[^\\]$/,"&")) inside_comment=3; return; } if (cppflag<2) { gsub(/\<(asm|auto|break|case|_?cdecl|char|const|continue|_cs|default|do|double|_ds|else|enum|_es|_?export|extern|_?far|_?fastcall|float|for|goto|huge|if|inline|int|interrupt|_loadds|long|_?near|_?pascal|register|return|_saveregs|_seg|short|signed|sizeof|_ss|static|_?stdcall|struct|switch|typedef|union|unsigned|void|volatile|while)\>/,"&"); if (cppflag) { gsub(/\<(bool|class|delete|friend|new|null|operator|private|protected|public|template|this|virtual)\>/,"&"); } }else{ // ULP gsub(/\<(UL_\w+|break|case|char|continue|default|do|else|enum|for|if|int|numeric|real|return|string|switch|void|while)\>/,"&"); } gsub(/{|}/,"&"); match($0,/^[ \t]*(()?[A-Za-z_][0-9A-Za-z_]*(<\/B>)?[ \t]+)+[A-Za-z_][0-9A-Za-z_]*[ \t]*\(/); if (RSTART && ($0 !~ /\<(return|switch)\>/)) { pro=gensub(/[ \t]*(()?[A-Za-z_][0-9A-Za-z_]*(<\/B>)?[ \t]+)+/,"","",substr($0,RSTART,RLENGTH-1)); pro=gensub(/[ \t]/,"","g",pro); if (!asso[pro]) { sub("\\<" pro "\\>","&"); if (linklist) linklist = linklist "|"; linklist = linklist pro; asso[pro]=1; }else{ gsub("\\<(" linklist ")\\>", "&"); } }else{ gsub("\\<(" linklist ")\\>", "&"); } gsub(/'([^']|\\')*'/,"&"); gsub(/"([^"]|\\")*"/,"&"); $0=gensub(/(^|[^0-9A-Za-z_.])((-|)[0-9]+([Xx][0-9A-Fa-f]+|\.[0-9]|)([Ee](+|-|)[0-9]+|)[UuLlFf]*)/,"\\1\\2","g"); } function ASM(void) { sub(/;.*$/,"&"); if (sub(/^[ \t.]*(include|else|endif|(|else)if(|1|2|[be]|def|dif(|i)|idn(|i)|nb|ndef|nz))\>[^;]*/,"&")) return; if (sub(/^[ \t.]*err(if|)(|1|2|[be]|def|(dif|idn)(|i)|n(b|def|z))\>[^;]*/,"&")) return; if (sub(/^[ \t.%]*(depth|display|incl|lall|lfcond|linum|(|no)(list|macs|trunc)|newpage|no(conds|cref|ctls|incl|syms)|%out|(page|tab)size|pcnt|(pop|push)ctl|subttl|text|title|xall|xcref|xlist)\>[^;]*/,"&")) return; if (sub(/^[ \t.]*((p[1-5]|p80|[1-5]|80)8[67]([pn]|)|align|alpha|assume|code(|seg)|const|(|u|far)data(|seg|\?)|even(|data)|exitcode|fastimul|group|ideal|includelib|(|no)jumps|locals|(|no)masm(|51)|model|name|(|no)(emul|jumps|masm(|51)|multerrs|smart|warn)|org|quirks|radix|segment|seq|stack|startup(|code)|version)\>[^;]*/,"&")) return; gsub(/\<(arg|align|dup|proc(desc|type|)|end(|[psm])|equ|macro|struc|extrn|public|d(|ef)[bdfpqtw]|enum|exit(m|code|)|goto|local(s|)|record|rept|type(|def)|union|uses)\>/,"&"); match($0,/proc<\/B>[ \t]+([A-Z_][0-9A-Z_]*)\>/); if (RSTART) { pro=gensub(/.*[ \t]+/,"","",substr($0,RSTART,RLENGTH)); if (!asso[pro]) { sub("\\<" pro "\\>","&"); if (linklist) linklist = linklist "|"; linklist = linklist pro; asso[pro]=1; }else{ gsub("\\<(" linklist ")\\>", "&"); } }else{ gsub("\\<(" linklist ")\\>", "&"); } gsub(/'[^']*'/,"&"); gsub(/"[^"]*"/,"&"); } function HEX(void) { if (substr($0,1,1) == ":") { l=length-11; $0=substr($0,1,3) "" substr($0,4,4) "" \ substr($0,8,2) "" substr($0,10,l) "" \ substr($0,10+l); }else $0="" $0 ""; } function DEF(void) { sub(/;.*$/,"&"); sub(/^\w+\>/,"&"); gsub(/'[^']*'/,"&"); gsub(/"[^"]*"/,"&"); } function INI(void) { sub(/(^|[ \t]);.*/,"&"); sub(/^\[.*\]$/,"&"); gsub(/"[^"]*"/,"&"); } function MAT(void) { sub(/(^|[ \t])%.*$/,"&"); gsub(/\<(case|else(if)?|end|for|function|if|switch|while)\>/,"&"); gsub(/'[^']*'/,"&"); } function MAK(void) { if (listchar) { if (substr($0,1,1) == listchar) { sub(/^/,""); listchar=0; } return; } sub(/^!.*$/,"&"); sub(/#.*$/,"&"); sub(/^[a-z_]+ *=.*$/,"&"); sub(/^[a-z_.][^=]*:.*$/,"&"); if (/(&&|<<).$/) { listchar=substr($0,length($0),1); sub(/$/,""); } } function BAT(void) { if (sub(/^rem.*$/,"&")) return; gsub(/\<@?(cd|date|del|do|echo|exist|for|goto|if|in|not|path|ren|set|shift|time|type)\>/,"&"); sub(/^:.*/,"&"); gsub(/(%[0-9]|%[0-9A-Z_]+%)/,"&"); } function BAS(void) { sub(/'.*$/,"&"); gsub(/\<@?(begin|attribute|let|set|declare|sub|for|next|dim|private|for|goto|if|as|not|end|then|else|and|or|while)\>/,"&"); gsub(/"[^"]*"/,"&"); } function TXT(void) { # bei Textdateien URLs und EMAIL-Adressen scharfmachen gsub(/\<((ht|f)tp:\/\/[a-z][0-9a-z_.-]*\/[0-9a-z_./%~-]*)\>/,"&"); gsub(/\<([a-z][0-9a-z_.-]*@[0-9a-z_.-]*[a-z])\>/,"&"); gsub(/\<_[0-9a-z]+_\>/,"&"); #Hervorhebungen gsub(/\W\*\w+\*\W/,"&"); gsub(/\W\/\w+\/\W/,"&"); } function TXW(void) { # WordPro-Textdateien mit Umlauten und Hervorhebungen versehen # Sollte eine angepasste Version von OEM2UTF8 machen, auch bei 0x03 abschneiden. # Das verflixte Zelenfortsetzungszeichen ("&" am Ende) bekomme ich nicht hin! gsub(/Ç/,"80"); # 80 gsub(/ü/,""); # 81 gsub(/é/,"82"); # 82 gsub(/â/,""); # 83 gsub(/ä/,"84"); # 84 gsub(/à/,""); # 85 gsub(/å/,""); # 86 gsub(/ç/,"87"); # 87 gsub(/ê/,"88"); # 88 gsub(/ë/,""); # 89 gsub(/è/,""); # 8A gsub(/ï/,"8B"); # 8B gsub(/î/,""); # 8C gsub(/ì/,"8D"); # 8D gsub(/Ä/,""); # 8E gsub(/Å/,"8F"); # 8F gsub(/\[/,"Ä"); gsub(/\\/,"Ö"); gsub(/\]/,"Ü"); gsub(/\{/,"ä"); gsub(/\|/,"ö"); gsub(/\}/,"ü"); gsub(/\~/,"ß"); } function ULT(void) { sub(/^\*./,"&"); sub(/^&"); } function XML(void) { #wird nicht ausgeführt! sub(/^/,"Hier!"); gsub(/[a-z]+/,"&"); } function OutChooseLanguage( i,n,pairs) { if (Lang!="de") print ("[deutsch]"); if (Lang!="en") print ("[english]"); } ################# # Hauptprogramm # ################# BEGIN { # if (ENVIRON["REQUEST_METHOD"]!="GET") { # Fehler("Dieses CGI-Programm muss mit der http-Methode GET aufgerufen werden"); # } SetDefaults(); info=ENVIRON["PATH_INFO"]; # gsub(/%23/,"#",info); if (info ~ /[*;<>|&`"']/) { Fehler(s("hack")); } i=index(info,".zip/"); # Wo die Datei-Inhalte beginnen if (!i) { i=index(info,".exe/"); if (i) ais_mode=1; } if (i) { trail=substr(info,i+5); # Wenn (trail), dann auspacken!! info=substr(info,1,i+3); }else if (info ~ /\.zip$/) { url="http://" ENVIRON["SERVER_NAME"]; port=ENVIRON["SERVER_PORT"]; if (port != 80) {url=url ":" port}; url=url ENVIRON["REQUEST_URI"] "/"; print "Location: " url "\n"; # Umleitung exit(0); }else{ Fehler(sprintf(s("upi"),DefaultUser)); } file=info; # kommt mit führendem / sub(/^\//,"",file); # vom Anfang entfernen if (file !~ /^~/) file="~" DefaultUser "/" file; sub(/\//,"/public_html/",file); # Standard-Vrz. einbasteln gsub(/[ #]/,"\\\\&",file); # Leerzeichen und '#' sichern split(FirstQuery,suche,"="); # suche[1]=N/M/S/D, suche[2]=A/D # prelink=gensub(/^.*\//,"",1,trail); # bei jedem Link davorzusetzen... if (trail && (trail !~ /\/$/)) { # Auspack-Modus (Einzeldatei) kdo="unzip -p"; if (ais_mode) kdo="./unais"; ttrail=trail; gsub(/[ #;<>|&`"']/,"\\\\&",ttrail); kdo=kdo " " file " " ttrail; if (suche[1]) { # Auspacken mit Anguck-Filter if (suche[2] == "X") { # Hexdump zuerst! kdo=kdo " | ./hdump"; } if (suche[1] ~ /^oem/) { kdo=kdo " | ./oem2utf8"; } if (suche[1] ~ /^auto/) { kdo=kdo " | ./oem2utf8 guess"; # Dummy-Argument } if (suche[1] ~ /^ainv/) { kdo=kdo " | ./oem2utf8 guess invers"; # 2 Dummy-Argumente } if (suche[1] ~ /^ansi/) { kdo=kdo " | ./oem2utf8 ansi windows cp1252"; # 3 Dummy-Argumente } if (suche[1] ~ /n$/) { linecount = 1; } if (suche[2] == "ICO") { kdo=kdo " | ./ico2gif"; }else if (suche[2] == "PCX") { kdo=kdo " > /tmp/viewzip.pcx && pcxtoppm /tmp/viewzip.pcx | ppmtogif ; rm /tmp/viewzip.pcx"; }else if (suche[2] == "PDFR") { kdo=kdo " | sed -e 's/scale/scale -90 rotate -9000 0 translate/'"; #rechts rotieren (nur UltiCAP) kdo=kdo " | /afs/tu-chemnitz.de/global/i386_linux26/bin/gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -r600 -g7010x4950 -sOutputFile=- - 2>&1" }else if (suche[2] == "PDF") { kdo=kdo " | /afs/tu-chemnitz.de/global/i386_linux26/bin/gs -dQUIET -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=- - 2>&1"; } printf("Content-type: "); if (suche[2] == "HLP") { print("application/x-ms-winhelp\n"); }else if (suche[2] == "DOC") { print("application/msword\n"); # keine automatische Verknüpfung }else if (suche[2] == "RES") { print("application/x-resource-workshop\n"); }else if (suche[2] ~ /HTML?/) { print("text/html\n"); }else if (suche[2] ~ /(ICO|PCX|GIF)/) { print("image/gif\n"); }else if (suche[2] == "PNG") { print("image/png\n"); }else if (suche[2] == "JPG") { print("image/jpeg\n"); }else if (suche[2] == "PS") { print("application/postscript\n"); }else if (suche[2] ~ /PDF.?/) { print("application/pdf\n"); }else{ texttyp=s("qt"); if (suche[2] ~ /(BAT|MAT|MAK)/) texttyp=s("sc"); if (suche[2] ~ /(INI|TXT)/) texttyp=s("fi"); if (suche[2] == "X") texttyp="Hexdump"; print ("text/html\n"); print (""); print (" "); if (suche[2] == "X") { print(" "); } printf(" %s %s\n",texttyp,trail); printf("\n"); OutChooseLanguage(); print ("
"); printf("

%s %s/%s

\n",texttyp,MakeUrl(),MakeUrlTrail()); CheckLn(); print ("
"); # print kdo "

"; print ("

");
    inside_comment=0;
    do {
     if (!(kdo | getline)) break;
     gsub("&","\\&A");	# 2stufig wegen störender Semikolons
     gsub("<","\\&L");
     gsub(">","\\&G");
     sub("\r","");
     if (suche[2]=="C")   CPP(0);
     if (suche[2]=="CPP") CPP(1);
     if (suche[2]=="ULP") CPP(2);
     IGNORECASE=1;
     if (suche[2]=="PAS") PAS(0);
     if (suche[2]=="BAS") BAS(0);
     if (suche[2]=="ASM") ASM(0);
     if (suche[2]=="HEX") HEX(0);
     if (suche[2]=="DEF") DEF(0);
     if (suche[2]=="INI") INI(0);
     if (suche[2]=="MAK") MAK(0);
     if (suche[2]=="MAT") MAT(0);
     if (suche[2]=="BAT") BAT(0);
     if (suche[2]=="TXT") TXT(0);
     if (suche[2]=="TXW") TXW(0);
     if (suche[2]=="ULT") ULT(0);
     if (Suche[2]=="XML") XML(0);
     IGNORECASE=0;
     gsub(//,"&");
     gsub(/<\/I>/,"&");
     gsub("&A","\\&");
     gsub("&L","\\<");
     gsub("&G","\\>");
     if (linecount) {
      printf("%5d  ",linecount++);
     }
     print;
    }while (1);
    ec=close(kdo);
    print "
"; # Vorgefundene Kodierung ausgeben if (suche[2] !~ /^(X|HEX|TXW)$/) { ec/=256; if (ec>=128) ec-=256; if (suche[1] ~ /^auto/ || suche[1] ~ /^ainv/) { if (ec==-3) ko="UTF-16LE + BOM"; else if (ec==-2) ko="UTF-16LE"; else if (ec==-1) ko="UTF-8 + BOM"; else if (ec==0) ko="UTF-8"; else if (ec==1) ko="OEM (CP437)"; else if (ec==4) ko="ANSI (CP1252)"; else ko="ASCII (7 bit)"; printf("
%s: %s%d
\n", s("ec"),ko,ec); } if (ec==1 || ec==4) { printf("
%s - \n",s("uf")); # Tabelle-in-Tabelle # Radio("none","nk"); # Radio("oem", "ok"); Radio("auto","wk"); # "ak" Radio("ainv","ok"); # "ik" # Radio("ansi","wk"); # print (" \"\" " s("bom")); print ("
"); } } print ""; exit; } # Binär-Start-Modus FS=RS; ORS=""; # $0 nicht zerlegen! do { # Binärdaten if (!(kdo | getline)) break; print $0 RT; }while (1); }else{ # Binär-Download-Modus print ("Content-type: application/octet-stream\n"); FS=RS; ORS=""; # $0 nicht zerlegen! do { if (!(kdo | getline)) break; print $0 RT; }while (1); } }else{ # Listing-Modus if (!suche[1]) suche[1]="n"; # Vorgaben if (!suche[2]) suche[2]="A"; kdo="unzip -l -qq"; if (ais_mode) kdo="./unais"; kdo=kdo " " file ; zl=0; do { if (!(kdo | getline)) break; split($0,av); for (i=5; av[i]; i++) av[4]=av[4] " " av[i]; # av=mysplit($0," ",4); if (trail && index(av[4],trail)!=1) continue; av[4]=substr(av[4],length(trail)+1); if (!av[4]) continue; # leerer Name geworden! if (av[4] ~ /\//) { # Ein Vrz.? has_dirs=1; # enthalten sub(/\/.*$/,"",av[4]) # Rest löschen sumsize[av[4]]+=av[1]; # Gesamt-Größe if (detected[av[4]]) continue; # nicht mehrfach einbauen. detected[av[4]]=1; # merken im assoziativem Array av[4]=av[4] "/"; # Slash anhängen av[1]=" "; # keine Größe } split(av[2],date,"-"); if (date[3]<100) date[3]+=1900; if (date[3]<1980) date[3]+=100; datum=date[2] "." date[1] "." date[3] " " av[3]; if (datum == "00.00.1980 00:00") datum="k. A."; listing[zl]=av[1] " " mkzipdate(av[2],av[3]) " "\ datum " "\ av[4] " " Desc(av[4]); #Beschreibung dazu (ohne Spaces!) zl++; }while (1); close(kdo); if (!zl) { Fehler(sprintf(s("ezip"),info,kdo)); } print ("Content-type: text/html; charset=utf-8\n"); print (""); print (" "); printf(" " s("con") "%s\n",info); print ("\n"); OutChooseLanguage(); printf("

" s("con") "%s/%s

\n",MakeUrl(),MakeUrlTrail()); if (has_dirs) { printf("
",\ !isupper(suche[1]) ? "checked" : "",\ swapcase(suche[1]),\ suche[2], ForceLang); printf("%s
\n",\ swapcase(suche[1]),\ suche[2], ForceLang, s("vz")); } printf("\n"); printf("\n",s("so")) printf("
%s",header(s("u"),"U")); printf(""); printf("%s",header(s("n"),"N")); printf(".%s",header(s("e"),"E")); printf("%s",header(s("m"),"M")); printf("%s",header(s("s"),"S")); printf("%s\n",header(s("d"),"D")); qsort(listing,0,zl-1); # immer sortieren für Verzeichnisse vorn gr=0; # Dateigröße nf=0; # Anzahl Dateien for (i=0; i",bc,\ ((mimetype && (mimetype!="text/html")) ?\ " title=\"" s("mt") "'" mimetype "'!\"" : "")); if (g) { if (g ~ /(PS|PSZ)$/) { printf("PDF ",\ Esc(av[4]), ((av[4]~/GE.$/)?"R":""), s("pk")); } if (g == "TXW") DefaultCP="oem"; printf("%s",Esc(av[4]),\ (g ~ /(HLP|RES|ICO|PCX|GIF|PNG|JPG|HTM|HTML|PS|PSZ)$/) ? "bin":DefaultCP,g,ForceLang,\ ((mimetype && (mimetype!="text/html")\ && (mimetype!="application/postscript")) ? s("st") : \ (g == "X") ? "Hexdump" : s("an"))); }else{ printf(" "); } printf("%s",\ (av[1]==" " ? s("hw") : s("hl")), Esc(av[4]),AnsiName(av[4])); printf("" av[3]); sum_size=(av[1]==" " ? sumsize[gensub(/\//,"","",av[4])] : av[1]); printf(""\ (av[1]==" " ? "(Σ "\ grouped(sum_size) ")" : grouped(sum_size)), s("ub"), sum_size); print ("" av[5]); gr+=av[1]; # zählt nicht Verzeichnisse, die mit Σ beginnen if (av[1]!=" ") nf++; } printf("
 %d %s "\ "Σ %s \n",nf,s("da"),grouped(gr)); print ("
\n"); print s("foot") print ""; } }