Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 2 additions & 24 deletions XSConsoleAuth.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

import os, spwd, re, sys, time, socket

try:
import PAM # From PyPAM RPM
except ImportError:
import pam as PAM # From pip install python-pam
import pam

from XSConsoleBases import *
from XSConsoleLang import *
Expand Down Expand Up @@ -109,26 +106,7 @@ def TCPAuthenticate(self, inUsername, inPassword):
session.close()

def PAMAuthenticate(self, inUsername, inPassword):

def PAMConv(inAuth, inQueryList, *theRest):
# *theRest consumes the userData argument from later versions of PyPAM
retVal = []
for query in inQueryList:
if query[1] == PAM.PAM_PROMPT_ECHO_ON or query[1] == PAM.PAM_PROMPT_ECHO_OFF:
# Return inPassword from the scope that encloses this function
retVal.append((inPassword, 0)) # Append a tuple with two values (so double brackets)
return retVal

auth = PAM.pam()
auth.start('passwd')
auth.set_item(PAM.PAM_USER, inUsername)
auth.set_item(PAM.PAM_CONV, PAMConv)

try:
auth.authenticate()
auth.acct_mgmt()
# No exception implies a successful login
except Exception as e:
if not pam.authenticate(inUsername, inPassword, service="passwd"):
# Display a generic message for all failures
raise Exception(Lang("The system could not log you in. Please check your access credentials and try again."))

Expand Down
8 changes: 4 additions & 4 deletions XSConsoleCurses.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ def ClippedAddStr(self, inString, inX, inY, inColour): # Internal use
if len(clippedStr) > 0:
try:
encodedStr = clippedStr
if isinstance(clippedStr, unicode):
encodedStr = clippedStr.encode('utf-8')
if isinstance(clippedStr, bytes):
encodedStr = clippedStr.decode('utf-8')
# Clear field here since addstr will clear len(encodedStr)-len(clippedStr) too few spaces
self.win.addstr(inY, xPos, len(clippedStr)*' ', CursesPalette.ColourAttr(FirstValue(inColour, self.defaultColour)))
self.win.refresh()
Expand Down Expand Up @@ -279,10 +279,10 @@ def Snapshot(self):
retVal.append(self.title)
if self.hasBox:
for i in range(1, self.ySize-1):
retVal.append(self.win.instr(i, 1, self.xSize-2))
retVal.append(self.win.instr(i, 1, self.xSize-2).decode('utf-8'))
else:
for i in range(self.ySize):
retVal.append(self.win.instr(i, 0, self.xSize))
retVal.append(self.win.instr(i, 0, self.xSize).decode('utf-8'))

return retVal

Expand Down
12 changes: 5 additions & 7 deletions XSConsoleHotData.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@ def __init__(self, inOpaqueRef, inType):
def __repr__(self):
return str(self.__dict__)

# __hash__ and __cmp__ allow this object to be used as a dictionary key
# __hash__ and __eq__ allow this object to be used as a dictionary key
def __hash__(self):
return self.hash

def __cmp__(self, inOther):
def __eq__(self, inOther):
if not isinstance(inOther, HotOpaqueRef):
return 1
return False
if self.opaqueRef == inOther.opaqueRef:
return 0
if self.opaqueRef < inOther.opaqueRef:
return -1
return 1
return True
return False

def OpaqueRef(self): return self.opaqueRef
def Type(self): return self.type
Expand Down
8 changes: 4 additions & 4 deletions XSConsoleLang.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ def ToString(cls, inLabel):
elif isinstance(inLabel, Exception):
exn_strings = []
for arg in inLabel.args:
if isinstance(arg, unicode):
exn_strings.append(arg.encode('utf-8'))
if isinstance(arg, bytes):
exn_strings.append(arg.decode('utf-8'))
else:
exn_strings.append(str(arg))
retVal = str(tuple(exn_strings))
cls.LogError(retVal)
else:
if isinstance(inLabel, unicode):
inLabel = inLabel.encode('utf-8')
if isinstance(inLabel, bytes):
inLabel = inLabel.decode('utf-8')
retVal = inLabel
if cls.stringHook is not None:
cls.stringHook(retVal)
Expand Down
6 changes: 3 additions & 3 deletions XSConsoleMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import XenAPI
import urllib
import urllib.request
import xml.dom.minidom

from XSConsoleAuth import *
Expand Down Expand Up @@ -138,9 +138,9 @@ def FetchData(self):

httpRequest = 'http://localhost/rrd_updates?session_id=%s&start=%s&host=true' % (sessionID, int(time.time()) - self.SNAPSHOT_SECS)

socket = urllib.URLopener().open(httpRequest)
socket = urllib.request.urlopen(httpRequest)
try:
content = socket.read()
content = socket.read().decode('utf-8')
finally:
socket.close()
retVal = self.ParseXML(content)
Expand Down
26 changes: 13 additions & 13 deletions XSConsoleRemoteTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,27 @@
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

import os, socket, xmlrpclib
import os, socket, xmlrpc.client

from XSConsoleBases import *
from XSConsoleImporter import *
from XSConsoleLang import *
from XSConsoleLog import *
from XSConsoleLayout import *

import SocketServer
import SimpleXMLRPCServer
import socketserver
import xmlrpc.server

class UnixSimpleXMLRPCRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
# Python 2.7's SimpleXMLRPCRequestHandler enables Nagle's algorithm by default
class UnixSimpleXMLRPCRequestHandler(xmlrpc.server.SimpleXMLRPCRequestHandler):
# Python's SimpleXMLRPCRequestHandler enables Nagle's algorithm by default
# which fails because we're working with Unix domain sockets so disable it.
disable_nagle_algorithm = False

class UDSXMLRPCServer(SocketServer.UnixStreamServer, SimpleXMLRPCServer.SimpleXMLRPCDispatcher):
class UDSXMLRPCServer(socketserver.UnixStreamServer, xmlrpc.server.SimpleXMLRPCDispatcher):
def __init__(self, inAddr, inRequestHandler = None):
self.logRequests = False
SimpleXMLRPCServer.SimpleXMLRPCDispatcher.__init__(self)
SocketServer.UnixStreamServer.__init__(self, inAddr,
xmlrpc.server.SimpleXMLRPCDispatcher.__init__(self)
socketserver.UnixStreamServer.__init__(self, inAddr,
FirstValue(inRequestHandler, UnixSimpleXMLRPCRequestHandler))

def handle_request(self):
Expand Down Expand Up @@ -122,14 +122,14 @@ def WrapProcedure(self, inProc): # Any return value of inProc is discarded
try:
inProc()
except Exception as e:
raise xmlrpclib.Fault(1, self.ErrorString(e))
raise xmlrpc.client.Fault(1, self.ErrorString(e))
return None

def WrapFunction(self, inFunc): # inFunc returns a value
try:
retVal = inFunc()
except Exception as e:
raise xmlrpclib.Fault(1, self.ErrorString(e))
raise xmlrpc.client.Fault(1, self.ErrorString(e))
return retVal

def StandardReturn(self, inInfix = None):
Expand Down Expand Up @@ -193,7 +193,7 @@ def HandleXMLRPCVerify(self, inString):
result = line
break
if result is None:
raise xmlrpclib.Fault(1, self.ErrorString()+"\n\nSearch string '"+inString+"' not found.")
raise xmlrpc.client.Fault(1, self.ErrorString()+"\n\nSearch string '"+inString+"' not found.")
return self.StandardReturn("found '"+result+"'")

def HandleXMLRPCActivate(self, inName):
Expand Down Expand Up @@ -250,7 +250,7 @@ def HandleXMLRPCAssertFailure(self):
"""
self.params = ['assertfailure']
if len(self.errors) == 0:
raise xmlrpclib.Fault(1, self.ErrorString())
raise xmlrpc.client.Fault(1, self.ErrorString())
return self.StandardReturn()

def HandleXMLRPCAssertSuccess(self):
Expand All @@ -261,7 +261,7 @@ def HandleXMLRPCAssertSuccess(self):
"""
self.params = ['assertsuccess']
if len(self.errors) > 0:
raise xmlrpclib.Fault(1, self.ErrorString())
raise xmlrpc.client.Fault(1, self.ErrorString())
return self.StandardReturn()

class NullRemoteTest:
Expand Down
6 changes: 3 additions & 3 deletions plugins-base/XSFeatureSRCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def UpdateFieldsINITIAL(self):
pane.ResetFields()

sr = HotAccessor().sr[self.srHandle]
srName = sr.name_label(None).encode('utf-8')
srName = sr.name_label(None)
if srName is None:
pane.AddTitleField(Lang("The Virtual Machine is no longer present"))
else:
Expand All @@ -226,7 +226,7 @@ def UpdateFieldsCONFIRM(self):
pane.ResetFields()

sr = HotAccessor().sr[self.srHandle]
srName = sr.name_label(None).encode('utf-8')
srName = sr.name_label(None)
if srName is None:
pane.AddTitleField(Lang("The Storage Repository is no longer present"))
else:
Expand Down Expand Up @@ -282,7 +282,7 @@ def Commit(self):
Layout.Inst().PopDialogue()

operationName = SRUtils.OperationName(self.operation)
srName = HotAccessor().sr[self.srHandle].name_label(Lang('<Unknown>')).encode('utf-8')
srName = HotAccessor().sr[self.srHandle].name_label(Lang('<Unknown>'))
messagePrefix = operationName + Lang(' operation on ') + srName + ' '
Layout.Inst().TransientBanner(messagePrefix+Lang('in progress...'))
try:
Expand Down
6 changes: 3 additions & 3 deletions plugins-base/XSFeatureVMCommon.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def UpdateFieldsINITIAL(self):
pane.ResetFields()

vm = HotAccessor().guest_vm[self.vmHandle]
vmName = vm.name_label(None).encode('utf-8')
vmName = vm.name_label(None)
if vmName is None:
pane.AddTitleField(Lang("The Virtual Machine is no longer present"))
else:
Expand All @@ -183,7 +183,7 @@ def UpdateFieldsCONFIRM(self):
pane.ResetFields()

vm = HotAccessor().vm[self.vmHandle]
vmName = vm.name_label(None).encode('utf-8')
vmName = vm.name_label(None)
if vmName is None:
pane.AddTitleField(Lang("The Virtual Machine is no longer present"))
else:
Expand Down Expand Up @@ -245,7 +245,7 @@ def Commit(self):
Layout.Inst().PopDialogue()

operationName = VMUtils.OperationName(self.operation)
vmName = HotAccessor().guest_vm[self.vmHandle].name_label(Lang('<Unknown>')).encode('utf-8')
vmName = HotAccessor().guest_vm[self.vmHandle].name_label(Lang('<Unknown>'))
messagePrefix = operationName + Lang(' operation on ') + vmName + ' '
try:
task = VMUtils.AsyncOperation(self.operation, self.vmHandle, *self.opParams)
Expand Down
2 changes: 1 addition & 1 deletion xsconsole
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ if [ "$USER" = "" ]; then
export USER=root
fi

exec /usr/bin/python /usr/lib64/xsconsole/XSConsole.py $@
exec /usr/bin/python3 /usr/lib64/xsconsole/XSConsole.py $@