Skip to content
Snippets Groups Projects
Commit bdde52f7 authored by Eric Oulashin's avatar Eric Oulashin Committed by Rob Swindell
Browse files

Updated Digital Distortion Upload Processor so that the scanning works...

Updated Digital Distortion Upload Processor so that the scanning works properly in Linux (directory permissions)
parent d3e4c4ed
No related branches found
No related tags found
2 merge requests!463MRC mods by Codefenix (2024-10-20),!178Updated Digital Distortion Upload Processor so that the scanning works properly in Linux (directory permissions)
nhc Digital Distortion Upload Processor yvw1.00
hy For Synchronet 3.14+
kÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ
ncThis is an upload processor for Synchronet
that allows for performing a virus scan on
files inside of archives. File extraction
commands and the virus scan command are
configurable.
bhRelease date: 2009-12-29
\ No newline at end of file
File moved
...@@ -9,11 +9,13 @@ ...@@ -9,11 +9,13 @@
* BBS: Digital Distortion * BBS: Digital Distortion
* BBS address: digdist.bbsindex.com * BBS address: digdist.bbsindex.com
* *
* Date User Description * Date Author Description
* 2009-12-25- * 2009-12-25-
* 2009-12-28 Eric Oulashin Initial development * 2009-12-28 Eric Oulashin Initial development
* 2009-12-29 Eric Oulashin Version 1.00 * 2009-12-29 Eric Oulashin Version 1.00
* Initial public release * Initial public release
* 2022-06-08 Eric Oulashin Version 1.01
* Made fixes to get the scanner functionality working properly in Linux
*/ */
/* Command-line arguments: /* Command-line arguments:
...@@ -22,6 +24,13 @@ ...@@ -22,6 +24,13 @@
load("sbbsdefs.js"); load("sbbsdefs.js");
// Require version 3.17 or newer of Synchronet (for file_chmod())
if (system.version_num < 31700)
{
console.print("\1nDigital Distortion Upload Processor requires Synchronet 3.17 or newer.\r\n");
exit(1);
}
// Determine the script's execution directory. // Determine the script's execution directory.
// This code is a trick that was created by Deuce, suggested by Rob // This code is a trick that was created by Deuce, suggested by Rob
// Swindell as a way to detect which directory the script was executed // Swindell as a way to detect which directory the script was executed
...@@ -31,11 +40,14 @@ var gStartupPath = '.'; ...@@ -31,11 +40,14 @@ var gStartupPath = '.';
try { throw dig.dist(dist); } catch(e) { gStartupPath = e.fileName; } try { throw dig.dist(dist); } catch(e) { gStartupPath = e.fileName; }
gStartupPath = backslash(gStartupPath.replace(/[\/\\][^\/\\]*$/,'')); gStartupPath = backslash(gStartupPath.replace(/[\/\\][^\/\\]*$/,''));
load(gStartupPath + "DDUP_Cleanup.js"); load(gStartupPath + "ddup_cleanup.js");
// Version information // Version information
var gDDUPVersion = "1.00"; var gDDUPVersion = "1.01";
var gDDUPVerDate = "2009-12-29"; var gDDUPVerDate = "2022-06-08";
// Store whether or not this is running in Windows
var gRunningInWindows = /^WIN/.test(system.platform.toUpperCase());
// If the filename was specified on the command line, then use that // If the filename was specified on the command line, then use that
...@@ -92,11 +104,12 @@ if (gFileToScan.length == 0) ...@@ -92,11 +104,12 @@ if (gFileToScan.length == 0)
} }
// Create the global configuration objects. // Create the global configuration objects.
var gGenCfg = new Object(); var gGenCfg = {
gGenCfg.scanCmd = ""; scanCmd: "",
gGenCfg.skipScanIfSysop = false; skipScanIfSysop: false,
gGenCfg.pauseAtEnd = false; pauseAtEnd: false
var gFileTypeCfg = new Object(); };
var gFileTypeCfg = {};
// Read the configuration files to populate the global configuration object. // Read the configuration files to populate the global configuration object.
var configFileRead = ReadConfigFile(gStartupPath); var configFileRead = ReadConfigFile(gStartupPath);
...@@ -271,6 +284,8 @@ function processFile(pFilename) ...@@ -271,6 +284,8 @@ function processFile(pFilename)
console.print("nyhWarning: nwh Unable to create the work dir.n\r\n"); console.print("nyhWarning: nwh Unable to create the work dir.n\r\n");
retval = -1; retval = -1;
} }
file_chmod(baseWorkDir, 0x1fd); // Octal 775, rwxrwxr-x
//chmodDirsRecursive(baseWorkDir, 0x1fd); // Octal 775, rwxrwxr-x
// 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";
...@@ -292,6 +307,8 @@ function processFile(pFilename) ...@@ -292,6 +307,8 @@ function processFile(pFilename)
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
chmodDirsRecursive(workDir, 0x1fd); // Octal 775, rwxrwxr-x
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, "r", "Scanning files inside the archive for viruses...");
...@@ -302,7 +319,7 @@ function processFile(pFilename) ...@@ -302,7 +319,7 @@ function processFile(pFilename)
else else
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
console.print("nyhVirus scan failed. Scan output:n\r\n"); console.print("nyhVirus scan failed.(1) Scan output:n\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]);
...@@ -334,7 +351,7 @@ function processFile(pFilename) ...@@ -334,7 +351,7 @@ function processFile(pFilename)
else else
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
console.print("nyhVirus scan failed. Scan output:n\r\n"); console.print("nyhVirus scan failed.(2) Scan output:n\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]);
...@@ -358,7 +375,7 @@ function processFile(pFilename) ...@@ -358,7 +375,7 @@ function processFile(pFilename)
else else
{ {
console.print(gFailStrWithNewline); console.print(gFailStrWithNewline);
console.print("nyhVirus scan failed. Scan output:n\r\n"); console.print("nyhVirus scan failed.(3) Scan output:n\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]);
...@@ -481,7 +498,7 @@ function ReadConfigFile(pCfgFilePath) ...@@ -481,7 +498,7 @@ function ReadConfigFile(pCfgFilePath)
{ {
// Read the file type settings. // Read the file type settings.
var fileTypeSettingsRead = false; var fileTypeSettingsRead = false;
var fileTypeCfgFile = new File(pCfgFilePath + "DDUPFileTypes.cfg"); var fileTypeCfgFile = new File(pCfgFilePath + "ddup_file_types.cfg");
if (fileTypeCfgFile.open("r")) if (fileTypeCfgFile.open("r"))
{ {
if (fileTypeCfgFile.length > 0) if (fileTypeCfgFile.length > 0)
...@@ -566,7 +583,7 @@ function ReadConfigFile(pCfgFilePath) ...@@ -566,7 +583,7 @@ function ReadConfigFile(pCfgFilePath)
// Read the general program configuration // Read the general program configuration
var genSettingsRead = false; var genSettingsRead = false;
var genCfgFile = new File(pCfgFilePath + "DDUP.cfg"); var genCfgFile = new File(pCfgFilePath + "ddup.cfg");
if (genCfgFile.open("r")) if (genCfgFile.open("r"))
{ {
if (genCfgFile.length > 0) if (genCfgFile.length > 0)
...@@ -728,11 +745,7 @@ function getPathFromFilename(pFilename) ...@@ -728,11 +745,7 @@ function getPathFromFilename(pFilename)
if (pFilename.length == 0) if (pFilename.length == 0)
return ""; return "";
// Determine which slash character to use for paths, depending var pathSlash = (gRunningInWindows ? "\\" : "/");
// on the OS.
if (getPathFromFilename.inWin == undefined)
getPathFromFilename.inWin = /^WIN/.test(system.platform.toUpperCase());
var pathSlash = (getPathFromFilename.inWin ? "\\" : "/");
// Make sure the filename has the correct slashes for // Make sure the filename has the correct slashes for
// the platform. // the platform.
...@@ -783,15 +796,10 @@ function fixPathSlashes(pPath) ...@@ -783,15 +796,10 @@ function fixPathSlashes(pPath)
if (pPath.length == 0) if (pPath.length == 0)
return ""; return "";
// Create a variable to store whether or not we're in Windows,
// but only once (for speed).
if (fixPathSlashes.inWin == undefined)
fixPathSlashes.inWin = /^WIN/.test(system.platform.toUpperCase());
// Fix the slashes and return the fixed version. // Fix the slashes and return the fixed version.
//return(fixPathSlashes.inWin ? pPath.replace("/", "\\") : pPath.replace("\\", "/")); //return(gRunningInWindows ? pPath.replace("/", "\\") : pPath.replace("\\", "/"));
var path = pPath; var path = pPath;
if (fixPathSlashes.inWin) // Windows if (gRunningInWindows) // Windows
{ {
while (path.indexOf("/") > -1) while (path.indexOf("/") > -1)
path = path.replace("/", "\\"); path = path.replace("/", "\\");
...@@ -956,17 +964,13 @@ function execCmdWithOutput(pCommand) ...@@ -956,17 +964,13 @@ function execCmdWithOutput(pCommand)
// cmdOutput: An array of strings containing the program's output. // cmdOutput: An array of strings containing the program's output.
function runExternalCmdWithOutput(pCommand) function runExternalCmdWithOutput(pCommand)
{ {
// Determine whether or not we're in Windows.
if (runExternalCmdWithOutput.inWin == undefined)
runExternalCmdWithOutput.inWin = /^WIN/.test(system.platform.toUpperCase());
var retObj = null; // The return object var retObj = null; // The return object
var wroteScriptFile = false; // Whether or not we were able to write the script file var wroteScriptFile = false; // Whether or not we were able to write the script file
// In the node directory, write a batch file (if in Windows) or a *nix shell // In the node directory, write a batch file (if in Windows) or a *nix shell
// script (if not in Windows) containing the command to run. // script (if not in Windows) containing the command to run.
var scriptFilename = ""; var scriptFilename = "";
if (runExternalCmdWithOutput.inWin) if (gRunningInWindows)
{ {
// Write a Windows batch file to run the command // Write a Windows batch file to run the command
scriptFilename = fixPathSlashes(system.node_dir + "DDUP_ScanCmd.bat"); scriptFilename = fixPathSlashes(system.node_dir + "DDUP_ScanCmd.bat");
...@@ -992,7 +996,7 @@ function runExternalCmdWithOutput(pCommand) ...@@ -992,7 +996,7 @@ function runExternalCmdWithOutput(pCommand)
scriptFile.writeln(pCommand); scriptFile.writeln(pCommand);
scriptFile.close(); scriptFile.close();
wroteScriptFile = true; wroteScriptFile = true;
system.exec("chmod ugo+x " + scriptFilename); file_chmod(scriptFilename, 775); // rwxrwxr-x
retObj = execCmdWithOutput("bash " + scriptFilename); retObj = execCmdWithOutput("bash " + scriptFilename);
} }
} }
...@@ -1006,10 +1010,30 @@ function runExternalCmdWithOutput(pCommand) ...@@ -1006,10 +1010,30 @@ function runExternalCmdWithOutput(pCommand)
if (!wroteScriptFile) if (!wroteScriptFile)
{ {
// Could not open the script file for writing // Could not open the script file for writing
retObj = new Object(); retObj = {
retObj.cmdOutput = new Array(); cmdOutput: [],
retObj.returnCode = -1; returnCode: -1
};
} }
return retObj; return retObj;
} }
// Changes the mode value of a directory and all of its subdirectories recursively
//
// Parameters:
// pBaseDir: The directory to chmod recursively (along with all of its subdirectories)
// pMode: The mode value (number) to apply
function chmodDirsRecursive(pBaseDir, pMode)
{
if (typeof(pBaseDir) !== "string" || !file_isdir(pBaseDir) || typeof(pMode) !== "number")
return;
file_chmod(pBaseDir, pMode);
var fileEntries = directory(backslash(pBaseDir) + "*");
for (var i = 0; i < fileEntries.length; ++i)
{
if (file_isdir(fileEntries[i]))
chmodDirsRecursive(fileEntries[i], pMode);
}
}
\ No newline at end of file
Digital Distortion Upload Processor Digital Distortion Upload Processor
Version 1.00 Version 1.01
Release date: 2009-12-29 Release date: 2022-06-08
by by
Eric Oulashin Eric Oulashin
Sysop of Digital Distortion BBS Sysop of Digital Distortion BBS
BBS internet address: digitaldistortionbbs.com BBS internet address: digdist.bbsindex.com
digdist.bbsindex.com
Email: eric.oulashin@gmail.com Email: eric.oulashin@gmail.com
...@@ -22,6 +21,7 @@ Contents ...@@ -22,6 +21,7 @@ Contents
4. Installation and Setup 4. Installation and Setup
5. Main configuration file 5. Main configuration file
6. Archive file type configuration file 6. Archive file type configuration file
7. Revision History
1. Disclaimer 1. Disclaimer
...@@ -90,19 +90,17 @@ EXTRACT command lines set properly for your system. For information on ...@@ -90,19 +90,17 @@ EXTRACT command lines set properly for your system. For information on
that configuration file, see section 6: Archive file type configuration that configuration file, see section 6: Archive file type configuration
file. file.
The following archive contains Win32 command-line archivers for popular Win32 command-line archivers have been included with this script for
archive file formats: convenience. Those archivers have been set up in DDUPFileTypes.cfg
http://digdist.bbsindex.com/miscFilesForDL/Win32CmdLineCompressionTools.zip to extract popular file formats (ZIP, 7Z (7-Zip), RAR, ARJ, MSI, TAR,
The archivers included in that archive handle the most popular file formats GZ, TGZ, and TAR.GZ). The Win32 archivers are in the Win32Archivers
(ZIP, 7Z (7-Zip), RAR, ARJ, TAR, GZ, TGZ, and TAR.GZ), and they are set up in directory. So if your BBS is running in Windows, the included
DDUPFileTypes.cfg to extract popular file formats (ZIP, 7Z (7-Zip), RAR, ARJ, configuration file should work for you (although it does also have the
MSI, TAR, GZ, TGZ, and TAR.GZ). Note that you will need to edit that .cfg Linux command lines as comments). You will need to copy the files from
file and change the path to the .exe file according to where you copied them the Win32Archivers directory to a directory in your path or another
on your system. If your BBS is running in Windows, the included configuration directory of your choice. If you copy them to a directory that is not
file should work for you (although it does also have the Linux command lines in your path, you will need to edit the DDUPFileTypes.cfg file to include
as comments). If you copy the archivers to a directory that is not in your the full paths with the archive executables.
system path, you will need to edit the DDUPFileTypes.cfg file to include the
full paths with the archive executables.
Extractor notes: Extractor notes:
DDUPFileTypes.cfg includes a setup for using 7-Zip to extract ISO (CD/DVD DDUPFileTypes.cfg includes a setup for using 7-Zip to extract ISO (CD/DVD
...@@ -341,3 +339,10 @@ uploads D:\Files\someArchive.zip and your Synchronet installation is located ...@@ -341,3 +339,10 @@ uploads D:\Files\someArchive.zip and your Synchronet installation is located
in D:\sbbs, the temp directory is D:\sbbs\node1\DDUploadProcessor_Temp, and in D:\sbbs, the temp directory is D:\sbbs\node1\DDUploadProcessor_Temp, and
the extract command will be translated to the following: the extract command will be translated to the following:
unzip.exe -qq -o D:\Files\someArchive.zip -d D:\sbbs\node1\DDUploadProcessor_Temp unzip.exe -qq -o D:\Files\someArchive.zip -d D:\sbbs\node1\DDUploadProcessor_Temp
7. Revision History
===================
Version Date Description
------- ---- -----------
1.00 2009-12-29 First general public release
\ No newline at end of file
...@@ -2,4 +2,5 @@ Revision History for Digital Distortion Upload Processor ...@@ -2,4 +2,5 @@ Revision History for Digital Distortion Upload Processor
======================================================== ========================================================
Version Date Description Version Date Description
------- ---- ----------- ------- ---- -----------
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
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment