(file) Return to hostinfo.pm CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / awstats-6.3 / wwwroot / cgi-bin / plugins

  1 rizwank 1.1 #!/usr/bin/perl
  2             #-----------------------------------------------------------------------------
  3             # HostInfo AWStats plugin
  4             # This plugin allow you to add information on hosts, like a whois fields.
  5             #-----------------------------------------------------------------------------
  6             # Perl Required Modules: XWhois
  7             #-----------------------------------------------------------------------------
  8             # $Revision: 1.15 $ - $Author: eldy $ - $Date: 2004/10/27 20:56:49 $
  9             
 10             
 11             # <-----
 12             # ENTER HERE THE USE COMMAND FOR ALL REQUIRED PERL MODULES
 13             push @INC, "${DIR}/plugins";
 14             if (!eval ('require "Net/XWhois.pm";')) { return $@?"Error: $@":"Error: Need Perl module Net::XWhois"; }
 15             # ----->
 16             use strict;no strict "refs";
 17             
 18             
 19             
 20             #-----------------------------------------------------------------------------
 21             # PLUGIN VARIABLES
 22 rizwank 1.1 #-----------------------------------------------------------------------------
 23             # <-----
 24             # ENTER HERE THE MINIMUM AWSTATS VERSION REQUIRED BY YOUR PLUGIN
 25             # AND THE NAME OF ALL FUNCTIONS THE PLUGIN MANAGE.
 26             my $PluginNeedAWStatsVersion="6.0";
 27             my $PluginHooksFunctions="ShowInfoHost AddHTMLBodyHeader BuildFullHTMLOutput";
 28             # ----->
 29             
 30             # <-----
 31             # IF YOUR PLUGIN NEED GLOBAL VARIABLES, THEY MUST BE DECLARED HERE.
 32             use vars qw/
 33             /;
 34             # ----->
 35             
 36             
 37             
 38             #-----------------------------------------------------------------------------
 39             # PLUGIN FUNCTION: Init_pluginname
 40             #-----------------------------------------------------------------------------
 41             sub Init_hostinfo {
 42             	my $InitParams=shift;
 43 rizwank 1.1 	my $checkversion=&Check_Plugin_Version($PluginNeedAWStatsVersion);
 44             
 45             	# <-----
 46             	# ENTER HERE CODE TO DO INIT PLUGIN ACTIONS
 47             	debug(" Plugin hostinfo: InitParams=$InitParams",1);
 48             	# ----->
 49             
 50             	return ($checkversion?$checkversion:"$PluginHooksFunctions");
 51             }
 52             
 53             
 54             
 55             #-----------------------------------------------------------------------------
 56             # PLUGIN FUNCTION: AddHTMLBodyHeader_pluginname
 57             # UNIQUE: NO (Several plugins using this function can be loaded)
 58             # Function called to Add HTML code at beginning of BODY section.
 59             # Parameters: None
 60             #-----------------------------------------------------------------------------
 61             sub AddHTMLBodyHeader_hostinfo {
 62             	# <-----
 63             	my $WIDTHINFO=640;
 64 rizwank 1.1 	my $HEIGHTINFO=480;
 65             
 66             	my $urlparam="pluginmode=hostinfo&config=$SiteConfig";
 67             	$urlparam.=($DirConfig?"&configdir=$DirConfig":"");
 68             	
 69             	print <<EOF;
 70             
 71             <script language="javascript" type="text/javascript">
 72             function neww(a,b) {
 73             var wfeatures="directories=0,menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,width=$WIDTHINFO,height=$HEIGHTINFO,left=" + eval("(screen.width - $WIDTHINFO)/2") + ",top=" + eval("(screen.height - $HEIGHTINFO)/2");
 74             EOF
 75             	print "if (b==1) { fen=window.open('".XMLEncode("$AWScript?$urlparam&host")."='+a,'whois',wfeatures); }\n";
 76             	print "if (b==2) { fen=window.open('".XMLEncode("$AWScript?$urlparam&host")."='+a,'whois',wfeatures); }\n";
 77             print <<EOF;
 78             }
 79             </script>
 80             
 81             EOF
 82             
 83             	return 1;
 84             	# ----->
 85 rizwank 1.1 }
 86             
 87             
 88             #-----------------------------------------------------------------------------
 89             # PLUGIN FUNCTION: ShowInfoHost_pluginname
 90             # UNIQUE: NO (Several plugins using this function can be loaded)
 91             # Function called to add additionnal columns to the Hosts report.
 92             # This function is called when building rows of the report (One call for each
 93             # row). So it allows you to add a column in report, for example with code :
 94             #   print "<TD>This is a new cell for $param</TD>";
 95             # Parameters: Host name or ip
 96             #-----------------------------------------------------------------------------
 97             sub ShowInfoHost_hostinfo {
 98                 my $param="$_[0]";
 99             	# <-----
100             	if ($param eq '__title__') {
101             		print "<th width=\"40\">$Message[114]</th>";	
102             	}
103             	elsif ($param) {
104             		my $keyforwhois;
105             		my $linkforwhois;
106 rizwank 1.1 		if ($param =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {	# IPv4 address
107             			$keyforwhois=$param;
108             			$linkforwhois=2;
109             		}
110             		elsif ($param =~ /^[0-9A-F]*:/i) {							# IPv6 address
111             			$keyforwhois=$param;
112             			$linkforwhois=2;
113             		}
114             		else {	# Hostname
115             			$param =~ /([-\w]+\.[-\w]+\.(?:au|uk|jp|nz))$/ or $param =~ /([-\w]+\.[-\w]+)$/;
116             			$keyforwhois=$1;
117             			$linkforwhois=1;
118             		}
119             		print "<td>";
120             		if ($keyforwhois && $linkforwhois) { print "<a href=\"javascript:neww('$keyforwhois',$linkforwhois)\">?</a>"; }
121             		else { print "&nbsp;" }
122             		print "</td>";
123             	}
124             	else {
125             		print "<td>&nbsp;</td>";
126             	}
127 rizwank 1.1 	return 1;
128             	# ----->
129             }
130             
131             
132             #-----------------------------------------------------------------------------
133             # PLUGIN FUNTION: BuildFullHTMLOutput_pluginname
134             # UNIQUE: NO (Several plugins using this function can be loaded)
135             # Function called to output an HTML page completely built by plugin instead
136             # of AWStats output
137             #-----------------------------------------------------------------------------
138             sub BuildFullHTMLOutput_hostinfo {
139             	# <-----
140             	my $Host='';
141             	if ($QueryString =~ /host=([^&]+)/i) {
142             		$Host=lc(&DecodeEncodedString("$1"));
143             	}
144             
145             	my $ip='';
146             	my $HostResolved='';
147             #	my $regipv4=qr/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
148 rizwank 1.1 #	my $regipv6=qr/^[0-9A-F]*:/i;
149             #	if ($Host =~ /$regipv4/o) { $ip=4; }
150             #	elsif ($Host =~ /$regipv6/o) { $ip=6; }
151             #	if ($ip == 4) {
152             #		my $lookupresult=lc(gethostbyaddr(pack("C4",split(/\./,$Host)),AF_INET));	# This is very slow, may spend 20 seconds
153             #		if (! $lookupresult || $lookupresult =~ /$regipv4/o || ! IsAscii($lookupresult)) {
154             #			$HostResolved='*';
155             #		}
156             #		else {
157             #			$HostResolved=$lookupresult;
158             #		}
159             #		if ($Debug) { debug("  Reverse DNS lookup for $Host done: $HostResolved",4); }
160             #	}
161             	if (! $ip) { $HostResolved=$Host; }
162             
163             	if ($Debug) { debug("  Plugin hostinfo: DirData=$DirData Host=$Host HostResolved=$HostResolved ",4); }
164             	my $w = new Net::XWhois Verbose=>$Debug, Cache=>$DirData, NoCache=>0, Timeout=>10, Domain=>$HostResolved;
165             
166             	print "<br />\n";
167             	
168             	if ($w && $w->response()) {
169 rizwank 1.1 		&tab_head("Common Whois Fields",0,0,'whois');
170             		print "<tr bgcolor=\"#$color_TableBGRowTitle\"><th>Common field info</th><th>Value</th></tr>\n";
171             		print "<tr><td>Name</td><td>".($w->name())."&nbsp;</td></tr>";
172             		print "<tr><td>Status</td><td>".($w->status())."&nbsp;</td></tr>";
173             		print "<tr><td>NameServers</td><td>".($w->nameservers())."&nbsp;</td></tr>";
174             		print "<tr><td>Registrant</td><td>".($w->registrant())."&nbsp;</td></tr>";
175             		print "<tr><td>Contact Admin</td><td>".($w->contact_admin())."&nbsp;</td></tr>";
176             		print "<tr><td>Contact Tech</td><td>".($w->contact_tech())."&nbsp;</td></tr>";
177             		print "<tr><td>Contact Billing</td><td>".($w->contact_billing())."&nbsp;</td></tr>";
178             		print "<tr><td>Contact Zone</td><td>".($w->contact_zone())."&nbsp;</td></tr>";
179             		print "<tr><td>Contact Emails</td><td>".($w->contact_emails())."&nbsp;</td></tr>";
180             		print "<tr><td>Contact Handles</td><td>".($w->contact_handles())."&nbsp;</td></tr>";
181             		print "<tr><td>Domain Handles</td><td>".($w->domain_handles())."&nbsp;</td></tr>";
182             		&tab_end;
183             	}
184             
185             	&tab_head("Full Whois Field",0,0,'whois');
186             	if ($w && $w->response()) {
187             		print "<tr><td class=\"aws\"><pre>".($w->response())."</pre></td></tr>\n";
188             	}
189             	else {
190 rizwank 1.1 		print "<tr><td><br />The Whois command failed.<br />Did the server running AWStats is allowed to send WhoIs queries (If a firewall is running, port 43 should be opened from inside to outside) ?<br /><br /></td></tr>\n";
191             	}
192             	&tab_end;
193             
194             	return 1;
195             	# ----->
196             }
197             
198             1;	# Do not remove this line

Rizwan Kassim
Powered by
ViewCVS 0.9.2