Exemple #1
0
 def __init__(self):
     main_config_file = process.config_file(Config.config_file)
     if main_config_file is None:
         raise RuntimeError("Cannot find the radius configuration file: `%s'" % Config.config_file)
     try:
         config = dict(line.rstrip("\n").split(None, 1) for line in open(main_config_file) if len(line.split(None, 1)) == 2 and not line.startswith("#"))
         secrets = dict(line.rstrip("\n").split(None, 1) for line in open(config["servers"]) if len(line.split(None, 1)) == 2 and not line.startswith("#"))
         server = config["acctserver"]
         try:
             server, acctport = server.split(":")
             acctport = int(acctport)
         except ValueError:
             acctport = 1813
         secret = secrets[server]
         dicts = [RadiusDictionaryFile(config["dictionary"])]
         if Config.additional_dictionary:
             additional_dictionary = process.config_file(Config.additional_dictionary)
             if additional_dictionary:
                 dicts.append(RadiusDictionaryFile(additional_dictionary))
             else:
                 log.warn("Could not load additional RADIUS dictionary file: `%s'" % Config.additional_dictionary)
         raddict = pyrad.dictionary.Dictionary(*dicts)
         timeout = int(config["radius_timeout"])
         retries = int(config["radius_retries"])
     except Exception, e:
         log.fatal("cannot read the RADIUS configuration file")
         raise
def main():
    name = 'ip-streamer'
    fullname = 'IP Streamer v2'
    version = ipstreamer.__version__
    runtime_directory = '/var/run/ip-streamer'
    system_config_directory = '/etc/vice'
    default_pid = os.path.join(runtime_directory, 'server.pid')
    default_config = ipstreamer.cfg_filename if os.path.isfile(ipstreamer.cfg_filename) else os.path.join(system_config_directory, ipstreamer.cfg_filename)

    parser = argparse.ArgumentParser(description='VICE ip streamer to control mumudvb.')
    parser.add_argument('--version', action='version', version='%s %s' % (fullname, version))
    parser.add_argument('--no-fork', action='store_false', dest='fork', default=True, help='run the process in the foreground')
    parser.add_argument('-c', '--config-file', dest='config_file', default=default_config, help='configuration file', metavar='FILE')
    parser.add_argument('-p', '--pid', dest='pid_file', default=default_pid, help='PID file', metavar='FILE')
    parser.add_argument('-d', '--debug', help='Run in debug mode', action='store_true', default=False, dest='debug')
    args = parser.parse_args()
    debug = args.debug

    path, cfg_file = os.path.split(args.config_file)
    if path:
        system_config_directory = path

    process.system_config_directory = system_config_directory
    ipstreamer.cfg_filename = process.config_file(cfg_file)

    # when run in foreground, do not require root access because of PID file in /var/run
    if args.fork:
        try:
            process.runtime_directory = runtime_directory
            process.daemonize(args.pid_file)
        except ProcessError, e:
            log.fatal("Cannot start %s: %s" % (fullname, e))
            sys.exit(1)
        log.start_syslog(name)
Exemple #3
0
 def __init__(self):
     main_config_file = process.config_file(RadiusConfig.config_file)
     if main_config_file is None:
         raise RuntimeError(
             "Cannot find the radius configuration file: `%s'" %
             RadiusConfig.config_file)
     try:
         config = dict(
             line.rstrip("\n").split(None, 1)
             for line in open(main_config_file)
             if len(line.split(None, 1)) == 2 and not line.startswith("#"))
         secrets = dict(
             line.rstrip("\n").split(None, 1)
             for line in open(config["servers"])
             if len(line.split(None, 1)) == 2 and not line.startswith("#"))
         server = config["acctserver"]
         try:
             server, acctport = server.split(":")
             acctport = int(acctport)
         except ValueError:
             acctport = 1813
         secret = secrets[server]
         dicts = [RadiusDictionaryFile(config["dictionary"])]
         if RadiusConfig.additional_dictionary:
             additional_dictionary = process.config_file(
                 RadiusConfig.additional_dictionary)
             if additional_dictionary:
                 dicts.append(RadiusDictionaryFile(additional_dictionary))
             else:
                 log.warn(
                     "Could not load additional RADIUS dictionary file: `%s'"
                     % RadiusConfig.additional_dictionary)
         raddict = pyrad.dictionary.Dictionary(*dicts)
         timeout = int(config["radius_timeout"])
         retries = int(config["radius_retries"])
     except Exception:
         log.fatal("cannot read the RADIUS configuration file")
         raise
     pyrad.client.Client.__init__(self, server, 1812, acctport, secret,
                                  raddict)
     self.timeout = timeout
     self.retries = retries
     if "bindaddr" in config and config["bindaddr"] != "*":
         self.bind((config["bindaddr"], 0))
     EventQueue.__init__(self, self.do_accounting)
Exemple #4
0
def file_content(file):
    path = process.config_file(file)
    if path is None:
        raise Exception("File '%s' does not exist" % file)
    try:
        f = open(path, 'rt')
    except Exception:
        raise Exception("File '%s' could not be open" % file)
    try:
        return f.read()
    finally:
        f.close()
Exemple #5
0
def file_content(file):
    path = process.config_file(file)
    if path is None:
        raise _FileError("File '%s' does not exist" % file)
    try:
        f = open(path, 'rt')
    except Exception:
        raise _FileError("File '%s' could not be open" % file)
    try:
        return f.read()
    finally:
        f.close()
Exemple #6
0
 def get(self):
     path = process.config_file(self.path)
     if path is None:
         raise RuntimeError("missing or unreadable file: %s" % self.path)
     mtime = os.stat(path)[stat.ST_MTIME]
     if self.timestamp < mtime:
         f = open(path)
         try:
             self.object = self.klass(f.read())
             self.timestamp = mtime
         finally:
             f.close()
     return self.object
Exemple #7
0
 def get(self):
     path = process.config_file(self.path)
     if path is None:
         raise RuntimeError("missing or unreadable file: %s" % self.path)
     mtime = os.stat(path)[stat.ST_MTIME]
     if self.timestamp < mtime:
         f = open(path)
         try:
             self.object = self.klass(f.read())
             self.timestamp = mtime
         finally:
             f.close()
     return self.object
 def __new__(typ, value):
     if isinstance(value, basestring):
         path = process.config_file(value)
         if path is None:
             log.warn("Private key file '%s' is not readable" % value)
             return None
         try:
             f = open(path, 'rt')
         except:
             log.warn("Private key file '%s' could not be open" % value)
             return None
         try:
             try:
                 return crypto.load_privatekey(crypto.FILETYPE_PEM, f.read())
             except crypto.Error, e:
                 log.warn("Private key file '%s' could not be loaded: %s" % (value, str(e)))
                 return None
         finally:
             f.close()
     else:
         raise TypeError, 'value should be a string'
 def __new__(typ, value):
     if isinstance(value, basestring):
         path = process.config_file(value)
         if path is None:
             log.warn("Private key file '%s' is not readable" % value)
             return None
         try:
             f = open(path, 'rt')
         except:
             log.warn("Private key file '%s' could not be open" % value)
             return None
         try:
             try:
                 return crypto.load_privatekey(crypto.FILETYPE_PEM, f.read())
             except crypto.Error, e:
                 log.warn("Private key file '%s' could not be loaded: %s" % (value, str(e)))
                 return None
         finally:
             f.close()
     else:
         raise TypeError, 'value should be a string'