Beispiel #1
0
def MCUFalse():
    return xmlrpclib.boolean(False)
	def ping( self, method, params ):
		if method != []: raise "Namespace not found"
		
		email, password, status, clientPort, userinfo = params
		print "email", email
		print "password", password
		print "status", status
		print "clientPort", clientPort
		print "userinfo", userinfo

		try:
			u = self.set.FindUser( email, password )
			
			print "---USER INFO---",userinfo,"------"

			try:
				clientPort = int(clientPort)
			except:
				pass
			u.clientPort = clientPort
			if userinfo != {}:
				u.email = userinfo['email']
				u.weblogTitle = userinfo['weblogTitle']
				u.serialNumber = userinfo['serialNumber']
				u.organization = userinfo['organization']
				u.flBehindFirewall = (userinfo['flBehindFirewall'] == xmlrpclib.True)
				u.name = userinfo['name']
			
			now = self.set.GetTime()
			
			if u.signedon:
				if status:
					# user is disconnecting
					u.signedon = 0
					u.lastsignoff = now
					u.signons += 1
			else:
				if not status:
					# user is signing on
					u.signedon = 1
					u.lastsignon = now
				
			u.lastping = now
			u.pings += 1
			if u.membersince == '':
				u.membersince = now
			
			self.set.Commit()
			
		except pycs_settings.PasswordIncorrect:
			return { 'flError': xmlrpclib.True,
				'message': _("Password incorrect"),
			}
		except pycs_settings.NoSuchUser:
			return { 'flError': xmlrpclib.True,
				'message': _("User not found"),
			}
		

		return {
			'flError': xmlrpclib.False,
			'cloudData': {
				'email': u.email,
				'name': u.name,
				'organization': u.organization,
				'ctFileDeletions': u.deletes,
				'whenCreated': u.membersince,
				'ctAccesses': u.pings,
				'serialNumber': u.serialNumber,
				'url': self.userFolder( u.usernum ),
				'flBehindFirewall': xmlrpclib.boolean( u.flBehindFirewall ),
				'weblogTitle': u.weblogTitle,
				'ctUpstreams': u.upstreams,
				'ctSignons': u.signons,
				'whenLastAccess': u.lastping,
				'whenLastUpstream': u.lastupstream,
				'port': u.clientPort,
				'ctBytesUpstreamed': u.bytesupstreamed,
				'userAgent': "don't know",
				'ctBytesInUse': self.userSpaceUsed( u.usernum ),
				'whenLastSignOff': u.lastsignoff,
				'messageOfTheDay': '',
				'whenLastSignOn': u.lastsignon,
				'flSignedOn': xmlrpclib.boolean( u.signedon ),
				'usernum': u.usernum,
				'ip': "don't know",
			}, 
			'message': 'Pong!',
			'yourUpstreamFolderUrl': self.userFolder( email ),
		}
Beispiel #3
0
 def delete(self, key):
     rv=super(NodeService, self).delete(key)
     return xmlrpclib.boolean(rv)
Beispiel #4
0
def MCUTrue():
    return xmlrpclib.boolean(True)
Beispiel #5
0
 def contains(self, key):
     rv=super(NodeService, self).contains(key)
     return xmlrpclib.boolean(rv)
Beispiel #6
0
 def set(self, key, value):
     super(NodeService, self).set(key, value)
     return xmlrpclib.boolean(True)
Beispiel #7
0
 def delete(self, key):
     rv = super(NodeService, self).delete(key)
     return xmlrpclib.boolean(rv)
Beispiel #8
0
	def ping( self, method, params ):
		if method != []: raise Exception("Namespace not found")
		
		email, password, status, clientPort, userinfo = params
		print "email", email
		print "password", password
		print "status", status
		print "clientPort", clientPort
		print "userinfo", userinfo

		u = self.set.FindUser( email, password )
#		print "---USER INFO---",userinfo,"------"

		try:
			clientPort = int(clientPort)
		except:
			pass
		u.clientPort = clientPort
		if userinfo != {}:
			u.email = userinfo['email']
			u.weblogTitle = encodeUnicode(userinfo['weblogTitle'], self.set.DocumentEncoding())
			u.serialNumber = userinfo['serialNumber']
			u.organization = encodeUnicode(userinfo['organization'], self.set.DocumentEncoding())
			u.flBehindFirewall = (userinfo['flBehindFirewall'] == xmlrpclib.True)
			u.name = encodeUnicode(userinfo['name'], self.set.DocumentEncoding())
		
		now = str(self.set.GetDbTime())
		
		if u.signedon:
			if status:
				# user is disconnecting
				u.signedon = 0
				u.lastsignoff = now
				u.signons += 1
		else:
			if not status:
				# user is signing on
				u.signedon = 1
				u.lastsignon = now
			
		u.lastping = now
		u.pings += 1
		if not u.membersince:
			u.membersince = now

		u.save()
			

		ret = {
			'flError': xmlrpclib.False,
			'cloudData': {
				'email': u.email,
				'name': u.name,
				'organization': u.organization,
				'ctFileDeletions': u.deletes,
				'whenCreated': u.membersince and str(u.membersince) or '',
				'ctAccesses': u.pings,
				'serialNumber': u.serialNumber,
				'url': self.userFolder( u.usernum ),
				'flBehindFirewall': xmlrpclib.boolean( u.flBehindFirewall ),
				'weblogTitle': u.weblogTitle,
				'ctUpstreams': u.upstreams,
				'ctSignons': u.signons,
				'whenLastAccess': u.lastping,
				'whenLastUpstream': u.lastupstream and str(u.lastupstream) or '',
				'port': u.clientPort,
				'ctBytesUpstreamed': u.bytesupstreamed,
				'userAgent': "don't know",
				'ctBytesInUse': u.bytesused,
				'whenLastSignOff': u.lastsignoff and str(u.lastsignoff) or '',
				'messageOfTheDay': '',
				'whenLastSignOn': u.lastsignon and str(u.lastsignon) or '',
				'flSignedOn': xmlrpclib.boolean( u.signedon ),
				'usernum': u.usernum,
				'ip': "don't know",
			}, 
			'message': 'Pong!',
			'yourUpstreamFolderUrl': self.userFolder( email ),
		}
Beispiel #9
0
 def set(self, key, value):
     super(NodeService, self).set(key, value)
     return xmlrpclib.boolean(True)
Beispiel #10
0
 def contains(self, key):
     rv = super(NodeService, self).contains(key)
     return xmlrpclib.boolean(rv)
def python_to_rpc (value, wrapObject, *wrapArgs):
	"""
	Convert a value from native python type into a type acceptable to xmlrpc.

	The following type conversions are performed.

	* None           -> None
	* str            -> unicode
	* unicode        -> unicode
	* bool           -> xmlrpclib.boolean
	* int/long/float -> int/long/float
	* datetime.datetime/.date/.time -> xmlrpclib.DateTime

	For lists and tuples the conversion will be applied to each element. For
	dictionaries the conversion will be applied to the key as well as the value.

	@param value: the native python value to be converted
	@param wrapObject: if the value is not one of the base types to be converted,
	  this function will be used to wrap the value
	"""

	if value is None:
		return value

	# None or String
	if isinstance (value, str):
		# if xmlrpclib returns an 8-bit string, it is always in default encoding
		return unicode (value)

	elif isinstance (value, unicode):
		return value

	# Boolean needs to be checked *before* <int>
	elif isinstance (value, bool):
		return xmlrpclib.boolean (value)

	# Number
	elif isinstance (value, (int, long, float)):
		return value

	# Date/Time
	elif isinstance (value, (datetime.datetime, datetime.date, datetime.time)):
		return xmlrpclib.DateTime (value.isoformat ())

	# List
	elif isinstance (value, list):
		return [python_to_rpc (element, wrapObject, *wrapArgs) for element in value]

	# Tuple
	elif isinstance (value, tuple):
		return tuple ([python_to_rpc (element, wrapObject, *wrapArgs) \
					for element in value])

	# Dictionary
	elif isinstance (value, dict):
		result = {}

		for (key, val) in value.items ():
			# Workaround for a bug xmlrpclib <= Python 2.3.4: No Unicode strings
			# possible as dictionary keys.
			if isinstance (key, unicode):
				key = key.encode ('utf-8')

			# Another deficiency in xmlrpclib: No <None> values as dictionary keys
			elif key is None:
				key = ''

			elif not isinstance (key, str):
				key = python_to_rpc (key, wrapObject, *wrapArgs)

			result [key] = python_to_rpc (val, wrapObject, *wrapArgs)

		return result

	elif wrapObject is not None:
		return wrapObject (value, *wrapArgs)

	else:
		raise exception, repr (value)
Beispiel #12
0
def MCUFalse():
    return xmlrpclib.boolean(False)
Beispiel #13
0
def MCUTrue():
    return xmlrpclib.boolean(True)