Translations of this page:

Anpassen der Authentifizierung via Nagios

Vor- und Nachteile

Vorteile:

  • Nur eine Anmeldung
  • Gruppen unter Nagios kann ein Bereich im Wiki zur Pflege deren Daten zugewiesen werden.

Nachteile:

  • Die User müssen im Wiki und in Nagios geflegt werden.

Vorraussetzung:

  • Das Wiki muss im share-Verzeichnis von Nagios liegen.
  • Die Authenifizierung im Wiki muss eingeschaltet sein.
  • Die Authenifizierung in Nagios muss eingeschaltet sein.
  • Die Authenifizierung im Wiki muss auf md5-Verschlüsselung (default) eingestellt sein.
  • Benutzername und Passwort müssen im Wiki mit Nagios übereinstimmen.

Hinweis:

Die User von Nagios können sehr leicht in das Wiki übernommen werden. Dazu einfach den jeweiligen User aus der htpasswd.users

htpasswd.users

 nagiosadmin:SjdiKs9=*ds

kopieren und in der users.auth.php einfügen. Die fehlenden Info's ergänzen.

users.auth.php

 nagiosadmin:SjdiKs9=*ds:Vollständiger Name:Mail:Gruppe

Fertig!

Los geht's

Wenn alle Vorrausetzungen gegeben sind, kann es los gehen!

  • Datei nagios.php im Wiki-Verzeichnis inc/auth mit foldendem Inhalt erstellen:
<?php
/**
 * Nagios authentication backend
 *
 * If you want to authenticate against something
 * else then the builtin flatfile auth system
 * you have to reimplement the "required auth
 * functions"
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author (original:plain.php)    Andreas Gohr <andi@splitbrain.org>
 * @author (changes:nagios.php)    Michael Luebben
 */
 
if(isset($_SERVER['PHP_AUTH_USER']))
  $_REQUEST['u'] = cleanID($_SERVER['PHP_AUTH_USER']);
/**
 * Check user+password [required auth function]
 *
 * Checks if the given user exists and the given
 * plaintext password is correct
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 * @return  bool
 */
function auth_checkPass($user,$pass){
  $users = auth_plain_loadUserData();
 
  if(!isset($users[$user])) return false;
 
  //return auth_verifyPassword($pass,$users[$user]['pass']);
  return auth_verifyPassword($_SERVER['PHP_AUTH_PW'],$users[$user]['pass']);
}
 
/**
 * Return user info [required auth function]
 *
 * Returns info about the given user needs to contain
 * at least these fields:
 *
 * name string  full name of the user
 * mail string  email addres of the user
 * grps array   list of groups the user is in
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 */
function auth_getUserData($user){
  $users = auth_plain_loadUserData();
  return $users[$user];
}
 
/**
 * Create a new User [required auth function]
 *
 * Returns false if the user already exists, null when an error
 * occured and the cleartext password of the new user if
 * everything went well.
 *
 * The new user HAS TO be added to the default group by this
 * function!
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 */
function auth_createUser($user,$pass,$name,$mail){
  global $conf;
 
  $users = auth_plain_loadUserData();
  if(isset($users[$user])) return false;
 
  $userline = join(':',array($user,
                             auth_cryptPassword($pass),
                             $name,
                             $mail,
                             $conf['defaultgroup']));
  $userline .= "\n";
  $fh = fopen(DOKU_INC.'conf/users.auth.php','a');
  if($fh){
    fwrite($fh,$userline);
    fclose($fh);
    return $pass;
  }
  msg('The users.auth.php file is not writable. Please inform the Wiki-Admin',-1);
   return null;
}
 
/**
 * Load all user data
 *
 * Used by the plaintext auth functions
 * loads the user file into a datastructure
 *
 * @author  Andreas Gohr <andi@splitbrain.org>
 */
function auth_plain_loadUserData(){
  $data = array();
  if(!@file_exists(DOKU_INC.'conf/users.auth.php')){
    return $data;
  }
  $lines = file(DOKU_INC.'conf/users.auth.php');
  foreach($lines as $line){
    $line = preg_replace('/#.*$/','',$line); //ignore comments
    $line = trim($line);
    if(empty($line)) continue;
 
    $row    = split(":",$line,5);
    $groups = split(",",$row[4]);
    $data[$row[0]]['pass'] = $row[1];
    $data[$row[0]]['name'] = urldecode($row[2]);
    $data[$row[0]]['mail'] = $row[3];
    $data[$row[0]]['grps'] = $groups;
  }
  return $data;
}
  • In der dokuwiki.php den authtype auf nagios stellen.
   $conf['authtype']    = 'nagios';
 
  • Als letztes entfernen wir noch den An- und Abmeldebutton. Dazu öffnen wir die Datei inc/template.php und suchen folgende Zeilen:
288     case 'login':
289       if($conf['useacl']){
290         if($_SERVER['REMOTE_USER']){
291           print html_btn('logout',$ID,'',array('do' => 'logout',));
292         }else{
293           print html_btn('login',$ID,'',array('do' => 'login'));
294         }
295       }
296       break;

und ändern diesen folgdermaßen ab:

288       case 'login':
289       break;

Fertig! Wenn Ihr euch jetzt an Nagios anmeldet und das Wiki dann aufruft solltet Ihr wie gewohnt ohne Anmeldung im Wiki arbeiten können.

FAQ's

Frage: Nach dem kopieren des Wiki-Verzeichnisses kann ich das Wiki nicht aufrufen. Es erscheint immer die Fehlermeldung:

Apache Error 500 (Internal Server Error)

Antwort: Die Datei .htaccess aus folgenden Verzeichnissen entfernen:

  • wiki
  • wiki/inc
  • wiki/conf

Noch weiter Fragen dazu?

Wenn Ihr Probleme oder Fragen habt, so postet diese einfach im Forum

MiCkEy2002 30.09.2005 10:02

nagios/howtos/wiki_auth.txt · Zuletzt geändert: 2005/10/20 16:43 von lairdofglencairn
CC Attribution-Noncommercial-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0