Example #1
0
def _get_rcfile(devname=None):
    if devname is None or str(devname) == socketlib.getfqdn():  # myself
        rcfile = RCCONF
    else:
        rcfile = os.path.join(os.environ["PYNMS_HOME"], "etc", "rc_conf.d", str(devname).replace(".", "_"))
    if os.path.isfile(rcfile):
        return rcfile
    else:
        print >> sys.stderr, "rcconfig: I don't see the file %s" % (rcfile,)
        return None
Example #2
0
def _get_rcfile(devname=None):
    if devname is None or str(devname) == socketlib.getfqdn():  # myself
        rcfile = RCCONF
    else:
        rcfile = os.path.join(os.environ["PYNMS_HOME"], "etc", "rc_conf.d",
                              str(devname).replace(".", "_"))
    if os.path.isfile(rcfile):
        return rcfile
    else:
        print >> sys.stderr, "rcconfig: I don't see the file %s" % (rcfile, )
        return None
Example #3
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)