config.py 2.37 KB
Newer Older
1
import logging
2 3 4
import os
import threading

5 6
from peewee import MySQLDatabase

Edvard Rejthar's avatar
Edvard Rejthar committed
7 8 9 10
logger = logging.getLogger("mdmaug")


class Pref:
11 12
    safebrowsing = False  # True
    pdns = False  # True
Edvard Rejthar's avatar
Edvard Rejthar committed
13
    geoip = False
14 15
    autoprune = True
    creation_spree = False
Edvard Rejthar's avatar
Edvard Rejthar committed
16
    cache = "oldcache"
Edvard Rejthar's avatar
Edvard Rejthar committed
17 18 19 20 21

    @classmethod
    def val2html(cls, param):
        return "1" if getattr(cls, param) in [True, "true", "1"] else "0"

22

23
class Config:
24
    profile_count = 21  # number of Firefox profiles. Its name is just a number – 0,1...
25
    browser = 'firefox'  # iceweasel, firefox. What browser gets launched.
Edvard Rejthar's avatar
Edvard Rejthar committed
26 27
    config_file = '/opt/mdmaug/.cache/mdmaug-scans/_tmp/queue.cache'  # RAM disk was too small: '/tmp/mdm/queue.cache'
    APP_PORT = 5000
28 29
    APP_IP = "127.0.0.1"  # 217.31.202.41
    APP_HOST = f'http://{APP_IP}:{APP_PORT}'  # Xhttps
30 31
    LOG_DIR = "/opt/mdmaug/.cache/mdmaug-scans/_tmp/"
    CACHE_DIR = "/opt/mdmaug/.cache/mdmaug-scans/"
32 33 34
    ALLOWED_DESTINATION = {"mdm.nic.cz": "https://mdm.nic.cz",
                           # "hostname": "scheme://hostname(:port)"; allowed destinations for iframe-postMessage communication between MDMaug and MDM host
                           APP_IP: APP_HOST}  # in every case we allow MDMaug to communicate with itself
35
    DIR = os.path.dirname(os.path.realpath(__file__)) + "/../"
36 37
    db: MySQLDatabase = None
    lock = threading.RLock()
38
    THUMBNAIL_SIZE = 640, 640
39 40 41
    MAX_WHOIS_DOMAIN_THREADS = 10  # spusti maximalne 10 threadu doraz, jednou mi to totiz preteklo (kazda domena spusti jeste tolik threadu, kolik ma IP, ale tech byva jen par)
    MAX_BROWSER_RUN_TIME = 25  # maximum time for a browser to run
    MAX_BROWSER_EXPIRATION = 15  # seconds that we wait before killing the browser (waiting for the files to be written)
42 43
    EXPORT_NOTBLOCK_TLD = ".cz"  # lowercase; this TLD is ignored in the export
    CRAWL_FILE = "analysis.json"
44

Edvard Rejthar's avatar
Edvard Rejthar committed
45
    @staticmethod
46 47 48
    def connect():
        # XX resim problem peewee.OperationalError: (2006, "MySQL server has gone away (BrokenPipeError(32, 'Broken pipe'))") po 7 hodinach timeoutu
        # XX kupodivu pripojeni nemuze byt v dbp DBModel.connect. Prestoze type je pak spravne (MySQLDatabase), nic udelat nejde a pokusy o select konci NoneType.
Edvard Rejthar's avatar
Edvard Rejthar committed
49
        logger.debug("Connecting to DB.")
50 51
        # XX dal jsem pryc: , threadlocals=False
        Config.db = MySQLDatabase("mdmaug", host='localhost', port=3306, user="mdmaug", passwd="fidFDSs676")