Login.php: Opening log facility [failure]


"; // print_end(); // flush(); } /* * End */ exit(); } else { // if ($debug) { // syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Opening log facility [success]"); // foreach ($_GET as $key => $value) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_GET[$key] is " . $_GET[$value]); } // foreach ($_SESSION as $key => $value) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION[$key] is " . $_SESSION[$value]); } // foreach ($_POST as $key => $value) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_POST[$key] is " . $_POST[$value]); } } // if ($debug) /* * If the user has successfully logged in go to his profile */ if ( isset($_SESSION['loggedIn']) && isset($_SESSION['userId']) ) { header("Location: MyProfile.php?showUser=" . $userId); } /* * Mark username and role attributes as unset */ unset($_SESSION['nsRole']); unset($_SESSION['userName']); // if ($debug) { // syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION['nsRole'] is " . $_SESSION['nsRole']); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION['userName'] is " . $_SESSION['userName']); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_POST['givenUserName'] is " . $_POST['givenUserName']); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_POST['givenPassword'] is " . $_POST['givenPassword']); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_POST['submitlogin'] is " . $_POST['submitlogin']); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_POST['givenUserName'] is " . $_POST['givenUserName']); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_POST['givenPassword'] is " . $_POST['givenPassword']); } // if ($debug) /* * If variable 'submitLogin' has been set in a previous POST */ if (array_key_exists('submitLogin', $_POST)) { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable 'submitlogin' is set"); } $userName = $_POST['givenUserName']; $passWord = $_POST['givenPassword']; // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable 'userName' is " . $userName); syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable 'passWord' is " . $passWord); } // if ($debug) // $ds=ldap_connect("localhost"); // Must be a valid LDAP server! If port different than 389 must be provided also // if ($ds) { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Connecting to LDAP server [success]"); } /* * 20061223 : Modified by Vangelis to accommodate upgrade to LDAPv3 protocol */ if (ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3)) { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Setting LDAP protocol to LDAPv3 [success]"); } /* * LDAP schema */ $userdn="ou=People,ou=CNL,ou=di,dc=UoA,dc=gr"; // $r=@ldap_bind($ds, "uid=$userName,$userdn", $passWord); if ($r) { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Authenticating user to LDAP server [success]"); } /* * Update login status */ $_SESSION['loggedIn'] = true; // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION['loggedIn'] is set to " . $_SESSION['loggedIn']); } /* * Register username with session */ $_SESSION['userName'] = $username; // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION['userName'] is set to " . $_SESSION['userName']); } // Must be set according to the session variable $id = $userName; // Set the filter for the searh to be performed. Probably more conditions should be added eventually $filter="uid=$id"; // Set the array of attributes to be returned by search $attrs = array("uid","cn","nsRole" ); /* * Set the DN under which the search will be performed */ $dn="ou=CNL,ou=di,dc=UoA,dc=gr"; // // Perform the search. Configured to return only the first occurence // $results=ldap_search($ds, $dn, $filter); // // If correct it should return one (1) if one user is found // $count=ldap_count_entries($ds, $results); // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": LDAP search returns " . $count . " results"); } // // Retrieve the userId from the mySQL database for the given user // @ $db = mysql_connect( "localhost", "cnlweb", "cnlweb" ) or die("Error:could not connect to database!"); // mysql_select_db( "cnl2" ); $query = "SELECT distinct * FROM Members WHERE Username='" . $userName . "'"; $result = mysql_query($query) or die(mysql_error($db)); /* * If the SQL query was successful */ if ($result) { // $row = mysql_fetch_array($result); // $userId = $row["ID"]; // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": MySQL search found user " . $userName . " (MySQL ID = " . $userId . ")"); } /* * Register the userId with the session */ $_SESSION['userId'] = $userId; // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION['userId'] is set to " . $_SESSION['userId']); } } else { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": MySQL search did not find user " . $userName); } /* * End */ exit(); } /* * Retrieve the user 'nsRole' attribute from the LDAP directory (if it exists) */ /* * Since only one user record was found in the LDAP directory */ if ($count == 1) { /* * First entry should also be only entry */ $entry = ldap_first_entry($ds, $results); /* * Get its attributes */ $attributes = ldap_get_attributes($ds, $entry); // if ($debug) { for ($i=0; $i < count($attributes); $i++) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Found LDAP attribute: " . $attributes[$i]); } } /* * Read the value of the 'nsRole' attribute */ $values = ldap_get_values($ds, $entry, "nsRole"); // $nsRole = $values[0]; /* * Register the nsRole with the session */ $_SESSION['nsRole'] = $nsRole; if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Variable \$_SESSION['nsRole'] is set to " . $nsRole); } // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Redirecting to MyProfile.php?showUser=" . $userId); } /* * Show user */ // header("Location: MyProfile.php?showUser=-1"); header("Location: MyProfile.php?showUser=" . $userId); } else { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": User " . $userName . " not found in LDAP"); } /* * End */ exit(); } /* * Close LDAP connection */ ldap_close($ds); // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Disconnecting from LDAP server [success]"); } } else { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Setting LDAP protocol to LDAPv3 [failure]"); } /* * End */ exit(); } } else { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Authenticating user to LDAP server [failure]"); } /* * End */ exit(); } } else { // if ($debug) { syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Connecting to LDAP server [failure]"); } /* * End */ exit(); } // syslog(LOG_INFO, basename($_SERVER['PHP_SELF']) . ": Closing log facility [success]"); /* * Close the log */ closelog(); } } function print_start() { echo " CNL Member Login



Username
Password



"; } function print_end() { echo ""; } print_start(); print_end(); ?>