mirror of https://github.com/procxx/kepka.git
Support tg://proxy links.
This commit is contained in:
parent
dc9483e07a
commit
8e99135f37
|
@ -23,18 +23,36 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "application.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
||||
void ConnectionBox::ShowApplyProxyConfirmation(const QMap<QString, QString> &fields) {
|
||||
auto server = fields.value(qsl("server"));
|
||||
auto port = fields.value(qsl("port")).toUInt();
|
||||
if (!server.isEmpty() && port != 0) {
|
||||
void ConnectionBox::ShowApplyProxyConfirmation(
|
||||
ProxyData::Type type,
|
||||
const QMap<QString, QString> &fields) {
|
||||
const auto server = fields.value(qsl("server"));
|
||||
const auto port = fields.value(qsl("port")).toUInt();
|
||||
const auto secret = fields.value(qsl("secret"));
|
||||
const auto valid = !server.isEmpty()
|
||||
&& (port != 0)
|
||||
&& (type != ProxyData::Type::Mtproto
|
||||
|| ProxyData::ValidSecret(secret))
|
||||
&& (type == ProxyData::Type::Socks5
|
||||
|| type == ProxyData::Type::Mtproto);
|
||||
if (valid) {
|
||||
const auto box = std::make_shared<QPointer<ConfirmBox>>();
|
||||
*box = Ui::show(Box<ConfirmBox>(lng_sure_enable_socks(lt_server, server, lt_port, QString::number(port)), lang(lng_sure_enable), [=] {
|
||||
const auto text = lng_sure_enable_socks(
|
||||
lt_server,
|
||||
server,
|
||||
lt_port,
|
||||
QString::number(port));
|
||||
*box = Ui::show(Box<ConfirmBox>(text, lang(lng_sure_enable), [=] {
|
||||
auto proxy = ProxyData();
|
||||
proxy.type = ProxyData::Type::Socks5;
|
||||
proxy.type = type;
|
||||
proxy.host = server;
|
||||
proxy.user = fields.value(qsl("user"));
|
||||
proxy.password = fields.value(qsl("pass"));
|
||||
proxy.port = port;
|
||||
if (type == ProxyData::Type::Socks5) {
|
||||
proxy.user = fields.value(qsl("user"));
|
||||
proxy.password = fields.value(qsl("pass"));
|
||||
} else if (type == ProxyData::Type::Mtproto) {
|
||||
proxy.password = secret;
|
||||
}
|
||||
Global::SetConnectionType(dbictTcpProxy);
|
||||
Global::SetConnectionProxy(proxy);
|
||||
Local::writeSettings();
|
||||
|
|
|
@ -26,7 +26,9 @@ class ConnectionBox : public BoxContent {
|
|||
public:
|
||||
ConnectionBox(QWidget *parent);
|
||||
|
||||
static void ShowApplyProxyConfirmation(const QMap<QString, QString> &fields);
|
||||
static void ShowApplyProxyConfirmation(
|
||||
ProxyData::Type type,
|
||||
const QMap<QString, QString> &fields);
|
||||
|
||||
protected:
|
||||
void prepare() override;
|
||||
|
|
|
@ -50,6 +50,8 @@ QString tryConvertUrlToLocal(QString url) {
|
|||
return url;
|
||||
} else if (auto socksMatch = regex_match(qsl("socks/?\\?(.+)(#|$)"), query, matchOptions)) {
|
||||
return qsl("tg://socks?") + socksMatch->captured(1);
|
||||
} else if (auto proxyMatch = regex_match(qsl("proxy/?\\?(.+)(#|$)"), query, matchOptions)) {
|
||||
return qsl("tg://proxy?") + proxyMatch->captured(1);
|
||||
} else if (auto usernameMatch = regex_match(qsl("^([a-zA-Z0-9\\.\\_]+)(/?\\?|/?$|/(\\d+)/?(?:\\?|$))"), query, matchOptions)) {
|
||||
auto params = query.mid(usernameMatch->captured(0).size()).toString();
|
||||
auto postParam = QString();
|
||||
|
|
|
@ -236,6 +236,10 @@ namespace {
|
|||
_MsStarter _msStarter;
|
||||
}
|
||||
|
||||
bool ProxyData::ValidSecret(const QString &secret) {
|
||||
return QRegularExpression("^[a-fA-F0-9]{32}$").match(secret).hasMatch();
|
||||
}
|
||||
|
||||
namespace ThirdParty {
|
||||
|
||||
void start() {
|
||||
|
|
|
@ -434,10 +434,14 @@ struct ProxyData {
|
|||
Http,
|
||||
Mtproto,
|
||||
};
|
||||
|
||||
Type type = Type::None;
|
||||
QString host;
|
||||
uint32 port = 0;
|
||||
QString user, password;
|
||||
|
||||
static bool ValidSecret(const QString &secret);
|
||||
|
||||
};
|
||||
|
||||
enum DBIScale {
|
||||
|
|
|
@ -838,7 +838,11 @@ bool Messenger::openLocalUrl(const QString &url) {
|
|||
}
|
||||
} else if (auto socksMatch = regex_match(qsl("^socks/?\\?(.+)(#|$)"), command, matchOptions)) {
|
||||
auto params = url_parse_params(socksMatch->captured(1), UrlParamNameTransform::ToLower);
|
||||
ConnectionBox::ShowApplyProxyConfirmation(params);
|
||||
ConnectionBox::ShowApplyProxyConfirmation(ProxyData::Type::Socks5, params);
|
||||
return true;
|
||||
} else if (auto proxyMatch = regex_match(qsl("^proxy/?\\?(.+)(#|$)"), command, matchOptions)) {
|
||||
auto params = url_parse_params(proxyMatch->captured(1), UrlParamNameTransform::ToLower);
|
||||
ConnectionBox::ShowApplyProxyConfirmation(ProxyData::Type::Mtproto, params);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<(src_loc)/base/algorithm.h
|
||||
<(src_loc)/base/assertion.h
|
||||
<(src_loc)/base/build_config.h
|
||||
<(src_loc)/base/bytes.h
|
||||
<(src_loc)/base/flags.h
|
||||
<(src_loc)/base/enum_mask.h
|
||||
<(src_loc)/base/flat_map.h
|
||||
|
|
Loading…
Reference in New Issue