mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-18 13:04:37 +03:00
parse hysteria share link
This commit is contained in:
17
fmt/Preset.hpp
Normal file
17
fmt/Preset.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
namespace Preset {
|
||||
namespace Hysteria {
|
||||
inline const char *command = "--no-check -c %config%";
|
||||
inline const char *config = "{\n"
|
||||
" \"server\": \"127.0.0.1:%mapping_port%\",\n"
|
||||
" \"obfs\": \"fuck me till the daylight\",\n"
|
||||
" \"up_mbps\": 10,\n"
|
||||
" \"down_mbps\": 50,\n"
|
||||
" \"server_name\": \"real.name.com\",\n"
|
||||
" \"socks5\": {\n"
|
||||
" \"listen\": \"127.0.0.1:%socks_port%\"\n"
|
||||
" }\n"
|
||||
"}";
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,5 @@ namespace NekoRay {
|
||||
VPN,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -3,10 +3,12 @@
|
||||
#include "db/Database.hpp"
|
||||
#include "db/ProfileFilter.hpp"
|
||||
#include "fmt/includes.h"
|
||||
#include "fmt/Preset.hpp"
|
||||
|
||||
#include "GroupUpdater.hpp"
|
||||
|
||||
#include <QInputDialog>
|
||||
#include <QUrlQuery>
|
||||
|
||||
#ifndef NKR_NO_EXTERNAL
|
||||
|
||||
@@ -105,6 +107,31 @@ namespace NekoRay::sub {
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
// Hysteria
|
||||
if (str.startsWith("hysteria://")) {
|
||||
// https://github.com/HyNetwork/hysteria/wiki/URI-Scheme
|
||||
ent = ProfileManager::NewProxyEntity("custom");
|
||||
auto bean = ent->CustomBean();
|
||||
auto url = QUrl(str);
|
||||
auto query = QUrlQuery(url.query());
|
||||
if (url.host().isEmpty() || url.port() == -1 || !query.hasQueryItem("upmbps")) return;
|
||||
bean->name = url.fragment();
|
||||
bean->serverAddress = url.host();
|
||||
bean->serverPort = url.port();
|
||||
bean->core = "hysteria";
|
||||
bean->command = QString(Preset::Hysteria::command).split(" ");
|
||||
auto result = QString2QJsonObject(Preset::Hysteria::config);
|
||||
result["obfs"] = query.queryItemValue("obfsParam");
|
||||
result["insecure"] = query.queryItemValue("insecure") == "1";
|
||||
result["up_mbps"] = query.queryItemValue("upmbps").toInt();
|
||||
result["down_mbps"] = query.queryItemValue("downmbps").toInt();
|
||||
result["protocol"] = query.hasQueryItem("protocol") ? query.queryItemValue("protocol") : "udp";
|
||||
if (query.hasQueryItem("auth")) result["auth_str"] = query.queryItemValue("auth");
|
||||
if (query.hasQueryItem("alpn")) result["alpn"] = query.queryItemValue("alpn");
|
||||
if (query.hasQueryItem("peer")) result["server_name"] = query.queryItemValue("peer");
|
||||
bean->config_simple = QJsonObject2QString(result, false);
|
||||
}
|
||||
|
||||
// End
|
||||
if (ent == nullptr) return;
|
||||
profileManager->AddProfile(ent, gid_add_to);
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "ui/edit/edit_custom.h"
|
||||
|
||||
#include "fmt/includes.h"
|
||||
#include "fmt/Preset.hpp"
|
||||
|
||||
#include "qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
|
||||
#include "main/GuiUtils.hpp"
|
||||
@@ -129,17 +130,8 @@ void DialogEditProfile::typeSelected(const QString &newType) {
|
||||
innerEditor = _innerWidget;
|
||||
if (type == "hysteria" || ent->CustomBean()->core == "hysteria") {
|
||||
_innerWidget->preset_core = type;
|
||||
_innerWidget->preset_command = "-c %config%";
|
||||
_innerWidget->preset_config = "{\n"
|
||||
" \"server\": \"127.0.0.1:%mapping_port%\",\n"
|
||||
" \"obfs\": \"fuck me till the daylight\",\n"
|
||||
" \"up_mbps\": 10,\n"
|
||||
" \"down_mbps\": 50,\n"
|
||||
" \"server_name\": \"real.name.com\",\n"
|
||||
" \"socks5\": {\n"
|
||||
" \"listen\": \"127.0.0.1:%socks_port%\"\n"
|
||||
" }\n"
|
||||
"}";
|
||||
_innerWidget->preset_command = Preset::Hysteria::command;
|
||||
_innerWidget->preset_config = Preset::Hysteria::config;
|
||||
}
|
||||
type = "custom";
|
||||
} else {
|
||||
|
||||
@@ -48,7 +48,7 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
// Generators
|
||||
if (bean->core == "hysteria") {
|
||||
ui->generator->setVisible(true);
|
||||
auto genHy = new GenHysteria(ent, preset_config);
|
||||
auto genHy = new GenHysteria(ent);
|
||||
ui->generator->layout()->addWidget(genHy);
|
||||
connect(genHy, &GenHysteria::config_generated, this, [=](const QString &result) {
|
||||
ui->config_simple->setText(result);
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
#include "ui_gen_hysteria.h"
|
||||
|
||||
#include "fmt/CustomBean.hpp"
|
||||
#include "fmt/Preset.hpp"
|
||||
|
||||
GenHysteria::GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, const QString &preset_config,
|
||||
QWidget *parent) :
|
||||
GenHysteria::GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, QWidget *parent) :
|
||||
QWidget(parent), ui(new Ui::GenHysteria) {
|
||||
ui->setupUi(this);
|
||||
this->ent = ent;
|
||||
this->preset_config = preset_config;
|
||||
}
|
||||
|
||||
GenHysteria::~GenHysteria() {
|
||||
@@ -16,7 +15,7 @@ GenHysteria::~GenHysteria() {
|
||||
}
|
||||
|
||||
void GenHysteria::on_gen_clicked() {
|
||||
auto result = QString2QJsonObject(preset_config);
|
||||
auto result = QString2QJsonObject(Preset::Hysteria::config);
|
||||
result["obfs"] = ui->obfs_password->text();
|
||||
result["insecure"] = ui->allow_insecure->isChecked();
|
||||
result["protocol"] = ui->protocol->currentText();
|
||||
|
||||
@@ -11,15 +11,13 @@ class GenHysteria : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, const QString &preset_config,
|
||||
QWidget *parent = nullptr);
|
||||
explicit GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, QWidget *parent = nullptr);
|
||||
|
||||
~GenHysteria() override;
|
||||
|
||||
private:
|
||||
Ui::GenHysteria *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
QString preset_config;
|
||||
|
||||
signals:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user