Skip to content

Commit

Permalink
Merge pull request #883 from mickem/fixing_deleted_config_on_upgrade
Browse files Browse the repository at this point in the history
Fixing deleted config on upgrade
  • Loading branch information
mickem authored Feb 8, 2025
2 parents ed676b3 + c28d8f6 commit fcf318a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ endif(WIN32)

# ##############################################################################
#
# Setup c/C++ build enviornment and flags
# Setup c/C++ build environment and flags
#
# ##############################################################################
set(NSCP_INCLUDEDIR ${CMAKE_SOURCE_DIR}/include)
Expand Down
28 changes: 14 additions & 14 deletions docs/docs/reference/generic/WEBServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ Section for WEB (WEBServer.dll) (check_WEB) protocol options.



| Key | Default Value | Description |
|-----------------------------------------------------|---------------|-----------------------------|
| [allowed hosts](#allowed-hosts) | 127.0.0.1 | Allowed hosts |
| [cache allowed hosts](#cache-list-of-allowed-hosts) | true | Cache list of allowed hosts |
| [certificate](#tls-certificate) | none | TLS Certificate |
| [password](#password) | | Password |
| [port](#server-port) | 8080 | Server port |
| [threads](#server-threads) | 10 | Server threads |
| Key | Default Value | Description |
|-----------------------------------------------------|-------------------------------------|-----------------------------|
| [allowed hosts](#allowed-hosts) | 127.0.0.1 | Allowed hosts |
| [cache allowed hosts](#cache-list-of-allowed-hosts) | true | Cache list of allowed hosts |
| [certificate](#tls-certificate) | ${certificate-path}/certificate.pem | TLS Certificate |
| [password](#password) | | Password |
| [port](#server-port) | 8443 | Server port |
| [threads](#server-threads) | 10 | Server threads |



Expand All @@ -319,8 +319,8 @@ Section for WEB (WEBServer.dll) (check_WEB) protocol options.
[/settings/WEB/server]
allowed hosts=127.0.0.1
cache allowed hosts=true
certificate=none
port=8080
certificate=${certificate-path}/certificate.pem
port=8443
threads=10

```
Expand Down Expand Up @@ -395,7 +395,7 @@ Ssl certificate to use for the ssl server
|----------------|-----------------------------------------------|
| Path: | [/settings/WEB/server](#/settings/WEB/server) |
| Key: | certificate |
| Default value: | `none` |
| Default value: | `${certificate-path}/certificate.pem` |
| Used by: | WEBServer |


Expand All @@ -404,7 +404,7 @@ Ssl certificate to use for the ssl server
```
[/settings/WEB/server]
# TLS Certificate
certificate=none
certificate=${certificate-path}/certificate.pem
```


Expand Down Expand Up @@ -449,7 +449,7 @@ Port to use for WEB server.
|----------------|-----------------------------------------------|
| Path: | [/settings/WEB/server](#/settings/WEB/server) |
| Key: | port |
| Default value: | `8080` |
| Default value: | `8443` |
| Used by: | WEBServer |


Expand All @@ -458,7 +458,7 @@ Port to use for WEB server.
```
[/settings/WEB/server]
# Server port
port=8080
port=8443
```


Expand Down
37 changes: 31 additions & 6 deletions installer_lib/installer_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,22 @@ extern "C" UINT __stdcall ScheduleWriteConfig (MSIHANDLE hInstall) {
h.logMessage(L"Configuration changes not allowed: set CONF_CAN_CHANGE=1");
return ERROR_SUCCESS;
}

std::wstring target = h.getTargetPath(L"INSTALLLOCATION");
boost::filesystem::wpath backup = boost::filesystem::temp_directory_path() / boost::filesystem::unique_path();
boost::filesystem::wpath target_path = target;
boost::filesystem::wpath config_file = target_path / L"nsclient.ini";
if (boost::filesystem::exists(config_file)) {
h.logMessage(L"Config file found: " + config_file.wstring());
h.logMessage(L"Backup file: " + backup.wstring());
copy_file(h, config_file.wstring(), backup.wstring());
}

msi_helper::custom_action_data_w data;
data.write_string(h.getTargetPath(L"INSTALLLOCATION"));
data.write_string(h.getPropery(KEY_CONFIGURATION_TYPE));
data.write_string(h.getPropery(L"RESTORE_FILE"));
data.write_string(h.getPropery(L"RESTORE_FILE"));
data.write_string(backup.wstring());
data.write_int(h.getPropery(L"ADD_DEFAULTS")==L"1"?1:0);

std::wstring confInclude = h.getPropery(KEY_CONF_INCLUDES);
Expand Down Expand Up @@ -774,27 +786,40 @@ extern "C" UINT __stdcall ExecWriteConfig (MSIHANDLE hInstall) {
std::wstring target = data.get_next_string();
std::wstring context_w = data.get_next_string();
std::string context = utf8::cvt<std::string>(context_w);
std::wstring restore = data.get_next_string();
std::wstring restore = data.get_next_string();
std::wstring backup = data.get_next_string();
int add_defaults = data.get_next_int();

h.logMessage(L"Target: " + target);
h.logMessage("Context: " + context);
h.logMessage(L"Restore: " + restore);
h.logMessage(L"Restore: " + restore);
h.logMessage(L"Backup: " + backup);

boost::filesystem::path path = target;
boost::filesystem::path old_path = path / "nsc.ini.old";
path = path / "nsc.ini";

boost::filesystem::path restore_path = restore;
boost::filesystem::path restore_path = restore;

boost::filesystem::path backup_path = backup;

if (boost::filesystem::exists(old_path))
h.logMessage(L"Found old (.old) file: " + strEx::xtos(boost::filesystem::file_size(old_path)));
if (boost::filesystem::exists(path))
h.logMessage(L"Found old file: " + strEx::xtos(boost::filesystem::file_size(path)));
if (boost::filesystem::exists(restore_path))
h.logMessage(L"Found restore file: " + strEx::xtos(boost::filesystem::file_size(restore_path)));

if (boost::filesystem::exists(backup_path)) {
h.logMessage(L"Found Backup file: " + strEx::xtos(boost::filesystem::file_size(backup_path)));
boost::filesystem::path config_path = path / "nsclient.ini";
h.logMessage(L"Restoring from backup: " + backup_path.wstring());
copy_file(h, backup_path.wstring(), path.wstring());
if (!boost::filesystem::remove(backup_path)) {
h.errorMessage(L"Failed to remove backup file: " + backup_path.wstring());
}
}

if (boost::filesystem::exists(restore_path)) {
h.logMessage(L"Found restore file: " + strEx::xtos(boost::filesystem::file_size(restore_path)));
h.logMessage(L"Restore path exists: " + restore);
if (!boost::filesystem::exists(path)) {
h.logMessage(L"Restoring nsc.ini configuration file");
Expand Down
5 changes: 0 additions & 5 deletions installers/installer-NSCP/RUNTIME_DLL.wxs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
<File Id="BOOST_SYS" Name="boost_system.dll" DiskId="1" Source="$(var.Source)/boost_system.dll" Vital="yes" />
<File Id="BOOST_T" Name="boost_thread.dll" DiskId="1" Source="$(var.Source)/boost_thread.dll" Vital="yes" />
<File Id="PROTOBUF" Name="libprotobuf.dll" DiskId="1" Source="$(var.Source)/libprotobuf.dll" Vital="yes" />
<!--
<File Id="SSL1" Name="$(var.OpenSSlCrypto)" DiskId="1" Source="$(var.Source)/$(var.OpenSSlCrypto)" Vital="yes" />
<File Id="SSL2" Name="$(var.OpenSSlLib)" DiskId="1" Source="$(var.Source)/$(var.OpenSSlLib)" Vital="yes" />
-->

</Component>
<Component Id="LibNSCP" Guid="365EF37C-49D4-4903-9EF7-A221F0915FB2">
<File Id="NSCP_PLUG" Name="plugin_api.dll" DiskId="1" Source="$(var.Source)/plugin_api.dll" Vital="yes" />
Expand Down
4 changes: 2 additions & 2 deletions modules/WEBServer/WEBServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ bool WEBServer::loadModuleEx(std::string alias, NSCAPI::moduleLoadMode mode) {

;
settings.alias().add_key_to_settings()
("port", sh::string_key(&port, "8080"),
("port", sh::string_key(&port, "8443"),
"Server port", "Port to use for WEB server.")

("threads", sh::int_key(&threads, 10),
"Server threads", "The number of threads in the sever response pool.")
;
settings.alias().add_key_to_settings()
("certificate", sh::string_key(&certificate, "none"),
("certificate", sh::string_key(&certificate, "${certificate-path}/certificate.pem"),
"TLS Certificate", "Ssl certificate to use for the ssl server")
;

Expand Down

0 comments on commit fcf318a

Please sign in to comment.