XHTML in Mantis 1.3 development trunk

I just wanted to upgrade my current installation of Mantis to the current 1.3.0 trunk. But this wasn’t as easy as in previous development releases of mantis. Obviously the content-encoding switched to more strict xhtml+xml. In previous versions the HTTP content-type was still text/html, which worked just fine. Using Firefox is no problem, but Internet Explorer doesn’t like the content-type application/xhtml+xml and always tries to download the page instead of displaying the page.

To resolve this problem I added a test prior to sending the content type, to which content type is actually supported by the client. The content-type is set in thehttp_api.php, so the modified function http_content_headers() looks like this:

/**
 * Set content-type headers.
 */
function http_content_headers() {
    if ( !headers_sent() ) {
        if (stristr($_SERVER[HTTP_ACCEPT], "application/xhtml+xml")) {
            header( 'Content-Type: application/xhtml+xml; charset=UTF-8' );
        } else {
            header( 'Content-Type: text/html; charset=UTF-8' );
        }
        // Disallow Internet Explorer from attempting to second guess the Content-Type
        // header as per http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-pro
        header( 'X-Content-Type-Options: nosniff' );
    }
}

On another quick side-note: I had some custom HTML to include my own header to mantis, which caused an XML parse error – this was because I didn’t close the img tag for an embedded image.

Integrated Windows Authentication in Mantis (Updated to Mantis 1.2.1)

In a previous post I described the necessary steps, to enable integrated windows authentication when working with Mantis on a linux box. These modifications where targeted against the 1.1.0a2 release of Mantis. In the meantime a lot of development has been done on Mantis, so that my original post isn’t quite accurate anymore. This post will enable you to use integrated security with the current 1.2.1 release of Mantis.

While the basic setup is somewhat unchanged, only the file core/authentication_api.php needs to be changed. The login.php doesn’t need to be changed anymore, since the functionallity moved to the authentication_api.php.

I added an updated patchfile to apply the necessary changes to the file.

PHP Installation

Grundsätzlich gibt es zwei unterschiedliche Möglichkeiten um PHP für den IIS unter Windows zu installieren. Zum Einen kann man PHP manuell installieren, zum Anderen gibt es einen fertigen Installer. Da ich bisher PHP immer nur manuell installiert habe, und das ganze auch mit wenigen Handgriffen erledigt ist, werde ich auch nur diesen Weg beschreiben. Auch gibt es verschiedene Möglichkeiten PHP mit dem IIS zu “verbinden”, am einfachsten und am häufigsten ist die Verwendung des ISAPI-Filters.

Diese Anleitung beschreibt das Vorgehen für den IIS 5.x; für Windows 2003 bzw. den IIS 6 sieht das ganze ein wenig anders aus, da muss man den ISAPI-Filter noch explizit zur Auführung aktivieren.

  1. Für die Installation muss zunächst die aktuelle PHP-Version von php.net als ZIP-Archiv herungeladen und in ein beliebiges Verzeichnis entpackt werden.
  2. Über Systemsteuerung\Verwaltung die IIS-Verwaltungskonsole Internet-Informationsdienste starten. Nun gibt es grundsätzlich ein paar Alterantiven:
    1. PHP wird für den gesamten Server eingerichtet
    2. PHP wird nur für ein einzelnes Verzeichnis oder einen einzelnen virtuellen Server eingerichtet

    Grundsätzlich ist das Vorgehen identisch, ausser daß einmal die Eigenschaften des Servers und ansonsten die Eigenschaften eines Verzeichnisses oder eines virtuellen Servers geändert werden müssen.

  3. In den Eigenschaften auf die Reiterkarte “Basisverzeichnis” wechseln und ggf. eine neue Anwendung konfigurieren. Bei virutellen Servern oder Verzeichnissen die Ausführungsberechtigung auf “nur Skritps” setzen.
  4. Anschließend auf “Konfiguration” und auf “Hinzufügen” klicken. Als ausführbare Datei die php5isapi.dll auswählen, Dateierweiterung ist .php. Bei den Verben kann nun alle ausgewählt werden, wodurch alle HTTP-Methoden zugelassen werden (auch solche wie OPTIONS oder PROPFIND), oder das ganze auf GET, POST, HEAD einschränken. Abschließend noch sicherstellen, daß die Haken bei “Skriptmodul” und “Prüfen, ob Datei existiert” gesetzt sind.

Die Einrichtung ist nun schon fast vollständig abgeschlossen. Um die Konfiguration von PHP noch vornehmen zu können muss entweder die php.ini in das %WINDIR%\system32 kopiert werden, oder PHP muss per Umgebungsvariable PHPRC mitgeteilt werden in welchem Verzeichnis sich die php.ini befindet. Nach dem setzen der Umgebungsvariable muss der Rechner ggf. neu gestartet werden, bevor die Änderung übernommen werden kann, weil die Umgebungsvariablen von dem IIS nur während des bootens ausgelesen werden.

PHP Installation: Microsoft IIS / PWS (englisch)

Integrated Windows Authentication in Mantis

Update: a new post is availbe, with an updates patchfile for Mantis 1.2.1!

The more tools are being used in an enterprise environment, the more logins and passwords need to be memorized. A first step is to use LDAP based authenticatin. In MS Windows based networks this offers to ability to manage all users in the Active Directory, so the users only have to use on username/password. But the user will still have to enter this into a login-screen in order to access the application.

Using SSO the user is always identified by already existind credentials. In the best case, the logon credetials of the operating system are being used. Since Active Directory is based on the Kereberos authentication protocoll, this offers the ability to use kerberos based authentication in other applications, and thus re-using the existing windows authentication.

The Internet Explorer is capable of using the windws logon-credentials to authenticate users on certain webservers. But with a slight modification this can also be used on an Apache running on a linux box. How to setup Apache to allow kerberos authentication is explained in another article. Once Apache is setup correct, Mantis needs to be slightly modified to use the information supplied by the kerberos authentication. My modifications are all based on the current development-release of mantis 1.1.0a2.

Modifing Mantis

Basically three files need to be modified: core\authentication_api.php, login.php and config.inc.php.

  1. In config.inc.php I switch from LDAP authentication to HTTP_AUTH, since I wand the webserver to handle the authentication. Also I introduce a new configuration setting sso_user_regex. This is needed, because I need to extract the username from the user identified by the webserver. So I use this handy little regex to do this for me:
             $g_login_method    = HTTP_AUTH;
             $g_sso_user_regex  = '/^(.*)@ACME\.COM$/i';

    This regex would extract the username portion for users of the domain “ACME.COM”.

  2. Next would be to modify login.php to extract the username from the authenticated user, if the user was detected using “Negotiation” (which is the case if IWA was used). So I apply my previously defined regex to the “Remote-User” variable of the server to get my mantis username. So we have to insert some code at line 32:
          if ( isset($_SERVER['REMOTE_USER'])) { #  $_SERVER['AUTH_TYPE'] == 'Negotiate' )
            preg_match(config_get('sso_user_regex'), $_SERVER['REMOTE_USER'], $user_match);
            $f_username = $user_match[1];
          }
  3. The last step is to add an additional condition to the authentication_api.php to prevent from trying to authenticate the user with the mantis user database using the username and password. This would only work, if the username and password would be supplied by the webserver, but using IWA we only have the username (the password is not transmitted in IWA, only the logon-challange). So this would only work if Basic Authentication would be used instead of kerberos authentication. So validating username and password with the mantis user database is restricted for HTTP_AUTH by modifing line 121:
          if ( HTTP_AUTH != $t_login_method && !auth_does_password_match( $t_user_id, $p_password ) ) {
          # if ( !auth_does_password_match( $t_user_id, $p_password ) ) {

So this should be all, to get Integrated Windows Authentication running. Below is a patchfile to apply the changes of authentication_api.php and login.php.

Attached you’ll find a patch-file to modified the corresponding files. To apply the patch you simple need to execute (assuming you have patch, and you’re executing it within your install-directory of Mantis):

   patch < iwa_sso.patch -p0

Download: iwa_sso patch