DSDialogs.pm 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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) 2007 Red Hat, Inc.
  35. # All rights reserved.
  36. # END COPYRIGHT BLOCK
  37. #
  38. package DSDialogs;
  39. use strict;
  40. use Net::Domain qw(hostname hostfqdn);
  41. use DialogManager;
  42. use Setup;
  43. use Dialog;
  44. use DSUtil;
  45. my $dsport = new Dialog (
  46. $TYPICAL,
  47. 'dialog_dsport_text',
  48. sub {
  49. my $self = shift;
  50. my $port = $self->{manager}->{inf}->{slapd}->{ServerPort};
  51. if (!defined($port)) {
  52. $port = 389;
  53. }
  54. if (!portAvailable($port)) {
  55. $port = getAvailablePort();
  56. }
  57. return $port;
  58. },
  59. sub {
  60. my $self = shift;
  61. my $ans = shift;
  62. my $res = $DialogManager::SAME;
  63. if ($ans !~ /^\d+$/) {
  64. $self->{manager}->alert("dialog_dsport_invalid", $ans);
  65. } elsif (!portAvailable($ans)) {
  66. $self->{manager}->alert("dialog_dsport_error", $ans);
  67. } else {
  68. $res = $DialogManager::NEXT;
  69. $self->{manager}->{inf}->{slapd}->{ServerPort} = $ans;
  70. }
  71. return $res;
  72. },
  73. ['dialog_dsport_prompt']
  74. );
  75. my $dsserverid = new Dialog (
  76. $TYPICAL,
  77. 'dialog_dsserverid_text',
  78. sub {
  79. my $self = shift;
  80. my $serverid = $self->{manager}->{inf}->{slapd}->{ServerIdentifier};
  81. if (!defined($serverid)) {
  82. $serverid = $self->{manager}->{inf}->{General}->{FullMachineName};
  83. if (!defined($serverid)) {
  84. $serverid = hostfqdn;
  85. }
  86. # strip out the leftmost domain component
  87. $serverid =~ s/\..*$//;
  88. }
  89. return $serverid;
  90. },
  91. sub {
  92. my $self = shift;
  93. my $ans = shift;
  94. my $res = $DialogManager::SAME;
  95. my $path = $self->{manager}->{setup}->{configdir} . "/slapd-" . $ans;
  96. if (!isValidServerID($ans)) {
  97. $self->{manager}->alert("error_invalid_serverid", $ans);
  98. } elsif (-d $path) {
  99. $self->{manager}->alert("error_server_already_exists", $path);
  100. } else {
  101. $res = $DialogManager::NEXT;
  102. $self->{manager}->{inf}->{slapd}->{ServerIdentifier} = $ans;
  103. }
  104. return $res;
  105. },
  106. ['dialog_dsserverid_prompt']
  107. );
  108. my $dssuffix = new Dialog (
  109. $TYPICAL,
  110. 'dialog_dssuffix_text',
  111. sub {
  112. my $self = shift;
  113. my $suffix = $self->{manager}->{inf}->{slapd}->{Suffix};
  114. if (!defined($suffix)) {
  115. $suffix = $self->{manager}->{inf}->{General}->{FullMachineName};
  116. if (!defined($suffix)) {
  117. $suffix = hostfqdn;
  118. }
  119. $suffix =~ s/^[^\.]*\.//; # just the domain part
  120. # convert fqdn to dc= domain components
  121. $suffix = "dc=$suffix";
  122. $suffix =~ s/\./, dc=/g;
  123. }
  124. return $suffix;
  125. },
  126. sub {
  127. my $self = shift;
  128. my $ans = shift;
  129. my $res = $DialogManager::SAME;
  130. if (!isValidDN($ans)) {
  131. $self->{manager}->alert("dialog_dssuffix_error", $ans);
  132. } else {
  133. $res = $DialogManager::NEXT;
  134. $self->{manager}->{inf}->{slapd}->{Suffix} = $ans;
  135. }
  136. return $res;
  137. },
  138. ['dialog_dssuffix_prompt']
  139. );
  140. my $dsrootdn = new Dialog (
  141. $EXPRESS,
  142. 'dialog_dsrootdn_text',
  143. sub {
  144. my $self = shift;
  145. my $index = shift;
  146. my $rootdn;
  147. if ($index == 0) { # return undef for password defaults
  148. $rootdn = $self->{manager}->{inf}->{slapd}->{RootDN};
  149. if (!defined($rootdn)) {
  150. $rootdn = "cn=Directory Manager";
  151. }
  152. }
  153. return $rootdn;
  154. },
  155. sub {
  156. my $self = shift;
  157. my $ans = shift;
  158. my $index = shift;
  159. my $res = $DialogManager::SAME;
  160. if ($index == 0) { # verify DN
  161. if (!isValidDN($ans)) {
  162. $self->{manager}->alert("dialog_dsrootdn_error", $ans);
  163. } else {
  164. $res = $DialogManager::NEXT;
  165. $self->{manager}->{inf}->{slapd}->{RootDN} = $ans;
  166. }
  167. } elsif ($index == 1) { # verify initial password
  168. my $test = $ans;
  169. if ($test) {
  170. $test =~ s/\s//g;
  171. }
  172. if (!$ans or (length($ans) < 8)) {
  173. $self->{manager}->alert("dialog_dsrootpw_tooshort", 8);
  174. } elsif (length($test) != length($ans)) {
  175. $self->{manager}->alert("dialog_dsrootpw_invalid");
  176. } else {
  177. $res = $DialogManager::NEXT;
  178. $self->{firstpassword} = $ans; # save for next index
  179. }
  180. } elsif ($index == 2) { # verify second password
  181. if ($ans ne $self->{firstpassword}) {
  182. $self->{manager}->alert("dialog_dsrootpw_nomatch");
  183. } else {
  184. $self->{manager}->{inf}->{slapd}->{RootDNPwd} = $ans;
  185. $res = $DialogManager::NEXT;
  186. }
  187. }
  188. return $res;
  189. },
  190. ['dialog_dsrootdn_prompt'], ['dialog_dsrootpw_prompt1', 1], ['dialog_dsrootpw_prompt2', 1]
  191. );
  192. my $dssample = new DialogYesNo (
  193. $CUSTOM,
  194. 'dialog_dssample_text',
  195. 0,
  196. sub {
  197. my $self = shift;
  198. my $ans = shift;
  199. my $res = $self->handleResponse($ans);
  200. if ($res == $DialogManager::NEXT) {
  201. $self->{manager}->{inf}->{slapd}->{AddSampleEntries} = ($self->isYes() ? 'Yes' : 'No');
  202. }
  203. return $res;
  204. },
  205. ['dialog_dssample_prompt'],
  206. );
  207. my $dspopulate = new Dialog (
  208. $CUSTOM,
  209. 'dialog_dspopulate_text',
  210. sub {
  211. my $self = shift;
  212. my $val = $self->{manager}->{inf}->{slapd}->{InstallLdifFile};
  213. if (!defined($val)) {
  214. $val = 'suggest';
  215. $self->{manager}->{inf}->{slapd}->{AddOrgEntries} = 'Yes';
  216. }
  217. return $val;
  218. },
  219. sub {
  220. my $self = shift;
  221. my $ans = shift;
  222. my $res = $DialogManager::SAME;
  223. if ($ans eq 'none') {
  224. $self->{manager}->{inf}->{slapd}->{InstallLdifFile} = 'none';
  225. $self->{manager}->{inf}->{slapd}->{AddOrgEntries} = 'No';
  226. $res = $DialogManager::NEXT;
  227. } elsif ($ans eq 'suggest') {
  228. $self->{manager}->{inf}->{slapd}->{InstallLdifFile} = 'suggest';
  229. $self->{manager}->{inf}->{slapd}->{AddOrgEntries} = 'Yes';
  230. $res = $DialogManager::NEXT;
  231. } else { # a file
  232. if (! -f $ans) {
  233. $self->{manager}->alert("dialog_dspopulate_error", $ans);
  234. } else {
  235. $self->{manager}->{inf}->{slapd}->{InstallLdifFile} = $ans;
  236. $self->{manager}->{inf}->{slapd}->{AddOrgEntries} = 'No';
  237. $res = $DialogManager::NEXT;
  238. }
  239. }
  240. return $res;
  241. },
  242. ['dialog_dspopulate_prompt']
  243. );
  244. sub getDialogs {
  245. return ($dsport, $dsserverid, $dssuffix, $dsrootdn, $dssample, $dspopulate);
  246. }
  247. 1;