~.town / ~cel

loginstats.html.sh

loginstats.html.sh: loginstats.html

#!/bin/sh

code=${LOGINTIME_DIR:-~/Code/logintime}
wtmp=/var/log/wtmp*

export TZ=UTC
export TITLE="User login stats"
./template.html.sh 3<<HEAD <<EOF
<link rel="stylesheet" href="tablesort.css"/>
<script src="tablesort.min.js"></script>
HEAD
<h2>For how much time are people logged in to $(hostname)?</h2>

<p class="pre">Begin: $(date --date=@$($code/sfirst $wtmp))
  End: $(date)</p>

<h3>Daily activity</h3>
<table class="histogram" id="day-by-hour">
<tbody>
  <tr>
	<td colspan="24"><img class="histogram-img" src="images/activity.png"
		alt="24-hour login activity histogram"></td>
  </tr>
</tbody>
<tfoot>
  <tr>
$(seq 0 23 | sed "s/.*/<td>&<\/td>/")
  </tr>
</tfoot>
</table>

<h3>User totals</h3>
<table id="stats">
  <thead>
    <tr>
      <th>#</th>
      <th class="align-right sort-default">d:h:m</th>
      <th>~</th>
    </tr>
  </thead>
<tbody>
$($code/slast $wtmp | awk -f $code/stats.awk | awk '{
  print "<tr><td>" $1 "</td>"\
    "<td class=\"align-right\">" $2 "</td>"\
    "<td><a href=\"/~" $3 "\">" $3 "</a></td></tr>"
}')
</tbody>
</table>
<script>
  new Tablesort(document.getElementById("stats"));
</script>
EOF