|
@@ -122,10 +122,15 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
|
|
|
def configureSSL(self,cert,key,pwd,cacert):
|
|
|
#do this first
|
|
|
- self.ctx=ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
|
|
- self.ctx.load_cert_chain(cert,key,pwd)
|
|
|
- self.ctx.verify_mode=ssl.CERT_REQUIRED
|
|
|
- self.ctx.load_verify_locations(cacert)
|
|
|
+ try:
|
|
|
+ self.ctx=ssl.SSLContext(ssl.PROTOCOL_SSLv23)
|
|
|
+ self.ctx.load_cert_chain(cert,key,pwd)
|
|
|
+ self.ctx.verify_mode=ssl.CERT_REQUIRED
|
|
|
+ self.ctx.load_verify_locations(cacert)
|
|
|
+ except ssl.SSLError as err:
|
|
|
+ print " Failed to configure SSL: {0}".format(str(err))
|
|
|
+
|
|
|
+
|
|
|
|
|
|
def connectRemote(self,serverUrl,uname,pwd):
|
|
|
https_handler=urllib2.HTTPSHandler(context=self.ctx)
|
|
@@ -144,12 +149,20 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
|
|
|
self.opener.open(r)
|
|
|
|
|
|
- #cj in opener contains the cookies
|
|
|
+ def initRemote(self):
|
|
|
+ https_handler=urllib2.HTTPSHandler(context=self.ctx)
|
|
|
+ #cookie part
|
|
|
+ cj=cookielib.CookieJar()
|
|
|
+ cookie_handler=urllib2.HTTPCookieProcessor(cj)
|
|
|
+ self.opener=urllib2.build_opener(https_handler,cookie_handler)
|
|
|
+
|
|
|
+ #cj in opener contains the cookies
|
|
|
|
|
|
def get(self,url):
|
|
|
|
|
|
+ print "GET: {0}".format(url)
|
|
|
r=urllib2.Request(url)
|
|
|
- base64string = base64.b64encode('%s:%s' % (self.auth_uname, self.auth_pass))
|
|
|
+ base64string = base64.b64encode('%s:%s' % (self.auth_name, self.auth_pass))
|
|
|
r.add_header("Authorization", "Basic %s" % base64string)
|
|
|
return self.opener.open(r)
|
|
|
#f contains json as a return value
|
|
@@ -160,7 +173,7 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
#makes it a post
|
|
|
r.add_data(data)
|
|
|
r.add_header("content-type","application/json")
|
|
|
- base64string = base64.b64encode('%s:%s' % (self.auth_uname, self.auth_pass))
|
|
|
+ base64string = base64.b64encode('%s:%s' % (self.auth_name, self.auth_pass))
|
|
|
r.add_header("Authorization", "Basic %s" % base64string)
|
|
|
|
|
|
f=self.opener.open(r)
|
|
@@ -180,10 +193,17 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
r.add_header('content-length',str(len(PROPFIND)))
|
|
|
r.add_header('Depth','1')
|
|
|
r.add_data(PROPFIND)
|
|
|
- f=self.opener.open(r)
|
|
|
+ base64string = base64.b64encode('%s:%s' % (self.auth_name, self.auth_pass))
|
|
|
+ r.add_header("Authorization", "Basic %s" % base64string)
|
|
|
+ print "PROPFIND: {0}".format(dirUrl)
|
|
|
+ dirs=[]
|
|
|
+ try:
|
|
|
+ f=self.opener.open(r)
|
|
|
+ except:
|
|
|
+ print "No data"
|
|
|
+ return dirs
|
|
|
tree=ET.XML(f.read())
|
|
|
rps=tree.findall('{DAV:}response')
|
|
|
- dirs=[]
|
|
|
for r in rps:
|
|
|
hr=r.find('{DAV:}href')
|
|
|
dirent=hr.text
|
|
@@ -210,14 +230,15 @@ class labkeyURIHandler(slicer.vtkURIHandler):
|
|
|
def loadDir(self, path):
|
|
|
#dirURL=serverUrl+"/labkey/_webdav/"+path
|
|
|
files=self.listDir(path)
|
|
|
+ fdir="NONE"
|
|
|
for f in files:
|
|
|
#returns local path
|
|
|
try:
|
|
|
- self.GetFile(f)
|
|
|
+ fdir=os.path.dirname(self.GetFile(f))
|
|
|
except:
|
|
|
#fails if there is a subdirectory; go recursively
|
|
|
self.readDir(f)
|
|
|
-
|
|
|
+ return fdir
|
|
|
|
|
|
class propfindRequest(urllib2.Request):
|
|
|
"""
|