VirtualBox

Ignore:
Timestamp:
Jul 9, 2020 7:49:52 AM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
139085
Message:

OCI: (bugref:9469) Proxy support (without authentication) for local gateway, cloud ssh and vpn. Proxy info retrieval in IPRT.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageCloud.cpp

    r84692 r85139  
    3131#include <iprt/uuid.h>
    3232#include <iprt/file.h>
     33#include <iprt/http.h>
    3334#include <VBox/log.h>
    3435
     
    21072108}
    21082109
     2110static bool getSystemProxyForUrl(const com::Utf8Str &strUrl, Bstr &strProxy)
     2111{
     2112    RTHTTP hHttp;
     2113    int rc = RTHttpCreate(&hHttp);
     2114    if (RT_FAILURE(rc))
     2115    {
     2116        LogRel(("OCI-NET: Failed to create HTTP context (rc=%d)\n", rc));
     2117        return false;
     2118    }
     2119    rc = RTHttpUseSystemProxySettings(hHttp);
     2120    if (RT_FAILURE(rc))
     2121    {
     2122        LogRel(("OCI-NET: Failed to use system proxy (rc=%d)\n", rc));
     2123        RTHttpDestroy(hHttp);
     2124        return false;
     2125    }
     2126
     2127    RTHTTPPROXYINFO proxy;
     2128    RT_ZERO(proxy);
     2129    rc = RTHttpGetProxyInfoForUrl(hHttp, strUrl.c_str(), &proxy);
     2130    if (RT_FAILURE(rc))
     2131    {
     2132        LogRel(("OCI-NET: Failed to get proxy for %s (rc=%d)\n", strUrl.c_str(), rc));
     2133        RTHttpDestroy(hHttp);
     2134        return false;
     2135    }
     2136    const char *pcszProxyScheme = "";
     2137    switch (proxy.enmProxyType)
     2138    {
     2139        case RTHTTPPROXYTYPE_HTTP:
     2140            pcszProxyScheme = "http://";
     2141            break;
     2142        case RTHTTPPROXYTYPE_HTTPS:
     2143            pcszProxyScheme = "https://";
     2144            break;
     2145        case RTHTTPPROXYTYPE_SOCKS4:
     2146            pcszProxyScheme = "socks4://";
     2147            break;
     2148        case RTHTTPPROXYTYPE_SOCKS5:
     2149            pcszProxyScheme = "socks://";
     2150            break;
     2151        case RTHTTPPROXYTYPE_UNKNOWN:
     2152            LogRel(("OCI-NET: Unknown proxy type. Using direct connecton."));
     2153            RTHttpDestroy(hHttp);
     2154            return false;
     2155    }
     2156    strProxy = BstrFmt("%s%s:%d", pcszProxyScheme, proxy.pszProxyHost, proxy.uProxyPort);
     2157    RTHttpFreeProxyInfo(&proxy);
     2158    RTHttpDestroy(hHttp);
     2159    return true;
     2160}
     2161
    21092162static HRESULT createLocalGatewayImage(ComPtr<IVirtualBox> virtualBox, const Bstr& aGatewayIso, const Bstr& aGuestAdditionsIso, const Bstr& aProxy)
    21102163{
     
    21252178
    21262179    ComPtr<ISystemProperties> systemProperties;
     2180    ProxyMode_T enmProxyMode;
     2181    Bstr strProxy;
    21272182    ComPtr<IMedium> hd;
    21282183    Bstr defaultMachineFolder;
     
    21312186    if (errorOccured(hrc, "Failed to obtain system properties."))
    21322187        return hrc;
     2188    if (aProxy.isNotEmpty())
     2189        strProxy = aProxy;
     2190    else
     2191    {
     2192        hrc = systemProperties->COMGETTER(ProxyMode)(&enmProxyMode);
     2193        if (errorOccured(hrc, "Failed to obtain proxy mode."))
     2194            return hrc;
     2195        switch (enmProxyMode)
     2196        {
     2197            case ProxyMode_NoProxy:
     2198                strProxy.setNull();
     2199                break;
     2200            case ProxyMode_Manual:
     2201                hrc = systemProperties->COMGETTER(ProxyURL)(strProxy.asOutParam());
     2202                if (errorOccured(hrc, "Failed to obtain proxy URL."))
     2203                    return hrc;
     2204                break;
     2205            case ProxyMode_System:
     2206                if (!getSystemProxyForUrl("https://dl.fedoraproject.org", strProxy))
     2207                    errorOccured(E_FAIL, "Failed to get system proxy for https://dl.fedoraproject.org. Will use direct connection.");
     2208                break;
     2209            default: /* To get rid of ProxyMode_32BitHack 'warning' */
     2210                RTAssertPanic();
     2211                break;
     2212        }
     2213
     2214    }
    21332215    hrc = systemProperties->COMGETTER(DefaultMachineFolder)(defaultMachineFolder.asOutParam());
    21342216    if (errorOccured(hrc, "Failed to obtain default machine folder."))
     
    22832365        return hrc;
    22842366
    2285     if (aProxy.isNotEmpty())
    2286     {
    2287         hrc = unattended->COMSETTER(Proxy)(aProxy.raw());
     2367    if (strProxy.isNotEmpty())
     2368    {
     2369        hrc = unattended->COMSETTER(Proxy)(strProxy.raw());
    22882370        if (errorOccured(hrc, "Failed to set post install script template for the unattended installer."))
    22892371            return hrc;
    22902372    }
     2373
    22912374    hrc = unattended->Prepare();
    22922375    if (errorOccured(hrc, "Failed to prepare unattended installation."))
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette