• Welcome to Simple Machines Community Forum. Please login or sign up.
September 21, 2021, 06:51:30 AM

News:

Want to get involved in developing SMF, then why not lend a hand on our github!


IP to Country

Started by vbgamer45, March 06, 2012, 12:01:14 PM

Previous topic - Next topic

vbgamer45

Link to the mod
This mod is based on Ip to Country mod. After attaining the proper permission from the mod author it became possible to update the mod for SMF 2.x branch. A huge thanks to SONSiVRi for that.

This mod makes use of the GeoLite data created by MaxMind, available from MaxMind which is released under an OPEN DATA LICENSE.

Installation may take as long as minutes because of IP database (inserting 158,068 rows into database)

This mod basically shows country name of the user with the IP address in posts and profiles.

With this mod membergroups who are able to see the IP address will be able to know the country name of concerned user without using whois.

After installation to show the country names associated with earlier posted messages, please go to
Administration Center >> Forum Maintenance >> Routine -- (Created index number of IP's associated with message) Run this task.


License
* This SMF Modification is subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this SMF modification except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Gryzor

This is very interesting and useful for battling spam and other tasks.

However, I'm worried about the amount of stuff it puts into the db; won't it affect performance?

Joker™

Quote from: Gryzor on March 10, 2012, 03:49:02 AM
However, I'm worried about the amount of stuff it puts into the db; won't it affect performance?
The amount of testing I've done on a test board provide by a team member having some thousand posts and members, showed fine results. Still if you find thing to worry about please notify in this topic.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

Gryzor

Ok, fair enough. I thought that maybe so many more lines would affect performance, but after looking around a bit it seems this is not the case!

makv

I would very much like to use this mod, but am currently getting a warning during install. I am in 2.0.6 and have also tried installing under 2.0.2 compatibility:

(Find)
$messages_request = $smcFunc['db_query']('', '
SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read
FROM {db_prefix}messages
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);


(Replace)
$messages_request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.icon, m.subject, m.poster_time, m.poster_ip, m.id_member, m.modified_time, m.modified_name, m.body,
m.smileys_enabled, m.poster_name, m.poster_email, m.approved,
m.id_msg_modified < {int:new_from} AS is_read, c.country_abbr, c.country_name
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)
WHERE m.id_msg IN ({array_int:message_list})
ORDER BY m.id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);


Thanks in advance for any suggestions.

Joker™

Quote from: makv on January 17, 2014, 08:40:06 AM
I would very much like to use this mod, but am currently getting a warning during install. I am in 2.0.6 and have also tried installing under 2.0.2 compatibility:
Some other mod must have made edits in the same code block. Attach the concerned file over here.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

makv

Quote from: Joker™ on January 17, 2014, 08:48:36 AM
Quote from: makv on January 17, 2014, 08:40:06 AM
I would very much like to use this mod, but am currently getting a warning during install. I am in 2.0.6 and have also tried installing under 2.0.2 compatibility:
Some other mod must have made edits in the same code block. Attach the concerned file over here.

Thanks for the prompt reply. Here it is.

Joker™

Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

makv

Quote from: Joker™ on January 17, 2014, 09:23:43 AM
Try the attached file

Do you mean install the mod and then overwrite with the attached?

Joker™

Quote from: makv on January 17, 2014, 09:48:22 AM
Quote from: Joker™ on January 17, 2014, 09:23:43 AM
Try the attached file

Do you mean install the mod and then overwrite with the attached?
Yup.

- Install the mod
- Make backup of file you have
- Override the file with the one attached above

Moreover if you face similar kind of issue again, you can parse the mod and make the edits manually too. How to manually install the mods
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

makv

Bit of a bug in the file, I had to change:


FROM {db_prefix}messages
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)


to


FROM {db_prefix}messages m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)


But other than that, seems to have worked. Am running the update process now, so I'll let you know :)

Joker™

Quote from: makv on January 17, 2014, 10:52:59 AM
Bit of a bug in the file, I had to change:


FROM {db_prefix}messages
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)


to


FROM {db_prefix}messages m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)


But other than that, seems to have worked. Am running the update process now, so I'll let you know :)

Ahhh, missed that. It seems like you are also having a bit of fun with mods :).
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

makv

Quote from: Joker™ on January 17, 2014, 11:31:02 AM
Ahhh, missed that. It seems like you are also having a bit of fun with mods :).

A heap of fun, yes.

So ... the mod seems to be OK, but I have notice a lot of errors in the Logs like this:

8: Undefined index: country_name
File: /var/www/smf/Sources/Display.php
Line: 1283

Any clues?

Joker™

Umm just make sure all edits required for the mod are there.
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

makv

Quote from: Joker™ on January 17, 2014, 11:52:47 AM
Umm just make sure all edits required for the mod are there.

Everything seems to be there. As the problem seems to be with Display.php, I'm wondering if it's another small problem in the file you sent me?

makv

Quote from: makv on January 17, 2014, 12:27:19 PM
Quote from: Joker™ on January 17, 2014, 11:52:47 AM
Umm just make sure all edits required for the mod are there.

Everything seems to be there. As the problem seems to be with Display.php, I'm wondering if it's another small problem in the file you sent me?

This is the code which seems to be causing the error message.


$output = array(
'attachment' => loadAttachmentContext($message['id_msg']),
'alternate' => $counter % 2,
'id' => $message['id_msg'],
'href' => $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'],
'link' => '<a href="' . $scripturl . '?topic=' . $topic . '.msg' . $message['id_msg'] . '#msg' . $message['id_msg'] . '" rel="nofollow">' . $message['subject'] . '</a>',
'member' => &$memberContext[$message['id_member']],
'icon' => $message['icon'],
'icon_url' => $settings[$context['icon_sources'][$message['icon']]] . '/post/' . $message['icon'] . '.gif',
'subject' => $message['subject'],
'time' => timeformat($message['poster_time']),
'timestamp' => forum_time(true, $message['poster_time']),
'counter' => $counter,
'modified' => array(
'time' => timeformat($message['modified_time']),
'timestamp' => forum_time(true, $message['modified_time']),
'name' => $message['modified_name']
),
'body' => $message['body'],
'ua_os' => $message['ua_os'],
'ua_browser' => $message['ua_browser'],
'ua_os_icon' => $message['ua_os_icon'],
'ua_browser_icon' => $message['ua_browser_icon'],
'new' => empty($message['is_read']),
'approved' => $message['approved'],
'first_new' => isset($context['start_from']) && $context['start_from'] == $counter,
'is_ignored' => !empty($modSettings['enable_buddylist']) && !empty($options['posts_apply_ignore_list']) && in_array($message['id_member'], $context['user']['ignoreusers']),
'can_approve' => !$message['approved'] && $context['can_approve'],
'can_unapprove' => $message['approved'] && $context['can_approve'],
'can_modify' => (!$context['is_locked'] || allowedTo('moderate_board')) && (allowedTo('modify_any') || (allowedTo('modify_replies') && $context['user']['started']) || (allowedTo('modify_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || !$message['approved'] || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time()))),
'can_remove' => allowedTo('delete_any') || (allowedTo('delete_replies') && $context['user']['started']) || (allowedTo('delete_own') && $message['id_member'] == $user_info['id'] && (empty($modSettings['edit_disable_time']) || $message['poster_time'] + $modSettings['edit_disable_time'] * 60 > time())),
'can_see_ip' => allowedTo('moderate_forum') || ($message['id_member'] == $user_info['id'] && !empty($user_info['id'])),
'country_abbr' => $message['country_abbr'],
'country_name' => $message['country_name'],
);
Quote from: makv on January 17, 2014, 11:39:53 AM
Quote from: Joker™ on January 17, 2014, 11:31:02 AM
Ahhh, missed that. It seems like you are also having a bit of fun with mods :).

So ... the mod seems to be OK, but I have notice a lot of errors in the Logs like this:

8: Undefined index: country_name
File: /var/www/smf/Sources/Display.php
Line: 1283

Any clues?

Line 1283 is the last line in the above code.

makv

Got it, I think. Earlier on in Display.php is this:


SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read, c.country_abbr, c.country_name
ua_os, ua_browser, ua_os_icon, ua_browser_icon
FROM {db_prefix}messages m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),


I think there is a missing comma after c.country_name

I've made that change in my local file and that has got rid of the error messages in the log.

Joker™

Quote from: makv on January 17, 2014, 01:41:35 PM
Got it, I think. Earlier on in Display.php is this:


SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read, c.country_abbr, c.country_name
ua_os, ua_browser, ua_os_icon, ua_browser_icon
FROM {db_prefix}messages m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),


I think there is a missing comma after c.country_name

I've made that change in my local file and that has got rid of the error messages in the log.
Great. Nice work :).
Github Profile
Android apps
Medium

How to enable Post Moderation

"For the wise man looks into space and he knows there is no limited dimensions." - Laozi

All support seeking PM's get microwaved

LiBen

During install I get this error:

Unknown column 'ip_from' in 'field list'
File: /myforum/Packages/temp/ip-to-country-i.php
Regel: 162


The DB used to be on SMF 1.1.21, now using SMF 2.0.11
Do I need te remove the table: prefix_ip_lookup prior to install or an edit to ip-to-country-i.php?

LiBen


Unknown column 'ip_from' in 'field list'
Bestand: /data/sites/web/filippijnenorg/www/Packages/temp/IP_to_Country/ip-to-country-i.php
Regel: 161


Any news after 5 years?

vbgamer45

I would drop the ip_lookup and ip_lookup_countries database tables and try to install again.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

LiBen

I Removed both tables, which were empty anyhow.

Hit install, didn't get a warning, waiting...
and succes!  :)

Now updating the old posts via Maintenance => Routine
Now at 7% so I guess it will be a two hour job. To prevent server overload it goes 3 secondes and pauses 3 secondes.  ;D Like a car low on fuel.

Thanks for your advice, vbgamer45!

LiBen

I had to uninstall it!  >:(

Reason: a bug in profile page
index.php?action=profile;area=summary
index.php?action=profile;area=statistics
index.php?action=profile;area=showposts
index.php?action=profile;area=permissions
index.php?action=profile;area=tracking

gives:

syntax error, unexpected ']'

in both:

  • error log
  • on the profile page where <div id="main_admsection"> should be.

It doesn't matter if it's a member or admin looking.   

LiBen

I had to edit modification.xml due to original $sourcedir/Profile-View.php being different than in the xml

Is that the reason?

Adding in pre-mod on line 226 & 228
Adding in post-mod on line 249 & 251



<?xml version="1.0"?>
<!DOCTYPE modification SYSTEM "http://www.simplemachines.org/xml/modification">
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* @package manifest file for IP to Country
* @version 1.0
* @author Joker (http://www.simplemachines.org/community/index.php?action=profile;u=226111)
* @copyright Copyright (c) 2012
* @license http://www.mozilla.org/MPL/MPL-1.1.html
*/

/*
*
* Version: MPL 1.1
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Initial Developer of the Original Code is
* SONSiVRi (http://www.simplemachines.org/community/index.php?action=profile;u=126462)
* Portions created by the Initial Developer are Copyright (C) 2011
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Joker (http://www.simplemachines.org/community/index.php?action=profile;u=226111)
* Helped in updating the mod for SMF 2.x branch
*/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<modification xmlns="http://www.simplemachines.org/xml/modification" xmlns:smf="http://www.simplemachines.org/">
<id>sid2varun:ip_to_country</id>
<version>1.0</version>

<file name="$sourcedir/ManageMaintenance.php">
<operation>
<search position="before"><![CDATA[ 'recount' => 'AdminBoardRecount',]]></search>
<add><![CDATA[
'recountipindex' => 'RecountIPIndex',]]></add>
</operation>
<operation>
<search position="after"><![CDATA[// Perform a detailed version check.  A very good thing ;).]]></search>
<add><![CDATA[// Recount/verify the ip index associated with each message
function RecountIPIndex()
{
global $txt, $context, $smcFunc;

isAllowedTo('admin_forum');
checkSession('request');

// Set up to the context.
$context['page_title'] =  $txt['not_done_title'];
$context['continue_countdown'] = '3';
$context['continue_post_data'] = '';
$context['continue_get_data'] = '';
$context['sub_template'] = 'not_done';
$context['start'] = $_REQUEST['start'];
$context['start_time'] =  time();

// Lets fire the bullet.
@set_time_limit(300);

// Determine the total members with posts.
$request = $smcFunc['db_query']('', '
SELECT COUNT(*)
FROM {db_prefix}messages'
);
list($totalmessages) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);

// Initialize the variables.
$increment = 100;
if (empty($_REQUEST['start']))
$_REQUEST['start'] = 0;

// Grab the set of messages to update.
$request = $smcFunc['db_query']('', '
SELECT id_msg, poster_ip
FROM {db_prefix}messages
ORDER BY id_msg ASC
LIMIT {int:start}, {int:max}',
array(
'start' => $_REQUEST['start'],
'max' => $increment,
)
);

$context['test'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$result = $smcFunc['db_query']('', '
SELECT index_number
FROM {db_prefix}ip_lookup
WHERE ip_to >= INET_ATON({string:ip_address})
ORDER BY ip_to ASC
LIMIT 1',
array(
'ip_address' => $row['poster_ip'],
)
);
list ($index_number) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);
$index_number = empty($index_number) ? 0 : $index_number;

// Update the index number
$smcFunc['db_query']('', '
UPDATE {db_prefix}messages
SET ip_index_number = {int:ip_index_number}
WHERE id_msg = {int:id_msg}',
array(
'ip_index_number' => $index_number,
'id_msg' => $row['id_msg'],
)
);
}
$smcFunc['db_free_result']($request);

$_REQUEST['start'] += $increment;

// Move on people
if($_REQUEST['start'] < $totalmessages)
{
$context['continue_get_data'] = '?action=admin;area=maintain;sa=routine;activity=recountipindex;step=0;start=' . $_REQUEST['start'] . ';' . $context['session_var'] . '=' . $context['session_id'];
$context['continue_percent'] = round(100 * $_REQUEST['start'] / $totalmessages);
return;
}
redirectexit('action=admin;area=maintain;sa=routine;done=recountipindex');
}

]]></add>
</operation>
</file>

<file name="$sourcedir/Subs-Post.php">
<operation>
<search position="after"><![CDATA[ // Insert the post.]]></search>
<add><![CDATA[ $result = $smcFunc['db_query']('', '
SELECT index_number
FROM {db_prefix}ip_lookup
WHERE ip_to >= INET_ATON({string:ip_address})
ORDER BY ip_to ASC
LIMIT 1',
array(
'ip_address' => $posterOptions['ip'],
)
);
list ($ip_index_number) = $smcFunc['db_fetch_row']($result);
$smcFunc['db_free_result']($result);
$msgOptions['ip_index_number'] = empty($ip_index_number) ? 0 : $ip_index_number;

]]></add>
</operation>
<operation>
<search position="before"><![CDATA['smileys_enabled' => 'int', 'modified_name' => 'string', 'icon' => 'string-16', 'approved' => 'int',]]></search>
<add><![CDATA[ 'ip_index_number' => 'int',]]></add>
</operation>
<operation>
<search position="before"><![CDATA[$msgOptions['smileys_enabled'] ? 1 : 0, '', $msgOptions['icon'], $msgOptions['approved'],]]></search>
<add><![CDATA[ $msgOptions['ip_index_number'],]]></add>
</operation>
</file>

<file name="$sourcedir/Display.php">
<operation>
<search position="replace"><![CDATA[$messages_request = $smcFunc['db_query']('', '
SELECT
id_msg, icon, subject, poster_time, poster_ip, id_member, modified_time, modified_name, body,
smileys_enabled, poster_name, poster_email, approved,
id_msg_modified < {int:new_from} AS is_read
FROM {db_prefix}messages
WHERE id_msg IN ({array_int:message_list})
ORDER BY id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);]]></search>
<add><![CDATA[$messages_request = $smcFunc['db_query']('', '
SELECT
m.id_msg, m.icon, m.subject, m.poster_time, m.poster_ip, m.id_member, m.modified_time, m.modified_name, m.body,
m.smileys_enabled, m.poster_name, m.poster_email, m.approved,
m.id_msg_modified < {int:new_from} AS is_read, c.country_abbr, c.country_name
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)
WHERE m.id_msg IN ({array_int:message_list})
ORDER BY m.id_msg' . (empty($options['view_newest_first']) ? '' : ' DESC'),
array(
'message_list' => $messages,
'new_from' => $topicinfo['new_from'],
)
);]]></add>
</operation>
<operation>
<search position="before"><![CDATA['can_see_ip' => allowedTo('moderate_forum') || ($message['id_member'] == $user_info['id'] && !empty($user_info['id'])),]]></search>
<add><![CDATA[
'country_abbr' => $message['country_abbr'],
'country_name' => $message['country_name'],
]]></add>
</operation>
</file>

<file name="$sourcedir/Profile-View.php">
<operation>
<search position="before"><![CDATA[ $context['last_ip'] = $user_profile[$memID]['member_ip'];
if ($context['last_ip'] != $user_profile[$memID]['member_ip2'])
$context['last_ip2'] = $user_profile[$memID]['member_ip2'];
$context['member']['name'] = $user_profile[$memID]['real_name'];
]]></search>
<add><![CDATA[
// IP to Country
ipToCountry($context['last_ip']);
]]></add>
</operation>
<operation>
<search position="replace"><![CDATA[$request = $smcFunc['db_query']('', '
SELECT poster_ip
FROM {db_prefix}messages
WHERE id_member = {int:current_member}
' . (isset($min_msg_member) ? '
AND id_msg >= {int:min_msg_member} AND id_msg <= {int:max_msg_member}' : '') . '
GROUP BY poster_ip
LIMIT {int:limit}',
array(
'limit' => min($user_profile[$memID]['posts'], 500),
'current_member' => $memID,
'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
)
);
$context['ips'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$context['ips'][] = '<a href="' . $scripturl . '?action=profile;area=tracking;sa=ip;searchip=' . $row['poster_ip'] . ';u=' . $memID . '">' . $row['poster_ip'] . '</a>';
$ips[] = $row['poster_ip'];
}
$smcFunc['db_free_result']($request);]]></search>
<add><![CDATA[$request = $smcFunc['db_query']('', '
SELECT m.poster_ip, c.country_abbr, c.country_name
FROM {db_prefix}messages AS m
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)
WHERE m.id_member = {int:current_member}
' . (isset($min_msg_member) ? '
AND m.id_msg >= {int:min_msg_member} AND m.id_msg <= {int:max_msg_member}' : '') . '
GROUP BY m.poster_ip
LIMIT {int:limit}',
array(
'limit' => min($user_profile[$memID]['posts'], 500),
'current_member' => $memID,
'min_msg_member' => !empty($min_msg_member) ? $min_msg_member : 0,
'max_msg_member' => !empty($max_msg_member) ? $max_msg_member : 0,
)
);
$context['ips'] = array();
while ($row = mysql_fetch_assoc($request))
{
$context['ips'][] = '<a href="' . $scripturl . '?action=trackip;searchip=' . $row['poster_ip'] . '" title="' . $row['country_name'] . '">' . $row['poster_ip'] . ' (' . $row['country_abbr'] . ')</a>';
$ips[] = $row['poster_ip'];
}
$smcFunc['db_free_result']($request);]($request);]]></add>
</operation>
<operation>
<search position="before"><![CDATA[ $ip_var = str_replace('*', '%', $context['ip']);
$ip_string = strpos($ip_var, '%') === false ? '= {string:ip_address}' : 'LIKE {string:ip_address}';

if (empty($context['tracking_area']))
$context['page_title'] = $txt['trackIP'] . ' - ' . $context['ip'];
]]></search>
<add><![CDATA[
// IP to Country
ipToCountry($context['ip']);
]]></add>
</operation>
<operation>
<search position="end" />
<add><![CDATA[
// Returns country name and country code of given IP parameter
function ipToCountry($ip_address)
{
global $context, $smcFunc, $settings, $txt;

$request = $smcFunc['db_query']('', '
SELECT c.country_name, c.country_abbr
FROM {db_prefix}ip_lookup as ip
INNER JOIN {db_prefix}ip_lookup_countries as c ON (c.index_number = ip.index_number)
WHERE ip.ip_to >= INET_ATON({string:ip_address})
ORDER BY ip.ip_to ASC
LIMIT 1',
array(
'ip_address' => $ip_address,
)
);

    if ($smcFunc['db_num_rows']($request) > 0)
    {
list ($context['country_name'], $context['country_abbr']) = $smcFunc['db_fetch_row']($request);
$smcFunc['db_free_result']($request);
}
$context['country_name'] = empty($context['country_name']) ? $txt['iptocountry_natitle'] : $context['country_name'];
$context['country_abbr'] = empty($context['country_abbr']) ? $txt['iptocountry_na'] : $context['country_abbr'];
}
]]></add>
</operation>
</file>

<file name="$themedir/Display.template.php">
<operation>
<search position="replace"><![CDATA[ <a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '">', $message['member']['ip'], '</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqWin(this.href);" class="help">(?)</a>';
]]></search>
<add><![CDATA[ <a href="', $scripturl, '?action=', !empty($message['member']['is_guest']) ? 'trackip' : 'profile;area=tracking;sa=ip;u=' . $message['member']['id'], ';searchip=', $message['member']['ip'], '" title="', $message['country_name'],'">', $message['member']['ip'], ' (', $message['country_abbr'], ')</a> <a href="', $scripturl, '?action=helpadmin;help=see_admin_ip" onclick="return reqWin(this.href);" class="help">(?)</a>';
]]></add>
</operation>
</file>

<file name="$themedir/Profile.template.php">
<operation>
<search position="replace"><![CDATA[ <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '">', $context['last_ip'], '</a>';
]]></search>
<add><![CDATA[ <a href="', $scripturl, '?action=profile;area=tracking;sa=ip;searchip=', $context['last_ip'], ';u=', $context['member']['id'], '" title="' . $context['country_name'] . '">' . $context['last_ip'] . ' (' . $context['country_abbr'] . ')</a>';
]]></add>
</operation>
<operation>
<search position="after"><![CDATA[ // The table inbetween the first and second table shows links to the whois server for every region.
if ($context['single_ip'])
]]></search>
<add><![CDATA[ // IP to Country table, fetches IP with lookup database
echo '
<div class="cat_bar">
<h3 class="catbg">', $context['ip'], ' ', $txt['iptocountry_title'], '</h3>
</div>
<div class="windowbg2">
<span class="topslice"><span></span></span>
<div class="padding">
', $context['country_name'], ' (', $context['country_abbr'], ')
</div>
<span class="botslice"><span></span></span>
</div>
<br />';
]]></add>
</operation>
</file>

<file name="$themedir/ManageMaintenance.template.php">
<operation>
<search position="after"><![CDATA[<div class="cat_bar">
<h3 class="catbg">', $txt['maintain_logs'], '</h3>
</div>]]></search>
<add><![CDATA[<div class="cat_bar">
<h3 class="catbg">', $txt['maintain_recount_ip_index'], '</h3>
</div>
<div class="windowbg">
<span class="topslice"><span></span></span>
<div class="content">
<form action="', $scripturl, '?action=admin;area=maintain;sa=routine;activity=recountipindex" method="post" accept-charset="', $context['character_set'], '">
<p>', $txt['maintain_recount_ip_index_info'], '</p>
<span><input type="submit" value="', $txt['maintain_run_now'], '" class="button_submit" /></span>
<input type="hidden" name="', $context['session_var'], '" value="', $context['session_id'], '" />
</form>
</div>
<span class="botslice"><span></span></span>
</div>
]]></add>
</operation>
</file>

<file name="$languagedir/Modifications.english.php">
<operation>
<search position="end" />
<add><![CDATA[
$txt['iptocountry_title'] = 'to Country';
$txt['iptocountry_na'] = '--';
$txt['iptocountry_natitle'] = 'Not Listed';
$txt['maintain_recount_ip_index'] = 'Created index number of IP\'s associated with message';
$txt['maintain_recount_ip_index_info'] = 'Just use this to regenerate the index number of message IP. Used by the IP to County mod.';
]]></add>
</operation>
</file>

<file name="$languagedir/Modifications.dutch-utf8.php">
<operation>
<search position="end" />
<add><![CDATA[
$txt['iptocountry_title'] = 'naar land';
$txt['iptocountry_na'] = '--';
$txt['iptocountry_natitle'] = 'Niet in de lijst';
$txt['maintain_recount_ip_index'] = 'Gecre&#235;erd indexnummer van IP\'s geassoci&#235;erd met bericht';
$txt['maintain_recount_ip_index_info'] = 'Gebruik dit gewoon om het berichten-IP-indexnummer te regenereren. Gebruikt door de IP naar land mod.';
]]></add>
</operation>
</file>
   
<file name="$languagedir/Modifications.english-utf8.php">
<operation>
<search position="end" />
<add><![CDATA[
$txt['iptocountry_title'] = 'to Country';
$txt['iptocountry_na'] = '--';
$txt['iptocountry_natitle'] = 'Not Listed';
$txt['maintain_recount_ip_index'] = 'Created index number of IP\'s associated with message';
$txt['maintain_recount_ip_index_info'] = 'Just use this to regenerate the index number of message IP. Used by the IP to County mod.';
]]></add>
</operation>
</file>

</modification>


vbgamer45

Yeah if you edited the Proile-View.php edit that could cause the error.

I would need to see the changed file to see the error.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

LiBen

It's in the previous post as code. Editing xml was because the "test before install" in the admin package manager pointed out a fail. And I also had to add dutch-utf8 and english-utf8 for my forum.

I'll place it as attachment. My Proile-View.php is excactly as the SMF 2.0.18 version should be.

vbgamer45

Updated with fixes for 2.0.18 to install.
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

LiBen

Installed version 1.0.1 on SMF 2.0.18

Works without errors now. Thank you, vbgamer45

Shades.

Can you update this for 2.1RC4? O:)

ShadesWeb.com - Custom Logos
https://shadesweb.com

BikerHound.com - Sniffing out the road ahead
https://bikerhound.com

Dream as if you'll live forever; Live as if you'll die today. - James Dean

vbgamer45

Probably for 2.1 final
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

GL700Wing

Just installed this very useful mod - thanks for continuing the development of it!

I noticed that the country information is not shown next to the IP address on the member profile summary screen (which is where I really need to see the country for new members before their application is approved) - fixed as follows:

In ./Sources/Profile-View.php
Find:
$context['can_see_ip'] = true;Add After:

// IP to Country
ipToCountry($context['member']['ip']);

In ./Themes/default/Profile.template.php
Find (a few lines after "if ($context['can_see_ip'])"):
searchip=', $context['member']['ip'], ';u=', $context['member']['id'], '">', $context['member']['ip']Add After:
Find:
. ' (' . $context['country_name'] . ')'
Life doesn't have to be perfect to be wonderful ...

GL700Wing

Another issue I discovered is that the IP Address list is out of date and as a result a lot of posts by my members were shown with a country of 'Not Available' or were attributed to the wrong country.

The list in the mod has just over 158,300 entries while the latest list available from ip2location has almost 209,000 entries.  Also, and to use the latest list from ip2location the country codes list also needs to be updated.

Attached is a zip file containing the updated country_codes.csv and ip_addresses.csv files which I'm now using and after reinstalling the mod with these files and running the maintenance task the IP to Country information in the messages table is now correct.
Life doesn't have to be perfect to be wonderful ...

vbgamer45

Version 1.1
Updated the IP/country database thanks to GL700Wing
Community Suite for SMF - Take your forum to the next level built for SMF, Gallery,Store,Classifieds,Downloads,more!

SMFHacks.com -  Paid Modifications for SMF

Mods:
EzPortal - Portal System for SMF
SMF Gallery Pro
SMF Store SMF Classifieds Ad Seller Pro

Advertisement: