api added
This commit is contained in:
parent
ba20e6f2e3
commit
1d95ede8db
|
@ -14,8 +14,6 @@ from werkzeug.middleware.shared_data import SharedDataMiddleware
|
||||||
from oauthlib.oauth2 import WebApplicationClient
|
from oauthlib.oauth2 import WebApplicationClient
|
||||||
from discord_webhook import DiscordWebhook, DiscordEmbed
|
from discord_webhook import DiscordWebhook, DiscordEmbed
|
||||||
|
|
||||||
contact_support_dc_webhook = ""
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
app.config.update(
|
app.config.update(
|
||||||
|
@ -40,7 +38,6 @@ class User(UserMixin):
|
||||||
def load_user(userid):
|
def load_user(userid):
|
||||||
return User(userid)
|
return User(userid)
|
||||||
|
|
||||||
|
|
||||||
def get_username(self):
|
def get_username(self):
|
||||||
return self.username
|
return self.username
|
||||||
|
|
||||||
|
@ -50,7 +47,6 @@ def homepage():
|
||||||
return redirect("/login")
|
return redirect("/login")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@app.route('/login', methods=['GET',"POST"])
|
@app.route('/login', methods=['GET',"POST"])
|
||||||
def login_general():
|
def login_general():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
@ -112,11 +108,52 @@ def cpdashy_1_main():
|
||||||
user_data = json.load(f)
|
user_data = json.load(f)
|
||||||
|
|
||||||
# Continue here -> log data reading
|
# Continue here -> log data reading
|
||||||
|
# start sim button
|
||||||
|
|
||||||
return render_template("main/dashboard_main1.html",sidebar_html_insert=cpdash_get_sidebar().replace("active_state_class1","is-active"), profile_picture=user_data["picture"],profile_username=user_data["username"],profile_userid=user_data["userid"],profile_email=user_data["email"])
|
return render_template("main/dashboard_main1.html",sidebar_html_insert=cpdash_get_sidebar().replace("active_state_class1","is-active"), profile_picture=user_data["picture"],profile_username=user_data["username"],profile_userid=user_data["userid"],profile_email=user_data["email"])
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return redirect('/login')
|
return redirect('/login')
|
||||||
|
|
||||||
|
@app.route("/d1/startsim", methods=['GET']) #start the sim
|
||||||
|
def cpdashy_startsim():
|
||||||
|
if current_user.is_authenticated:
|
||||||
|
clear_session_full()
|
||||||
|
with open("database/temp/attack_start.txt","w") as f:
|
||||||
|
f.write(str(time.time()))
|
||||||
|
return redirect("/d1")
|
||||||
|
else:
|
||||||
|
return redirect('/login')
|
||||||
|
|
||||||
|
|
||||||
|
# API
|
||||||
|
def clear_session_full():
|
||||||
|
os.remove("database/temp/sim_start.txt")
|
||||||
|
os.remove("database/temp/attack_start.txt")
|
||||||
|
with open("database/logs/red.json","w") as f:
|
||||||
|
f.write("{}")
|
||||||
|
with open("database/logs/blue.json","w") as f:
|
||||||
|
f.write("{}")
|
||||||
|
|
||||||
|
@app.route("/api/red", methods=['POST'])
|
||||||
|
def api_red_logs():
|
||||||
|
temp_json_n = request.json
|
||||||
|
print("red log received")
|
||||||
|
print(temp_json_n)
|
||||||
|
|
||||||
|
if temp_json_n["title"] == "Start of attack":
|
||||||
|
with open("database/temp/attack_start.txt",'w') as f:
|
||||||
|
f.write(str(temp_json_n["timestamp"]))
|
||||||
|
|
||||||
|
with open("database/logs/red.json","r") as f:
|
||||||
|
logs_list = json.load(f)
|
||||||
|
logs_list.append(temp_json_n)
|
||||||
|
with open("database/logs/red.json","w") as f:
|
||||||
|
json.dump(logs_list)
|
||||||
|
|
||||||
|
return("log saved")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Error handling
|
# Error handling
|
||||||
|
@ -124,7 +161,6 @@ def cpdashy_1_main():
|
||||||
def custom_401(error):
|
def custom_401(error):
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
||||||
|
|
||||||
@app.errorhandler(404)
|
@app.errorhandler(404)
|
||||||
def custom_404(error):
|
def custom_404(error):
|
||||||
return redirect("/")
|
return redirect("/")
|
||||||
|
|
|
@ -1309,14 +1309,14 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="video anim" style="--delay: .45s">
|
<div class="video anim" style="--delay: .45s">
|
||||||
<a href="#" style="text-decoration: none;color: #ff66d9;">
|
<a href="#" style="text-decoration: none;color: #ff66d9;">
|
||||||
<div class="video-by" title="xxx">Status</div>
|
<div class="video-by" title="xxx">Time since Sim start</div>
|
||||||
<div class="video-name padding_stat_n">xxx</div>
|
<div class="video-name padding_stat_n">xxx</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="video anim" style="--delay: .5s">
|
<div class="video anim" style="--delay: .5s">
|
||||||
<a target="_blank" href="#" style="text-decoration: none;color: #ff66d9;">
|
<a target="_blank" href="/d1/startsim" style="text-decoration: none;color: #ff66d9;">
|
||||||
<div class="video-by" title="xxx">Other</div>
|
<div class="video-by" title="Start the Simulation">Start Simulation</div>
|
||||||
<div class="video-name padding_stat_n">xxx</div>
|
<div class="video-name padding_stat_n">click here</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="video anim" style="--delay: .55s">
|
<div class="video anim" style="--delay: .55s">
|
||||||
|
|
Loading…
Reference in New Issue