[tarent-useful-scripts SCM] git branch master updated. 4769223915c30587c962b0606abdace4931c2d83

mirabilos at evolvis.org mirabilos at evolvis.org
Wed May 21 15:07:20 CEST 2014


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main git repository for Evolvis project useful-scripts".

The branch, master has been updated
       via  4769223915c30587c962b0606abdace4931c2d83 (commit)
       via  df82e87bfc2b96def56f5e0aa721766c397e048f (commit)
      from  6e46fcc44bee12f59e6fa121fc6cb08a71ddad03 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4769223915c30587c962b0606abdace4931c2d83
Author: Thorsten Glaser <t.glaser at tarent.de>
Date:   Wed May 21 15:07:04 2014 +0200

    reporting server, vaguely anonymised and without .htaccess

commit df82e87bfc2b96def56f5e0aa721766c397e048f
Author: Thorsten Glaser <t.glaser at tarent.de>
Date:   Wed May 21 15:04:01 2014 +0200

    add (anonymised) reporting VBscript
    
    • schtaskp.exe is schtasks.exe portable across Windows® versions
      and thus cannot be freely distributed; just use your own version’s
      schtasks.exe in its stead
    • you need a reporting server

-----------------------------------------------------------------------

Summary of changes:
 tarentET/client-win/wincktfn.vbs |  257 +++++++++++++++++++++++++++
 tarentET/client-win/wincktsk.bat |    3 +
 tarentET/client-win/wincktsk.inf |  117 +++++++++++++
 tarentET/server/overview.cgi     |  354 ++++++++++++++++++++++++++++++++++++++
 tarentET/server/report.cgi       |  327 +++++++++++++++++++++++++++++++++++
 5 files changed, 1058 insertions(+)
 create mode 100644 tarentET/client-win/wincktfn.vbs
 create mode 100644 tarentET/client-win/wincktsk.bat
 create mode 100644 tarentET/client-win/wincktsk.inf
 create mode 100755 tarentET/server/overview.cgi
 create mode 100755 tarentET/server/report.cgi

diff --git a/tarentET/client-win/wincktfn.vbs b/tarentET/client-win/wincktfn.vbs
new file mode 100644
index 0000000..c94c6ff
--- /dev/null
+++ b/tarentET/client-win/wincktfn.vbs
@@ -0,0 +1,257 @@
+' $Id: wincktfn.vbs 3875 2013-12-11 13:39:34Z tglase $
+' -
+' Copyright (c) 2011, 2012, 2013
+'	Thorsten Glaser <t.glaser at tarent.de>
+'
+' Provided that these terms and disclaimer and all copyright notices
+' are retained or reproduced in an accompanying document, permission
+' is granted to deal in this work without restriction, including un-
+' limited rights to use, publicly perform, distribute, sell, modify,
+' merge, give away, or sublicence.
+'
+' This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
+' the utmost extent permitted by applicable law, neither express nor
+' implied; without malicious intent or gross negligence. In no event
+' may a licensor, author or contributor be held liable for indirect,
+' direct, other damage, loss, or other issues arising in any way out
+' of dealing in the work, even if advised of the possibility of such
+' damage or existence of a defect, except proven that it results out
+' of said person's immediate fault when using the work as intended.
+
+debg = False
+vsn = "$Revision: 3875 $"
+
+set re = new regexp
+re.pattern = "^.* ([0-9]*) .*$"
+set matches = re.execute(vsn)
+vsn = matches(0).submatches(0)
+
+function regread(ByRef wss, key)
+	on error resume next
+	res = ""
+	res = trim(wss.RegRead(key))
+	regread = res
+end function
+
+function getescaped(intro, dbgas, values)
+	on error resume next
+	res = ""
+	for each value in values
+		if debg then wscript.echo dbgas, value
+		if trim(value) <> "" then res = res + intro + escape(value)
+	next
+	getescaped = res
+end function
+
+function gettimezone()
+	gesetzt = 0
+	for each os in GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
+		z = os.CurrentTimeZone
+		if z < 0 then
+			tz = "-"
+			z = -z
+		else
+			tz = "+"
+		end if
+		tz = tz + right("00" & (z / 60), 2) + right("00" & (z mod 60), 2)
+		if gesetzt = 0 then gettimezone = tz : gesetzt = 1
+	next
+	if gesetzt = 0 then gettimezone = "(unknown time zone)"
+end function
+
+function shl(ByVal ax, cl)
+	for i=1 to cl
+		ax = ax * 2
+	next
+	shl = ax
+end function
+
+function shr(ByVal ax, cl)
+	for i=1 to cl
+		ax = ax \ 2
+	next
+	shr = ax
+end function
+
+function urlhex(c)
+	if c < 16 then res = "%0" else res = "%"
+	urlhex = res + hex(c)
+end function
+
+function urlstr(s)
+	res = ""
+	for i = 1 to len(s)
+		c = mid(s, i, 1)
+		wc = ascW(c)
+
+		' Interesting brokenness: ascW returns signed short
+		if wc < 0 then wc = wc + 65536
+
+		if wc < 128 then
+			res = res + escape(c)
+		elseif wc < 2048 then
+			c1 = shr(wc, 6) or &hC0
+			c2 = (wc and &h3F) or &h80
+			res = res + urlhex(c1) + urlhex(c2)
+		else
+			c1 = shr(wc, 12) or &hE0
+			c2 = (shr(wc, 6) and &h3F) or &h80
+			c3 = (wc and &h3F) or &h80
+			res = res + urlhex(c1) + urlhex(c2) + urlhex(c3)
+		end if
+	next
+	urlstr = res
+end function
+
+argstr = "tarent-windows r" + vsn
+blau = ""
+
+set wss = CreateObject("WScript.Shell")
+
+osver = regread(wss, "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProductName")
+if left(osver, 10) = "Microsoft " then osver=mid(osver, 11)
+osrev = regread(wss, "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CurrentVersion")
+osver = osver + " (" + osrev
+osver = osver + ", " + regread(wss, "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\CSDVersion")
+osver = osver + ")"
+
+set WshNetwork = CreateObject("WScript.Network")
+set WMIService = GetObject("winmgmts:!\\.\root\cimv2")
+
+gesetzt = 0
+set processors = WMIService.ExecQuery("SELECT * FROM Win32_Processor")
+for each cpu in processors
+	if gesetzt = 0 then
+		select case cpu.architecture
+		case 0
+			argstr = argstr + " (i386)"
+			gesetzt = 1
+		case 1
+			argstr = argstr + " (mips)"
+			gesetzt = 1
+
+		case 2
+			argstr = argstr + " (alpha32)"
+			gesetzt = 1
+
+		case 3
+			argstr = argstr + " (powerpc)"
+			gesetzt = 1
+
+		case 4
+			argstr = argstr + " (shx)"
+			gesetzt = 1
+
+		case 5
+			argstr = argstr + " (arm)"
+			gesetzt = 1
+
+		case 6
+			argstr = argstr + " (IA64)"
+			gesetzt = 1
+		case 7
+			argstr = argstr + " (alpha)"
+			gesetzt = 1
+
+		case 8
+			argstr = argstr + " (MSIL)"
+			gesetzt = 1
+
+		case 9
+			argstr = argstr + " (amd64)"
+			gesetzt = 1
+		case 10
+			argstr = argstr + " (ia32w64)"
+			gesetzt = 1
+
+		end select
+	end if
+next
+if gesetzt = 0 then argstr = argstr + " (unknown)"
+
+argstr = argstr + "%0A" + osver + "%0A"
+if debg then wscript.echo "Running on:", osver
+
+argstr = argstr + "%0Acurrent time%09" + FormatDateTime(Now()) + " " + gettimezone()
+
+ntpsvr = regread(wss, "HKLM\SYSTEM\CurrentControlSet\Services\W32Time\Parameters\NtpServer")
+if ntpsvr <> "" then argstr = argstr + "%0ANTP Server%09" + ntpsvr
+
+if debg then wscript.echo "NTP Server:", ntpsvr
+
+check_antivir = 0
+if check_antivir <> 0 then
+	avversion = ""
+	gesetzt = regread(wss, "HKLM\SOFTWARE\Avira\AntiVir Server\EngineVersion")
+	if gesetzt <> "" then avversion = "Server Native " + gesetzt
+	if avversion = "" then
+		gesetzt = regread(wss, "HKLM\SOFTWARE\Wow6432Node\Avira\AntiVir Server\EngineVersion")
+		if gesetzt <> "" then avversion = "Server W32oW64 " + gesetzt
+	end if
+	if avversion = "" then
+		gesetzt = regread(wss, "HKLM\SOFTWARE\Avira\AntiVir Desktop\EngineVersion")
+		if gesetzt <> "" then avversion = "Desktop Native " + gesetzt
+	end if
+	if avversion = "" then
+		gesetzt = regread(wss, "HKLM\SOFTWARE\Wow6432Node\Avira\AntiVir Desktop\EngineVersion")
+		if gesetzt <> "" then avversion = "Desktop W32oW64 " + gesetzt
+	end if
+	if avversion = "" then
+		avversion = "not installed"
+		blau = "!"
+	end if
+	argstr = argstr + "%0AH+BEDV AntiVir%09" + avversion
+end if
+
+set netconfigs = WMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=True")
+
+hn = WshNetwork.ComputerName
+mac = ""
+
+dim ipaddrs()
+dim netmsks()
+for each nic in netconfigs
+	if mac = "" then mac = nic.MACAddress
+	argstr = argstr + "%0A%0A" + urlstr(nic.caption)
+	argstr = argstr + "%0All address%09" + escape(nic.MACAddress)
+	if debg then wscript.echo nic.MACAddress + " " + nic.caption
+	ips = 0
+	nms = 0
+	for each ip in nic.IPAddress
+		ips = ips + 1
+		redim preserve ipaddrs(ips)
+		ipaddrs(ips) = ip
+		if debg then wscript.echo "IP#", ips, "= " + ip
+	next
+	for each ip in nic.IPSubnet
+		nms = nms + 1
+		redim preserve netmsks(nms)
+		netmsks(nms) = ip
+		if debg then wscript.echo "NM#", nms, "= " + ip
+	next
+	for i = 1 to ips
+		if ipaddrs(i) <> "" then
+			argstr = argstr + "%0AIP/netmask%09"
+			nm = ""
+			if i <= nms then nm = " / " + escape(netmsks(i))
+			argstr = argstr + escape(ipaddrs(i)) + nm
+		end if
+	next
+	argstr = argstr + getescaped("%0Adefault gw%09", "GW", nic.DefaultIPGateway)
+	argstr = argstr + "%0ADHCP used?%09" + escape(nic.DHCPEnabled)
+next
+
+tzofs = regread(wss, "HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias")
+utnow = DateAdd("n", tzofs, Now())
+
+uri = "http://reportingsystem.tarent.de/cgi-bin/report.cgi?8,"
+uri = uri & DateDiff("s", "01/01/1970 00:00:00", utnow)
+uri = uri + "/,0,4,WinNT:" + osrev + ","
+uri = uri + mac + "," + blau + hn + "," + argstr
+
+set hr = CreateObject("WinHttp.WinHttpRequest.5.1")
+hr.open "GET", uri
+hr.SetCredentials "httpbasicauthuser", "httpbasicauthpass", 0
+hr.send
+wscript.echo hr.ResponseText
+wscript.quit
diff --git a/tarentET/client-win/wincktsk.bat b/tarentET/client-win/wincktsk.bat
new file mode 100644
index 0000000..b3484cd
--- /dev/null
+++ b/tarentET/client-win/wincktsk.bat
@@ -0,0 +1,3 @@
+REM $Id: wincktsk.bat 1779 2011-03-14 13:15:58Z tglase $
+REM
+cscript /nologo wincktfn.vbs
diff --git a/tarentET/client-win/wincktsk.inf b/tarentET/client-win/wincktsk.inf
new file mode 100644
index 0000000..77ed8e7
--- /dev/null
+++ b/tarentET/client-win/wincktsk.inf
@@ -0,0 +1,117 @@
+; $Id: wincktsk.inf 2678 2012-01-17 12:08:24Z tglase $
+; -
+; Copyright (c) 2011, 2012
+;	Thorsten Glaser <t.glaser at tarent.de>
+;
+; Provided that these terms and disclaimer and all copyright notices
+; are retained or reproduced in an accompanying document, permission
+; is granted to deal in this work without restriction, including un-
+; limited rights to use, publicly perform, distribute, sell, modify,
+; merge, give away, or sublicence.
+;
+; This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
+; the utmost extent permitted by applicable law, neither express nor
+; implied; without malicious intent or gross negligence. In no event
+; may a licensor, author or contributor be held liable for indirect,
+; direct, other damage, loss, or other issues arising in any way out
+; of dealing in the work, even if advised of the possibility of such
+; damage or existence of a defect, except proven that it results out
+; of said person's immediate fault when using the work as intended.
+; -
+; Installer for "tarent-E.T. for Windows NT"
+
+[Version]
+Signature=$CHICAGO$
+
+[DestinationDirs]
+STaddWindir=10
+SToldSystem=11
+ETaddSystem=11
+EToldSystem=11
+STaddINF=17
+EToldINF=17
+
+[DefaultInstall]
+CopyFiles=STaddWindir,ETaddSystem,STaddINF
+DelFiles=SToldSystem,EToldSystem,EToldINF
+AddReg=ETaddReg,NTPaddReg,MISCaddReg
+
+[STRemove]
+DelFiles=STaddWindir,STaddINF
+DelReg=STdelReg
+
+[ETRemove]
+AddReg=ETaddRegPostuninst
+DelFiles=ETaddSystem
+DelReg=ETdelReg
+
+[STaddWindir]
+schtaskp.exe
+
+[SToldSystem]
+schtaskp.exe
+
+[ETaddSystem]
+wincktfn.vbs
+wincktsk.bat
+
+[EToldSystem]
+; drop files from an older version
+wincktsk.vbs
+
+[STaddINF]
+wincktsk.inf
+
+[EToldINF]
+; drop files from an older version
+wckt2003.inf
+wxpcktsk.inf
+
+[ETaddReg]
+; postinstall
+HKLM,Software\Microsoft\Windows\CurrentVersion\RunOnce,"tarentETcron",,"%10%\schtaskp.exe /create /tn tarent-ET /tr wincktsk.bat /sc MINUTE /mo 10 /st 00:00:00 /et 23:59 /ru System /f"
+; uninstallation information
+HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\schtaskp2k,"QuietDisplayName",,"schtaskp (needed by tarent-E.T.) Task Scheduler for win2k+"
+HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\schtaskp2k,"QuietUninstallString",,"rundll32 setupapi.dll,InstallHinfSection STRemove 132 wincktsk.inf"
+HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\tarentET,"DisplayName",,"tarent-E.T."
+HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\tarentET,"UninstallString",,"rundll32 setupapi.dll,InstallHinfSection ETRemove 132 wincktsk.inf"
+
+[NTPaddReg]
+; configuration
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\Config,"UpdateInterval",0x10001,12000
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\Parameters,"AvoidTimeSyncOnWan",0x10001,0
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\Parameters,"NtpServer",,"ntp.tarent.de,0x1 entp.tarent.de,0x1 2.europe.pool.ntp.org,0x2"
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\Parameters,"Period",0x10001,144
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\Parameters,"Type",,"NTP"
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient,"CrossSiteSyncFlags",0x10001,2
+HKLM,SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpClient,"SpecialPollInterval",0x10001,360
+; postinstall
+HKLM,Software\Microsoft\Windows\CurrentVersion\RunOnce,"tarentETntp",,"%11%\w32tm.exe /config /update"
+
+[MISCaddReg]
+HKLM,Software\Microsoft\Windows NT\CurrentVersion\Winlogon,"DefaultDomainName",,"TARENT"
+
+[ETaddRegPostuninst]
+; postuninstall
+HKLM,Software\Microsoft\Windows\CurrentVersion\RunOnce,"tarentETcron",,"%10%\schtaskp.exe /delete /tn tarent-ET /f"
+
+[STdelReg]
+; drop the entire key
+HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\schtaskp2k
+
+[ETdelReg]
+; drop the entire key
+HKLM,SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\tarentET
+
+[SourceDisksNames]
+1=%DiskName%,tarentET,0
+
+[SourceDisksFiles]
+schtaskp.exe=1,,161280
+wincktfn.vbs=1,,6937
+wincktsk.bat=1,,90
+wxpcktsk.inf=1,,3998
+
+[Strings]
+Author="mirabilos"
+DiskName="tarent-E.T. Installation Floppy"
diff --git a/tarentET/server/overview.cgi b/tarentET/server/overview.cgi
new file mode 100755
index 0000000..5e6641b
--- /dev/null
+++ b/tarentET/server/overview.cgi
@@ -0,0 +1,354 @@
+#!/bin/mksh
+# $Id: overview.cgi 3963 2014-03-24 12:17:13Z tglase $
+#-
+# Copyright © 2009, 2010, 2011, 2014
+#	Thorsten Glaser <t.glaser at tarent.de>
+# Licenced under the AGPLv3
+
+export LC_ALL=C TZ=Europe/Berlin
+unset LANG LANGUAGE
+
+cd /var/lib/checktask-server
+
+function htmlencode {
+	print -nr -- "$@" | sed \
+	    -e 's/&/\&/g' \
+	    -e 's/</\</g' \
+	    -e 's/>/\>/g'
+}
+
+set -A files -- cooked.*
+
+if (( ${#files[*]} == 0 )); then
+	print Content-type: text/plain
+	print
+	print Sorry, cannot find any data files.
+	exit 0
+fi
+
+cat <<-'EOF'
+	Content-type: text/html; charset=utf-8
+
+	<?xml version="1.0"?>
+	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+	 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
+	<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"><head>
+	 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+	 <title>Overview of all checktask’d hosts</title>
+	 <style type="text/css">
+	  table {
+	   border:1px solid black;
+	   border-collapse:collapse;
+	   text-align:left;
+	   vertical-align:top;
+	  }
+	  tr {
+	   border:1px solid black;
+	   text-align:left;
+	   vertical-align:top;
+	  }
+	  td {
+	   border:1px solid black;
+	   text-align:left;
+	   vertical-align:top;
+	  }
+	  th {
+	   background-color:#333333;
+	   color:#FFFFFF;
+	  }
+	  .tha {
+	   color:#9999FF;
+	  }
+	  .pms {
+	   border:1px solid grey;
+	   margin:1px 7px 1px 1px;
+	   padding:3px 3px 3px 3px;
+	  }
+	  .greyed {
+	   color:#666666;
+	  }
+	  .bwinverse {
+	   color:#FFFFFF;
+	   background-color:#000000;
+	  }
+	  .bwnormal {
+	   color:#000000;
+	   background-color:#FFFFFF;
+	  }
+	  .grey {
+	   color:#000000;
+	   background-color:#CCCCCC;
+	  }
+	  .blue {
+	   color:#FFFFFF;
+	   background-color:#0000FF;
+	  }
+	  .green {
+	   color:#000000;
+	   background-color:#00FF00;
+	  }
+	  .yellow {
+	   color:#000000;
+	   background-color:#FFFF00;
+	  }
+	  .orange {
+	   color:#000000;
+	   background-color:#F87217;
+	  }
+	  .red {
+	   color:#FFFFFF;
+	   background-color:#FF0000;
+	  }
+	  .ip {
+	   font-size:80%;
+	  }
+	  .ttype {
+	   font-size:85%;
+	  }
+	  .tsval {
+	   font-size:80%;
+	  }
+	  .ipdom {
+	   font-size:75%;
+	  }
+	 </style>
+	 <script type="text/javascript">//<![CDATA[
+	  function klappen(nr, shnr, tsnr, wie) {
+	   var el = document.getElementById("pms" + nr);
+	   var bn = document.getElementById("txt" + nr);
+
+	   if (wie == "0")
+	    bn.style.display = "block";
+	   else if (wie == "1")
+	    bn.style.display = "none";
+
+	   if (bn.style.display == "none") {
+	    bn.style.display = "block";
+	    el.firstChild.nodeValue = "[-]";
+	    wie = '1';
+	   } else {
+	    bn.style.display = "none";
+	    el.firstChild.nodeValue = "[+]";
+	    wie = '0';
+	   }
+	   el.className = "pms";
+	   if (shnr != '') {
+	    shrev(shnr, wie);
+	   }
+	   if (tsnr != '') {
+	    tsrev(tsnr, wie);
+	   }
+	  }
+
+	  function shrev(nr, wie) {
+	   var el = document.getElementById("rev" + nr);
+	   var bn = document.getElementById("dns" + nr);
+
+	   if (wie == "0")
+	    bn.style.display = "block";
+	   else if (wie == "1")
+	    bn.style.display = "none";
+
+	   if (bn.style.display == "none") {
+	    bn.style.display = "block";
+	    el.firstChild.nodeValue = "[-]";
+	    wie = '1';
+	   } else {
+	    bn.style.display = "none";
+	    el.firstChild.nodeValue = "[+]";
+	    wie = '0';
+	   }
+	   el.className = "rev";
+	  }
+
+	  function tsrev(nr, wie) {
+	   var bn = document.getElementById("tsv" + nr);
+
+	   if (wie == "0")
+	    bn.style.display = "block";
+	   else if (wie == "1")
+	    bn.style.display = "none";
+
+	   if (bn.style.display == "none") {
+	    bn.style.display = "block";
+	   } else {
+	    bn.style.display = "none";
+	   }
+	  }
+	 //]]></script>
+	</head><body>
+	<h1>Overview of all checktask’d hosts</h1>
+EOF
+print "<p>This page was generated on: $(htmlencode $(TZ=Europe/Berlin date))</p>"
+cat <<-'EOF'
+	<p><a href="#" onclick="javascript:alle_klappen('1', '1');">Expand
+	 all</a> (<a href="#" onclick="javascript:alle_klappen('1',
+	 '0');">DNS/MAC only</a>) or <a onclick="javascript:alle_klappen('0',
+	 '0');" href="#">Unexpand all</a>;
+	 click on a <tt>[-]</tt> or <tt>[+]</tt> to toggle extra text.</p>
+	<table border="1" width="100%">
+	<thead>
+	 <tr>
+	  <th colspan="2" style="font-size:80%; vertical-align:bottom;"><b><a class="tha" href="overview.cgi?s=ip">IPv4</a>, DNS, <a class="tha" href="overview.cgi?s=ll">MAC</a></b></th>
+	  <th><a class="tha" href="overview.cgi?s=tt">Type</a></th>
+	  <th><a class="tha" href="overview.cgi?s=hn">FQDN</a></th>
+	  <th><a class="tha" href="overview.cgi?s=ts">Last Valid</a></th>
+	  <th>Information String</th>
+	 </tr>
+	</thead><tbody>
+EOF
+
+cbgred="#FF0000";	cfgred="#FFFFFF"
+cbgyellow="#FFFF00";	cfgyellow="#000000"
+cbggreen="#00FF00";	cfggreen="#000000"
+cbgblue="#0000FF";	cfgblue="#FFFFFF"
+cbgblueold="#0000FF";	cfgblueold="#CCCC00"
+cbggrey="#CCCCCC";	cfggrey="#000000"
+
+integer nummern=0 revnr=1 tsnrn=0
+
+sortargs=-r	# by default, sort by tsval
+if [[ ,$QUERY_STRING, = *,s=ip,* ]]; then
+	sortargs=-k3
+elif [[ ,$QUERY_STRING, = *,s=hn,* ]]; then
+	sortargs='-k4,4 -k3'
+elif [[ ,$QUERY_STRING, = *,s=ll,* ]]; then
+	sortargs='-k5,5 -k3'
+elif [[ ,$QUERY_STRING, = *,s=tt,* ]]; then
+	sortargs='-k6,6 -k3'
+elif [[ ,$QUERY_STRING, = *,s=ts,* ]]; then
+	sortargs=-r
+fi
+
+older=''
+print "$(date -d '1 hour ago' +'%Y-%m-%d %H:%M') FFFFFFFF - " | \
+    cat - "${files[@]}" | sort -r | while IFS= read -r line; do
+	if [[ $line = *''* ]]; then
+		older='' # older than an hour
+		continue
+	fi
+	print -r -- "$line" | tr '' "$older"
+done | sort $sortargs | sed -ne '/^.* /s///p' |&
+while IFS= read -pr line; do
+	tsnr=''
+	nummer=
+	[[ $line = *''* ]] && nummer=$((++nummern))
+	[[ $line = *''* ]] && tsnr=$((++tsnrn))
+	jsbeg="<tt id=\"pms$nummer\" onclick=\"klappen('$nummer', '$revnr', '$tsnr', '');\"> </tt>"
+	jsmid="<pre id=\"txt$nummer\">"
+	jsend="</pre>"
+	dmbeg="id=\"rev$revnr\" onclick=\"shrev('$revnr', '');\"> </td>"
+	dmmid="<tt style=\"font-size:x-small;\" id=\"dns$revnr\">"
+	dmend="</tt>"
+	tsbeg="<td class=\"tsval "
+	tsmid="\" onclick=\"tsrev('$tsnr', '');\">"
+	tsend="<pre id=\"tsv$tsnr\">"
+	let ++revnr
+
+	sed \
+	    -e "s/;/$cbgred; color:$cfgred;/g" \
+	    -e "s/;/$cbgyellow; color:$cfgyellow;/g" \
+	    -e "s/;/$cbggreen; color:$cfggreen;/g" \
+	    -e "s/;/$cbgblue; color:$cfgblue;/g" \
+	    -e "s/;/$cbggrey; color:$cfggrey;/g" \
+	    -e "s/;/$cbgblueold; color:$cfgblueold;/g" \
+	    -e "s\(.*\)\(.*\)${dmbeg}\1${dmmid}\2${dmend}g" \
+	    -e "s\(.*\)\(.*\)${jsbeg}\1${jsmid}\2${jsend}g" \
+	    -e "s\(.*\)\(.*\)${tsbeg}\1${tsmid}\2${tsend}g" \
+	    <<<"$line" | tr '' '\n'
+done
+
+cat <<-'EOF'
+	</tbody>
+	</table>
+	<p><a href="#" onclick="javascript:alle_klappen('1', '1');">Expand
+	 all</a> (<a href="#" onclick="javascript:alle_klappen('1',
+	 '0');">DNS/MAC only</a>) or <a onclick="javascript:alle_klappen('0',
+	 '0');" href="#">Unexpand all</a>;
+	 click on a <tt>[-]</tt> or <tt>[+]</tt> to toggle extra text.</p>
+	<p>Note: on both FQDNs and PTR RRs, the DNS search suffix is cut off.</p>
+	<script type="text/javascript">//<![CDATA[
+	 function alle_klappen(dnsmac, etext) {
+EOF
+cat <<-EOF
+	  for (var i = 1; i <= $nummern; ++i)
+	   klappen(i, '', '', etext);
+	  for (var i = 1; i < $revnr; ++i)
+	   shrev(i, dnsmac);
+	  for (var i = 1; i <= $tsnrn; ++i)
+	   tsrev(i, etext);
+EOF
+cat <<-'EOF'
+	 }
+
+	 alle_klappen('0', '0');	// initially at page load
+	//]]></script>
+	<hr />
+	<h2>Legende</h2>
+	<table style="border:medium outset violet; padding:3px;">
+	<tr>
+		<th>Colour</th>
+		<th>IP/DNS/MAC</th>
+		<th>FQDN</th>
+		<th>Timestamp</th>
+	</tr><tr>
+		<td class="bwinverse">inverse</td>
+		<td>-</td>
+		<td>-</td>
+		<td>no NTP; delta > 30 seconds</td>
+	</tr><tr>
+		<td class="bwnormal">normal</td>
+		<td>-</td>
+		<td>normal system</td>
+		<td>NTP delta < 128 ms</td>
+	</tr><tr>
+		<td class="greyed">greyed out</td>
+		<td>-</td>
+		<td>-</td>
+		<td>no time delta reported</td>
+	</tr><tr>
+		<td class="grey">grey</td>
+		<td>DHCP</td>
+		<td>DHCP</td>
+		<td>no NTP; delta < 30 seconds</td>
+	</tr><tr>
+		<td style="color:#CCCC00; background-color:#0000FF;">yellow/blue</td>
+		<td>blue, older than 1 hour</td>
+		<td>-</td>
+		<td>-</td>
+	</tr><tr>
+		<td class="blue">blue</td>
+		<td>flagged as “needs attention”</td>
+		<td>-</td>
+		<td>NTP delta < 5 seconds</td>
+	</tr><tr>
+		<td class="green">green</td>
+		<td>not flagged</td>
+		<td>-</td>
+		<td>NTP delta < 500 ms</td>
+	</tr><tr>
+		<td class="yellow">yellow</td>
+		<td>green, older than 1 hour</td>
+		<td>short hostname not FQDN</td>
+		<td>NTP delta < 1 second</td>
+	</tr><tr>
+		<td class="orange">orange</td>
+		<td>-</td>
+		<td>broken FQDN, run mkhosts(1)</td>
+		<td>NTP delta < 1 minute</td>
+	</tr><tr>
+		<td class="red">red</td>
+		<td>hard error in QUERY_STRING, or no MAC address found on eth0</td>
+		<td>invalid hostname, run mkhosts(1) immediately</td>
+		<td>NTP delta > 1 minute</td>
+	</tr>
+	</table>
+	<hr />
+	<p style="font-size:small;">Generated by
+	 <tt style="white-space:nowrap;">$Id: overview.cgi 3963 2014-03-24 12:17:13Z tglase $</tt></p>
+	<div class="footer"><a href="http://validator.w3.org/check/referer"><img
+	 src="http://www.w3.org/Icons/valid-xhtml11" alt="Valid XHTML 1.1"
+	 style="border:0px;" height="31" width="88" /></a></div>
+	</body></html>
+EOF
+exit 0
diff --git a/tarentET/server/report.cgi b/tarentET/server/report.cgi
new file mode 100755
index 0000000..622c405
--- /dev/null
+++ b/tarentET/server/report.cgi
@@ -0,0 +1,327 @@
+#!/bin/mksh
+# $Id: report.cgi 3963 2014-03-24 12:17:13Z tglase $
+#-
+# Copyright © 2009, 2010, 2011, 2012, 2013, 2014
+#	Thorsten Glaser <t.glaser at tarent.de>
+# Licenced under the AGPLv3
+
+export LC_ALL=C TZ=Europe/Berlin
+unset LANG LANGUAGE
+
+cd /var/lib/checktask-server
+
+if [[ $REMOTE_ADDR != +([0-9]).+([0-9]).+([0-9]).+([0-9]) ]]; then
+	logger -t checktasks-report "rc=500 IP<$REMOTE_ADDR> QS<$QUERY_STRING>"
+	print Status: 500 wrong input
+	exit 1
+fi
+
+if [[ $REMOTE_ADDR = @(195.71.200.162|172.28.1.14) ]]; then
+	print Status: 402 Payment Required
+	print Content-type: text/plain
+	print
+	print FAIL because ... are no longer managed by us.
+	exit 0
+fi
+
+qs=$QUERY_STRING
+tslval=$(date +'%s')
+tsval=$tslval
+if [[ $qs = 8,+([0-9/.-]),* ]]; then
+	qs=${qs#8,}
+	tsqs=${qs%%,*}
+	qs=7,${qs#*,}
+else
+	tsqs=
+fi
+if [[ $qs = 7,?(-)+([0-9]),* ]]; then
+	qs=${qs#7,}
+	deltat=${qs%%,*}
+	qs=${qs#*,}
+	(( tsval -= deltat ))
+fi
+tsval=$(date -d @$tsval +'%Y-%m-%d %H:%M')
+
+if [[ $qs = 1,?([~!])+([a-zA-Z0-9._-]),* || \
+    $qs = [23],,?([~!])+([a-zA-Z0-9._-]),* || \
+    $qs = 4,+([0-9a-zA-Z:.]),,?([~!])+([a-zA-Z0-9._-]),* ]]; then
+	logger -t checktasks-report "rc=NOMAC IP<$REMOTE_ADDR> QS<$QUERY_STRING>"
+	typeset -Uui16 -Z5 hexval
+	remote_lladdr=ff:ff
+	save_IFS=$IFS
+	IFS=.
+	for i in $REMOTE_ADDR; do
+		let hexval=10#$i
+		remote_lladdr=$remote_lladdr:${hexval#16#}
+	done
+	IFS=$save_IFS
+elif [[ $qs = 4,+([0-9a-zA-Z:.]),*([0-9a-fA-F:]),?([~!])+([a-zA-Z0-9._-]),* ]]; then
+	logger -t checktasks-report "rc=OK IP<$REMOTE_ADDR> QS<$QUERY_STRING>"
+	remote_lladdr=${qs#4,+([0-9a-zA-Z:.]),}
+	remote_lladdr=${remote_lladdr%%,*}
+elif [[ $qs = 2,*([0-9a-fA-F:]),?([~!])+([a-zA-Z0-9._-]),* ]]; then
+	logger -t checktasks-report "rc=OLD IP<$REMOTE_ADDR> QS<$QUERY_STRING>"
+	remote_lladdr=${qs#2,}
+	remote_lladdr=${remote_lladdr%%,*}
+elif [[ $qs = 3,*([0-9a-fA-F:]),?([~!])+([a-zA-Z0-9._-]),* ]]; then
+	logger -t checktasks-report "rc=DHCP IP<$REMOTE_ADDR> QS<$QUERY_STRING>"
+	remote_lladdr=${qs#3,}
+	REMOTE_ADDR=${remote_lladdr#*,}
+	qs=${REMOTE_ADDR#*,}
+	REMOTE_ADDR=${REMOTE_ADDR%%,*}
+	remote_lladdr=${remote_lladdr%%,*}
+	qs=3,$remote_lladdr,$qs
+else
+	logger -t checktasks-report "rc=FAIL IP<$REMOTE_ADDR> QS<$QUERY_STRING>"
+	rc=FAIL
+	print Content-type: text/plain
+	print
+	print -r -- $rc "$QUERY_STRING"
+	exit 0
+fi
+
+typeset -u remote_lladdr
+rc=OK
+outf=cooked.$remote_lladdr
+ipdot=$REMOTE_ADDR
+
+print Content-type: text/plain
+print
+print -r -- $rc "$QUERY_STRING"
+
+# for debugging, append stderr now
+exec 2>&1
+
+function iptohex {
+	local i h a save_IFS
+	typeset -Uui n
+
+	save_IFS=$IFS; IFS=.; set -A a -- $1; IFS=$save_IFS
+	h=0x
+	for i in 0 1 2 3; do
+		(( n = 0x100 + 10#${a[i]} ))
+		(( n < 0x100 || n > 0x1FF )) && return 1
+		h=$h${n#16#1}
+	done
+	print $h
+}
+
+function fqdnfix {
+	local fqdn=$1
+
+	[[ $fqdn = *.tarent.buero ]] && \
+	    fqdn=${fqdn%%.tarent.buero}.berlin.tarent.de
+	fqdn=${fqdn/.tarent.//}
+	fqdn=${fqdn/%.unbelievable-machine.net/\~UM}
+	fqdn=${fqdn/%.pool.mediaWays.net/\~Viag}
+	fqdn=${fqdn/%.dip0.t-ipconnect.de/\~Tdip}
+	print -r -- "$fqdn"
+}
+
+function url2html {
+	print -n -- $(print -nr -- "$@" | sed -e 's/\\/%5c/g' \
+	    -e 's/%\([0-9a-fA-F][0-9a-fA-F]\)/\\x\1/g') | \
+	    expand | \
+	    sed -e 's/&/\&/g' -e 's/</\</g' -e 's/>/\>/g' \
+	    -e 's!\([
]\)!	\1</span>!g' \
+	    -e 's!</span>	!!g' \
+	    -e 's	<span style="background:#000000; color:#FF00FF; margin:1px; padding:1px;">g' \
+	    -e 'y/
/ABCDEFGHKLMNPQRSTUVWXYZ[\\]^_/' | \
+	    tr '\n' ''
+}
+
+function htmlencode {
+	print -nr -- "$@" | sed \
+	    -e 's/&/\&/g' \
+	    -e 's/</\</g' \
+	    -e 's/>/\>/g'
+}
+
+function fqdnencode {
+	local short=$1 full=$2 makesmall=$3
+
+	if (( makesmall )) && \
+	    [[ $short != +([0-9]).+([0-9]).+([0-9]).+([0-9]) ]]; then
+		short=$(htmlencode "$short" | \
+		    sed 's!^\([^.]*.\)\(.*\)$!\1<span class="ipdom">\2</span>!')
+	else
+		short=$(htmlencode "$short")
+	fi
+
+	if [[ -n $full ]]; then
+		print -r "<span title=\"$(htmlencode "$full")\">$short</span>"
+	else
+		print -r -- "$short"
+	fi
+}
+
+typeset -Z11 -Uui16 iphex
+typeset -Uui1 c
+
+iphex=$(iptohex $ipdot) || exit 0
+
+ttype=%
+ofqdn=
+sfqdn=1
+if [[ $qs = 1,?([~!])+([a-zA-Z0-9._-]),* || \
+    $qs = [23],*([0-9a-fA-F:]),?([~!])+([a-zA-Z0-9._-]),* ||
+    $qs = 4,+([0-9a-zA-Z:.]),*([0-9a-fA-F:]),?([~!])+([a-zA-Z0-9._-]),* ]]; then
+	if [[ $qs = 4,* ]]; then
+		lladdr=${qs#4,}
+		ttype=${lladdr%%,*}
+		lladdr=${lladdr#+([0-9a-zA-Z:.]),}
+		fqdn=${lladdr#*([0-9a-fA-F:]),}
+		lladdr=${lladdr%%,*}
+	elif [[ $qs = 1,* ]]; then
+		fqdn=${qs#1,}
+		lladdr=
+	elif [[ $qs = [23],* ]]; then
+		[[ $qs = 3* ]] && ttype=DHCP
+		lladdr=${qs#[23],}
+		fqdn=${lladdr#*([0-9a-fA-F:]),}
+		lladdr=${lladdr%%,*}
+	fi
+	text=${fqdn#*,}
+	fqdn=${fqdn%%,*}
+	if [[ $qs = 1,* || $qs = [23],,* || $qs = 4,+([0-9a-zA-Z:.]),,* ]]; then
+		c=1	# red
+		fqdn=${fqdn#[~!]}
+	elif [[ $qs = 3,* ]]; then
+		c=8	# grey
+	elif [[ $fqdn = !* ]]; then
+		c=4	# blue
+		fqdn=${fqdn#!}
+	elif [[ $fqdn = ~* ]]; then
+		c=1	# red
+		fqdn=${fqdn#~}
+	else
+		c=3	# green
+	fi
+	lladdr=$remote_lladdr
+
+	if [[ $fqdn = *.X ]]; then
+		sfqdn=0
+		fqdn=${fqdn%.X}
+	fi
+	ofqdn=$fqdn
+	fqdn=$(fqdnfix "$ofqdn")
+	[[ $ofqdn = "$fqdn" ]] && ofqdn=
+
+	if [[ $text = *'%0'[Aa]* ]]; then
+		body=$(url2html "${text#*'%0'[Aa]}")
+		text=${text%%'%0'[Aa]*}
+	else
+		body=
+	fi
+	text=$(url2html "$text")
+else
+	fqdn=0x${iphex#16#}
+	lladdr=
+	c=1	# red
+	text="invalid QUERY_STRING received"
+	body=$(htmlencode "$qs")
+fi
+
+revdns=$(host $ipdot 2>&1 | fgrep -v 'is an alias for' | tr '\n' '')
+if [[ $revdns = *'domain name pointer'*''* ]]; then
+	revdns=${revdns%%.*}
+	orevdns=${revdns##*domain name pointer }
+	revdns=$(fqdnfix "$orevdns")
+	[[ $orevdns = "$revdns" ]] && orevdns=
+else
+	revdns="no PTR RR"
+	orevdns=
+fi
+
+if [[ $tsqs = +([0-9])/* ]]; then
+	tsqtv=10#${tsqs%%/*}
+	tsqs=${tsqs#*/}
+else
+	tsqtv=
+	tsqs=
+fi
+if [[ $tsqs = ?(-)+([0-9]).+([0-9])/+([0-9]).+([0-9]).+([0-9]).+([0-9]) ]]; then
+	tsqd=${tsqs%%/*}
+	tsqr=${tsqs#*/}
+	tsqms=${tsqd#-}
+	tsqs=${tsqms%.*}
+	tsqms=${tsqms#*.}000
+	tsqms=$tsqs${tsqms::3}
+	tsqd="$tsqd s to"
+	tsqms=10#$tsqms		# interpret as decimal
+	if [[ $tsqs = @([0-9][0-9][0-9][0-9][0-9][0-9])* && -n $tsqtv ]]; then
+		# much more than a day
+		tsqs=$((tslval - tsqtv))
+		(( tsqs >= 0 )) || (( tsqs = -tsqs ))
+		tsqd="$tsqs s off(${tsqd%%[ .]*})"
+		tsqr=
+		tsfarbe=grey
+		(( tsqs > 30 )) && tsfarbe=bwinverse
+		(( tsqs > 86400 )) && tsfarbe=red
+	elif (( tsqms < 128 )); then
+		tsfarbe=bwnormal
+	elif (( tsqms < 500 )); then
+		tsfarbe=green
+	elif (( tsqms < 1000 )); then
+		tsfarbe=yellow
+	elif (( tsqms < 5000 )); then
+		tsfarbe=blue
+	elif (( tsqms < 60000 )); then
+		tsfarbe=orange
+	else
+		tsfarbe=red
+	fi
+elif [[ -n $tsqtv ]]; then
+	tsqs=$((tslval - tsqtv))
+	(( tsqs >= 0 )) || (( tsqs = -tsqs ))
+	tsqd="$tsqs s off"
+	tsqr=127.0.0.1
+	tsfarbe=grey
+	(( tsqs > 30 )) && tsfarbe=bwinverse
+else
+	tsqd=
+	tsqr=
+	tsqms=
+fi
+if [[ -n $tsqd ]]; then
+	tslinepart="${tsfarbe}$(htmlencode $tsval)${tsqd}${tsqr}</pre></td><td>"
+else
+	tslinepart="<td class=\"tsval greyed\">$(htmlencode $tsval)</td><td>"
+fi
+
+line="$tsval ${iphex#16#} $fqdn ${lladdr:-~} $ttype "
+line="$line <tr><td style=\"background-color:${c#1#};\" "
+line="$line<td style=\"background-color:${c#1#};\""
+line="$line class=\"ip\">$(htmlencode $ipdot)"
+line="$line$(fqdnencode "$revdns" "$orevdns" 0)"
+line="$line${lladdr:+<br />$lladdr}</td>"
+line="$line<td class=\"ttype\">$(htmlencode "$ttype")</td>"
+if [[ $fqdn = +([0-9]).+([0-9]).+([0-9]).+([0-9]) ]]; then
+	fqdnclass=grey
+elif [[ $fqdn = *localhost* || $fqdn = *.local* ]]; then
+	fqdnclass=red
+elif [[ $fqdn = *.invalid.fqdn || $fqdn = dhcp-* || $fqdn = *.dynamic* ]]; then
+	fqdnclass=orange
+	fqdn=${fqdn%.invalid.fqdn}
+elif [[ $fqdn = *.no.fqdn ]]; then
+	fqdnclass=orange
+	fqdn=${fqdn%.no.fqdn}.--
+elif [[ $fqdn = +([!.]).lan/de ]]; then
+	fqdnclass=fqdn
+elif [[ $fqdn = +([!.]).lan.osiam.net ]]; then
+	fqdnclass=fqdn
+elif [[ $fqdn = *.lan* ]]; then
+	fqdnclass=red
+else
+	fqdnclass=fqdn
+fi
+[[ $sfqdn$fqdnclass = 0fqdn ]] && fqdnclass=yellow
+line="$line<td class=\"$fqdnclass\">$(fqdnencode \
+    "$fqdn" "$ofqdn" 1)</td>$tslinepart"
+[[ -n $body ]] && line="${line}"
+line="$line<tt>$text</tt>"
+[[ -n $body ]] && line="${line}$body"
+line="$line</td></tr>"
+
+print -r -- "$line" >$outf
+exit 0


hooks/post-receive
-- 
Main git repository for Evolvis project useful-scripts
(Evolvis project useful-scripts repository useful-scripts)


More information about the Useful-scripts-commits mailing list