Commit dba23e3c authored by Sebastien Robin's avatar Sebastien Robin

now compress messages, and use gpg in both ways


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@640 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 8c9b9fe2
......@@ -63,7 +63,7 @@ class SyncCode(Persistent):
PUB_CONFLICT_MERGE = 6
PUB_CONFLICT_CLIENT_WIN = 8
MAX_LINES = 1000
MAX_LINES = 10000
action_tag = 'workflow_action'
#NOT_EDITABLE_PROPERTY = ('id','object','uid','xupdate:element',action_tag,
......
......@@ -43,6 +43,7 @@ from Products.ERP5Type import Permissions
from PublicationSynchronization import PublicationSynchronization
from SubscriptionSynchronization import SubscriptionSynchronization
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
from AccessControl.User import UnrestrictedUser
#import sys
#import StringIO
......@@ -517,7 +518,7 @@ class SynchronizationTool( UniqueObject, SimpleItem,
return context.getPhysicalPath()
security.declarePublic('sendResponse')
def sendResponse(self, to_url=None, from_url=None, sync_id=None,xml=None, domain=None):
def sendResponse(self, to_url=None, from_url=None, sync_id=None,xml=None, domain=None, send=1):
"""
We will look at the url and we will see if we need to send mail, http
response, or just copy to a file.
......@@ -533,13 +534,15 @@ class SynchronizationTool( UniqueObject, SimpleItem,
decrypted = file('/tmp/%s' % filename,'w')
decrypted.write(xml)
decrypted.close()
(status,output)=commands.getstatusoutput('gpg --yes --homedir /var/lib/zope/Products/ERP5SyncML/gnupg_keys -r "%s" -se /tmp/%s' % (gpg_key,filename))
(status,output)=commands.getstatusoutput('gzip /tmp/%s' % filename)
(status,output)=commands.getstatusoutput('gpg --yes --homedir /var/lib/zope/Products/ERP5SyncML/gnupg_keys -r "%s" -se /tmp/%s.gz' % (gpg_key,filename))
LOG('readResponse, gpg output:',0,output)
encrypted = file('/tmp/%s.gpg' % filename,'r')
encrypted = file('/tmp/%s.gz.gpg' % filename,'r')
xml = encrypted.read()
encrypted.close()
commands.getstatusoutput('rm -f /tmp/%s' % filename)
commands.getstatusoutput('rm -f /tmp/%s.gpg' % filename)
commands.getstatusoutput('rm -f /tmp/%s.gz' % filename)
commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
if send:
if type(to_url) is type('a'):
if to_url.find('http://')==0:
# we will send an http response
......@@ -559,6 +562,8 @@ class SynchronizationTool( UniqueObject, SimpleItem,
to_address = to_url[len('mailto:'):]
from_address = from_url[len('mailto:'):]
self.sendMail(from_address,to_address,sync_id,xml)
else:
return xml
security.declarePrivate('sendHttpResponse')
def sendHttpResponse(self, to_url=None, sync_id=None, xml=None, domain=None ):
......@@ -574,11 +579,32 @@ class SynchronizationTool( UniqueObject, SimpleItem,
LOG('sendHttpResponse, result:',0,result)
if domain is not None:
if domain.domain_type == self.SUB:
gpg_key = domain.getGPGKey()
if result not in (None,''):
#if gpg_key not in ('',None):
# result = self.sendResponse(domain=domain,xml=result,send=0)
uf = self.acl_users
user = UnrestrictedUser('syncml','syncml',['Manager','Member'],'')
newSecurityManager(None, user)
self.activate(activity='RAMQueue').SubSync(sync_id,result)
get_transaction().commit()
#self.activate(activity='RAMQueue').SubSync(sync_id,result)
self.activate(activity='RAMQueue').readResponse(sync_id=sync_id,text=result)
security.declarePublic('sync')
def sync(self):
"""
This will try to synchronize every subscription
"""
# Login as a manager to make sure we can create objects
uf = self.acl_users
user = UnrestrictedUser('syncml','syncml',['Manager','Member'],'')
newSecurityManager(None, user)
message_list = self.portal_activities.getMessageList()
LOG('sync, message_list:',0,message_list)
if len(message_list) == 0:
for subscription in self.getSubscriptionList():
LOG('sync, subcription:',0,subscription)
self.activate(activity='RAMQueue').SubSync(subscription.getId())
security.declarePublic('readResponse')
def readResponse(self, text=None, sync_id=None, to_url=None, from_url=None):
......@@ -608,16 +634,18 @@ class SynchronizationTool( UniqueObject, SimpleItem,
# decrypt the message if needed
if gpg_key not in (None,''):
filename = str(random.randrange(1,2147483600)) + '.txt'
encrypted = file('/tmp/%s.gpg' % filename,'w')
encrypted = file('/tmp/%s.gz.gpg' % filename,'w')
encrypted.write(text)
encrypted.close()
(status,output)=commands.getstatusoutput('gpg --homedir /var/lib/zope/Products/ERP5SyncML/gnupg_keys -r "%s" --decrypt /tmp/%s.gpg > /tmp/%s' % (gpg_key,filename,filename))
(status,output)=commands.getstatusoutput('gpg --homedir /var/lib/zope/Products/ERP5SyncML/gnupg_keys -r "%s" --decrypt /tmp/%s.gz.gpg > /tmp/%s.gz' % (gpg_key,filename,filename))
LOG('readResponse, gpg output:',0,output)
(status,output)=commands.getstatusoutput('gunzip /tmp/%s.gz' % filename)
decrypted = file('/tmp/%s' % filename,'r')
text = decrypted.read()
LOG('readResponse, text:',0,text)
decrypted.close()
commands.getstatusoutput('rm -f /tmp/%s' % filename)
commands.getstatusoutput('rm -f /tmp/%s.gpg' % filename)
commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
# Get the target and then find the corresponding publication or
# Subscription
xml = FromXml(text)
......@@ -632,12 +660,15 @@ class SynchronizationTool( UniqueObject, SimpleItem,
for publication in self.getPublicationList():
if publication.getPublicationUrl()==url:
result = self.PubSync(sync_id,xml)
return result['xml']
# Then encrypt the message
xml = result['xml']
xml = self.sendResponse(xml=xml,domain=publication,send=0)
return xml
for subscription in self.getSubscriptionList():
if subscription.getSubscriptionUrl()==url:
result = self.SubSync(sync_id,xml)
if result is not None:
self.SubSync(sync_id,result)
#if result is not None: # Why Do I have this ??? XXX
# self.SubSync(sync_id,result)
# we use from only if we have a file
elif type(from_url) is type('a'):
......
......@@ -32,6 +32,7 @@ from Products.ERP5SyncML.Subscription import Signature
from xml.dom.ext.reader.Sax2 import FromXml
from cStringIO import StringIO
from xml.dom.ext import PrettyPrint
import random
try:
from Products.CMFActivity.ActiveObject import ActiveObject
except ImportError:
......@@ -198,14 +199,19 @@ class XMLSyncUtilsMixin(SyncCode, ActiveObject):
over the xmldiff code, there's some print to the standard
output, so this is unusable
"""
file1 = open('/tmp/sync_new_object','w')
filename = str(random.randrange(1,2147483600))
old_filename = filename + '.old'
new_filename = filename + '.new'
file1 = open('/tmp/%s' % new_filename,'w')
file1.write(self.getXMLObject(object=object,xml_mapping=xml_mapping))
file1.close()
file2 = open('/tmp/sync_old_object','w')
file2 = open('/tmp/%s'% old_filename,'w')
file2.write(old_xml)
file2.close()
xupdate = commands.getoutput('erp5diff /tmp/sync_old_object /tmp/sync_new_object')
xupdate = commands.getoutput('erp5diff /tmp/%s /tmp/%s' % (old_filename,new_filename))
xupdate = xupdate[xupdate.find('<xupdate:modifications'):]
commands.getstatusoutput('rm -f /tmp/%s' % old_filename)
commands.getstatusoutput('rm -f /tmp/%s' % new_filename)
return xupdate
def getXMLObject(self, object=None, xml_mapping=None):
......
export INSTANCE_HOME=/home/$USER/zope
export SOFTWARE_HOME=/usr/lib/zope/lib/python/
export COPY_OF_INSTANCE_HOME=$INSTANCE_HOME
export COPY_OF_SOFTWARE_HOME=$SOFTWARE_HOME
dir="`dirname $0`"
if test -n "$dir"; then
......
......@@ -92,12 +92,12 @@ class TestERP5SyncML(ERP5TypeTestCase):
"""
Return the list of business templates.
the business template crm give 3 folders:
the business template sync_crm give 3 folders:
/person_server with persons: 170,171, 180
/person_client1 : empty
/person_client2 : empty
"""
return ('crm',)
return ('sync_crm',)
def getSynchronizationTool(self):
return getattr(self.getPortal(), 'portal_synchronizations', None)
......@@ -134,7 +134,7 @@ class TestERP5SyncML(ERP5TypeTestCase):
portal_sync = self.getSynchronizationTool()
portal_sync.manage_addPublication(self.pub_id,self.publication_url,
'/%s/person_server' % portal_id,'',
self.xml_mapping)
self.xml_mapping,'')
pub = portal_sync.getPublication(self.pub_id)
self.failUnless(pub is not None)
......@@ -147,7 +147,7 @@ class TestERP5SyncML(ERP5TypeTestCase):
portal_sync = self.getSynchronizationTool()
portal_sync.manage_addSubscription(self.sub_id1,self.publication_url,
self.subscription_url1,'/%s/person_client1' % portal_id,'',
self.xml_mapping)
self.xml_mapping,'')
sub = portal_sync.getSubscription(self.sub_id1)
self.failUnless(sub is not None)
......@@ -160,7 +160,7 @@ class TestERP5SyncML(ERP5TypeTestCase):
portal_sync = self.getSynchronizationTool()
portal_sync.manage_addSubscription(self.sub_id2,self.publication_url,
self.subscription_url2,'/%s/person_client2' % portal_id,'',
self.xml_mapping)
self.xml_mapping,'')
sub = portal_sync.getSubscription(self.sub_id2)
self.failUnless(sub is not None)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment