Changing User Passwords

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
szkoda
Posts: 42
Joined: Thu Dec 04, 2014 8:48 am

Changing User Passwords

Post by szkoda »

Is there a way I can allow Nagios users to change thier own passwords?

Currently using 4.x with no additional front ends or addons.

I found this but there are no actual instructions on how to install it?

https://exchange.nagios.org/directory/A ... te/details
User avatar
rhassing
Posts: 416
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Changing User Passwords

Post by rhassing »

It should be not so hard to write your own script.

index.php to select the user and mailaddress:

Code: Select all

<head>
<title>Password recovery for Nagios</title>
</head>
<body>
<center>
<h1>Password recovery for Nagios<sup><font size=-2>4.0.X</font></sup> </h1>
</center>
<FORM METHOD="post" ACTION="mailform.php" onsubmit="return checkform(); return false;">
<table cellpadding=5 cellspacing=0 border=0>
<tr><td colspan=2><b>Which users password should be changed?</b></td></tr>
<tr><td width=80>Mailadres:</td><td><input type="text" name="mailadres" [email protected]></td></tr>
<tr><td width=80>Gebruikersnaam:</td><td>
</td></tr>

<tr><td width=80>Password:</td><td><input type="password" name="password"></td></tr>
</table>
<br><br>
        <input type="submit" name="button" value="Verzenden">
        </form>
</body>
</html>
Mailform.php to submit the form:

Code: Select all

<?php
// read the variables...
$adres=$_POST["mailadres"];
$password=$_POST["password"];

if($adres=="[email protected]"){ $name="user1"; $mail="[email protected]";  change($mail,$name,$password);}
elseif($adres=="[email protected]"){ $name="user2"; $mail="[email protected]";  change($mail,$name,$password);}
else { echo "Something went wrong, mailaddress unknown. $adres"; }


function change($mail,$name,$password) {
if($password=="") {
$passwd=exec("openssl rand -base64 6");
} else {
$passwd=$password;
}

$pwd = shell_exec("/usr/local/bin/passwd-recovery.sh $name $passwd $mail");
echo $pwd;
}
?>
And the shell scrtip to do the change:

Code: Select all

#!/bin/bash
name=$1;
passwd=$2;
mailadres=$3;


echo "<h1> The new password for <font color=red> $name </font> is now changed! <!-- $passwd --></h1><br><br>"
echo "<br><br><br>"

sudo htpasswd -D /etc/nagios/htpasswd.users $name
sudo htpasswd -mb /etc/nagios/htpasswd.users $name $passwd

echo "<br><br><br>"
echo "<h1>A mail is sent to: <font color=red>$mailadres </font>, If you did not receive the mail, please contact your administrator<br><br><br></h1>"
# Email text/message
EMAILMESSAGE="The password for $name is changed"
# send an email using /bin/mail
echo $EMAILMESSAGE | /bin/mail -s "The new password for Nagios 4.0.X WEB environment" "$mailadres"
exit
Rob Hassing
Image
szkoda
Posts: 42
Joined: Thu Dec 04, 2014 8:48 am

Re: Changing User Passwords

Post by szkoda »

Sorry this is way above my knowledge of Nagios - how do I go about installing this script?
User avatar
rhassing
Posts: 416
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Changing User Passwords

Post by rhassing »

Actually this has nothing to do with Nagios, this is standard Linux.
Rob Hassing
Image
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Changing User Passwords

Post by tmcdonald »

Something like this is just another web page, and as rhassing pointed out is not something that would be loaded up in a nagios config file.

It's simply a set of web pages and a bash script that will present users with a page to change passwords. You would host these files somewhere on your web server (making sure not to overwrite any Nagios files) and then view the web page directly.
Former Nagios employee
Locked