示例#1
0
def main(argv):
    """
    Run the program.
    """

    # Set up logging. See the logging module docs.
    logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)

    # Parse command-line arguments. Make sure to give our docstring as program
    # help.
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument("configFile",
                        type=argparse.FileType("r"),
                        help="configuration file of hosts to read")
    parser.add_argument("--noWait",
                        action="store_true",
                        help="look up dynamic peers once and exit")

    # Parse all the command-line arguments
    options = parser.parse_args(argv[1:])

    # Now we can load the config file. It is now required.

    # Maker a new parser to parse the config file
    parsedConfig = ConfigParser.SafeConfigParser()

    # Be case sensitive
    parsedConfig.optionxform = str

    # Read the config from the file
    parsedConfig.readfp(options.configFile)

    # Connect to the router
    cjdns = connectWithAdminInfo()

    # Make a new watcher on that connection, with the config from the config
    # file. This automatically looks up all the peers and tries to connect to
    # them once.
    watcher = DynamicEndpointWatcher(cjdns, parsedConfig)

    if options.noWait or os.environ.get('nowait', False):
        # We're not supposed to wait. Quit while we're ahead
        sys.exit(0)
    else:
        # Monitor for unresponsive nodes. This will loop until cjdns restarts,
        # at which point it will keep looping but won't actually work anymore.
        watcher.run()
示例#2
0
def main(argv):
  options, remainder = parse(argv)
  transform = lambda s: s
  connect = lambda : cjdnsadmin.connectWithAdminInfo()

  for opt, arg in options:
    if opt in ('-c', '--config'):
      connect = lambda :  cjdnsadmin.connectWithAdminInfo(arg)
    elif opt in ('-h', '--help'):
      usage()
      sys.exit(0)
    elif opt in ('-p', '--pretty'):
      transform = lambda s: json.dumps(s, sort_keys=True, indent=4, separators=(',', ': '))

  if remainder:
    try:
      s = connect()
    except FileNotFoundError: sys.exit(1)
    result = eval('s.' + ''.join(remainder))
    if result:
      print(transform(result))
  else:
    usage()
  return 0
示例#3
0
def main(argv):
    """
    Run the program.
    """

    # Set up logging. See the logging module docs.
    logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)

    # Parse command-line arguments. Make sure to give our docstring as program
    # help.
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument("configFile", type=argparse.FileType("r"), help="configuration file of hosts to read")
    parser.add_argument("--noWait", action="store_true", help="look up dynamic peers once and exit")

    # Parse all the command-line arguments
    options = parser.parse_args(argv[1:])

    # Now we can load the config file. It is now required.

    # Maker a new parser to parse the config file
    parsedConfig = ConfigParser.SafeConfigParser()

    # Be case sensitive
    parsedConfig.optionxform = str

    # Read the config from the file
    parsedConfig.readfp(options.configFile)

    # Connect to the router
    cjdns = connectWithAdminInfo()

    # Make a new watcher on that connection, with the config from the config
    # file. This automatically looks up all the peers and tries to connect to
    # them once.
    watcher = DynamicEndpointWatcher(cjdns, parsedConfig)

    if options.noWait or os.environ.get("nowait", False):
        # We're not supposed to wait. Quit while we're ahead
        sys.exit(0)
    else:
        # Monitor for unresponsive nodes. This will loop until cjdns restarts,
        # at which point it will keep looping but won't actually work anymore.
        watcher.run()
示例#4
0
def main(argv):
    """
    Run the program.
    """

    # Set up logging. See the logging module docs.
    logging.basicConfig(format="[%(asctime)s] %(levelname)s: %(message)s",
                        level=logging.INFO)

    # Parse command-line arguments. Make sure to give our docstring as program
    # help.
    parser = argparse.ArgumentParser(
        description=__doc__,
        formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument("configFile",
                        type=argparse.FileType("r"),
                        help="configuration file of hosts to read")
    parser.add_argument("--noWait",
                        action="store_true",
                        help="look up dynamic peers once and exit")
    parser.add_argument("--adminInfo",
                        help="use this file to load the cjdns admin password")

    # Parse all the command-line arguments
    options = parser.parse_args(argv[1:])

    while True:
        try:
            # Connect to the router, using the specified admin info file, if
            # given.
            cjdns = connectWithAdminInfo(path=options.adminInfo)
            break
        except socket.error:
            # Connection probably refused. Retry in a bit
            logging.error("Error connecting to cjdns. Retrying in 1 minute...")
            time.sleep(60)

    # Drop root if we have it. We can't do it before we load the admin info
    # file, for the use case where that file is root-only.
    try:

        # Switch group to nogroup
        os.setgid(grp.getgrnam("nogroup").gr_gid)
        # Switch user to nobody
        os.setuid(pwd.getpwnam("nobody").pw_uid)

        # Announce we dropped privs
        logging.info("Dropped privileges: running as {}:{}".format(
            pwd.getpwuid(os.getuid())[0],
            grp.getgrgid(os.getgid())[0]))
    except (OSError, KeyError):
        # Complain we couldn't drop privs right
        logging.warning("Could not drop privileges: running as {}:{}".format(
            pwd.getpwuid(os.getuid())[0],
            grp.getgrgid(os.getgid())[0]))

    # Now we can load the config file. It is now required.

    # Maker a new parser to parse the config file
    parsedConfig = ConfigParser.SafeConfigParser()

    # Be case sensitive
    parsedConfig.optionxform = str

    # Read the config from the file
    parsedConfig.readfp(options.configFile)

    # Make a new watcher on the cjdroute connection, with the config from the
    # config file. This automatically looks up all the peers and tries to
    # connect to them once.
    watcher = DynamicEndpointWatcher(cjdns, parsedConfig)

    if options.noWait or os.environ.get('nowait', False):
        # We're not supposed to wait. Quit while we're ahead
        sys.exit(0)
    else:
        # Monitor for unresponsive nodes. This will loop until cjdns restarts,
        # at which point it will throw an exception.
        watcher.run()
示例#5
0
文件: pingAll.py 项目: CSRedRat/cjdns
# You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys;
from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;

cjdns = connectWithAdminInfo();
addresses = {};
allRoutes = [];

i = 0;
while True:
    table = cjdns.NodeStore_dumpTable(i);
    routes = table['routingTable'];
    allRoutes += routes;
    for entry in routes:
        if (entry['link'] != 0):
            addresses[entry['ip']] = entry['path'];
        #print entry['ip'] + '@' + entry['path'] + ' - ' + str(entry['link']);
    if (not 'more' in table):
        break;
    i += 1;
示例#6
0
文件: pingAll.py 项目: worr/cjdns
# You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import sys;
from cjdnsadmin.cjdnsadmin import connectWithAdminInfo;

cjdns = connectWithAdminInfo();
allRoutes = [];

magicalLinkConstant = 5366870.0;

def pingNode(addr, path, link):
    addrAtPath = addr + '@' + path;
    result = cjdns.RouterModule_pingNode(path, 2000);
    res = '';
    if ('result' in result): res = result['result'];

    if (res == 'pong'):
        if (addrAtPath != result['from']): addrAtPath += ' mismatch ' + result['from'];
        print(addrAtPath +
            ' link ' + str(link) +
            ' proto ' + str(result['protocol']) +
示例#7
0
#!/usr/bin/python3
# You may redistribute this program and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

import sys
import os
from cjdnsadmin import cjdnsadmin

s = cjdnsadmin.connectWithAdminInfo()

print("Interactive cjdns admin shell.")
print("Usage: `s.command()`. 's' for Session.")
print("Try s.ping() or s.functions() to start.")
print("Ctrl-D to exit.")
示例#8
0
def main(argv):
    """
    Run the program.
    """

    # Set up logging. See the logging module docs.
    logging.basicConfig(format="[%(asctime)s] %(levelname)s: %(message)s", level=logging.INFO)

    # Parse command-line arguments. Make sure to give our docstring as program
    # help.
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)

    parser.add_argument("configFile", type=argparse.FileType("r"), help="configuration file of hosts to read")
    parser.add_argument("--noWait", action="store_true", help="look up dynamic peers once and exit")
    parser.add_argument("--adminInfo", help="use this file to load the cjdns admin password")

    # Parse all the command-line arguments
    options = parser.parse_args(argv[1:])

    while True:
        try:
            # Connect to the router, using the specified admin info file, if
            # given.
            cjdns = connectWithAdminInfo(path=options.adminInfo)
            break
        except socket.error:
            # Connection probably refused. Retry in a bit
            logging.error("Error connecting to cjdns. Retrying in 1 minute...")
            time.sleep(60)

    # Drop root if we have it. We can't do it before we load the admin info
    # file, for the use case where that file is root-only.
    try:

        # Switch group to nogroup
        os.setgid(grp.getgrnam("nogroup").gr_gid)
        # Switch user to nobody
        os.setuid(pwd.getpwnam("nobody").pw_uid)

        # Announce we dropped privs
        logging.info(
            "Dropped privileges: running as {}:{}".format(pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0])
        )
    except OSError:
        # Complain we couldn't drop privs right
        logging.warning(
            "Could not drop privileges: running as {}:{}".format(
                pwd.getpwuid(os.getuid())[0], grp.getgrgid(os.getgid())[0]
            )
        )

    # Now we can load the config file. It is now required.

    # Maker a new parser to parse the config file
    parsedConfig = ConfigParser.SafeConfigParser()

    # Be case sensitive
    parsedConfig.optionxform = str

    # Read the config from the file
    parsedConfig.readfp(options.configFile)

    # Make a new watcher on the cjdroute connection, with the config from the
    # config file. This automatically looks up all the peers and tries to
    # connect to them once.
    watcher = DynamicEndpointWatcher(cjdns, parsedConfig)

    if options.noWait or os.environ.get("nowait", False):
        # We're not supposed to wait. Quit while we're ahead
        sys.exit(0)
    else:
        # Monitor for unresponsive nodes. This will loop until cjdns restarts,
        # at which point it will throw an exception.
        watcher.run()