Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
CP-1290: Display EULAs on boot if password not set
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy Southgate committed Sep 30, 2009
1 parent 8e48a18 commit e9321f9
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ PLUGINS_BASE += XSFeatureDRRestore.py
PLUGINS_BASE += XSFeatureDRSchedule.py
PLUGINS_BASE += XSFeatureDNS.py
PLUGINS_BASE += XSFeatureDisplayNICs.py
PLUGINS_BASE += XSFeatureEULA.py
PLUGINS_BASE += XSFeatureHostCommon.py
PLUGINS_BASE += XSFeatureHostEvacuate.py
PLUGINS_BASE += XSFeatureHostInfo.py
Expand Down
4 changes: 4 additions & 0 deletions XSConsoleConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ def DisplayAssetTag(self):
def BMCName(self):
return 'BMC'

def FirstBootEULAs(self):
# Subclasses in XSConsoleConfigOEM can add their EULAs to this array
return ['/EULA']

# Import a more specific configuration if available
if os.path.isfile(sys.path[0]+'/XSConsoleConfigOEM.py'):
import XSConsoleConfigOEM
Expand Down
2 changes: 1 addition & 1 deletion XSConsoleLayout.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def PopDialogue(self):
self.dialogues.pop()
if len(self.dialogues) == 1:
# When the display returns to the root screen, it's possible that data has changed, so
# selete the HotData cache to force a refetch
# delete the HotData cache to force a refetch
HotData.Inst().DeleteCache()
self.TopDialogue().UpdateFields()
self.Refresh()
Expand Down
8 changes: 5 additions & 3 deletions XSConsoleTerm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,18 @@ def Enter(self):
Lang("The underlying Xen API xapi is not running. This console will have reduced functionality. "
"Would you like to attempt to restart xapi?"), lambda x: self.HandleRestartChoice(x)))

# Request password change on first boot, or if it isn't set
if not Auth.Inst().IsPasswordSet() :
XSLog("Displaying 'Please specify a password' dialogue")
# Request password change on first boot, or if it isn't set
XSLog("Displaying 'Please specify a password' dialogue and EULAs")
Importer.ActivateNamedPlugIn('CHANGE_PASSWORD', Lang("Please specify a password for user 'root' before continuing"))
# Create a stack of EULA dialogues that must be accepted before the password dialogue is revealed
Importer.ActivateNamedPlugIn('EULA')
elif State.Inst().PasswordChangeRequired():
Importer.ActivateNamedPlugIn('CHANGE_PASSWORD', Lang("Please change the password for user 'root' before continuing"))
elif State.Inst().RebootMessage() is not None:
Importer.ActivateNamedPlugIn('REBOOT', State.Inst().RebootMessage())
State.Inst().RebootMessageSet(None)

self.layout.Clear()
if not '--dryrun' in sys.argv:
self.MainLoop()
Expand Down
1 change: 1 addition & 0 deletions plugins-base/XSFeatureChangePassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, inText = None, inSuccessFunc = None):
pane.TitleSet("Change Password")
pane.AddBox()
self.UpdateFields()
pane.InputIndexSet(None) # Reactivate cursor if this dialogue is initially covered and revealed later

def UpdateFields(self):
pane = self.Pane()
Expand Down
100 changes: 100 additions & 0 deletions plugins-base/XSFeatureEULA.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) Citrix Systems 2009. All rights reserved.
# xsconsole is proprietary software.
#
# Xen, the Xen logo, XenCenter, XenMotion are trademarks or registered
# trademarks of Citrix Systems, Inc., in the United States and other
# countries.

if __name__ == "__main__":
raise Exception("This script is a plugin for xsconsole and cannot run independently")

from XSConsoleStandard import *

class EULADialogue(Dialogue):
def __init__(self, inFilename):
Dialogue.__init__(self)

xSize = Layout.Inst().APP_XSIZE
ySize = Layout.Inst().APP_YSIZE

self.filename = inFilename
try:
file = open(inFilename)
try:
contents = ''.join(file.readlines())
finally:
file.close()
except Exception, e:
contents = str(e)

self.maxLine = 0
for line in contents.split('\n'):
self.maxLine = max(self.maxLine, len(line))
self.padding = ' ' * max(0, (xSize - 4 - self.maxLine) / 2)

self.text = Lang("End User License Agreement")
self.info = contents
paneSizer = PaneSizerFixed(0, 1, xSize, ySize - 1)
pane = self.NewPane(DialoguePane(self.parent, paneSizer))
pane.AddBox()
self.UpdateFields()

def UpdateFields(self):
pane = self.Pane()
pane.ResetFields()

pane.AddWrappedCentredBoldTextField(self.text)

if self.info is not None:
pane.NewLine()
# Add one field per line to preserve preformatting
for line in self.info.split('\n'):
pane.AddTextField(self.padding+line)
pane.NewLine()

helpKeys = { Lang("<Enter>") : Lang("Accept") , Lang("<Esc>") : Lang("Decline") }
if pane.NeedsScroll():
helpKeys.update({
Lang("<Page Up/Page Down>") : Lang("Scroll")
})

pane.AddKeyHelpField( helpKeys )

def HandleKey(self, inKey):
handled = True
if inKey == 'KEY_ESCAPE':
Importer.ActivateNamedPlugIn('SHUTDOWN', Lang("You must accept the End User License Agreement to continue. Would you like to shutdown?"))
elif inKey == 'KEY_ENTER':
XSLog("User accepted EULA '"+self.filename+"'")
Layout.Inst().PopDialogue()
elif inKey == 'KEY_PPAGE':
for i in range(20):
self.Pane().ScrollPageUp()
elif inKey == 'KEY_NPAGE':
for i in range(20):
self.Pane().ScrollPageDown()
elif inKey == 'KEY_UP':
self.Pane().ScrollPageUp()
elif inKey in ('KEY_DOWN', ' '):
self.Pane().ScrollPageDown()
else:
handled = False
return handled

class XSFeatureEULA:
@classmethod
def ActivateHandler(cls, *inParams):
for eula in Config.Inst().FirstBootEULAs():
Layout.Inst().PushDialogue(EULADialogue(eula, *inParams))

def Register(self):
Importer.RegisterNamedPlugIn(
self,
'EULA', # This key is referred to by name in XSConsoleTerm.py
{
'activatehandler' : self.ActivateHandler
}
)

# Register this plugin when module is imported
XSFeatureEULA().Register()
9 changes: 6 additions & 3 deletions plugins-base/XSFeatureShutdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,12 @@ def ShutdownReplyHandler(cls, inYesNo):
Layout.Inst().PushDialogue(InfoDialogue(Lang("Shutdown Failed"), Lang(e)))

@classmethod
def ActivateHandler(cls):
DialogueUtils.AuthenticatedOrPasswordUnsetOnly(lambda: Layout.Inst().PushDialogue(QuestionDialogue(
Lang("Do you want to shutdown this server?"), lambda x: cls.ShutdownReplyHandler(x))))
def ActivateHandler(cls, *inParams):
if len(inParams) > 0:
banner = inParams[0]
else:
banner = Lang("Do you want to shutdown this server?")
DialogueUtils.AuthenticatedOrPasswordUnsetOnly(lambda: Layout.Inst().PushDialogue(QuestionDialogue(banner, lambda x: cls.ShutdownReplyHandler(x))))

def Register(self):
Importer.RegisterNamedPlugIn(
Expand Down
7 changes: 4 additions & 3 deletions xsconsole.e4p
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Project SYSTEM "Project-4.4.dtd">
<!-- eric4 project file for project xsconsole -->
<!-- Saved: 2008-09-30, 19:14:13 -->
<!-- Copyright (C) 2008 , -->
<!-- Saved: 2009-09-30, 18:56:03 -->
<!-- Copyright (C) 2009 , -->
<Project version="4.4">
<ProgLanguage mixed="0">Python</ProgLanguage>
<ProjectType>Other</ProjectType>
Expand Down Expand Up @@ -86,6 +86,7 @@
<Source>XSConsoleLog.py</Source>
<Source>XSConsoleMetrics.py</Source>
<Source>XSConsoleRemoteTest.py</Source>
<Source>plugins-base/XSFeatureEULA.py</Source>
</Sources>
<Forms>
</Forms>
Expand Down Expand Up @@ -225,4 +226,4 @@
</dict>
</CheckersParams>
</Checkers>
</Project>
</Project>

0 comments on commit e9321f9

Please sign in to comment.