summaryrefslogtreecommitdiff
path: root/list_users.php
blob: 17d9e038d23f8de7bc93db127a197adb13475a33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
require_once("ldap_config.php");

$bind_rdn = "uid=".$_SERVER["PHP_AUTH_USER"].",".$baseDn;
$bind_password = $_SERVER["PHP_AUTH_PW"];

$ldap_ds = ldap_connect($hostname, $port) or die("Could not connect to LDAP");

ldap_set_option($ldap_ds,LDAP_OPT_PROTOCOL_VERSION,3);

$connected = @ldap_bind($ldap_ds, $bind_rdn, $bind_password);

if ($connected) {
$result = ldap_search($ldap_ds, $baseDn, "(uid=*)") or die ("Error in search query: ".ldap_error($ldap_ds));
$data = ldap_get_entries($ldap_ds, $result);
?>
<!DOCTYPE html>
<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>LDAP Users</title>
	<script type="text/javascript" src="js/prototype/prototype.js"></script>
	<script type="text/javascript" src="js/prototype-window/javascripts/window.js"></script>
	 <link href="js/prototype-window/themes/default.css" rel="stylesheet" type="text/css"/>
	  <!-- Add this to have a specific theme--> <link href="js/prototype-window/themes/alphacube.css" rel="stylesheet" type="text/css"/> 
	<style type="text/css">
		label, input, select { /* Alle Labels UND Formularelemente auswählen */
		  display: block;
		  float: left;
		  width: 250px; /* Breite.*/
		}
		
		label {
			width: 100px;
			text-align: right;
			padding-right: 15px;
		}
		
		form br { /* Alle Zeilenumbrüche in Formularen auswählen */
		  clear: left; /* das floating der labels und inputs aufheben */
		}
		
		input#submit { /* den Submit-Button */
		  float: none;
		  width: auto;
		}
	</style>
	<script type="text/javascript">
	function openDialog(uid, title) {
		Dialog.confirm($(uid+"_dialog").innerHTML,
			{className: "alphacube",
			 width: 400,
			 title: title,
			 okLabel: "speichern",
			 cancelLabel: "abbrechen", 
			 onOk: function(win) {
				new Ajax.Request("modify_ldap_user.php", {
					method: "post",
					parameters: $(uid + "_form").serialize(true),
					onSuccess: function(transport) {
						var response = transport.responseText || "no response text";
						alert("Success! \n\n" + response);
					},
					onFailure: function() {
						$(uid + "_error").innerHTML = "something went wrong";
						$(uid + "_error").show();
						Windows.focusedWindow.updateHeight();
						return false;
					}
				});
			}
			}
		);
	}
	</script>
	</head>
	<body>
	<p>Du bist eingeloggt als: <?php echo $_SERVER['PHP_AUTH_USER']; ?></p>
	<?php
	function cmp($a, $b) {
		return strcmp($a["cn"][0], $b["cn"][0]);
	}
	
	usort($data, "cmp");
	
	foreach ($data as $entry) {
	$uid = $entry['uid'][0];
	$dn = $entry["dn"];
	?>
	<div id="<?=$uid?>_dialog" style="display:none">
		<span id="<?=$uid?>_error" style="display:none; float: left; color: red">&nbsp;</span>
		<form id="<?=$uid?>_form">
		<?php
		foreach ($entry as $key=>$value) {
		if (is_numeric($key) || "objectclass" == $key || "count" == $key || "dn" == $key) {
			continue;
		}
		?>
		<label for="<?=$uid?>_<?=$key?>"><?=$key?></label>
		<input id="<?=$uid?>_<?=$key?>" name="<?=$key?>" type="text" value="<?=$value[0]?>"/><br/>
		<?php
		}
		?>
		<label for="<?=$uid?>_resetPassword">Passwort zur&uuml;cksetzen</label> <input type="checkbox" value="yes" id="<?=$uid?>_resetPassword" name="resetPassword"/>
		</form>
	</div>
	<a href="javascript:openDialog('<?=$uid?>', '<?=$dn?>')"><?=$entry['cn'][0]?></a><br/>
	<?php
	}
	?>
	</body>
</html>
<?php
} else {
	if (49 == ldap_errno($ldap_ds)) {
		echo "Falsches Passwort";
	} else {
		echo "LDAP Error: '".ldap_error($ldap_ds)."'";
	}
}
?>