Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

auto detect last http&https proxy for macos

  • Loading branch information...
commit 2dcf3c195637e0d9d69c9e663f4edbe8ac5841c7 1 parent 10d91a9
@iptton iptton authored
View
31 mainwindow.cpp
@@ -627,8 +627,12 @@ void MainWindow::toggleProxy(){
if(isFirstTimeToggle){
isFirstTimeToggle = false;
CFDictionaryRef proxies = SCDynamicStoreCopyProxies(NULL);
- CFShow(proxies);
+ //CFShow(proxies);
int isPacEnabled = 0;
+ //CFStringRef CFPacUrl = (CFStringRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesProxyAutoConfigURLString);
+ //if(CFPacUrl){
+ // _previousProxyInfo.pacUrl = QString::fromUtf8( CFStringGetCStringPtr(CFPacUrl,kCFStringEncodingUTF8) );
+ //}
if (proxies){
CFNumberRef pacEnabled;
//kSCPropNetProxiesHTTPSProxy
@@ -646,8 +650,31 @@ void MainWindow::toggleProxy(){
qDebug()<<_previousProxyInfo.pacUrl;
ProxyAutoConfig::instance()->setConfigByUrl(_previousProxyInfo.pacUrl);
}else{
- // TODO check http&https proxy
+ CFNumberRef httpEnabled = (CFNumberRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPEnable);
+ CFNumberRef httpsEnabled = (CFNumberRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPSEnable);
+ int tmp;
+ if (CFNumberGetValue(httpEnabled, kCFNumberIntType, &tmp) && tmp){
+ CFStringRef host = (CFStringRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPProxy);
+ CFNumberRef port = (CFNumberRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPPort);
+ QString hostQ = QString::fromUtf8( CFStringGetCStringPtr(host,kCFStringEncodingUTF8) );
+ UInt64 portQ=20;
+ CFNumberGetValue(port, kCFNumberSInt64Type, &portQ);
+ QString proxyStr = QString("Proxy %1:%2").arg(hostQ).arg(portQ);
+ //qDebug()<<proxyStr;
+ ProxyAutoConfig::instance()->setHttpProxy(proxyStr);
+ }
+ if (CFNumberGetValue(httpsEnabled, kCFNumberIntType, &tmp) && tmp){
+ CFStringRef host = (CFStringRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPSProxy);
+ CFNumberRef port = (CFNumberRef)CFDictionaryGetValue(proxies, kSCPropNetProxiesHTTPSPort);
+ QString hostQ = QString::fromUtf8( CFStringGetCStringPtr(host,kCFStringEncodingUTF8) );
+ UInt64 portQ=20;
+ CFNumberGetValue(port, kCFNumberSInt64Type, &portQ);
+ QString proxyStr = QString("Proxy %1:%2").arg(hostQ).arg(portQ);
+ ProxyAutoConfig::instance()->setHttpProxy(proxyStr);
+ }
+
}
+ CFRelease(proxies);
}
setProxySuccess = setMyPAC();
}
View
11 proxy/proxyautoconfig.cpp
@@ -42,6 +42,12 @@ void ProxyAutoConfig::setConfigByUrl(const QString &url){
QString script = QString(reply->readAll());
setConfig(script);
}
+void ProxyAutoConfig::setHttpProxy(const QString &http){
+ httpProxy = http;
+}
+void ProxyAutoConfig::setHttpsProxy(const QString &https){
+ httpsProxy = https;
+}
void ProxyAutoConfig::setConfig( const QString &config )
{
@@ -144,6 +150,11 @@ QScriptValue ProxyAutoConfig::dnsResolve( QScriptContext *context, QScriptEngine
QString ProxyAutoConfig::findProxyForUrl( const QString &url, const QString &host )
{
if(!_isSettup){
+ if(!httpProxy.isEmpty() && url.startsWith("http://")){
+ return httpProxy;
+ }else if(!httpsProxy.isEmpty() && url.startsWith("https://")){
+ return httpsProxy;
+ }
return "DIRECT";
}
QMutexLocker locker(&_queryMutex);
View
8 proxy/proxyautoconfig.h
@@ -22,6 +22,7 @@ class ProxyAutoConfig : public QObject
static ProxyAutoConfig *instance();
~ProxyAutoConfig();
+
/**
* add by iptton#gmail.com
*
@@ -29,6 +30,11 @@ class ProxyAutoConfig : public QObject
* @param url
*/
void setConfigByUrl(const QString &url);
+ /*
+ * set fall back proxy, if no pac setted ,use this
+ */
+ void setHttpProxy(const QString &http);
+ void setHttpsProxy(const QString &https);
/**
* Call this to set the script to be executed. Note that the argument should be
@@ -65,6 +71,8 @@ class ProxyAutoConfig : public QObject
private:
QScriptEngine *engine;
+ QString httpProxy;
+ QString httpsProxy;
private slots:
void onException();
};
View
12 rythem_zh_CN.ts
@@ -199,16 +199,16 @@ Host: www.alloyteam.com
<translation type="unfinished">选择文件</translation>
</message>
<message>
- <location filename="mainwindow.cpp" line="664"/>
- <location filename="mainwindow.cpp" line="693"/>
- <location filename="mainwindow.cpp" line="694"/>
+ <location filename="mainwindow.cpp" line="691"/>
+ <location filename="mainwindow.cpp" line="720"/>
+ <location filename="mainwindow.cpp" line="721"/>
<source>start capture</source>
<translation type="unfinished">开始抓包</translation>
</message>
<message>
- <location filename="mainwindow.cpp" line="673"/>
- <location filename="mainwindow.cpp" line="689"/>
- <location filename="mainwindow.cpp" line="690"/>
+ <location filename="mainwindow.cpp" line="700"/>
+ <location filename="mainwindow.cpp" line="716"/>
+ <location filename="mainwindow.cpp" line="717"/>
<source>stop capture</source>
<translation type="unfinished">停止抓包</translation>
</message>
Please sign in to comment.
Something went wrong with that request. Please try again.