<?php

defined('MAXIMUS') or die ('Access denied track active MAXIMUS directly...');

  if(!empty($nsnst_const['post_string'])) {
    $pg = $nsnst_const['script_name']."?".$nsnst_const['post_string'];
  } elseif(!empty($nsnst_const['get_string'])) {
    $pg = $nsnst_const['script_name']."?".$nsnst_const['get_string'];
  } elseif(!empty($nsnst_const['query_string'])) {
    $pg = $nsnst_const['script_name']."?".$nsnst_const['query_string'];
  } else {
    $pg = $nsnst_const['script_name'];
  }
  if($pg != "/backend.php" AND $pg != '/modules.php' AND !stristr($pg, "op=gfx") AND !stristr($pg, "gfx=gfx") AND !stristr($pg, "gfx=gfx_little")) {
    $checkrow = $GLOBALS['db']->sql_numrows($GLOBALS['db']->sql_query("SELECT `ip_lo` FROM `".$prefix."_nsnst_ip2country` LIMIT 0,1"));
    if($checkrow > 0) {
      $remote_long = sprintf("%u", ip2long($nsnst_const['remote_ip']));
      $rowx = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `c2c` FROM `".$prefix."_nsnst_ip2country` WHERE `ip_lo`<='$remote_long' AND `ip_hi`>='$remote_long'"));
      $c2c = $rowx['c2c'];
    }
    if(!$c2c) { $c2c = "00"; }
    if($nsnst_const['ban_user_id']==1) { $nsnst_const['ban_username2'] = ""; } else { $nsnst_const['ban_username2'] = $nsnst_const['ban_username']; }
      if (!get_magic_quotes_runtime()) {
        $ban_username2 = addslashes($nsnst_const['ban_username2']);
        $user_agent = addslashes($nsnst_const['user_agent']);
        $pg = addslashes($pg);
      }
    $GLOBALS['db']->sql_query("INSERT INTO `".$prefix."_nsnst_tracked_ips` (`user_id`, `username`, `date`, `ip_addr`, `page`, `user_agent`, `x_forward_for`, `client_ip`, `remote_addr`, `remote_port`, `request_method`, `c2c`) VALUES ('".$nsnst_const['ban_user_id']."', '$ban_username2', '".$nsnst_const['ban_time']."', '".$nsnst_const['remote_ip']."', '$pg', '$user_agent', '".$nsnst_const['forward_ip']."', '".$nsnst_const['client_ip']."', '".$nsnst_const['remote_addr']."', '".$nsnst_const['remote_port']."', '".$nsnst_const['request_method']."', '$c2c')");
    if($ab_config['track_max'] > 0) {
      $deltime = $max_time;
      $ab_config['track_del'] = $deltime - $ab_config['track_max'];
      $GLOBALS['db']->sql_query("DELETE FROM `".$prefix."_nsnst_tracked_ips` WHERE `date` < ".$ab_config['track_del']);
      //$GLOBALS['db']->sql_query("OPTIMIZE TABLE `".$prefix."_nsnst_tracked_ips`");
    }
  }