DSUpdateDialogs.pm 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # BEGIN COPYRIGHT BLOCK
  2. # This Program is free software; you can redistribute it and/or modify it under
  3. # the terms of the GNU General Public License as published by the Free Software
  4. # Foundation; version 2 of the License.
  5. #
  6. # This Program is distributed in the hope that it will be useful, but WITHOUT
  7. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. #
  10. # You should have received a copy of the GNU General Public License along with
  11. # this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. # Place, Suite 330, Boston, MA 02111-1307 USA.
  13. #
  14. # In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. # right to link the code of this Program with code not covered under the GNU
  16. # General Public License ("Non-GPL Code") and to distribute linked combinations
  17. # including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. # permitted under this exception must only link to the code of this Program
  19. # through those well defined interfaces identified in the file named EXCEPTION
  20. # found in the source code files (the "Approved Interfaces"). The files of
  21. # Non-GPL Code may instantiate templates or use macros or inline functions from
  22. # the Approved Interfaces without causing the resulting work to be covered by
  23. # the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. # additions to the list of Approved Interfaces. You must obey the GNU General
  25. # Public License in all respects for all of the Program code and other code used
  26. # in conjunction with the Program except the Non-GPL Code covered by this
  27. # exception. If you modify this file, you may extend this exception to your
  28. # version of the file, but you are not obligated to do so. If you do not wish to
  29. # provide this exception without modification, you must delete this exception
  30. # statement from your version and license this file solely under the GPL without
  31. # exception.
  32. #
  33. #
  34. # Copyright (C) 2009 Red Hat, Inc.
  35. # All rights reserved.
  36. # END COPYRIGHT BLOCK
  37. #
  38. package DSUpdateDialogs;
  39. use strict;
  40. use DialogManager;
  41. use Setup;
  42. use Dialog;
  43. use DSUtil;
  44. use FileConn;
  45. my @updateadmindialogs;
  46. my $updatewelcome = new DialogYesNo (
  47. $EXPRESS,
  48. ['update_dialog_first', 'brand', 'brand'],
  49. 1,
  50. sub {
  51. my $self = shift;
  52. my $ans = shift;
  53. my $res = $self->handleResponse($ans);
  54. if ($res == $DialogManager::NEXT) {
  55. $res = $DialogManager::ERR if (!$self->isYes());
  56. }
  57. return $res;
  58. },
  59. ['update_dialog_first_prompt'],
  60. );
  61. my $updatemode = new Dialog (
  62. $EXPRESS,
  63. 'update_dialog_mode',
  64. sub {
  65. my $self = shift;
  66. return $self->{manager}->{inf}->{General}->{UpdateMode} ||
  67. 'quit';
  68. },
  69. sub {
  70. my $self = shift;
  71. my $ans = shift;
  72. my $res = $DialogManager::ERR;
  73. if ($ans =~ /^off/i) {
  74. $self->{manager}->{inf}->{General}->{UpdateMode} = 'offline';
  75. $res = $DialogManager::NEXT;
  76. for (@updateadmindialogs) {
  77. $_->disable(); # don't need admins and passwords
  78. }
  79. } elsif ($ans =~ /^on/i) {
  80. $self->{manager}->{inf}->{General}->{UpdateMode} = 'online';
  81. $res = $DialogManager::NEXT;
  82. if (!@updateadmindialogs) {
  83. @updateadmindialogs = makeInstanceDialogs($self->{manager});
  84. $self->{manager}->addDialog(@updateadmindialogs);
  85. }
  86. for (@updateadmindialogs) {
  87. $_->enable(); # need admins and passwords
  88. }
  89. }
  90. return $res;
  91. },
  92. ['update_dialog_mode_prompt']
  93. );
  94. sub makeInstanceDialogs {
  95. my $manager = shift;
  96. # for each directory server instance, create a dialog that prompts
  97. # for the admin user and password for that instance
  98. # the default admin user for each instance is the rootdn for that
  99. # instance
  100. for my $inst ($manager->{setup}->getDirServers()) {
  101. my $innerinst = $inst;
  102. if (!$manager->{inf}->{$inst}->{RootDN}) {
  103. # if we don't already have an admin DN set for this
  104. # instance, look in the dse.ldif for the nsslapd-rootdn
  105. my $dseldif = $manager->{setup}->{configdir} . "/" . $inst . "/dse.ldif";
  106. my $conn = new FileConn($dseldif, 1);
  107. my $rootdn;
  108. if ($conn) {
  109. my $ent = $conn->search("cn=config", "base", '(objectclass=*)');
  110. if ($ent) {
  111. $rootdn = $ent->getValue('nsslapd-rootdn');
  112. } else {
  113. $manager->alert('error_finding_config_entry',
  114. "cn=config", $dseldif, $conn->getErrorString());
  115. }
  116. $conn->close();
  117. } else {
  118. $manager->alert('error_opening_dseldif', $dseldif, $!);
  119. }
  120. if ($rootdn) {
  121. $manager->{inf}->{$inst}->{RootDN} = $rootdn;
  122. } else {
  123. $manager->{inf}->{$inst}->{RootDN} = "cn=Directory Manager";
  124. }
  125. }
  126. my $dlg = new Dialog (
  127. $EXPRESS,
  128. ['update_admin_dialog', $innerinst],
  129. sub {
  130. my $self = shift;
  131. my $index = shift;
  132. my $id;
  133. if ($index == 0) { # return undef for password defaults
  134. $id = $self->{manager}->{inf}->{$innerinst}->{RootDN};
  135. }
  136. return $id;
  137. },
  138. sub {
  139. my $self = shift;
  140. my $ans = shift;
  141. my $index = shift;
  142. my $res = $DialogManager::SAME;
  143. if ($index == 0) {
  144. if (!isValidDN($ans)) {
  145. $self->{manager}->alert("dialog_dsrootdn_error", $ans);
  146. } else {
  147. $self->{manager}->{inf}->{$innerinst}->{RootDN} = $ans;
  148. $res = $DialogManager::NEXT;
  149. }
  150. } else {
  151. if (!$ans or !length($ans)) {
  152. $self->{manager}->alert("dialog_dsrootpw_invalid");
  153. } else {
  154. $self->{manager}->{inf}->{$innerinst}->{RootDNPwd} = $ans;
  155. $res = $DialogManager::NEXT;
  156. }
  157. }
  158. return $res;
  159. },
  160. ['update_admin_id_prompt'], ['update_admin_pwd_prompt', 1]
  161. );
  162. push @updateadmindialogs, $dlg;
  163. }
  164. return @updateadmindialogs;
  165. }
  166. sub getDialogs {
  167. return ($updatewelcome, $updatemode);
  168. }
  169. 1;