示例#1
0
	def rdpFile(self, **kw):

		# Require authentication
		if not self.checkAuth():
			# Auth failed. Send 401.
			raise cherrypy.HTTPError(401, "Authentication is required to access the requested resource on this server.")
		
		# Init win32 com
		self.prepareCOM()

		if re.match('[^\d]', cherrypy.request.params.get('port')):
			response = {'errors':[],'data':{},'fn':'getVMDetails' }
			try:
				cherrypy.thread_data.vbox = vboxactions.vboxactions(self.ctx)
				req = {'vm':cherrypy.request.params.get('vm')}
				cherrypy.thread_data.vbox('getVMDetails',req,response)
			finally:
				if cherrypy.thread_data.vbox:
					cherrypy.thread_data.vbox.shutdown()
				del cherrypy.thread_data.vbox
			port = response['data'].get('consolePort')
		else:
			port = cherrypy.request.params.get('port')

		cherrypy.response.headers['Content-Type'] = "application/x-rdp"
		cherrypy.response.headers['Content-Disposition'] = "attachment; filename=\""+ cherrypy.request.params.get('vm') +".rdp\""
		
		return str("auto connect:i:1\nfull address:s:"+cherrypy.request.params.get('host')+( str(port+":") if port else '')+"\ncompression:i:1\ndisplayconnectionbar:i:1\n")
示例#2
0
	def ajax(self,fn, **kw):

		# Require authentication
		if not self.checkAuth():
			# Auth failed. Send 401.
			raise cherrypy.HTTPError(401, "Authentication is required to access the requested resource on this server.")

		# Init win32 com
		self.prepareCOM()
        
		response = {'errors':[],'data':{},'fn':fn }
        
		cherrypy.thread_data.vbox = None
		
		try:
			
			##########################
			#
    		# Configuration request
    		#
    		#########################
			if fn == 'getConfig':
    
				response['data'] = self.ctx['config']
    

				try:              
				
					cherrypy.thread_data.vbox = vboxactions.vboxactions(self.ctx)
    				
					response['data']['VBWEB_ERRNO_FATAL'] = self.VBWEB_ERRNO_FATAL
    
					response['data']['version'] = cherrypy.thread_data.vbox.vboxVersion()
            		
					response['data']['hostOS'] = str(cherrypy.thread_data.vbox.vbox.host.operatingSystem)
					if response['data']['hostOS'].lower().find('windows') == -1:
						response['data']['DSEP'] = '/'
					else:
						response['data']['DSEP'] = '\\'
            				
				except:
					pass
        		
				if response['data'].get('username'): del response['data']['username']
				if response['data'].get('password'): del response['data']['password']
        		
				# Get host
				if response['data'].get('location'):
					
					try:
						from urlparse import urlparse
						url = urlparse(response['data'].get('location'))
					except:
						url = urllib.parse(response['data'].get('location'))
					response['data']['host'] = url.hostname

					if not response['data'].get('servers') or type(response['data']['servers']) != type(list()):
						response['data']['servers'] = [
    						{'name' : response['data']['host'],
    						'location' : response['data']['location']
    						}
    					]
					response['data']['servername'] = response['data']['servers'][0]['name']
                
				else:
					response['data']['host'] = 'localhost'
					response['data']['servers'] = []
        
				if not response['data'].get('consoleHost'):
					response['data']['consoleHost'] = response['data']['host']


			##############################
			#
			# Other AJAX requests
			#
			##############################
			else:
                
				cherrypy.thread_data.vbox = vboxactions.vboxactions(self.ctx)
    
				cherrypy.thread_data.vbox(fn,cherrypy.request.params, response)
				
                
			try:
				if cherrypy.thread_data.vbox and len(cherrypy.thread_data.vbox.errors):
					response['errors'] = cherrypy.thread_data.vbox.errors
			except:
				pass
            
		except Exception, e:
			
			errno = 0
			error = str(e)
			details = traceback.format_exc()
			
			try:
				errno = self.VBWEB_ERRNO_FATAL if cherrypy.thread_data.vbox and not cherrypy.thread_data.vbox.connected else 0
			except:
				pass
				
			response['errors'].append(
				{'errno':errno,
				'error':error,
				'details':details
				}
			)				
示例#3
0
	def screen(self, **kw):
    	
    	# Require authentication
		if not self.checkAuth():
			# Auth failed. Send 401.
			raise cherrypy.HTTPError(401, "Authentication is required to access the requested resource on this server.")

		# Init win32 com
		self.prepareCOM()
    	
		width = cherrypy.request.params.get('width')
		vm = cherrypy.request.params.get('vm')
		if not vm: return ''

		try:
			cherrypy.thread_data.vbox = vboxactions.vboxactions(self.ctx)
			cherrypy.thread_data.vbox.connect()
    	
			machine = cherrypy.thread_data.vbox.vbox.findMachine(vm)
			machineState = str(cherrypy.thread_data.vbox.vboxType('MachineState',machine.state))
    		
			if str(machineState) != 'Running' and str(machineState) != 'Saved':
				machine.releaseRemote()
				raise Exception('The specified virtual machine is not in a Running state.')
            
    		# Date last modified
			dlm = math.floor(int(machine.lastStateChange)/1000)
    
    		# Running screen shot
			if str(machineState) == 'Running':
    
				cherrypy.thread_data.vbox.session = cherrypy.thread_data.vbox.vboxMgr.platform.getSessionObject(cherrypy.thread_data.vbox.vbox)
				machine.lockMachine(cherrypy.thread_data.vbox.session,cherrypy.thread_data.vbox.vboxType('LockType','Shared'))
    
				res = cherrypy.thread_data.vbox.session.console.display.getScreenResolution(0)
    
				screenWidth = int(res[0])
				screenHeight = int(res[1])
    
				if width and int(width) > 0:
					factor  = float(float(width) / float(screenWidth))
					screenWidth = width
					if factor > 0:screenHeight = factor * screenHeight
					else:screenHeight = (screenWidth * 3.0/4.0)
    			
				cherrypy.response.headers["Expires"] = "Mon, 26 Jul 1997 05:00:00 GMT"
				cherrypy.response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime())
				cherrypy.response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0"
				cherrypy.response.headers["Pragma"] = "no-cache"
    
				imageraw = [cherrypy.thread_data.vbox.session.console.display.takeScreenShotPNGToArray(0,int(screenWidth), int(screenHeight))]				
				cherrypy.thread_data.vbox.session.unlockMachine()
    			
    
			else:
    
    			# Set last modified header
				cherrypy.response.headers['Last-Modified'] = time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(dlm))
    			
    		  	# Let the browser cache images
			  	if cherrypy.request.headers.get('If-Modified-Since') and time.mktime(parsedate_tz(cherrypy.request.headers.get('If-Modified-Since'))).time() >= dlm:
			  		raise cherrypy.HTTPRedirect([], 304)
          		
				if cherrypy.request.params.get('full'):
					imageraw = machine.readSavedScreenshotPNGToArray(0);
				else:
					imageraw = machine.readSavedThumbnailPNGToArray(0);
    
			cherrypy.response.headers['Content-Type'] = 'image/png'
    		
			imgdata = ''
    
    		# Non-web data is printed directly
			if cherrypy.thread_data.vbox.vboxConnType != 'web':
				for i in range(len(imageraw)):
					if len(imageraw[i]):
						imgdata = imageraw[i]
						break
			else:
    			
				for i in range(len(imageraw)):
					if type(imageraw[i]) == types.InstanceType:
						for b in imageraw[i]:
							imgdata += chr(b)
    		    		
		finally:
			if cherrypy.thread_data.vbox:
				cherrypy.thread_data.vbox.shutdown()
				del cherrypy.thread_data.vbox
			
		imgdata = StringIO.StringIO(imgdata)
		return cherrypy.lib.file_generator(imgdata)
示例#4
0
	def jqueryFileTree(self, **kw):

		from jqueryFileTree import jqueryFileTree
		
		# Require authentication
		if not self.checkAuth():
			# Auth failed. Send 401.
			raise cherrypy.HTTPError(401, "Authentication is required to access the requested resource on this server.")

		# Init win32 com
		self.prepareCOM()
		
		rstr = ''
		
		allowedFiles = {}
		if self.ctx['config'].get('browserRestrictFiles'):
			allowedList = self.ctx['config']['browserRestrictFiles'].lower().split(',')
			for i in allowedList: allowedFiles[i] = i
        
		allowedFolders = {}
		if self.ctx['config'].get('browserRestrictFolders'):
			allowedList = self.ctx['config']['browserRestrictFolders'].lower().split(',')
			for i in allowedList: allowedFolders[i] = i
        
		localBrowser = bool(self.ctx['config'].get('browserLocal') or g_vboxManager)

		try:       
			cherrypy.thread_data.vbox = vboxactions.vboxactions(self.ctx)
            
			cherrypy.thread_data.vbox.connect()
            
			if str(cherrypy.thread_data.vbox.vbox.host.operatingSystem).lower().find('windows') == -1:
				strDSEP = '/'
			else:
				strDSEP = '\\'
    		
			ft = jqueryFileTree()
    		
			if localBrowser:
				if cherrypy.thread_data.vbox:
					cherrypy.thread_data.vbox.shutdown()
					del cherrypy.thread_data.vbox
				ft.mode = 'local'
			else:
				ft.mode = 'remote'
				ft.vbox = cherrypy.thread_data.vbox.vbox
    		
    		
			if cherrypy.request.params.get('fullpath'):
				ft.fullpath = int(cherrypy.request.params.get('fullpath'))
			if cherrypy.request.params.get('dirsOnly'):
				ft.dirsOnly = int(cherrypy.request.params.get('dirsOnly'))
			ft.strDSEP = strDSEP
			ft.allowedFiles = allowedFiles
			ft.allowedFolders = allowedFolders
    		
			rstr = ft.getdir(cherrypy.request.params.get('dir'))

		except Exception, e:
			print e
			print traceback.format_exc()