Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_query/LdapQuery.class.php
3 3
/**
4 4
 * @file
5 5
 * Defines server classes and related functions.
6
 *
7 6
 */
8 7

  
9 8
/**
10
 * LDAP Server Class
9
 * LDAP Server Class.
11 10
 *
12 11
 *  This class is used to create, work with, and eventually destroy ldap_server
13 12
 * objects.
......
15 14
 * @todo make bindpw protected
16 15
 */
17 16
class LdapQuery {
18
  // LDAP Settings
19

  
17
  /**
18
   * LDAP Settings.
19
   */
20 20
  public $query_numeric_id;
21 21
  public $qid;
22 22
  public $name;
23 23
  public $sid;
24 24
  public $status;
25 25

  
26
  public $baseDn = array();
26
  public $baseDn = [];
27 27
  public $base_dn_str = NULL;
28 28
  public $filter;
29 29
  public $attributes_str = NULL;
30
  public $attributes = array();
30
  public $attributes = [];
31 31

  
32 32
  public $sizelimit = 0;
33 33
  public $timelimit = 0;
......
38 38
  public $inDatabase = FALSE;
39 39
  public $detailedWatchdogLog = FALSE;
40 40

  
41

  
42 41
  /**
43
   * Constructor Method
42
   * Constructor Method.
44 43
   */
45
  function __construct($qid) {
44
  public function __construct($qid) {
46 45
    if (!is_scalar($qid)) {
47 46
      return;
48 47
    }
49 48

  
50
    $query_records = array();
49
    $query_records = [];
51 50
    if (module_exists('ctools')) {
52 51
      ctools_include('export');
53
      $result = ctools_export_load_object('ldap_query', 'names', array($qid));
52
      $result = ctools_export_load_object('ldap_query', 'names', [$qid]);
54 53
      if (isset($result[$qid])) {
55 54
        $query_record = $result[$qid];
56 55
        foreach ($query_record as $property_name => $value) {
......
71 70
        return;
72 71
      }
73 72
      $query_record = $query_records[$qid];
74
      foreach ($this->fields() as $field_id => $field ) {
73
      foreach ($this->fields() as $field_id => $field) {
75 74
        if (isset($query_record->$field_id)) {
76 75
          $this->{$field['property_name']} = @$query_record->$field_id;
77 76
        }
78 77
      }
79 78
    }
80 79

  
81
    // special properties that don't map directly from storage and defaults
80
    // Special properties that don't map directly from storage and defaults.
82 81
    $this->inDatabase = TRUE;
83 82
    $this->detailedWatchdogLog = variable_get('ldap_help_watchdog_detail', 0);
84 83

  
85 84
    $this->baseDn = $this->linesToArray($this->base_dn_str);
86
    $this->attributes = ($this->attributes_str) ? $this->csvToArray($this->attributes_str, TRUE) : array();
85
    $this->attributes = ($this->attributes_str) ? $this->csvToArray($this->attributes_str, TRUE) : [];
87 86

  
88 87
  }
89 88

  
90 89
  /**
91
   * Destructor Method
90
   * Destructor Method.
92 91
   */
93
  function __destruct() {
92
  public function __destruct() {
94 93

  
95 94
  }
96 95

  
97

  
98 96
  /**
99
   * Invoke Method
97
   * Invoke Method.
100 98
   */
101
  function __invoke() {
99
  public function __invoke() {
102 100

  
103 101
  }
104 102

  
105
//  function search($base_dn = NULL, $filter, $attributes = array(), $attrsonly = 0, $sizelimit = 0, $timelimit = 0, $deref = LDAP_DEREF_NEVER) {
106

  
107
  function query() {
103
  /**
104
   * Function search($base_dn = NULL, $filter, $attributes = array(), $attrsonly = 0, $sizelimit = 0, $timelimit = 0, $deref = LDAP_DEREF_NEVER) {.
105
   */
106
  public function query() {
108 107
    ldap_servers_module_load_include('php', 'ldap_servers', 'LdapServer.class');
109 108
    $ldap_server = new LdapServer($this->sid);
110 109
    $ldap_server->connect();
111 110
    $ldap_server->bind();
112
    $results = array();
111
    $results = [];
113 112

  
114 113
    $count = 0;
115 114

  
......
133 132
  protected $_hasError = FALSE;
134 133
  protected $_errorName = NULL;
135 134

  
135
  /**
136
   *
137
   */
136 138
  public function setError($_errorName, $_errorMsgText = NULL) {
137 139
    $this->_errorMsgText = $_errorMsgText;
138 140
    $this->_errorName = $_errorName;
139 141
    $this->_hasError = TRUE;
140 142
  }
141 143

  
144
  /**
145
   *
146
   */
142 147
  public function clearError() {
143 148
    $this->_hasError = FALSE;
144 149
    $this->_errorMsg = NULL;
145 150
    $this->_errorName = NULL;
146 151
  }
147 152

  
153
  /**
154
   *
155
   */
148 156
  public function hasError() {
149 157
    return ($this->_hasError || $this->ldapErrorNumber());
150 158
  }
151 159

  
160
  /**
161
   * @param null $type
162
   *
163
   * @return string|null
164
   */
152 165
  public function errorMsg($type = NULL) {
153 166
    if ($type == 'ldap' && $this->connection) {
154 167
      return ldap_err2str(ldap_errno($this->connection));
......
161 174
    }
162 175
  }
163 176

  
177
  /**
178
   * @param null $type
179
   *
180
   * @return string|null
181
   */
164 182
  public function errorName($type = NULL) {
165 183
    if ($type == 'ldap' && $this->connection) {
166 184
      return "LDAP Error: " . ldap_error($this->connection);
......
173 191
    }
174 192
  }
175 193

  
194
  /**
195
   *
196
   */
176 197
  public function ldapErrorNumber() {
177
   // if ($this->connection && ldap_errno($this->connection)) {
178
    //  return ldap_errno($this->connection);
179
   // }
180
   // else {
181
      return FALSE;
182
   // }
198
    return FALSE;
183 199
  }
184 200

  
201
  /**
202
   *
203
   */
185 204
  protected function linesToArray($lines) {
186 205
    $lines = trim($lines);
187 206
    if ($lines) {
......
191 210
      }
192 211
    }
193 212
    else {
194
      $array = array();
213
      $array = [];
195 214
    }
196 215
    return $array;
197 216
  }
198 217

  
218
  /**
219
   *
220
   */
199 221
  protected function csvToArray($string, $strip_quotes = FALSE) {
200 222
    $items = explode(',', $string);
201 223
    foreach ($items as $i => $item) {
......
207 229
    return $items;
208 230
  }
209 231

  
232
  /**
233
   *
234
   */
210 235
  public static function fields() {
211
    $fields = array(
212
      'query_numeric_id' => array(
213
          'property_name' => 'query_numeric_id',
214
          'schema' => array(
215
            'type' => 'serial',
216
            'unsigned' => TRUE,
217
            'not null' => TRUE,
218
            'description' => 'Primary ID field for the table.  Only used internally.',
219
            'no export' => TRUE,
220
          ),
221
        ),
222

  
223
      'qid' => array(
236
    $fields = [
237
      'query_numeric_id' => [
238
        'property_name' => 'query_numeric_id',
239
        'schema' => [
240
          'type' => 'serial',
241
          'unsigned' => TRUE,
242
          'not null' => TRUE,
243
          'description' => 'Primary ID field for the table.  Only used internally.',
244
          'no export' => TRUE,
245
        ],
246
      ],
247

  
248
      'qid' => [
224 249
        'property_name' => 'qid',
225
        'schema' => array(
250
        'schema' => [
226 251
          'type' => 'varchar',
227 252
          'length' => 20,
228 253
          'description' => 'Machine name for query.',
229 254
          'not null' => TRUE,
230
          ),
231
        'form' => array(
255
        ],
256
        'form' => [
232 257
          'field_group' => 'basic',
233 258
          '#type' => 'textfield',
234 259
          '#title' => t('Machine name for this query configuration.'),
235 260
          '#size' => 20,
236 261
          '#maxlength' => 20,
237
          '#description' => t('May only contain alphanumeric characters (a-z, A-Z, 0-9, and _)' ),
262
          '#description' => t('May only contain alphanumeric characters (a-z, A-Z, 0-9, and _)'),
238 263
          '#required' => TRUE,
239
        ),
240
        'form_to_prop_functions' => array('trim'),
241
      ),
264
        ],
265
        'form_to_prop_functions' => ['trim'],
266
      ],
242 267

  
243
      'name' => array(
268
      'name' => [
244 269
        'property_name' => 'name',
245
        'schema' => array(
270
        'schema' => [
246 271
          'type' => 'varchar',
247 272
          'length' => '60',
248
          'not null' => TRUE
249
        ),
250
        'form' => array(
273
          'not null' => TRUE,
274
        ],
275
        'form' => [
251 276
          'field_group' => 'basic',
252 277
          '#type' => 'textfield',
253 278
          '#title' => t('Name'),
......
255 280
          '#size' => 50,
256 281
          '#maxlength' => 255,
257 282
          '#required' => TRUE,
258
        ),
259
        'form_to_prop_functions' => array('trim'),
260
      ),
283
        ],
284
        'form_to_prop_functions' => ['trim'],
285
      ],
261 286

  
262
      'sid' => array(
287
      'sid' => [
263 288
        'property_name' => 'sid',
264
        'schema' => array(
289
        'schema' => [
265 290
          'type' => 'varchar',
266 291
          'length' => 20,
267 292
          'not null' => TRUE,
268
        ),
269
        'form' => array(
293
        ],
294
        'form' => [
270 295
          'field_group' => 'basic',
271 296
          '#type' => 'radios',
272 297
          '#title' => t('LDAP Server used for query.'),
273 298
          '#required' => 1,
274
        ),
275
        'form_to_prop_functions' => array('trim'),
276
      ),
299
        ],
300
        'form_to_prop_functions' => ['trim'],
301
      ],
277 302

  
278
      'status' => array(
303
      'status' => [
279 304
        'property_name' => 'status',
280
        'schema' => array(
305
        'schema' => [
281 306
          'type' => 'int',
282 307
          'size' => 'tiny',
283 308
          'not null' => TRUE,
284 309
          'default' => 0,
285
        ),
286
        'form' => array(
310
        ],
311
        'form' => [
287 312
          'field_group' => 'basic',
288 313
          '#type' => 'checkbox',
289 314
          '#title' => t('Enabled'),
290 315
          '#description' => t('Disable in order to keep configuration without having it active.'),
291
        ),
292
        'form_to_prop_functions' => array('trim'),
293
      ),
316
        ],
317
        'form_to_prop_functions' => ['trim'],
318
      ],
294 319

  
295
      'base_dn_str' => array(
320
      'base_dn_str' => [
296 321
        'property_name' => 'base_dn_str',
297
        'schema' => array(
322
        'schema' => [
298 323
          'type' => 'text',
299
          'not null' => FALSE
300
        ),
301
        'form' => array(
324
          'not null' => FALSE,
325
        ],
326
        'form' => [
302 327
          'field_group' => 'query',
303 328
          '#type' => 'textarea',
304 329
          '#title' => t('Base DNs to search in query.'),
......
306 331
          '#cols' => 50,
307 332
          '#rows' => 6,
308 333
          '#required' => TRUE,
309
        ),
310
        'form_to_prop_functions' => array('trim'),
311
      ),
334
        ],
335
        'form_to_prop_functions' => ['trim'],
336
      ],
312 337

  
313
      'baseDn' => array(
338
      'baseDn' => [
314 339
        'property_name' => 'baseDn',
315 340
        'exportable' => FALSE,
316
      ),
341
      ],
317 342

  
318
      'filter' => array(
343
      'filter' => [
319 344
        'property_name' => 'filter',
320
        'schema' => array(
345
        'schema' => [
321 346
          'type' => 'text',
322
          'not null' => FALSE
323
        ),
324
        'form' => array(
347
          'not null' => FALSE,
348
        ],
349
        'form' => [
325 350
          'field_group' => 'query',
326 351
          '#type' => 'textarea',
327 352
          '#title' => t('Filter'),
......
330 355
          '#cols' => 50,
331 356
          '#rows' => 1,
332 357
          '#required' => TRUE,
333
        ),
334
        'form_to_prop_functions' => array('trim'),
335
      ),
358
        ],
359
        'form_to_prop_functions' => ['trim'],
360
      ],
336 361

  
337
      'attributes_str' => array(
362
      'attributes_str' => [
338 363
        'property_name' => 'attributes_str',
339
        'schema' => array(
364
        'schema' => [
340 365
          'type' => 'text',
341
          'not null' => FALSE
342
        ),
343
        'form' => array(
366
          'not null' => FALSE,
367
        ],
368
        'form' => [
344 369
          'field_group' => 'query',
345 370
          '#type' => 'textarea',
346 371
          '#title' => t('Attributes to return.'),
347 372
          '#description' => t('Enter as comma separated list. DN is automatically returned. Leave empty to return all attributes. e.g. <code>objectclass,name,cn,samaccountname</code>'),
348 373
          '#cols' => 50,
349 374
          '#rows' => 6,
350
        ),
351
        'form_to_prop_functions' => array('trim'),
352
      ),
375
        ],
376
        'form_to_prop_functions' => ['trim'],
377
      ],
353 378

  
354
      'attributes' => array(
379
      'attributes' => [
355 380
        'property_name' => 'attributes',
356 381
        'exportable' => FALSE,
357
      ),
382
      ],
358 383

  
359
      'sizelimit' => array(
384
      'sizelimit' => [
360 385
        'property_name' => 'sizelimit',
361
        'schema' => array(
386
        'schema' => [
362 387
          'type' => 'int',
363 388
          'size' => 'small',
364 389
          'not null' => TRUE,
365 390
          'default' => 0,
366
        ),
367
        'form' => array(
391
        ],
392
        'form' => [
368 393
          'field_group' => 'query_advanced',
369 394
          '#type' => 'textfield',
370 395
          '#title' => t('Size Limit of returned data'),
......
372 397
          '#size' => 7,
373 398
          '#maxlength' => 5,
374 399
          '#required' => TRUE,
375
        ),
376
        'form_to_prop_functions' => array('trim'),
377
      ),
400
        ],
401
        'form_to_prop_functions' => ['trim'],
402
      ],
378 403

  
379
      'timelimit' => array(
404
      'timelimit' => [
380 405
        'property_name' => 'timelimit',
381
        'schema' => array(
406
        'schema' => [
382 407
          'type' => 'int',
383 408
          'size' => 'small',
384 409
          'not null' => TRUE,
385 410
          'default' => 0,
386 411

  
387
        ),
388
        'form' => array(
412
        ],
413
        'form' => [
389 414
          'field_group' => 'query_advanced',
390 415
          '#type' => 'textfield',
391 416
          '#title' => t('Time Limit in Seconds'),
......
393 418
          '#size' => 7,
394 419
          '#maxlength' => 5,
395 420
          '#required' => TRUE,
396
        ),
397
        'form_to_prop_functions' => array('trim'),
398
      ),
421
        ],
422
        'form_to_prop_functions' => ['trim'],
423
      ],
399 424

  
400
      'deref' => array(
425
      'deref' => [
401 426
        'property_name' => 'deref',
402
        'schema' => array(
427
        'schema' => [
403 428
          'type' => 'int',
404 429
          'size' => 'tiny',
405 430
          'not null' => TRUE,
406 431
          'default' => LDAP_DEREF_NEVER,
407
        ),
408
        'form' => array(
432
        ],
433
        'form' => [
409 434
          'field_group' => 'query_advanced',
410 435
          '#type' => 'radios',
411 436
          '#title' => t('How aliases should be handled during the search.'),
412 437
          '#required' => 1,
413
          '#options' => array(
438
          '#options' => [
414 439
            LDAP_DEREF_NEVER => t('(default) aliases are never dereferenced.'),
415 440
            LDAP_DEREF_SEARCHING => t('aliases should be dereferenced during the search but not when locating the base object of the search.'),
416 441
            LDAP_DEREF_FINDING => t('aliases should be dereferenced when locating the base object but not during the search.'),
417 442
            LDAP_DEREF_ALWAYS => t('aliases should be dereferenced always.'),
418
          ),
419
        ),
420
        'form_to_prop_functions' => array('trim'),
421
      ),
422
     'scope' => array(
443
          ],
444
        ],
445
        'form_to_prop_functions' => ['trim'],
446
      ],
447
      'scope' => [
423 448
        'property_name' => 'scope',
424
        'schema' => array(
449
        'schema' => [
425 450
          'type' => 'int',
426 451
          'size' => 'tiny',
427 452
          'not null' => TRUE,
428 453
          'default' => LDAP_SCOPE_SUBTREE,
429
        ),
430
        'form' => array(
454
        ],
455
        'form' => [
431 456
          'field_group' => 'query_advanced',
432 457
          '#type' => 'radios',
433 458
          '#title' => t('Scope of search.'),
434 459
          '#required' => 1,
435
          '#options' => array(
460
          '#options' => [
436 461
            LDAP_SCOPE_BASE => t('BASE. This value is used to indicate searching only the entry at the base DN, resulting in only that entry being returned (keeping in mind that it also has to meet the search filter criteria!).'),
437 462
            LDAP_SCOPE_ONELEVEL => t('ONELEVEL. This value is used to indicate searching all entries one level under the base DN - but not including the base DN and not including any entries under that one level under the base DN.'),
438 463
            LDAP_SCOPE_SUBTREE => t('SUBTREE. (default) This value is used to indicate searching of all entries at all levels under and including the specified base DN.'),
439
          ),
440
        ),
441
        'form_to_prop_functions' => array('trim'),
442
      ),
464
          ],
465
        ],
466
        'form_to_prop_functions' => ['trim'],
467
      ],
443 468

  
444
    );
469
    ];
445 470
    return $fields;
446 471
  }
447 472

  
448

  
449 473
}

Formats disponibles : Unified diff