make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / ls2html
blob8d4749179fb73b20d454972e23f143f7d2567e52
1 #!/bin/bash
2 ###########
4 colspan=7
6 ###########
8 is_fs_loop() {
9 expr "$1" : "$2" >/dev/null
12 unslashify() {
13 while expr "${!1}" : ".*//" >/dev/null; do
14 eval "$1=\${$1//\/\//\/}"
15 done
16 [ "${!1: -1}" = / ] && eval "$1=\${$1:0:\$[\${#$1}-1]}"
19 iter() {
20 iterroot=$1
21 unslashify iterroot
22 pwd=$(pwd)
23 declare -a fields
25 find -L "$iterroot" -type d | \
26 while read scandir; do
27 echo -n . >&2
29 echo "<a name=\"$scandir\"></a>"
30 echo "<table>"
31 parent=
32 parents=
33 oldIFS=$IFS
34 IFS=/
35 #for dir in ${wd:1}; do
36 for dir in $scandir; do
37 if [ -z "$dir" ]; then
38 parent=/
39 parents="<a href='#/'>/</a>"
40 else
41 if [ "$parent" = / ]; then
42 parent="/$dir"
43 else
44 parent="$parent${parent:+/}$dir"
46 parents="$parents${parents:+/}<a href='#$parent'>$dir</a>"
48 done
49 IFS=$oldIFS
50 echo "<tr><td colspan=$colspan><h2>$parents</h2></td></tr>"
52 if cd "$scandir"; then
53 #wd=$(pwd)
54 wd=$scandir
56 for f in .* *; do
57 if [ -d "$f" ]; then
58 [ "$f" = . ] && continue
59 if [ "$f" = .. ]; then
60 #stat -c "<tr><td>%A</td><td class=numeric>%h</td><td>%U</td><td>%G</td><td class=numeric>%s</td><td>%y</td><td><a href=\"#$pwd\">${f}</a></td></tr>" "./$f" 2>/dev/null
61 true
62 else
63 href="#${wd}/${f}"
64 if [ -L "$f" ]; then
65 l=$(readlink -n -e "./$f")
66 is_fs_loop "$l" "$base" && href="#$l"
68 fields=($(stat -c "%A %h %U %G %s %Y" "./$f" 2>/dev/null))
69 fields[5]=`date -d@${fields[5]}`
70 printf "<tr><td>%s</td><td class=numeric>%s</td><td>%s</td><td>%s</td><td class=numeric>%s</td><td>%s</td><td><a href=\"%s\">%s</a></td></tr>\n" "${fields[@]}" "$href" "$f"
73 done
74 for f in .* *; do
75 if [ ! -d "$f" ]; then
76 fields=($(stat -c "%A %h %U %G %s %Y" "./$f" 2>/dev/null))
77 fields[5]=`date -d@${fields[5]}`
78 printf "<tr><td>%s</td><td class=numeric>%s</td><td>%s</td><td>%s</td><td class=numeric>%s</td><td>%s</td><td>%s</td></tr>\n" "${fields[@]}" "$f"
80 done
81 echo "</table>"
82 #for f in .* *; do
83 # if [ "$f" != . -a "$f" != .. -a -d "$f" ]; then
84 # if [ -L "$f" ] && is_fs_loop "$(readlink -n -e "./$f")" "$base"; then
85 # true
86 # else
87 # iter "$f"
88 # fi
89 # fi
90 #done
92 #cd ..
93 cd "$pwd"
94 else
95 echo "<tr><td colspan=$colspan><i>Can't change directory: $scandir</i></tr>"
96 echo "</table>"
98 done
99 return 0
102 # HEADER
103 echo "<html>
104 <head>
105 <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
106 <style>
107 table {
108 border: 1px solid black;
109 margin-bottom: 6px;
111 tr:not(:first-child):hover td {
112 background: lightblue;
114 tr:first-child a {
115 text-decoration: none;
117 tr:first-child a:hover {
118 background: lightblue;
120 tr:nth-child(odd) {
121 background: #b0b0b0;
123 tr:nth-child(even) {
124 background: #e0e0e0;
126 td.numeric {
127 text-align: right;
129 td:first-child:not([colspan]) {
130 letter-spacing: -1.5pt;
131 font-family: monospace;
133 h2 {
134 margin: 0;
136 td:not(:last-child) {
137 white-space: nowrap;
139 </style>
140 </head>
141 <body>
144 [ -z "$1" ] && set .
146 # CONTENT
147 while [ -n "$1" ]; do
148 base=$(readlink -n -f "$1")
149 iter "$1"
150 shift
151 done
152 echo >&2
154 # FOOTER
155 echo "<p align=right><hr>Made by <em>ls2html</em>.</p>
156 </body>
157 </html>"