Where is the path for the link in password change emails?

Get help from other users here.

Moderators: Developer, Contributor

btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Where is the path for the link in password change emails?

Post by btenpenny »

When my Mantis system sends emails for changing passwords, the clickable link has "localhost" in the rather than the ip/hostname of the machine it is running on. Obviously, this doesn't work unless you happen to be reading the email on the machine itself.

I'm sure I've missed changing a default somewhere, but I can't determine where it derives that particular link from.

Any helpers?

Thanks,
gravyface
Posts: 20
Joined: 16 Aug 2006, 20:48

Post by gravyface »

The URL is generated programmatically, around line 71 in the config_defaults_inc.php:

Code: Select all


		if ( isset( $_SERVER['HTTP_HOST'] ) ) {
			$t_host = $_SERVER['HTTP_HOST'];
		} else if ( isset( $_SERVER['SERVER_NAME'] ) ) {
			$t_host = $_SERVER['SERVER_NAME'] . $t_port;
		} else if ( isset( $_SERVER['SERVER_ADDR'] ) ) {
			$t_host = $_SERVER['SERVER_ADDR'] . $t_port;
		} else {
			$t_host = 'www.example.com';
		}

		$t_path = dirname( strip_tags( $_SERVER['PHP_SELF'] ) );
		if ( '/' == $t_path || '\\' == $t_path ) {
			$t_path = '';
		}

		$g_path	= $t_protocol . '://' . $t_host . $t_path.'/';
	} else {
		$g_path	= 'http://www.example.com/mantis/';
	}
These are standard PHP/Apache/system environmental variables; check /etc/hostsname and /etc/network/interfaces (I think this is the same across distros; might be different in RedHat).

See this:
http://www.cpqlinux.com/hostname.html
btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Post by btenpenny »

Thanks for the info!

I saw that section of the code, but I can't figure out where it's pulling the info from.

This is on a Windows box. Does anyone know what the Windows version of this informatino would be?
gravyface
Posts: 20
Joined: 16 Aug 2006, 20:48

Post by gravyface »

Are you running Apache or IIS?
btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Post by btenpenny »

Apache
shark
Posts: 43
Joined: 12 Jul 2005, 22:23

Post by shark »

$g_smtp_host in the config file.

go to the "# Mantis Email Settings" section of the config_defaults_inc.php file and go through those settings and set what you need for email in your config_inc.php file.
btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Post by btenpenny »

Isn't $g_smtp_host the smtp server host name? My emails are going out, and arriving. It's just that the link they include looks something like this:

http://localhost/mantis/verify.php?id=3 ... 0ee5ab527a
^^^^^^
The "localhost" bit is the problem.
shark
Posts: 43
Joined: 12 Jul 2005, 22:23

Post by shark »

lol, ok I misunderstood.

Let me find that setting... just a second.
shark
Posts: 43
Joined: 12 Jul 2005, 22:23

Post by shark »

Check the "serverName" setting in httpd.conf for apache.

that might do it.
btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Post by btenpenny »

Already tried that one, it's configured with the IP of the machine.


Thanks for the idea, though!
shark
Posts: 43
Joined: 12 Jul 2005, 22:23

Post by shark »

Digging through the code, gravyface is right on the money.

It appears that one of these:
$_SERVER['HTTP_HOST']

$_SERVER['SERVER_NAME']

$_SERVER['SERVER_ADDR']
needs to be set, to correctly create the url.

Check what those PHP vars are set to by running phpinfo.php
gravyface
Posts: 20
Joined: 16 Aug 2006, 20:48

Post by gravyface »

You need to set ServerName to your hostname:

http://httpd.apache.org/docs/2.0/mod/co ... servername
btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Post by btenpenny »

Shark:
Yep, that looks like the culprit. Where are those values set? I can't find an entry for them.

Gravy: I've already got that set to the machine's IP

Thanks to both!
gravyface
Posts: 20
Joined: 16 Aug 2006, 20:48

Post by gravyface »

PHP's environmental variables (also known as "CGI Variables") are pulled from the Web server. To see the values for yourself, create a php file with:

Code: Select all

<?php
echo phpinfo();
?>
...and run it.

According to the Apache 2.x documentation, the ServerName defines your hostname. I'm wondering if perhaps since it's set to IP, it resolves to localhost (using local DNS cache or c:\windows\system32\etc\hosts).

I use virtual hosts (and I think Apache2 by default uses this) and under each virtual host, I have
ServerName appname.hostname like:

Code: Select all

<VirtualHost *>
      ServerAdmin gravyface@foo.com
      ServerName mantis.foo.com
      ServerAlias mantis.foo.com
      DocumentRoot /var/www/mantis
      ErrorLog /var/log/apache2/mantis.error.log

      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn

      CustomLog /var/log/apache2/mantis.access.log combined
      ServerSignature On

</VirtualHost>

This way, foo.com always resolves to my machine, and the "mantis" string sent in the header tells Apache which virtual host to use. I do not have my IP address anywhere in the Apache configuration; I have * for NameVirtualHost in the "default" file in /sites-available.

http://httpd.apache.org/docs/2.0/vhosts/examples.html

Try setting ServerName to your hostname and restarting; it can't hurt anything (unless it's in production of course).
Last edited by gravyface on 17 Aug 2006, 18:33, edited 1 time in total.
btenpenny
Posts: 18
Joined: 15 Aug 2006, 17:12

Post by btenpenny »

Once again, thanks for all the suggestions!

I've been using phpinfo() to check these variables

To test, I changed ServerName to the hostname of the PC and restarted Apache. It still listed localhost in the variable field.
Post Reply