25 error_reporting(E_ALL);
26 if ((php_sapi_name() !=
'cli')) {
27 trigger_error(
"You can only run this script from the command line\n", E_USER_ERROR);
30 $SYSTEM_ROOT = (isset($_SERVER[
'argv'][1])) ? $_SERVER[
'argv'][1] :
'';
31 if (empty($SYSTEM_ROOT) || !is_dir($SYSTEM_ROOT)) {
32 echo
"ERROR: You need to supply the path to the System Root as the first argument\n";
36 require_once $SYSTEM_ROOT.
'/core/include/init.inc';
39 echo
'Enter the root password for "'.SQ_CONF_SYSTEM_NAME.
'": ';
40 $root_password = rtrim(fgets(STDIN, 4094));
43 $root_user = &$GLOBALS[
'SQ_SYSTEM']->am->getSystemAsset(
'root_user');
44 if (!$root_user->comparePassword($root_password)) {
45 echo
"ERROR: The root password entered was incorrect\n";
50 if (!$GLOBALS[
'SQ_SYSTEM']->setCurrentUser($root_user)) {
51 trigger_error(
"Failed loging in as root user\n", E_USER_ERROR);
55 $bridge_ids = $GLOBALS[
'SQ_SYSTEM']->am->getTypeAssetids(
'ldap_bridge',
true);
56 $bridge_info = $GLOBALS[
'SQ_SYSTEM']->am->getAssetInfo($bridge_ids,
'ldap_bridge');
59 echo
"\n*** The following bridges are available in the system ***\n";
60 foreach ($bridge_info as $assetid => $asset_info) {
61 echo
"[$assetid] - ".$asset_info[
'name'].
"\n";
63 echo
'Enter the ID of the bridge to apply changes to: ';
64 $bridge_id = rtrim(fgets(STDIN, 4094));
65 if (!in_array($bridge_id, $bridge_ids)) {
66 echo
"Supplied bridge ID was not valid. No DN changes were made\n";
71 echo
'Enter the DN to change: ';
72 $old_dn = rtrim(fgets(STDIN, 4094));
75 echo
'Enter the new DN: ';
76 $new_dn = rtrim(fgets(STDIN, 4094));
79 echo
"\n*** Please confirm the following information is correct ***\n";
80 echo
"[BRIDGE] $bridge_id\n";
81 echo
"[OLD DN] $old_dn\n";
82 echo
"[NEW DN] $new_dn\n";
83 echo
'Is this correct [y/n]: ';
84 $confirm = rtrim(fgets(STDIN, 4094));
86 if (strtolower($confirm) !=
'y') {
87 echo
"No DN changes were made\n";
92 $old_dn = $bridge_id.
':'.$old_dn;
93 $new_dn = $bridge_id.
':'.$new_dn;
95 $db =& $GLOBALS[
'SQ_SYSTEM']->db;
96 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'BEGIN');
98 printActionName(
'Changing asset ownership');
101 'old_userid' => $old_dn,
102 'new_userid' => $new_dn,
110 printActionStatus(
'OK');
112 printActionName(
'Changing asset ownership (rollback)');
113 $sql =
'UPDATE sq_rb_ast
114 SET created_userid = '.MatrixDAL::quote($new_dn).
'
118 $sql =
'UPDATE sq_rb_ast
119 SET updated_userid = '.MatrixDAL::quote($new_dn).
'
123 $sql =
'UPDATE sq_rb_ast
124 SET published_userid = '.MatrixDAL::quote($new_dn).
'
128 $sql =
'UPDATE sq_rb_ast
129 SET status_changed_userid = '.MatrixDAL::quote($new_dn).
'
133 $sql =
'UPDATE sq_rb_ast_lnk
134 SET updated_userid = '.MatrixDAL::quote($new_dn).
'
137 printActionStatus(
'OK');
139 printActionName(
'Changing shadow links');
141 $sql =
'SELECT majorid FROM sq_shdw_ast_lnk where minorid = '.MatrixDAL::quote($new_dn);
144 foreach ($existing_links as $index => $existing_link) {
145 $existing_links[] = $existing_links[$index][
'majorid'];
146 unset($existing_links[$index]);
153 $sql =
'UPDATE sq_shdw_ast_lnk
154 SET minorid = '.MatrixDAL::quote($new_dn).
'
156 AND majorid NOT IN (SELECT s.majorid FROM sq_shdw_ast_lnk s where s.minorid = '.
MatrixDAL::quote($new_dn).
')';
160 printActionStatus(
'OK');
162 printActionName(
'Changing shadow links (rollback)');
163 $sql =
'UPDATE sq_rb_shdw_ast_lnk
164 SET minorid = '.MatrixDAL::quote($new_dn).
'
168 $sql =
'UPDATE sq_rb_shdw_ast_lnk
169 SET updated_userid = '.MatrixDAL::quote($new_dn).
'
172 printActionStatus(
'OK');
174 printActionName(
'Changing asset permissions');
175 $sql =
'UPDATE sq_ast_perm
176 SET userid = '.MatrixDAL::quote($new_dn).
'
179 printActionStatus(
'OK');
181 printActionName(
'Changing asset permissions (rollback)');
182 $sql =
'UPDATE sq_rb_ast_perm
183 SET userid = '.MatrixDAL::quote($new_dn).
'
186 printActionStatus(
'OK');
188 printActionName(
'Changing internal messages');
189 $sql =
'UPDATE sq_internal_msg
190 SET userto = '.MatrixDAL::quote($new_dn).
'
194 $sql =
'UPDATE sq_internal_msg
195 SET userfrom = '.MatrixDAL::quote($new_dn).
'
198 printActionStatus(
'OK');
200 printActionName(
'Changing screen access');
201 $sql =
'UPDATE sq_ast_edit_access
202 SET userid = '.MatrixDAL::quote($new_dn).
'
205 printActionStatus(
'OK');
207 printActionName(
'Changing screen access (rollback)');
208 $sql =
'UPDATE sq_rb_ast_edit_access
209 SET userid = '.MatrixDAL::quote($new_dn).
'
212 printActionStatus(
'OK');
214 printActionName(
'Changing locks');
215 $class_name =
'locking_method_'.SQ_CONF_LOCKING_METHOD;
216 $GLOBALS[
'SQ_SYSTEM']->am->includeAsset($class_name);
219 eval(
'return '.$class_name.
'::changeLockOwner($old_dn, $new_dn);');
220 }
catch (Exception $e) {
221 trigger_error(
'Unable to change owner of existing locks, '.$e->getMessage(), E_USER_ERROR);
225 $sql =
'UPDATE sq_lock
226 SET lockid = '.MatrixDAL::quote(
'asset.'.$new_dn).
'
230 $sql =
'UPDATE sq_lock
231 SET source_lockid = '.MatrixDAL::quote(
'asset.'.$new_dn).
'
234 printActionStatus(
'OK');
239 printActionName(
'Changing Asset Attributes ');
240 $sql =
'UPDATE sq_ast_attr_val
241 SET custom_val = '.MatrixDAL::quote($new_dn).
'
244 printActionStatus(
'OK');
246 $GLOBALS[
'SQ_SYSTEM']->doTransaction(
'COMMIT');
249 if (!empty($existing_links)) {
250 echo
"Few links in sq_shdw_ast_lnk table were already updated prior to running script.\n";
251 echo
"Links for old DN under following parents need to be fixed manually\n";
252 foreach ($existing_links as $index => $link) {
253 echo
"$index) $link\n";
266 function printActionName($str)
268 printf (
'%s%'.(40 - strlen($str)).
's', $str,
'');
281 function printActionStatus($status)
283 echo
"[ $status ]\n";