The Error:
functions.phpFatal error: Cannot redeclare authenticatead() (previously declared in D:\Inetpub\wwwcrud\functions.php:39) in D:\Inetpub\wwwcrud\functions.php on line 96
Code: Select all
<?php
/*
** List of Existing Functions **
authenticatead($fnusername, $fnpassword) //Function that authenticates user to AD
- returns array - $adresults
- $adresults[0] - 1 for authenticated, 0 for not authenticated
- $adresults[1] - Department
- $adresults[2] - Permissions
pulluserdbinfo($username) //Function that pulls information about the user from the DB
-returns mssql db handle
adtodb($username, $password) //Function that pulls user's information from AD and puts it into the DB
- returns array $userinfo
- $userinfo[0] - E-mail Address
- $userinfo[1] - Firstname
- $userinfo[2] - Lastname
- $userinfo[3] - Badge Number
startusersession($username, $badge, $firstname, $lastname, $email, $department, $permissions) //Starts a session with the user's information
endusersession() //Ends a user's session
caseexists($complaintno) //Checks for the existence of a case
- returns number of cases found
startnewcase($complaintno, $badge, $datetime) //Inputs basic case data into DB
mssql_escape_string($string_to_escape) //Cleans URL variables for MSSQL use
- returns cleaned variable
departmentcheck() //Check to see what department a case belongs to
- not started
function pullcaseinfo() //Pulls basic case information
- returns SQL row
*/
function authenticatead($fnusername, $fnpassword) //Function that authenticates user to AD
{
include("./config.php");
//Connection
$ad = ldap_connect($host) or die( "Could not connect to Active Directory! Contact Helpdesk.<br>" );
//Set LDAP Version Info
ldap_set_option($ad, LDAP_OPT_PROTOCOL_VERSION, 3) or die ("Could not set ldap protocol<br>");
ldap_set_option($ad, LDAP_OPT_REFERRALS,0);
//Bind to AD - Actual Username Authentication Test
if (!($bd = ldap_bind($ad, $fnusername . $usersuffix, $fnpassword)))
{
//Did not pass AD authentication
$adresults[0] = "0";
} else {
//Passed AD authentication
$adresults[0] = "1";
}
if ($adresults[0] == "1") {
//Passed authentication, see what CRUD groups they are part of
//See if user is part of any groups in AD
$bd = ldap_bind($ad, $fnusername . $usersuffix, $fnpassword) or die ("Could not bind<br>");
// Create the DN
$dn = "****Taken out for security****";
// Specify only those parameters we're interested in displaying
$attrs = array("displayname");
// Create the filter from the search parameters
$filter = "(samaccountname=" . $fnusername . ")";
$search = ldap_search($ad, $dn, $filter) or die ("ldap search failed<br>");
$entries = ldap_get_entries($ad, $search);
for ($i=0; $i<$entries[0]["memberof"]["count"]; $i++) {
if (substr($entries[0]["memberof"][$i], 0, 7) == "CN=CRUD") {
$sections = explode(",", $entries[0]["memberof"][$i]);
$permissions = explode("_", $sections[0]);
}
}
ldap_unbind($ad);
if (isset($permissions)) {
if ($permissions[1] == "Admin") {
$adresults[1] = "Admin";
$adresults[2] = "Admin";
} else {
$adresults[1] = $permissions[1];
$adresults[2] = $permissions[2];
}
}
}
return $adresults;
}
?>