Example #1
0
def killall(lhost=None):
	import socketlib
	import proctools
	if lhost is None or socketlib.islocal(lhost):
		proctools.killall("redir")
	else:
		import sshlib
		sshlib.ssh_command(lhost, "killall redir")
Example #2
0
def start_redir(lhost=None, lport=25, cport=9025):
	"""start_redir(lhost=None, lport=25, cport=9025)
Starts the redir program in such a way as to ensure that whatever
listening port is specified, local or remote, connections get to the
cport on the host where this is run. If remote execution is necessary
then SSH will be used.	lhost defaults to localhost."""
	import socketlib
	if lhost is None:
		lhost = socketlib.getfqdn()
	if socketlib.check_port(lhost, lport):
		raise RuntimeError, "something is already listening on (%r, %r)" % (lhost, lport)
	if socketlib.islocal(lhost):
		if perm_check():
			return redir(lport, cport)
		else:
			raise RuntimeError, "cannot run redir as non-root. check suid bit."
	else:
		myself = socketlib.getfqdn()
		# for this to work it assumes a lot...
		# 1. ssh is configured for public-key authentication (no
		# password).
		# 2. redir exists and is on the PATH on the remote host.
		# 3. redir is suid-root on the host.
		return remote_redir(lhost, lport, cport, caddr=myself)