api added

This commit is contained in:
KyuDev 2023-04-13 17:55:01 +02:00
parent ba20e6f2e3
commit 1d95ede8db
2 changed files with 45 additions and 9 deletions

View File

@ -14,8 +14,6 @@ from werkzeug.middleware.shared_data import SharedDataMiddleware
from oauthlib.oauth2 import WebApplicationClient
from discord_webhook import DiscordWebhook, DiscordEmbed
contact_support_dc_webhook = ""
app = Flask(__name__)
app.config.update(
@ -40,7 +38,6 @@ class User(UserMixin):
def load_user(userid):
return User(userid)
def get_username(self):
return self.username
@ -50,7 +47,6 @@ def homepage():
return redirect("/login")
@app.route('/login', methods=['GET',"POST"])
def login_general():
if request.method == "POST":
@ -112,11 +108,52 @@ def cpdashy_1_main():
user_data = json.load(f)
# 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"])
else:
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
@ -124,7 +161,6 @@ def cpdashy_1_main():
def custom_401(error):
return redirect("/")
@app.errorhandler(404)
def custom_404(error):
return redirect("/")

View File

@ -1309,14 +1309,14 @@
</div>
<div class="video anim" style="--delay: .45s">
<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>
</a>
</div>
<div class="video anim" style="--delay: .5s">
<a target="_blank" href="#" style="text-decoration: none;color: #ff66d9;">
<div class="video-by" title="xxx">Other</div>
<div class="video-name padding_stat_n">xxx</div>
<a target="_blank" href="/d1/startsim" style="text-decoration: none;color: #ff66d9;">
<div class="video-by" title="Start the Simulation">Start Simulation</div>
<div class="video-name padding_stat_n">click here</div>
</a>
</div>
<div class="video anim" style="--delay: .55s">