echo "Hi there! I'm just a plugin, not much I can do when called directly.\n";
exit;
}
+$LDAP_CONN = null;
$DB_TYPES['ldap'] = [
'quote_name' => '',
'quote' => function($v) { return $v; },
'_connect' => function($db) {
require_once(NB_ROOT.'/lib/php/ldap.php');
- $db->ldap = new Ldap([
+ $LDAP_CONN = new Ldap([
'host' => $db->host,
'user' => $db->user,
'password' => $db->password,
'base' => $db->name,
]);
- return $db->ldap->connect();
+ return $LDAP_CONN->connect();
},
'rows_prepare' => function($table,$sql) {
$fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only);
$table->replace_fields($fields);
- $table->db()->ldap->prepare($sql,['attrs'=>$fields]); return $table->db()->ldap;
+ $LDAP_CONN->prepare($sql,['attrs'=>$fields]); return $LDAP_CONN;
},
'rows_fetch' => function($table) {
- $row = $table->db()->ldap->fetch();
+ $row = $LDAP_CONN->fetch();
if (!$row) return [];
$fields = (empty($table->fields_only) ? array_keys($table->fields()) : $table->fields_only);
- $row = $table->db()->ldap->ar_filter_keys($row,$fields);
+ $row = $LDAP_CONN->ar_filter_keys($row,$fields);
$table->fields_only($row,$fields); # reorder by fields
return $row;
},
foreach ($m[1] as $v) {
$row['objectClass'][] = $v;
}
- $row['dn'] = 'cn=CHANGEME,'.$table->db()->ldap->base();
+ $row['dn'] = 'cn=CHANGEME,'.$LDAP_CONN->base();
} else {
- $table->db()->ldap->prepare([
+ $LDAP_CONN->prepare([
'base' => $values['dn'],
]);
- $row = $table->db()->ldap->fetch();
+ $row = $LDAP_CONN->fetch();
}
# Sort fields
)) unset($values[$k]);
}
#bye([$dn,$values]);
- return (int)$table->db()->ldap->add($dn,$values);
+ return (int)$LDAP_CONN->add($dn,$values);
},
'delete' => function(&$table,&$values) {
$dn = $values['dn']; unset($values['dn']);
- return (int)$table->db()->ldap->delete($dn);
+ return (int)$LDAP_CONN->delete($dn);
},
'update' => function(&$table,&$values) {
$dn = $values['dn']; unset($values['dn']);
- return (int)$table->db()->ldap->update($dn,$values);
+ return (int)$LDAP_CONN->update($dn,$values);
},
];
?>
}
- public function ldap($table='',$attrs=[]) {
- $this->deniedUnless($this->perm >= self::ADMIN);
-
- require_once(NB_ROOT.'/lib/php/ldap.php');
- #debug($GLOBALS['DBQ_LDAP']);
- $dn = join(',',$attrs);
- $ldap = new Ldap($GLOBALS['DBQ_LDAP']);
-
- if ($table == 'add') {
- $this->deniedUnless($this->perm >= self::WRITE);
- $rows = (int)$ldap->add($dn,$_POST);
-
- } elseif ($table == 'update') {
- $this->deniedUnless($this->perm >= self::WRITE);
- $rows = (int)$ldap->update($dn,$_POST);
-
- } elseif ($table == 'rm') {
- $this->deniedUnless($this->perm >= self::DELETE);
- $rows = (int)$ldap->delete($dn,$_POST);
-
- } else { // ls
- $this->deniedUnless($this->perm >= self::READ);
-
- $filter = ($table ? $table : '');
-
- if (!empty($table) and !strpos($table,'=')) {
- $filter = '';
- $attrs = explode(',',$table);
- }
-
- $search = [
- 'filter' => $filter,
- 'attrs' => $attrs,
- ];
-
- if (!$search['filter']) {
- if (1
- and !empty($GLOBALS['DBQ_LDAP']['user'])
- and preg_match('/^([^,]+),(.*?)$/',$GLOBALS['DBQ_LDAP']['user'],$m)
- ) {
- $search['filter'] = $m[1];
- $search['base'] = $m[2];
- } else {
- $search['filter'] = 'cn='.Http::user();
- }
- $search['filter'] = '(&('.$search['filter'].')(userPassword=*))';
- }
- $rows = $ldap->search($GLOBALS['DBQ_LDAP'] + $search);
-
- if ($this->is_html
- or ($this->params['format'] == $this->format_cli)
- or ($this->params['format'] == 'csv')
- ) $rows = $this->array_fill_assoc($rows);
-
- }
-
- return $rows;
- }
+ # NB 08.10.24 public function ldap($table='',$attrs=[]) {
+ # NB 08.10.24 $this->deniedUnless($this->perm >= self::ADMIN);
+# NB 08.10.24
+ # NB 08.10.24 require_once(NB_ROOT.'/lib/php/ldap.php');
+ # NB 08.10.24 #debug($GLOBALS['DBQ_LDAP']);
+ # NB 08.10.24 $dn = join(',',$attrs);
+ # NB 08.10.24 $ldap = new Ldap($GLOBALS['DBQ_LDAP']);
+# NB 08.10.24
+ # NB 08.10.24 if ($table == 'add') {
+ # NB 08.10.24 $this->deniedUnless($this->perm >= self::WRITE);
+ # NB 08.10.24 $rows = (int)$ldap->add($dn,$_POST);
+# NB 08.10.24
+ # NB 08.10.24 } elseif ($table == 'update') {
+ # NB 08.10.24 $this->deniedUnless($this->perm >= self::WRITE);
+ # NB 08.10.24 $rows = (int)$ldap->update($dn,$_POST);
+# NB 08.10.24
+ # NB 08.10.24 } elseif ($table == 'rm') {
+ # NB 08.10.24 $this->deniedUnless($this->perm >= self::DELETE);
+ # NB 08.10.24 $rows = (int)$ldap->delete($dn,$_POST);
+# NB 08.10.24
+ # NB 08.10.24 } else { // ls
+ # NB 08.10.24 $this->deniedUnless($this->perm >= self::READ);
+# NB 08.10.24
+ # NB 08.10.24 $filter = ($table ? $table : '');
+# NB 08.10.24
+ # NB 08.10.24 if (!empty($table) and !strpos($table,'=')) {
+ # NB 08.10.24 $filter = '';
+ # NB 08.10.24 $attrs = explode(',',$table);
+ # NB 08.10.24 }
+# NB 08.10.24
+ # NB 08.10.24 $search = [
+ # NB 08.10.24 'filter' => $filter,
+ # NB 08.10.24 'attrs' => $attrs,
+ # NB 08.10.24 ];
+# NB 08.10.24
+ # NB 08.10.24 if (!$search['filter']) {
+ # NB 08.10.24 if (1
+ # NB 08.10.24 and !empty($GLOBALS['DBQ_LDAP']['user'])
+ # NB 08.10.24 and preg_match('/^([^,]+),(.*?)$/',$GLOBALS['DBQ_LDAP']['user'],$m)
+ # NB 08.10.24 ) {
+ # NB 08.10.24 $search['filter'] = $m[1];
+ # NB 08.10.24 $search['base'] = $m[2];
+ # NB 08.10.24 } else {
+ # NB 08.10.24 $search['filter'] = 'cn='.Http::user();
+ # NB 08.10.24 }
+ # NB 08.10.24 $search['filter'] = '(&('.$search['filter'].')(userPassword=*))';
+ # NB 08.10.24 }
+ # NB 08.10.24 $rows = $ldap->search($GLOBALS['DBQ_LDAP'] + $search);
+# NB 08.10.24
+ # NB 08.10.24 if ($this->is_html
+ # NB 08.10.24 or ($this->params['format'] == $this->format_cli)
+ # NB 08.10.24 or ($this->params['format'] == 'csv')
+ # NB 08.10.24 ) $rows = $this->array_fill_assoc($rows);
+# NB 08.10.24
+ # NB 08.10.24 }
+# NB 08.10.24
+ # NB 08.10.24 return $rows;
+ # NB 08.10.24 }
public function page_table_ls($fields=null) {
$this->deniedUnless($this->perm >= self::READ);
(
($this->perm < self::ADMIN) ? [] :
[
- # NB 07.02.18 [ 'ldap', 'Connect to domain ldap server [/FILTER/ATTRS' ],
[ 'phpinfo', 'Phpinfo' ],
[ '_SERVER', 'Dump _SERVER' ],
[ '_REQUEST', 'Dump _REQUEST' ],
# NB 14.12.22 $this->deniedUnless($this->perm >= self::ADMIN);
# NB 14.12.22 $this->page($this->db->databases());
- } elseif ($action == 'ldap2') {
- $table = $this->params['table'];
- $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : ['dn','objectClass']);
- $this->page($this->ldap($table,$attrs));
+ # NB 08.10.24 } elseif ($action == 'ldap2') {
+ # NB 08.10.24 $table = $this->params['table'];
+ # NB 08.10.24 $attrs = ($this->params['action'] ? explode(',',$this->params['action']) : ['dn','objectClass']);
+ # NB 08.10.24 $this->page($this->ldap($table,$attrs));
} elseif ($action == 'phpinfo') {
$this->deniedUnless($this->perm >= self::ADMIN);