1 #!/usr/bin/php
2 <?php
3 require_once('../include/class_sambaMungedDial.inc');
5 /*
6 * GOsa: fix_munged.php - Modify existings sambaMungedDial-Entries to work with latest Win2003SP1
7 *
8 * Authors: Jan Wenzel <jan.wenzel@GONICUS.de>
9 *
10 * Copyright (C) 2006 GONICUS GmbH
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
25 * USA
26 *
27 * Contact information: GONICUS GmbH
28 * Moehnestrasse 11-17
29 * D-59755 Arnsberg
30 * Germany
31 * tel: ++49 2932 916 0
32 * fax: ++49 2932 916 230
33 * email: info@GONICUS.de
34 * http://www.GONICUS.de
35 * */
37 /* Modify these settings to your needs */
38 $ldap_host= "localhost";
39 $ldap_port= "389";
40 $ldap_base= "dc=gonicus,dc=de";
41 $ldap_admin= "cn=ldapadmin,".$ldap_base;
42 $ldap_password= "tester";
44 /* Internal Settings */
45 $ldap_protocol= "3";
46 $filter= "(&(objectClass=sambaSamAccount)(sambaMungedDial=*))";
47 $attributes= array("dn","sambaMungedDial");
49 print("This script will try to convert all ldap entries that have the sambaMungedDial-Attribute set, into the new \n".
50 "format that win2003sp1 and later requires. If an entry is already in the new format, it is not touched. \n".
51 "BEWARE: This script is not widely tested yet, so use it at your own risk! Be sure to backup your complete LDAP \n".
52 "before running.\n".
53 "Do you want to continue (y/n)?\n");
55 $handle= fopen("php://stdin","r");
56 $input=(fgets($handle,16));
57 fclose($handle);
58 if(substr(strtolower($input),0,1)!="y") {
59 exit(1);
60 }
61 /* Connect to server */
62 $connection= ldap_connect($ldap_host,$ldap_port)
63 or die ('Could not connect to server '.$ldap_host."\n!");
64 ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, $ldap_protocol);
65 ldap_bind($connection,$ldap_admin,$ldap_password)
66 or die ('Could not bind to server '.$ldap_host."!\n");
68 $results= ldap_get_entries($connection, ldap_search($connection, $ldap_base, $filter, $attributes));
70 $count= 0;
72 if(array_key_exists('count', $results)) {
73 $count= $results['count'];
74 }
76 if($count > 0) {
77 print('We found '.$count.' matching '.(($count==1)?'entry':'entries').".\n");
78 }
80 for($i=0; $i<$count; $i++) {
81 $entry= $results[$i];
82 print('Converting '.$entry['dn'].'...');
83 $mungedDial = new sambaMungedDial();
84 $mungedDial->load($entry['sambamungeddial'][0]);
85 $modify['sambaMungedDial'][0]= $mungedDial->getMunged();
86 if(ldap_modify($connection,$entry['dn'],$modify)) {
87 print("done.\n");
88 } else {
89 print("failed.\n");
90 }
91 }
93 ldap_close($connection);
94 ?>