|
@@ -2,7 +2,6 @@ import os
|
|
|
import unittest
|
|
|
from __main__ import vtk, qt, ctk, slicer
|
|
|
from slicer.ScriptedLoadableModule import *
|
|
|
-import OpenSSL
|
|
|
|
|
|
|
|
|
#
|
|
@@ -39,7 +38,7 @@ class labkeySlicerPythonExtensionWidget(ScriptedLoadableModuleWidget):
|
|
|
def setup(self):
|
|
|
ScriptedLoadableModuleWidget.setup(self)
|
|
|
# Instantiate and connect widgets ...
|
|
|
-
|
|
|
+ self.logic=labkeySlicerPythonExtensionLogic(self)
|
|
|
#
|
|
|
# Parameters Area
|
|
|
#
|
|
@@ -49,15 +48,33 @@ class labkeySlicerPythonExtensionWidget(ScriptedLoadableModuleWidget):
|
|
|
|
|
|
connectionFormLayout = qt.QFormLayout(connectionCollapsibleButton)
|
|
|
|
|
|
- self.serverURL=qt.QLineEdit()
|
|
|
+ self.serverURL=qt.QLineEdit("https://merlin.fmf.uni-lj.si")
|
|
|
+
|
|
|
+ connectionFormLayout.addRow("Server: ", self.serverURL)
|
|
|
+
|
|
|
self.userCertButton=qt.QPushButton("Load")
|
|
|
- self.userCertButton.toolTip="Load user certificate (p12)"
|
|
|
+ self.userCertButton.toolTip="Load user certificate (crt)"
|
|
|
self.userCertButton.connect('clicked(bool)',self.onUserCertButtonClicked)
|
|
|
|
|
|
- connectionFormLayout.addRow("Server: ", self.serverURL)
|
|
|
connectionFormLayout.addRow("User certificate:",self.userCertButton)
|
|
|
|
|
|
+ self.privateKeyButton=qt.QPushButton("Load")
|
|
|
+ self.privateKeyButton.toolTip="Load private key"
|
|
|
+ self.privateKeyButton.connect('clicked(bool)',self.onPrivateKeyButtonClicked)
|
|
|
+
|
|
|
+ connectionFormLayout.addRow("Private key:",self.privateKeyButton)
|
|
|
+
|
|
|
+ self.caCertButton=qt.QPushButton("Load")
|
|
|
+ self.caCertButton.toolTip="Load CA certificate (crt)"
|
|
|
+ self.caCertButton.connect('clicked(bool)',self.onCaCertButtonClicked)
|
|
|
+
|
|
|
+ connectionFormLayout.addRow("CA certificate:",self.caCertButton)
|
|
|
+
|
|
|
+ self.connectButton=qt.QPushButton("Connect")
|
|
|
+ self.connectButton.toolTip="Connect to the server"
|
|
|
+ self.connectButton.connect('clicked(bool)',self.onConnectButtonClicked)
|
|
|
|
|
|
+ connectionFormLayout.addRow("Connection:",self.connectButton)
|
|
|
|
|
|
parametersCollapsibleButton = ctk.ctkCollapsibleButton()
|
|
|
parametersCollapsibleButton.text = "Parameters"
|
|
@@ -140,20 +157,87 @@ class labkeySlicerPythonExtensionWidget(ScriptedLoadableModuleWidget):
|
|
|
self.applyButton.enabled = self.inputSelector.currentNode() and self.outputSelector.currentNode()
|
|
|
|
|
|
def onApplyButton(self):
|
|
|
- logic = labkeySlicerPythonExtensionLogic()
|
|
|
- enableScreenshotsFlag = self.enableScreenshotsFlagCheckBox.checked
|
|
|
- screenshotScaleFactor = int(self.screenshotScaleFactorSliderWidget.value)
|
|
|
+ #logic = labkeySlicerPythonExtensionLogic()
|
|
|
+ #enableScreenshotsFlag = self.enableScreenshotsFlagCheckBox.checked
|
|
|
+ #screenshotScaleFactor = int(self.screenshotScaleFactorSliderWidget.value)
|
|
|
print("Run the algorithm")
|
|
|
- logic.run(self.inputSelector.currentNode(), self.outputSelector.currentNode(), enableScreenshotsFlag,screenshotScaleFactor)
|
|
|
+ #logic.run(self.inputSelector.currentNode(), self.outputSelector.currentNode(), enableScreenshotsFlag,screenshotScaleFactor)
|
|
|
|
|
|
def onUserCertButtonClicked(self):
|
|
|
- startDir=os.environ['HOME']
|
|
|
+ startDir=os.environ['HOME']+"/temp"
|
|
|
filename=qt.QFileDialog.getOpenFileName(None,'Open user certificate',
|
|
|
- startDir, '*.p12')
|
|
|
- pwd=qt.QInputDialog.getText(None,'Certificate password',
|
|
|
- 'Enter certificate password',qt.QLineEdit.Password)
|
|
|
+ startDir, '*.crt')
|
|
|
+ #pwd=qt.QInputDialog.getText(None,'Certificate password',
|
|
|
+ # 'Enter certificate password',qt.QLineEdit.Password)
|
|
|
+ if not(filename) :
|
|
|
+ print "No file selected"
|
|
|
+ return
|
|
|
+
|
|
|
+ f=qt.QFile(filename)
|
|
|
+ if not (f.open(qt.QIODevice.ReadOnly)) :
|
|
|
+ print "Could not open file"
|
|
|
+ return
|
|
|
+
|
|
|
+ certList=qt.QSslCertificate.fromPath(filename)
|
|
|
+ if len(certList) < 1:
|
|
|
+ print "Troubles parsing {0}".format(filename)
|
|
|
+ return
|
|
|
+
|
|
|
+ self.logic.cert=qt.QSslCertificate(f)
|
|
|
+ print "cert.isNull()={0}".format(self.logic.cert.isNull())
|
|
|
+ self.userCertButton.setText(filename)
|
|
|
+
|
|
|
+ def onPrivateKeyButtonClicked(self):
|
|
|
+ startDir=os.environ['HOME']+"/temp"
|
|
|
+ filename=qt.QFileDialog.getOpenFileName(None,'Open private key',
|
|
|
+ startDir, '*.key')
|
|
|
+ if not (filename) :
|
|
|
+ print "No file selected"
|
|
|
+ return
|
|
|
+
|
|
|
+ f=qt.QFile(filename)
|
|
|
+ if not (f.open(qt.QIODevice.ReadOnly)) :
|
|
|
+ print "Could not open file"
|
|
|
+ return
|
|
|
+ pwd=qt.QInputDialog.getText(None,'Private key password',
|
|
|
+ 'Enter key password',qt.QLineEdit.Password)
|
|
|
+
|
|
|
+ self.logic.key=qt.QSslKey(f,qt.QSsl.Rsa,qt.QSsl.Pem,qt.QSsl.PrivateKey,str(pwd))
|
|
|
+ self.privateKeyButton.setText(filename)
|
|
|
+
|
|
|
+ def onCaCertButtonClicked(self):
|
|
|
+ startDir=os.environ['HOME']+"/temp"
|
|
|
+ filename=qt.QFileDialog.getOpenFileName(None,'Open authority certificate',
|
|
|
+ startDir, '*.crt')
|
|
|
+ if not(filename) :
|
|
|
+ print "No file selected"
|
|
|
+ return
|
|
|
+
|
|
|
+ f=qt.QFile(filename)
|
|
|
+
|
|
|
+ if not (f.open(qt.QIODevice.ReadOnly)) :
|
|
|
+ print "Could not open file"
|
|
|
+ return
|
|
|
+
|
|
|
+ certList=qt.QSslCertificate.fromPath(filename)
|
|
|
+
|
|
|
+ if len(certList) < 1:
|
|
|
+ print "Troubles parsing {0}".format(filename)
|
|
|
+ return
|
|
|
+ self.logic.caCert=qt.QSslCertificate(f)#certList[0]
|
|
|
+ self.caCertButton.setText(filename)
|
|
|
+
|
|
|
+ def onConnectButtonClicked(self):
|
|
|
+ uname=str(self.logic.cert.subjectInfo("emailAddress"))
|
|
|
+ uname=qt.QInputDialog.getText(None,
|
|
|
+ "Labkey credentials","Enter username",qt.QLineEdit.Normal,uname)
|
|
|
+
|
|
|
+ pwd=qt.QInputDialog.getText(None,
|
|
|
+ "Labkey credentials","Enter password",qt.QLineEdit.Password)
|
|
|
+
|
|
|
+ self.logic.connectRemote(str(self.serverURL.text),uname,pwd)
|
|
|
+
|
|
|
|
|
|
- p12=OpenSSL.crypto.load_pkcs12(open(filename,'rb').read(),pwd)
|
|
|
|
|
|
|
|
|
#
|
|
@@ -169,6 +253,39 @@ class labkeySlicerPythonExtensionLogic(ScriptedLoadableModuleLogic):
|
|
|
Uses ScriptedLoadableModuleLogic base class, available at:
|
|
|
https://github.com/Slicer/Slicer/blob/master/Base/Python/slicer/ScriptedLoadableModule.py
|
|
|
"""
|
|
|
+ def __init__(self,parent):
|
|
|
+ ScriptedLoadableModuleLogic.__init__(self, parent)
|
|
|
+ self.qnam=qt.QNetworkAccessManager()
|
|
|
+
|
|
|
+ def connectRemote(self,serverURL,uname,pwd):
|
|
|
+ request=qt.QNetworkRequest()
|
|
|
+ request.setUrl(qt.QUrl(serverURL));
|
|
|
+ request.setHeader(qt.QNetworkRequest.ContentTypeHeader,
|
|
|
+ "application/x-www-form-urlencoded")
|
|
|
+
|
|
|
+ data="email="+uname+"&password="+pwd;
|
|
|
+
|
|
|
+ #setup the transfer
|
|
|
+ sConfig=qt.QSslConfiguration()
|
|
|
+
|
|
|
+ #user certificate
|
|
|
+ sConfig.setLocalCertificate(self.cert)
|
|
|
+ sConfig.setPrivateKey(self.key)
|
|
|
+
|
|
|
+ #ca certificate
|
|
|
+ caList=[self.caCert]
|
|
|
+ sConfig.setCaCertificates(caList)
|
|
|
+
|
|
|
+ request.setSslConfiguration(sConfig)
|
|
|
+
|
|
|
+ #post
|
|
|
+
|
|
|
+ r=self.qnam.post(request,data)
|
|
|
+ connect(qnam, qt.QNetworkAccessManager.finished, self, replyFinished);
|
|
|
+
|
|
|
+ def replyFinished(self,res):
|
|
|
+ print "Reply finished"
|
|
|
+
|
|
|
|
|
|
def hasImageData(self,volumeNode):
|
|
|
"""This is a dummy logic method that
|