Advertisement:

Author Topic: IP to Country  (Read 19323 times)

Online vbgamer45

  • Customizer
  • SMF Super Hero
  • *
  • Posts: 21,624
    • smfhacks on Facebook
    • VBGAMER45 on GitHub
    • @createaforum on Twitter
    • SMF For Free
IP to Country
« on: March 06, 2012, 12:01:14 PM »
Link to 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

Offline Gryzor

  • Sr. Member
  • ****
  • Posts: 783
  • Gender: Male
  • CPCwiki.eu - The Amstrad CPC Encyclopaedia!
    • CPCWiki
Re: IP to Country
« Reply #1 on: March 10, 2012, 03:49:02 AM »
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?

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #2 on: March 10, 2012, 07:37:57 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

Offline Gryzor

  • Sr. Member
  • ****
  • Posts: 783
  • Gender: Male
  • CPCwiki.eu - The Amstrad CPC Encyclopaedia!
    • CPCWiki
Re: IP to Country
« Reply #3 on: March 11, 2012, 04:42:29 AM »
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!

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #4 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:

(Find)
Code: [Select]
$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)
Code: [Select]
$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.

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #5 on: January 17, 2014, 08:48:36 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

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #6 on: January 17, 2014, 09:14:37 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.

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #7 on: January 17, 2014, 09:23:43 AM »
Try the attached file
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

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #8 on: January 17, 2014, 09:48:22 AM »
Try the attached file

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

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #9 on: January 17, 2014, 10:01:08 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

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #10 on: January 17, 2014, 10:52:59 AM »
Bit of a bug in the file, I had to change:

Code: [Select]
FROM {db_prefix}messages
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)

to

Code: [Select]
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 :)

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #11 on: January 17, 2014, 11:31:02 AM »
Bit of a bug in the file, I had to change:

Code: [Select]
FROM {db_prefix}messages
LEFT JOIN {db_prefix}ip_lookup_countries AS c ON (c.index_number = m.ip_index_number)

to

Code: [Select]
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

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #12 on: January 17, 2014, 11:39:53 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?

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #13 on: January 17, 2014, 11:52:47 AM »
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

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #14 on: January 17, 2014, 12:27:19 PM »
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?

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #15 on: January 17, 2014, 01:29:57 PM »
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.

Code: [Select]
$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'],
);
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.

Offline makv

  • Semi-Newbie
  • *
  • Posts: 56
Re: IP to Country
« Reply #16 on: January 17, 2014, 01:41:35 PM »
Got it, I think. Earlier on in Display.php is this:

Code: [Select]
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.

Offline Joker™

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 5,914
  • Gender: Male
    • siddhartha-gupta on GitHub
Re: IP to Country
« Reply #17 on: January 18, 2014, 01:16:44 AM »
Got it, I think. Earlier on in Display.php is this:

Code: [Select]
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

Offline LiBen

  • Semi-Newbie
  • *
  • Posts: 32
Re: IP to Country
« Reply #18 on: January 01, 2016, 11:29:44 AM »
During install I get this error:

Code: [Select]
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?