mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-19 13:50:12 +08:00
parse hysteria share link
This commit is contained in:
parent
6931b4c8e1
commit
38e51be766
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,
|
VPN,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,10 +3,12 @@
|
|||||||
#include "db/Database.hpp"
|
#include "db/Database.hpp"
|
||||||
#include "db/ProfileFilter.hpp"
|
#include "db/ProfileFilter.hpp"
|
||||||
#include "fmt/includes.h"
|
#include "fmt/includes.h"
|
||||||
|
#include "fmt/Preset.hpp"
|
||||||
|
|
||||||
#include "GroupUpdater.hpp"
|
#include "GroupUpdater.hpp"
|
||||||
|
|
||||||
#include <QInputDialog>
|
#include <QInputDialog>
|
||||||
|
#include <QUrlQuery>
|
||||||
|
|
||||||
#ifndef NKR_NO_EXTERNAL
|
#ifndef NKR_NO_EXTERNAL
|
||||||
|
|
||||||
@ -105,6 +107,31 @@ namespace NekoRay::sub {
|
|||||||
if (!ok) return;
|
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
|
// End
|
||||||
if (ent == nullptr) return;
|
if (ent == nullptr) return;
|
||||||
profileManager->AddProfile(ent, gid_add_to);
|
profileManager->AddProfile(ent, gid_add_to);
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include "ui/edit/edit_custom.h"
|
#include "ui/edit/edit_custom.h"
|
||||||
|
|
||||||
#include "fmt/includes.h"
|
#include "fmt/includes.h"
|
||||||
|
#include "fmt/Preset.hpp"
|
||||||
|
|
||||||
#include "qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
|
#include "qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
|
||||||
#include "main/GuiUtils.hpp"
|
#include "main/GuiUtils.hpp"
|
||||||
@ -129,17 +130,8 @@ void DialogEditProfile::typeSelected(const QString &newType) {
|
|||||||
innerEditor = _innerWidget;
|
innerEditor = _innerWidget;
|
||||||
if (type == "hysteria" || ent->CustomBean()->core == "hysteria") {
|
if (type == "hysteria" || ent->CustomBean()->core == "hysteria") {
|
||||||
_innerWidget->preset_core = type;
|
_innerWidget->preset_core = type;
|
||||||
_innerWidget->preset_command = "-c %config%";
|
_innerWidget->preset_command = Preset::Hysteria::command;
|
||||||
_innerWidget->preset_config = "{\n"
|
_innerWidget->preset_config = Preset::Hysteria::config;
|
||||||
" \"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"
|
|
||||||
"}";
|
|
||||||
}
|
}
|
||||||
type = "custom";
|
type = "custom";
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -48,7 +48,7 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
|||||||
// Generators
|
// Generators
|
||||||
if (bean->core == "hysteria") {
|
if (bean->core == "hysteria") {
|
||||||
ui->generator->setVisible(true);
|
ui->generator->setVisible(true);
|
||||||
auto genHy = new GenHysteria(ent, preset_config);
|
auto genHy = new GenHysteria(ent);
|
||||||
ui->generator->layout()->addWidget(genHy);
|
ui->generator->layout()->addWidget(genHy);
|
||||||
connect(genHy, &GenHysteria::config_generated, this, [=](const QString &result) {
|
connect(genHy, &GenHysteria::config_generated, this, [=](const QString &result) {
|
||||||
ui->config_simple->setText(result);
|
ui->config_simple->setText(result);
|
||||||
|
|||||||
@ -2,13 +2,12 @@
|
|||||||
#include "ui_gen_hysteria.h"
|
#include "ui_gen_hysteria.h"
|
||||||
|
|
||||||
#include "fmt/CustomBean.hpp"
|
#include "fmt/CustomBean.hpp"
|
||||||
|
#include "fmt/Preset.hpp"
|
||||||
|
|
||||||
GenHysteria::GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, const QString &preset_config,
|
GenHysteria::GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, QWidget *parent) :
|
||||||
QWidget *parent) :
|
|
||||||
QWidget(parent), ui(new Ui::GenHysteria) {
|
QWidget(parent), ui(new Ui::GenHysteria) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->ent = ent;
|
this->ent = ent;
|
||||||
this->preset_config = preset_config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GenHysteria::~GenHysteria() {
|
GenHysteria::~GenHysteria() {
|
||||||
@ -16,7 +15,7 @@ GenHysteria::~GenHysteria() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GenHysteria::on_gen_clicked() {
|
void GenHysteria::on_gen_clicked() {
|
||||||
auto result = QString2QJsonObject(preset_config);
|
auto result = QString2QJsonObject(Preset::Hysteria::config);
|
||||||
result["obfs"] = ui->obfs_password->text();
|
result["obfs"] = ui->obfs_password->text();
|
||||||
result["insecure"] = ui->allow_insecure->isChecked();
|
result["insecure"] = ui->allow_insecure->isChecked();
|
||||||
result["protocol"] = ui->protocol->currentText();
|
result["protocol"] = ui->protocol->currentText();
|
||||||
|
|||||||
@ -11,15 +11,13 @@ class GenHysteria : public QWidget {
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, const QString &preset_config,
|
explicit GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, QWidget *parent = nullptr);
|
||||||
QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
~GenHysteria() override;
|
~GenHysteria() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::GenHysteria *ui;
|
Ui::GenHysteria *ui;
|
||||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||||
QString preset_config;
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user