action.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. require_once(__DIR__.SLASH.'ActiveDirectoryGroup.class.php');
  3. global $_,$conf,$myUser;
  4. switch($_['action']){
  5. case 'activedirectory_setting_save':
  6. Action::write(function(&$response){
  7. global $myUser,$conf,$_;
  8. User::check_access('activedirectory','configure');
  9. foreach(Configuration::setting('activedirectory') as $key=>$value){
  10. if(!is_array($value) && !in_array($key, array('activedirectory_users_root', 'activedirectory_groups_root'))) continue;
  11. $allowed[] = $key;
  12. }
  13. foreach ($_['fields'] as $key => $value){
  14. if(in_array($key, $allowed)){
  15. if(in_array($key, array('activedirectory_users_root', 'activedirectory_groups_root'))){
  16. foreach ($value as $i => $val)
  17. if(empty($val)) unset($value[$i]);
  18. $value = implode(";",$value);
  19. }
  20. $conf->put($key,$value);
  21. }
  22. }
  23. unset($_SESSION['configuration']);
  24. $conf = new Configuration();
  25. $conf->getAll();
  26. });
  27. break;
  28. case 'activedirectory_connection_check':
  29. Action::write(function(&$response){
  30. global $myUser, $conf;
  31. User::check_access('activedirectory','configure');
  32. foreach (array('reach','reader','users') as $check)
  33. $response['tests'][$check.'-connection'] = false;
  34. try {
  35. $ldap = ldap_instance();
  36. $ldap->connect($conf->get('activedirectory_reader_login'),$conf->get('activedirectory_reader_password'));
  37. $response['tests']['reach-connection'] = true;
  38. if(!empty($conf->get('activedirectory_reader_login')) && !empty($conf->get('activedirectory_reader_password')))
  39. $response['tests']['reader-connection'] = true;
  40. //Récupération users
  41. $infos = $ldap->populate($conf->get('activedirectory_users_root'));
  42. $response['tests']['users-connection'] = $infos["count"] == 0 ? false : true;
  43. $ldap->disconnect();
  44. } catch (Exception $e) {
  45. switch ($e->getCode()) {
  46. //Connexion simple
  47. case 400:
  48. $response['tests']['reach-connection'] = false;
  49. break;
  50. //Connexion compte reader
  51. case 401:
  52. $response['tests']['reader-connection'] = false;
  53. break;
  54. default:
  55. break;
  56. }
  57. $ldap->disconnect();
  58. }
  59. });
  60. break;
  61. /** ACTIVEDIRECTORY GROUPS **/
  62. case 'activedirectory_group_search':
  63. Action::write(function(&$response){
  64. global $myUser, $conf, $_;
  65. User::check_access('activedirectory','read');
  66. $query = 'SELECT * FROM '.ActiveDirectoryGroup::tableName().' WHERE 1';
  67. $data = array();
  68. $firms = array();
  69. foreach(Firm::loadAll() as $firm)
  70. $firms[$firm->id] = $firm->label;
  71. $ranks = array();
  72. foreach(Rank::loadAll() as $rank)
  73. $ranks[$rank->id] = $rank->label;
  74. $response['pagination'] = ActiveDirectoryGroup::paginate(10,(!empty($_['page'])?$_['page']:0),$query,$data);
  75. foreach(ActiveDirectoryGroup::staticQuery($query,$data,true) as $adGroup){
  76. $row = $adGroup->toArray();
  77. $row['rankLabel'] = isset($ranks[$adGroup->rank]) ? $ranks[$adGroup->rank] : '-';
  78. $row['firmLabel'] = isset($firms[$adGroup->firm]) ? $firms[$adGroup->firm] : '-';
  79. $response['rows'][] = $row;
  80. }
  81. });
  82. break;
  83. case 'activedirectory_group_save':
  84. Action::write(function(&$response){
  85. global $myUser,$_;
  86. User::check_access('activedirectory','edit');
  87. if(!isset($_['ad-group']) || empty($_['ad-group'])) throw new Exception("Nom de groupe obligatoire");
  88. $item = ActiveDirectoryGroup::provide();
  89. $item->adgroup = $_['ad-group'];
  90. $item->rank = $_['ad-rank'];
  91. $item->firm = $_['ad-firm'];
  92. $item->save();
  93. });
  94. break;
  95. case 'activedirectory_group_edit':
  96. Action::write(function(&$response){
  97. global $myUser,$_;
  98. User::check_access('activedirectory','edit');
  99. $adgroup = ActiveDirectoryGroup::getById($_['id']);
  100. $adgroup = $adgroup->toArray();
  101. $adgroup['ad-group'] = html_entity_decode($adgroup['adgroup']);
  102. $adgroup['ad-rank'] = html_entity_decode($adgroup['rank']);
  103. $adgroup['ad-firm'] = html_entity_decode($adgroup['firm']);
  104. $response = $adgroup;
  105. });
  106. break;
  107. case 'activedirectory_group_delete':
  108. Action::write(function(&$response){
  109. global $myUser,$_;
  110. User::check_access('activedirectory','delete');
  111. ActiveDirectoryGroup::deleteById($_['id']);
  112. });
  113. break;
  114. }