Ejemplo n.º 1
0
 def __init__(self,
              storage_directory: Path = None,
              loglevel: int = logging.DEBUG):
     super().__init__(loglevel)
     if not storage_directory:
         storage_directory = get_homedir() / 'rawdata'
     self.asn_descr = ASNDescriptions(storage_directory, loglevel)
Ejemplo n.º 2
0
 def __init__(self, config_dir: Path=None, storage_directory: Path=None, loglevel: int=logging.DEBUG):
     super().__init__(loglevel)
     if not config_dir:
         config_dir = get_config_path()
     if not storage_directory:
         self.storage_directory = get_homedir() / 'rawdata'
     self.modules_config = config_dir / 'modules'
     self.modules_paths = [modulepath for modulepath in self.modules_config.glob('*.json')]
     self.modules = [Fetcher(path, self.storage_directory, loglevel) for path in self.modules_paths]
Ejemplo n.º 3
0
 def __init__(self,
              config_dir: Path = None,
              storage_directory: Path = None,
              loglevel: int = logging.INFO):
     super().__init__(loglevel)
     self.config = True
     if not config_dir:
         config_dir = get_config_path()
     if not (config_dir / 'shadowserver.json').exists():
         self.config = False
         self.logger.warning(
             f'No config file available, the shadow server module will not be launched.'
         )
         return
     with open(config_dir / 'shadowserver.json') as f:
         ss_config = json.load(f)
     if not storage_directory:
         storage_directory = get_homedir() / 'rawdata'
     modules_config = config_dir / 'modules'
     self.fetcher = ShadowServerFetcher(ss_config['user'],
                                        ss_config['password'],
                                        modules_config, storage_directory,
                                        loglevel)
Ejemplo n.º 4
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from subprocess import Popen
from bgpranking.libs.helpers import get_homedir

if __name__ == '__main__':
    get_homedir()
    p = Popen(['shutdown.py'])
    p.wait()
    Popen(['run_backend.py', '--stop'])
Ejemplo n.º 5
0
import requests

from flask import Flask, render_template, request, session, Response, redirect, url_for
from flask_bootstrap import Bootstrap

from bgpranking.querying import Querying
from bgpranking.libs.exceptions import MissingConfigEntry
from bgpranking.libs.helpers import load_general_config, get_homedir, get_ipasn
from datetime import date, timedelta
import pycountry
from collections import defaultdict

app = Flask(__name__)

secret_file_path = get_homedir() / 'website' / 'secret_key'

if not secret_file_path.exists() or secret_file_path.stat().st_size < 64:
    with open(secret_file_path, 'wb') as f:
        f.write(os.urandom(64))

with open(secret_file_path, 'rb') as f:
    app.config['SECRET_KEY'] = f.read()

Bootstrap(app)
app.config['BOOTSTRAP_SERVE_LOCAL'] = True

# ############# Helpers #############


def load_session():
Ejemplo n.º 6
0
def shutdown_storage(storage_directory: Path = None):
    if not storage_directory:
        storage_directory = get_homedir()
    Popen(["./shutdown_ardb.sh"], cwd=(storage_directory / 'storage'))
Ejemplo n.º 7
0
def launch_storage(storage_directory: Path = None):
    if not storage_directory:
        storage_directory = get_homedir()
    if not check_running('storage'):
        Popen(["./run_ardb.sh"], cwd=(storage_directory / 'storage'))
Ejemplo n.º 8
0
def shutdown_temp(storage_directory: Path = None):
    if not storage_directory:
        storage_directory = get_homedir()
    Popen(["./shutdown_redis.sh"], cwd=(storage_directory / 'temp'))
Ejemplo n.º 9
0
def launch_temp(storage_directory: Path = None):
    if not storage_directory:
        storage_directory = get_homedir()
    if not check_running('intake') and not check_running('prepare'):
        Popen(["./run_redis.sh"], cwd=(storage_directory / 'temp'))
Ejemplo n.º 10
0
def launch_cache(storage_directory: Path = None):
    if not storage_directory:
        storage_directory = get_homedir()
    if not check_running('cache'):
        Popen(["./run_redis.sh"], cwd=(storage_directory / 'cache'))
Ejemplo n.º 11
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from subprocess import Popen
from bgpranking.libs.helpers import get_homedir

if __name__ == '__main__':
    website_dir = get_homedir() / 'website'
    Popen([f'{website_dir}/3drparty.sh'], cwd=website_dir)
    try:
        Popen([
            'gunicorn', '--worker-class', 'gevent', '-w', '10', '-b',
            '0.0.0.0:5005', 'web:app'
        ],
              cwd=website_dir).communicate()
    except KeyboardInterrupt:
        print('Stopping gunicorn.')