Skip to content

Commit

Permalink
Merge pull request automatic-ripping-machine#1182 from microtechno900…
Browse files Browse the repository at this point in the history
…0/feature_limitedstats

[Feature] - basic stats on index with no login
  • Loading branch information
shitwolfymakes authored Aug 21, 2024
2 parents a182408 + c627f1c commit 9d7f202
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 51 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.7.2
2.8.0
2 changes: 1 addition & 1 deletion arm/ui/auth/templates/login.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "base.html" %}
{% extends "support/base_simple.html" %}

{% block content %}
<div class="container">
Expand Down
5 changes: 4 additions & 1 deletion arm/ui/database/templates/support/base_simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav">
<li id="navhome" class="nav-item">
<a class="nav-link" href="index.html">Home</a>
<a class="nav-link" href="index">Home</a>
</li>
<li id="navlogin" class="nav-item">
<a class="nav-link" href="login">Login</a>
</li>
</ul>
</div>
Expand Down
76 changes: 45 additions & 31 deletions arm/ui/jobs/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -219,7 +219,6 @@ def list_titles():


@route_jobs.route('/json', methods=['GET'])
@login_required
def feed_json():
"""
json mini API
Expand All @@ -228,41 +227,56 @@ 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',)},
}
# prepare JSON data
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 JSON data
return app.response_class(response=json.dumps(return_json, indent=4, sort_keys=True),
status=200,
mimetype=constants.JSON_TYPE)
8 changes: 6 additions & 2 deletions arm/ui/json_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions arm/ui/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
26 changes: 16 additions & 10 deletions arm/ui/static/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}`)
Expand All @@ -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 += "</div></div></div></div></div></div></div>";
return x;
Expand Down Expand Up @@ -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) {
Expand All @@ -137,13 +137,19 @@ function buildRightSection(job, idsplit) {
x += `<div id="jobId${job.job_id}_MAXLENGTH"><strong>Max Length: </strong>${job.config.MAXLENGTH}</div>`;
x += "</div>";
// Section 3 (Right Bottom) Contains Buttons for arm json api
x += `<div class="card-body px-2 py-1"><div class="btn-group-vertical" role="group" aria-label="buttons" ${idsplit[0] !== "0" ? "style=\"display: none;\"" : ""}>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-type="abandon" data-jobid="${idsplit[1]}"
data-href="json?job=${idsplit[1]}&mode=abandon">Abandon Job</button>
<a href="logs?logfile=${job.logfile}&mode=full" class="btn btn-primary">View logfile</a>`;
x += musicCheck(job, idsplit);
x += `<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-type="fixperms"
data-jobid="${idsplit[1]}" data-href="json?mode=fixperms&job=${idsplit[1]}">Fix Permissions</button>`;
// Only show when authenticated
x += `<div class="card-body px-2 py-1">`;
if (authenticated === true) {
x += `<div class="btn-group-vertical" role="group" aria-label="buttons" ${idsplit[0] !== "0" ? "style=\"display: none;\"" : ""}>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-type="abandon" data-jobid="${idsplit[1]}"
data-href="json?job=${idsplit[1]}&mode=abandon">Abandon Job</button>
<a href="logs?logfile=${job.logfile}&mode=full" class="btn btn-primary">View logfile</a>`;
x += musicCheck(job, idsplit);
x += `<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal" data-type="fixperms"
data-jobid="${idsplit[1]}" data-href="json?mode=fixperms&job=${idsplit[1]}">Fix Permissions</button>`;
x += `</div>`;
}
x += `</div>`;
return x;
}

Expand Down
2 changes: 1 addition & 1 deletion arm/ui/static/js/jobRefresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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--;
});
Expand Down
7 changes: 5 additions & 2 deletions arm/ui/templates/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{% extends "base.html" %}

{% if authenticated %}
{% extends "base.html" %}
{% else %}
{% extends "support/base_simple.html" %}
{% endif %}
{% block content %}
<style>
.progress-bar {
Expand Down
3 changes: 3 additions & 0 deletions arm/ui/templates/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<li id="navchangepass" class="nav-item">
<a class="nav-link" href="update_password"> Change admin password</a>
</li>
<li id="navlogout" class="nav-item">
<a class="nav-link" href="logout"> Logout</a>
</li>
<li id="notificationview" class="nav-item">
{% include 'navnotify.html' %}
</li>
Expand Down

0 comments on commit 9d7f202

Please sign in to comment.