コード例 #1
0
ファイル: Share.py プロジェクト: skdong/nfs-ovd
	def __init__(self, name, directory):
		self.name = name
		self.directory = directory + "/" + name
		self.group = "ovd_share_"+self.name
		self.users = []
		self.crypt = FsCryptManger(self.directory,Config.crypt_key)
		
		self.active = False
コード例 #2
0
ファイル: Share.py プロジェクト: skdong/nfs-ovd
class Share:
	STATUS_NOT_EXISTS = 1
	STATUS_ACTIVE = 2
	STATUS_INACTIVE = 3
	
	def __init__(self, name, directory):
		self.name = name
		self.directory = directory + "/" + name
		self.group = "ovd_share_"+self.name
		self.users = []
		self.crypt = FsCryptManger(self.directory,Config.crypt_key)
		
		self.active = False
	
	
	def exists(self):
		return os.path.isdir(self.directory)
	
	def isActive(self):
		return self.active
	
	def status(self):
		if not self.exists():
			return self.STATUS_NOT_EXISTS
		
		if self.active:
			return self.STATUS_ACTIVE
		
		return self.STATUS_INACTIVE

	
	def create(self):
		try:
			os.mkdir(self.directory, 0700)
			os.chown(self.directory, -1, Config.gid)
			os.chmod(self.directory, stat.S_IRWXU | stat.S_IRWXG | stat.S_ISGID)
		except:
			Logger.warn("FS: unable to create profile '%s'"%(self.name))
			return False
		
		return True
	
	
	def delete(self):
		cmd = "rm -rf %s"%(self.directory)
		s, o = commands.getstatusoutput(cmd)
		if s is not 0:
			Logger.error("FS: unable to del share")
			Logger.debug("FS: command '%s' return %d: %s"%(cmd, s, o.decode("UTF-8")))
		
		return s == 0
	
	
	
	def enable(self):
		self.crypt.decrypt_dir()
		cmd = "groupadd  %s"%(self.group)
		s, o = commands.getstatusoutput(cmd)
		if s is not 0:
			Logger.error("FS: unable to create group")
			Logger.debug("FS: command '%s' return %d: %s"%(cmd, s, o.decode("UTF-8")))
			return False
		
		cmd = 'net usershare add %s "%s" %s %s:f,Everyone:f'%(self.name, self.directory, self.name, self.group)
		s, o = commands.getstatusoutput(cmd)
		if s is not 0:
			Logger.error("FS: unable to add share")
			Logger.debug("FS: command '%s' return %d: %s"%(cmd, s, o.decode("UTF-8")))
			return False
		
		path = os.path.join(self.directory, ".htaccess")
		try:
			f = file(path, "w")
		except IOError, err:
			Logger.error("FS: unable to write .htaccess")
			Logger.debug("FS: unable to write .htaccess '%s' return: %s"%(path, str(err)))
			return False
		for user in self.users:
			f.write("Require user %s\n"%(user))
		f.close()
		
		self.do_right_normalization()
		
		self.active = True
		return True