-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
151 lines (110 loc) · 3.66 KB
/
app.py
File metadata and controls
151 lines (110 loc) · 3.66 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
import numpy as np
from flask import Flask, request, jsonify, render_template
import joblib
import sqlite3
import numpy as np
import pandas as pd
from sklearn import metrics
import warnings
import pickle
import pandas as pd
import numpy as np
import pickle
import sqlite3
import random
import smtplib
from email.message import EmailMessage
from datetime import datetime
warnings.filterwarnings('ignore')
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route("/about")
def about():
return render_template("about.html")
@app.route('/home')
def home():
return render_template('home.html')
@app.route('/logon')
def logon():
return render_template('signup.html')
@app.route('/login')
def login():
return render_template('signin.html')
@app.route('/home1')
def home1():
return render_template('home1.html')
@app.route("/signup")
def signup():
global otp, username, name, email, number, password
username = request.args.get('user','')
name = request.args.get('name','')
email = request.args.get('email','')
number = request.args.get('mobile','')
password = request.args.get('password','')
otp = random.randint(1000,5000)
print(otp)
msg = EmailMessage()
msg.set_content("Your OTP is : "+str(otp))
msg['Subject'] = 'OTP'
msg['From'] = "evotingotp4@gmail.com"
msg['To'] = email
s = smtplib.SMTP('smtp.gmail.com', 587)
s.starttls()
s.login("evotingotp4@gmail.com", "xowpojqyiygprhgr")
s.send_message(msg)
s.quit()
return render_template("val.html")
@app.route('/predict1', methods=['POST'])
def predict1():
global otp, username, name, email, number, password
if request.method == 'POST':
message = request.form['message']
print(message)
if int(message) == otp:
print("TRUE")
con = sqlite3.connect('signup.db')
cur = con.cursor()
cur.execute("insert into `info` (`user`,`email`, `password`,`mobile`,`name`) VALUES (?, ?, ?, ?, ?)",(username,email,password,number,name))
con.commit()
con.close()
return render_template("signin.html")
return render_template("signup.html")
@app.route("/signin")
def signin():
mail1 = request.args.get('user','')
password1 = request.args.get('password','')
con = sqlite3.connect('signup.db')
cur = con.cursor()
cur.execute("select `user`, `password` from info where `user` = ? AND `password` = ?",(mail1,password1,))
data = cur.fetchone()
if data == None:
return render_template("signin.html")
elif mail1 == str(data[0]) and password1 == str(data[1]):
return render_template("home.html")
else:
return render_template("signin.html")
@app.route("/notebook")
def notebook1():
return render_template("Notebook.html")
@app.route('/predict',methods=['POST'])
def predict():
int_features= [float(x) for x in request.form.values()]
print(int_features,len(int_features))
final4=[np.array(int_features)]
model = joblib.load('model.sav')
predict = model.predict(final4)
if predict==0:
output = 'There is an Attack Detected, Attack Type is DDoS!'
elif predict == 1:
output = 'There is an Attack Detected, Attack Type is Probe!'
elif predict == 2:
output = 'There is an Attack Detected, Attack Type is R2L!'
elif predict == 3:
output = 'There is an Attack Detected, Attack Type is U2R!'
elif predict == 4:
output = 'There is an No Attack Detected, it is Normal!'
return render_template('prediction.html', output=output)
if __name__ == "__main__":
app.run(debug=True)