Skip to content

Commit

Permalink
Added tool to import project as zip on Windows platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
riclolsen committed Oct 10, 2024
1 parent 923313d commit 0054cfe
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 17 deletions.
12 changes: 8 additions & 4 deletions conf/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ As you can have multiple JSON-SCADA systems in the same computer server, each in
}

* **_nodeName_** - Unique name for a computer installation. This name will be used to match the node configuration in the database. This name is used also to control processes on redundant computers. **Mandatory parameter**.
* **_mongoConnectionString_** - Standard MongoDB connection string pointing to the database server.
See https://docs.mongodb.com/manual/reference/connection-string/. **Mandatory parameter**
* **_mongoConnectionString_** - Standard MongoDB URI connection string pointing to the database server. Please include the database name in this URI string (the same db name from the next parameter) and TLS options. See https://docs.mongodb.com/manual/reference/connection-string/. **Mandatory parameter**
* **_mongoDatabaseName_** - Database name to be accessed in the MongoDB server. **Mandatory parameter**.

The TLS parameters below are necessary for secure connecions, anyway please include the equivalent TLS options directly in the URI connection string. See https://www.mongodb.com/pt-br/docs/manual/reference/connection-string-options/#std-label-connections-connection-options.

If you encounter secure connection problems, please report your findings.

* **_tlsCaPemFile_** - Path/Name of the certificate root CA PEM file. **Optional parameter, required for TLS connection**.
* **_tlsClientPemFile_** - Path/Name of the client certificate PEM file. **Optional parameter, required for TLS connection**.
* **_tlsClientPfxFile_** - Path/Name of the client certificate PFX file. **Optional parameter, required for TLS connection**.
Expand All @@ -40,9 +44,9 @@ To use MongoDB authorization, specify the database user and password in the conn

To encrypt connections to the database with TLS it is necessary to create and specify certificates in the config file that can be accepted by the MongoDB server. This is important for connections over the Internet and untrusted networks.

MongoDB servers can be Community, Enterprise or Atlas Cloud, all on 4.2 or later version. Other servers are not tested.
MongoDB servers can be Community, Enterprise or Atlas Cloud, all on 6.0 or later version. Other servers are not tested or supported.

The hostname(s) used in the connection string must match the hostnames for the MongoDB replica set members. The hostname must be available via DNS or be present in the server's _/etc/hosts_ file. A replica set is mandatory for the change streams to work and must be created with at least one member. A three member replica set is highly recommended for redundancy.
The hostname(s) used in the connection string must match the hostnames for the MongoDB replica set members. The hostname must be available via DNS or be present in the server's _/etc/hosts_ file. A replica set is mandatory for the change streams to work and must be created with at least one member. A three member replica set is highly recommended for redundancy and high availability.

## Creating self-signed certificates

Expand Down
46 changes: 33 additions & 13 deletions platform-windows/export_project.bat
Original file line number Diff line number Diff line change
@@ -1,33 +1,53 @@
@ECHO OFF
set JSPATH=c:\json-scada
set TMPPATH=%JSPATH%\tmp
set DATABASE=json_scada
set MONGO_CONNECT_STRING=mongodb://192.168.239.133/?tls=false&directConnection=true
set MONGOBIN=%JSPATH%\platform-windows\mongodb-runtime\bin
set JAVAPATH=%JSPATH%\platform-windows\jdk-runtime\bin
set TARPATH=%JSPATH%\platform-windows
set SVGPATH=%JSPATH%\src\AdminUI\dist\svg
set mongoConnectionString=mongodb://127.0.0.1/?tls=false&directConnection=true
set mongoConnectionString=mongodb://127.0.0.1/json_scada?tls=false&directConnection=true
set database=json_scada
set tlsCaPemFile=
set tlsClientPemFile=
set tlsClientKeyFile=
set tlsClientPfxFile=
set tlsClientKeyPassword=
set tlsAllowInvalidHostnames=true
set tlsAllowChainErrors=true
set tlsInsecure=false

cd %JSPATH%\platform-windows\

IF [%1]==[] ( SET "OUTPUTFILE=jsproject.zip" ) ELSE ( SET "OUTPUTFILE=%1" )

for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json mongoConnectionString') do set "mongoConnectionString=%%~a"
for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json database') do set "database=%%~a"

mkdir %TMPPATH%
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsCaPemFile') do set "tlsCaPemFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientPemFile') do set "tlsClientPemFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientKeyFile') do set "tlsClientKeyFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientPfxFile') do set "tlsClientPfxFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientKeyPassword') do set "tlsClientKeyPassword=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsAllowInvalidHostnames') do set "tlsAllowInvalidHostnames=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsAllowChainErrors') do set "tlsAllowChainErrors=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsInsecure') do set "tlsInsecure=%%~a"
rem set TLSFLAGS=--sslCAFile=%tlsCaPemFile% --sslPEMKeyFile=%tlsClientPemFile% --sslPEMKeyPassword=%tlsClientKeyPassword% --sslAllowInvalidHostnames=%tlsAllowInvalidHostnames% --sslAllowInvalidCertificates=%tlsAllowChainErrors%
rem echo "%TLSFLAGS%"

if not exist "%TMPPATH%" mkdir "%TMPPATH%"
del %TMPPATH%\*.* /Q
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection realtimeData --out %TMPPATH%\realtimeData.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection processInstances --out %TMPPATH%\processInstances.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection protocolDriverInstances --out %TMPPATH%\protocolDriverInstances
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection protocolConnections --out %TMPPATH%\protocolConnections.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection users --out %TMPPATH%\users.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection roles --out %TMPPATH%\roles.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection realtimeData --out %TMPPATH%\realtimeData.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection processInstances --out %TMPPATH%\processInstances.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection protocolDriverInstances --out %TMPPATH%\protocolDriverInstances.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection protocolConnections --out %TMPPATH%\protocolConnections.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection users --out %TMPPATH%\users.json
%MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection roles --out %TMPPATH%\roles.json
rem optional historical data
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection hist --out %TMPPATH%\hist.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection backfillData --out %TMPPATH%\backfillData.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection soeData --out %TMPPATH%\soeData.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %DATABASE% --collection userActions --out %TMPPATH%\userActions.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection hist --out %TMPPATH%\hist.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection backfillData --out %TMPPATH%\backfillData.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection soeData --out %TMPPATH%\soeData.json
rem %MONGOBIN%\mongoexport.exe --uri "%mongoConnectionString%" --db %database% --collection userActions --out %TMPPATH%\userActions.json

copy %SVGPATH%\*.svg %TMPPATH%\
copy %SVGPATH%\screen_list.js %TMPPATH%\
Expand Down
75 changes: 75 additions & 0 deletions platform-windows/import_project.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
@ECHO OFF
set JSPATH=c:\json-scada
set TMPPATH=%JSPATH%\tmp
set MONGO_CONNECT_STRING=mongodb://192.168.239.133/?tls=false&directConnection=true
set MONGOBIN=%JSPATH%\platform-windows\mongodb-runtime\bin
set JAVAPATH=%JSPATH%\platform-windows\jdk-runtime\bin
set TARPATH=%JSPATH%\platform-windows
set SVGPATH=%JSPATH%\src\AdminUI\dist\svg
set mongoConnectionString=mongodb://127.0.0.1/json_scada?tls=false&directConnection=true
set database=json_scada
set tlsCaPemFile=
set tlsClientPemFile=
set tlsClientKeyFile=
set tlsClientPfxFile=
set tlsClientKeyPassword=
set tlsAllowInvalidHostnames=true
set tlsAllowChainErrors=true
set tlsInsecure=false

cd %JSPATH%\platform-windows\

IF [%1]==[] ( SET "INPUTFILE=jsproject.zip" ) ELSE ( SET "INPUTFILE=%1" )

for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json mongoConnectionString') do set "mongoConnectionString=%%~a"
for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json database') do set "database=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsCaPemFile') do set "tlsCaPemFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientPemFile') do set "tlsClientPemFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientKeyFile') do set "tlsClientKeyFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientPfxFile') do set "tlsClientPfxFile=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsClientKeyPassword') do set "tlsClientKeyPassword=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsAllowInvalidHostnames') do set "tlsAllowInvalidHostnames=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsAllowChainErrors') do set "tlsAllowChainErrors=%%~a"
rem for /f "tokens=* delims=" %%a in ('jsonextractor.bat ..\conf\json-scada.json tlsInsecure') do set "tlsInsecure=%%~a"
rem set TLSFLAGS=--sslCAFile=%tlsCaPemFile% --sslPEMKeyFile=%tlsClientPemFile% --sslPEMKeyPassword=%tlsClientKeyPassword% --sslAllowInvalidHostnames=%tlsAllowInvalidHostnames% --sslAllowInvalidCertificates=%tlsAllowChainErrors%
rem echo "%TLSFLAGS%"

if not exist "%TMPPATH%" mkdir "%TMPPATH%"
cd %TMPPATH%

del %TMPPATH%\*.json /Q
del %TMPPATH%\*.js /Q
del %TMPPATH%\*.svg /Q
del %TMPPATH%\*.conf /Q
del %TMPPATH%\*.xml /Q
del %TMPPATH%\*.ini /Q

%JAVAPATH%\jar -xf %INPUTFILE%

set FLAGS=--mode=upsert

%MONGOBIN%\mongosh --quiet --eval "db.realtimeData.deleteMany({})" "%mongoConnectionString%"
%MONGOBIN%\mongosh --quiet --eval "db.processInstances.deleteMany({})" "%mongoConnectionString%"
%MONGOBIN%\mongosh --quiet --eval "db.protocolConnections.deleteMany({})" "%mongoConnectionString%"
%MONGOBIN%\mongosh --quiet --eval "db.protocolDriverInstances.deleteMany({})" "%mongoConnectionString%"
%MONGOBIN%\mongosh --quiet --eval "db.users.deleteMany({})" "%mongoConnectionString%"
%MONGOBIN%\mongosh --quiet --eval "db.roles.deleteMany({})" "%mongoConnectionString%"

%MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection roles %FLAGS% --file roles.json
%MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection users %FLAGS% --file users.json
%MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection processInstances %FLAGS% --file processInstances.json
%MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection protocolDriverInstances %FLAGS% --file protocolDriverInstances.json
%MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection protocolConnections %FLAGS% --file protocolConnections.json
%MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection realtimeData %FLAGS% --file realtimeData.json
rem optional historical data
rem %MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection hist --file hist.json %FLAGS%
rem %MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection backfillData --file backfillData.json %FLAGS%
rem %MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection soeData --file soeData.json %FLAGS%
rem %MONGOBIN%\mongoimport.exe --uri "%mongoConnectionString%" --db %database% --collection userActions --file userActions.json %FLAGS%

copy %TMPPATH%\*.svg %SVGPATH%\*.svg /Y
copy %TMPPATH%\screen_list.js %SVGPATH%\ /Y
rem optional
rem copy %TMPPATH%\ %JSPATH%\conf\*.*

cd %JSPATH%\platform-windows\

0 comments on commit 0054cfe

Please sign in to comment.