Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ball42 committed Apr 3, 2024
2 parents d8dce73 + 7b917cc commit e775cac
Show file tree
Hide file tree
Showing 46 changed files with 2,599 additions and 2,753 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 Jamf Open Source Community
Copyright (c) 2023 Jamf Open Source Community

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
53 changes: 36 additions & 17 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
#
# Copyright (c) 2022 Jamf. All rights reserved.
# Copyright (c) 2024 Jamf. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -30,10 +30,11 @@
import json
import os
import uuid
from datetime import timedelta

from datetime import timedelta
from flask import (Flask, request, render_template,
session, redirect, url_for, escape)
session, redirect, url_for)
from markupsafe import escape
from waitress import serve

from bin import logger
Expand All @@ -44,7 +45,6 @@
logthis = logger.setup_child_logger('jawa', 'app')
error_message = ""


# Initiate Flask
app = Flask(__name__)

Expand Down Expand Up @@ -109,12 +109,11 @@ def register_blueprints():


# Server setup including making .json file necessary for webhooks


@app.route('/setup', methods=['GET', 'POST'])
def setup():
if 'username' not in session:
return redirect(url_for('home_view.logout', error_title="Session Timed Out", error_message="Please sign in again"))
return redirect(
url_for('home_view.logout', error_title="Session Timed Out", error_message="Please sign in again"))
if request.method == 'POST':
logthis.debug(f"[{session.get('url')}] {session.get('username')} /setup - POST")
server_url = request.form.get('address')
Expand Down Expand Up @@ -174,19 +173,35 @@ def setup():
@response(template_file="setup/cleanup.html")
def cleanup():
if 'username' not in session:
return redirect(url_for('home_view.logout', error_title="Session Timed Out", error_message="Please sign in again"))
return redirect(
url_for('home_view.logout', error_title="Session Timed Out", error_message="Please sign in again"))
if request.method != 'POST':
return {"username": session.get('username'), "scripts_dir": scripts_directory}
owd = os.getcwd()
if not os.path.isdir(scripts_directory):
os.mkdir(scripts_directory)
os.chdir(scripts_directory)
old_scripts = glob.glob("*.old")
os.chdir(owd)
return {"username": session.get('username'), "scripts_dir": scripts_directory, "scripts": old_scripts}
logthis.info(f"[{session.get('url')}] {session.get('username')} is cleaning up scripts...")
owd = os.getcwd()
if not os.path.isdir(scripts_directory):
os.mkdir(scripts_directory)
os.chdir(scripts_directory)
del_list = []
for file in glob.glob("*.old"):
logthis.info(f"[{session.get('url')}] {session.get('username')} removed the script {file}...")
del_list.append(f"{file}")
os.remove(file)
os.chdir(owd)
return redirect(url_for('success'))
if not del_list:
success_msg = "No Script files found to clean up."
else:
txt_list = "Deleted: \n"
for file in del_list:
txt_list += f"{file}\n"
success_msg = txt_list or "No script files found to clean up."
return redirect(url_for('success', success_msg=success_msg))


@app.route("/")
Expand All @@ -195,21 +210,25 @@ def home():


@app.route('/success', methods=['GET', 'POST'])
def success():
def success(success_msg=""):
if 'username' not in session:
logthis.info("No user logged in - returning to login page.")
return redirect(url_for('home_view.logout', error_title="Session Timed Out", error_message="Please sign in again"))
return render_template(
'success.html',
success_msg="",
login="true",
username=str(escape(session['username'])))
return redirect(
url_for('home_view.logout', error_title="Session Timed Out", error_message="Please sign in again"))
success_msg = request.args.get('success_msg')
if success_msg:
success_msg = escape(success_msg)
return render_template('success.html', success_msg=success_msg, login="true", username=str(escape(session['username'])))


@app.route('/error', methods=['GET', 'POST'])
def error():
error_title = request.args.get('error')
error_message = request.args.get('error_message')
if error_title:
error_title = escape(error_title)
if error_message:
error_message = escape(error_message)
if 'username' not in session:
return redirect(url_for('home_view.logout'))
logthis.info(
Expand Down
Loading

0 comments on commit e775cac

Please sign in to comment.