redactor
This commit is contained in:
17
app.py
17
app.py
@@ -20,12 +20,10 @@ app = Flask(
|
||||
template_folder=os.path.join(BASE_DIR, 'templates')
|
||||
)
|
||||
|
||||
# Uniwersalne ścieżki - sprawdzaj obie
|
||||
CONFIG_DIR_DOCKER = '/etc/haproxy-configurator'
|
||||
CONFIG_DIR_LOCAL = './config'
|
||||
CONFIG_DIR_ENV = os.environ.get('CONFIG_DIR', None)
|
||||
|
||||
# Określ która ścieżka istnieje
|
||||
if CONFIG_DIR_ENV and os.path.exists(CONFIG_DIR_ENV):
|
||||
CONFIG_DIR = CONFIG_DIR_ENV
|
||||
elif os.path.exists(CONFIG_DIR_DOCKER):
|
||||
@@ -33,16 +31,14 @@ elif os.path.exists(CONFIG_DIR_DOCKER):
|
||||
elif os.path.exists(CONFIG_DIR_LOCAL):
|
||||
CONFIG_DIR = CONFIG_DIR_LOCAL
|
||||
else:
|
||||
CONFIG_DIR = CONFIG_DIR_DOCKER # Fallback
|
||||
CONFIG_DIR = CONFIG_DIR_DOCKER
|
||||
|
||||
AUTH_CFG = os.path.join(CONFIG_DIR, 'auth', 'auth.cfg')
|
||||
SSL_INI = os.path.join(CONFIG_DIR, 'ssl.ini')
|
||||
|
||||
# Create directories
|
||||
os.makedirs(os.path.dirname(AUTH_CFG), exist_ok=True)
|
||||
os.makedirs(os.path.dirname(SSL_INI), exist_ok=True)
|
||||
|
||||
# Load basic auth credentials
|
||||
BASIC_AUTH_USERNAME = "admin"
|
||||
BASIC_AUTH_PASSWORD = "admin"
|
||||
|
||||
@@ -60,17 +56,11 @@ except Exception as e:
|
||||
BASIC_AUTH_USERNAME = "admin"
|
||||
BASIC_AUTH_PASSWORD = "admin"
|
||||
|
||||
|
||||
# Register blueprints
|
||||
app.register_blueprint(main_bp)
|
||||
app.register_blueprint(edit_bp)
|
||||
|
||||
|
||||
# Setup authentication
|
||||
setup_auth(app)
|
||||
|
||||
|
||||
# SSL Configuration - Z ERROR HANDLINGIEM
|
||||
certificate_path = None
|
||||
private_key_path = None
|
||||
ssl_context = None
|
||||
@@ -79,7 +69,6 @@ try:
|
||||
config2 = configparser.ConfigParser()
|
||||
config2.read(SSL_INI)
|
||||
|
||||
# WAŻNE: has_section check PRZED .get()
|
||||
if config2.has_section('ssl'):
|
||||
certificate_path = config2.get('ssl', 'certificate_path')
|
||||
private_key_path = config2.get('ssl', 'private_key_path')
|
||||
@@ -87,7 +76,6 @@ try:
|
||||
print(f"[APP] ✗ No [ssl] section in {SSL_INI}", flush=True)
|
||||
sys.exit(1)
|
||||
|
||||
# Sprawdź czy pliki istnieją
|
||||
if not os.path.exists(certificate_path):
|
||||
print(f"[APP] ✗ Certificate not found: {certificate_path}", flush=True)
|
||||
sys.exit(1)
|
||||
@@ -105,20 +93,17 @@ except Exception as e:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# Statistics Route
|
||||
@app.route('/statistics')
|
||||
def display_haproxy_stats():
|
||||
haproxy_stats = fetch_haproxy_stats()
|
||||
parsed_stats = parse_haproxy_stats(haproxy_stats)
|
||||
return render_template('statistics.html', stats=parsed_stats)
|
||||
|
||||
# Logs Route
|
||||
@app.route('/logs')
|
||||
def display_logs():
|
||||
log_file_path = '/var/log/haproxy.log'
|
||||
parsed_entries = parse_log_file(log_file_path)
|
||||
return render_template('logs.html', entries=parsed_entries)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='::', port=5000, ssl_context=ssl_context, debug=True)
|
||||
Reference in New Issue
Block a user