From 4e9dfee79956186bea1f7fd9af9c7e18d7e33d5c Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Wed, 4 May 2022 18:33:36 +0000 Subject: [PATCH] Build a file listing page for any given directory --- out/DIRECTORY_LISTING | 35 +++++++++++++++ out/articles/DIRECTORY_LISTING | 32 ++++++++++++++ out/articles/test articles/DIRECTORY_LISTING | 32 ++++++++++++++ sigPlace.java | 45 +++++++++++++++++--- sigServer.java | 4 +- 5 files changed, 141 insertions(+), 7 deletions(-) create mode 100644 out/DIRECTORY_LISTING create mode 100644 out/articles/DIRECTORY_LISTING create mode 100644 out/articles/test articles/DIRECTORY_LISTING diff --git a/out/DIRECTORY_LISTING b/out/DIRECTORY_LISTING new file mode 100644 index 0000000..25f7f18 --- /dev/null +++ b/out/DIRECTORY_LISTING @@ -0,0 +1,35 @@ + + + + + + + + + +
+ +articles 2022-05-04T18:30:43.309932Z gitpod 116
+codeBackground 2022-05-04T18:30:43.285932Z gitpod 2635
+otherpage.html 2022-05-04T18:30:43.289932Z gitpod 900
+reset.css 2022-05-04T18:30:43.293932Z gitpod 1093
+sig.css 2022-05-04T18:30:43.301932Z gitpod 3550
+testfile.html 2022-05-04T18:30:43.301932Z gitpod 828
+ +
+
+
+ + + diff --git a/out/articles/DIRECTORY_LISTING b/out/articles/DIRECTORY_LISTING new file mode 100644 index 0000000..20f5024 --- /dev/null +++ b/out/articles/DIRECTORY_LISTING @@ -0,0 +1,32 @@ + + + + + + + + + +
+ +curabitur vel tempus ex.article 2022-05-04T18:30:43.269932Z gitpod 618
+sigplace1.article 2022-05-04T18:30:43.273932Z gitpod 1559
+test articles 2022-05-04T18:30:43.205932Z gitpod 69
+ +
+
+
+ + + diff --git a/out/articles/test articles/DIRECTORY_LISTING b/out/articles/test articles/DIRECTORY_LISTING new file mode 100644 index 0000000..f5a3e93 --- /dev/null +++ b/out/articles/test articles/DIRECTORY_LISTING @@ -0,0 +1,32 @@ + + + + + + + + + +
+ +test1.article 2022-05-04T18:30:43.277932Z gitpod 1111
+test2.article 2022-05-04T18:30:43.277932Z gitpod 807
+test3.article 2022-05-04T18:30:43.281932Z gitpod 1020
+ +
+
+
+ + + diff --git a/sigPlace.java b/sigPlace.java index 3dbc0d9..e970078 100644 --- a/sigPlace.java +++ b/sigPlace.java @@ -151,12 +151,47 @@ public class sigPlace { map.put("/",new ArrayList()); while (it.hasNext()) { Path f = it.next(); - String myKey = f.toAbsolutePath().toString().replace(startingPath,"").replace(f.getFileName().toString(),""); - System.out.println(myKey+","+f); - map.putIfAbsent(myKey,new ArrayList()); - map.get(myKey).add(f); + if (!f.getFileName().toString().equals(OUTDIR)) { + String myKey = f.toAbsolutePath().toString().replace(startingPath,"").replace(f.getFileName().toString(),""); + //System.out.println(myKey+","+f); + map.putIfAbsent(myKey,new ArrayList()); + map.get(myKey).add(f); + } + } + System.out.println("Directory structure determined:"); + System.out.println(" "+map); + for (String key : map.keySet()) { + System.out.println("Creating directory listing for "+key+"..."); + StringBuilder sb = new StringBuilder(""); + List data = Files.readAllLines(ops.get("%DEFAULT")); + List data2 = Files.readAllLines(ops.get("%FOOTER")); + for (String d : data) { + for (String k : sigPlace.map.keySet()) { + d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k)); + } + sb.append(d).append("\n"); + } + sb.append("
"); + for (Path f : map.get(key)) { + sb.append(f.getFileName()) + .append("\t") + .append(Files.getLastModifiedTime(f)) + .append("\t") + .append(Files.getOwner(f)) + .append("\t") + .append(Files.size(f)) + .append("
\n"); + } + sb.append("
"); + for (String d : data2) { + for (String k : sigPlace.map.keySet()) { + d=d.replaceAll(Pattern.quote(k),sigPlace.map.get(k)); + } + sb.append(d).append("\n"); + } + Path newf = Files.write(Paths.get(OUTDIR,key,DIRECTORYLISTING_FILENAME),sb.toString().getBytes()); + System.out.println(" Added info for ("+map.size()+") files to "+newf.toAbsolutePath()); } - System.out.println(map); } private static boolean isArticleFile(Path f) { return f.getFileName().toString().contains(".article"); diff --git a/sigServer.java b/sigServer.java index 2fcfbde..53a32d9 100644 --- a/sigServer.java +++ b/sigServer.java @@ -94,10 +94,10 @@ public class sigServer { } } } else { - CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","We're sorry, your webpage is in another castle!".getBytes()); + CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","\nWe're sorry, your webpage is in another castle!".getBytes()); } } else { - CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","We're sorry, your webpage exploded!".getBytes()); + CreateRawRequest(clientOutput,statusCode,statusMsg,"text/html","\nWe're sorry, your webpage exploded!".getBytes()); } clientOutput.write("\r\n\r\n".getBytes()); clientOutput.flush();