From 5ca285bbb6163f6c5b2af3526f7f3b6f321fa014 Mon Sep 17 00:00:00 2001 From: Microtechno9000 Date: Tue, 20 Aug 2024 14:34:30 +0930 Subject: [PATCH 1/3] Feature - basic stats on index with no login addition of basic job information and no edit features from the main index, or home page --- arm/ui/auth/templates/login.html | 2 +- .../templates/support/base_simple.html | 5 +- arm/ui/jobs/jobs.py | 75 +++++++++++-------- arm/ui/json_api.py | 8 +- arm/ui/routes.py | 5 +- arm/ui/static/js/common.js | 26 ++++--- arm/ui/static/js/jobRefresh.js | 2 +- arm/ui/templates/index.html | 7 +- arm/ui/templates/nav.html | 3 + 9 files changed, 83 insertions(+), 50 deletions(-) diff --git a/arm/ui/auth/templates/login.html b/arm/ui/auth/templates/login.html index 3ca94c8c4..aedeefc57 100755 --- a/arm/ui/auth/templates/login.html +++ b/arm/ui/auth/templates/login.html @@ -1,4 +1,4 @@ -{% extends "base.html" %} +{% extends "support/base_simple.html" %} {% block content %}
diff --git a/arm/ui/database/templates/support/base_simple.html b/arm/ui/database/templates/support/base_simple.html index 2b699a4ef..cd8b038f1 100644 --- a/arm/ui/database/templates/support/base_simple.html +++ b/arm/ui/database/templates/support/base_simple.html @@ -33,7 +33,10 @@ diff --git a/arm/ui/jobs/jobs.py b/arm/ui/jobs/jobs.py index 8f7e5697a..f31484c8e 100644 --- a/arm/ui/jobs/jobs.py +++ b/arm/ui/jobs/jobs.py @@ -13,7 +13,7 @@ """ import json -from flask_login import LoginManager, login_required # noqa: F401 +from flask_login import LoginManager, login_required, current_user # noqa: F401 from flask import render_template, request, Blueprint, flash, redirect, url_for from werkzeug.routing import ValidationError @@ -196,7 +196,6 @@ def list_titles(): @route_jobs.route('/json', methods=['GET']) -@login_required def feed_json(): """ json mini API @@ -205,41 +204,55 @@ def feed_json(): is your call You can then add a function inside utils to deal with the request """ + # Check if users is authenticated + # Return data when authenticated, but allow basic job info when not + authenticated = current_user.is_authenticated mode = str(request.args.get('mode')) return_json = {'mode': mode, 'success': False} - # Hold valid data (post/get data) we might receive from pages - not in here ? it's going to throw a key error - valid_data = { - 'j_id': request.args.get('job'), - 'searchq': request.args.get('q'), - 'logpath': cfg.arm_config['LOGPATH'], - 'fail': 'fail', - 'success': 'success', - 'joblist': 'joblist', - 'mode': mode, - 'config_id': request.args.get('config_id'), - 'notify_id': request.args.get('notify_id'), - 'notify_timeout': {'funct': json_api.get_notify_timeout, 'args': ('notify_timeout',)}, - 'restart': {'funct': json_api.restart_ui, 'args': ()}, - } - # Valid modes that should trigger functions - valid_modes = { - 'delete': {'funct': json_api.delete_job, 'args': ('j_id', 'mode')}, - 'abandon': {'funct': json_api.abandon_job, 'args': ('j_id',)}, - 'full': {'funct': json_api.generate_log, 'args': ('logpath', 'j_id')}, - 'search': {'funct': json_api.search, 'args': ('searchq',)}, - 'getfailed': {'funct': json_api.get_x_jobs, 'args': ('fail',)}, - 'getsuccessful': {'funct': json_api.get_x_jobs, 'args': ('success',)}, - 'fixperms': {'funct': ui_utils.fix_permissions, 'args': ('j_id',)}, - 'joblist': {'funct': json_api.get_x_jobs, 'args': ('joblist',)}, - 'send_item': {'funct': ui_utils.send_to_remote_db, 'args': ('j_id',)}, - 'change_job_params': {'funct': json_api.change_job_params, 'args': ('config_id',)}, - 'read_notification': {'funct': json_api.read_notification, 'args': ('notify_id',)}, - 'notify_timeout': {'funct': json_api.get_notify_timeout, 'args': ('notify_timeout',)} - } + + if authenticated: + # Hold valid data (post/get data) we might receive from pages - not in here ? it's going to throw a key error + valid_data = { + 'j_id': request.args.get('job'), + 'searchq': request.args.get('q'), + 'logpath': cfg.arm_config['LOGPATH'], + 'fail': 'fail', + 'success': 'success', + 'joblist': 'joblist', + 'mode': mode, + 'config_id': request.args.get('config_id'), + 'notify_id': request.args.get('notify_id'), + 'notify_timeout': {'funct': json_api.get_notify_timeout, 'args': ('notify_timeout',)}, + 'restart': {'funct': json_api.restart_ui, 'args': ()}, + } + # Valid modes that should trigger functions + valid_modes = { + 'delete': {'funct': json_api.delete_job, 'args': ('j_id', 'mode')}, + 'abandon': {'funct': json_api.abandon_job, 'args': ('j_id',)}, + 'full': {'funct': json_api.generate_log, 'args': ('logpath', 'j_id')}, + 'search': {'funct': json_api.search, 'args': ('searchq',)}, + 'getfailed': {'funct': json_api.get_x_jobs, 'args': ('fail',)}, + 'getsuccessful': {'funct': json_api.get_x_jobs, 'args': ('success',)}, + 'fixperms': {'funct': ui_utils.fix_permissions, 'args': ('j_id',)}, + 'joblist': {'funct': json_api.get_x_jobs, 'args': ('joblist',)}, + 'send_item': {'funct': ui_utils.send_to_remote_db, 'args': ('j_id',)}, + 'change_job_params': {'funct': json_api.change_job_params, 'args': ('config_id',)}, + 'read_notification': {'funct': json_api.read_notification, 'args': ('notify_id',)}, + 'notify_timeout': {'funct': json_api.get_notify_timeout, 'args': ('notify_timeout',)} + } + else: + valid_data = { + 'joblist': 'joblist', + } + valid_modes = { + 'joblist': {'funct': json_api.get_x_jobs, 'args': ('joblist',)}, + } + if mode in valid_modes: args = [valid_data[x] for x in valid_modes[mode]['args']] return_json = valid_modes[mode]['funct'](*args) return_json['notes'] = json_api.get_notifications() + return app.response_class(response=json.dumps(return_json, indent=4, sort_keys=True), status=200, mimetype=constants.JSON_TYPE) diff --git a/arm/ui/json_api.py b/arm/ui/json_api.py index f76585cb0..61a016aa7 100755 --- a/arm/ui/json_api.py +++ b/arm/ui/json_api.py @@ -10,6 +10,7 @@ import datetime import psutil from flask import request +from flask_login import current_user import arm.config.config as cfg from arm.models.config import Config @@ -64,8 +65,11 @@ def get_x_jobs(job_status): if jobs: app.logger.debug("jobs - we have " + str(len(job_results)) + " jobs") success = True - return {"success": success, "mode": job_status, - "results": job_results, "arm_name": cfg.arm_config['ARM_NAME']} + return {"success": success, + "mode": job_status, + "results": job_results, + "arm_name": cfg.arm_config['ARM_NAME'], + "authenticated": current_user.is_authenticated} def process_logfile(logfile, job, job_results): diff --git a/arm/ui/routes.py b/arm/ui/routes.py index 05350303a..df61216b3 100644 --- a/arm/ui/routes.py +++ b/arm/ui/routes.py @@ -45,7 +45,6 @@ @app.route('/') @app.route('/index.html') @app.route('/index') -@login_required def home(): """ The main homepage showing current rips and server stats @@ -82,7 +81,9 @@ def home(): else: jobs = {} - return render_template("index.html", jobs=jobs, + return render_template("index.html", + authenticated=current_user.is_authenticated, + jobs=jobs, children=cfg.arm_config['ARM_CHILDREN'], server=server, serverutil=serverutil, arm_path=arm_path, media_path=media_path, stats=stats) diff --git a/arm/ui/static/js/common.js b/arm/ui/static/js/common.js index 621ff8443..b79b1567c 100755 --- a/arm/ui/static/js/common.js +++ b/arm/ui/static/js/common.js @@ -28,7 +28,7 @@ function getRipperName(job, idsplit) { return ripperName; } -function addJobItem(job) { +function addJobItem(job, authenticated) { // Local server or remote const idsplit = job.job_id.split("_"); console.log(`${idsplit[1]} - ${idsplit[0]}`) @@ -44,7 +44,7 @@ function addJobItem(job) { } // Section 2 (Middle) Contains Job info (status, type, device, start time, progress) x += buildMiddleSection(job); - x += buildRightSection(job, idsplit); + x += buildRightSection(job, idsplit, authenticated); // Close Job.card x += "
"; return x; @@ -118,7 +118,7 @@ function buildMiddleSection(job) { return x; } -function buildRightSection(job, idsplit) { +function buildRightSection(job, idsplit, authenticated) { let x; // idsplit[1] should only be undefined on the /database page if (idsplit[1] === undefined) { @@ -137,13 +137,19 @@ function buildRightSection(job, idsplit) { x += `
Max Length: ${job.config.MAXLENGTH}
`; x += ""; // Section 3 (Right Bottom) Contains Buttons for arm json api - x += `
- - View logfile`; - x += musicCheck(job, idsplit); - x += ``; + // Only show when authenticated + x += `
`; + if (authenticated === true) { + x += `
+ + View logfile`; + x += musicCheck(job, idsplit); + x += ``; + x += `
`; + } + x += `
`; return x; } diff --git a/arm/ui/static/js/jobRefresh.js b/arm/ui/static/js/jobRefresh.js index 881b3255e..f8797b520 100644 --- a/arm/ui/static/js/jobRefresh.js +++ b/arm/ui/static/js/jobRefresh.js @@ -248,7 +248,7 @@ function refreshJobsSuccess(data, serverIndex, serverUrl, serverCount) { updateJobItem(oldJob, job); } else { activeJobs.push(job); - $("#joblist").append(addJobItem(job)); + $("#joblist").append(addJobItem(job, data.authenticated)); } serverCount--; }); diff --git a/arm/ui/templates/index.html b/arm/ui/templates/index.html index 054805db0..11f1a17b4 100644 --- a/arm/ui/templates/index.html +++ b/arm/ui/templates/index.html @@ -1,5 +1,8 @@ -{% extends "base.html" %} - +{% if authenticated %} + {% extends "base.html" %} +{% else %} + {% extends "support/base_simple.html" %} +{% endif %} {% block content %}