Add IP address to the New User Registration Email which goes to admin

myholden.com

Joined: 2007-05-08
Posts: 4
Posted: Tue, 2007-05-22 12:43

Hi,
Im trying to figure out how to include the new user's ip address in the email which is sent to gallery administrators on new user registration.

I suspect some stupid galleries being created are coming from the same IP address. I recently hacked the comment system to disallow comments from 2 IP addresses which stopped tens of dumb comments a day.

My plan was to make the following change in modules/register/classes/GalleryPendingUserHelper.class

        $ret = GalleryCoreApi::sendTemplatedEmail(
                'modules/register/templates/ConfirmationEmail.tpl',
                array(
                    'name' => $pendingUser->getFullName(),
                        /* We send plain text email so decode entities in username */
                    'username' => GalleryUtilities::htmlEntityDecode($pendingUser->getUserName()),
                    'confirmationUrl' => $confirmationUrl,
                    'baseUrl' => $baseUrl,                
                                                                                 /* THE FOLLOWING TO LINES ADDED BY ME */               
                    'ip' => $HTTP_SERVER_VARS['REMOTE_ADDR'],
                    'ipaddress' => GalleryUtilities::getRemoteHostAddress()),
                                                                                 /* END OF THE LINES ADDED BY ME */
                $params['from'],
                $pendingUser->getEmail(),
                $module->translate($params['subject']));

And then add the following to modules/register/templates/AdminEmail.tpl

{*
 * $Revision: 1.6 $
 * If you want to customize this file, do not edit it directly since future upgrades
 * may overwrite it.  Instead, copy it into a new directory called "local" and edit that
 * version.  Gallery will look for that file first and use it if it exists.
 *}
{g->text text="New user registration:"}

{g->text text="    Username: %s" arg1=$username}
{g->text text="   Full name: %s" arg1=$name}
{g->text text="       Email: %s" arg1=$email}

{* BEGINNING OF LINES I ADDED *}
{g->text text="  IP Address: %s" arg1=$ipaddress}
{g->text text="         IP : %s" arg1=$ip}
{* END OF LINES I ADDED *}

{g->text text="Activate or delete this user here"}
{g->url arg1="view=core.SiteAdmin" arg2="subView=register.AdminSelfRegistration"
	forceFullUrl=true htmlEntities=false}

The email Im getting however just contains the following

New user registration:

    Username: test80
   Full name: test
       Email: 
  IP Address: %s
         IP : %s

Does anyone have any suggestions where I've gone wrong?

Thanks
Glen

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2007-05-22 13:57

You should be able to HTTP VARS in the template without changing the class or inc file
IP Address: {$smarty.server.REMOTE_ADDR} should work.

Dave
_____________________________________________
Blog & G2 || floridave - Gallery Team

 
myholden.com

Joined: 2007-05-08
Posts: 4
Posted: Wed, 2007-05-23 07:55

Awesome, thanks heaps Dave, that worked a treat..... and so much simpler than my effort. :)
Cheers mate,
Glen