예제 #1
0
def setup_config():
    if not os.path.exists(config._configfile):
        # this is the default config, it will be overwritten if a config file already exists. Else, it saves it
        conf_data = readstatic.read_static('default_config.json', ret_bin=False)
        config.set_config(json.loads(conf_data))

        config.save()

    config.reload()

    settings = 0b000
    if config.get('log.console.color', True):
        settings = settings | USE_ANSI
    if config.get('log.console.output', True):
        settings = settings | OUTPUT_TO_CONSOLE
    if config.get('log.file.output', True):
        settings = settings | OUTPUT_TO_FILE
    set_settings(settings)

    verbosity = str(config.get('log.verbosity', 'default')).lower().strip()
    if not verbosity in ['default', 'null', 'none', 'nil']:
        map = {
            str(LEVEL_DEBUG) : LEVEL_DEBUG,
            'verbose' : LEVEL_DEBUG,
            'debug' : LEVEL_DEBUG,
            str(LEVEL_INFO) : LEVEL_INFO,
            'info' : LEVEL_INFO,
            'information' : LEVEL_INFO,
            str(LEVEL_WARN) : LEVEL_WARN,
            'warn' : LEVEL_WARN,
            'warning' : LEVEL_WARN,
            'warnings' : LEVEL_WARN,
            str(LEVEL_ERROR) : LEVEL_ERROR,
            'err' : LEVEL_ERROR,
            'error' : LEVEL_ERROR,
            'errors' : LEVEL_ERROR,
            str(LEVEL_FATAL) : LEVEL_FATAL,
            'fatal' : LEVEL_FATAL,
            str(LEVEL_IMPORTANT) : LEVEL_IMPORTANT,
            'silent' : LEVEL_IMPORTANT,
            'quiet' : LEVEL_IMPORTANT,
            'important' : LEVEL_IMPORTANT
        }

        if verbosity in map:
            set_level(map[verbosity])
        else:
            logger.warn('Verbosity level %s is not valid, using default verbosity.' % verbosity)

    if type(config.get('client.webpassword')) is type(None):
        config.set('client.webpassword', base64.b16encode(os.urandom(32)).decode('utf-8'), savefile=True)
    if type(config.get('client.client.port')) is type(None):
        randomPort = netcontroller.get_open_port()
        config.set('client.client.port', randomPort, savefile=True)
    if type(config.get('client.public.port')) is type(None):
        randomPort = netcontroller.get_open_port()
        config.set('client.public.port', randomPort, savefile=True)
    if type(config.get('client.api_version')) is type(None):
        config.set('client.api_version', onionrvalues.API_VERSION, savefile=True)
예제 #2
0
from utils import readstatic, gettransports
from coredb import keydb
"""
    This program is free software: you can redistribute it 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/>.
"""

bootstrap_peers = readstatic.read_static('bootstrap-nodes.txt').split(',')


def add_bootstrap_list_to_peer_list(kv, peerList, db_only=False):
    """Add the bootstrap list to the peer list (no duplicates)."""
    for i in bootstrap_peers:
        # Add bootstrap peers to peerList (does not save them)
        # Don't add them if they're already added or in the offline list
        if i not in peerList and i not in kv.get('offlinePeers') \
                and i not in gettransports.get() and len(str(i).strip()) > 0:
            if not db_only:
                peerList.append(i)
            keydb.addkeys.add_address(i)
예제 #3
0
 def test_default_file(self):
     json.loads(readstatic.read_static('default_config.json'))
예제 #4
0
def _load_from_files(file_list: list)->str:
    """Loads multiple static dir files and returns them in combined string format (non-binary)"""
    combo_data = ''
    for f in file_list:
        combo_data += readstatic.read_static('www/shared/main/themes/' + f)
    return combo_data