mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-23 01:50:17 +08:00
add random listen port feature
This commit is contained in:
parent
fdffa32191
commit
a17a94a3e3
@ -115,6 +115,7 @@ namespace Configs {
|
|||||||
// Socks & HTTP Inbound
|
// Socks & HTTP Inbound
|
||||||
QString inbound_address = "127.0.0.1";
|
QString inbound_address = "127.0.0.1";
|
||||||
int inbound_socks_port = 2080; // Mixed, actually
|
int inbound_socks_port = 2080; // Mixed, actually
|
||||||
|
bool random_inbound_port = false;
|
||||||
QString custom_inbound = "{\"inbounds\": []}";
|
QString custom_inbound = "{\"inbounds\": []}";
|
||||||
|
|
||||||
// Routing
|
// Routing
|
||||||
|
|||||||
@ -89,6 +89,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="random_listen_port">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>Selects a random available port on every run</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Random port</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@ -245,6 +245,7 @@ namespace Configs {
|
|||||||
_add(new configItem("current_group", ¤t_group, itemType::integer));
|
_add(new configItem("current_group", ¤t_group, itemType::integer));
|
||||||
_add(new configItem("inbound_address", &inbound_address, itemType::string));
|
_add(new configItem("inbound_address", &inbound_address, itemType::string));
|
||||||
_add(new configItem("inbound_socks_port", &inbound_socks_port, itemType::integer));
|
_add(new configItem("inbound_socks_port", &inbound_socks_port, itemType::integer));
|
||||||
|
_add(new configItem("random_inbound_port", &random_inbound_port, itemType::boolean));
|
||||||
_add(new configItem("log_level", &log_level, itemType::string));
|
_add(new configItem("log_level", &log_level, itemType::string));
|
||||||
_add(new configItem("mux_protocol", &mux_protocol, itemType::string));
|
_add(new configItem("mux_protocol", &mux_protocol, itemType::string));
|
||||||
_add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer));
|
_add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer));
|
||||||
|
|||||||
@ -52,6 +52,7 @@
|
|||||||
#include <QToolTip>
|
#include <QToolTip>
|
||||||
#include <random>
|
#include <random>
|
||||||
#include <3rdparty/QHotkey/qhotkey.h>
|
#include <3rdparty/QHotkey/qhotkey.h>
|
||||||
|
#include <3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.hpp>
|
||||||
#include <include/api/gRPC.h>
|
#include <include/api/gRPC.h>
|
||||||
#include <include/global/HTTPRequestHelper.hpp>
|
#include <include/global/HTTPRequestHelper.hpp>
|
||||||
|
|
||||||
@ -125,6 +126,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
runOnUiThread([=] { show_log_impl(log); });
|
runOnUiThread([=] { show_log_impl(log); });
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Listen port if random
|
||||||
|
if (Configs::dataStore->random_inbound_port)
|
||||||
|
{
|
||||||
|
Configs::dataStore->inbound_socks_port = MkPort();
|
||||||
|
}
|
||||||
|
|
||||||
// Prepare core
|
// Prepare core
|
||||||
Configs::dataStore->core_port = MkPort();
|
Configs::dataStore->core_port = MkPort();
|
||||||
if (Configs::dataStore->core_port <= 0) Configs::dataStore->core_port = 19810;
|
if (Configs::dataStore->core_port <= 0) Configs::dataStore->core_port = 19810;
|
||||||
@ -688,6 +695,15 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
|
|||||||
if (info.contains("UpdateDisableTray")) {
|
if (info.contains("UpdateDisableTray")) {
|
||||||
tray->setVisible(!Configs::dataStore->disable_tray);
|
tray->setVisible(!Configs::dataStore->disable_tray);
|
||||||
}
|
}
|
||||||
|
if (info.contains("NeedChoosePort"))
|
||||||
|
{
|
||||||
|
Configs::dataStore->inbound_socks_port = MkPort();
|
||||||
|
if (Configs::dataStore->spmode_system_proxy)
|
||||||
|
{
|
||||||
|
set_spmode_system_proxy(false);
|
||||||
|
set_spmode_system_proxy(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
auto suggestRestartProxy = Configs::dataStore->Save();
|
auto suggestRestartProxy = Configs::dataStore->Save();
|
||||||
if (info.contains("RouteChanged")) {
|
if (info.contains("RouteChanged")) {
|
||||||
Configs::dataStore->routing->Save();
|
Configs::dataStore->routing->Save();
|
||||||
@ -700,7 +716,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
|
|||||||
if (info.contains("VPNChanged") && Configs::dataStore->spmode_vpn) {
|
if (info.contains("VPNChanged") && Configs::dataStore->spmode_vpn) {
|
||||||
MessageBoxWarning(tr("Tun Settings changed"), tr("Restart Tun to take effect."));
|
MessageBoxWarning(tr("Tun Settings changed"), tr("Restart Tun to take effect."));
|
||||||
}
|
}
|
||||||
if (suggestRestartProxy && Configs::dataStore->started_id >= 0 &&
|
if ((info.contains("NeedChoosePort") || suggestRestartProxy) && Configs::dataStore->started_id >= 0 &&
|
||||||
QMessageBox::question(GetMessageBoxParent(), tr("Confirmation"), tr("Settings changed, restart proxy?")) == QMessageBox::StandardButton::Yes) {
|
QMessageBox::question(GetMessageBoxParent(), tr("Confirmation"), tr("Settings changed, restart proxy?")) == QMessageBox::StandardButton::Yes) {
|
||||||
profile_start(Configs::dataStore->started_id);
|
profile_start(Configs::dataStore->started_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,6 +31,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
|||||||
D_LOAD_COMBO_STRING(log_level)
|
D_LOAD_COMBO_STRING(log_level)
|
||||||
CACHE.custom_inbound = Configs::dataStore->custom_inbound;
|
CACHE.custom_inbound = Configs::dataStore->custom_inbound;
|
||||||
D_LOAD_INT(inbound_socks_port)
|
D_LOAD_INT(inbound_socks_port)
|
||||||
|
ui->random_listen_port->setChecked(Configs::dataStore->random_inbound_port);
|
||||||
D_LOAD_INT(test_concurrent)
|
D_LOAD_INT(test_concurrent)
|
||||||
D_LOAD_STRING(test_latency_url)
|
D_LOAD_STRING(test_latency_url)
|
||||||
D_LOAD_BOOL(disable_tray)
|
D_LOAD_BOOL(disable_tray)
|
||||||
@ -43,6 +44,16 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
|||||||
connect(ui->disable_tray, &QCheckBox::stateChanged, this, [=](const bool &) {
|
connect(ui->disable_tray, &QCheckBox::stateChanged, this, [=](const bool &) {
|
||||||
CACHE.updateDisableTray = true;
|
CACHE.updateDisableTray = true;
|
||||||
});
|
});
|
||||||
|
connect(ui->random_listen_port, &QCheckBox::checkStateChanged, this, [=](const bool &state)
|
||||||
|
{
|
||||||
|
if (state)
|
||||||
|
{
|
||||||
|
ui->inbound_socks_port->setDisabled(true);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
ui->inbound_socks_port->setDisabled(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
#ifndef Q_OS_WIN
|
#ifndef Q_OS_WIN
|
||||||
ui->proxy_scheme_box->hide();
|
ui->proxy_scheme_box->hide();
|
||||||
@ -172,11 +183,17 @@ DialogBasicSettings::~DialogBasicSettings() {
|
|||||||
|
|
||||||
void DialogBasicSettings::accept() {
|
void DialogBasicSettings::accept() {
|
||||||
// Common
|
// Common
|
||||||
|
bool needChoosePort = false;
|
||||||
|
|
||||||
D_SAVE_STRING(inbound_address)
|
D_SAVE_STRING(inbound_address)
|
||||||
D_SAVE_COMBO_STRING(log_level)
|
D_SAVE_COMBO_STRING(log_level)
|
||||||
Configs::dataStore->custom_inbound = CACHE.custom_inbound;
|
Configs::dataStore->custom_inbound = CACHE.custom_inbound;
|
||||||
D_SAVE_INT(inbound_socks_port)
|
D_SAVE_INT(inbound_socks_port)
|
||||||
|
if (!Configs::dataStore->random_inbound_port && ui->random_listen_port->isChecked())
|
||||||
|
{
|
||||||
|
needChoosePort = true;
|
||||||
|
}
|
||||||
|
Configs::dataStore->random_inbound_port = ui->random_listen_port->isChecked();
|
||||||
D_SAVE_INT(test_concurrent)
|
D_SAVE_INT(test_concurrent)
|
||||||
D_SAVE_STRING(test_latency_url)
|
D_SAVE_STRING(test_latency_url)
|
||||||
D_SAVE_BOOL(disable_tray)
|
D_SAVE_BOOL(disable_tray)
|
||||||
@ -239,6 +256,7 @@ void DialogBasicSettings::accept() {
|
|||||||
QStringList str{"UpdateDataStore"};
|
QStringList str{"UpdateDataStore"};
|
||||||
if (CACHE.needRestart) str << "NeedRestart";
|
if (CACHE.needRestart) str << "NeedRestart";
|
||||||
if (CACHE.updateDisableTray) str << "UpdateDisableTray";
|
if (CACHE.updateDisableTray) str << "UpdateDisableTray";
|
||||||
|
if (needChoosePort) str << "NeedChoosePort";
|
||||||
MW_dialog_message(Dialog_DialogBasicSettings, str.join(","));
|
MW_dialog_message(Dialog_DialogBasicSettings, str.join(","));
|
||||||
QDialog::accept();
|
QDialog::accept();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user