forked from jyothsna1076/AnamolyDetectionPRMLProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
198 lines (175 loc) · 6.6 KB
/
index.html
File metadata and controls
198 lines (175 loc) · 6.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Real-Time NIDS</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background: linear-gradient(to right, #ece9e6, #ffffff);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
text-align: center;
color: #333;
}
h1 {
font-size: 36px;
margin-bottom: 10px;
color: #2c3e50;
}
h3 {
margin: 20px 0 10px;
color: #666;
}
button {
padding: 12px 24px;
font-size: 18px;
margin: 10px;
border: none;
border-radius: 6px;
cursor: pointer;
background-color: #3498db;
color: white;
transition: background-color 0.3s, transform 0.2s;
}
button:hover {
background-color: #2980b9;
transform: scale(1.05);
}
input[type="file"] {
padding: 10px;
font-size: 16px;
margin-top: 10px;
}
#status {
margin-top: 30px;
font-size: 18px;
font-style: italic;
color: #8e44ad;
}
#results {
margin-top: 10px;
font-size: 22px;
font-weight: bold;
}
.container {
background: #ffffff;
padding: 40px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
max-width: 500px;
width: 90%;
}
</style>
</head>
<body>
<div class="container">
<h1>Network Intrusion Detection System</h1>
<button onclick="startMonitoring()">📡 Capture Real Traffic</button>
<h3>OR</h3>
<input type="file" id="fileInput" />
<button onclick="checkManually()">📁 Check Manually</button>
<div id="status"></div>
<div id="results"></div>
</div>
<script>
function fetchResults() {
fetch('/get-predictions')
.then(response => response.json())
.then(data => {
if (data.predictions) {
const resultText = data.predictions.some(p => p.includes('anomaly'))
? "Anomaly Detected!"
: "Traffic Appears Normal.";
document.getElementById("results").innerText = resultText;
document.getElementById("status").innerText = "Prediction Complete";
} else if (data.status === 'processing') {
document.getElementById("status").innerText = "Still processing... checking again soon.";
setTimeout(fetchResults, 3000);
} else if (data.error) {
document.getElementById("status").innerText = "Error: " + data.error;
} else {
document.getElementById("status").innerText = data.message || "Waiting to start.";
}
});
}
function checkManually() {
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
if (!file) {
alert("Please select a file first.");
return;
}
const formData = new FormData();
formData.append("file", file);
document.getElementById("status").innerText = "Uploading and processing file...";
document.getElementById("results").innerText = "";
fetch('/manual-check', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.predictions) {
const resultText = data.predictions.some(p => p.includes('anomaly'))
? "Anomaly Detected in File!"
: "File Traffic Appears Normal.";
document.getElementById("results").innerText = resultText;
document.getElementById("status").innerText = "Manual File Prediction Complete";
} else if (data.error) {
document.getElementById("status").innerText = "Error: " + data.error;
}
})
.catch(error => {
document.getElementById("status").innerText = "Error: " + error;
});
}
function startMonitoring() {
document.getElementById("status").innerText = "🔍 Monitoring started... Please wait.";
document.getElementById("results").innerText = "";
fetch('/start-monitoring', { method: 'POST' })
.then(response => response.json())
.then(data => {
console.log(data.status);
startCountdown(30);
pollForResults();
});
}
function startCountdown(seconds) {
let remaining = seconds;
const statusDiv = document.getElementById("status");
const interval = setInterval(() => {
statusDiv.innerHTML = `⏳ Still processing... The data is captured in <strong>${remaining}</strong> seconds.`;
remaining--;
if (remaining < 0) {
clearInterval(interval);
}
}, 1000);
}
function pollForResults() {
fetch('/get-predictions')
.then(response => response.json())
.then(data => {
if (data.predictions) {
const resultText = data.predictions.includes('anomaly')
? "Anomaly Detected!"
: "Traffic Appears Normal.";
document.getElementById("results").innerText = resultText;
document.getElementById("status").innerText = "Prediction Complete!";
} else {
setTimeout(pollForResults, 3000);
}
})
.catch(err => {
document.getElementById("status").innerText = "Error checking predictions.";
console.error(err);
});
}
</script>
</body>
</html>