class Ldap {
- public static function connect(&$o=[]) {
+ public static function _connect(&$o=[]) {
$host = '127.0.0.1';
if (preg_match('/^.*?([^\.]+\.[^\.]+)$/',$_SERVER['HTTP_HOST'],$m)) {
$host = 'ldap.'.$m[1];
return $connect;
}
- public static function search($o=[]) {
+ public static function _search($o=[]) {
- $connect = self::connect($o);
+ $connect = self::_connect($o);
if (empty($o['filter'])) {
$o['filter'] = "(&(userpassword=*))";
} # < ldap_search
+ private $conn;
+ private $host = '127.0.0.1';
+ private $base;
+ private $user;
+ private $password;
+
private static function ar_filter_keys($ar,$keys) {
$new = [];
foreach ($keys as $k) {
return $new;
}
- public $host = '127.0.0.1';
- public $base;
- public $user;
- public $password;
- #public $search = false;
-
- private $conn;
-
public function __construct($opt = []) {
foreach ($opt as $k => $v) if ((string)$v !== '') $this->$k = $v;
}
ldap_close($this->conn);
}
- public function _search($o=[]) {
+ public function search($o=[]) {
$conn = $this->conn();
} # < ldap_search
- public static function add($dn,$data) {
+ public function add($dn,$data) {
$conn = $this->conn();
return ldap_add($conn, $dn, $data); # or self::bye("Unable to add entry to ldap server");
}
- public static function update($dn,$data) {
- $conn = $this->conn();
- return ldap_mod_add($conn, $dn, $data); # or self::bye("Unable to add entry to ldap server");
+ public function update($dn,$data) {
+ return ldap_mod_add($this->conn(), $dn, $data); # or self::bye("Unable to add entry to ldap server");
+ }
+
+ public function delete($dn) {
+ return ldap_delete($this->conn(), $dn); # or self::bye("Unable to add entry to ldap server");
}
}
}
public function page_ldap() {
- require_once(NB_ROOT.'/lib/php/ldap.php');
$this->deniedUnless($this->perm >= self::READ);
+
+ require_once(NB_ROOT.'/lib/php/ldap.php');
+ #debug($GLOBALS['DBQ_LDAP']);
+ $ldap = new Ldap($GLOBALS['DBQ_LDAP']);
+
+ if ($this->params['table'] == 'add') {
+ debug($this->params);
+ $rows = (int)$ldap->add($this->params['action'],$_POST);
+ bye($_POST);
+ $this->page($rows);
+
+ } elseif ($this->params['table'] == 'update') {
+ $rows = (int)$ldap->update($this->params['action'],$_POST);
+ $this->page($rows);
+
+ } elseif ($this->params['table'] == 'rm') {
+ $rows = (int)$ldap->delete($this->params['action'],$_POST);
+ $this->page($rows);
+
+ }
+
$filter = ($this->params['table'] ? $this->params['table'] : '');
$attrs = ($this->params['action'] ? explode(',',$this->params['action']) : []);
'attrs' => $attrs,
];
- if (true and !empty($GLOBALS['DBQ_LDAP'])) {
- #debug($GLOBALS['DBQ_LDAP']);
- $ldap = new Ldap($GLOBALS['DBQ_LDAP']);
- if (!$search['filter']) {
- if (preg_match('/^([^,]+),(.*?)$/',$GLOBALS['DBQ_LDAP']['user'],$m)) {
- $search['filter'] = $m[1];
- $search['base'] = $m[2];
- } else {
- $search['filter'] = 'cn='.Http::user();
- }
+ if (!$search['filter']) {
+ if (preg_match('/^([^,]+),(.*?)$/',$GLOBALS['DBQ_LDAP']['user'],$m)) {
+ $search['filter'] = $m[1];
+ $search['base'] = $m[2];
+ } else {
+ $search['filter'] = 'cn='.Http::user();
}
- $rows = $ldap->_search($GLOBALS['DBQ_LDAP'] + $search);
- } else {
- $rows = Ldap::search([
- 'bind_dn_preff' => (!empty($_SERVER['DBQ_LDAP_BIND_DN_PREFF']) ? 'ou='.$_SERVER['DBQ_LDAP_BIND_DN_PREFF'] : 'ou=auth'),
- 'exit_on_err' => $this->p('err',true),
- ]+$search);
}
+ $rows = $ldap->search($GLOBALS['DBQ_LDAP'] + $search);
#echo $rows[0]['jpegPhoto']; exit;
#$rows = [ 'jpegPhoto' => $rows[0]['jpegPhoto'] ];
or ($this->params['format'] == $this->format_cli)
or ($this->params['format'] == 'csv')
) $rows = $this->array_fill_assoc($rows);
+
$this->page($rows);
}
'value' => $this->params['format'],
];
- $user = '';
- if (true or $user = $this->http->user()) {
- if ($user) $rows[] = [ 'name' => 'dbq.user.name', 'value' => $user ];
- $rows[] = [ 'name' => 'dbq.user.perm', 'value' => $this->perm2h() ];
+ if ($user = $this->http->user()) {
+ $rows[] = [ 'name' => 'dbq.user.name', 'value' => $user ];
}
+ $rows[] = [ 'name' => 'dbq.user.perm', 'value' => $this->perm2h() ];
// Machine
if ($this->perm >= self::ADMIN and function_exists('posix_uname')) {