Skip to content
Snippets Groups Projects
Commit 81de0efb authored by Eric Oulashin's avatar Eric Oulashin
Browse files

DD Upload Processor: Better more werkens for teh Linux.

DD Upload Processor v1.02: For Linux, after extracting an archive, sets file permissions too (in addition to directories which were being set already) so that all the files are readable
parent bb5542fa
No related branches found
No related tags found
1 merge request!181DD Upload Processor: Better more werkens for teh Linux.
Pipeline #3107 passed
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
* Initial public release * Initial public release
* 2022-06-08 Eric Oulashin Version 1.01 * 2022-06-08 Eric Oulashin Version 1.01
* Made fixes to get the scanner functionality working properly in Linux * Made fixes to get the scanner functionality working properly in Linux
* 2022-06-11 Eric Oulashin Version 1.02
* Improved file/dir permissions more: Set file permissions too after extracting
* an archive so that they're all readable.
*/ */
/* Command-line arguments: /* Command-line arguments:
...@@ -43,8 +46,8 @@ gStartupPath = backslash(gStartupPath.replace(/[\/\\][^\/\\]*$/,'')); ...@@ -43,8 +46,8 @@ gStartupPath = backslash(gStartupPath.replace(/[\/\\][^\/\\]*$/,''));
load(gStartupPath + "ddup_cleanup.js"); load(gStartupPath + "ddup_cleanup.js");
// Version information // Version information
var gDDUPVersion = "1.01"; var gDDUPVersion = "1.02";
var gDDUPVerDate = "2022-06-08"; var gDDUPVerDate = "2022-06-11";
// Store whether or not this is running in Windows // Store whether or not this is running in Windows
var gRunningInWindows = /^WIN/.test(system.platform.toUpperCase()); var gRunningInWindows = /^WIN/.test(system.platform.toUpperCase());
...@@ -65,13 +68,13 @@ if (argv.length > 0) ...@@ -65,13 +68,13 @@ if (argv.length > 0)
gFileToScan = fixedArgs[0]; gFileToScan = fixedArgs[0];
else else
{ {
console.print("nyhError: ncBlank filename argument given.\r\np"); console.print("\1n\1y\1hError: \1n\1cBlank filename argument given.\r\n\1p");
exit(-2); exit(-2);
} }
} }
else else
{ {
console.print("nyhError: ncUnknown command-line argument specified.\r\np"); console.print("\1n\1y\1hError: \1n\1cUnknown command-line argument specified.\r\n\1p");
exit(-1); exit(-1);
} }
} }
...@@ -99,7 +102,7 @@ if (gFileToScan.length > 0) ...@@ -99,7 +102,7 @@ if (gFileToScan.length > 0)
// if not. // if not.
if (gFileToScan.length == 0) if (gFileToScan.length == 0)
{ {
console.print("nyhError: ncNo filename specified to process.\r\np"); console.print("\1n\1y\1hError: \1n\1cNo filename specified to process.\r\n\1p");
exit(1); exit(1);
} }
...@@ -116,26 +119,26 @@ var configFileRead = ReadConfigFile(gStartupPath); ...@@ -116,26 +119,26 @@ var configFileRead = ReadConfigFile(gStartupPath);
// If the configuration files weren't read, then output an error and exit. // If the configuration files weren't read, then output an error and exit.
if (!configFileRead) if (!configFileRead)
{ {
console.print("nyhError: ncUpload processor is unable to read its\r\n"); console.print("\1n\1y\1hError: \1n\1cUpload processor is unable to read its\r\n");
console.print("configuration files.\r\np"); console.print("configuration files.\r\n\1p");
exit(2); exit(2);
} }
// Exit if there is no scan command. // Exit if there is no scan command.
if (gGenCfg.scanCmd.length == 0) if (gGenCfg.scanCmd.length == 0)
{ {
console.print("nyhWarning: ncNo scan command configured for the upload processor.\r\n"); console.print("\1n\1y\1hWarning: \1n\1cNo scan command configured for the upload processor.\r\n");
exit(0); exit(0);
} }
// Global variables // Global variables
// Strings for the OK and failure symbols // Strings for the OK and failure symbols
var gOKStr = "nkh[ngûkh]n"; var gOKStr = "\1n\1k\1h[\1n\1gû\1k\1h]\1n";
var gOKStrWithNewline = gOKStr + "\r\n"; var gOKStrWithNewline = gOKStr + "\r\n";
var gFailStr = "nkh[rXk]n"; var gFailStr = "\1n\1k\1h[\1rX\1k]\1n";
var gFailStrWithNewline = gFailStr + "\r\n"; var gFailStrWithNewline = gFailStr + "\r\n";
// Stuff for the printf formatting string for the status messages // Stuff for the printf formatting string for the status messages
var gStatusTextLen = 79 - console.strlen(gOKStr); // gOKStr and gFailStr should have the same length var gStatusTextLen = 79 - console.strlen(gOKStr); // gOKStr and gFailStr should have the same length
var gStatusPrintfStr = "n%s%-" + gStatusTextLen + "sn"; // For a color and the status text var gStatusPrintfStr = "\1n%s%-" + gStatusTextLen + "s\1n"; // For a color and the status text
// Now, scan the file and return the appropriate return code. // Now, scan the file and return the appropriate return code.
exit(main()); exit(main());
...@@ -149,12 +152,12 @@ exit(main()); ...@@ -149,12 +152,12 @@ exit(main());
function main() function main()
{ {
// Output the program name & version information // Output the program name & version information
console.print("n\r\nchDncigital hDncistortion hUncpload hPncrocessor whvng" + console.print("\1n\r\n\1c\1hD\1n\1cigital \1hD\1n\1cistortion \1hU\1n\1cpload \1hP\1n\1crocessor \1w\1hv\1n\1g" +
gDDUPVersion); gDDUPVersion);
// Originally I had this script output the version date, but now I'm not sure // Originally I had this script output the version date, but now I'm not sure
// if I want to do that.. // if I want to do that..
//console.print(" wh(b" + gDDUPVerDate + "w)"); //console.print(" \1w\1h(\1b" + gDDUPVerDate + "\1w)");
console.print("n"); console.print("\1n");
console.crlf(); console.crlf();
// Process the file // Process the file
...@@ -162,15 +165,15 @@ function main() ...@@ -162,15 +165,15 @@ function main()
// Depending on the exit code, display a success or failure message. // Depending on the exit code, display a success or failure message.
console.crlf(); console.crlf();
if (exitCode == 0) if (exitCode == 0)
console.print(gOKStr + " nbhScan successful - The file passed.\r\n"); console.print(gOKStr + " \1n\1b\1hScan successful - The file passed.\r\n");
else else
console.print(gFailStr + " nyhScan failed!\r\n"); console.print(gFailStr + " \1n\1y\1hScan failed!\r\n");
// If the option to pause at the end is enabled, then prompt the user for // If the option to pause at the end is enabled, then prompt the user for
// a keypress. // a keypress.
if (gGenCfg.pauseAtEnd) if (gGenCfg.pauseAtEnd)
{ {
console.print("nwhPress any key to continue:n"); console.print("\1n\1w\1hPress any key to continue:\1n");
console.getkey(K_NOECHO); console.getkey(K_NOECHO);
} }
...@@ -240,14 +243,14 @@ function processFile(pFilename) ...@@ -240,14 +243,14 @@ function processFile(pFilename)
// Display the program header stuff - The name of the file being scanned // Display the program header stuff - The name of the file being scanned
// and the status header line // and the status header line
var justFilename = getFilenameFromPath(pFilename); var justFilename = getFilenameFromPath(pFilename);
console.print("nwhScanning b" + justFilename.substr(0, 70)); console.print("\1n\1w\1hScanning \1b" + justFilename.substr(0, 70));
console.print("n\r\nb7 File Scan Status n\r\n"); console.print("\1n\r\n\1b\1" + "7 File Scan Status \1n\r\n");
// If the skipScanIfSysop option is enabled and the user is a sysop, // If the skipScanIfSysop option is enabled and the user is a sysop,
// then assume the file is good. // then assume the file is good.
if (gGenCfg.skipScanIfSysop && user.compare_ars("SYSOP")) if (gGenCfg.skipScanIfSysop && user.compare_ars("SYSOP"))
{ {
printf(gStatusPrintfStr, "gh", "Auto-approving the file (you're a sysop)"); printf(gStatusPrintfStr, "\1g\1h", "Auto-approving the file (you're a sysop)");
console.print(gOKStrWithNewline); console.print(gOKStrWithNewline);
return 0; return 0;
} }
...@@ -281,11 +284,14 @@ function processFile(pFilename) ...@@ -281,11 +284,14 @@ function processFile(pFilename)
deltree(baseWorkDir + "/"); deltree(baseWorkDir + "/");
if (!mkdir(baseWorkDir)) if (!mkdir(baseWorkDir))
{ {
console.print("nyhWarning: nwh Unable to create the work dir.n\r\n"); console.print("\1n\1y\1hWarning: \1n\1w\1h Unable to create the work dir.\1n\r\n");
retval = -1; retval = -1;
} }
if (!gRunningInWindows)
{
file_chmod(baseWorkDir, 0x1fd); // Octal 775, rwxrwxr-x file_chmod(baseWorkDir, 0x1fd); // Octal 775, rwxrwxr-x
//chmodDirsRecursive(baseWorkDir, 0x1fd); // Octal 775, rwxrwxr-x //chmodDirsRecursive(baseWorkDir, 0x1fd, 0x1b6); // Octal 775, rwxrwxr-x, and octal 666, rw-rw-rw-
}
// If all is okay, then create the directory in the temporary work dir. // If all is okay, then create the directory in the temporary work dir.
var workDir = baseWorkDir + "/" + justFilename + "_temp"; var workDir = baseWorkDir + "/" + justFilename + "_temp";
...@@ -294,7 +300,7 @@ function processFile(pFilename) ...@@ -294,7 +300,7 @@ function processFile(pFilename)
deltree(workDir + "/"); deltree(workDir + "/");
if (!mkdir(workDir)) if (!mkdir(workDir))
{ {
console.print("nyhWarning: nwh Unable to create a dir in the temporary work dir.n\r\n"); console.print("\1n\1y\1hWarning: \1n\1w\1h Unable to create a dir in the temporary work dir.\1n\r\n");
retval = -1; retval = -1;
} }
} }
...@@ -303,15 +309,15 @@ function processFile(pFilename) ...@@ -303,15 +309,15 @@ function processFile(pFilename)
if (retval == 0) if (retval == 0)
{ {
// Extract the file to the work directory // Extract the file to the work directory
printf(gStatusPrintfStr, "mh", "Extracting the file..."); printf(gStatusPrintfStr, "\1m\1h", "Extracting the file...");
var errorStr = extractFileToDir(pFilename, workDir); var errorStr = extractFileToDir(pFilename, workDir);
if (errorStr.length == 0) if (errorStr.length == 0)
{ {
// In case we're running in Linux, chmod all directories in the work dir recursively so the scanner can access their files // In case we're running in Linux, chmod all directories in the work dir recursively so the scanner can access their files
chmodDirsRecursive(workDir, 0x1fd); // Octal 775, rwxrwxr-x chmodDirsRecursive(workDir, 0x1fd, 0x1b6); // Octal 775, rwxrwxr-x, and octal 666, rw-rw-rw-
console.print(gOKStrWithNewline); console.print(gOKStrWithNewline);
// Scan the files in the work directory. // Scan the files in the work directory.
printf(gStatusPrintfStr, "r", "Scanning files inside the archive for viruses..."); printf(gStatusPrintfStr, "\1r", "Scanning files inside the archive for viruses...");
var retObj = scanFilesInDir(workDir); var retObj = scanFilesInDir(workDir);
retval = retObj.returnCode; retval = retObj.returnCode;
if (retObj.returnCode == 0) if (retObj.returnCode == 0)
...@@ -319,7 +325,7 @@ function processFile(pFilename) ...@@ -319,7 +325,7 @@ function processFile(pFilename)
else else
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
console.print("nyhVirus scan failed.(1) Scan output:n\r\n"); console.print("\1n\1y\1hVirus scan failed.(1) Scan output:\1n\r\n");
for (var index = 0; index < retObj.cmdOutput.length; ++index) for (var index = 0; index < retObj.cmdOutput.length; ++index)
{ {
console.print(retObj.cmdOutput[index]); console.print(retObj.cmdOutput[index]);
...@@ -331,7 +337,7 @@ function processFile(pFilename) ...@@ -331,7 +337,7 @@ function processFile(pFilename)
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
// Scan the files in the work directory. // Scan the files in the work directory.
console.print("nyhWarning: nwh Unable to extract to work dir.n\r\n"); console.print("\1n\1y\1hWarning: \1n\1w\1h Unable to extract to work dir.\1n\r\n");
retval = -2; retval = -2;
} }
} }
...@@ -341,7 +347,7 @@ function processFile(pFilename) ...@@ -341,7 +347,7 @@ function processFile(pFilename)
else else
{ {
// The file has no extract command, so just scan it. // The file has no extract command, so just scan it.
printf(gStatusPrintfStr, "bh", "Scanning..."); printf(gStatusPrintfStr, "\1b\1h", "Scanning...");
var scanCmd = gGenCfg.scanCmd.replace("%FILESPEC%", "\"" + fixPathSlashes(pFilename) + "\""); var scanCmd = gGenCfg.scanCmd.replace("%FILESPEC%", "\"" + fixPathSlashes(pFilename) + "\"");
// Run the scan command and capture its output, in case the scan fails. // Run the scan command and capture its output, in case the scan fails.
var retObj = runExternalCmdWithOutput(scanCmd); var retObj = runExternalCmdWithOutput(scanCmd);
...@@ -351,7 +357,7 @@ function processFile(pFilename) ...@@ -351,7 +357,7 @@ function processFile(pFilename)
else else
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
console.print("nyhVirus scan failed.(2) Scan output:n\r\n"); console.print("\1n\1y\1hVirus scan failed.(2) Scan output:\1n\r\n");
for (var index = 0; index < retObj.cmdOutput.length; ++index) for (var index = 0; index < retObj.cmdOutput.length; ++index)
{ {
console.print(retObj.cmdOutput[index]); console.print(retObj.cmdOutput[index]);
...@@ -366,7 +372,7 @@ function processFile(pFilename) ...@@ -366,7 +372,7 @@ function processFile(pFilename)
else else
{ {
// There's nothing configured for the file's extension, so just scan it. // There's nothing configured for the file's extension, so just scan it.
printf(gStatusPrintfStr, "r", "Scanning..."); printf(gStatusPrintfStr, "\1r", "Scanning...");
var scanCmd = gGenCfg.scanCmd.replace("%FILESPEC%", "\"" + fixPathSlashes(pFilename) + "\""); var scanCmd = gGenCfg.scanCmd.replace("%FILESPEC%", "\"" + fixPathSlashes(pFilename) + "\"");
var retObj = runExternalCmdWithOutput(scanCmd); var retObj = runExternalCmdWithOutput(scanCmd);
retval = retObj.returnCode; retval = retObj.returnCode;
...@@ -375,7 +381,7 @@ function processFile(pFilename) ...@@ -375,7 +381,7 @@ function processFile(pFilename)
else else
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
console.print("nyhVirus scan failed.(3) Scan output:n\r\n"); console.print("\1n\1y\1hVirus scan failed.(3) Scan output:\1n\r\n");
for (var index = 0; index < retObj.cmdOutput.length; ++index) for (var index = 0; index < retObj.cmdOutput.length; ++index)
{ {
console.print(retObj.cmdOutput[index]); console.print(retObj.cmdOutput[index]);
...@@ -996,6 +1002,7 @@ function runExternalCmdWithOutput(pCommand) ...@@ -996,6 +1002,7 @@ function runExternalCmdWithOutput(pCommand)
scriptFile.writeln(pCommand); scriptFile.writeln(pCommand);
scriptFile.close(); scriptFile.close();
wroteScriptFile = true; wroteScriptFile = true;
if (!gRunningInWindows)
file_chmod(scriptFilename, 775); // rwxrwxr-x file_chmod(scriptFilename, 775); // rwxrwxr-x
retObj = execCmdWithOutput("bash " + scriptFilename); retObj = execCmdWithOutput("bash " + scriptFilename);
} }
...@@ -1019,21 +1026,27 @@ function runExternalCmdWithOutput(pCommand) ...@@ -1019,21 +1026,27 @@ function runExternalCmdWithOutput(pCommand)
return retObj; return retObj;
} }
// Changes the mode value of a directory and all of its subdirectories recursively // Changes the mode value of a directory and its files, and all files in its subdirectories recursively.
// This is mainly for Linux and *nix-type operating systems.
// //
// Parameters: // Parameters:
// pBaseDir: The directory to chmod recursively (along with all of its subdirectories) // pBaseDir: The directory to chmod recursively (along with all of its subdirectories)
// pMode: The mode value (number) to apply // pDirMode: The mode value (number) to apply to directories
function chmodDirsRecursive(pBaseDir, pMode) // pFileMode: The mode value (number) to apply to files (non-directories)
function chmodDirsRecursive(pBaseDir, pDirMode, pFileMode)
{ {
if (typeof(pBaseDir) !== "string" || !file_isdir(pBaseDir) || typeof(pMode) !== "number") if (gRunningInWindows || typeof(pBaseDir) !== "string" || !file_isdir(pBaseDir) || typeof(pDirMode) !== "number")
return; return;
file_chmod(pBaseDir, pMode); file_chmod(pBaseDir, pDirMode);
var fileEntries = directory(backslash(pBaseDir) + "*"); var fileEntries = directory(backslash(pBaseDir) + "*");
for (var i = 0; i < fileEntries.length; ++i) for (var i = 0; i < fileEntries.length; ++i)
{ {
if (file_isdir(fileEntries[i])) if (file_isdir(fileEntries[i]))
chmodDirsRecursive(fileEntries[i], pMode); {
chmodDirsRecursive(fileEntries[i], pDirMode, pFileMode);
}
else
file_chmod(fileEntries[i], pFileMode);
} }
} }
\ No newline at end of file
Digital Distortion Upload Processor Digital Distortion Upload Processor
Version 1.01 Version 1.02
Release date: 2022-06-08 Release date: 2022-06-11
by by
......
...@@ -2,5 +2,8 @@ Revision History for Digital Distortion Upload Processor ...@@ -2,5 +2,8 @@ Revision History for Digital Distortion Upload Processor
======================================================== ========================================================
Version Date Description Version Date Description
------- ---- ----------- ------- ---- -----------
1.02 2022-06-11 For Linux, after extracting an archive, sets file
permissions too (in addition to directories which were
being set already) so that all the files are readable
1.01 2022-06-08 Updated so that the scanning works properly in Linux 1.01 2022-06-08 Updated so that the scanning works properly in Linux
1.00 2009-12-29 First general public release 1.00 2009-12-29 First general public release
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment