Exemplo n.º 1
0
#######################################
#
# App Configuration
#
#######################################

# In-case of issues resolving ASNs, OUR_ASN / LOCAL_IPs will be used as a fallback.
# This is useful in the case of Cisco route servers, as your own ASN will most likely be removed
# from the AS path of the route advertisement.
from lg.exceptions import IPNotFound

OUR_ASN = env('OUR_ASN', 210083)
OUR_ASN_NAME = env('OUR_ASN_NAME', 'Privex Inc.')

LOCAL_IPS = env_csv('LOCAL_IPS', ['185.130.44.0/22', '2a07:e00::/29'])
LOCAL_IPS = [ip_network(ip) for ip in LOCAL_IPS]

BLACKLIST_ROUTES = env_csv('BLACKLIST_ROUTES',
                           ['0.0.0.0/0', '::/0', '2000::/3'])
"""Ignore any route in this list"""

IX_RANGES = env_keyval('IX_RANGES', [
    ('SOL-IX STH', '193.110.13.0/24'),
    ('SOL-IX STH', '2001:7F8:21:9::/64'),
    ('SOL-IX STH (MTU 4470)', '2001:7F8:21:10::/64'),
    ('SOL-IX STH (MTU 4470)', '193.110.12.0/24'),
],
                       valsplit='|')
"""
To override the above subnets for exchanges, set the env var IX_RANGES in .env like so::
Exemplo n.º 2
0
    +===================================================+
"""
from decimal import Decimal
from beem.steem import Steem
from beem.instance import set_shared_steem_instance
# from bhive.hive import Hive
# from bhive.instance import set_shared_hive_instance
from getenv import env

#########
# Steem Network related settings
####
from privex.helpers import env_csv

# Supply a list of one or more comma-separated Steem RPC nodes. If not set, will use the default beem nodes.
STEEM_RPC_NODES = env_csv('STEEM_RPC_NODES', None)
# Supply a list of one or more comma-separated Steem RPC nodes. If not set, will use the default beem nodes.
HIVE_RPC_NODES = env_csv('HIVE_RPC_NODES', [
    'https://anyx.io', 'https://hived.privex.io',
    'https://hived.hive-engine.com'
])
# Set the shared Beem RPC instance to use the specified nodes
steem_ins = Steem(node=STEEM_RPC_NODES,
                  num_retries=5,
                  num_retries_call=3,
                  timeout=20)
steem_ins.set_password_storage(
    'environment')  # Get Beem wallet pass from env var ``UNLOCK``
set_shared_steem_instance(steem_ins)

# Set the shared Beem RPC instance to use the specified nodes
Exemplo n.º 3
0
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'gna*8lm&p4n_g*@^e3$%x-wdgy+kp&^8v#&r(7*sk4q06mz!t$'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

# Ignore the whitelist and allow CORS from anywhere
CORS_ORIGIN_ALLOW_ALL = env_bool('CORS_ORIGIN_ALLOW_ALL', True)
# A comma separated list of domains (must include each subdomain) that can send CORS requests
# This is ignored if you don't change CORS_ORIGIN_ALLOW_ALL to False.
CORS_ORIGIN_WHITELIST = env_csv('CORS_ORIGIN_WHITELIST', [])
# CORS_ORIGIN_WHITELIST = CORS_ORIGIN_WHITELIST.split(',') if CORS_ORIGIN_WHITELIST is not None else None

REST_FRAMEWORK = {
    'DEFAULT_FILTER_BACKENDS':
    ('django_filters.rest_framework.DjangoFilterBackend', )
}

EOS_NODE = env('EOS_NODE', 'https://eos.greymass.com')

EOS_START_TYPE = "relative"
"""
EOS_START_TYPE can be either ``"relative"`` (meaning EOS_START_BLOCK is relative to the head block),
or ``"exact"`` (meaning EOS_START_BLOCK specifies an exact block number to start from).

This only really matters for the first run, as once there are some blocks in the database, the sync tasks will
Exemplo n.º 4
0
import time
import asyncio
import logging

try:
    from rich import print
except ImportError:
    pass

log = logging.getLogger('privex.steem')
log.setLevel(logging.ERROR)

SECS_NS = Decimal('1000000000')

HIVE_NODES = env_csv('HIVE_NODES', [
    'https://direct.hived.privex.io', 'https://anyx.io',
    'https://api.deathwing.me'
])
BATCH_SIZE = env_int('BATCH_SIZE', 100)
NUM_BLOCKS = env_int('NUM_BLOCKS', 1000)


async def main():
    ss = SteemAsync(HIVE_NODES)
    ss.config_set('batch_size', BATCH_SIZE)
    print(
        f"\n [{datetime.utcnow()!s}] Loading last {NUM_BLOCKS} blocks using steem-async ... \n\n"
    )
    start_time = time.time_ns()
    blks = await ss.get_blocks(-NUM_BLOCKS)
    end_time = time.time_ns()
    print(f"\n [{datetime.utcnow()!s}] Total blocks:", len(blks), "\n")
Exemplo n.º 5
0
if SECRET_KEY is None:
    print('Critical ERROR: No SECRET_KEY set in .env! Cannot continue.')
    print('Please generate a secure random string used to encrypt sensitive data such as user sessions')
    print(
        f"Place the following line into the file {join(BASE_DIR, '.env')} - for production we "
        f"recommend generating it by hand."
    )
    print()
    print(f'SECRET_KEY={random_str(size=64)}')
    print()
    sys.exit()

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env_bool('DEBUG', False)

ALLOWED_HOSTS = env_csv('ALLOWED_HOSTS', ['*'])

if '*' in ALLOWED_HOSTS and not DEBUG:
    print("\n================================================================================================\n")
    print('WARNING: ALLOWED_HOSTS currently contains "*". You should configure ALLOWED_HOSTS in your .env')
    print("so that it's restricted to the domains / IPs you expect this app to be accessed from, e.g.\n")
    print("    ALLOWED_HOSTS=eos-history.example.com,eoshistory.example.net,1.2.3.4\n")
    print("\n================================================================================================\n")

# Ignore the whitelist and allow CORS from anywhere
CORS_ORIGIN_ALLOW_ALL = env_bool('CORS_ORIGIN_ALLOW_ALL', True)
# A comma separated list of domains (must include each subdomain) that can send CORS requests
# This is ignored if you don't change CORS_ORIGIN_ALLOW_ALL to False.
CORS_ORIGIN_WHITELIST = env_csv('CORS_ORIGIN_WHITELIST', [])
# CORS_ORIGIN_WHITELIST = CORS_ORIGIN_WHITELIST.split(',') if CORS_ORIGIN_WHITELIST is not None else None
Exemplo n.º 6
0
    You should have received a copy of the GNU Affero General Public License along with this program.
    If not, see <https://www.gnu.org/licenses/>.


"""
import logging
import dotenv
from os.path import dirname, abspath, join
from os import getenv as env
from privex.helpers import env_csv

dotenv.load_dotenv()

MOD_DIR = dirname(abspath(__file__))
BASE_DIR = dirname(MOD_DIR)

OUT_FOLDER = env('OUT_FOLDER', join(BASE_DIR, 'output'))
BUILD_FOLDER = env('BUILD_FOLDER', '/tmp')

BUILD_LIBS = env_csv('BUILD_LIBS', ['eosjs', 'scatterjs'])

# Valid environment log levels (from least to most severe) are:
# DEBUG, INFO, WARNING, ERROR, FATAL, CRITICAL
LOG_LEVEL = env('LOG_LEVEL', None)
LOG_LEVEL = logging.getLevelName(
    str(LOG_LEVEL).upper()) if LOG_LEVEL is not None else None

if LOG_LEVEL is None:
    LOG_LEVEL = logging.INFO
Exemplo n.º 7
0
"""Conversion fee taken by us, in percentage (i.e. "1" = 1%)"""

COIN_TYPES = (
    ('crypto', 'Generic Cryptocurrency',),
    ('token', 'Generic Token'),
)
"""This is used for the dropdown "Coin Type" selection in the Django admin panel. Coin handlers may add to this list."""

COIN_HANDLERS_BASE = env('COIN_HANDLERS_BASE', 'payments.coin_handlers')
"""Load coin handlers from this absolute module path"""

COIN_HANDLERS = env_csv('COIN_HANDLERS', [
    'SteemEngine',
    'Bitcoin',
    'Steem',
    'EOS',
    'Telos',
    'Bitshares',
    'Appics',
])
"""
Specify in the env var ``COIN_HANDERS`` a comma separated list of local coin handlers
:py:mod:`payments.coin_handlers` to load. If not specified, the default list will be used.
"""

PRIVEX_HANDLERS = env_csv('PRIVEX_HANDLERS', [
    'Golos'
])
"""
These handlers are from the :py:my:`privex.coin_handlers` package, so they're loaded differently to the
handlers listed in :py:attr:`.COIN_HANDLERS`
Exemplo n.º 8
0
    '[::1]',
    '[::1]:5000',
    f'[::1]:{PORT}',
    'localhost',
    f'localhost:{PORT}',
    'l.privex.io',
    '*.l.privex.io',
    f'l.privex.io:{PORT}',
    f'*.l.privex.io:{PORT}',
    f'l4.privex.io:{PORT}',
    f'*.l4.privex.io:{PORT}',
    f'l6.privex.io:{PORT}',
    f'*.l6.privex.io:{PORT}',
] if DEBUG else []

EXTRA_HOSTS = env_csv('EXTRA_HOSTS', ['myip.vc', 'address.computer'])
"""
Additional domains to use, alongside MAIN_HOST. They'll be added to ALLOWED_HOSTS, including the V4 and V6_SUBDOMAIN
"""

FORCE_MAIN_HOST = env_bool('FORCE_MAIN_HOST', DEBUG)
"""
When this is True, v4/v6_host in the template context will always use settings.V4_HOST and settings.V6_HOST,
instead of reading the host from the headers.
"""

CACHE_ADAPTER = env('CACHE_ADAPTER', None)
"""
This environment var controls which caching adapter is used to store any cached data from the app.

By default, it's set to ``None`` (empty) which results in the ``auto`` behaviour - trying redis, memcached, and then memory cache,
Exemplo n.º 9
0
# Logging Configuration
#######

CONSOLE_LOG_LEVEL = env('CONSOLE_LOG_LEVEL', 'DEBUG') if DEBUG else env('LOG_LEVEL', 'INFO')
CONSOLE_LOG_LEVEL = logging.getLevelName(CONSOLE_LOG_LEVEL.upper())
LOG_FORMATTER = logging.Formatter('[%(asctime)s]: %(name)-55s -> %(funcName)-20s : %(levelname)-8s:: %(message)s')

# Log messages equal/above the specified level to debug.log (default: DEBUG if debug enabled, otherwise INFO)
DBGFILE_LEVEL = env('DBGFILE_LEVEL', 'DEBUG') if DEBUG else env('LOG_LEVEL', 'INFO')
DBGFILE_LEVEL = logging.getLevelName(DBGFILE_LEVEL.upper())

# Log messages equal/above the specified level to error.log (default: WARNING)
ERRFILE_LEVEL = logging.getLevelName(env('ERRFILE_LEVEL', 'WARNING').upper())

# Use the same logging configuration for all privex modules
LOGGER_NAMES = env_csv('LOGGER_NAMES', ['historyapp', 'privex'])

# Main logger name
BASE_LOGGER = env('BASE_LOGGER_NAME', 'eoshistory')

# Output logs to respective files with automatic daily log rotation (up to 14 days of logs)
BASE_LOG_FOLDER = os.path.join(BASE_DIR, env('LOG_FOLDER', 'logs'))

# To make it easier to identify whether a log entry came from the web application, or from a cron (e.g. load_txs)
# we log to the sub-folder ``BASE_WEB_LOGS`` by default, and management commands such as load_txs will
# re-configure the logs to go to ``BASE_CRON_LOGS``
BASE_WEB_LOGS = os.path.join(BASE_LOG_FOLDER, env('BASE_WEB_LOGS', 'web'))
BASE_CRON_LOGS = os.path.join(BASE_LOG_FOLDER, env('BASE_CRON_LOGS', 'crons'))

#######
# End Logging Configuration
Exemplo n.º 10
0
import logging
import sys
from os import getenv as env, getcwd
from os.path import dirname, abspath, join, isabs, exists, expanduser, basename
from typing import Optional, List

from privex.helpers import env_bool, env_int, env_csv, env_cast, empty_if, empty
import dotenv

BASE_DIR = dirname(dirname(abspath(__file__)))

dotenv.load_dotenv()
dotenv.load_dotenv(join(BASE_DIR, '.env'))
dotenv.load_dotenv(join(getcwd(), '.env'))

SEARCH_PATHS = env_csv('SEARCH_PATHS', [getcwd(), BASE_DIR, '~', '/'])


def scan_paths(filename: str, search_dirs: List[str] = None) -> Optional[str]:
    search_dirs = empty_if(search_dirs, SEARCH_PATHS)
    for b in search_dirs:
        f = abspath(expanduser(join(b, filename)))
        if exists(f): return f
    return None


def find_parent(filename: str, rise=1, throw=True) -> Optional[str]:
    parent = dirname(filename)

    if isabs(parent):
        if exists(parent):
Exemplo n.º 11
0
# This is used for the dropdown "Coin Type" selection in the Django admin panel. Coin handlers may add to this list.
COIN_TYPES = (
    (
        'crypto',
        'Generic Cryptocurrency',
    ),
    ('token', 'Generic Token'),
)

# Load coin handlers from this absolute module path
COIN_HANDLERS_BASE = env('COIN_HANDLERS_BASE', 'payments.coin_handlers')
# A comma separated list of modules to load
COIN_HANDLERS = env_csv('COIN_HANDLERS', [
    'SteemEngine',
    'Bitcoin',
    'Steem',
    'EOS',
    'Bitshares',
    'Appics',
])

# After the first email to inform admins a wallet is low, how long before we send out a second notification?
# (in hours) (Default: 12 hrs)
LOWFUNDS_RENOTIFY = int(env('LOWFUNDS_RENOTIFY', 12))

#########
# Defaults for pre-installed Coin Handlers, to avoid potential exceptions when accessing their settings.
####

COIND_RPC = {
}  # Used by coin_handlers.Bitcoin if you don't want to store connection details in DB.
Exemplo n.º 12
0
LOG_LEVEL = env('LOG_LEVEL', None)
LOG_LEVEL = logging.getLevelName(
    str(LOG_LEVEL).upper()) if LOG_LEVEL is not None else None

if LOG_LEVEL is None:
    LOG_LEVEL = logging.DEBUG if DEBUG or verbose else logging.INFO
    LOG_LEVEL = logging.CRITICAL if quiet else LOG_LEVEL

RPC_TIMEOUT = env_int('RPC_TIMEOUT', 3)
MAX_TRIES = env_int('MAX_TRIES', 3)
RETRY_DELAY = env_cast('RETRY_DELAY', cast=float, env_default=2.0)
PUB_PREFIX = env(
    'PUB_PREFIX', 'STM'
)  # Used as part of the thorough plugin tests for checking correct keys are returned

TEST_PLUGINS_LIST = env_csv('TEST_PLUGIN_LIST', [])
"""
Controls which plugins are tested by :class:`.RPCScanner` when :attr:`rpcscanner.settings.plugins` is
set to ``True``.

If the TEST_PLUGINS_LIST is empty, it will be populated automatically when the module container :class:`.MethodTests`
is loaded, which will replace it with a tuple containing :attr:`rpcscanner.MethodTests.METHOD_MAP`.
"""

EXTRA_PLUGINS_LIST = env_csv('EXTRA_PLUGINS_LIST', [])
"""
Additional RPC methods to test - add to your ``.env`` as comma separated RPC method names.

Will be appended to ``TEST_PLUGIN_LIST``

Example ``.env`` entry::
Exemplo n.º 13
0
        sys.exit()
    print(" !!! WARNING !!! No SECRET_KEY has been set in .env")
    print(
        " !!! WARNING !!! As DEBUG is currently set to True, we'll use the default hardcoded development secret key"
    )
    print(
        " !!! WARNING !!! In production mode (DEBUG=False), please be warned that the application will refuse"
    )
    print(" !!! WARNING !!! to start unless you set SECRET_KEY correctly.")
    _suggest_secret()
    SECRET_KEY = "Th1sIsAPlaceH0lderS3cretK£yF@rDev3l0pm3ntPurpO$es"

# ALLOWED_HOSTS defines a list of hostnames/ips that this app can be accessed from
# In DEBUG, we add localhost/127.0.0.1 by default, as well as when ALLOWED_HOSTS isn't set in .env
# Specify allowed hosts in .env comma separated, e.g. ALLOWED_HOSTS=example.org,127.0.0.1,example.com
ALLOWED_HOSTS = env_csv('ALLOWED_HOSTS', ['pxe.privex.bz', 'pxe.privex.dev'])
ALLOWED_HOSTS += ['127.0.0.1', 'localhost'
                  ] if empty(ALLOWED_HOSTS, itr=True) or DEBUG else []

ADMINS = env_keyval('ADMINS', [
    ('Chris (Someguy123)', '*****@*****.**'),
    ('Kale', '*****@*****.**'),
])

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
Exemplo n.º 14
0
SEARCH_DIRS controls the order of paths to scan when loading an individual .pyre
file from the CLI

For convenience, the current working directory takes priority for SEARCH_DIRS
"""

# Load .env file (search through SEARCH_DIRS, BASE_DIR, as well as dotenv's auto finding)
for d in SEARCH_DIRS:
    dotenv.load_dotenv(join(d, '.env'))

dotenv.load_dotenv(join(BASE_DIR, '.env'))
dotenv.load_dotenv()

DEBUG = env_bool('DEBUG', False)

CONF_DIRS = env_csv('CONF_DIRS', CONF_DIRS)
SEARCH_DIRS = env_csv('SEARCH_DIRS', SEARCH_DIRS)

FILE_SUFFIX = env('FILE_SUFFIX', '.pyre')
IPT4_SUFFIX = env('IPT4_SUFFIX', '.v4')
IPT6_SUFFIX = env('IPT6_SUFFIX', '.v6')

SEARCH_EXTENSIONS = env_csv('SEARCH_EXTENSIONS',
                            ['', FILE_SUFFIX, IPT4_SUFFIX, IPT6_SUFFIX])

MAIN_PYRE = [
    f'rules{FILE_SUFFIX}', f'main{FILE_SUFFIX}', f'master{FILE_SUFFIX}',
    f'base{FILE_SUFFIX}', f'firewall{FILE_SUFFIX}'
]
"""
A list of default 'master' Pyrewall rule files to try and locate and use, if one isn't specified on the command line.