mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 05:30:06 +08:00
feat: Add custom system parameters for x-hwid header (#1027)
- Add sub_custom_hwid_params field to DataStore - Add UI text field for entering custom parameters - Parse and apply custom parameters when sending HWID headers - Format: hwid=value,os=value,osVersion=value,model=value - Empty input uses default system parameters Co-authored-by: hgx100 <hgx100@github.com>
This commit is contained in:
parent
6e8610c2cb
commit
721d79f981
@ -116,6 +116,7 @@ namespace Configs {
|
|||||||
int sub_auto_update = -30;
|
int sub_auto_update = -30;
|
||||||
bool sub_clear = false;
|
bool sub_clear = false;
|
||||||
bool sub_send_hwid = false;
|
bool sub_send_hwid = false;
|
||||||
|
QString sub_custom_hwid_params = ""; // Custom system parameters: format "hwid=value,os=value,osVersion=value,model=value"
|
||||||
|
|
||||||
// Security
|
// Security
|
||||||
bool skip_cert = false;
|
bool skip_cert = false;
|
||||||
|
|||||||
@ -569,6 +569,23 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_custom_hwid_params">
|
||||||
|
<property name="text">
|
||||||
|
<string>Custom System Parameters (optional)</string>
|
||||||
|
</property>
|
||||||
|
<property name="toolTip">
|
||||||
|
<string><html><head/><body><p>Format: hwid=value,os=value,osVersion=value,model=value</p><p>Leave empty to use default values. Only specify the parameters you want to override.</p></body></html></string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QLineEdit" name="sub_custom_hwid_params">
|
||||||
|
<property name="placeholderText">
|
||||||
|
<string>hwid=custom_value,os=custom_os,osVersion=custom_version,model=custom_model</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_20">
|
<widget class="QLabel" name="label_20">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
|
|||||||
@ -287,6 +287,7 @@ namespace Configs {
|
|||||||
_add(new configItem("net_insecure", &net_insecure, itemType::boolean));
|
_add(new configItem("net_insecure", &net_insecure, itemType::boolean));
|
||||||
_add(new configItem("sub_auto_update", &sub_auto_update, itemType::integer));
|
_add(new configItem("sub_auto_update", &sub_auto_update, itemType::integer));
|
||||||
_add(new configItem("sub_send_hwid", &sub_send_hwid, itemType::boolean));
|
_add(new configItem("sub_send_hwid", &sub_send_hwid, itemType::boolean));
|
||||||
|
_add(new configItem("sub_custom_hwid_params", &sub_custom_hwid_params, itemType::string));
|
||||||
_add(new configItem("start_minimal", &start_minimal, itemType::boolean));
|
_add(new configItem("start_minimal", &start_minimal, itemType::boolean));
|
||||||
_add(new configItem("max_log_line", &max_log_line, itemType::integer));
|
_add(new configItem("max_log_line", &max_log_line, itemType::integer));
|
||||||
_add(new configItem("splitter_state", &splitter_state, itemType::string));
|
_add(new configItem("splitter_state", &splitter_state, itemType::string));
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QMap>
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
#include "include/global/Configs.hpp"
|
#include "include/global/Configs.hpp"
|
||||||
#include "include/ui/mainwindow.h"
|
#include "include/ui/mainwindow.h"
|
||||||
@ -40,11 +42,42 @@ namespace Configs_network {
|
|||||||
//Attach HWID and device info headers if enabled in settings
|
//Attach HWID and device info headers if enabled in settings
|
||||||
if (sendHwid) {
|
if (sendHwid) {
|
||||||
auto details = GetDeviceDetails();
|
auto details = GetDeviceDetails();
|
||||||
|
|
||||||
if (!details.hwid.isEmpty()) request.setRawHeader("x-hwid", details.hwid.toUtf8());
|
// Parse custom parameters if provided
|
||||||
if (!details.os.isEmpty()) request.setRawHeader("x-device-os", details.os.toUtf8());
|
QMap<QString, QString> customParams;
|
||||||
if (!details.osVersion.isEmpty()) request.setRawHeader("x-ver-os", details.osVersion.toUtf8());
|
if (!Configs::dataStore->sub_custom_hwid_params.isEmpty()) {
|
||||||
if (!details.model.isEmpty()) request.setRawHeader("x-device-model", details.model.toUtf8());
|
QStringList pairs = Configs::dataStore->sub_custom_hwid_params.split(',');
|
||||||
|
for (const QString &pair : pairs) {
|
||||||
|
QString trimmed = pair.trimmed();
|
||||||
|
int eqPos = trimmed.indexOf('=');
|
||||||
|
if (eqPos > 0) {
|
||||||
|
QString key = trimmed.left(eqPos).trimmed();
|
||||||
|
QString value = trimmed.mid(eqPos + 1).trimmed();
|
||||||
|
// Validate: key must be one of the allowed parameters, value must not contain newlines
|
||||||
|
if (!key.isEmpty() && !value.isEmpty() &&
|
||||||
|
!value.contains('\n') && !value.contains('\r') &&
|
||||||
|
value.length() < 1000) { // Reasonable length limit
|
||||||
|
QString lowerKey = key.toLower();
|
||||||
|
// Only accept known parameter keys
|
||||||
|
if (lowerKey == "hwid" || lowerKey == "os" ||
|
||||||
|
lowerKey == "osversion" || lowerKey == "model") {
|
||||||
|
customParams[lowerKey] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use custom values if provided, otherwise use default values
|
||||||
|
QString hwid = customParams.contains("hwid") ? customParams["hwid"] : details.hwid;
|
||||||
|
QString os = customParams.contains("os") ? customParams["os"] : details.os;
|
||||||
|
QString osVersion = customParams.contains("osversion") ? customParams["osversion"] : details.osVersion;
|
||||||
|
QString model = customParams.contains("model") ? customParams["model"] : details.model;
|
||||||
|
|
||||||
|
if (!hwid.isEmpty()) request.setRawHeader("x-hwid", hwid.toUtf8());
|
||||||
|
if (!os.isEmpty()) request.setRawHeader("x-device-os", os.toUtf8());
|
||||||
|
if (!osVersion.isEmpty()) request.setRawHeader("x-ver-os", osVersion.toUtf8());
|
||||||
|
if (!model.isEmpty()) request.setRawHeader("x-device-model", model.toUtf8());
|
||||||
}
|
}
|
||||||
//
|
//
|
||||||
auto _reply = accessManager.get(request);
|
auto _reply = accessManager.get(request);
|
||||||
@ -59,7 +92,7 @@ namespace Configs_network {
|
|||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
connect(_reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
connect(_reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
|
|
||||||
//
|
//
|
||||||
auto result = HTTPResponse{_reply->error() == QNetworkReply::NetworkError::NoError ? "" : _reply->errorString(),
|
auto result = HTTPResponse{_reply->error() == QNetworkReply::NetworkError::NoError ? "" : _reply->errorString(),
|
||||||
_reply->readAll(), _reply->rawHeaderPairs()};
|
_reply->readAll(), _reply->rawHeaderPairs()};
|
||||||
|
|||||||
@ -155,6 +155,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
|||||||
D_LOAD_BOOL(sub_clear)
|
D_LOAD_BOOL(sub_clear)
|
||||||
D_LOAD_BOOL(net_insecure)
|
D_LOAD_BOOL(net_insecure)
|
||||||
D_LOAD_BOOL(sub_send_hwid)
|
D_LOAD_BOOL(sub_send_hwid)
|
||||||
|
D_LOAD_STRING(sub_custom_hwid_params)
|
||||||
D_LOAD_INT_ENABLE(sub_auto_update, sub_auto_update_enable)
|
D_LOAD_INT_ENABLE(sub_auto_update, sub_auto_update_enable)
|
||||||
auto details = GetDeviceDetails();
|
auto details = GetDeviceDetails();
|
||||||
ui->sub_send_hwid->setToolTip(
|
ui->sub_send_hwid->setToolTip(
|
||||||
@ -253,6 +254,7 @@ void DialogBasicSettings::accept() {
|
|||||||
D_SAVE_BOOL(sub_clear)
|
D_SAVE_BOOL(sub_clear)
|
||||||
D_SAVE_BOOL(net_insecure)
|
D_SAVE_BOOL(net_insecure)
|
||||||
D_SAVE_BOOL(sub_send_hwid)
|
D_SAVE_BOOL(sub_send_hwid)
|
||||||
|
D_SAVE_STRING(sub_custom_hwid_params)
|
||||||
D_SAVE_INT_ENABLE(sub_auto_update, sub_auto_update_enable)
|
D_SAVE_INT_ENABLE(sub_auto_update, sub_auto_update_enable)
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user