mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-31 04:31:15 -06:00 
			
		
		
		
	Follow-up to OctoPrint upload: ignore certificate revocation checks
6b03b66167
Renamed the new "printhost_ignore_check" option to "printhost_ssl_ignore_revoke"
Improved the Physical Printers dialog in regard to the new option checkbox
(added tooltip to the checkbox, moved it to the end of options).
Disabled the host_xxx options at the command line interface, they no
more work after these options were separated to Physical Printers profiles.
Little refactoring of Http.cpp/hpp, OctoPrint.cpp/hpp
Private local variables prefixed with m_, some renaming for clarity.This commit is contained in:
		
							parent
							
								
									c029cd44a4
								
							
						
					
					
						commit
						d3f11a6ab7
					
				
					 7 changed files with 82 additions and 66 deletions
				
			
		|  | @ -1408,7 +1408,7 @@ static std::vector<std::string> s_PhysicalPrinter_opts { | |||
|     // HTTP digest authentization (RFC 2617)
 | ||||
|     "printhost_user", | ||||
|     "printhost_password", | ||||
|     "printhost_ignore_check" | ||||
|     "printhost_ssl_ignore_revoke" | ||||
| }; | ||||
| 
 | ||||
| const std::vector<std::string>& PhysicalPrinter::printer_options() | ||||
|  |  | |||
|  | @ -232,6 +232,16 @@ void PrintConfigDef::init_common_params() | |||
|     def->mode = comAdvanced; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
| 
 | ||||
|     def = this->add("elefant_foot_compensation", coFloat); | ||||
|     def->label = L("Elephant foot compensation"); | ||||
|     def->category = L("Advanced"); | ||||
|     def->tooltip = L("The first layer will be shrunk in the XY plane by the configured value " | ||||
|                      "to compensate for the 1st layer squish aka an Elephant Foot effect."); | ||||
|     def->sidetext = L("mm"); | ||||
|     def->min = 0; | ||||
|     def->mode = comAdvanced; | ||||
|     def->set_default_value(new ConfigOptionFloat(0.)); | ||||
| 
 | ||||
|     def = this->add("thumbnails", coPoints); | ||||
|     def->label = L("G-code thumbnails"); | ||||
|     def->tooltip = L("Picture sizes to be stored into a .gcode and .sl1 / .sl1s files, in the following format: \"XxY, XxY, ...\""); | ||||
|  | @ -264,6 +274,7 @@ void PrintConfigDef::init_common_params() | |||
|                    "Print host behind HAProxy with basic auth enabled can be accessed by putting the user name and password into the URL " | ||||
|                    "in the following format: https://username:password@your-octopi-address/"); | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
| 
 | ||||
|     def = this->add("printhost_apikey", coString); | ||||
|  | @ -271,6 +282,7 @@ void PrintConfigDef::init_common_params() | |||
|     def->tooltip = L("Slic3r can upload G-code files to a printer host. This field should contain " | ||||
|                    "the API Key or the password required for authentication."); | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
|      | ||||
|     def = this->add("printhost_port", coString); | ||||
|  | @ -278,6 +290,7 @@ void PrintConfigDef::init_common_params() | |||
|     def->tooltip = L("Name of the printer"); | ||||
|     def->gui_type = ConfigOptionDef::GUIType::select_open; | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
|      | ||||
|     def = this->add("printhost_cafile", coString); | ||||
|  | @ -285,36 +298,32 @@ void PrintConfigDef::init_common_params() | |||
|     def->tooltip = L("Custom CA certificate file can be specified for HTTPS OctoPrint connections, in crt/pem format. " | ||||
|                    "If left blank, the default OS CA certificate repository is used."); | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
|      | ||||
|     def = this->add("elefant_foot_compensation", coFloat); | ||||
|     def->label = L("Elephant foot compensation"); | ||||
|     def->category = L("Advanced"); | ||||
|     def->tooltip = L("The first layer will be shrunk in the XY plane by the configured value " | ||||
|                      "to compensate for the 1st layer squish aka an Elephant Foot effect."); | ||||
|     def->sidetext = L("mm"); | ||||
|     def->min = 0; | ||||
|     def->mode = comAdvanced; | ||||
|     def->set_default_value(new ConfigOptionFloat(0.)); | ||||
| 
 | ||||
|     // Options used by physical printers
 | ||||
|      | ||||
|     def = this->add("printhost_user", coString); | ||||
|     def->label = L("User"); | ||||
| //    def->tooltip = L("");
 | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
|      | ||||
|     def = this->add("printhost_password", coString); | ||||
|     def->label = L("Password"); | ||||
| //    def->tooltip = L("");
 | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionString("")); | ||||
| 
 | ||||
|     def = this->add("printhost_ignore_check", coBool); | ||||
|     def->label = L("Ignore certificate revocation checks"); | ||||
|     //    def->tooltip = L("");
 | ||||
|     // Only available on Windows.
 | ||||
|     def = this->add("printhost_ssl_ignore_revoke", coBool); | ||||
|     def->label = L("Ignore HTTPS certificate revocation checks"); | ||||
|     def->tooltip = L("Ignore HTTPS certificate revocation checks in case of missing or offline distribution points. " | ||||
|                      "One may want to enable this option for self signed certificates if connection fails."); | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionBool(false)); | ||||
|      | ||||
|     def = this->add("preset_names", coStrings); | ||||
|  | @ -323,12 +332,6 @@ void PrintConfigDef::init_common_params() | |||
|     def->mode = comAdvanced; | ||||
|     def->set_default_value(new ConfigOptionStrings()); | ||||
| 
 | ||||
|     // temporary workaround for compatibility with older Slicer
 | ||||
|     { | ||||
|         def = this->add("preset_name", coString); | ||||
|         def->set_default_value(new ConfigOptionString()); | ||||
|     } | ||||
| 
 | ||||
|     def = this->add("printhost_authorization_type", coEnum); | ||||
|     def->label = L("Authorization Type"); | ||||
| //    def->tooltip = L("");
 | ||||
|  | @ -338,7 +341,14 @@ void PrintConfigDef::init_common_params() | |||
|     def->enum_labels.push_back(L("API key")); | ||||
|     def->enum_labels.push_back(L("HTTP digest")); | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionEnum<AuthorizationType>(atKeyPassword)); | ||||
| 
 | ||||
|     // temporary workaround for compatibility with older Slicer
 | ||||
|     { | ||||
|         def = this->add("preset_name", coString); | ||||
|         def->set_default_value(new ConfigOptionString()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void PrintConfigDef::init_fff_params() | ||||
|  | @ -1816,6 +1826,7 @@ void PrintConfigDef::init_fff_params() | |||
|     def->enum_labels.push_back("AstroBox"); | ||||
|     def->enum_labels.push_back("Repetier"); | ||||
|     def->mode = comAdvanced; | ||||
|     def->cli = ConfigOptionDef::nocli; | ||||
|     def->set_default_value(new ConfigOptionEnum<PrintHostType>(htOctoPrint)); | ||||
| 
 | ||||
|     def = this->add("only_retract_when_crossing_perimeters", coBool); | ||||
|  |  | |||
|  | @ -413,13 +413,6 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr | |||
|             return sizer; | ||||
|         }; | ||||
|         m_optgroup->append_line(line); | ||||
| 
 | ||||
| #ifdef WIN32 | ||||
|         option = m_optgroup->get_option("printhost_ignore_check"); | ||||
|         option.opt.width = Field::def_width_wider(); | ||||
|         m_optgroup->append_single_option_line(option); | ||||
| #endif | ||||
|         | ||||
|     } | ||||
| 
 | ||||
|     for (const std::string& opt_key : std::vector<std::string>{ "printhost_user", "printhost_password" }) {         | ||||
|  | @ -428,6 +421,12 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr | |||
|         m_optgroup->append_single_option_line(option); | ||||
|     } | ||||
| 
 | ||||
| #ifdef WIN32 | ||||
|     option = m_optgroup->get_option("printhost_ssl_ignore_revoke"); | ||||
|     option.opt.width = Field::def_width_wider(); | ||||
|     m_optgroup->append_single_option_line(option); | ||||
| #endif | ||||
| 
 | ||||
|     m_optgroup->activate(); | ||||
| 
 | ||||
|     Field* printhost_field = m_optgroup->get_field("print_host"); | ||||
|  |  | |||
|  | @ -491,7 +491,9 @@ Http& Http::form_add_file(const std::string &name, const fs::path &path, const s | |||
| 	return *this; | ||||
| } | ||||
| 
 | ||||
| Http& Http::revoke_best_effort(bool set) | ||||
| // Tells libcurl to ignore certificate revocation checks in case of missing or offline distribution points for those SSL backends where such behavior is present. 
 | ||||
| // This option is only supported for Schannel (the native Windows SSL library).
 | ||||
| Http& Http::ssl_revoke_best_effort(bool set) | ||||
| { | ||||
| 	if(p && set){ | ||||
| 		::curl_easy_setopt(p->curl, CURLOPT_SSL_OPTIONS, CURLSSLOPT_REVOKE_BEST_EFFORT); | ||||
|  |  | |||
|  | @ -80,7 +80,11 @@ public: | |||
| 	// Same as above except also override the file's filename with a custom one
 | ||||
| 	Http& form_add_file(const std::string &name, const boost::filesystem::path &path, const std::string &filename); | ||||
| 
 | ||||
| 	Http& revoke_best_effort(bool set); | ||||
| #ifdef WIN32 | ||||
| 	// Tells libcurl to ignore certificate revocation checks in case of missing or offline distribution points for those SSL backends where such behavior is present. 
 | ||||
| 	// This option is only supported for Schannel (the native Windows SSL library).
 | ||||
| 	Http& ssl_revoke_best_effort(bool set); | ||||
| #endif // WIN32
 | ||||
| 
 | ||||
| 	// Set the file contents as a POST request body.
 | ||||
| 	// The data is used verbatim, it is not additionally encoded in any way.
 | ||||
|  |  | |||
|  | @ -23,10 +23,10 @@ namespace pt = boost::property_tree; | |||
| namespace Slic3r { | ||||
| 
 | ||||
| OctoPrint::OctoPrint(DynamicPrintConfig *config) : | ||||
|     host(config->opt_string("print_host")), | ||||
|     apikey(config->opt_string("printhost_apikey")), | ||||
|     cafile(config->opt_string("printhost_cafile")), | ||||
|     ignore_checks(config->opt_bool("printhost_ignore_check")) | ||||
|     m_host(config->opt_string("print_host")), | ||||
|     m_apikey(config->opt_string("printhost_apikey")), | ||||
|     m_cafile(config->opt_string("printhost_cafile")), | ||||
|     m_ssl_revoke_best_effort(config->opt_bool("printhost_ssl_ignore_revoke")) | ||||
| {} | ||||
| 
 | ||||
| const char* OctoPrint::get_name() const { return "OctoPrint"; } | ||||
|  | @ -75,7 +75,7 @@ bool OctoPrint::test(wxString &msg) const | |||
|             } | ||||
|         }) | ||||
| #ifdef WIN32 | ||||
|         .revoke_best_effort(ignore_checks) | ||||
|         .ssl_revoke_best_effort(m_ssl_revoke_best_effort) | ||||
| #endif | ||||
|         .perform_sync(); | ||||
| 
 | ||||
|  | @ -142,7 +142,7 @@ bool OctoPrint::upload(PrintHostUpload upload_data, ProgressFn prorgess_fn, Erro | |||
|             } | ||||
|         }) | ||||
| #ifdef WIN32 | ||||
|         .revoke_best_effort(ignore_checks) | ||||
|         .ssl_revoke_best_effort(m_ssl_revoke_best_effort) | ||||
| #endif | ||||
|         .perform_sync(); | ||||
| 
 | ||||
|  | @ -156,31 +156,31 @@ bool OctoPrint::validate_version_text(const boost::optional<std::string> &versio | |||
| 
 | ||||
| void OctoPrint::set_auth(Http &http) const | ||||
| { | ||||
|     http.header("X-Api-Key", apikey); | ||||
|     http.header("X-Api-Key", m_apikey); | ||||
| 
 | ||||
|     if (! cafile.empty()) { | ||||
|         http.ca_file(cafile); | ||||
|     if (!m_cafile.empty()) { | ||||
|         http.ca_file(m_cafile); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| std::string OctoPrint::make_url(const std::string &path) const | ||||
| { | ||||
|     if (host.find("http://") == 0 || host.find("https://") == 0) { | ||||
|         if (host.back() == '/') { | ||||
|             return (boost::format("%1%%2%") % host % path).str(); | ||||
|     if (m_host.find("http://") == 0 || m_host.find("https://") == 0) { | ||||
|         if (m_host.back() == '/') { | ||||
|             return (boost::format("%1%%2%") % m_host % path).str(); | ||||
|         } else { | ||||
|             return (boost::format("%1%/%2%") % host % path).str(); | ||||
|             return (boost::format("%1%/%2%") % m_host % path).str(); | ||||
|         } | ||||
|     } else { | ||||
|         return (boost::format("http://%1%/%2%") % host % path).str(); | ||||
|         return (boost::format("http://%1%/%2%") % m_host % path).str(); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| SL1Host::SL1Host(DynamicPrintConfig *config) :  | ||||
|     OctoPrint(config), | ||||
|     authorization_type(dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(config->option("printhost_authorization_type"))->value), | ||||
|     username(config->opt_string("printhost_user")), | ||||
|     password(config->opt_string("printhost_password")) | ||||
|     m_authorization_type(dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(config->option("printhost_authorization_type"))->value), | ||||
|     m_username(config->opt_string("printhost_user")), | ||||
|     m_password(config->opt_string("printhost_password")) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -206,12 +206,12 @@ bool SL1Host::validate_version_text(const boost::optional<std::string> &version_ | |||
| 
 | ||||
| void SL1Host::set_auth(Http &http) const | ||||
| { | ||||
|     switch (authorization_type) { | ||||
|     switch (m_authorization_type) { | ||||
|     case atKeyPassword: | ||||
|         http.header("X-Api-Key", get_apikey()); | ||||
|         break; | ||||
|     case atUserPassword: | ||||
|         http.auth_digest(username, password); | ||||
|         http.auth_digest(m_username, m_password); | ||||
|         break; | ||||
|     } | ||||
| 
 | ||||
|  | @ -223,9 +223,9 @@ void SL1Host::set_auth(Http &http) const | |||
| // PrusaLink
 | ||||
| PrusaLink::PrusaLink(DynamicPrintConfig* config) : | ||||
|     OctoPrint(config), | ||||
|     authorization_type(dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(config->option("printhost_authorization_type"))->value), | ||||
|     username(config->opt_string("printhost_user")), | ||||
|     password(config->opt_string("printhost_password")) | ||||
|     m_authorization_type(dynamic_cast<const ConfigOptionEnum<AuthorizationType>*>(config->option("printhost_authorization_type"))->value), | ||||
|     m_username(config->opt_string("printhost_user")), | ||||
|     m_password(config->opt_string("printhost_password")) | ||||
| { | ||||
| } | ||||
| 
 | ||||
|  | @ -250,12 +250,12 @@ bool PrusaLink::validate_version_text(const boost::optional<std::string>& versio | |||
| 
 | ||||
| void PrusaLink::set_auth(Http& http) const | ||||
| { | ||||
|     switch (authorization_type) { | ||||
|     switch (m_authorization_type) { | ||||
|     case atKeyPassword: | ||||
|         http.header("X-Api-Key", get_apikey()); | ||||
|         break; | ||||
|     case atUserPassword: | ||||
|         http.auth_digest(username, password); | ||||
|         http.auth_digest(m_username, m_password); | ||||
|         break; | ||||
|     } | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,18 +29,18 @@ public: | |||
|     bool has_auto_discovery() const override { return true; } | ||||
|     bool can_test() const override { return true; } | ||||
|     bool can_start_print() const override { return true; } | ||||
|     std::string get_host() const override { return host; } | ||||
|     const std::string& get_apikey() const { return apikey; } | ||||
|     const std::string& get_cafile() const { return cafile; } | ||||
|     std::string get_host() const override { return m_host; } | ||||
|     const std::string& get_apikey() const { return m_apikey; } | ||||
|     const std::string& get_cafile() const { return m_cafile; } | ||||
| 
 | ||||
| protected: | ||||
|     virtual bool validate_version_text(const boost::optional<std::string> &version_text) const; | ||||
| 
 | ||||
| private: | ||||
|     std::string host; | ||||
|     std::string apikey; | ||||
|     std::string cafile; | ||||
|     bool        ignore_checks; | ||||
|     std::string m_host; | ||||
|     std::string m_apikey; | ||||
|     std::string m_cafile; | ||||
|     bool        m_ssl_revoke_best_effort; | ||||
| 
 | ||||
|     virtual void set_auth(Http &http) const; | ||||
|     std::string make_url(const std::string &path) const; | ||||
|  | @ -65,10 +65,10 @@ private: | |||
|     void set_auth(Http &http) const override; | ||||
| 
 | ||||
|     // Host authorization type.
 | ||||
|     AuthorizationType authorization_type; | ||||
|     AuthorizationType m_authorization_type; | ||||
|     // username and password for HTTP Digest Authentization (RFC RFC2617)
 | ||||
|     std::string username; | ||||
|     std::string password; | ||||
|     std::string m_username; | ||||
|     std::string m_password; | ||||
| }; | ||||
| 
 | ||||
| class PrusaLink : public OctoPrint | ||||
|  | @ -90,10 +90,10 @@ private: | |||
|     void set_auth(Http& http) const override; | ||||
| 
 | ||||
|     // Host authorization type.
 | ||||
|     AuthorizationType authorization_type; | ||||
|     AuthorizationType m_authorization_type; | ||||
|     // username and password for HTTP Digest Authentization (RFC RFC2617)
 | ||||
|     std::string username; | ||||
|     std::string password; | ||||
|     std::string m_username; | ||||
|     std::string m_password; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Vojtech Bubnik
						Vojtech Bubnik