Пример #1
0
	def dispatch_create_item(self, path):
		responseData = {}
		if not os.path.isfile(path):
			responseData['response'] = 1
		else:
			responseData['response'] = 0

			uid = ndutil.getUid(path)
			if self.dbManager.exists(uid):
				responseData['uid'] = uid
				if self.fileMode == 'move':
					os.remove(path)
			else:
				size = ndutil.getSize(path) / 1024
				createTime = ndutil.getCreated()
						
				fileExt = os.path.basename(path).split('.', 1)
				dirPath = self.enable_storage_dir(self.storageDir, uid)
				newPath = '%s/%s.%s' % (dirPath, uid, fileExt[1])
				if self.fileMode == 'move':
					shutil.move(path, newPath)
				elif self.fileMode == 'copy':
					shutil.copyfile(path, newPath)
				path = ndutil.getAbstractPath(newPath)

				self.dbManager.create_item(uid, path, createTime, size)
				responseData['uid'] = uid
		return responseData
Пример #2
0
	def dispatch(self, data, host, port):
		retCode, result = self.msgManager.resRequest(data)
		if retCode != 0:
			self.logger.logger('Error Request')
		else:
			responseData = {}
			if result['request'] == 'scan':
				self.logger.logger('Request: SCAN')
				if not os.path.isfile(result['path']):
					responseData['response'] = 1
				else:
					hashval = ndutil.getMd5(result['path'])
					reqTime = ndutil.getCreated()
					fileSize = ndutil.getSize(result['path'])

					if (fileSize/1024/1024) >= 32:
						responseData['response'] = 1
					else:
						scanCode, scanResult = self.dbManager.scan(reqTime, result['path'], hashval)
						if scanCode == 0:
							responseData['response'] = 0
							nums = scanResult.split('/', 1)
							responseData['hashval'] = hashval
							responseData['positive'] = nums[0]
							responseData['total'] = nums[1]
						if scanCode == 1:
							responseData['response'] = 2
						if scanCode == 2:
							responseData['response'] = 2
							self.fsLock.acquire()
							self.fsQueue.put('%s,%s' % (hashval, result['path']), 1)
							self.fsLock.release()

			msg = self.msgManager.genResponse(responseData)
			self.transport.write(msg, (host, port))
Пример #3
0
 def dispatch_create_item(self, uid, state):
     responseData = {}
     if state not in ['b', 'm', 'u']:
         responseData['response'] = 1
         return responseData
     
     if self.dbManager.exists(uid):
         responseData = self.dispatch_update_state(uid, state)
     else:
         self.dbManager.create_item(uid, state, ndutil.getCreated())
         responseData['response'] = 0
     return responseData