Skip to content

Commit 6892a50

Browse files
committed
2 parents 96c3b07 + 3f61983 commit 6892a50

File tree

18 files changed

+757
-343
lines changed

18 files changed

+757
-343
lines changed

.vscode/settings.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"files.exclude": {
99
"**/.git": true, // this is a default value
1010
"**/*bundle*": true,
11-
"**/*grafana*": true,
1211
"**/*mpv*": true,
1312
"**/*.log":true,
1413
"**/dist*":true

build_tools/ResourceHacker.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[MRU List]
2-
MRU1=C:\dev\ffastrans_webui\dist\server.exe
3-
MRU2=C:\dev\ffastrans_webui\server.exe
2+
MRU1=C:\dev\ffastrans_webui\server.exe
3+
MRU2=C:\dev\ffastrans_webui\dist\server.exe
44
MRU3=C:\dev\MongoCBridge\x64\Debug\MongoCBridge.dll
55
MRU4=D:\dev\ffastrans_webui\server.exe
66
MRU5=

node_components/cron_tasks/scheduled_jobs.js

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
const assert = require('assert');
2-
const Request = require("request");
1+
const path = require("path");
32
const parser = require('cron-parser');
43
var tmp = require('tmp');
54
tmp.setGracefulCleanup();
@@ -11,7 +10,8 @@ const ffastransapi = require("../ffastransapi");
1110
const moment = require("moment");
1211
const Datastore = require("@seald-io/nedb");
1312
const axios = require("axios");
14-
const logfactory = require("../../shared_modules/logger")
13+
const logfactory = require("../../shared_modules/logger");
14+
const { exitCode } = require("process");
1515

1616
var logger = logfactory.getLogger("scheduler");
1717
logger.log = logger.info;
@@ -91,7 +91,7 @@ function formatFilename(str){
9191
function executeJob(current_job,socketioClientId,informCallback){
9292

9393
var runId = Math.random();
94-
var joblogger = logfactory.getLogger(formatFilename(new Date().toISOString()),current_job['job_name']);
94+
var joblogger = logfactory.getLogger(formatFilename(new Date().toISOString()),true,path.join("scheduled_jobs",current_job['id'] + "_" + current_job['job_name']));
9595
joblogger.info("Job Start: [" + current_job['job_name'] + "]");
9696
global.socketio.to(socketioClientId).emit("logmessage","Job Start: [" + current_job['job_name'] + "]");
9797
//logger.log ("SCIRPT",current_job["script"])
@@ -148,7 +148,7 @@ function executeJob(current_job,socketioClientId,informCallback){
148148
logger.log("MESSAGE FROM FORK: " + msg);
149149
if (current_job["workflow"] == ""){
150150
logger.warn("No Workflow selected!", "number of non started jobs:", msg.length);
151-
updateScheduledJob(current_job["id"],"last_message","No Workflow selected!");
151+
updateScheduledJob(current_job["id"],"last_message","No Workflow selected!" + formatDate());
152152
return;
153153
}
154154
//if we have an array of values, execute the ffastrans job
@@ -215,6 +215,7 @@ function executeJob(current_job,socketioClientId,informCallback){
215215
}
216216

217217
})()
218+
218219
//delete userscript file
219220
fs.unlink(path, (err) => {
220221
if (err) {
@@ -223,7 +224,11 @@ function executeJob(current_job,socketioClientId,informCallback){
223224

224225
}
225226
});
226-
227+
228+
if (exitCode == 0){
229+
updateScheduledJob(current_job["id"],"last_message","Executed successfully " + formatDate());
230+
}
231+
227232
});
228233

229234

@@ -281,7 +286,7 @@ async function needsExecution(current_job){
281286
var youngest_next = new Date("9999"); //hight start date, year 9999
282287
for (var _idx in crons){
283288
var _cur_cron = crons[_idx];
284-
var _interval = parser.parseExpression(_cur_cron,{//parseExpression func needs last_start_date to calcualte next interval
289+
var _interval = parser.parseExpression(_cur_cron,{//parseExpression func needs last_start_date to calcualte next interval, but why can it not work with current date?
285290
currentDate: last_start_date,
286291
iterator: false
287292
});
@@ -333,7 +338,7 @@ async function needsExecution(current_job){
333338

334339
if ("last_job_id" in current_job){
335340
if (current_job["last_job_id"] != ""){
336-
updateScheduledJob(current_job["id"],"last_message","Detected last Jobid exists, checking if Jobid is active");
341+
updateScheduledJob(current_job["id"],"last_message","Detected last Jobid exists, checking if Jobid is active " + formatDate());
337342
logger.log("checking if job is still runing");
338343
var protocol = global.config.STATIC_WEBSERVER_ENABLE_HTTPS == "true" ? "https://" : "http://";
339344
var url = protocol + global.config["STATIC_API_HOST"] + ":" + global.config["STATIC_API_NEW_PORT"] + "/tickets?nodetails=true" ;
@@ -342,7 +347,7 @@ async function needsExecution(current_job){
342347
var resp = await axios.get(url);
343348
if ("data" in resp){
344349
if (JSON.stringify(resp["data"]).indexOf(current_job["last_job_id"]) != -1){
345-
updateScheduledJob(current_job["id"],"last_message","Last job is still active");
350+
updateScheduledJob(current_job["id"],"last_message","Last job is still active "+ formatDate());
346351
logger.log("last_job_id is still active")
347352
return false;
348353
}else{
@@ -352,7 +357,7 @@ async function needsExecution(current_job){
352357
}
353358
}catch(ex){
354359
logger.error("Could not get information about currently running job, resetting las_job_id",ex);
355-
updateScheduledJob(current_job["id"],"last_message","Reset last job id due to error getting job details: " + current_job["last_job_id"] + ex);
360+
updateScheduledJob(current_job["id"],"last_message","Reset last job id due to error getting job details: " + current_job["last_job_id"] + ex + + formatDate());
356361
updateScheduledJob(current_job["id"],"last_job_id","");
357362
return true;
358363
}
@@ -383,4 +388,24 @@ function updateScheduledJob(id,field,value){
383388

384389
}
385390

391+
/**
392+
* Formats a Date object into a string with the format "YYYY-MM-DD HH:MM:SS".
393+
* Pads single-digit months, days, hours, minutes, and seconds with leading zeros.
394+
*
395+
* @param {Date} date - The date to format.
396+
* @returns {string} The formatted date string.
397+
*/
386398

399+
function formatDate(date) {
400+
if (!date) {
401+
date = new Date();
402+
}
403+
const year = date.getFullYear();
404+
const month = (date.getMonth() + 1).toString().padStart(2, '0'); // Months are 0-indexed
405+
const day = date.getDate().toString().padStart(2, '0');
406+
const hours = date.getHours().toString().padStart(2, '0');
407+
const minutes = date.getMinutes().toString().padStart(2, '0');
408+
const seconds = date.getSeconds().toString().padStart(2, '0');
409+
410+
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
411+
}

node_components/filebrowser.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const fs = require('fs');
22
const path = require('path');
33
const { spawn,execSync } = require('child_process');
44
const { PromisePool } = require('@supercharge/promise-pool');
5+
const userpermissions = require('./userpermissions');
56

67
function regexEscape(string) {
78
if (typeof string !== 'string') {
@@ -107,9 +108,12 @@ module.exports = function(app, express){
107108
baseFolder += "\\";
108109
}
109110
if (!checkFolderInGlobalConfig(baseFolder,res)){
110-
return;
111+
throw new Error(baseFolder + " is not configured as Location");
111112
}; //ends request with error if basefolder is is not within configured locations
112113

114+
if (!await userpermissions.checkFolderPermissions(req.user?.local?.username,baseFolder)){
115+
throw new Error("No permission to browse",baseFolder)
116+
}
113117
//do the work
114118
var rows = {};
115119
rows.rows =[];

0 commit comments

Comments
 (0)