mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 20:44:38 +03:00
system proxy format (windows)
This commit is contained in:
@@ -17,4 +17,11 @@ namespace Preset {
|
||||
namespace SingBox {
|
||||
inline QStringList VpnImplementation = {"gvisor", "system"};
|
||||
}
|
||||
|
||||
namespace Windows {
|
||||
inline QStringList system_proxy_format{"{ip}:{http_port}",
|
||||
"socks={ip}:{socks_port}",
|
||||
"http={ip}:{http_port};https={ip}:{http_port};ftp={ip}:{http_port};socks={ip}:{socks_port}",
|
||||
"http=http://{ip}:{http_port};https=http://{ip}:{http_port}"};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ namespace NekoRay {
|
||||
_add(new configItem("vpn_bypass_process", &vpn_bypass_process, itemType::string));
|
||||
_add(new configItem("vpn_bypass_cidr", &vpn_bypass_cidr, itemType::string));
|
||||
_add(new configItem("check_include_pre", &check_include_pre, itemType::boolean));
|
||||
_add(new configItem("sp_format", &system_proxy_format, itemType::string));
|
||||
}
|
||||
|
||||
void DataStore::UpdateStartedId(int id) {
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace NekoRay {
|
||||
int language = 0;
|
||||
QString mw_size = "";
|
||||
bool check_include_pre = false;
|
||||
QString system_proxy_format = "";
|
||||
|
||||
// Security
|
||||
bool insecure_hint = true;
|
||||
|
||||
@@ -25,6 +25,8 @@ inline std::function<void(QString, QString)> dialog_message;
|
||||
#define QJSONOBJECT_COPY(src, dst, key) if (src.contains(key)) dst[key] = src[key];
|
||||
#define QJSONOBJECT_COPY2(src, dst, src_key, dst_key) if (src.contains(src_key)) dst[dst_key] = src[src_key];
|
||||
|
||||
#define Int2String(num) QString::number(num)
|
||||
|
||||
inline QString SubStrBefore(QString str, const QString &sub) {
|
||||
if (!str.contains(sub)) return str;
|
||||
return str.left(str.indexOf(sub));
|
||||
@@ -58,14 +60,6 @@ DecodeB64IfValid(const QString &input, QByteArray::Base64Option options = QByteA
|
||||
|
||||
QString GetQueryValue(const QUrlQuery &q, const QString &key, const QString &def = "");
|
||||
|
||||
inline QString Int2String(int i) {
|
||||
return QVariant(i).toString();
|
||||
}
|
||||
|
||||
inline QString Int2String(qint64 i) {
|
||||
return QVariant(i).toString();
|
||||
}
|
||||
|
||||
QString GetRandomString(int randomStringLength);
|
||||
|
||||
// QString >> QJson
|
||||
@@ -114,6 +108,8 @@ inline QStringList SplitLines(const QString &_string) {
|
||||
return _string.split(QRegularExpression("[\r\n]"), Qt::SplitBehaviorFlags::SkipEmptyParts);
|
||||
}
|
||||
|
||||
// Files
|
||||
|
||||
QByteArray ReadFile(const QString &path);
|
||||
|
||||
QString ReadFileText(const QString &path);
|
||||
|
||||
@@ -14,7 +14,8 @@
|
||||
#include <QProcess>
|
||||
|
||||
#include "qv2ray/wrapper.hpp"
|
||||
#include "main/NekoRay_Utils.hpp"
|
||||
#include "fmt/Preset.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
|
||||
#define QV_MODULE_NAME "SystemProxy"
|
||||
|
||||
@@ -250,8 +251,8 @@ namespace Qv2ray::components::proxy {
|
||||
}
|
||||
#endif
|
||||
|
||||
void SetSystemProxy(const QString &address, int httpPort, int socksPort) {
|
||||
LOG("Setting up System Proxy");
|
||||
void SetSystemProxy(int httpPort, int socksPort) {
|
||||
const QString &address = "127.0.0.1";
|
||||
bool hasHTTP = (httpPort > 0 && httpPort < 65536);
|
||||
bool hasSOCKS = (socksPort > 0 && socksPort < 65536);
|
||||
|
||||
@@ -281,23 +282,15 @@ namespace Qv2ray::components::proxy {
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QString __a;
|
||||
const QHostAddress ha(address);
|
||||
const auto type = ha.protocol();
|
||||
if (type == QAbstractSocket::IPv6Protocol)
|
||||
{
|
||||
// many software do not recognize IPv6 proxy server string though
|
||||
const auto str = ha.toString(); // RFC5952
|
||||
__a = "[" + str + "]:" + QSTRN(httpPort);
|
||||
}
|
||||
else
|
||||
{
|
||||
__a = address + ":" + QSTRN(httpPort);
|
||||
}
|
||||
|
||||
LOG("Windows proxy string: " + __a);
|
||||
auto proxyStrW = new WCHAR[__a.length() + 1];
|
||||
wcscpy(proxyStrW, __a.toStdWString().c_str());
|
||||
QString str = NekoRay::dataStore->system_proxy_format;
|
||||
if (str.isEmpty()) str = Preset::Windows::system_proxy_format[0];
|
||||
str = str.replace("{ip}", address)
|
||||
.replace("{http_port}", Int2String(httpPort))
|
||||
.replace("{socks_port}", Int2String(socksPort));
|
||||
//
|
||||
LOG("Windows proxy string: " + str);
|
||||
auto proxyStrW = new WCHAR[str.length() + 1];
|
||||
wcscpy(proxyStrW, str.toStdWString().c_str());
|
||||
//
|
||||
__QueryProxyOptions();
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
namespace Qv2ray::components::proxy
|
||||
{
|
||||
void ClearSystemProxy();
|
||||
void SetSystemProxy(const QString &address, int http_port, int socks_port);
|
||||
void SetSystemProxy(int http_port, int socks_port);
|
||||
} // namespace Qv2ray::components::proxy
|
||||
|
||||
using namespace Qv2ray::components;
|
||||
|
||||
@@ -191,6 +191,14 @@
|
||||
<source>Switching the core to %1, click "Yes" to complete the switch and the program will restart. This feature may be unstable, please do not switch frequently.</source>
|
||||
<translation>将核心切换到 %1。点击 "是" 完成切换,程序将重新启动。此功能可能不稳定,请不要频繁切换。</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>System proxy format</source>
|
||||
<translation>系统代理格式</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Advanced system proxy settings. Please select a format.</source>
|
||||
<translation>高级系统代理设置。请选择一种格式。</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>DialogEditGroup</name>
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "ui_dialog_basic_settings.h"
|
||||
|
||||
#include "qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
|
||||
#include "fmt/Preset.hpp"
|
||||
#include "ui/ThemeManager.hpp"
|
||||
#include "main/GuiUtils.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
@@ -78,6 +79,22 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
C_EDIT_JSON_ALLOW_EMPTY(custom_inbound)
|
||||
});
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
connect(ui->sys_proxy_format, &QPushButton::clicked, this, [=] {
|
||||
bool ok;
|
||||
auto str = QInputDialog::getItem(this, ui->sys_proxy_format->text() + " (Windows)",
|
||||
tr("Advanced system proxy settings. Please select a format."),
|
||||
Preset::Windows::system_proxy_format,
|
||||
Preset::Windows::system_proxy_format.indexOf(
|
||||
NekoRay::dataStore->system_proxy_format),
|
||||
false, &ok
|
||||
);
|
||||
if (ok) NekoRay::dataStore->system_proxy_format = str;
|
||||
});
|
||||
#else
|
||||
ui->sys_proxy_format->hide();
|
||||
#endif
|
||||
|
||||
// Style
|
||||
if (IS_NEKO_BOX) {
|
||||
ui->connection_statistics_box->setDisabled(true);
|
||||
|
||||
@@ -209,6 +209,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="sys_proxy_format">
|
||||
<property name="text">
|
||||
<string>System proxy format</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@@ -588,7 +588,7 @@ void MainWindow::neko_set_spmode(int mode, bool save) {
|
||||
// ENABLE
|
||||
|
||||
if (mode == NekoRay::SystemProxyMode::SYSTEM_PROXY) {
|
||||
#ifdef Q_OS_WIN
|
||||
#if defined(Q_OS_WIN) || defined(Q_OS_MACOS)
|
||||
if (mode == NekoRay::SystemProxyMode::SYSTEM_PROXY && !IS_NEKO_BOX &&
|
||||
!InRange(NekoRay::dataStore->inbound_http_port, 0, 65535)) {
|
||||
auto btn = QMessageBox::warning(this, software_name,
|
||||
@@ -604,9 +604,8 @@ void MainWindow::neko_set_spmode(int mode, bool save) {
|
||||
auto http_port = NekoRay::dataStore->inbound_http_port;
|
||||
if (IS_NEKO_BOX) {
|
||||
http_port = socks_port;
|
||||
socks_port = -1;
|
||||
}
|
||||
SetSystemProxy("127.0.0.1", http_port, socks_port);
|
||||
SetSystemProxy(http_port, socks_port);
|
||||
} else if (mode == NekoRay::SystemProxyMode::VPN) {
|
||||
if (!StartVPNProcess()) {
|
||||
refresh_status();
|
||||
|
||||
Reference in New Issue
Block a user