From 52b816b657791b053c8123abfdd2450e7854e8cc Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Thu, 24 Aug 2023 10:04:39 +0800 Subject: [PATCH] FIX: [STUDIO-4522] hide passwd of media url from log Change-Id: Ib4da577ea39cca9fb34d920101a81f1708a6934e Jira: STUDIO-4522 --- src/slic3r/GUI/MediaFilePanel.cpp | 4 +- src/slic3r/GUI/MediaPlayCtrl.cpp | 90 +++++++++++++------- src/slic3r/GUI/MediaPlayCtrl.h | 2 + src/slic3r/GUI/Printer/PrinterFileSystem.cpp | 6 +- 4 files changed, 70 insertions(+), 32 deletions(-) diff --git a/src/slic3r/GUI/MediaFilePanel.cpp b/src/slic3r/GUI/MediaFilePanel.cpp index 024c41bc2..a86d42ff0 100644 --- a/src/slic3r/GUI/MediaFilePanel.cpp +++ b/src/slic3r/GUI/MediaFilePanel.cpp @@ -410,6 +410,8 @@ void MediaFilePanel::modeChanged(wxCommandEvent& e1) m_last_mode = mode; } +extern wxString hide_passwd(wxString url, std::vector const &passwords); + void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) { boost::shared_ptr fs(wfs.lock()); @@ -446,7 +448,7 @@ void MediaFilePanel::fetchUrl(boost::weak_ptr wfs) if (agent) { agent->get_camera_url(m_machine, [this, wfs, m = m_machine, v = m_dev_ver](std::string url) { - BOOST_LOG_TRIVIAL(info) << "MediaFilePanel::fetchUrl: camera_url: " << url; + BOOST_LOG_TRIVIAL(info) << "MediaFilePanel::fetchUrl: camera_url: " << hide_passwd(url, {"authkey=", "passwd="}); CallAfter([=] { boost::shared_ptr fs(wfs.lock()); if (!fs || fs != m_image_grid->GetFileSystem()) return; diff --git a/src/slic3r/GUI/MediaPlayCtrl.cpp b/src/slic3r/GUI/MediaPlayCtrl.cpp index cc286ce8b..ee93b50d9 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.cpp +++ b/src/slic3r/GUI/MediaPlayCtrl.cpp @@ -41,7 +41,23 @@ MediaPlayCtrl::MediaPlayCtrl(wxWindow *parent, wxMediaCtrl2 *media_ctrl, const w wxLaunchDefaultBrowser(url); }); - Bind(wxEVT_RIGHT_UP, [this](auto & e) { wxClipboard & c = *wxTheClipboard; if (c.Open()) { c.SetData(new wxTextDataObject(m_url)); c.Close(); } }); + Bind(wxEVT_RIGHT_UP, [this](auto & e) { + wxClipboard & c = *wxTheClipboard; + if (c.Open()) { + if (wxGetKeyState(WXK_SHIFT)) { + if (c.IsSupported(wxDF_TEXT)) { + wxTextDataObject data; + c.GetData(data); + Stop(); + m_url = data.GetText(); + load(); + } + } else { + c.SetData(new wxTextDataObject(m_url)); + } + c.Close(); + } + }); wxBoxSizer * sizer = new wxBoxSizer(wxHORIZONTAL); sizer->Add(m_button_play, 0, wxEXPAND | wxALL, 0); @@ -123,6 +139,23 @@ void MediaPlayCtrl::SetMachineObject(MachineObject* obj) SetStatus("", false); } +wxString hide_passwd(wxString url, std::vector const &passwords) +{ + for (auto &p : passwords) { + auto i = url.find(p); + auto j = i + p.length(); + if (p[p.length() - 1] == '=') { + i = j; + j = url.find('&', i); + if (j == wxString::npos) j = url.length(); + } + auto l = size_t(j - i); + if (j == url.length() || url[j] == '@' || url[j] == '&') + url.replace(i, l, l, wxUniChar('*')); + } + return url; +} + void MediaPlayCtrl::Play() { if (!m_next_retry.IsValid() || wxDateTime::Now() < m_next_retry) @@ -166,22 +199,8 @@ void MediaPlayCtrl::Play() m_url += "&device=" + m_machine; m_url += "&version=" + agent_version; m_url += "&dev_ver=" + m_dev_ver; - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: " << m_url.substr(0, 16); - m_last_state = MEDIASTATE_LOADING; - SetStatus(_L("Loading...")); - if (wxGetApp().app_config->get("internal_developer_mode") == "true") { - std::string file_h264 = data_dir() + "/video.h264"; - std::string file_info = data_dir() + "/video.info"; - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl dump video to " << file_h264; - // closed by BambuSource - FILE *dump_h264_file = boost::nowide::fopen(file_h264.c_str(), "wb"); - FILE *dump_info_file = boost::nowide::fopen(file_info.c_str(), "wb"); - m_url = m_url + "&dump_h264=" + boost::lexical_cast(dump_h264_file); - m_url = m_url + "&dump_info=" + boost::lexical_cast(dump_info_file); - } - boost::unique_lock lock(m_mutex); - m_tasks.push_back(m_url); - m_cond.notify_all(); + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: " << hide_passwd(m_url, {m_lan_passwd} ); + load(); return; } @@ -213,7 +232,7 @@ void MediaPlayCtrl::Play() url += "&version=" + v; url += "&dev_ver=" + dv; } - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: " << url.substr(0, 16) << ", machine: " << m_machine; + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: " << hide_passwd(url, {"authkey=", "passwd="}) << ", machine: " << m_machine; CallAfter([this, m, url] { if (m != m_machine) { BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl drop late ttcode for machine: " << m; @@ -225,15 +244,7 @@ void MediaPlayCtrl::Play() m_failed_code = 3; Stop(wxString::Format(_L("Initialize failed (%s)!"), url.empty() ? _L("Network unreachable") : from_u8(url))); } else { - m_last_state = MEDIASTATE_LOADING; - SetStatus(_L("Loading...")); - if (wxGetApp().app_config->get("internal_developer_mode") == "true") { - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl dump video to " << boost::filesystem::current_path(); - m_url = m_url + "&dump=video.h264"; - } - boost::unique_lock lock(m_mutex); - m_tasks.push_back(m_url); - m_cond.notify_all(); + load(); } } else { BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl drop late ttcode for state: " << m_last_state; @@ -395,7 +406,7 @@ void MediaPlayCtrl::ToggleStream() url = "bambu:///rtsp___" + m_lan_user + ":" + m_lan_passwd + "@" + m_lan_ip + "/streaming/live/1?proto=rtsp"; url += "&device=" + m_machine; url += "&dev_ver=" + m_dev_ver; - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << url.substr(0, 16); + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << hide_passwd(url, {m_lan_passwd}); std::string file_url = data_dir() + "/cameratools/url.txt"; boost::nowide::ofstream file(file_url); auto url2 = encode_path(url.c_str()); @@ -411,7 +422,7 @@ void MediaPlayCtrl::ToggleStream() url += "&version=" + v; url += "&dev_ver=" + dv; } - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << url.substr(0, 16); + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl::ToggleStream: " << hide_passwd(url, {"authkey=", "passwd="}); CallAfter([this, m, url] { if (m != m_machine) return; if (url.empty() || !boost::algorithm::starts_with(url, "bambu:///")) { @@ -509,6 +520,25 @@ void MediaPlayCtrl::SetStatus(wxString const &msg2, bool hyperlink) bool MediaPlayCtrl::IsStreaming() const { return m_streaming; } +void MediaPlayCtrl::load() +{ + m_last_state = MEDIASTATE_LOADING; + SetStatus(_L("Loading...")); + if (wxGetApp().app_config->get("internal_developer_mode") == "true") { + std::string file_h264 = data_dir() + "/video.h264"; + std::string file_info = data_dir() + "/video.info"; + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl dump video to " << file_h264; + // closed by BambuSource + FILE *dump_h264_file = boost::nowide::fopen(file_h264.c_str(), "wb"); + FILE *dump_info_file = boost::nowide::fopen(file_info.c_str(), "wb"); + m_url = m_url + "&dump_h264=" + boost::lexical_cast(dump_h264_file); + m_url = m_url + "&dump_info=" + boost::lexical_cast(dump_info_file); + } + boost::unique_lock lock(m_mutex); + m_tasks.push_back(m_url); + m_cond.notify_all(); +} + void MediaPlayCtrl::on_show_hide(wxShowEvent &evt) { evt.Skip(); @@ -528,7 +558,7 @@ void MediaPlayCtrl::media_proc() } wxString url = m_tasks.front(); if (m_tasks.size() >= 2 && !url.IsEmpty() && url[0] != '<' && m_tasks[1] == "") { - BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: busy skip url" << url; + BOOST_LOG_TRIVIAL(info) << "MediaPlayCtrl: busy skip url: " << hide_passwd(url, {"authkey=", "passwd=", m_lan_passwd}); m_tasks.pop_front(); m_tasks.pop_front(); continue; diff --git a/src/slic3r/GUI/MediaPlayCtrl.h b/src/slic3r/GUI/MediaPlayCtrl.h index c36e3c408..79ce3a4b9 100644 --- a/src/slic3r/GUI/MediaPlayCtrl.h +++ b/src/slic3r/GUI/MediaPlayCtrl.h @@ -54,6 +54,8 @@ protected: void SetStatus(wxString const &msg, bool hyperlink = true); private: + void load(); + void on_show_hide(wxShowEvent & evt); void media_proc(); diff --git a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp index 170d18687..e8f451899 100644 --- a/src/slic3r/GUI/Printer/PrinterFileSystem.cpp +++ b/src/slic3r/GUI/Printer/PrinterFileSystem.cpp @@ -1217,6 +1217,10 @@ void PrinterFileSystem::HandleResponse(boost::unique_lock &l, Bamb } } +namespace Slic3r { namespace GUI { + extern wxString hide_passwd(wxString url, std::vector const &passwords); +}} + void PrinterFileSystem::Reconnect(boost::unique_lock &l, int result) { if (m_session.tunnel) { @@ -1258,7 +1262,7 @@ void PrinterFileSystem::Reconnect(boost::unique_lock &l, int resul wxLogMessage("PrinterFileSystem::Reconnect Initialize failed: %s", wxString::FromUTF8(url)); m_last_error = atoi(url.c_str()); } else { - wxLogMessage("PrinterFileSystem::Reconnect Initialized: %s", wxString::FromUTF8(url)); + wxLogMessage("PrinterFileSystem::Reconnect Initialized: %s", Slic3r::GUI::hide_passwd(wxString::FromUTF8(url), {"authkey=", "passwd="})); l.unlock(); m_status = Status::Connecting; wxLogMessage("PrinterFileSystem::Reconnect Connecting");