File: example.php

package info (click to toggle)
phpldapadmin 1.2.6.7-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 5,528 kB
  • sloc: php: 17,684; javascript: 5,299; xml: 1,498; sh: 379; python: 148; makefile: 23
file content (402 lines) | stat: -rw-r--r-- 15,409 bytes parent folder | download | duplicates (6)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
<?php
/**
 * An example of a hooks implementation.
 *
 * Functions should return true on success and false on failure.
 * If a function returns false it will trigger the rollback to be executed.
 *
 * @author The phpLDAPadmin development team
 * @package phpLDAPadmin
 */

/**
 * This example hooks implementation will just show system_messages after each hooks is called.
 *
 * @package phpLDAPadmin
 * @subpackage Functions
 */

# If you want to see this example in action, just comment out the return.
return false;

/**
 * The post_session_init function is called after lib/common.php has completed its processing.
 * This can be used to further initialise the session.
 *
 * No arguments are passed to post_session_init.
 */
function example_post_session_init() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Global Vars</i>: <small>%s</small>',join('| ',array_keys($GLOBALS))),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_session_init','example_post_session_init');

/**
 * This pre_connect function is called before making a connection to the LDAP server.
 * While PLA makes many calls to connect to the LDAP server, this is called only once
 * when caching is turned on.
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @see post_connect
 */
function example_pre_connect() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li></ul>',$args[0],$args[1]),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_connect','example_pre_connect');

/**
 * This post_connect function is called after making a connection to the LDAP server.
 * While PLA makes many calls to connect to the LDAP server, this is called only once
 * when caching is turned on.
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string User ID of the user who successfully made the connection.
 * @see pre_connect
 */
function example_post_connect() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>User DN: <small>%s</small></li></ul>',$args[0],$args[1],$args[2]),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_connect','example_post_connect');

/**
 * This pre_entry_create function is called before an entry is created in ds_ldap_pla::add().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the entry created
 * @param array Attributes for the new DN
 * @see post_entry_create
 */
function example_pre_entry_create() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attributes: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],join(',',(array_keys($args[3])))),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_entry_create','example_pre_entry_create');

/**
 * This post_entry_create function is called after an entry is created in ds_ldap_pla::add().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the entry created
 * @param array Attributes for the new DN
 * @see pre_entry_create
 */
function example_post_entry_create() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attributes: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],join(',',(array_keys($args[3])))),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_entry_create','example_post_entry_create');

/**
 * This pre_entry_delete function is called before an entry is deleted in ds_ldap_pla::delete().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the entry deleted
 * @see post_entry_delete
 */
function example_pre_entry_delete() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li></ul>',$args[0],$args[1],$args[2]),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_entry_delete','example_pre_entry_delete');

/**
 * This post_entry_delete function is called after an entry is deleted in ds_ldap_pla::delete().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the entry deleted
 * @see pre_entry_delete
 */
function example_post_entry_delete() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li></ul>',$args[0],$args[1],$args[2]),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_entry_delete','example_post_entry_delete');

/**
 * This pre_entry_rename function is called before an entry is renamed in ds_ldap_pla::rename().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string Old DN of the entry to be renamed
 * @param string New RDN for the new entry
 * @param string Container for the new entry
 * @see post_entry_rename
 */
function example_pre_entry_rename() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>New RDN: <small>%s</small></li><li>New Container: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],$args[4]),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_entry_rename','example_pre_entry_rename');

/**
 * This post_entry_rename function is called after an entry is renamed in ds_ldap_pla::rename().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string Old DN of the entry to be renamed
 * @param string New RDN for the new entry
 * @param string Container for the new entry
 * @see pre_entry_rename
 */
function example_post_entry_rename() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>New RDN: <small>%s</small></li><li>New Container: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],$args[4]),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_entry_rename','example_post_entry_rename');

/**
 * This pre_entry_modify function is called before an entry is modified in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the entry to be modified
 * @param array Attributes to be modified
 * @see post_entry_modify
 */
function example_pre_entry_modify() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attributes: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],join('|',array_keys($args[3]))),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_entry_modify','example_pre_entry_modify');

/**
 * This post_entry_modify function is called after an entry is modified in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the entry to be modified
 * @param array Attributes to be modified
 * @see pre_entry_modify
 */
function example_post_entry_modify() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attributes: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],join('|',array_keys($args[3]))),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_entry_modify','example_post_entry_modify');

// pre_attr_add
// post_attr_add
/**
 * This pre_attr_add function is called before an attribute is deleted in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the attribute to be deleted
 * @param string Attribute to be deleted
 * @param array Old values
 * @see post_attr_add
 */
function example_pre_attr_add() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attribute: <small>%s</small></li><li>New Values: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],join('|',$args[4])),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_attr_add','example_pre_attr_add');

/**
 * This post_attr_add function is called after an attribute is added in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the attribute to be added
 * @param string Attribute to be added
 * @param array New values
 * @see pre_attr_add
 */
function example_post_attr_add() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attribute: <small>%s</small></li><li>New Values: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],join('|',$args[4])),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_attr_add','example_post_attr_add');

// pre_attr_modify
// post_attr_modify
/**
 * This pre_attr_modify function is called before an attribute is modified in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the attribute to be modified
 * @param string Attribute to be modified
 * @param array New values
 * @see post_attr_modify
 */
function example_pre_attr_modify() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attribute: <small>%s</small></li><li>Old Values: <small>%s</small></li><li>New Values: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],join('|',$args[4]),join('|',$args[5])),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_attr_modify','example_pre_attr_modify');

/**
 * This post_attr_modify function is called after an attribute is deleted in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the attribute to be deleted
 * @param string Attribute to be deleted
 * @param array Old values
 * @see pre_attr_modify
 */
function example_post_attr_modify() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attribute: <small>%s</small></li><li>Old Values: <small>%s</small></li><li>New Values: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],join('|',$args[4]),join('|',$args[5])),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_attr_modify','example_post_attr_modify');

/**
 * This pre_attr_delete function is called before an attribute is deleted in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the attribute to be deleted
 * @param string Attribute to be deleted
 * @param array Old values
 * @see post_attr_delete
 */
function example_pre_attr_delete() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attribute: <small>%s</small></li><li>Old Values: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],join('|',$args[4])),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('pre_attr_delete','example_pre_attr_delete');

/**
 * This post_attr_delete function is called after an attribute is deleted in ds_ldap_pla::modify().
 *
 * Arguments available are:
 * @param int Server ID of the server to be connected to
 * @param string Method. The user connection method, normally 'user'.
 * @param string DN of the attribute to be deleted
 * @param string Attribute to be deleted
 * @param array Old values
 * @see pre_attr_delete
 */
function example_post_attr_delete() {
	$args = func_get_args();

	system_message(array(
		'title'=>sprintf('Hook called [%s]',__METHOD__),
		'body'=>sprintf('<i>Arguments</i>:<ul><li>Server ID: <small>%s</small></li><li>Method: <small>%s</small></li><li>DN: <small>%s</small></li><li>Attribute: <small>%s</small></li><li>Old Values: <small>%s</small></li></ul>',$args[0],$args[1],$args[2],$args[3],join('|',$args[4])),
		'type'=>'info','special'=>true));

	return true;
}
add_hook('post_attr_delete','example_post_attr_delete');
?>