-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathirclogger_tohtml
executable file
·177 lines (164 loc) · 5.37 KB
/
irclogger_tohtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
# $1=channel $2=date('%Y-%m-%d,%a') $3=selected_line $4=config_file $5=header
# $6=filename $7=urls_only(true)
set -a
CHAN=$1
if test -e "$4"; then conffile="$4"; . "${conffile%/*}/irclogger_common"
else logsdir=${logsdir:-/var/log/irclogger}
fi
urls=${7:-false}
urls_param=
if test -n "$7"; then urls_param="&urls=true"; fi
case "$6" in /*)logfile="$6";; *)logfile="$PWD/$6";;
esac
case "$3" in
*-*) selstart="${3%%-*}";selend="${3##*-}";;
'') selstart="-1";selend="-1";;
*) let selstart="$3"; let selend="$3";;
esac
date=$2
cd $logsdir/$CHAN
DEFSTYLE='
body {background-color: #ffffff;font: 80% verdana,arial,geneva,helvetica,sans-serif;}
tr.even {background-color: #f0f0f0}
tr.odd {background-color: #e0e0e0}
tr.sep {background-color: #c0c0c0}
td.legend {color: #606060;font: 80%}
tr.irc {background-color: #f7f7f7; font: 80% sans-serif;color: #707070}
tr.selected {background-color: #ffffa5; border:solid;
font: bold 100% sans-serif;color #593a3a }
'
STYLE=
if [ -e ../style.css ]; then STYLE="$STYLE `cat ../style.css`"
fi
if [ -e style.css ]; then STYLE="$STYLE `cat style.css`"
fi
if [ -z "$STYLE" ]; then STYLE="$DEFSTYLE"
fi
navigation () {
local file pdate ndate cdate
ls -1r *log|grep -1 $date|(while read file; do
case "$file" in
$date.log) cdate=$date;;
*) if test -z "$cdate"; then ndate=${file%.log}; else pdate=${file%.log}
fi;;
esac
done
if test -n "$pdate"; then pdate=" <a href='${SCRIPT_NAME%/*}/irclogger_log/$CHAN?date=$pdate$urls_param'>←Prev date</a>"
else pdate=' (first date)'
fi
if test -n "$ndate"; then ndate=" <a href='${SCRIPT_NAME%/*}/irclogger_log/$CHAN?date=$ndate$urls_param'>Next date→</a>"
else ndate=' (last date)'
fi
echo "$pdate$ndate"
if $urls; then
echo " (<b>Showing only urls</b> - <a href='${SCRIPT_NAME%/*}/irclogger_log/$CHAN?date=$date'>See all</a>)"
else
echo " <a
href='${SCRIPT_NAME%/*}/irclogger_log/$CHAN?date=$date&urls=true'>Show only urls</a>"
fi
)
}
if $urls; then time_label='Click on time to show url line in full context'
else time_label='Click on time to select a line by its url'
fi
actions="<table width='100%'><tr><td><a href='${SCRIPT_NAME%/*}/irclogger_logs/${1}'>↑back</a> <a href='${SCRIPT_NAME%/*}/irclogger_log_search/$1'>Search</a>`navigation`<td class=legend align=right>($time_label)</table>"
echo "<html>
<head>
<title>#$1 $2</title>
<style type='text/css'> $STYLE </style>
<link rel=stylesheet href='${SCRIPT_NAME%/*}/irclogger_log_style/$1/${logfile##*/}'>
</head>
<body>
<h1>#$1 $2</h1>
$5
$actions
<hr><table valign=top>
"
omn=-100
owho=""
iseven=true
echo "<tr><th>Who<th>What<th>When"
eol=""
sed -r -e '{
s/&/\&/g
s/</\</g
s/>/\>/g
s/(http|https|ftp):\/\/[-a-zA-Z0-9$_@.&+!*"'"'"'(),%\/;=?~:#]*/<a href="&">&<\/a>/g
s/(<a href=")([^"]*)([.,])(">[^<]*)\3(<\/a>)/\1\2\4\5\3/g
s/(<a href=")([^("]*)([)])(">[^<]*)\3(<\/a>)/\1\2\4\5\3/g
}' | ( curline=0
while read -r time who text;do
let curline=curline+1
# skin lines without urls
if $urls;then case "$text" in *'<a href="'*) :;; *)
omn=-100
continue;;
esac; fi
h=${time:1:2}
m=${time:4:2}
let mn="(${h#0}*60)+${m#0}"
if [ "$who" = "*" ]; then who="${text%% *}"; text="<i>$text</i>"; fi
if [ "$who" = "<WebGate>" -o "$who" = "<Webgate>" ]; then
who="${text%%]*}"; who="${who#[}"
text="${text#*] }"
fi
who="${who%>}";who="${who#<}"
if let 'mn<(omn+5)'; then wakeup=false; else wakeup=true; fi
if let 'mn>=(omn+15)'; then
if [ "$omn" = -100 ]; then seprow=
else
let "dur=mn-omn";dots=
unset idle;let idle='dur%60'
if let 'dur>=60';then let durm='dur/60'; idle="${durm}h$idle";fi
idle="${idle}mn"
while let 'dur>=0';do dots="$dots.";let dur=dur-5;done
seprow="<tr class=sep><td colspan=3><font size=-5>$dots (idle for $idle)</font>"
fi
else seprow=; fi
omn=$mn
let aboveline=curline-4
timelink="<a href='?date=$2&sel=$curline#l$aboveline' class=timelink>$time</a>"
timelinkminor="<a href='?date=$2&sel=$curline#l$aboveline' class=timelinkminor>$time</a>"
if [ "$who" = "$owho" ]; then
if $wakeup; then
echo "$eol"
if let 'selstart>=0 && curline>=selstart && curline<=selend'
then trclass=selected
else trclass=$rowcol
fi
echo "$seprow<tr class=$trclass><td><td><a name=l$curline></a>$text"
eol="<td valign=top align=right><small>$timelink</small>"
else
if let 'selstart>=0 && curline>=selstart && curline<=selend'
then echo "<table><tr class=selected><td><a name=l$curline></a>$text</table>"
else echo "<br><a name=l$curline></a>$text"
fi
fi
else
if $iseven; then rowcol="even"; iseven=false
else rowcol="odd"; iseven=true
fi
owho="$who"
echo "$eol"
if [ "$who" = "***" ]; then class=IRC;rowcol=irc; else class="$who";fi
if let 'selstart>=0 && curline>=selstart && curline<=selend'
then trclass=selected
else trclass=$rowcol
fi
echo "$seprow<tr class=$trclass><td valign=top class=$class>$who<td class=text><a name=l$curline></a>$text"
if $wakeup; then
eol="<td valign=top align=right class=time><small>$timelink</small>"
else
eol="<td valign=top align=right class=time><small>$timelinkminor</small>"
fi
fi
done;echo "$eol")
echo "</table>
<hr>$actions
</body></html>"
exit 0
### EMACS MODES
### Local Variables: ***
### mode:ksh ***
### End: ***