Code:<?php
echo "<!-- IP Tracking Module v3.5 for PHP-Nuke -->\n";
echo "<!-- Copyright (c) 2003 by Scott Rubin -->\n";
echo "<!-- phpnuke id: scottr -->\n\n";
if (!eregi("modules.php", $_SERVER['PHP_SELF'])) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);
$pagetitle = "- "._IPTRACKING."";
if(is_user($user)) {
if($cookie[9]=="") $cookie[9]=$Default_Theme;
if(!$file=@opendir("themes/$cookie[9]")) {
$ThemeSel = $Default_Theme;
} else {
$ThemeSel = $cookie[9];
}
} else {
$ThemeSel = $Default_Theme;
}
$now = date("d-m-Y");
$dot = explode ("-",$now);
$nowdate = $dot[0];
$nowmonth = $dot[1];
$nowyear = $dot[2];
function IPTrack_IPTrack() {
global $hlpfile, $nowyear, $nowmonth, $nowdate, $nowhour, $sitename, $startdate;
global $prefix, $db, $now, $numip, $pagenum, $show_hits, $Version_Num, $showmodule;
$sql = "SELECT count FROM ".$prefix."_counter ORDER BY type DESC";
$result = $db->sql_query($sql);
list($total) = $db->sql_fetchrow($result);
include ("header.php");
title("$sitename "._IPTRACKING."");
OpenTable();
OpenTable();
echo "<center><font class=\"option\"><b>$sitename "._IPTRACKING."</b></font><br>";
echo "<br>"._WERECEIVED." <b>$total</b> "._PAGESVIEWS." $startdate<br>"._TODAYIS.": $now[1]/$now[0]/$now[2]<br><br>";
echo "</center>";
CloseTable();
echo "<br><br>";
IPTrack_showIPStats();
echo "<br><br>";
CloseTable();
if($show_hits==1) {
$filter="WHERE username IS NOT NULL";
} elseif($show_hits==2) {
$filter="WHERE username IS NULL";
} else {
$filter="WHERE 1=1";
}
if (ereg("All.*Modules", $showmodule) || !$showmodule ) {
$modfilter="";
} else {
$modfilter=" AND page LIKE '%name=$showmodule%'";
}
$sql = "SELECT username, ip_address, hostname, MAX(date_time), COUNT(*) "
."FROM ".$prefix."_iptracking $filter $modfilter GROUP BY 1,2,3";
$res = $db->sql_query($sql);
$numips = $db->sql_numrows($res);
$sql = "SELECT * FROM ".$prefix."_iptracking WHERE 1=1 $modfilter";
$res = $db->sql_query($sql);
$numhits = $db->sql_numrows($res);
$numpages = ceil($numips / $numip);
if ($numpages > 1) {
echo "<br>";
OpenTable();
echo "<center>";
echo "$numips "._IPADDRESSES." ($numhits "._HITS.", $numpages "._PAGES.", $numip "._PERPAGE.")<br>" ;
# START Left Arrow
if ($pagenum > 1) {
$prevpage = $pagenum - 1 ;
if(file_exists("images/download/left.gif")) {
$leftarrow = "images/download/left.gif" ; # 5.x
} else {
$leftarrow = "images/left.gif" ; # 6.x+
}
if (ereg("All.*Modules", $showmodule) || !$showmodule ) {
echo "<a href=\"modules.php?name=IP_Tracking&pagenum=$prevpage\">";
} else {
echo "<a href=\"modules.php?name=IP_Tracking&showmodule=$showmodule&pagenum=$prevpage\">";
}
echo "<img src=\"$leftarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
}
# END Left Arrow
# START Page Numbers
echo "[ " ;
for ($i=1; $i < $numpages+1; $i++) {
if ($i == $pagenum) {
echo "$i";
} else {
if (ereg("All.*Modules", $showmodule) || !$showmodule ) {
echo "<a href=\"modules.php?name=IP_Tracking&pagenum=$i\">$i</a>";
} else {
echo "<a href=\"modules.php?name=IP_Tracking&showmodule=$showmodule&pagenum=$i\">$i</a>";
}
}
if ($i < $numpages) { echo " | "; } else { echo " ]"; }
}
# END Page Numbers
# START Right Arrow
if ($pagenum < $numpages) {
$nextpage = $pagenum + 1 ;
if(file_exists("images/download/right.gif")) {
$rightarrow = "images/download/right.gif" ; # 5.x
} else {
$rightarrow = "images/right.gif" ; # 6.x+
}
if (ereg("All.*Modules", $showmodule) || !$showmodule ) {
echo "<a href=\"modules.php?name=IP_Tracking&pagenum=$nextpage\">";
} else {
echo "<a href=\"modules.php?name=IP_Tracking&showmodule=$showmodule&pagenum=$nextpage\">";
}
echo "<img src=\"$rightarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
}
# END Right Arrow
echo "</center>";
CloseTable();
}
include ("footer.php");
}
function IPTrack_showIPStats(){
global $admin, $prefix, $bgcolor1, $bgcolor2, $db, $ThemeSel;
global $trackip, $numip, $pagenum, $hide_ipseg, $hide_host, $members_see_iphost, $ipmaskchar, $user, $orderby, $orderdir;
global $show_hits, $members_see_users, $Version_Num, $gridcolor, $members_see_online, $admin_see_online, $updown_arrows, $showmodule;
$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
if ($numip == "") { $numip = 100 ; } # Default 100 per page
if ($pagenum == "") { $pagenum = 1 ; }
if ($trackip == 1) {
$actip = _ACTIVATED;
} else {
$actip = _NOTACTIVATED;
}
echo "<center><b>"._IPTRACKINGINFO." - $actip"."</center></b><br>";
# START Modules
$content = "<center>";
$content .= "<table cellspacing=\"10\"><tr><td><form action=\"index.php\" method=\"get\">";
$content .= "<select name=\"module\" onChange=\"top.location.href=this.options[this.selectedIndex].value\">";
$handle=opendir('modules');
while ($file = readdir($handle)) {
if ( (!ereg("^[.]",$file)) && !ereg("html$", $file) ) {
$moduleslist .= "$file ";
}
}
closedir($handle);
$moduleslist .= " All Modules";
$moduleslist = explode(" ", $moduleslist);
sort($moduleslist);
for ($i=0; $i < sizeof($moduleslist); $i++) {
if($moduleslist[$i]!="") {
$content .= "<option value=\"modules.php?name=IP_Tracking&showmodule=$moduleslist[$i]\" ";
if($showmodule==$moduleslist[$i]) $content .= " selected";
$content .= ">".$moduleslist[$i]."</option>\n";
}
}
$content .= "</select></td><td><font class=\"option\">";
# Pulldown Menu pop-up help screen
$content .= "<div align=\"right\"><a href=\"javascript:IPTrack_openHelp1Win()\">?</a></div>";
$content .= "<script type=\"text/javascript\">\n";
$content .= "<!--\n";
$content .= "function IPTrack_openHelp1Win(){\n";
$content .= "window.open (\"modules/IP_Tracking/help1.php\",\"Information\",\"toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,width=500,height=200\");\n";
$content .= "}\n";
$content .= "//-->\n";
$content .= "</SCRIPT>\n\n";
$content .= "</font></td></tr></table></form></center>";
echo $content;
# END Modules
echo "<table align=\"center\" bgcolor=\"$gridcolor\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\"><tr>";
# Online?
if ((is_admin($admin) and $admin_see_online) or (is_user($user) and $members_see_online)) {
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._ONLINE."?</td>";
}
# End Online?
#START allow sorting by any column
if ($updown_arrows) {
$asc="<img src=\"images/up.gif\" border=\"0\">";
$desc="<img src=\"images/down.gif\" border=\"0\">";
$sep="";
} else {
$asc="A";
$desc="D";
$sep="/";
}
if(is_admin($admin) or (is_user($user) and $members_see_users)) {
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._USER;
echo " <a href=\"modules.php?name=IP_Tracking&orderby=1&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&orderby=1&orderdir=desc\">$desc</a></td>";
}
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._IPADDRESS;
echo " <a href=\"modules.php?name=IP_Tracking&orderby=2&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&orderby=2&orderdir=desc\">$desc</a></td>";
if(is_admin($admin) or !$hide_host or (is_user($user) and $members_see_iphost)) {
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._HOSTNAME;
echo " <a href=\"modules.php?name=IP_Tracking&orderby=3&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&orderby=3&orderdir=desc\">$desc</a></td>";
}
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._LASTVIEWED;
echo " <a href=\"modules.php?name=IP_Tracking&orderby=4&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&orderby=4&orderdir=desc\">$desc</a></td>";
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._HITS;
echo " <a href=\"modules.php?name=IP_Tracking&orderby=5&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&orderby=5&orderdir=desc\">$desc</a></td></tr>";
# default values if none set
if(!$orderby) $orderby="4";
if(!$orderdir) $orderdir="DESC";
#END allow sorting by any column
$offset = ($pagenum-1) * $numip ;
if($show_hits==1) {
$filter="WHERE username IS NOT NULL";
} elseif($show_hits==2) {
$filter="WHERE username IS NULL";
} else {
$filter="WHERE 1=1";
}
if (ereg("All.*Modules", $showmodule) || !$showmodule ) {
$modfilter="";
} else {
$modfilter=" AND page LIKE '%name=$showmodule%'";
}
# if multiple Users share same IP Address, then you'll see multiple identical IP Addresses when not displaying User, that's ok.
#
# now that we can select a module, the number of hits will represent hits to the selected module
# even though drilling down to display the page views will show all the hits by that IP Address.
$sql = "SELECT username, ip_address, hostname, MAX(date_time), COUNT(*), MIN(ipid) FROM ".$prefix."_iptracking "
."$filter $modfilter GROUP BY 1,2,3 ORDER BY $orderby $orderdir LIMIT $offset, $numip";
$result = $db->sql_query($sql);
while (list($username,$ipaddr,$hostnm,$lastview,$hits,$ipid) = $db->sql_fetchrow($result)){
if(!is_admin($admin) and !(is_user($user) and $members_see_iphost)) $ipaddr = IPTrack_mask_ip($ipaddr);
echo "<tr bgcolor=\"$bgcolor1\">";
# Online?
# Note: admins won't appear Online since they are not entered in the nuke_session table.
if ((is_admin($admin) and $admin_see_online) or (is_user($user) and $members_see_online)) {
if($Version_Num >= 6.5) { # nuke_session.username became nuke_session.uname in Nuke 6.5
# check if this registered user is online
$sql = "SELECT * FROM ".$prefix."_session WHERE uname='$username' AND host_addr='$ipaddr'";
$res = $db->sql_query($sql);
# check if this anonymous user is online
$sql2 = "SELECT * FROM ".$prefix."_session WHERE host_addr='$ipaddr' AND host_addr=uname";
$res2 = $db->sql_query($sql2);
} else {
# check if this registered user is online
$sql = "SELECT * FROM ".$prefix."_session WHERE username='$username' AND host_addr='$ipaddr'";
$res = $db->sql_query($sql);
# check if this anonymous user is online
$sql2 = "SELECT * FROM ".$prefix."_session WHERE host_addr='$ipaddr' AND host_addr=username";
$res2 = $db->sql_query($sql2);
}
if ($db->sql_numrows($res) > 0 or ($db->sql_numrows($res2) > 0 and $username=='')) {
echo "<td align=\"center\">"._YES."</td>";
} else {
echo "<td> </td>";
}
}
# END Online?
if(is_admin($admin) or (is_user($user) and $members_see_users)) {
if($username != ""){
if($Version_Num >= 6.5) {
$sql2 = "SELECT user_id FROM ".$prefix."_users WHERE username='$username'";
$result2 = $db->sql_query($sql2);
list($u) = $db->sql_fetchrow($result2);
if($u != "") {
echo "<td><a href=\"forums.html?amp;file=profile&mode=viewprofile&u=$u\">$username</a></td>";
} else {
echo "<td>$username</td>"; # additional admins aren't in nuke_users so don't make a link
}
} else {
echo "<td><a href=\"modules.php?name=Your_Account&op=userinfo&uname=$username\">$username</a></td>";
}
} else {
echo "<td> </td>";
}
}
echo "<td><a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid\">$ipaddr</a></td>";
if(is_admin($admin) or !$hide_host or (is_user($user) and $members_see_iphost)) echo "<td>$hostnm</td>";
echo "<td>$lastview</td><td align=\"center\">$hits</td></tr>";
}
$db->sql_freeresult($result);
echo "</table>";
}
function IPTrack_PagesViewed() {
global $hlpfile,$nowyear,$nowmonth,$nowdate,$nowhour, $sitename, $startdate, $prefix, $db, $now, $ipid, $numip, $pagenum, $Version_Num;
$sql = "SELECT count FROM ".$prefix."_counter ORDER BY type DESC";
$result = $db->sql_query($sql);
list($total) = $db->sql_fetchrow($result);
include ("header.php");
title("$sitename "._IPTRACKING."");
OpenTable();
OpenTable();
echo "<center><font class=\"option\"><b>$sitename "._IPTRACKING."</b></font><br>";
echo "<br>"._WERECEIVED." <b>$total</b> "._PAGESVIEWS." $startdate<br>"._TODAYIS.": $now[1]/$now[0]/$now[2]<br><br>";
echo "</center>";
CloseTable();
echo "<br><br>";
IPTrack_showPageStats();
echo "<br><br><center>"._GOBACK."</center><br><br>";
CloseTable();
$ipid=intval($ipid);
$sql = "SELECT ip_address FROM ".$prefix."_iptracking WHERE ipid='$ipid'";
$result = $db->sql_query($sql);
list($ip_address) = $db->sql_fetchrow($result);
$sql = "SELECT * FROM ".$prefix."_iptracking WHERE ip_address='$ip_address'";
$res = $db->sql_query($sql);
$numurls = $db->sql_numrows($res);
$numpages = ceil($numurls / $numip);
if ($numpages > 1) {
echo "<br>";
OpenTable();
echo "<center>";
echo "$numurls "._URLS." ($numpages "._PAGES.", $numip "._PERPAGE.")<br>" ;
# START Left Arrow
if ($pagenum > 1) {
$prevpage = $pagenum - 1 ;
if(file_exists("images/download/left.gif")) {
$leftarrow = "images/download/left.gif" ; # 5.x
} else {
$leftarrow = "images/left.gif" ; # 6.x+
}
echo "<a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&pagenum=$prevpage\">";
echo "<img src=\"$leftarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
}
# END Left Arrow
# START Page Numbers
echo "[ " ;
for ($i=1; $i < $numpages+1; $i++) {
if ($i == $pagenum) {
echo "$i";
} else {
echo "<a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&pagenum=$i\">$i</a>";
}
if ($i < $numpages) { echo " | "; } else { echo " ]"; }
}
# END Page Numbers
# START Right Arrow
if ($pagenum < $numpages) {
$nextpage = $pagenum + 1 ;
if(file_exists("images/download/right.gif")) {
$rightarrow = "images/download/right.gif" ; # 5.x
} else {
$rightarrow = "images/right.gif" ; # 6.x+
}
echo "<a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&pagenum=$nextpage\">";
echo "<img src=\"$rightarrow\" align=\"absmiddle\" border=\"0\" hspace=\"10\"></a>";
}
# END Right Arrow
echo "</center>";
CloseTable();
}
include ("footer.php");
}
function IPTrack_showPageStats(){
global $admin, $prefix, $bgcolor1, $bgcolor2, $db, $ThemeSel;
global $numip, $pagenum, $ipid, $hide_host, $members_see_iphost, $user, $orderby, $orderdir, $gridcolor, $updown_arrows;
$l_size = getimagesize("themes/$ThemeSel/images/leftbar.gif");
$m_size = getimagesize("themes/$ThemeSel/images/mainbar.gif");
$r_size = getimagesize("themes/$ThemeSel/images/rightbar.gif");
if ($numip == "") { $numip = 100 ; } # Default 100 per page
if ($pagenum == "") { $pagenum = 1 ; }
$offset = ($pagenum-1) * $numip ;
$ipid=intval($ipid);
$sql = "SELECT ip_address FROM ".$prefix."_iptracking WHERE ipid='$ipid'";
$result = $db->sql_query($sql);
list($ip_address) = $db->sql_fetchrow($result);
# default values if none set
if(!$orderby) $orderby="2";
if(!$orderdir) $orderdir="DESC";
$sql = "SELECT page, date_time FROM ".$prefix."_iptracking "
."WHERE ip_address = '$ip_address' "
."ORDER BY $orderby $orderdir LIMIT $offset, $numip ";
$result = $db->sql_query($sql);
echo "<center><b>"._PAGEVIEWINFO."<br>";
# Admin always see info
#if(is_admin($admin)) {
if(!is_admin($admin) and !(is_user($user) and $members_see_iphost)) {
echo IPTrack_mask_ip($ip_address);
} else {
echo "$ip_address";
}
#if (is_admin($admin) or !$hide_host) echo " - " . gethostbyaddr($ip_address);
if(is_admin($admin) or !$hide_host or (is_user($user) and $members_see_iphost)) echo " - " . gethostbyaddr($ip_address);
echo "</center></b><br>";
echo "<table align=\"center\" bgcolor=\"$gridcolor\" cellspacing=\"1\" cellpadding=\"3\" border=\"0\"><tr>";
#START allow sorting by any column
if ($updown_arrows) {
$asc="<img src=\"images/up.gif\" border=\"0\">";
$desc="<img src=\"images/down.gif\" border=\"0\">";
$sep="";
} else {
$asc="A";
$desc="D";
$sep="/";
}
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._PAGEVIEWED;
echo " <a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&orderby=1&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&orderby=1&orderdir=desc\">$desc</a></td>";
echo "<td bgcolor=\"$bgcolor2\" nowrap>"._HITDATE;
echo " <a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&orderby=2&orderdir=asc\">$asc</a>$sep";
echo "<a href=\"modules.php?name=IP_Tracking&op=PagesViewed&ipid=$ipid&orderby=2&orderdir=desc\">$desc</a></td></tr>";
#END allow sorting by any column
while (list($page,$date_time) = $db->sql_fetchrow($result)){
echo "<tr bgcolor=\"$bgcolor1\"><td><a href=\"$page\">$page</a></td><td>$date_time</td></tr>";
}
$db->sql_freeresult($result);
echo "</table>";
}
function IPTrack_mask_ip($ipaddr) {
# IP Address Masking
global $hide_ipseg, $ipmaskchar;
if(in_array(TRUE, $hide_ipseg)){
$ipseg = explode(".", $ipaddr);
for($lcv=1; $lcv<=count($ipseg); $lcv++){
$seg=$lcv-1;
# ereg_replace() didn't like $ipseg[$lcv-1] so had to make $seg
if($hide_ipseg[$lcv]) $ipseg[$seg] = ereg_replace("[0-9]", "$ipmaskchar", "$ipseg[$seg]");
}
$ipaddr = implode(".",$ipseg);
}
return $ipaddr;
}
switch($op) {
default:
IPTrack_IPTrack();
break;
case "PagesViewed":
IPTrack_PagesViewed();
break;
}
?>
|