Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 155483 Details for
Bug 237356
Move DS Admin Code into Admin Server
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
new Dialog perl module
Dialog.pm (text/plain), 8.70 KB, created by
Rich Megginson
on 2007-05-25 22:45:31 UTC
(
hide
)
Description:
new Dialog perl module
Filename:
MIME Type:
Creator:
Rich Megginson
Created:
2007-05-25 22:45:31 UTC
Size:
8.70 KB
patch
obsolete
># BEGIN COPYRIGHT BLOCK ># This Program is free software; you can redistribute it and/or modify it under ># the terms of the GNU General Public License as published by the Free Software ># Foundation; version 2 of the License. ># ># This Program is distributed in the hope that it will be useful, but WITHOUT ># ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS ># FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. ># ># You should have received a copy of the GNU General Public License along with ># this Program; if not, write to the Free Software Foundation, Inc., 59 Temple ># Place, Suite 330, Boston, MA 02111-1307 USA. ># ># In addition, as a special exception, Red Hat, Inc. gives You the additional ># right to link the code of this Program with code not covered under the GNU ># General Public License ("Non-GPL Code") and to distribute linked combinations ># including the two, subject to the limitations in this paragraph. Non-GPL Code ># permitted under this exception must only link to the code of this Program ># through those well defined interfaces identified in the file named EXCEPTION ># found in the source code files (the "Approved Interfaces"). The files of ># Non-GPL Code may instantiate templates or use macros or inline functions from ># the Approved Interfaces without causing the resulting work to be covered by ># the GNU General Public License. Only Red Hat, Inc. may make changes or ># additions to the list of Approved Interfaces. You must obey the GNU General ># Public License in all respects for all of the Program code and other code used ># in conjunction with the Program except the Non-GPL Code covered by this ># exception. If you modify this file, you may extend this exception to your ># version of the file, but you are not obligated to do so. If you do not wish to ># provide this exception without modification, you must delete this exception ># statement from your version and license this file solely under the GPL without ># exception. ># ># ># Copyright (C) 2007 Red Hat, Inc. ># All rights reserved. ># END COPYRIGHT BLOCK ># > >package Dialog; > >use DialogManager qw($BACK $SAME $NEXT $ERR); > >require Exporter; >@ISA = qw(Exporter); >@EXPORT = qw(); > ># NOTE: This "class" is an "abstract" class. There are two methods which ># must be provided by subclasses: ># $ans = $dialog->defaultAns($promptindex); ># where $promptindex is the index into the array of prompts given when ># constructing the Dialog object ># The dialog will typically use a default answer either hardcoded in ># or from some key in the setup cache (.inf) file ># ># $resp = $dialog->handleResponse($ans, $index); ># The dialog uses this method to perform validation of the input, set the value ># in the setup cache, display errors or warnings, and tell the dialog manager ># if the prompt needs to be redisplayed, or if there was an unrecoverable error ># $resp should be $SAME to reprompt, $ERR to abort, or $NEXT to continue ># the $ans and defaultAns should be in the native charset, so the dialog ># may have to convert to/from utf8 as needed. > ># a dialog consists of a title, some explanatory text, and one or more prompts ># each prompt has a default value. An example of a dialog with more than ># one prompt would be a dialog asking the user for the new root DN and password - ># in that case, there would be 3 prompts - one for the DN, one for the password, ># and one to verify the password ># The text and prompts are given as resource keys. Usually the resource value ># will be a simple string, in which case the resource key is passed in as a simple ># string. However, if the resource string contains replaceable parameters, the ># resource key is passed as an array ref consisting of the resource key as the ># first element and the parameters to use for replacement as the subsequent ># array elements e.g. ># $foo = new Dialog(['RESOURCE_KEY_CONFIG_LDAP_URL', $secure, $host, $port, $suffix], ...); ># but usually for simple cases like this: ># $foo = new Dialog('RESOURCE_KEY_WELCOME', ...); ># The manager contains the context for all of the dialogs - the setup type, the resource ># file, setup log, other context shared among the dialogs ># the type is the setup type - 1, 2, or 3 for express, typical, or custom ># type is used to say which types use this dialog >sub new { > my $type = shift; > my $self = {}; > > $self->{type} = shift; > $self->{text} = shift; > $self->{defaultAns} = shift; > $self->{handleResp} = shift; > $self->{prompts} = @_; > > $self = bless $self, $type; > > return $self; >} > >sub setManager { > my $self = shift; > $self-{manager} = shift; >} > ># returns true if this dialog is to be displayed for the current setup type ># false otherwise >sub isDisplayed { > my $self = shift; > > return $self->{type} <= $self->{manager}->{type}; >} > ># each prompt looks like this: ># [ 'resource key', is pwd ] ># The resource key is the string key of the resource ># is pwd is optional - if present, the prompt is for a password ># and should not echo the answer ># e.g. ># ['RESOURCE_USERNAME'], ['RESOURCE_PASSWORD', 1], ['RESOURCE_PASSWORD_AGAIN', 1] >sub display { > my $self = shift; > my $resp = $SAME; > > # convert the resource key to the actual text, > my $text = $self->{manager}->getText($self->{text}); > # display it, > print $text; > # log it > $self->{manager}->log($text); > > my $index = 0; > for (my $index = 0; $index < $self->{prompts}; ++$index) { > my $prompt = $self->{prompts}[$index]; > # convert the prompt resource key to the actual text, > $text = $self->{manager}->getText($prompt->[0]); > # display it, > print $text; > # log it > $self->{manager}->log($text); > # display the default answer > my $defaultans = $self->{defaultAns}($self, $index); > if ($defaultans) { > print $defaultans; > $self->{manager}->log($defaultans); > } > # if we are prompting for a password, disable console echo > if ($prompt->[2]) { > system("stty -echo"); > } > # read the answer > my $ans = <STDIN>; > # if we are prompting for a password, enable console echo > if ($prompt->[2]) { > system("stty echo"); > } > chop($ans); # trim trailing newline > > # see if this is the special BACK response, and finish if so > if ($self->{manager}->isBack($ans)) { > $resp = $BACK; > $self->{manager}->log("BACK\n"); > last; > } > # log the response, if not a password > if (!$prompt->[2]) { > $self->{manager}->log($ans . "\n"); > } > > # see if this is the special BACK response, and finish if so > # response handler is NOT called in this case > if ($self->{manager}->isBack($ans)) { > $resp = $BACK; > last; > } > > # figure out what action to take based on the users response > # this will set values in the setup info file > # this will also validate input, and display errors if the > # input is not correct - in that case, the resp will be > # SAME to reprompt, or ERR if unrecoverable > # NOTE: user cannot BACK from prompt to prompt - BACK > # always means BACK to the previous dialog > $resp = $self->{handleResp}($self, $ans, $index); > if ($resp == $SAME) { > $index--; # reprompt > } elsif ($resp == $ERR) { > last; > } > } > > return $resp; >} > >package DialogYesNo; > >@ISA = qw(Dialog); > >sub new { > my $type = shift; > my $setuptype = shift; > my $text = shift; > my $handler = shift || &handleResponse; > my $prompt = ['RESOURCE_PROMPT_YES_NO']; > my $self = Dialog->new($setuptype, $text, > &defaultAns, $handler, $prompt); > > $self = bless $self, $type; > > return $self; >} > >sub setDefaultYes { > my $self = shift; > $self->{default} = $self->{manager}->getText("RESOURCE_YES"); >} > >sub setDefaultNo { > my $self = shift; > $self->{default} = $self->{manager}->getText("RESOURCE_NO"); >} > >sub defaultAns { > return $self->{ans} || $self->{default}; >} > >sub isYes { > my $self = shift; > return $self->{ans} eq $self->{manager}->getText("RESOURCE_YES"); >} > >sub handleResponse { > my $self = shift; > my $ans = shift; > my $resp = $SAME; > my $yes = $self->{manager}->getText("RESOURCE_YES"); > my $nno = $self->{manager}->getText("RESOURCE_NO"); > > if ($ans =~ /^$nno/) { > $resp = $NEXT; > $self->{ans} = $nno; > } elsif ($ans =~ /^$yes/) { > $resp = $NEXT; > $self->{ans} = $yes; > } else { > my $text = $self->{manager}->getText("RESOURCE_YES_NO_ERROR"); > print $text; > } > > return $resp; >} > >############################################################################# ># Mandatory TRUE return value. ># >1;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 237356
:
153230
|
153562
|
153667
|
153668
|
153674
|
153675
|
153677
|
153678
|
155103
|
155105
|
155406
|
155407
|
155408
|
155409
|
155410
|
155411
|
155412
|
155413
|
155414
|
155483
|
155484
|
155485
|
155486
|
155487
|
155488
|
155489
|
155490
|
156389
|
156510
|
156525
|
156539
|
156540
|
156541
|
156612
|
156613
|
156614
|
156626
|
156633
|
156634
|
156741
|
156829
|
156834
|
156839
|
156840
|
156895
|
157043
|
157044
|
157133
|
157159
|
157160
|
157164
|
157165
|
157167
|
157298
|
157378
|
157381
|
157388
|
157390
|
157400
|
157401
|
157407
|
157408
|
157429
|
157431
|
157469
|
157471
|
157479
|
157480
|
160762