Beispiel #1
0
	def rm(self, domains, force=False):
		do = Domain(self.dburi, self.db)
		da = Domain_attrs(self.dburi, self.db)
		ur = Uri(self.dburi, self.db)
		cr = Cred(self.dburi, self.db)
		domains = uniq(domains)

		doms = []
		for d in domains:
			try:
				did = do.get_did(d)
			except:
				if not force:
					raise Error (ENODOMAIN, d)
			doms.append((did, d))

		for i, d in doms:
			try:
				ur.rm_did(i, force=force)
			except:
				pass
			try:
				cr.rm_realm(d, force=force)
			except:
				pass
			do.rm(i, d, force=force)

		do.purge()
		ur.purge()
		cr.purge()
		da.purge()
		self._reload()
Beispiel #2
0
	def rm(self, aliases, force=False):
		ur = Uri(self.dburi, self.db)

		aliases = uniq(aliases)
		for a in aliases:
			if not ur.exist_uri(a) and not force:
				raise Error (ENOREC, a)

		for a in aliases:
			try:
				ur.rm_uri(a, force=force)
			except Error, inst:
				warning(str(inst))
Beispiel #3
0
	def rm(self, uri, idtype=ID_URI, force=False):
		us = User(self.dburi, self.db)
		ur = Uri(self.dburi, self.db)
		cr = Cred(self.dburi, self.db)
		try:
			uid = ur.get_uid(uri)
		except:
			if force: return
			raise
		try:
			ur.rm_uid(uid, force=force)
		except Error:
			pass
		try:
			cr.rm_uid(uid, force=force)
		except Error:
			pass
		try:
			us.rm(uid, force=force)
		except Error:
			pass
		us.purge()
		ur.purge()
		cr.purge()
		self._reload()
Beispiel #4
0
def usrloc(command, uri, contact=None, *args, **opts):
	ad, al = arg_attrs(args)
	table = opts['UL_TABLE']
	q = float(ad.get('q', 1))
	expires = ad.get('expires')
	if expires is not None:
		expires = int(expires)
	flags = ad.get('flags')
	if flags is not None:
		flags = int(flags)

	# LB hack
	if opts['SER_URI'][:4] == 'http':
		ur = Uri(opts['DB_URI'])
		curi = ur.canonize(uri)
		del(ur)
		if opts['SER_URI'][-1:] != '/':
			opts['SER_URI'] = opts['SER_URI'] + '/'
		opts['SER_URI'] = opts['SER_URI'] + 'sip:' + curi

	cmd = CMD.get(command)
	if cmd == CMD_ADD:
		if contact is None:
			raise Error (ENOARG, 'contact')
		u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts))
		u.add(uri, contact, table, expires, q, flags)
	elif cmd == CMD_RM:
		u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts))
		u.rm(uri, contact, table)
	elif cmd == CMD_SHOW:
		cols, numeric, limit, rsep, lsep, astab = show_opts(opts)
		u = Usrloc_ctl(opts['DB_URI'], any_rpc(opts))
		ret = u.show(uri, table)
		if type(ret) == dict:	# FIX: Is this a bug in usrloc SER code?
			ret = [ret]
		ret = [ (str(i['contact']), str(i['expires']), str(i['q'])) for i in ret ]
		desc = (('contact',), ('expires',), ('q',))
		tabprint(ret, desc, rsep, lsep, astab)
	else:
		raise Error (EINVAL, command)
Beispiel #5
0
	def add(self, uri, aliases, force=False):
		do = Domain(self.dburi, self.db)
		ur = Uri(self.dburi, self.db)
		us = User(self.dburi, self.db)

		try:
			uid = ur.get_uid(uri)
		except:
			if force: return
			raise
		try:
			user, did = ur.uri2id(uri)
		except:
			if force: return
			raise

		if not us.exist(uid):
			if force: return
			raise Error (ENOUSER, user)

		aliases = uniq(aliases)
		try:
			n = aliases.index(uri)
			aliases = aliases[:n] + aliases[n+1:]
		except:
			pass

		for a in aliases:
			if ur.exist_uri(a) and not force:
				raise Error (EDUPL, a)
			u, d =  split_sip_uri(a)
			if not do.exist_domain(d) and not force:
				raise Error (ENODOMAIN, d)
		
		for a in aliases:
			try:
				ur.add(uid, a, force=force)
			except Error, inst:
				warning(str(inst))
Beispiel #6
0
	def _get_uid(self, uri):
		ur = Uri(self.dburi, self.db)
		uid = ur.get_uid(uri)
		return uid
Beispiel #7
0
	def add(self, uri, aliases, password, idtype=ID_URI, force=False):
		do = Domain(self.dburi, self.db)
		da = Domain_attrs(self.dburi, self.db)
		ur = Uri(self.dburi, self.db)
		cr = Cred(self.dburi, self.db)
		us = User(self.dburi, self.db)

		user, domain = split_sip_uri(uri)
		aliases = uniq(aliases)
		try:
			n = aliases.index(uri)
			aliases = aliases[:n] + aliases[n+1:]
		except:
			pass
		aliases = [ split_sip_uri(a) for a in aliases ]

		uid = id(user + '@' + domain, idtype)
		if us.exist(uid):
			if not force:
				raise Error (EDUPL, errstr(uid=uid))
		if cr.exist(user, domain):
			if not force:
				raise Error (EDUPL, errstr(auth_username=user, domain=domain))
		if not do.exist_domain(domain):
			if force:
				i = id(domain, idtype)
				do.add(i, domain, force=force)
			else:
				raise Error (ENODOMAIN, domain)
		did = do.get_did(domain)
		try:
			realm = da.get(did, 'digest_realm')
		except:
			if force:
				realm = domain
			else:
				raise
		for u, d in aliases:
			if not do.exist_domain(d):
				if force:
					i = id(d, idtype)
					do.add(i, d, force=force)
				else:
					raise Error (ENODOMAIN, d)
			did = do.get_did(d)
			if ur.exist_username_did(u, did) and not force:
				raise Error (EDUPL, '%s@%s' % (u, d))
		did = do.get_did(domain)
		if ur.exist(uid, user, did):
			if not force:
				raise Error(EDUPL, errstr(uid=uid, username=user, did=did))

		us.add(uid, force=force)
		cr.add(uid, user, did, realm, password, force=force)
		ur.add(uid, uri, force=force)
		for u, d in aliases:
			uri = '%s@%s' % (u, d)
			try:
				ur.add(uid, uri, force=force)
			except Error, inst:
				warning(str(inst))
Beispiel #8
0
	def show(self, uri, cols=None, fformat=False, limit=0):
		ur = Uri(self.dburi, self.db)
		us = User(self.dburi, self.db)
		ua = User_attrs(self.dburi, self.db)
		do = Domain(self.dburi, self.db)
		cr = Cred(self.dburi, self.db)
		try:
			uids = ur.get_uids(uri)
		except:
			try:
				uids = ur.get_uids_for_username(uri)
			except:
				try:
					uids = us.get(uri)
				except:
					u, d = split_sip_uri(uri)
					try:
						uids = [cr.get_uid(u, d)]
					except:
						try:
							uids = cr.get_uids_for_username(u)
						except:
							try:
								uids = cr.get_uids_for_username(uri)
							except:
								uids = []

		dids = []

		# get uris
		uris = []
		for uid in uids:
			u, d = ur.show_uid(uid, ['uid', 'username', 'did'], fformat=fformat, limit=limit)
			uris += u
		for row in uris:
			dids.append(row[2])

		# get credentials
		creds = []
		for uid in uids:
			u, d = cr.show_uid(uid, ['uid', 'auth_username', 'realm', 'password'], fformat=fformat, limit=limit)
			creds += u
		for row in creds:
			try:
				did = do.get_did(row[2])
			except:
				continue
			dids.append(did)
	
		dids = uniq(dids)
		domains = {}
		for did in dids:
			try:
				dom = do.get_domain(did)
			except:
				continue
			domains[did] = dom

		attrs = {}
		for uid in uids:
			ce = cond(CND_NO_DELETED, uid=uid)
			rows = ua.show_cnd(ce, ['name', 'value'], fformat, limit)[0]
			line = []
			for row in rows:
				line.append('%s=%s' % tuple(row))
			attrs[uid] = ', '.join(line)

		# show
		desc = [('uid',), ('source',), ('value',)]
		ret  = [] 
		for u in uris:
			dom = domains.get(u[2])
			uri = '%s@%s' % (u[1], dom)
			uid = u[0]
			ret.append([uid, 'uri', uri ])
		for c in creds:
			cred = 'username=%s realm=%s password=%s' % (c[1], c[2], c[3])
			uid = c[0]
			ret.append([uid, 'credentials', cred ])
		for uid, attr in attrs.items():
			ret.append([uid, 'attr', attr ])

		# limit output
		if limit > 0:
			ret = ret[:limit]
		return ret, desc