ldap_set_option($this->conn, LDAP_OPT_REFERRALS, 0);
#debug($this);
- if (!@ldap_bind($this->conn, $this->user, $this->password)) self::bye("Could not bind to LDAP server");
+ if (!@ldap_bind($this->conn, $this->user, $this->password)) self::bye("Could not authenticate to LDAP server");
return $this->conn;
}
if (!isset($o['dn'])) $o['dn'] = true;
if (!isset($o['base'])) $o['base'] = null;
-# NB 25.01.18 if (!isset($o['filter'])) $o['filter'] = null;
if (!isset($o['filter'])) $o = array_merge($o,[ 'filter' => 'objectClass=*', 'attrs' => ['dn','objectClass'], 'dn' => true ]);
if (!isset($o['attrs'])) $o['attrs'] = [];
if (!is_array($o['attrs'])) $o['attrs'] = [$o['attrs']];
public function add($dn,$data) {
$conn = $this->conn();
- return ldap_add($conn, $dn, $data);
+ return ldap_add($conn, $dn . ',' . $this->base, $data);
}
public function update($dn,$data) {
- return ldap_mod_add($this->conn(), $dn, $data);
+# NB 28.01.18 return ldap_mod_add($this->conn(), $dn . ',' . $this->base, $data);
+ return ldap_mod_replace($this->conn(), $dn . ',' . $this->base, $data);
}
public function delete($dn) {
}
- public function page_ldap() {
+ public function ldap() {
$this->deniedUnless($this->perm >= self::READ);
+ #$this->deniedUnless($this->perm >= self::ADMIN);
require_once(NB_ROOT.'/lib/php/ldap.php');
#debug($GLOBALS['DBQ_LDAP']);
if ($this->params['table'] == 'add') {
$this->deniedUnless($this->perm >= self::WRITE);
$rows = (int)$ldap->add($this->params['action'],$_POST);
- $this->page($rows);
} elseif ($this->params['table'] == 'update') {
$this->deniedUnless($this->perm >= self::WRITE);
$rows = (int)$ldap->update($this->params['action'],$_POST);
- $this->page($rows);
} elseif ($this->params['table'] == 'rm') {
$this->deniedUnless($this->perm >= self::DELETE);
$rows = (int)$ldap->delete($this->params['action'],$_POST);
- $this->page($rows);
} else { // Search
$filter = ($this->params['table'] ? $this->params['table'] : '');
];
if (!$search['filter']) {
- if (preg_match('/^([^,]+),(.*?)$/',$GLOBALS['DBQ_LDAP']['user'],$m)) {
+ 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 {
or ($this->params['format'] == 'csv')
) $rows = $this->array_fill_assoc($rows);
- $this->page($rows);
}
+ return $rows;
}
public function page_table_ls($args=null) {
}
-# NB 18.12.17 if (!empty($rows))
#if (empty($rows)) bye($rows);
+# NB 18.12.17 if (!empty($rows))
$this->db->out($rows,$head,$conf);
if (empty($this->_nopage)) {
$this->page($types);
} elseif ($action == 'ldap') {
- $this->deniedUnless($this->perm >= self::ADMIN);
- $this->page_ldap();
+ $this->page($this->ldap());
} elseif ($action == 'phpinfo') {
$this->deniedUnless($this->perm >= self::ADMIN);