<?php
/*
Copyright (C) 2009 DantoBB Team
http://www.dantobb.com
*/
/**
* ACP IP address lookup
*
* Gives an interface to do IP address to hostname lookups.
*
* @author DantoBB Team
* @link http://www.dantobb.com
* @license GPL-2
* @version $Revision: 1.0 $
* @copyright Copyright (C) 2009 DantoBB Team
* @package DantoBB
* @subpackage ACP
*/
//
// Die when called directly in browser
//
if ( !defined('INCLUDED') )
exit();
$ip_addr_format = '#^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$#';
if ( !empty($_REQUEST['ip']) && preg_match($ip_addr_format, $_REQUEST['ip']) )
$ip_addr = $_REQUEST['ip'];
elseif ( !empty($_POST['ip']) && preg_match($ip_addr_format, $_POST['ip']) )
$ip_addr = $_POST['ip'];
else
$ip_addr = '';
if ( $_SERVER['REQUEST_METHOD'] == 'POST' ) {
$search_hostname_checked = ( !empty($_POST['search_hostname']) ) ? ' checked="checked"' : '';
$search_usernames_checked = ( !empty($_POST['search_usernames']) ) ? ' checked="checked"' : '';
} else {
$search_hostname_checked = $search_usernames_checked = ' checked="checked"';
}
$content .= '<form action="'.$functions->make_url('admin.php', array('act' => 'iplookup')).'" method="post">';
$content .= '<p>'.$lang['IPAddress'].': <input type="text" name="ip" id="ip" size="15" maxlength="15" value="'.$ip_addr.'" /> <input type="submit" value="'.$lang['Search'].'" /></p>';
$content .= '<p><label><input type="checkbox" name="search_hostname" value="1"'.$search_hostname_checked.' /> '.$lang['IPLookupSearchHostname'].'</label> <label><input type="checkbox" name="search_usernames" value="1"'.$search_usernames_checked.' /> '.$lang['IPLookupSearchUsernames'].'</label></p>';
$content .= '</form>';
if ( !empty($ip_addr) && $_SERVER['REQUEST_METHOD'] == 'POST' ) {
if ( !empty($_POST['search_hostname']) ) {
$content .= '<fieldset><legend>'.$lang['IPLookupHostname'].'</legend>';
$hostname = @gethostbyaddr($ip_addr);
if ( !empty($hostname) && $ip_addr != $hostname )
$content .= '<p><em>'.$hostname.'</em></p>';
else
$content .= '<p>'.$lang['IPLookupHostnameNotFound'].'</p>';
$content .= '</fieldset>';
}
if ( !empty($_POST['search_usernames']) ) {
$content .= '<fieldset><legend>'.$lang['IPLookupUsernames'].'</legend>';
$result = $db->query("SELECT DISTINCT(u.name) as name FROM ".TABLE_PREFIX."members u, ".TABLE_PREFIX."posts p WHERE u.id = p.poster_id AND p.poster_ip_addr = '".$ip_addr."' ORDER BY u.name ASC");
$usernames = array();
while ( $user = $db->fetch_result($result) )
$usernames[] = unhtml(stripslashes($user['name']));
if ( count($usernames) )
$content .= '<p><em>'.join(', ', $usernames).'</em></p>';
else
$content .= '<p>'.$lang['IPLookupUsernamesNotFound'].'</p>';
$content .= '</fieldset>';
}
}
$admin_functions->create_body('iplookup', $content);
$template->set_js_onload("set_focus('ip')");
?>