Ticket #10829: Option to copy URL with password.patch

File Option to copy URL with password.patch, 18.9 KB (added by Julien Blitte, 9 years ago)

Patch - Option to copy URL with password

  • src/engine/ControlSocket.cpp

     
    10441044
    10451045    const int proxy_type = engine_.GetOptions().GetOptionVal(OPTION_PROXY_TYPE);
    10461046    if (proxy_type > CProxySocket::unknown && proxy_type < CProxySocket::proxytype_count && !m_pCurrentServer->GetBypassProxy()) {
    1047         LogMessage(MessageType::Status, _("Connecting to %s through %s proxy"), m_pCurrentServer->FormatHost(), CProxySocket::Name(static_cast<CProxySocket::ProxyType>(proxy_type)));
     1047        LogMessage(MessageType::Status, _("Connecting to %s through %s proxy"), m_pCurrentServer->FormatServer(SERVER_HOST_PORT), CProxySocket::Name(static_cast<CProxySocket::ProxyType>(proxy_type)));
    10481048
    10491049        host = engine_.GetOptions().GetOption(OPTION_PROXY_HOST);
    10501050        port = engine_.GetOptions().GetOptionVal(OPTION_PROXY_PORT);
  • src/engine/ftpcontrolsocket.cpp

     
    526526            pData->loginSequence.push_back(cmd);
    527527        }
    528528        // User@host
    529         t_loginCommand cmd = {false, false, loginCommandType::user, wxString::Format(_T("USER %s@%s"), server.GetUser(), server.FormatHost())};
     529        t_loginCommand cmd = {false, false, loginCommandType::user, wxString::Format(_T("USER %s@%s"), server.GetUser(), server.FormatServer(SERVER_HOST_PORT))};
    530530        pData->loginSequence.push_back(cmd);
    531531
    532532        // Password
     
    558558        // Site or Open
    559559        t_loginCommand cmd = {false, false, loginCommandType::user, _T("")};
    560560        if (pData->ftp_proxy_type == 2)
    561             cmd.command = _T("SITE ") + server.FormatHost();
     561            cmd.command = _T("SITE ") + server.FormatServer(SERVER_HOST_PORT);
    562562        else
    563             cmd.command = _T("OPEN ") + server.FormatHost();
     563            cmd.command = _T("OPEN ") + server.FormatServer(SERVER_HOST_PORT);
    564564        pData->loginSequence.push_back(cmd);
    565565
    566566        // User
     
    584584    else if (pData->ftp_proxy_type == 4) {
    585585        wxString proxyUser = engine_.GetOptions().GetOption(OPTION_FTP_PROXY_USER);
    586586        wxString proxyPass = engine_.GetOptions().GetOption(OPTION_FTP_PROXY_PASS);
    587         wxString host = server.FormatHost();
     587        wxString host = server.FormatServer(SERVER_HOST_PORT);
    588588        wxString user = server.GetUser();
    589589        wxString account = server.GetAccount();
    590590        proxyUser.Replace(_T("%"), _T("%%"));
     
    42444244            return FZ_REPLY_ERROR;
    42454245        }
    42464246
    4247         LogMessage(MessageType::Status, _("Connecting to %s through %s proxy"), server.FormatHost(), _T("FTP")); // @translator: Connecting to ftp.example.com through SOCKS5 proxy
     4247        LogMessage(MessageType::Status, _("Connecting to %s through %s proxy"), FormatServer(SERVER_HOST_PORT), _T("FTP")); // @translator: Connecting to ftp.example.com through SOCKS5 proxy
    42484248    }
    42494249    else {
    42504250        pData->ftp_proxy_type = 0;
  • src/engine/httpcontrolsocket.cpp

     
    343343    m_pCurOpData = pData;
    344344    m_pHttpOpData = pData;
    345345
    346     m_current_uri = wxURI(m_pCurrentServer->FormatServer() + pData->remotePath.FormatFilename(pData->remoteFile));
     346    m_current_uri = wxURI(m_pCurrentServer->FormatServer(SERVER_USER_HOST_PORT) + pData->remotePath.FormatFilename(pData->remoteFile));
    347347
    348348    if (!localFile.empty()) {
    349349        pData->localFileSize = fz::local_filesys::get_size(fz::to_native(pData->localFile));
  • src/engine/server.cpp

     
    637637    return m_maximumMultipleConnections;
    638638}
    639639
    640 wxString CServer::FormatHost(bool always_omit_port /*=false*/) const
     640wxString CServer::FormatServer(FormatServerType formatType) const
    641641{
    642     wxString host = m_host;
     642    wxString server = m_host;
    643643
    644     if (host.Find(':') != -1)
    645         host = _T("[") + host + _T("]");
     644    if (server.Find(':') != -1)
     645        server = _T("[") + server + _T("]");
    646646
    647     if (!always_omit_port)
     647    if (formatType == SERVER_HOST_ONLY)
     648        return server;
     649   
     650    if (m_port != GetDefaultPort(m_protocol) || expanded_form)
     651        server += wxString::Format(_T(":%d"), m_port);
     652
     653    if (formatType == SERVER_HOST_PORT)
     654        return server;
     655       
     656    if (m_logonType != ANONYMOUS)
    648657    {
    649         if (m_port != GetDefaultPort(m_protocol))
    650             host += wxString::Format(_T(":%d"), m_port);
     658        if (formatType == SERVER_URL_PASSWORD)
     659            server = GetUser() + _T(":") + GetPass() + _T("@") + server
     660        else
     661            server = GetUser() + _T("@") + server;
    651662    }
    652 
    653     return host;
    654 }
    655 
    656 wxString CServer::FormatServer(const bool always_include_prefix /*=false*/) const
    657 {
    658     wxString server = FormatHost();
    659 
    660     if (m_logonType != ANONYMOUS)
    661         server = GetUser() + _T("@") + server;
    662 
     663   
     664    if (formatType == SERVER_USER_HOST_PORT)
     665    {
     666        if (info.alwaysShowPrefix || m_port != info.defaultPort)
     667            formatType == SERVER_URL
     668        else
     669            return server;
     670    }
     671       
    663672    const t_protocolInfo& info = GetProtocolInfo(m_protocol);
    664673    if (!info.prefix.empty())
    665674    {
    666         if (always_include_prefix || info.alwaysShowPrefix)
    667             server = info.prefix + _T("://") + server;
    668         else if (m_port != info.defaultPort)
    669             server = info.prefix + _T("://") + server;
     675        server = info.prefix + _T("://") + server;
    670676    }
    671677
    672678    return server;
  • src/engine/sftpcontrolsocket.cpp

     
    355355
    356356int CSftpControlSocket::Connect(const CServer &server)
    357357{
    358     LogMessage(MessageType::Status, _("Connecting to %s..."), server.FormatHost());
     358    LogMessage(MessageType::Status, _("Connecting to %s..."), server.FormatServer(SERVER_HOST_PORT));
    359359    SetWait(true);
    360360
    361361    m_sftpEncryptionDetails = CSftpEncryptionNotification();
  • src/include/server.h

     
    6060    ENCODING_CUSTOM
    6161};
    6262
     63enum FormatServerType
     64{
     65    SERVER_HOST_ONLY,
     66    SERVER_HOST_PORT,
     67    SERVER_USER_HOST_PORT,
     68    SERVER_URL,
     69    SERVER_URL_PASSWORD
     70};
     71
    6372class CServerPath;
    6473class CServer final
    6574{
     
    111120    void SetPasvMode(PasvMode pasvMode);
    112121    void MaximumMultipleConnections(int maximum);
    113122
    114     wxString FormatHost(bool always_omit_port = false) const;
    115     wxString FormatServer(const bool always_include_prefix = false) const;
     123    wxString FormatServer(const FormatServerType formatType) const;
    116124
    117125    bool SetEncodingType(CharsetEncoding type, const wxString& encoding = wxString());
    118126    bool SetCustomEncoding(const wxString& encoding);
  • src/interface/edithandler.cpp

     
    716716        else
    717717            dlg.SetChildLabel(XRCID("ID_OPENEDAS"), file);
    718718    }
    719     dlg.SetChildLabel(XRCID("ID_SERVER"), iter->server.FormatServer());
     719    dlg.SetChildLabel(XRCID("ID_SERVER"), iter->server.FormatServer(SERVER_USER_HOST_PORT));
    720720    dlg.SetChildLabel(XRCID("ID_REMOTEPATH"), iter->remotePath.GetPath());
    721721
    722722    dlg.GetSizer()->Fit(&dlg);
     
    11171117                pListCtrl->SetItem(i, COLUMN_STATUS, _("Unknown"));
    11181118                break;
    11191119            }
    1120             pListCtrl->SetItem(i, COLUMN_REMOTEPATH, iter->server.FormatServer() + iter->remotePath.GetPath());
     1120            pListCtrl->SetItem(i, COLUMN_REMOTEPATH, iter->server.FormatServer(SERVER_USER_HOST_PORT) + iter->remotePath.GetPath());
    11211121            CEditHandler::t_fileData* pData = new CEditHandler::t_fileData(*iter);
    11221122            pListCtrl->SetItemPtrData(i, (wxUIntPtr)pData);
    11231123        }
     
    11451145                pListCtrl->SetItem(i, COLUMN_STATUS, _("Unknown"));
    11461146                break;
    11471147            }
    1148             pListCtrl->SetItem(i, COLUMN_REMOTEPATH, iter->server.FormatServer() + iter->remotePath.GetPath());
     1148            pListCtrl->SetItem(i, COLUMN_REMOTEPATH, iter->server.FormatServer(SERVER_USER_HOST_PORT) + iter->remotePath.GetPath());
    11491149            CEditHandler::t_fileData* pData = new CEditHandler::t_fileData(*iter);
    11501150            pListCtrl->SetItemPtrData(i, (wxUIntPtr)pData);
    11511151        }
  • src/interface/file_utils.cpp

     
    2020    if (!utf8)
    2121        return wxString();
    2222
     23    //TODO: create a standalone URLEncode function
    2324    const char* p = utf8;
    2425    while (*p)
    2526    {
  • src/interface/loginmanager.cpp

     
    5959        pwdDlg.GetSizer()->Show(XRCCTRL(pwdDlg, "ID_REMEMBER", wxCheckBox), canRemember, true);
    6060        XRCCTRL(pwdDlg, "ID_CHALLENGE", wxTextCtrl)->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
    6161    }
    62     XRCCTRL(pwdDlg, "ID_HOST", wxStaticText)->SetLabel(server.FormatHost());
     62    XRCCTRL(pwdDlg, "ID_HOST", wxStaticText)->SetLabel(server.FormatServer(SERVER_HOST_PORT));
    6363
    6464    if (server.GetUser().empty()) {
    6565        pwdDlg.SetTitle(_("Enter username and password"));
  • src/interface/Mainfrm.cpp

     
    830830        CSpeedLimitsDialog dlg;
    831831        dlg.Run(this);
    832832    }
     833    else if (event.GetId() == XRCID("ID_MENU_EDIT_URLPASSWORD")) {
     834        if (event.IsChecked()) {
     835            if (wxMessageBoxEx(_("This option will enable the ability to copy password in clear in the clipboard.\nThis is insecure, are you sure you want to continue?"), _("Include password in URL"), wxICON_QUESTION | wxYES_NO) == wxYES)     
     836                COptions::Get()->SetOption(OPTION_PASSWORD_IN_URL, 1);
     837        }
     838        else
     839            COptions::Get()->SetOption(OPTION_PASSWORD_IN_URL, 0);
     840    }
    833841    else if (event.GetId() == m_comparisonToggleAcceleratorId) {
    834842        CState* pState = CContextManager::Get()->GetCurrentContext();
    835843        if (!pState)
  • src/interface/manual_transfer.cpp

     
    159159{
    160160    if (m_pServer)
    161161    {
    162         XRCCTRL(*this, "ID_HOST", wxTextCtrl)->ChangeValue(m_pServer->FormatHost(true));
     162        XRCCTRL(*this, "ID_HOST", wxTextCtrl)->ChangeValue(m_pServer->FormatServer(SERVER_HOST_ONLY));
    163163        unsigned int port = m_pServer->GetPort();
    164164
    165165        if (port != CServer::GetDefaultPort(m_pServer->GetProtocol()))
     
    461461        return false;
    462462    }
    463463
    464     xrc_call(*this, "ID_HOST", &wxTextCtrl::ChangeValue, server.FormatHost(true));
     464    xrc_call(*this, "ID_HOST", &wxTextCtrl::ChangeValue, server.FormatServer(SERVER_HOST_ONLY));
    465465    xrc_call(*this, "ID_PORT", &wxTextCtrl::ChangeValue, wxString::Format(_T("%d"), server.GetPort()));
    466466
    467467    protocolName = CServer::GetProtocolName(server.GetProtocol());
  • src/interface/menu_bar.cpp

     
    8686    menubar->Check(XRCID("ID_VIEW_REMOTETREE"), COptions::Get()->GetOptionVal(OPTION_SHOW_TREE_REMOTE) != 0);
    8787    menubar->Check(XRCID("ID_MENU_VIEW_FILELISTSTATUSBAR"), COptions::Get()->GetOptionVal(OPTION_FILELIST_STATUSBAR) != 0);
    8888    menubar->Check(XRCID("ID_MENU_TRANSFER_PRESERVETIMES"), COptions::Get()->GetOptionVal(OPTION_PRESERVE_TIMESTAMPS) != 0);
    89 
     89    menubar->Check(XRCID("ID_MENU_EDIT_URLPASSWORD"), COptions::Get()->GetOptionVal(OPTION_PASSWORD_IN_URL) != 0);
     90   
    9091    switch (COptions::Get()->GetOptionVal(OPTION_ASCIIBINARY))
    9192    {
    9293    case 1:
     
    373374    if (options.test(OPTION_PRESERVE_TIMESTAMPS)) {
    374375        Check(XRCID("ID_MENU_TRANSFER_PRESERVETIMES"), COptions::Get()->GetOptionVal(OPTION_PRESERVE_TIMESTAMPS) != 0);
    375376    }
     377    if (options.test(OPTION_PASSWORD_IN_URL)) {
     378        Check(XRCID("ID_MENU_EDIT_URLPASSWORD"), COptions::Get()->GetOptionVal(OPTION_PASSWORD_IN_URL) != 0);
     379    }
    376380    if (options.test(OPTION_SHOW_TREE_LOCAL)) {
    377381        Check(XRCID("ID_VIEW_LOCALTREE"), COptions::Get()->GetOptionVal(OPTION_SHOW_TREE_LOCAL) != 0);
    378382    }
  • src/interface/Options.cpp

     
    198198    // Default/internal options
    199199    { "Config Location", string, _T(""), default_only },
    200200    { "Kiosk mode", number, _T("0"), default_priority },
    201     { "Disable update check", number, _T("0"), default_only }
     201    { "Disable update check", number, _T("0"), default_only },
     202    { "Include passwords in URL", number, _T("0"), default_only }
    202203};
    203204
    204205BEGIN_EVENT_TABLE(COptions, wxEvtHandler)
  • src/interface/Options.h

     
    9898    OPTION_PERSISTENT_CHOICES,
    9999    OPTION_QUEUE_COMPLETION_ACTION,
    100100    OPTION_QUEUE_COMPLETION_COMMAND,
     101    OPTION_PASSWORD_IN_URL,
    101102
    102103    // Default/internal options
    103104    OPTION_DEFAULT_SETTINGSDIR, // guaranteed to be (back)slash-terminated
  • src/interface/queue.cpp

     
    391391
    392392wxString CServerItem::GetName() const
    393393{
    394     return m_server.FormatServer();
     394    return m_server.FormatServer(SERVER_USER_HOST_PORT);
    395395}
    396396
    397397void CServerItem::AddChild(CQueueItem* pItem)
  • src/interface/quickconnectbar.cpp

     
    8686        return;
    8787    }
    8888
    89     host = server.FormatHost(true);
     89    host = server.FormatServer(SERVER_HOST_ONLY);
    9090    ServerProtocol protocol = server.GetProtocol();
    9191    switch (protocol)
    9292    {
     
    159159            iter != m_recentServers.end();
    160160            ++iter, ++i)
    161161        {
    162             wxString name(iter->FormatServer());
     162            wxString name(iter->FormatServer(SERVER_USER_HOST_PORT));
    163163            name.Replace(_T("&"), _T("&&"));
    164164            pMenu->Append(10 + i, name);
    165165        }
  • src/interface/RemoteListView.cpp

     
    25232523    }
    25242524
    25252525    const CServerPath& path = m_pDirectoryListing->path;
    2526     const wxString server = pServer->FormatServer(true);
     2526
     2527    if (COptions::Get()->GetOptionVal(OPTION_PASSWORD_IN_URL) != 0)
     2528        wxString server = pServer->FormatServer(SERVER_URL_PASSWORD)
     2529    else
     2530        wxString server = pServer->FormatServer(SERVER_URL);
     2531
    25272532    if (selected_item_list.size() == 1)
    25282533    {
    25292534        wxString url = server;
     
    25302535        url += path.FormatFilename(selected_item_list.front().name, false);
    25312536
    25322537        // Poor mans URLencode
     2538        // TODO: use a proper URLEncode function, confer file_utils.cpp
    25332539        url.Replace(_T(" "), _T("%20"));
    25342540
    25352541        wxTheClipboard->SetData(new wxURLDataObject(url));
     
    25492555        }
    25502556
    25512557        // Poor mans URLencode
     2558        // TODO: use a proper URLEncode function, confer file_utils.cpp
    25522559        urls.Replace(_T(" "), _T("%20"));
    25532560
    25542561        wxTheClipboard->SetData(new wxTextDataObject(urls));
  • src/interface/RemoteTreeView.cpp

     
    13821382        return;
    13831383    }
    13841384
    1385     wxString url = pServer->FormatServer(true);
     1385    if (COptions::Get()->GetOptionVal(OPTION_PASSWORD_IN_URL) != 0)
     1386        wxString url = pServer->FormatServer(SERVER_URL_PASSWORD)
     1387    else
     1388        wxString url = pServer->FormatServer(SERVER_URL);
     1389       
    13861390    url += path.GetPath();
    13871391
    13881392    // Poor mans URLencode
     1393    // TODO: use a proper URLEncode function, confer file_utils.cpp
    13891394    url.Replace(_T(" "), _T("%20"));
    13901395
    13911396    wxTheClipboard->SetData(new wxURLDataObject(url));
  • src/interface/resources/xrc/menus.xrc

     
    4949      <object class="wxMenuItem" name="ID_MENU_EDIT_CLEARPRIVATEDATA">
    5050        <label>&amp;Clear private data...</label>
    5151      </object>
     52      <object class="wxMenuItem" name="ID_MENU_EDIT_URLPASSWORD">
     53        <label>Show &amp;password in URL...</label>
     54        <checkable>1</checkable>
     55      </object>
    5256      <object class="separator"/>
    5357      <object class="wxMenuItem" name="wxID_PREFERENCES">
    5458        <label>&amp;Settings...</label>
  • src/interface/sitemanager_dialog.cpp

     
    10001000            return false;
    10011001        }
    10021002
    1003         XRCCTRL(*this, "ID_HOST", wxTextCtrl)->ChangeValue(server.FormatHost(true));
     1003        XRCCTRL(*this, "ID_HOST", wxTextCtrl)->ChangeValue(server.FormatServer(SERVER_HOST_ONLY));
    10041004        if (server.GetPort() != CServer::GetDefaultPort(server.GetProtocol())) {
    10051005            XRCCTRL(*this, "ID_PORT", wxTextCtrl)->ChangeValue(wxString::Format(_T("%d"), server.GetPort()));
    10061006        }
     
    16231623        xrc_call(*this, "ID_CONNECT", &wxButton::Enable, true);
    16241624
    16251625        xrc_call(*this, "ID_HOST", &wxWindow::Enable, !predefined);
    1626         xrc_call(*this, "ID_HOST", &wxTextCtrl::ChangeValue, site_data->m_server.FormatHost(true));
     1626        xrc_call(*this, "ID_HOST", &wxTextCtrl::ChangeValue, site_data->m_server.FormatServer(SERVER_HOST_ONLY));
    16271627        unsigned int port = site_data->m_server.GetPort();
    16281628
    16291629        if (port != CServer::GetDefaultPort(site_data->m_server.GetProtocol()))
  • src/interface/state.cpp

     
    469469
    470470        const wxString& name = server->GetName();
    471471        if (!name.empty())
    472             m_title = name + _T(" - ") + server->FormatServer();
     472            m_title = name + _T(" - ") + server->FormatServer(SERVER_USER_HOST_PORT);
    473473        else
    474             m_title = server->FormatServer();
     474            m_title = server->FormatServer(SERVER_USER_HOST_PORT);
    475475    }
    476476    else {
    477477        m_pServer = 0;
  • src/interface/statuslinectrl.cpp

     
    240240        m_statusText = _("Waiting for transfer to be cancelled");
    241241        break;
    242242    case t_EngineData::connect:
    243         m_statusText = wxString::Format(_("Connecting to %s"), m_pEngineData->lastServer.FormatServer());
     243        m_statusText = wxString::Format(_("Connecting to %s"), m_pEngineData->lastServer.FormatServer(SERVER_USER_HOST_PORT));
    244244        break;
    245245    default:
    246246        m_statusText = _("Transferring");