mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-26 10:21:00 +00:00
refactor: make printer connection SSL agent-specific
This commit is contained in:
@@ -673,12 +673,7 @@ namespace Slic3r
|
||||
m_agent->disconnect_printer();
|
||||
it->second->reset();
|
||||
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
AppConfig* config = get_app_config();
|
||||
it->second->connect(config && config->get("enable_ssl_for_mqtt") == "true");
|
||||
#else
|
||||
it->second->connect(it->second->local_use_ssl);
|
||||
#endif
|
||||
it->second->connect();
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
}
|
||||
@@ -700,12 +695,7 @@ namespace Slic3r
|
||||
{
|
||||
BOOST_LOG_TRIVIAL(info) << "set_selected_machine: select new lan machine, dev_id =" << dev_id;
|
||||
it->second->reset();
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
AppConfig* config = get_app_config();
|
||||
it->second->connect(config && config->get("enable_ssl_for_mqtt") == "true");
|
||||
#else
|
||||
it->second->connect(it->second->local_use_ssl);
|
||||
#endif
|
||||
it->second->connect();
|
||||
it->second->set_lan_mode_connection_state(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2619,14 +2619,19 @@ void MachineObject::update_print_progress(const json& value)
|
||||
curr_task->task_progress = mc_print_percent;
|
||||
}
|
||||
|
||||
int MachineObject::connect(bool use_openssl)
|
||||
int MachineObject::connect()
|
||||
{
|
||||
if (get_dev_ip().empty()) return -1;
|
||||
std::string username = m_agent ? m_agent->default_lan_username() : std::string();
|
||||
std::string password = get_access_code();
|
||||
|
||||
std::string port;
|
||||
std::string host = Http::get_host_from_url(get_dev_ip(), &port);
|
||||
std::string input = get_dev_ip();
|
||||
|
||||
const bool use_ssl = input.rfind("https", 0) == 0;
|
||||
|
||||
// This strips out the http/https prefix
|
||||
std::string host = Http::get_host_from_url(input, &port);
|
||||
std::string ca_file;
|
||||
|
||||
if (GUI::wxGetApp().preset_bundle) {
|
||||
@@ -2639,6 +2644,7 @@ int MachineObject::connect(bool use_openssl)
|
||||
if (host.empty())
|
||||
host = get_dev_ip();
|
||||
|
||||
|
||||
if (m_agent) {
|
||||
try {
|
||||
PrinterConnectionParams params{
|
||||
@@ -2647,7 +2653,7 @@ int MachineObject::connect(bool use_openssl)
|
||||
port,
|
||||
username,
|
||||
password,
|
||||
use_openssl,
|
||||
use_ssl,
|
||||
ca_file
|
||||
};
|
||||
return m_agent->connect_printer(params);
|
||||
|
||||
@@ -678,7 +678,7 @@ public:
|
||||
|
||||
|
||||
/* machine mqtt apis */
|
||||
int connect(bool use_openssl = true);
|
||||
int connect();
|
||||
int disconnect();
|
||||
|
||||
json_diff print_json;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "NetworkAgentFactory.hpp"
|
||||
#include "NetworkAgent.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
@@ -264,8 +265,18 @@ int BBLPrinterAgent::connect_printer(const PrinterConnectionParams& params)
|
||||
auto& plugin = BBLNetworkPlugin::instance();
|
||||
auto agent = plugin.get_agent();
|
||||
auto func = plugin.get_connect_printer();
|
||||
#if !BBL_RELEASE_TO_PUBLIC
|
||||
const bool use_ssl_for_mqtt = GUI::wxGetApp().app_config &&
|
||||
GUI::wxGetApp().app_config->get_bool("enable_ssl_for_mqtt");
|
||||
#else
|
||||
bool use_ssl_for_mqtt = true;
|
||||
if (auto* dev_manager = GUI::wxGetApp().getDeviceManager()) {
|
||||
if (auto* machine = dev_manager->get_my_machine(params.dev_id))
|
||||
use_ssl_for_mqtt = machine->local_use_ssl;
|
||||
}
|
||||
#endif
|
||||
if (func && agent) {
|
||||
return func(agent, params.dev_id, params.host, params.username, params.password, params.use_ssl);
|
||||
return func(agent, params.dev_id, params.host, params.username, params.password, use_ssl_for_mqtt);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -34,13 +34,14 @@ struct AgentInfo {
|
||||
std::string description; ///< Brief description of the agent's capabilities, e.g. "Orca printer agent"
|
||||
};
|
||||
|
||||
struct PrinterConnectionParams {
|
||||
struct PrinterConnectionParams
|
||||
{
|
||||
std::string dev_id;
|
||||
std::string host;
|
||||
std::string port;
|
||||
std::string host; // host address, usually the IP address without the http/https protocol
|
||||
std::string port; // optional
|
||||
std::string username;
|
||||
std::string password;
|
||||
bool use_ssl = false;
|
||||
bool use_ssl = false; // indicates if http or https
|
||||
std::string ca_file;
|
||||
};
|
||||
|
||||
|
||||
@@ -1056,9 +1056,7 @@ bool MoonrakerPrinterAgent::init_device_info(const std::string& dev_id, const st
|
||||
device_info.api_key = password;
|
||||
device_info.model_name = printer_cfg.opt_string("printer_model");
|
||||
device_info.model_id = preset.get_printer_type(preset_bundle);
|
||||
device_info.base_url = normalize_base_url(dev_ip, port);
|
||||
if (use_ssl && boost::istarts_with(device_info.base_url, "http://"))
|
||||
device_info.base_url.replace(0, 7, "https://");
|
||||
device_info.base_url = normalize_base_url(use_ssl, dev_ip, port);
|
||||
device_info.dev_id = dev_id;
|
||||
device_info.version = "";
|
||||
device_info.dev_name = device_info.dev_id;
|
||||
@@ -2107,26 +2105,11 @@ bool MoonrakerPrinterAgent::is_numeric(const std::string& value)
|
||||
return !value.empty() && std::all_of(value.begin(), value.end(), [](unsigned char c) { return std::isdigit(c) != 0; });
|
||||
}
|
||||
|
||||
std::string MoonrakerPrinterAgent::normalize_base_url(std::string host, const std::string& port)
|
||||
std::string MoonrakerPrinterAgent::normalize_base_url(bool use_ssl, const std::string& host, const std::string& port)
|
||||
{
|
||||
boost::trim(host);
|
||||
if (host.empty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string value = host;
|
||||
if (is_numeric(port) && value.find("://") == std::string::npos && value.find(':') == std::string::npos) {
|
||||
value += ":" + port;
|
||||
}
|
||||
|
||||
if (!boost::istarts_with(value, "http://") && !boost::istarts_with(value, "https://")) {
|
||||
value = "http://" + value;
|
||||
}
|
||||
|
||||
if (value.size() > 1 && value.back() == '/') {
|
||||
value.pop_back();
|
||||
}
|
||||
|
||||
std::string value = use_ssl ? "https://" : "http://";
|
||||
value += host;
|
||||
value += port.empty() ? "" : (":" + port);
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ protected:
|
||||
|
||||
// Helpers
|
||||
bool is_numeric(const std::string& value);
|
||||
std::string normalize_base_url(std::string host, const std::string& port);
|
||||
std::string normalize_base_url(bool use_ssl, const std::string& host, const std::string& port);
|
||||
std::string sanitize_filename(const std::string& filename);
|
||||
std::string join_url(const std::string& base_url, const std::string& path) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user