mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-19 18:30:34 +08:00
parent
4361de7b31
commit
05b2fd671e
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -4,3 +4,6 @@
|
||||
[submodule "3rdparty/qzxing_noTests"]
|
||||
path = 3rdparty/qzxing_noTests
|
||||
url = https://github.com/lhy0403/qzxing_noTests
|
||||
[submodule "3rdparty/qhttpserver"]
|
||||
path = 3rdparty/qhttpserver
|
||||
url = https://github.com/nikhilm/qhttpserver
|
||||
|
1
3rdparty/qhttpserver
vendored
Submodule
1
3rdparty/qhttpserver
vendored
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 02a6e7174b5be76e2c0e74a109817e39a141b9fd
|
@ -1 +1 @@
|
||||
695
|
||||
706
|
||||
|
14
Qv2ray.pro
14
Qv2ray.pro
@ -39,6 +39,7 @@ SOURCES += \
|
||||
src/ui/w_RoutesEditor.cpp \
|
||||
src/ui/w_SubscriptionEditor.cpp \
|
||||
src/utils/QObjectMessageProxy.cpp \
|
||||
src/utils/QvGFWPACConverter.cpp \
|
||||
src/utils/QvHTTPRequestHelper.cpp \
|
||||
src/utils/QvPingModel.cpp \
|
||||
src/utils/QvRunguard.cpp \
|
||||
@ -148,9 +149,22 @@ for(var, $$list($$files("translations/*.ts", true))) {
|
||||
message("Qv2ray will build with" $${replace(EXTRA_TRANSLATIONS, "translations/", "")})
|
||||
TRANSLATIONS += translations/en-US.ts
|
||||
|
||||
|
||||
message(" ")
|
||||
QMAKE_CXXFLAGS += -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unused-variable
|
||||
|
||||
message("Adding QHttpServer Support")
|
||||
message(" --> Adding qhttpserver")
|
||||
HEADERS += $$PWD/3rdparty/qhttpserver/src/*.h
|
||||
SOURCES += $$PWD/3rdparty/qhttpserver/src/*.cpp
|
||||
INCLUDEPATH += 3rdparty/qhttpserver/src/
|
||||
|
||||
message(" --> Adding http parser")
|
||||
HEADERS += 3rdparty/qhttpserver/http-parser/http_parser.h
|
||||
SOURCES += 3rdparty/qhttpserver/http-parser/http_parser.c
|
||||
INCLUDEPATH += 3rdparty/qhttpserver/http-parser
|
||||
|
||||
message(" ")
|
||||
win32 {
|
||||
message("Configuring for win32 environment")
|
||||
message(" --> Setting up target descriptions")
|
||||
|
@ -84,6 +84,9 @@ namespace Qv2ray
|
||||
|
||||
QString FormatBytes(long long bytes);
|
||||
void DeducePossibleFileName(const QString &baseDir, QString *fileName, const QString &extension);
|
||||
//
|
||||
//
|
||||
QString ConvertGFWToPAC(const QString &rawContent, const QString &customProxyString);
|
||||
}
|
||||
}
|
||||
|
||||
|
132
src/utils/QvGFWPACConverter.cpp
Normal file
132
src/utils/QvGFWPACConverter.cpp
Normal file
@ -0,0 +1,132 @@
|
||||
/* ORIGINAL LICENSE: Do What The F*ck You Want To Public License
|
||||
* AUTHOR: LBYPatrick
|
||||
*
|
||||
* MODIFIED BY Leroy.H.Y @lhy0403 re-licenced under GPLv3
|
||||
*/
|
||||
|
||||
#include "QvUtils.hpp"
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
// Private function
|
||||
string getRawDomain(string originLine)
|
||||
{
|
||||
size_t startPosition = 0;
|
||||
size_t endPosition = originLine.size();
|
||||
string returnBuffer;
|
||||
bool skipRule1 = originLine.find("[") != string::npos; // [Auto xxxx...
|
||||
bool skipRule2 = originLine.find("!") != string::npos; // Comments
|
||||
bool skipRule3 = originLine.find("@") != string::npos; // Non-proxy Lines
|
||||
bool skipRule4 = originLine.find("*") != string::npos;
|
||||
bool passRule1 = originLine.find("|") != string::npos; // Proxy Lines
|
||||
bool passRule2 = originLine.find(".") != string::npos; // Link-Contained Lines
|
||||
|
||||
if (originLine[endPosition] == '\n') {
|
||||
endPosition -= 1;
|
||||
}
|
||||
|
||||
if (originLine.find("http://") != string::npos) {
|
||||
startPosition += 8;
|
||||
} else if (originLine.find("https://") != string::npos) {
|
||||
startPosition += 9;
|
||||
}
|
||||
|
||||
// Skip unrelated lines
|
||||
if (skipRule1 || skipRule2 || skipRule3 || skipRule4) {
|
||||
return "";
|
||||
} else if (passRule2) {
|
||||
if (passRule1) {
|
||||
startPosition += originLine.find_last_of("|") + 1;
|
||||
}
|
||||
|
||||
if (originLine[startPosition] == '\n') startPosition += 1;
|
||||
|
||||
for (size_t i = startPosition; i < endPosition; ++i) {
|
||||
returnBuffer += originLine[i];
|
||||
}
|
||||
}
|
||||
|
||||
return returnBuffer;
|
||||
}
|
||||
|
||||
QString ConvertGFWToPAC(const QString &rawContent, const QString &customProxyString)
|
||||
{
|
||||
auto rawFileContent = Base64Decode(rawContent).toStdString();
|
||||
string readBuffer = ""; //cleanup
|
||||
string writeBuffer;
|
||||
string domainListCache = "";
|
||||
|
||||
for (size_t i = 0; i < rawFileContent.size(); ++i) {
|
||||
readBuffer += rawFileContent[i];
|
||||
|
||||
if (rawFileContent[i + 1] == '\n') {
|
||||
writeBuffer = getRawDomain(readBuffer);
|
||||
|
||||
if (writeBuffer != "") {
|
||||
domainListCache += writeBuffer + "\n";
|
||||
}
|
||||
|
||||
readBuffer = "";
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
|
||||
size_t rotatorTwo = 0;
|
||||
string readDomainBuffer = "";
|
||||
bool isFirstLine = true;
|
||||
string outputContent = "";
|
||||
//Header
|
||||
outputContent += "var domains = {\n";
|
||||
|
||||
//Read and process output content line by line
|
||||
while (rotatorTwo < domainListCache.size()) {
|
||||
while (true) {
|
||||
//Get Domain
|
||||
readDomainBuffer += domainListCache[rotatorTwo];
|
||||
|
||||
if (domainListCache[rotatorTwo + 1] == '\n') {
|
||||
rotatorTwo += 2;
|
||||
break;
|
||||
}
|
||||
|
||||
rotatorTwo++;
|
||||
}
|
||||
|
||||
//Format
|
||||
if (!isFirstLine) outputContent += ",\n";
|
||||
else isFirstLine = false;
|
||||
|
||||
outputContent += "\t\"";
|
||||
outputContent += readDomainBuffer;
|
||||
outputContent += "\" : 1";
|
||||
readDomainBuffer = "";
|
||||
}
|
||||
|
||||
//End Message
|
||||
outputContent += "\n\n};\n\n\n";
|
||||
outputContent += "var proxy = \"";
|
||||
outputContent += customProxyString.toStdString();
|
||||
outputContent += "\";\n";
|
||||
outputContent += "var direct = 'DIRECT;';\n";
|
||||
outputContent += "var hasOwnProperty = Object.hasOwnProperty;\n\n";
|
||||
outputContent += "function FindProxyForURL(url, host) {\n\n";
|
||||
outputContent += "\tvar suffix;\n";
|
||||
outputContent += "\tvar pos = host.lastIndexOf('.');\n";
|
||||
outputContent += "\tpos = host.lastIndexOf('.', pos - 1);\n\n";
|
||||
outputContent += "\twhile(1) {\n";
|
||||
outputContent += "\t\tif (pos <= 0) {\n";
|
||||
outputContent += "\t\t\tif (hasOwnProperty.call(domains, host)) ";
|
||||
outputContent += "return proxy;\n";
|
||||
outputContent += "\t\t\telse ";
|
||||
outputContent += "return direct;\n";
|
||||
outputContent += "\t\t}\n\n";
|
||||
outputContent += "\tsuffix = host.substring(pos + 1);\n";
|
||||
outputContent += "\tif (hasOwnProperty.call(domains, suffix))";
|
||||
outputContent += "return proxy;\n";
|
||||
outputContent += "\tpos = host.lastIndexOf('.', pos - 1);\n\t}\n}";
|
||||
return QSTRING(outputContent);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user