Ejemplo n.º 1
0
	def req_session_status(self, session_id):
		if self.role_instance.sessions.has_key(session_id):
			session = self.role_instance.sessions[session_id]
		else:
			session = Session(session_id, None, None, None, None)
			session.status = "unknown"
		
		return self.req_answer(self.session2xmlstatus(session))
Ejemplo n.º 2
0
	def req_session_disconnect(self, session_id):
		if self.role_instance.sessions.has_key(session_id):
			session = self.role_instance.sessions[session_id]
			if session.status == Session.SESSION_STATUS_ACTIVE:
				self.role_instance.spool_action("disconnect", session.id)
		else:
			session = Session(session_id, None, None, None, None)
			session.status = Session.SESSION_STATUS_UNKNOWN
		
		return self.req_answer(self.session2xmlstatus(session))
Ejemplo n.º 3
0
	def req_session_destroy(self, session_id):
		if self.role_instance.sessions.has_key(session_id):
			session = self.role_instance.sessions[session_id]
			if session.status not in [Session.SESSION_STATUS_WAIT_DESTROY, Session.SESSION_STATUS_DESTROYED, Session.SESSION_STATUS_ERROR]:
				# Switch the session status without warn the session manager
				session.switch_status(Session.SESSION_STATUS_WAIT_DESTROY)
				self.role_instance.spool_action("destroy", session.id)
		else:
			session = Session(session_id, None, None, None, None)
			session.status = Session.SESSION_STATUS_UNKNOWN
		
		return self.req_answer(self.session2xmlstatus(session))
Ejemplo n.º 4
0
	def req_session_create(self, request):
		if self.role_instance.stopping():
			return self.req_stopping(request)
		
		environment = DomainUlteo()
		try:
			document = minidom.parseString(request["data"])
			sessionNode = document.documentElement
			
			if sessionNode.nodeName != "session":
				raise Exception("invalid root node")
			
			if not sessionNode.hasAttribute("id"):
				raise Exception("invalid root node")
			
			if not sessionNode.hasAttribute("mode"):
				raise Exception("invalid root node")
			
			session = {}
			session["id"] = sessionNode.getAttribute("id")
			session["mode"] = sessionNode.getAttribute("mode")
			
			if len(session["id"])==0:
				raise Exception("Missing attribute id")
			
			if session["mode"] == "desktop":
				session["mode"] = Session.MODE_DESKTOP
			elif session["mode"] == "applications":
				session["mode"] = Session.MODE_APPLICATIONS
			else:
				raise Exception("Missing attribute id")
			
			nodes = sessionNode.getElementsByTagName("environment")
			if len(nodes)>0:
				environmentNode = nodes[0]
				name = environmentNode.getAttribute("id")
				
				if name == "Microsoft":
					environment = DomainMicrosoft()
				elif name == "Novell":
					environment = DomainNovell()
				elif name == "Local":
					environment = DomainLocal()
				else:
					raise Exception("unknown environment '%s'"%(name))
				
				ret = environment.parse(environmentNode)
				if ret is False:
					raise Exception("invalid environment schema")
			
			
			userNode = sessionNode.getElementsByTagName("user")[0]
			
			for attr in ["login", "password", "displayName"]:
				if not userNode.hasAttribute(attr):
					raise Exception("invalid child node: missing attribute "+attr)
				
				session[attr] = userNode.getAttribute(attr)
			
			applications = {}
			
			self.role_instance.applications_mutex.acquire()
			applicationNodes = sessionNode.getElementsByTagName("application")
			for node in applicationNodes:
				if node.parentNode != sessionNode:
					continue
				
				app_id = node.getAttribute("id")
				if self.role_instance.applications_id_SM.has_key(app_id):
					applications[app_id] = self.role_instance.applications_id_SM[app_id]
				
				elif self.role_instance.static_apps.applications.has_key(app_id):
					applications[app_id] = self.role_instance.static_apps.applications[app_id]
				
				else:
					self.role_instance.applications_mutex.release()
					Logger.warn("Unknown application id %s"%(app_id))
					raise Exception("Unknown application id %s"%(app_id))
			
			self.role_instance.applications_mutex.release()
			
			shellNode = sessionNode.getElementsByTagName("shell")[0]
			
			session["parameters"] = {}
			for node in sessionNode.getElementsByTagName("parameter"):
				session["parameters"][node.getAttribute("name")] = node.getAttribute("value")
			
			
			nodes = sessionNode.getElementsByTagName("profile")
			if len(nodes)>0:
				profileNode = nodes[0]
				for attribute in ("rid", "uri", "profile_mode"):
					if len(profileNode.getAttribute(attribute)) == 0:
						raise Exception("Empty attribute "+attribute)
			else:
				profileNode = None
			
			sharedfolderNodes = sessionNode.getElementsByTagName("sharedfolder")
			for node in sharedfolderNodes:
				for attribute in ("rid", "uri", "name"):
					if len(node.getAttribute(attribute)) == 0:
						raise Exception("Empty attribute "+attribute)
		
		except Exception:
			Logger.exception("Invalid xml input")
			doc = Document()
			rootNode = doc.createElement('error')
			rootNode.setAttribute("id", "usage")
			doc.appendChild(rootNode)
			return self.req_answer(doc)
		
		user = User(session["login"], {"displayName": session["displayName"], "password": session["password"]})
		if session["parameters"].has_key("locale"):
			user.infos["locale"] = session["parameters"]["locale"]
		
		session = Session(session["id"], session["mode"], user, session["parameters"], applications.values())
		session.setDomain(environment)
		session.setShellConf(shellNode)
		session.init()
		
		if profileNode is not None or len(sharedfolderNodes)>0:
			profile = Profile(session)
		
		if profileNode is not None:
			folder = {}
			for (key, value) in profileNode.attributes.items():
				folder[key] = value
			
			profile.setProfile(folder)
		
		for sharedFolderNode in sharedfolderNodes:
			folder = {}
			for (key, value) in sharedFolderNode.attributes.items():
				folder[key] = value
			
			profile.addSharedFolder(folder)
		
		if self.role_instance.sessions.has_key(session.id):
			Logger.warn("Session %s already exist, aborting creation"%(session.id))
			doc = Document()
			rootNode = doc.createElement('error')
			rootNode.setAttribute("id", "user already exist")
			doc.appendChild(rootNode)
			return self.req_answer(doc)
		
		self.role_instance.sessions[session.id] = session
		self.role_instance.spool_action("create", session.id)
		
		return self.req_answer(self.session2xmlstatus(session))