Ejemplo n.º 1
0
 def __init__(self,host=None,port=None,username=None,password=None,prefix=None):
   self.host = cfg['host'] if host is None else host
   self.port = cfg['port'] if port is None else port
   self.username = cfg['username'] if username is None else username
   self.password = cfg['password'] if password is None else password
   self.prefix = cfg['prefix'] if prefix is None else prefix
   BtSyncApi.__init__(self,self.host,self.port,self.username,self.password)
Ejemplo n.º 2
0
	def __init__(self,args):
		BtSyncApi.__init__(self)
		self.args = args
		self.uid = int(os.getuid())
		self.pid = None
		self.configpath = os.environ['HOME'] + '/.config/btsync'
		self.storagepath = os.environ['HOME'] + '/.btsync'
		self.pidfile = self.configpath + '/btsync-agent.pid'
		self.conffile = self.configpath + '/btsync-agent.conf'
		self.preffile = self.configpath + '/btsync-gui.prefs'
		self.lockfile = self.configpath + '/btsync-gui.pid'
		self.lock = None
		# load and process values from preferences file
		self.load_prefs()
		self.read_prefs()
		# process command line arguments
		self.read_args()
		self.exec_args()
		# initialize btsync api
		self.reset_connection_params()
		if self.is_auto():
			self.lock = BtSingleton(self.lockfile,'btsync-gui')
Ejemplo n.º 3
0
	def __init__(self,args):
		BtSyncApi.__init__(self)
		self.args = args
		self.uid = int(os.getuid())
		self.pid = None
		self.configpath = os.environ['HOME'] + '/.config/btsync'
		self.storagepath = os.environ['HOME'] + '/.btsync'
		self.pidfile = self.configpath + '/btsync-agent.pid'
		self.conffile = self.configpath + '/btsync-agent.conf'
		self.preffile = self.configpath + '/btsync-gui.prefs'
		self.lockfile = self.configpath + '/btsync-gui.pid'
		self.lock = None
		self.prefs = {}
		# load values from preferences
		self.load_prefs()
		# generate random credentials
		try:
			username = base64.b64encode(os.urandom(16))[:-2]
			password = base64.b64encode(os.urandom(32))[:-2]
		except NotImplementedError:
			logging.warning('No good random generator available. Using default credentials')
			username = '******'
			password = base64.b64encode('This is really not secure!')[:-2]
		self.username = self.get_pref('username',username)
		self.password = self.get_pref('password',password)
		self.bindui = self.get_pref('bindui','127.0.0.1')
		self.portui = self.get_pref('portui',self.uid + 8999)
		self.paused = self.get_pref('paused',False)
		self.webui = self.get_pref('webui',False)
		# process command line arguments
		if self.args.username is not None:
			self.username = self.args.username
		if self.args.password is not None:
			self.password = self.args.password
		if self.args.bindui is not None:
			self.bindui = '0.0.0.0' if self.args.bindui == 'auto' else self.args.bindui
		if self.args.port != 0:
			self.portui = self.args.port
		if self.args.webui:
			self.webui = self.args.webui
		if self.args.cleardefaults:
			# clear saved defaults
			if 'username' in self.prefs:
				del self.prefs['username']
			if 'password' in self.prefs:
				del self.prefs['password']
			if 'webui' in self.prefs:
				del self.prefs['webui']
			if 'bindui' in self.prefs:
				del self.prefs['bindui']
			if 'portui' in self.prefs:
				del self.prefs['portui']
			self.save_prefs()
			raise BtSyncAgentException(0, _('Default settings cleared.'))
		if self.args.savedefaults:
			# save new defaults
			if self.args.username is not None:
				self.set_pref('username',self.username)
#			else:
#				raise BtSyncAgentException(-1,
#					'Username must be specified when saving defaults')
			if self.args.password is not None:
				self.set_pref('password',self.password)
#			else:
#				raise BtSyncAgentException(-1,
#					'Password must be specified when saving defaults')
			if self.args.bindui is not None:
				# changed bind address for web ui
				self.set_pref('bindui',self.bindui)
			if self.args.port != 0:
				# changed bind port for web ui
				self.set_pref('portui',self.portui)
			if self.args.webui:
				self.set_pref('webui',self.args.webui)
			raise BtSyncAgentException(0, _('Default settings saved.'))
		# initialize btsync api
		self.set_connection_params(
			host = self.get_host(), port = self.get_port(),
			username = self.get_username(), password = self.get_password()
		)
		if self.is_auto():
			self.lock = BtSingleton(self.lockfile,'btsync-gui')
Ejemplo n.º 4
0
    def __init__(self, args):
        BtSyncApi.__init__(self)
        self.args = args
        self.uid = int(os.getuid())
        self.pid = None
        self.configpath = os.environ['HOME'] + '/.config/btsync'
        self.storagepath = os.environ['HOME'] + '/.btsync'
        self.pidfile = self.configpath + '/btsync-agent.pid'
        self.conffile = self.configpath + '/btsync-agent.conf'
        self.preffile = self.configpath + '/btsync-gui.prefs'
        self.lockfile = self.configpath + '/btsync-gui.pid'
        self.lock = None
        self.prefs = {}
        # load values from preferences
        self.load_prefs()
        # generate random credentials
        try:
            username = base64.b64encode(os.urandom(16))[:-2]
            password = base64.b64encode(os.urandom(32))[:-2]
        except NotImplementedError:
            logging.warning(
                'No good random generator available. Using default credentials'
            )
            username = '******'
            password = base64.b64encode('This is really not secure!')[:-2]
        self.username = self.get_pref('username', username)
        self.password = self.get_pref('password', password)
        self.bindui = self.get_pref('bindui', '127.0.0.1')
        self.portui = self.get_pref('portui', self.uid + 8999)
        self.paused = self.get_pref('paused', False)
        self.webui = self.get_pref('webui', False)
        # process command line arguments
        if self.args.username is not None:
            self.username = self.args.username
        if self.args.password is not None:
            self.password = self.args.password
        if self.args.bindui is not None:
            self.bindui = '0.0.0.0' if self.args.bindui == 'auto' else self.args.bindui
        if self.args.port != 0:
            self.portui = self.args.port
        if self.args.webui:
            self.webui = self.args.webui
        if self.args.cleardefaults:
            # clear saved defaults
            if 'username' in self.prefs:
                del self.prefs['username']
            if 'password' in self.prefs:
                del self.prefs['password']
            if 'webui' in self.prefs:
                del self.prefs['webui']
            if 'bindui' in self.prefs:
                del self.prefs['bindui']
            if 'portui' in self.prefs:
                del self.prefs['portui']
            self.save_prefs()
            raise BtSyncAgentException(0, _('Default settings cleared.'))
        if self.args.savedefaults:
            # save new defaults
            if self.args.username is not None:
                self.set_pref('username', self.username)
#			else:
#				raise BtSyncAgentException(-1,
#					'Username must be specified when saving defaults')
            if self.args.password is not None:
                self.set_pref('password', self.password)
#			else:
#				raise BtSyncAgentException(-1,
#					'Password must be specified when saving defaults')
            if self.args.bindui is not None:
                # changed bind address for web ui
                self.set_pref('bindui', self.bindui)
            if self.args.port != 0:
                # changed bind port for web ui
                self.set_pref('portui', self.portui)
            if self.args.webui:
                self.set_pref('webui', self.args.webui)
            raise BtSyncAgentException(0, _('Default settings saved.'))
        # initialize btsync api
        self.set_connection_params(host=self.get_host(),
                                   port=self.get_port(),
                                   username=self.get_username(),
                                   password=self.get_password())
        if self.is_auto():
            self.lock = BtSingleton(self.lockfile, 'btsync-gui')