From daf4485f1aa12e79d31480c9c81fa50b837f1292 Mon Sep 17 00:00:00 2001 From: Robert Anderson <randerson@lbsd.net> Date: Thu, 2 Jul 2009 14:46:40 +0000 Subject: [PATCH] Send email notification on successful multi user add --- webgui/include/ajax/functions/WiSPUsers.php | 45 +++++++++++++++++++++ webgui/include/config.php | 5 ++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/webgui/include/ajax/functions/WiSPUsers.php b/webgui/include/ajax/functions/WiSPUsers.php index c72c5c1a..57b8c23c 100644 --- a/webgui/include/ajax/functions/WiSPUsers.php +++ b/webgui/include/ajax/functions/WiSPUsers.php @@ -195,6 +195,7 @@ function removeWiSPUser($params) { # Add wisp user function createWiSPUser($params) { global $db; + global $adminEmails; DBBegin(); $res = "Username & Password required for single user. For adding multiple users an integer is required."; @@ -428,6 +429,7 @@ function createWiSPUser($params) { $res = DBDo("INSERT INTO users_to_groups (UserID,GroupID) VALUES (?,?)",array($id,$groupID)); } } + # Link to wisp users if ($res !== FALSE) { $res = DBDo("INSERT INTO wisp_userdata (UserID) VALUES (?)", @@ -436,6 +438,49 @@ function createWiSPUser($params) { } } } + + # Email userlist to admin + if ($res !== FALSE && isset($adminEmails)) { + + // multiple recipients + $to = $adminEmails; + + // subject + $subject = count($wispUser).' WiSP users added'; + + // html + $html = ''; + + foreach ($wispUser as $key => $val) { + $html .= '<tr><td>'.$key.'</td><td>'.$val.'</td></tr>'; + } + + // message + $message = ' + <html> + <head> + <title>User List</title> + </head> + <body> + <table cellspacing="10"> + <tr> + <th>Username</th><th>Password</th> + </tr>'.$html.' + </table> + </body> + </html> + '; + + // To send HTML mail, the Content-type header must be set + $headers = 'MIME-Version: 1.0' . "\r\n"; + $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; + + // Additional headers + $headers .= 'From: SMRadius'; + + // Mail it + $res = mail($to, $subject, $message, $headers); + } } # Commit changes if all was successful, else rollback diff --git a/webgui/include/config.php b/webgui/include/config.php index 5de0edcd..838e4861 100644 --- a/webgui/include/config.php +++ b/webgui/include/config.php @@ -32,8 +32,9 @@ $DB_PASS="root"; $DB_TABLE_PREFIX=""; -# Admin email -# $adminEmail = 'admin@example.com'; +# Email address/addresses to receive notifications +# Seperated by commas, eg. "admin@example.org,admin@example.net" +# $adminEmails="admin@example.org"; -- GitLab