def execCommand(self, callable, *args, **keywds): try: result = zanshin.util.blockUntil(callable, *args, **keywds) return (1, result) except Utility.CertificateVerificationError, err: assert err.args[1] == 'certificate verify failed' # Reason why verification failed is stored in err.args[0], see # codes at http://www.openssl.org/docs/apps/verify.html#DIAGNOSTICS try: result = (2, None) # Send the message to destroy the progress dialog first. This needs # to be done in this order on Linux because otherwise killing # the progress dialog will also kill the SSL error dialog. # Weird, huh? Welcome to the world of wx... callMethodInUIThread(self.callback, result) if err.args[0] in ssl.unknown_issuer: d = ssl.askTrustServerCertificate(err.host, err.untrustedCertificates[0], self.reconnect) else: d = ssl.askIgnoreSSLError(err.host, err.untrustedCertificates[0], err.args[0], self.reconnect) waitForDeferred(d) return result except Exception, e: # There is a bug in the M2Crypto code which needs # to be fixed. #log.exception('This should not happen') return (0, (CANT_CONNECT, _(u"SSL error.")))
def _testAccountSettings(self, callback, reconnect): handle = TestChandlerServerHandle(self.host, self.port, self.username, self.password, self.useSSL, self.view, reconnect, callback=callback) path = self.path.strip("/") if path: path = "/" + path usdPath = urllib.quote("%s/cmp/user/%s/service" % (path, self.username)) request = zanshin.http.Request("GET", usdPath, {}, None) statusCode, result = handle.execCommand(handle.addRequest, request) if self.cancel: return if statusCode != 1: return if result.status == 200: # Success! return callMethodInUIThread(callback, (1, (READ_WRITE, None))) return callMethodInUIThread(callback, (0, (NO_ACCESS, result.status)))
def execCommand(self, callable, *args, **keywds): try: result = zanshin.util.blockUntil(callable, *args, **keywds) return (1, result) except Utility.CertificateVerificationError, err: assert err.args[1] == 'certificate verify failed' # Reason why verification failed is stored in err.args[0], see # codes at http://www.openssl.org/docs/apps/verify.html#DIAGNOSTICS try: result = (2, None) # Send the message to destroy the progress dialog first. This needs # to be done in this order on Linux because otherwise killing # the progress dialog will also kill the SSL error dialog. # Weird, huh? Welcome to the world of wx... callMethodInUIThread(self.callback, result) if err.args[0] in ssl.unknown_issuer: d = ssl.askTrustServerCertificate( err.host, err.untrustedCertificates[0], self.reconnect) else: d = ssl.askIgnoreSSLError(err.host, err.untrustedCertificates[0], err.args[0], self.reconnect) waitForDeferred(d) return result except Exception, e: # There is a bug in the M2Crypto code which needs # to be fixed. #log.exception('This should not happen') return (0, (CANT_CONNECT, _(u"SSL error.")))
def _testAccountSettings(self, callback, reconnect): handle = TestChandlerServerHandle(self.host, self.port, self.username, self.password, self.useSSL, self.view, reconnect, callback=callback) path = self.path.strip("/") if path: path = "/" + path usdPath = urllib.quote("%s/cmp/user/%s/service" % (path, self.username)) request = zanshin.http.Request("GET", usdPath, { }, None) statusCode, result = handle.execCommand(handle.addRequest, request) if self.cancel: return if statusCode != 1: return if result.status == 200: # Success! return callMethodInUIThread(callback, (1, (READ_WRITE, None))) return callMethodInUIThread(callback, (0, (NO_ACCESS, result.status)))
def _getPublishedShares(self, callback): path = self.path.strip("/") if path: path = "/%s" % path path = urllib.quote("%s/mc/user/%s" % (path, self.username)) handle = WebDAV.ChandlerServerHandle( self.host, self.port, username=self.username, password=waitForDeferred(self.password.decryptPassword()), useSSL=self.useSSL, repositoryView=self.itsView) extraHeaders = {} body = None request = zanshin.http.Request('GET', path, extraHeaders, body) try: resp = handle.blockUntil(handle.addRequest, request) except zanshin.webdav.ConnectionError, err: exc = errors.CouldNotConnect( _(u"Unable to connect to server: %(error)s") % {'error': err}) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc
def _getPublishedShares(self, callback): path = self.path.strip("/") if path: path = "/%s" % path path = urllib.quote("%s/mc/user/%s" % (path, self.username)) handle = WebDAV.ChandlerServerHandle(self.host, self.port, username=self.username, password=waitForDeferred(self.password.decryptPassword()), useSSL=self.useSSL, repositoryView=self.itsView) extraHeaders = {} body = None request = zanshin.http.Request('GET', path, extraHeaders, body) try: resp = handle.blockUntil(handle.addRequest, request) except zanshin.webdav.ConnectionError, err: exc = errors.CouldNotConnect(_(u"Unable to connect to server: %(error)s") % {'error': err}) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc
def _testAccountSettings(self, callback, reconnect): handle = TestChandlerServerHandle(self.host, self.port, self.username, self.password, self.useSSL, self.view, reconnect, callback=callback) # Make sure path begins/ends with / self.path = self.path.strip("/") if self.path == "": self.path = "/" else: self.path = "/" + self.path + "/" # Get the C{Resource} object associated with the specified # path topLevelResource = handle.getResource(self.path) statusCode, statusValue = handle.execCommand(topLevelResource.propfind, depth=1) if self.cancel: return if statusCode != 1: return childNames = set([]) for child in statusValue: if child is not topLevelResource: childPath = child.path if childPath and childPath[-1] == '/': childPath = childPath[:-1] childComponents = childPath.split('/') if len(childComponents): childNames.add(childComponents[-1]) # Try to figure out a unique path (although the odds of # even more than one try being needs are probably negligible).. testFilename = unicode(chandlerdb.util.c.UUID()) # Random string to use for trying a put while testFilename in childNames: testFilename = unicode(chandlerdb.util.c.UUID()) # Now, we try to PUT a small test file on the server. If that # fails, we're going to say the user only has read-only access. tmpResource = handle.getResource(topLevelResource.path + testFilename) body = "Write access test" statusCode, statusValue = handle.execCommand(tmpResource.put, body, checkETag=False, contentType="text/plain") if self.cancel: return if statusCode == 0: # No access in this case means read only if statusValue[0] == NO_ACCESS: return callMethodInUIThread(callback, (1, (READ_ONLY, None))) return callMethodInUIThread(callback, (statusCode, statusValue)) # Remove the temporary resource, and ignore failures (since there's # not much we can do here, anyway). handle.execCommand(tmpResource.delete) if self.cancel: return # Success! return callMethodInUIThread(callback, (1, (READ_WRITE, None)))
waitForDeferred(d) return result except Exception, e: # There is a bug in the M2Crypto code which needs # to be fixed. #log.exception('This should not happen') return (0, (CANT_CONNECT, _(u"SSL error."))) except M2Crypto.SSL.Checker.WrongHost, err: result = (2, None) # Send the message to destroy the progress dialog first. This needs # to be done in this order on Linux because otherwise killing # the progress dialog will also kill the SSL error dialog. # Weird, huh? Welcome to the world of wx... callMethodInUIThread(self.callback, result) d = ssl.askIgnoreSSLError(err.expectedHost, err.pem, messages.SSL_HOST_MISMATCH % \ {'actualHost': err.actualHost}, self.reconnect) waitForDeferred(d) return result except M2Crypto.BIO.BIOError, err: return (0, (CANT_CONNECT, str(err))) except zanshin.webdav.ConnectionError, err: return (0, (CANT_CONNECT, err.message))
def _testAccountSettings(self, callback, reconnect): handle = TestChandlerServerHandle(self.host, self.port, self.username, self.password, self.useSSL, self.view, reconnect, callback=callback) # Make sure path begins/ends with / self.path = self.path.strip("/") if self.path == "": self.path = "/" else: self.path = "/" + self.path + "/" # Get the C{Resource} object associated with the specified # path topLevelResource = handle.getResource(self.path) statusCode, statusValue = handle.execCommand( topLevelResource.propfind, depth=1) if self.cancel: return if statusCode != 1: return childNames = set([]) for child in statusValue: if child is not topLevelResource: childPath = child.path if childPath and childPath[-1] == '/': childPath = childPath[:-1] childComponents = childPath.split('/') if len(childComponents): childNames.add(childComponents[-1]) # Try to figure out a unique path (although the odds of # even more than one try being needs are probably negligible).. testFilename = unicode(chandlerdb.util.c.UUID()) # Random string to use for trying a put while testFilename in childNames: testFilename = unicode(chandlerdb.util.c.UUID()) # Now, we try to PUT a small test file on the server. If that # fails, we're going to say the user only has read-only access. tmpResource = handle.getResource(topLevelResource.path + testFilename) body = "Write access test" statusCode, statusValue = handle.execCommand(tmpResource.put, body, checkETag=False, contentType="text/plain") if self.cancel: return if statusCode == 0: # No access in this case means read only if statusValue[0] == NO_ACCESS: return callMethodInUIThread(callback, (1, (READ_ONLY, None))) return callMethodInUIThread(callback, (statusCode, statusValue)) # Remove the temporary resource, and ignore failures (since there's # not much we can do here, anyway). handle.execCommand(tmpResource.delete) if self.cancel: return # Success! return callMethodInUIThread(callback, (1, (READ_WRITE, None)))
class CosmoAccount(accounts.SharingAccount): # The path attribute we inherit from WebDAVAccount represents the # base path of the Cosmo installation, typically "/cosmo". The # following attributes store paths relative to WebDAVAccount.path pimPath = schema.One( schema.Text, doc='Base path on the host to use for the user-facing urls', initialValue=u'pim/collection', ) morsecodePath = schema.One( schema.Text, doc='Base path on the host to use for morsecode publishing', initialValue=u'mc/collection', ) davPath = schema.One( schema.Text, doc='Base path on the host to use for DAV publishing', initialValue=u'dav/collection', ) accountProtocol = schema.One(initialValue='Morsecode', ) accountType = schema.One(initialValue='SHARING_MORSECODE', ) # modify this only in sharing view to avoid merge conflicts unsubscribed = schema.Many( schema.Text, initialValue=set(), doc='UUIDs of unsubscribed collections the user has not acted upon') # modify this only in main view to avoid merge conflicts ignored = schema.Many( schema.Text, initialValue=set(), doc='UUIDs of unsubscribed collections the user chose to ignore') # modify this only in main view to avoid merge conflicts requested = schema.Many( schema.Text, initialValue=set(), doc='UUIDs of unsubscribed collections the user wants to restore') def publish(self, collection, displayName=None, activity=None, filters=None, overwrite=False, options=None): rv = self.itsView share = shares.Share(itsView=rv, contents=collection) shareName = collection.itsUUID.str16() conduit = CosmoConduit(itsParent=share, shareName=shareName, account=self, translator=translator.SharingTranslator, serializer=eimml.EIMMLSerializer) if filters: conduit.filters = filters share.conduit = conduit if overwrite: if activity: activity.update( totalWork=None, msg=_(u"Removing old collection from server...")) share.destroy() share.put(activity=activity) return share def getPublishedShares(self, callback=None, blocking=False): if blocking: return self._getPublishedShares(None) # don't block the current thread def startThread(repository, uuid): rv = viewpool.getView(repository) conduit = rv[uuid] try: conduit._getPublishedShares(callback) finally: viewpool.releaseView(rv) t = threading.Thread(target=startThread, args=(self.itsView.repository, self.itsUUID)) t.start() def _getPublishedShares(self, callback): path = self.path.strip("/") if path: path = "/%s" % path path = urllib.quote("%s/mc/user/%s" % (path, self.username)) handle = WebDAV.ChandlerServerHandle( self.host, self.port, username=self.username, password=waitForDeferred(self.password.decryptPassword()), useSSL=self.useSSL, repositoryView=self.itsView) extraHeaders = {} body = None request = zanshin.http.Request('GET', path, extraHeaders, body) try: resp = handle.blockUntil(handle.addRequest, request) except zanshin.webdav.ConnectionError, err: exc = errors.CouldNotConnect( _(u"Unable to connect to server: %(error)s") % {'error': err}) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc except M2Crypto.BIO.BIOError, err: exc = errors.CouldNotConnect( _(u"Unable to connect to server: %(error)s") % {'error': err}) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc
except M2Crypto.BIO.BIOError, err: exc = errors.CouldNotConnect( _(u"Unable to connect to server: %(error)s") % {'error': err}) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc if resp.status != 200: exc = errors.SharingError("%s (HTTP status %d)" % (resp.message, resp.status), details="Received [%s]" % resp.body) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc info = [] rootElement = fromstring(resp.body) for colElement in rootElement: uuid = colElement.get("uuid") href = colElement.get("href") name = _(u"Untitled") tickets = [] for subElement in colElement: if subElement.tag == "{%s}name" % mcURI: name = subElement.text elif subElement.tag == "{%s}ticket" % mcURI:
else: raise exc except M2Crypto.BIO.BIOError, err: exc = errors.CouldNotConnect(_(u"Unable to connect to server: %(error)s") % {'error': err}) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc if resp.status != 200: exc = errors.SharingError("%s (HTTP status %d)" % (resp.message, resp.status), details="Received [%s]" % resp.body) if callback: return callMethodInUIThread(callback, (exc, self.itsUUID, None)) else: raise exc info = [] rootElement = fromstring(resp.body) for colElement in rootElement: uuid = colElement.get("uuid") href = colElement.get("href") name = _(u"Untitled") tickets = [] for subElement in colElement: if subElement.tag == "{%s}name" % mcURI: name = subElement.text