Skip to content

Instantly share code, notes, and snippets.

@durzo
Created January 8, 2020 12:59
Show Gist options
  • Save durzo/521b29f911496b6fe4c8a5a7a0bed495 to your computer and use it in GitHub Desktop.
Save durzo/521b29f911496b6fe4c8a5a7a0bed495 to your computer and use it in GitHub Desktop.
pnp4nagios authenticate with Icinga
<?php
namespace Icinga;
class User extends \stdClass {
public $localUsername;
public $groups;
}
function icinga_login() {
header("Location: /authentication/login");
die();
}
if (isset($_COOKIE['Icingaweb2'])) {
$sessionfile = ini_get("session.save_path")."/sess_".$_COOKIE['Icingaweb2'];
if (file_exists($sessionfile)) {
$sessiondata = file_get_contents($sessionfile);
session_start();
session_decode($sessiondata);
if (empty($_SESSION['user'])) {
icinga_login();
}
if (!in_array("Administrators", $_SESSION['user']->groups)) {
error_log("user (". $_SESSION['user']->localUsername .") has icinga cookie but is not in Administrators group");
die();
}
session_destroy();
}else {
// session does not exist on disk. timeout.
icinga_login();
}
}else {
// no Icingaweb2 cookie passed.
icinga_login();
}
// Rest of original file remains untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment