alpn settings

This commit is contained in:
arm64v8a
2022-08-13 13:53:16 +08:00
parent fd849f781b
commit 6931b4c8e1
9 changed files with 76 additions and 40 deletions

View File

@@ -17,30 +17,34 @@ namespace NekoRay::fmt {
if (network == "ws") { if (network == "ws") {
QJsonObject ws; QJsonObject ws;
if (!path.isEmpty()) ws["path"] = path; if (!path.trimmed().isEmpty()) ws["path"] = path;
if (!host.isEmpty()) ws["headers"] = QJsonObject{{"Host", host}}; if (!host.trimmed().isEmpty()) ws["headers"] = QJsonObject{{"Host", host}};
streamSettings["wsSettings"] = ws; streamSettings["wsSettings"] = ws;
} else if (network == "h2") { } else if (network == "h2") {
QJsonObject h2; QJsonObject h2;
if (!path.isEmpty()) h2["path"] = path; if (!path.trimmed().isEmpty()) h2["path"] = path;
if (!host.isEmpty()) h2["host"] = QList2QJsonArray(host.split(",")); if (!host.trimmed().isEmpty()) h2["host"] = QList2QJsonArray(host.split(","));
streamSettings["httpSettings"] = h2; streamSettings["httpSettings"] = h2;
} else if (network == "grpc") { } else if (network == "grpc") {
QJsonObject grpc; QJsonObject grpc;
if (!path.isEmpty()) grpc["serviceName"] = path; if (!path.trimmed().isEmpty()) grpc["serviceName"] = path;
streamSettings["grpcSettings"] = grpc; streamSettings["grpcSettings"] = grpc;
} }
if (security == "tls") { if (security == "tls") {
QJsonObject tls; QJsonObject tls;
if (!sni.isEmpty()) tls["serverName"] = sni;
if (allow_insecure || dataStore->skip_cert) tls["allowInsecure"] = true; if (allow_insecure || dataStore->skip_cert) tls["allowInsecure"] = true;
if (!certificate.isEmpty()) if (!sni.trimmed().isEmpty()) tls["serverName"] = sni;
if (!certificate.trimmed().isEmpty()) {
tls["certificates"] = QJsonArray{ tls["certificates"] = QJsonArray{
QJsonObject{ QJsonObject{
{"certificate", certificate}, {"certificate", certificate},
}, },
}; };
}
if (!alpn.trimmed().isEmpty()) {
tls["alpn"] = QList2QJsonArray(alpn.split(","));
}
streamSettings["tlsSettings"] = tls; streamSettings["tlsSettings"] = tls;
} }
@@ -94,7 +98,7 @@ namespace NekoRay::fmt {
servers.push_back(server); servers.push_back(server);
settings["servers"] = servers; settings["servers"] = servers;
if (!plugin.isEmpty()) { if (!plugin.trimmed().isEmpty()) {
settings["plugin"] = SubStrBefore(plugin, ";"); settings["plugin"] = SubStrBefore(plugin, ";");
settings["pluginOpts"] = SubStrAfter(plugin, ";"); settings["pluginOpts"] = SubStrAfter(plugin, ";");
} }

View File

@@ -11,13 +11,11 @@ namespace NekoRay::fmt {
// ws/h2/grpc // ws/h2/grpc
QString path = ""; QString path = "";
QString host = ""; QString host = "";
// ws
int max_early_data = 0;
QString early_data_header_name = "";
// QUIC & KCP // QUIC & KCP
QString header_type = ""; QString header_type = "";
// tls // tls
QString sni = ""; QString sni = "";
QString alpn = "";
QString certificate = ""; QString certificate = "";
bool allow_insecure = false; bool allow_insecure = false;
@@ -28,10 +26,9 @@ namespace NekoRay::fmt {
_add(new configItem("path", &path, itemType::string)); _add(new configItem("path", &path, itemType::string));
_add(new configItem("host", &host, itemType::string)); _add(new configItem("host", &host, itemType::string));
_add(new configItem("sni", &sni, itemType::string)); _add(new configItem("sni", &sni, itemType::string));
_add(new configItem("alpn", &alpn, itemType::string));
_add(new configItem("cert", &certificate, itemType::string)); _add(new configItem("cert", &certificate, itemType::string));
_add(new configItem("insecure", &allow_insecure, itemType::boolean)); _add(new configItem("insecure", &allow_insecure, itemType::boolean));
_add(new configItem("ws_med", &max_early_data, itemType::integer));
_add(new configItem("ws_edhn", &early_data_header_name, itemType::string));
_add(new configItem("h_type", &header_type, itemType::string)); _add(new configItem("h_type", &header_type, itemType::string));
} }

View File

@@ -205,8 +205,6 @@ namespace NekoRay::sub {
} }
} }
bean->stream->path = Node2QString(ws["path"]); bean->stream->path = Node2QString(ws["path"]);
bean->stream->max_early_data = Node2Int(proxy["max-early-data"]);
bean->stream->early_data_header_name = Node2QString(ws["early-data-header-name"]);
} }
auto grpc = proxy["grpc-opts"]; auto grpc = proxy["grpc-opts"];

View File

@@ -273,10 +273,6 @@
<source>Host</source> <source>Host</source>
<translation>(Host)</translation> <translation>(Host)</translation>
</message> </message>
<message>
<source>SNI</source>
<translation></translation>
</message>
<message> <message>
<source>Custom</source> <source>Custom</source>
<translation></translation> <translation></translation>
@@ -997,10 +993,6 @@ End: %2</source>
<source>Export V2ray config</source> <source>Export V2ray config</source>
<translation> V2ray </translation> <translation> V2ray </translation>
</message> </message>
<message>
<source>QR Code and link (Nekoray)</source>
<translation> QR Code (Nekoray)</translation>
</message>
<message> <message>
<source>Active Routing</source> <source>Active Routing</source>
<translation></translation> <translation></translation>
@@ -1085,6 +1077,10 @@ End: %2</source>
<source>Clone %1 item(s)</source> <source>Clone %1 item(s)</source>
<translation> %1 </translation> <translation> %1 </translation>
</message> </message>
<message>
<source>Copy links of selected (Nekoray)</source>
<translation> (Nekoray)</translation>
</message>
</context> </context>
<context> <context>
<name>ProxyItem</name> <name>ProxyItem</name>

View File

@@ -173,6 +173,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
ui->path->setText(stream->path); ui->path->setText(stream->path);
ui->host->setText(stream->host); ui->host->setText(stream->host);
ui->sni->setText(stream->sni); ui->sni->setText(stream->sni);
ui->alpn->setText(stream->alpn);
ui->insecure->setChecked(stream->allow_insecure); ui->insecure->setChecked(stream->allow_insecure);
CACHE.certificate = stream->certificate; CACHE.certificate = stream->certificate;
} else { } else {
@@ -209,6 +210,14 @@ void DialogEditProfile::typeSelected(const QString &newType) {
ui->port->setText(Int2String(ent->bean->serverPort)); ui->port->setText(Int2String(ent->bean->serverPort));
ui->port->setValidator(QRegExpValidator_Number, this)); ui->port->setValidator(QRegExpValidator_Number, this));
// 星号
for (auto label: findChildren<QLabel *>()) {
auto text = label->text();
if (!label->toolTip().isEmpty() && !text.endsWith("*")) {
label->setText(text + "*");
}
}
editor_cache_updated_impl(); editor_cache_updated_impl();
ADJUST_SIZE ADJUST_SIZE
@@ -238,6 +247,7 @@ void DialogEditProfile::accept() {
stream->path = ui->path->text(); stream->path = ui->path->text();
stream->host = ui->host->text(); stream->host = ui->host->text();
stream->sni = ui->sni->text(); stream->sni = ui->sni->text();
stream->alpn = ui->alpn->text();
stream->allow_insecure = ui->insecure->isChecked(); stream->allow_insecure = ui->insecure->isChecked();
stream->certificate = CACHE.certificate; stream->certificate = CACHE.certificate;
} }

View File

@@ -157,6 +157,9 @@
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="toolTip">
<string/>
</property>
<layout class="QVBoxLayout" name="right_layout"> <layout class="QVBoxLayout" name="right_layout">
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum> <enum>QLayout::SetDefaultConstraint</enum>
@@ -365,27 +368,17 @@
</item> </item>
<item> <item>
<layout class="QGridLayout" name="_3"> <layout class="QGridLayout" name="_3">
<item row="1" column="1"> <item row="2" column="1">
<widget class="QPushButton" name="certificate_edit"> <widget class="QPushButton" name="certificate_edit">
<property name="text"> <property name="text">
<string notr="true">PushButton</string> <string notr="true">PushButton</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0"> <item row="2" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string notr="true">服务器名称指示,明文。</string>
</property>
<property name="text">
<string>SNI</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="toolTip"> <property name="toolTip">
<string notr="true">固定证书</string> <string notr="true"/>
</property> </property>
<property name="text"> <property name="text">
<string>Certificate</string> <string>Certificate</string>
@@ -395,6 +388,29 @@
<item row="0" column="1"> <item row="0" column="1">
<widget class="MyLineEdit" name="sni"/> <widget class="MyLineEdit" name="sni"/>
</item> </item>
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="toolTip">
<string notr="true">服务器名称指示,明文。</string>
</property>
<property name="text">
<string notr="true">SNI</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="toolTip">
<string notr="true">应用层协议协商,明文。多个请以英文逗号分隔。</string>
</property>
<property name="text">
<string notr="true">ALPN</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="MyLineEdit" name="alpn"/>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@@ -344,7 +344,6 @@ MainWindow::MainWindow(QWidget *parent)
connect(ui->menu_spmode_disabled, &QAction::triggered, this, connect(ui->menu_spmode_disabled, &QAction::triggered, this,
[=]() { neko_set_spmode(NekoRay::SystemProxyMode::DISABLE); }); [=]() { neko_set_spmode(NekoRay::SystemProxyMode::DISABLE); });
connect(ui->menu_qr, &QAction::triggered, this, [=]() { display_qr_link(false); }); connect(ui->menu_qr, &QAction::triggered, this, [=]() { display_qr_link(false); });
connect(ui->menu_qr_nkr, &QAction::triggered, this, [=]() { display_qr_link(true); });
connect(ui->menu_tcp_ping, &QAction::triggered, this, [=]() { speedtest_current_group(0); }); connect(ui->menu_tcp_ping, &QAction::triggered, this, [=]() { speedtest_current_group(0); });
connect(ui->menu_url_test, &QAction::triggered, this, [=]() { speedtest_current_group(1); }); connect(ui->menu_url_test, &QAction::triggered, this, [=]() { speedtest_current_group(1); });
connect(ui->menu_full_test, &QAction::triggered, this, [=]() { speedtest_current_group(2); }); connect(ui->menu_full_test, &QAction::triggered, this, [=]() { speedtest_current_group(2); });
@@ -963,6 +962,17 @@ void MainWindow::on_menu_copy_links_triggered() {
MessageBoxInfo("NekoRay", tr("Copied %1 item(s)").arg(links.length())); MessageBoxInfo("NekoRay", tr("Copied %1 item(s)").arg(links.length()));
} }
void MainWindow::on_menu_copy_links_nkr_triggered() {
auto ents = get_now_selected();
QStringList links;
for (const auto &ent: ents) {
links += ent->bean->ToNekorayShareLink(ent->type);
}
if (links.length() == 0) return;
QApplication::clipboard()->setText(links.join("\n"));
MessageBoxInfo("NekoRay", tr("Copied %1 item(s)").arg(links.length()));
}
void MainWindow::on_menu_export_config_triggered() { void MainWindow::on_menu_export_config_triggered() {
auto ents = get_now_selected(); auto ents = get_now_selected();
if (ents.count() != 1) return; if (ents.count() != 1) return;

View File

@@ -86,6 +86,8 @@ private slots:
void on_menu_copy_links_triggered(); void on_menu_copy_links_triggered();
void on_menu_copy_links_nkr_triggered();
void on_menu_export_config_triggered(); void on_menu_export_config_triggered();
void display_qr_link(bool nkrFormat = false); void display_qr_link(bool nkrFormat = false);

View File

@@ -512,10 +512,10 @@
<string>Share</string> <string>Share</string>
</property> </property>
<addaction name="menu_qr"/> <addaction name="menu_qr"/>
<addaction name="menu_qr_nkr"/>
<addaction name="menu_export_config"/> <addaction name="menu_export_config"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="menu_copy_links"/> <addaction name="menu_copy_links"/>
<addaction name="menu_copy_links_nkr"/>
</widget> </widget>
<widget class="QMenu" name="menugroup"> <widget class="QMenu" name="menugroup">
<property name="title"> <property name="title">
@@ -755,9 +755,12 @@
<string notr="true">Ctrl+A</string> <string notr="true">Ctrl+A</string>
</property> </property>
</action> </action>
<action name="menu_qr_nkr"> <action name="menu_copy_links_nkr">
<property name="text"> <property name="text">
<string>QR Code and link (Nekoray)</string> <string>Copy links of selected (Nekoray)</string>
</property>
<property name="shortcut">
<string notr="true">Ctrl+Alt+C</string>
</property> </property>
</action> </action>
<action name="actionfake_2"> <action name="actionfake_2">