Exemple #1
0
class Main(object):
    """
    TODO: Doku
    """

    def __init__(self, debug: bool = False) -> None:
        self.cfg = Config(CONFIG_PATH)

        loglevel = self.cfg.get_value("LOG", "level")
        to_stdout = self.cfg.get_value("LOG", "to_stdout")
        to_files = self.cfg.get_value("LOG", "to_files")
        logpath = self.cfg.get_value("LOG", "filepath")
        logfile = self.cfg.get_value("LOG", "filename")
        self.log = Log(str(loglevel), bool(to_stdout), bool(to_files), str(logpath), str(logfile))

        self.login_attempts = self.cfg.get_value("WEB", "login_attempts")
        self.login_bantime = self.cfg.get_value("WEB", "login_bantime")
        self.ip_ban = IpBan(app=APP, ban_count=self.login_attempts,
                            ban_seconds=self.login_bantime, ipc=True)
        self.ip_ban.url_pattern_add('^/static.*$', match_type='regex')

        info("starting easywall-web")

        self.rules_handler = RulesHandler()
        self.rules_handler.ensure_files_exist()

        if debug is True:
            port = self.cfg.get_value("WEB", "bindport")
            host = self.cfg.get_value("WEB", "bindip")
            APP.config.from_object('easywall_web.__main__.DevelopmentConfig')
            APP.run(str(host), str(port))
        else:
            APP.config.from_object('easywall_web.__main__.ProductionConfig')
from flask_ipban import IpBan
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'

app = Flask(__name__, static_folder='../build/static',template_folder='./views/templates')
app.config.from_pyfile('config.py')
db = SQLAlchemy(app)
babel = Babel(app)
blueprint = Blueprint('api',__name__,url_prefix='/api')
api = Api(blueprint,doc='/doc/',title = 'WhyDoThat API 문서',description = '모든 API 호출에 대해 정리한 문서 입니다.')
app.register_blueprint(blueprint)
ip_ban = IpBan(ban_seconds=200)
ip_ban.init_app(app)
ip_ban.load_nuisances()
ip_ban.ip_whitelist_add('1.223.233.222')
ip_ban.ip_whitelist_add('172.18.0.4')
ip_ban.url_pattern_add('/.env',match_type='string')
CORS(app,resources={
    r'*':{'origins':'*',
          'methods' : '*',
          'allow-headers':'*',
          'supports_credentials':True
          }
    })

google_oauth = app.config['GOOGLE_OAUTH']
google_client = WebApplicationClient(google_oauth['client_id'])
google_discovery_uri = "https://accounts.google.com/.well-known/openid-configuration"

github_oauth = app.config['GITHUB_OAUTH']
github_client = WebApplicationClient(github_oauth['client_id'])