Skip to content

Commit

Permalink
hysteria generator
Browse files Browse the repository at this point in the history
  • Loading branch information
arm64v8a committed Aug 9, 2022
1 parent 0b7abbe commit a3a0b1a
Show file tree
Hide file tree
Showing 11 changed files with 368 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ set(PROJECT_SOURCES
ui/edit/edit_trojan_vless.h
ui/edit/edit_trojan_vless.cpp
ui/edit/edit_trojan_vless.ui
ui/edit/gen_hysteria.h
ui/edit/gen_hysteria.cpp
ui/edit/gen_hysteria.ui

ui/edit/edit_naive.h
ui/edit/edit_naive.cpp
Expand Down
25 changes: 11 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,6 @@ https://matsuridayo.github.io
- `-many` 无视同目录正在运行的实例,强行开启新的实例 (0.11+)
- `-appdata` 开启后配置文件会放在共享目录,无法多开和自动升级 (0.11+)

### 代理

| 协议 | 状态 | 配置编辑 | 分享链接生成 | 分享链接解析 | Clash 配置解析 |
|--------------|--------|------|--------|-----------|------------|
| Socks ||||||
| HTTP ||||||
| Shadowsocks | ✅ (经典) ||| 常见格式 ||
| VMess |||| v2rayN 格式 ||
| Trojan |||| 标准&常见格式 ||
| VLESS ||||| 不适用 |
| NaïveProxy ||||| 不适用 |
| Hysteria ||||| 不适用 |

## Linux 运行 & 简易编译教程

**使用 Linux 系统相信您已具备基本的排错能力,
Expand Down Expand Up @@ -85,7 +72,7 @@ git submodule update
2. Qt 版本必须大于等于 5.15
3. 系统为 `x86-64-linux-gnu`

```
```shell
mkdir build
cd build
cmake -GNinja ..
Expand All @@ -104,6 +91,16 @@ C++ 部分

依赖搜寻 prefix 为 `libs/deps/bulit`

示例

```shell
./libs/build_deps_all.sh
mkdir build
cd build
cmake -GNinja ..
ninja
```

编译完成后得到 `nekoray`

Go 部分
Expand Down
39 changes: 37 additions & 2 deletions translations/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@
<source>Command</source>
<translation>命令</translation>
</message>
<message>
<source>Generator</source>
<translation>生成器</translation>
</message>
</context>
<context>
<name>EditNaive</name>
Expand Down Expand Up @@ -596,6 +600,37 @@
<translation></translation>
</message>
</context>
<context>
<name>GenHysteria</name>
<message>
<source>Generate</source>
<translation>生成配置</translation>
</message>
<message>
<source>Allow Insecure</source>
<translation>不检查服务器证书(不安全)</translation>
</message>
<message>
<source>Certificate Path</source>
<translation>证书路径</translation>
</message>
<message>
<source>Obfs Password</source>
<translation>混淆密码</translation>
</message>
<message>
<source>Auth String</source>
<translation>字符串验证密钥</translation>
</message>
<message>
<source>Protocol</source>
<translation>协议</translation>
</message>
<message>
<source>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/HyNetwork/hysteria/wiki&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;Document&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</source>
<translation>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;a href=&quot;https://github.com/HyNetwork/hysteria/wiki&quot;&gt;&lt;span style=&quot; text-decoration: underline; color:#2980b9;&quot;&gt;文档&lt;/span&gt;&lt;/a&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</translation>
</message>
</context>
<context>
<name>GroupItem</name>
<message>
Expand Down Expand Up @@ -999,8 +1034,8 @@ End: %2</source>
<translation>复制了 %1 个项目</translation>
</message>
<message>
<source>New profile from clipboard</source>
<translation>从剪切板添加</translation>
<source>Add profile from clipboard [ Ctrl+V ]</source>
<translation>从剪切板添加 [ Ctrl+V ]</translation>
</message>
<message>
<source>Full Test</source>
Expand Down
5 changes: 2 additions & 3 deletions ui/edit/dialog_edit_profile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
auto _innerWidget = new EditCustom(this);
innerWidget = _innerWidget;
innerEditor = _innerWidget;
// I don't want to write a settings
if (type == "hysteria") {
if (type == "hysteria" || ent->CustomBean()->core == "hysteria") {
_innerWidget->preset_core = type;
_innerWidget->preset_command = "-c %config%";
_innerWidget->preset_config = "{\n"
Expand All @@ -141,8 +140,8 @@ void DialogEditProfile::typeSelected(const QString &newType) {
" \"listen\": \"127.0.0.1:%socks_port%\"\n"
" }\n"
"}";
type = "custom";
}
type = "custom";
} else {
validType = false;
}
Expand Down
21 changes: 16 additions & 5 deletions ui/edit/edit_custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "qv2ray/v2/ui/widgets/editors/w_JsonEditor.hpp"
#include "fmt/CustomBean.hpp"
#include "ui/edit/gen_hysteria.h"

EditCustom::EditCustom(QWidget *parent) :
QWidget(parent), ui(new Ui::EditCustom) {
Expand Down Expand Up @@ -34,17 +35,27 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
ui->core->addItem(key);
}

if (!preset_core.isEmpty()) {
if (!bean->core.isEmpty()) {
ui->core->setDisabled(true);
} else if (!preset_core.isEmpty()) {
bean->core = preset_core;
ui->core->setCurrentText(preset_core);
ui->core->setDisabled(true);
ui->core->setCurrentText(preset_core);
ui->command->setText(preset_command);
ui->config_simple->setText(preset_config);
}
if (!bean->core.isEmpty()) {
ui->core->setDisabled(true);
}

// Generators
if (bean->core == "hysteria") {
ui->generator->setVisible(true);
auto genHy = new GenHysteria(ent, preset_config);
ui->generator->layout()->addWidget(genHy);
connect(genHy, &GenHysteria::config_generated, this, [=](const QString &result) {
ui->config_simple->setText(result);
});
} else {
ui->generator->setVisible(false);
}
}

bool EditCustom::onEnd() {
Expand Down
116 changes: 69 additions & 47 deletions ui/edit/edit_custom.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,93 @@
<x>0</x>
<y>0</y>
<width>400</width>
<height>394</height>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>EditCustom</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QHBoxLayout" name="layout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Core</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="core">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="as_json">
<property name="text">
<string>Json</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Core</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="core">
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="as_json">
<property name="text">
<string>Json</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Command</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Command</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="command">
<property name="placeholderText">
<string notr="true">%config%</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLineEdit" name="command">
<property name="placeholderText">
<string notr="true">%config%</string>
<widget class="QTextEdit" name="config_simple">
<property name="minimumSize">
<size>
<width>0</width>
<height>300</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QTextEdit" name="config_simple">
<property name="minimumSize">
<size>
<width>0</width>
<height>300</height>
</size>
<widget class="QGroupBox" name="generator">
<property name="title">
<string>Generator</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QWidget" name="fake" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
Expand All @@ -79,7 +102,6 @@
<tabstop>core</tabstop>
<tabstop>as_json</tabstop>
<tabstop>command</tabstop>
<tabstop>config_simple</tabstop>
</tabstops>
<resources/>
<connections/>
Expand Down
38 changes: 38 additions & 0 deletions ui/edit/gen_hysteria.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "gen_hysteria.h"
#include "ui_gen_hysteria.h"

#include "fmt/CustomBean.hpp"

GenHysteria::GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, const QString &preset_config,
QWidget *parent) :
QWidget(parent), ui(new Ui::GenHysteria) {
ui->setupUi(this);
this->ent = ent;
this->preset_config = preset_config;
}

GenHysteria::~GenHysteria() {
delete ui;
}

void GenHysteria::on_gen_clicked() {
auto result = QString2QJsonObject(preset_config);
result["obfs"] = ui->obfs_password->text();
result["insecure"] = ui->allow_insecure->isChecked();
result["protocol"] = ui->protocol->currentText();
result["up_mbps"] = ui->up_mbps->text().toInt();
result["down_mbps"] = ui->down_mbps->text().toInt();
if (!ui->auth_string->text().isEmpty()) {
result["auth_str"] = ui->auth_string->text();
}
if (!ui->alpn->text().isEmpty()) {
result["alpn"] = ui->alpn->text();
}
if (!ui->sni->text().isEmpty()) {
result["server_name"] = ui->sni->text();
}
if (!ui->cert_path->text().isEmpty()) {
result["ca"] = ui->cert_path->text();
}
emit config_generated(QJsonObject2QString(result, false));
}
31 changes: 31 additions & 0 deletions ui/edit/gen_hysteria.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#include <QWidget>
#include "db/ProxyEntity.hpp"

QT_BEGIN_NAMESPACE
namespace Ui { class GenHysteria; }
QT_END_NAMESPACE

class GenHysteria : public QWidget {
Q_OBJECT

public:
explicit GenHysteria(const QSharedPointer<NekoRay::ProxyEntity> &ent, const QString &preset_config,
QWidget *parent = nullptr);

~GenHysteria() override;

private:
Ui::GenHysteria *ui;
QSharedPointer<NekoRay::ProxyEntity> ent;
QString preset_config;

signals:

void config_generated(const QString &result);

private slots:

void on_gen_clicked();
};
Loading

0 comments on commit a3a0b1a

Please sign in to comment.