Skip to content

Commit

Permalink
Merge pull request #1 from andrisecops/IT-Infrastructure-Webserver
Browse files Browse the repository at this point in the history
build(devsecops)insfratuctur
  • Loading branch information
andrisecops authored Aug 14, 2024
2 parents 6048d32 + 95846d0 commit 64db6d9
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
7 changes: 7 additions & 0 deletions app/analysis.py
Original file line number Diff line number Diff line change
@@ -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'
11 changes: 11 additions & 0 deletions app/dashboard.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions app/monitoring.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions app/routes.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions app/utils.py
Original file line number Diff line number Diff line change
@@ -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)
10 changes: 10 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -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 = '[email protected]'
REPORT_INTERVAL = 7 # days

# Tambahkan konfigurasi lainnya yang diperlukan
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==2.0.1
Flask-Mail==0.9.1
4 changes: 4 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from app import app

if __name__ == '__main__':
app.run(debug=True)
22 changes: 22 additions & 0 deletions static/css/style.css
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 2 additions & 0 deletions static/js/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Anda bisa menambahkan interaktivitas di sini jika diperlukan.
console.log('Dashboard loaded');
17 changes: 17 additions & 0 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>IT Infrastruktur Dashboard</title>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
<h1>Dashboard</h1>
<div id="data-visualization">
<p>Traffic In: {{ data.traffic_in }}</p>
<p>Traffic Out: {{ data.traffic_out }}</p>
<p>Threats Detected: {{ data.threats_detected }}</p>
<p>Alerts: {{ data.alerts }}</p>
</div>
</body>
</html>

0 comments on commit 64db6d9

Please sign in to comment.