123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- require_once(__DIR__.SLASH.'ActiveDirectoryGroup.class.php');
- global $_,$conf,$myUser;
- switch($_['action']){
- case 'activedirectory_setting_save':
- Action::write(function(&$response){
- global $myUser,$conf,$_;
- User::check_access('activedirectory','configure');
- foreach(Configuration::setting('activedirectory') as $key=>$value){
- if(!is_array($value) && !in_array($key, array('activedirectory_users_root', 'activedirectory_groups_root'))) continue;
- $allowed[] = $key;
- }
- foreach ($_['fields'] as $key => $value){
- if(in_array($key, $allowed)){
- if(in_array($key, array('activedirectory_users_root', 'activedirectory_groups_root'))){
- foreach ($value as $i => $val)
- if(empty($val)) unset($value[$i]);
- $value = implode(";",$value);
- }
- $conf->put($key,$value);
- }
- }
- unset($_SESSION['configuration']);
- $conf = new Configuration();
- $conf->getAll();
- });
- break;
- case 'activedirectory_connection_check':
- Action::write(function(&$response){
- global $myUser, $conf;
- User::check_access('activedirectory','configure');
- foreach (array('reach','reader','users') as $check)
- $response['tests'][$check.'-connection'] = false;
- try {
- $ldap = ldap_instance();
- $ldap->connect($conf->get('activedirectory_reader_login'),$conf->get('activedirectory_reader_password'));
- $response['tests']['reach-connection'] = true;
-
- if(!empty($conf->get('activedirectory_reader_login')) && !empty($conf->get('activedirectory_reader_password')))
- $response['tests']['reader-connection'] = true;
- //Récupération users
- $infos = $ldap->populate($conf->get('activedirectory_users_root'));
- $response['tests']['users-connection'] = $infos["count"] == 0 ? false : true;
- $ldap->disconnect();
- } catch (Exception $e) {
- switch ($e->getCode()) {
- //Connexion simple
- case 400:
- $response['tests']['reach-connection'] = false;
- break;
- //Connexion compte reader
- case 401:
- $response['tests']['reader-connection'] = false;
- break;
- default:
- break;
- }
- $ldap->disconnect();
- }
- });
- break;
- /** ACTIVEDIRECTORY GROUPS **/
- case 'activedirectory_group_search':
- Action::write(function(&$response){
- global $myUser, $conf, $_;
- User::check_access('activedirectory','read');
- $query = 'SELECT * FROM '.ActiveDirectoryGroup::tableName().' WHERE 1';
- $data = array();
- $firms = array();
- foreach(Firm::loadAll() as $firm)
- $firms[$firm->id] = $firm->label;
- $ranks = array();
- foreach(Rank::loadAll() as $rank)
- $ranks[$rank->id] = $rank->label;
- $response['pagination'] = ActiveDirectoryGroup::paginate(10,(!empty($_['page'])?$_['page']:0),$query,$data);
- foreach(ActiveDirectoryGroup::staticQuery($query,$data,true) as $adGroup){
- $row = $adGroup->toArray();
- $row['rankLabel'] = isset($ranks[$adGroup->rank]) ? $ranks[$adGroup->rank] : '-';
- $row['firmLabel'] = isset($firms[$adGroup->firm]) ? $firms[$adGroup->firm] : '-';
- $response['rows'][] = $row;
- }
- });
- break;
- case 'activedirectory_group_save':
- Action::write(function(&$response){
- global $myUser,$_;
- User::check_access('activedirectory','edit');
- if(!isset($_['ad-group']) || empty($_['ad-group'])) throw new Exception("Nom de groupe obligatoire");
- $item = ActiveDirectoryGroup::provide();
- $item->adgroup = $_['ad-group'];
- $item->rank = $_['ad-rank'];
- $item->firm = $_['ad-firm'];
- $item->save();
- });
- break;
- case 'activedirectory_group_edit':
- Action::write(function(&$response){
- global $myUser,$_;
- User::check_access('activedirectory','edit');
- $adgroup = ActiveDirectoryGroup::getById($_['id']);
- $adgroup = $adgroup->toArray();
- $adgroup['ad-group'] = html_entity_decode($adgroup['adgroup']);
- $adgroup['ad-rank'] = html_entity_decode($adgroup['rank']);
- $adgroup['ad-firm'] = html_entity_decode($adgroup['firm']);
- $response = $adgroup;
- });
- break;
- case 'activedirectory_group_delete':
- Action::write(function(&$response){
- global $myUser,$_;
- User::check_access('activedirectory','delete');
- ActiveDirectoryGroup::deleteById($_['id']);
- });
- break;
- }
|