From 95846d0dc7b10562b6e584e6063876de717a7d06 Mon Sep 17 00:00:00 2001 From: ANDRI <2655710+andrisecops@users.noreply.github.com> Date: Wed, 14 Aug 2024 17:56:06 +0700 Subject: [PATCH] build(devsecops)insfratuctur --- app/__init__.py | 20 ++++++++++++++++++++ app/analysis.py | 7 +++++++ app/dashboard.py | 11 +++++++++++ app/monitoring.py | 14 ++++++++++++++ app/routes.py | 10 ++++++++++ app/utils.py | 9 +++++++++ config.py | 10 ++++++++++ requirements.txt | 2 ++ run.py | 4 ++++ static/css/style.css | 22 ++++++++++++++++++++++ static/js/script.js | 2 ++ templates/dashboard.html | 17 +++++++++++++++++ 12 files changed, 128 insertions(+) create mode 100644 app/__init__.py create mode 100644 app/analysis.py create mode 100644 app/dashboard.py create mode 100644 app/monitoring.py create mode 100644 app/routes.py create mode 100644 app/utils.py create mode 100644 config.py create mode 100644 requirements.txt create mode 100644 run.py create mode 100644 static/css/style.css create mode 100644 static/js/script.js create mode 100644 templates/dashboard.html diff --git a/app/__init__.py b/app/__init__.py new file mode 100644 index 0000000..b4c6088 --- /dev/null +++ b/app/__init__.py @@ -0,0 +1,20 @@ +from flask import Flask +from config import Config + +app = Flask(__name__) +app.config.from_object(Config) + +from app import routes, dashboard, monitoring, analysis + +# Inisialisasi logging +import logging +from logging.handlers import RotatingFileHandler +import os + +if not os.path.exists(app.config['LOG_PATH']): + os.makedirs(app.config['LOG_PATH']) + +file_handler = RotatingFileHandler(os.path.join(app.config['LOG_PATH'], 'system.log'), maxBytes=10240, backupCount=10) +file_handler.setFormatter(logging.Formatter('%(asctime)s %(levelname)s: %(message)s')) +file_handler.setLevel(logging.INFO) +app.logger.addHandler(file_handler) diff --git a/app/analysis.py b/app/analysis.py new file mode 100644 index 0000000..d9a25e5 --- /dev/null +++ b/app/analysis.py @@ -0,0 +1,7 @@ +def analyze_file(file_path): + # Contoh analisis sederhana + with open(file_path, 'rb') as file: + content = file.read() + if b'backdoor' in content: + return 'Malware Detected' + return 'File is Safe' diff --git a/app/dashboard.py b/app/dashboard.py new file mode 100644 index 0000000..7657be7 --- /dev/null +++ b/app/dashboard.py @@ -0,0 +1,11 @@ +import random + +def get_dashboard_data(): + # Contoh data, ganti dengan data yang diambil dari sistem + data = { + 'traffic_in': random.randint(100, 1000), + 'traffic_out': random.randint(100, 1000), + 'threats_detected': random.randint(0, 5), + 'alerts': random.randint(0, 3), + } + return data diff --git a/app/monitoring.py b/app/monitoring.py new file mode 100644 index 0000000..c5b6bcc --- /dev/null +++ b/app/monitoring.py @@ -0,0 +1,14 @@ +import os +import logging + +def monitor_incoming_files(directory): + files = os.listdir(directory) + for file in files: + if file.endswith(('.php', '.exe', '.js', '.bat')): + logging.warning(f'Threat detected in file: {file}') + alert_admin(f'Threat detected in file: {file}') + +def alert_admin(message): + # Fungsi untuk mengirim notifikasi email + logging.info(f'Sending alert to admin: {message}') + # Implementasi pengiriman email di sini diff --git a/app/routes.py b/app/routes.py new file mode 100644 index 0000000..c5fbee6 --- /dev/null +++ b/app/routes.py @@ -0,0 +1,10 @@ +from flask import render_template +from app import app +from app.dashboard import get_dashboard_data + +@app.route('/') +def index(): + data = get_dashboard_data() + return render_template('dashboard.html', data=data) + +# Tambahkan rute lainnya yang diperlukan diff --git a/app/utils.py b/app/utils.py new file mode 100644 index 0000000..423bb9f --- /dev/null +++ b/app/utils.py @@ -0,0 +1,9 @@ +from flask_mail import Mail, Message +from app import app + +mail = Mail(app) + +def send_email(subject, recipient, body): + msg = Message(subject, sender=app.config['ALERT_EMAIL'], recipients=[recipient]) + msg.body = body + mail.send(msg) diff --git a/config.py b/config.py new file mode 100644 index 0000000..07f2dbe --- /dev/null +++ b/config.py @@ -0,0 +1,10 @@ +import os + +class Config: + SECRET_KEY = os.environ.get('SECRET_KEY') or 'kunci_rahasia' + DEBUG = True + LOG_PATH = os.path.join(os.getcwd(), 'logs') + ALERT_EMAIL = 'admin@example.com' + REPORT_INTERVAL = 7 # days + +# Tambahkan konfigurasi lainnya yang diperlukan diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e2b2bb6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==2.0.1 +Flask-Mail==0.9.1 diff --git a/run.py b/run.py new file mode 100644 index 0000000..357912d --- /dev/null +++ b/run.py @@ -0,0 +1,4 @@ +from app import app + +if __name__ == '__main__': + app.run(debug=True) diff --git a/static/css/style.css b/static/css/style.css new file mode 100644 index 0000000..a378e85 --- /dev/null +++ b/static/css/style.css @@ -0,0 +1,22 @@ +body { + font-family: Arial, sans-serif; + background-color: #f4f4f4; + margin: 0; + padding: 0; +} + +h1 { + text-align: center; + padding: 20px; + background-color: #333; + color: #fff; +} + +#data-visualization { + margin: 20px auto; + padding: 10px; + max-width: 600px; + background-color: #fff; + border-radius: 5px; + box-shadow: 0 0 10px rgba(0,0,0,0.1); +} diff --git a/static/js/script.js b/static/js/script.js new file mode 100644 index 0000000..d564691 --- /dev/null +++ b/static/js/script.js @@ -0,0 +1,2 @@ +// Anda bisa menambahkan interaktivitas di sini jika diperlukan. +console.log('Dashboard loaded'); diff --git a/templates/dashboard.html b/templates/dashboard.html new file mode 100644 index 0000000..0b3002f --- /dev/null +++ b/templates/dashboard.html @@ -0,0 +1,17 @@ + + + + + IT Infrastruktur Dashboard + + + +

Dashboard

+
+

Traffic In: {{ data.traffic_in }}

+

Traffic Out: {{ data.traffic_out }}

+

Threats Detected: {{ data.threats_detected }}

+

Alerts: {{ data.alerts }}

+
+ +