[ Index ]
 

Code source de eGroupWare 1.2.106-2

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/setup/ -> ldapexport.php (source)

   1  <?php
   2    /**************************************************************************\
   3    * eGroupWare - Setup                                                       *
   4    * http://www.egroupware.org                                                *
   5    * --------------------------------------------                             *
   6    *  This program is free software; you can redistribute it and/or modify it *
   7    *  under the terms of the GNU General Public License as published by the   *
   8    *  Free Software Foundation; either version 2 of the License, or (at your  *
   9    *  option) any later version.                                              *
  10    \**************************************************************************/
  11  
  12    /* $Id: ldapexport.php 21707 2006-06-03 19:37:14Z ralfbecker $ */
  13  
  14      $GLOBALS['egw_info'] = array(
  15          'flags' => array(
  16              'noheader'   => True,
  17              'nonavbar'   => True,
  18              'currentapp' => 'home',
  19              'noapi'      => True
  20      ));
  21      include ('./inc/functions.inc.php');
  22  
  23      // Authorize the user to use setup app and load the database
  24      if (!$GLOBALS['egw_setup']->auth('Config'))
  25      {
  26          Header('Location: index.php');
  27          exit;
  28      }
  29      // Does not return unless user is authorized
  30  
  31      class egw
  32      {
  33          var $common;
  34          var $accounts;
  35          var $applications;
  36          var $db;
  37      }
  38      $egw =& new egw;
  39      $egw->common =& CreateObject('phpgwapi.common');
  40  
  41      $common =& $egw->common;
  42      $GLOBALS['egw_setup']->loaddb();
  43      $egw->db = clone($GLOBALS['egw_setup']->db);
  44  
  45      $tpl_root = $GLOBALS['egw_setup']->html->setup_tpl_dir('setup');
  46      $setup_tpl = CreateObject('setup.Template',$tpl_root);
  47      $setup_tpl->set_file(array(
  48          'ldap'   => 'ldap.tpl',
  49          'T_head' => 'head.tpl',
  50          'T_footer' => 'footer.tpl',
  51          'T_alert_msg' => 'msg_alert_msg.tpl'
  52      ));
  53  
  54      $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->config_table,'config_name,config_value',array(
  55          "config_name LIKE 'ldap%'",
  56      ),__LINE__,__FILE__);
  57      while ($GLOBALS['egw_setup']->db->next_record())
  58      {
  59          $GLOBALS['egw_info']['server'][$GLOBALS['egw_setup']->db->f('config_name')] = $GLOBALS['egw_setup']->db->f('config_value');
  60      }
  61      $GLOBALS['egw_info']['server']['account_repository'] = 'ldap';
  62  
  63      $egw->accounts     =& CreateObject('phpgwapi.accounts');
  64      $acct              =& $egw->accounts;
  65  
  66      // First, see if we can connect to the LDAP server, if not send `em back to config.php with an
  67      // error message.
  68  
  69      // connect to ldap server
  70      if(!$ldap = $common->ldapConnect())
  71      {
  72          $noldapconnection = True;
  73      }
  74  
  75      if($noldapconnection)
  76      {
  77          Header('Location: config.php?error=badldapconnection');
  78          exit;
  79      }
  80  
  81      // read all accounts & groups direct from SQL for export
  82      $group_info = $account_info = array();
  83      $GLOBALS['egw_setup']->db->select($GLOBALS['egw_setup']->accounts_table,'*',false,__LINE__,__FILE__);
  84      while(($row = $GLOBALS['egw_setup']->db->row(true)))
  85      {
  86          if ($row['account_type'] == 'u')    // account
  87          {
  88              $account_info[$row['account_id']] = $row;
  89          }
  90          else    // group
  91          {
  92              $row['account_id'] *= -1;    // group account_id is internally negative since 1.2
  93              $group_info[(string)$row['account_id']] = $row;
  94              
  95          }
  96      }
  97  
  98      if($_POST['cancel'])
  99      {
 100          Header('Location: ldap.php');
 101          exit;
 102      }
 103      $GLOBALS['egw_setup']->html->show_header(lang('LDAP Export'),False,'config',$GLOBALS['egw_setup']->ConfigDomain . '(' . $GLOBALS['egw_domain'][$GLOBALS['egw_setup']->ConfigDomain]['db_type'] . ')');
 104      
 105      if($_POST['submit'])
 106      {
 107          if($_POST['users'])
 108          {
 109              foreach($_POST['users'] as $accountid)
 110              {
 111                  if (!isset($account_info[$accountid])) continue;
 112  
 113                  $accounts =& CreateObject('phpgwapi.accounts',(int)$accountid);
 114  
 115                  // check if user already exists in ldap
 116                  if ($accounts->exists($accountid))
 117                  {
 118                      echo '<p>'.lang('%1 already exists in LDAP.',lang('User')." $accountid ({$account_info[$accountid]['account_lid']})")."</p>\n";
 119                      continue;
 120                  }
 121                  $account_info[$accountid]['homedirectory'] = $GLOBALS['egw_info']['server']['ldap_account_home'] . '/' . $account_info[$accountid]['account_lid'];
 122                  $account_info[$accountid]['loginshell'] = $GLOBALS['egw_info']['server']['ldap_account_shell'];
 123  
 124                  if (!$accounts->create($account_info[$accountid]))
 125                  {
 126                      echo '<p>'.lang('Creation of %1 in LDAP failed !!!',lang('User')." $accountid ({$account_info[$accountid]['account_lid']})")."</p>\n";
 127                      continue;
 128                  }
 129                  echo '<p>'.lang('%1 created in LDAP.',lang('User')." $accountid ({$account_info[$accountid]['account_lid']})")."</p>\n";
 130              }
 131          }
 132          if($_POST['ldapgroups'])
 133          {
 134              foreach($_POST['ldapgroups'] as $groupid)
 135              {
 136                  if (!isset($group_info[$groupid])) continue;
 137  
 138                  $groups =& CreateObject('phpgwapi.accounts',(int)$groupid);
 139                  
 140                  // check if group already exists in ldap
 141                  if (!$groups->exists($groupid))
 142                  {
 143                      if (!$groups->create($group_info[$groupid]))
 144                      {
 145                          echo '<p>'.lang('Creation of %1 failed !!!',lang('Group')." $groupid ({$group_info[$groupid]['account_lid']})")."</p>\n";
 146                          continue;
 147                      }
 148                      echo '<p>'.lang('%1 created in LDAP.',lang('Group')." $groupid ({$group_info[$groupid]['account_lid']})")."</p>\n";
 149                  }
 150                  else
 151                  {
 152                      echo '<p>'.lang('%1 already exists in LDAP.',lang('Group')." $groupid ({$group_info[$groupid]['account_lid']})")."</p>\n";
 153  
 154                      if ($groups->id2name($groupid) != $group_info[$groupid]['account_lid'])
 155                      {
 156                          continue;    // different group under that gidnumber in ldap!
 157                      }
 158                  }
 159                  // now saving / updating the memberships
 160                  $groups->read_repository();
 161                  if (!is_object($GLOBALS['egw']->acl))
 162                  {
 163                      $GLOBALS['egw']->acl =& CreateObject('phpgwapi.acl');
 164                  }
 165                  $groups->save_repository();
 166              }
 167          }
 168          $setup_complete = True;
 169      }
 170  
 171  
 172      if($error)
 173      {
 174          //echo '<br /><center><b>Error:</b> '.$error.'</center>';
 175          $GLOBALS['egw_setup']->html->show_alert_msg('Error',$error);
 176      }
 177  
 178      if($setup_complete)
 179      {
 180          echo '<br /><center>'.lang('Export has been completed!  You will need to set the user passwords manually.').'</center>';
 181          echo '<br /><center>'.lang('Click <a href="index.php">here</a> to return to setup.').'</center>';
 182          $GLOBALS['egw_setup']->html->show_footer();
 183          exit;
 184      }
 185  
 186      $setup_tpl->set_block('ldap','header','header');
 187      $setup_tpl->set_block('ldap','user_list','user_list');
 188      $setup_tpl->set_block('ldap','admin_list','admin_list');
 189      $setup_tpl->set_block('ldap','group_list','group_list');
 190      $setup_tpl->set_block('ldap','app_list','app_list');
 191      $setup_tpl->set_block('ldap','submit','submit');
 192      $setup_tpl->set_block('ldap','footer','footer');
 193  
 194      foreach($account_info as $account)
 195      {
 196          $user_list .= '<option value="' . $account['account_id'] . '" selected="1">'
 197              . $common->display_fullname($account['account_lid'],$account['account_firstname'],$account['account_lastname'])
 198              . '</option>';
 199      }
 200  
 201      foreach($group_info as $group)
 202      {
 203          $group_list .= '<option value="' . $group['account_id'] . '" selected="1">'
 204              . $group['account_lid']
 205              . '</option>';
 206      }
 207  
 208      $setup_tpl->set_var('action_url','ldapexport.php');
 209      $setup_tpl->set_var('users',$user_list);
 210      $setup_tpl->set_var('admins',$admin_list);
 211      $setup_tpl->set_var('ldapgroups',$group_list);
 212      $setup_tpl->set_var('s_apps',$app_list);
 213  
 214      $setup_tpl->set_var('ldap_import',lang('LDAP export users'));
 215      $setup_tpl->set_var('description',lang("This section will help you export users and groups from eGroupWare's account tables into your LDAP tree").'.');
 216      $setup_tpl->set_var('select_users',lang('Select which user(s) will be exported'));
 217      $setup_tpl->set_var('select_groups',lang('Select which group(s) will be exported (group membership will be maintained)'));
 218      $setup_tpl->set_var('form_submit','export');
 219      $setup_tpl->set_var('cancel',lang('Cancel'));
 220  
 221      $setup_tpl->pfp('out','header');
 222      if($account_info)
 223      {
 224          $setup_tpl->pfp('out','user_list');
 225      }
 226      if($group_info)
 227      {
 228          $setup_tpl->pfp('out','group_list');
 229      }
 230      $setup_tpl->pfp('out','submit');
 231      $setup_tpl->pfp('out','footer');
 232  
 233      $GLOBALS['egw_setup']->html->show_footer();


Généré le : Sun Feb 25 17:20:01 2007 par Balluche grâce à PHPXref 0.7