first commit
This commit is contained in:
73
adLDAP/examples/authenticate.php
Executable file
73
adLDAP/examples/authenticate.php
Executable file
@ -0,0 +1,73 @@
|
||||
<?php
|
||||
//log them out
|
||||
$logout=$_GET['logout'];
|
||||
if ($logout=="yes"){ //destroy the session
|
||||
session_start();
|
||||
$_SESSION = array();
|
||||
session_destroy();
|
||||
}
|
||||
|
||||
echo $_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']."<br>";
|
||||
//force the browser to use ssl (STRONGLY RECOMMENDED!!!!!!!!)
|
||||
#if ($_SERVER["SERVER_PORT"]!=443){ header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']); exit(); }
|
||||
|
||||
//you should look into using PECL filter or some form of filtering here for POST variables
|
||||
$username=strtoupper($_POST["username"]); //remove case sensitivity on the username
|
||||
$password=$_POST["password"];
|
||||
$formage=$_POST["formage"];
|
||||
|
||||
if ($_POST["oldform"]){ //prevent null bind
|
||||
|
||||
if ($username!=NULL && $password!=NULL){
|
||||
//include the class and create a connection
|
||||
include ("../adLDAP.php");
|
||||
try {
|
||||
$adldap = new adLDAP();
|
||||
}
|
||||
catch (adLDAPException $e) {
|
||||
echo $e; exit();
|
||||
}
|
||||
|
||||
//authenticate the user
|
||||
if ($adldap -> authenticate($username,$password)){
|
||||
//establish your session and redirect
|
||||
session_start();
|
||||
$_SESSION["username"]=$username;
|
||||
$redir="Location: http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/menu.htm";
|
||||
header($redir);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
$failed=1;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>adLDAP example</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
This area is restricted.<br>
|
||||
Please login to continue.<br>
|
||||
|
||||
<form method='post' action='<?php echo $_SERVER["PHP_SELF"]; ?>'>
|
||||
<input type='hidden' name='oldform' value='1'>
|
||||
|
||||
Username: <input type='text' name='username' value='<?php echo ($username); ?>'><br>
|
||||
Password: <input type='password' name='password'><br>
|
||||
<br>
|
||||
|
||||
<input type='submit' name='submit' value='Submit'><br>
|
||||
<?php if ($failed){ echo ("<br>Login Failed!<br><br>\n"); } ?>
|
||||
</form>
|
||||
|
||||
<?php if ($logout=="yes") { echo ("<br>You have successfully logged out."); } ?>
|
||||
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
123
adLDAP/examples/examples.php
Executable file
123
adLDAP/examples/examples.php
Executable file
@ -0,0 +1,123 @@
|
||||
<?
|
||||
/*
|
||||
Examples file
|
||||
|
||||
To test any of the functions, just change the 0 to a 1.
|
||||
*/
|
||||
|
||||
//error_reporting(E_ALL ^ E_NOTICE);
|
||||
|
||||
include ("../adLDAP.php");
|
||||
try {
|
||||
$adldap = new adLDAP($options);
|
||||
}
|
||||
catch (adLDAPException $e) {
|
||||
echo $e; exit();
|
||||
}
|
||||
//var_dump($ldap);
|
||||
|
||||
echo ("<pre>\n");
|
||||
|
||||
// authenticate a username/password
|
||||
if (0){
|
||||
$result=$ldap->authenticate("username","password");
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// add a group to a group
|
||||
if (0){
|
||||
$result=$ldap->group_add_group("Parent Group Name","Child Group Name");
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// add a user to a group
|
||||
if (0){
|
||||
$result=$ldap->group_add_user("Group Name","username");
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// create a group
|
||||
if (0){
|
||||
$attributes=array(
|
||||
"group_name"=>"Test Group",
|
||||
"description"=>"Just Testing",
|
||||
"container"=>array("Groups","A Container"),
|
||||
);
|
||||
$result=$ldap->group_create($attributes);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// retrieve information about a group
|
||||
if (0){
|
||||
$result=$ldap->group_info("Group Name");
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// create a user account
|
||||
if (0){
|
||||
$attributes=array(
|
||||
"username"=>"freds",
|
||||
"logon_name"=>"freds@mydomain.local",
|
||||
"firstname"=>"Fred",
|
||||
"surname"=>"Smith",
|
||||
"company"=>"My Company",
|
||||
"department"=>"My Department",
|
||||
"email"=>"freds@mydomain.local",
|
||||
"container"=>array("Container Parent","Container Child"),
|
||||
"enabled"=>1,
|
||||
"password"=>"Password123",
|
||||
);
|
||||
|
||||
try {
|
||||
$result=$ldap->user_create($attributes);
|
||||
var_dump($result);
|
||||
}
|
||||
catch (adLDAPException $e) {
|
||||
echo $e; exit();
|
||||
}
|
||||
}
|
||||
|
||||
// retrieve the group membership for a user
|
||||
if (0){
|
||||
$result=$ldap->user_groups("username");
|
||||
print_r($result);
|
||||
}
|
||||
|
||||
// retrieve information about a user
|
||||
if (0){
|
||||
$result=$ldap->user_info("username");
|
||||
print_r($result);
|
||||
}
|
||||
|
||||
// check if a user is a member of a group
|
||||
if (0){
|
||||
$result=$ldap->user_ingroup("username","Group Name");
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// modify a user account (this example will set "user must change password at next logon")
|
||||
if (0){
|
||||
$attributes=array(
|
||||
"change_password"=>1,
|
||||
);
|
||||
$result=$ldap->user_modify("username",$attributes);
|
||||
var_dump($result);
|
||||
}
|
||||
|
||||
// change the password of a user
|
||||
if (0){
|
||||
try {
|
||||
$result=$ldap->user_password("username","Password123");
|
||||
var_dump($result);
|
||||
}
|
||||
catch (adLDAPException $e) {
|
||||
echo $e; exit();
|
||||
}
|
||||
}
|
||||
|
||||
// list the contents of the Users OU
|
||||
if (0){
|
||||
$result=$ldap->folder_list(array('Users'), ADLDAP_FOLDER, false);
|
||||
var_dump ($result);
|
||||
}
|
||||
?>
|
5
adLDAP/examples/menu.htm
Executable file
5
adLDAP/examples/menu.htm
Executable file
@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
If you called authenticate.php and you are redirected to this page, you successfully authenticated against Active Directory
|
||||
</body>
|
||||
</html>
|
Reference in New Issue
Block a user