예제 #1
0
 def __init__(self):
     """
     Loads session defaults from the 'controller.ini' configuration file.
     """
     self.__conf_file = FsTools.get_config_file('controller.ini')
     config = configparser.ConfigParser()
     config.read(self.__conf_file)
     config_changed = False
     if not 'SessionManagement' in config.sections():
         config.add_section('SessionManagement')
         config.set('SessionManagement', 'max_age_seconds', '86400')
         config.set('SessionManagement', 'max_inactivity', '3600')
         config_changed = True
     if config_changed:
         with open(self.__conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
             config_changed = False
     if not 'max_age_seconds' in config['SessionManagement']:
         config.set('SessionManagement', 'max_age_seconds', '86400')
         config_changed = True
     if not 'max_inactivity' in config['SessionManagement']:
         config.set('SessionManagement', 'max_inactivity', '3600')
         config_changed = True
     if config_changed:
         with open(self.__conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
     self.__config = config
     self.__session_max_age = float(self.__config['SessionManagement']['max_age_seconds'])
     self.__session_max_inactivity = float(self.__config['SessionManagement']['max_inactivity'])
     self.__user_manager = UserManager()
     self.__sessions = dict()
예제 #2
0
    def __init__(self):
        """
        Load the user basic configuration from the users.ini file.

        :raise IOError: When there can be no users.ini can be loaded or created.
        """
        self.__conf_file = FsTools.get_config_file('users.ini')
        config = configparser.ConfigParser()
        config.read(self.__conf_file)
        config_changed = False
        if not '_Config_' in config.sections():
            config.add_section('_Config_')
            config.set('_Config_', 'secret', create_salt())
            config_changed = True
        if config_changed:
            with open(self.__conf_file, 'w') as fh:
                config.write(fh)
                fh.flush()
                fh.close()
                config_changed = False
        if not 'secret' in config['_Config_']:
            config.set('_Config_', 'secret', create_salt())
            config_changed = True
        if config_changed:
            with open(self.__conf_file, 'w') as fh:
                config.write(fh)
                fh.flush()
                fh.close()
                config_changed = False
        if len(config.sections()) < 1:
            raise IOError('Invalid configuration in "{:s}"'.format(
                self.__conf_file))
        self.secret = config['_Config_']['secret']
        if len(config.sections()) == 1:
            # No std user!
            config.add_section('User:arobito')
            config.set('User:arobito', 'level', 'Administrator')
            salt = create_salt()
            config.set('User:arobito', 'salt', salt)
            config.set('User:arobito', 'password',
                       hash_password('arobito', salt=salt, secret=self.secret))
            config.set('User:arobito', 'enabled', 'yes')
            config_changed = True
        if config_changed:
            with open(self.__conf_file, 'w') as fh:
                config.write(fh)
                fh.flush()
                fh.close()
        self.__config = config
예제 #3
0
    def __init__(self):
        """
        Load the user basic configuration from the users.ini file.

        :raise IOError: When there can be no users.ini can be loaded or created.
        """
        self.__conf_file = FsTools.get_config_file('users.ini')
        config = configparser.ConfigParser()
        config.read(self.__conf_file)
        config_changed = False
        if not '_Config_' in config.sections():
            config.add_section('_Config_')
            config.set('_Config_', 'secret', create_salt())
            config_changed = True
        if config_changed:
            with open(self.__conf_file, 'w') as fh:
                config.write(fh)
                fh.flush()
                fh.close()
                config_changed = False
        if not 'secret' in config['_Config_']:
            config.set('_Config_', 'secret', create_salt())
            config_changed = True
        if config_changed:
            with open(self.__conf_file, 'w') as fh:
                config.write(fh)
                fh.flush()
                fh.close()
                config_changed = False
        if len(config.sections()) < 1:
            raise IOError('Invalid configuration in "{:s}"'.format(self.__conf_file))
        self.secret = config['_Config_']['secret']
        if len(config.sections()) == 1:
            # No std user!
            config.add_section('User:arobito')
            config.set('User:arobito', 'level', 'Administrator')
            salt = create_salt()
            config.set('User:arobito', 'salt', salt)
            config.set('User:arobito', 'password', hash_password('arobito', salt=salt, secret=self.secret))
            config.set('User:arobito', 'enabled', 'yes')
            config_changed = True
        if config_changed:
            with open(self.__conf_file, 'w') as fh:
                config.write(fh)
                fh.flush()
                fh.close()
        self.__config = config
예제 #4
0
 def __init__(self):
     """
     Look in the config file 'controller.ini' for the folder with the static contents to serve.
     """
     self.conf_file = FsTools.get_config_file('controller.ini')
     config = configparser.ConfigParser()
     config.read(self.conf_file)
     config_changed = False
     if not 'Server' in config.sections():
         config.add_section('Server')
         config.set('Server', 'static-folder',
                    path.join(find_root_path(), 'web-static'))
         config_changed = True
     if config_changed:
         with open(self.conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
             config_changed = False
     if not 'static-folder' in config['Server']:
         config.set('Server', 'static-folder',
                    path.join(find_root_path(), 'web-static'))
         config_changed = True
     if config_changed:
         with open(self.conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
             config_changed = True
     static_folder = config.get('Server', 'static-folder')
     if static_folder is None or len(static_folder) <= 0:
         config.set('Server', 'static-folder',
                    path.join(find_root_path(), 'web-static'))
         config_changed = True
     if config_changed:
         with open(self.conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
     static_folder = config.get('Server', 'static-folder')
     self.root_dir = static_folder
예제 #5
0
 def __init__(self):
     """
     Look in the config file 'controller.ini' for the folder with the static contents to serve.
     """
     self.conf_file = FsTools.get_config_file('controller.ini')
     config = configparser.ConfigParser()
     config.read(self.conf_file)
     config_changed = False
     if not 'Server' in config.sections():
         config.add_section('Server')
         config.set('Server', 'static-folder', path.join(find_root_path(), 'web-static'))
         config_changed = True
     if config_changed:
         with open(self.conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
             config_changed = False
     if not 'static-folder' in config['Server']:
         config.set('Server', 'static-folder', path.join(find_root_path(), 'web-static'))
         config_changed = True
     if config_changed:
         with open(self.conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
             config_changed = True
     static_folder = config.get('Server', 'static-folder')
     if static_folder is None or len(static_folder) <= 0:
         config.set('Server', 'static-folder', path.join(find_root_path(), 'web-static'))
         config_changed = True
     if config_changed:
         with open(self.conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
     static_folder = config.get('Server', 'static-folder')
     self.root_dir = static_folder
예제 #6
0
 def __init__(self):
     """
     Loads session defaults from the 'controller.ini' configuration file.
     """
     self.__conf_file = FsTools.get_config_file('controller.ini')
     config = configparser.ConfigParser()
     config.read(self.__conf_file)
     config_changed = False
     if not 'SessionManagement' in config.sections():
         config.add_section('SessionManagement')
         config.set('SessionManagement', 'max_age_seconds', '86400')
         config.set('SessionManagement', 'max_inactivity', '3600')
         config_changed = True
     if config_changed:
         with open(self.__conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
             config_changed = False
     if not 'max_age_seconds' in config['SessionManagement']:
         config.set('SessionManagement', 'max_age_seconds', '86400')
         config_changed = True
     if not 'max_inactivity' in config['SessionManagement']:
         config.set('SessionManagement', 'max_inactivity', '3600')
         config_changed = True
     if config_changed:
         with open(self.__conf_file, 'w') as fh:
             config.write(fh)
             fh.flush()
             fh.close()
     self.__config = config
     self.__session_max_age = float(
         self.__config['SessionManagement']['max_age_seconds'])
     self.__session_max_inactivity = float(
         self.__config['SessionManagement']['max_inactivity'])
     self.__user_manager = UserManager()
     self.__sessions = dict()