General improvements and bug fixes
This commit is contained in:
parent
07974a7e34
commit
187fa0080a
10 changed files with 762 additions and 144 deletions
|
|
@ -4,25 +4,32 @@
|
|||
#include <QThread>
|
||||
|
||||
#include "communicator.h"
|
||||
#include "core/openvpnconfigurator.h"
|
||||
#include "core/servercontroller.h"
|
||||
#include "debug.h"
|
||||
#include "defines.h"
|
||||
#include "mainwindow.h"
|
||||
#include "settings.h"
|
||||
#include "ui_mainwindow.h"
|
||||
#include "utils.h"
|
||||
#include "vpnconnection.h"
|
||||
|
||||
#include <QStandardPaths>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
ui(new Ui::MainWindow),
|
||||
m_settings(new Settings),
|
||||
m_vpnConnection(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Post initialization
|
||||
ui->widget_tittlebar->hide();
|
||||
ui->stackedWidget_main->setCurrentIndex(2);
|
||||
|
||||
if (m_settings->haveAuthData()) {
|
||||
goToPage(Page::Vpn);
|
||||
} else {
|
||||
goToPage(Page::Initialization);
|
||||
}
|
||||
|
||||
connect(ui->pushButton_blocked_list, SIGNAL(clicked(bool)), this, SLOT(onPushButtonBlockedListClicked(bool)));
|
||||
connect(ui->pushButton_connect, SIGNAL(toggled(bool)), this, SLOT(onPushButtonConnectToggled(bool)));
|
||||
|
|
@ -30,6 +37,9 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||
|
||||
connect(ui->pushButton_back_from_sites, SIGNAL(clicked(bool)), this, SLOT(onPushButtonBackFromSitesClicked(bool)));
|
||||
connect(ui->pushButton_back_from_settings, SIGNAL(clicked(bool)), this, SLOT(onPushButtonBackFromSettingsClicked(bool)));
|
||||
connect(ui->pushButton_new_server_setup, SIGNAL(clicked(bool)), this, SLOT(onPushButtonNewServerSetup(bool)));
|
||||
connect(ui->pushButton_back_from_new_server, SIGNAL(clicked(bool)), this, SLOT(onPushButtonBackFromNewServerClicked(bool)));
|
||||
connect(ui->pushButton_new_server_connect_with_new_data, SIGNAL(clicked(bool)), this, SLOT(onPushButtonNewServerConnectWithNewData(bool)));
|
||||
|
||||
setFixedSize(width(),height());
|
||||
|
||||
|
|
@ -66,9 +76,9 @@ MainWindow::~MainWindow()
|
|||
qDebug() << "Application closed";
|
||||
}
|
||||
|
||||
void MainWindow::goToIndex(int index)
|
||||
void MainWindow::goToPage(Page page)
|
||||
{
|
||||
ui->stackedWidget_main->setCurrentIndex(index);
|
||||
ui->stackedWidget_main->setCurrentIndex(static_cast<int>(page));
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent *event)
|
||||
|
|
@ -84,30 +94,60 @@ void MainWindow::keyPressEvent(QKeyEvent *event)
|
|||
}
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonNewServerConnectWithNewData(bool clicked)
|
||||
{
|
||||
if (ui->lineEdit_new_server_ip->text().isEmpty() ||
|
||||
ui->lineEdit_new_server_login->text().isEmpty() ||
|
||||
ui->lineEdit_new_server_password->text().isEmpty() ) {
|
||||
QMessageBox::warning(this, APPLICATION_NAME, tr("Please fill in all fields"));
|
||||
return;
|
||||
} else {
|
||||
qDebug() << "Start connection with new data";
|
||||
m_settings->setServerName(ui->lineEdit_new_server_ip->text());
|
||||
m_settings->setLogin(ui->lineEdit_new_server_login->text());
|
||||
m_settings->setPassword(ui->lineEdit_new_server_password->text());
|
||||
m_settings->save();
|
||||
|
||||
if (requestOvpnConfig(m_settings->serverName(), m_settings->login(), m_settings->password())) {
|
||||
goToPage(Page::Vpn);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::onBytesChanged(quint64 receivedData, quint64 sentData)
|
||||
{
|
||||
ui->label_speed_received->setText(VpnConnection::bytesToText(receivedData));
|
||||
ui->label_speed_sent->setText(VpnConnection::bytesToText(sentData));
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonBackFromNewServerClicked(bool)
|
||||
{
|
||||
goToPage(Page::Initialization);
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonNewServerSetup(bool)
|
||||
{
|
||||
goToPage(Page::NewServer);
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonBackFromSettingsClicked(bool)
|
||||
{
|
||||
goToIndex(2);
|
||||
goToPage(Page::Vpn);
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonBackFromSitesClicked(bool)
|
||||
{
|
||||
goToIndex(2);
|
||||
goToPage(Page::Vpn);
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonBlockedListClicked(bool)
|
||||
{
|
||||
goToIndex(3);
|
||||
goToPage(Page::Sites);
|
||||
}
|
||||
|
||||
void MainWindow::onPushButtonSettingsClicked(bool)
|
||||
{
|
||||
goToIndex(4);
|
||||
goToPage(Page::SomeSettings);
|
||||
}
|
||||
|
||||
void MainWindow::onConnectionStateChanged(VpnProtocol::ConnectionState state)
|
||||
|
|
@ -162,4 +202,32 @@ void MainWindow::onPushButtonConnectToggled(bool checked)
|
|||
}
|
||||
}
|
||||
|
||||
bool MainWindow::requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port, int timeout)
|
||||
{
|
||||
QSsh::SshConnectionParameters sshParams;
|
||||
sshParams.authenticationType = QSsh::SshConnectionParameters::AuthenticationTypePassword;
|
||||
sshParams.host = hostName;
|
||||
sshParams.userName = userName;
|
||||
sshParams.password = password;
|
||||
sshParams.timeout = timeout;
|
||||
sshParams.port = port;
|
||||
sshParams.hostKeyCheckingMode = QSsh::SshHostKeyCheckingMode::SshHostKeyCheckingNone;
|
||||
|
||||
if (!ServerController::setupServer(sshParams, ServerController::OpenVPN)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QString configData = OpenVpnConfigurator::genOpenVpnConfig(sshParams);
|
||||
if (configData.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile file(Utils::defaultVpnConfigFileName());
|
||||
if (file.open(QIODevice::WriteOnly | QIODevice::Truncate)){
|
||||
QTextStream stream(&file);
|
||||
stream << configData << endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "vpnprotocol.h"
|
||||
|
||||
class Settings;
|
||||
class VpnConnection;
|
||||
|
||||
namespace Ui {
|
||||
|
|
@ -22,28 +23,30 @@ public:
|
|||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
|
||||
enum class Page {Initialization = 0, NewServer = 1, Vpn = 2, Sites = 3, SomeSettings = 4, Share = 5};
|
||||
|
||||
private slots:
|
||||
void onPushButtonBlockedListClicked(bool clicked);
|
||||
void onPushButtonConnectToggled(bool checked);
|
||||
void onPushButtonSettingsClicked(bool clicked);
|
||||
|
||||
void onPushButtonBackFromSettingsClicked(bool clicked);
|
||||
void onPushButtonBackFromSitesClicked(bool clicked);
|
||||
|
||||
void onBytesChanged(quint64 receivedBytes, quint64 sentBytes);
|
||||
void onConnectionStateChanged(VpnProtocol::ConnectionState state);
|
||||
void onPushButtonBackFromNewServerClicked(bool clicked);
|
||||
void onPushButtonBackFromSettingsClicked(bool clicked);
|
||||
void onPushButtonBackFromSitesClicked(bool clicked);
|
||||
void onPushButtonBlockedListClicked(bool clicked);
|
||||
void onPushButtonConnectToggled(bool checked);
|
||||
void onPushButtonNewServerConnectWithNewData(bool clicked);
|
||||
void onPushButtonNewServerSetup(bool clicked);
|
||||
void onPushButtonSettingsClicked(bool clicked);
|
||||
|
||||
protected:
|
||||
void keyPressEvent(QKeyEvent* event);
|
||||
bool requestOvpnConfig(const QString& hostName, const QString& userName, const QString& password, int port = 22, int timeout = 30);
|
||||
|
||||
private:
|
||||
void goToIndex(int index);
|
||||
void goToPage(Page page);
|
||||
|
||||
Ui::MainWindow *ui;
|
||||
VpnConnection* m_vpnConnection;
|
||||
Settings* m_settings;
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ QStackedWidget QWidget {
|
|||
</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="page_connect_server">
|
||||
<widget class="QLabel" name="label_23">
|
||||
|
|
@ -291,12 +291,14 @@ color: #100A44;
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Подключиться к уже
|
||||
созданному серверу VPN</string>
|
||||
<string>Connect to the already created VPN server</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_24">
|
||||
<property name="geometry">
|
||||
|
|
@ -320,7 +322,7 @@ line-height: 150%;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Код для подключения</string>
|
||||
<string>Connection code</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QProgressBar" name="progressBar_new_server_connection_3">
|
||||
|
|
@ -346,7 +348,7 @@ border-radius: 4px;</string>
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="format">
|
||||
<string>Подключение...</string>
|
||||
<string>Connecting...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_25">
|
||||
|
|
@ -386,7 +388,7 @@ color: #333333;</string>
|
|||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_new_server_3">
|
||||
<widget class="QPushButton" name="pushButton_new_server_connect">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
|
|
@ -418,10 +420,10 @@ border-radius: 4px;
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Подключиться</string>
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_new_server_4">
|
||||
<widget class="QPushButton" name="pushButton_new_server_setup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
|
|
@ -455,7 +457,7 @@ border-radius: 4px;
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Настроить собственный сервер</string>
|
||||
<string>Set up your own server</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
@ -493,12 +495,14 @@ color: #100A44;
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Подключите ваш сервер,
|
||||
чтобы использовать VPN</string>
|
||||
<string>Connect your server to use VPN</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="geometry">
|
||||
|
|
@ -522,7 +526,7 @@ line-height: 150%;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>IP-адрес сервера</string>
|
||||
<string>Server IP address</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_5">
|
||||
|
|
@ -547,7 +551,7 @@ line-height: 150%;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Логин для подключения по SSH</string>
|
||||
<string>Login to connect via SSH</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_6">
|
||||
|
|
@ -572,7 +576,7 @@ line-height: 150%;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Пароль</string>
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_new_server_ip">
|
||||
|
|
@ -593,7 +597,7 @@ box-sizing: border-box;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>51.83.180.158</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_new_server_login">
|
||||
|
|
@ -614,7 +618,7 @@ box-sizing: border-box;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>root</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLineEdit" name="lineEdit_new_server_password">
|
||||
|
|
@ -635,13 +639,13 @@ box-sizing: border-box;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>qazqazwsxwsx</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="echoMode">
|
||||
<enum>QLineEdit::Password</enum>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_new_server">
|
||||
<widget class="QPushButton" name="pushButton_new_server_connect_with_new_data">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>40</x>
|
||||
|
|
@ -673,7 +677,7 @@ border-radius: 4px;
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Подключиться</string>
|
||||
<string>Connect</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
|
|
@ -701,7 +705,7 @@ text-align: center;
|
|||
color: #15CDCB;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Где взять данные для подключения →</string>
|
||||
<string>Where to get connection data →</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QProgressBar" name="progressBar_new_server_connection">
|
||||
|
|
@ -727,7 +731,7 @@ border-radius: 4px;</string>
|
|||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="format">
|
||||
<string>Подключение...</string>
|
||||
<string>Connecting...</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_back_from_new_server">
|
||||
|
|
@ -786,7 +790,7 @@ QPushButton:hover {
|
|||
<zorder>lineEdit_new_server_ip</zorder>
|
||||
<zorder>lineEdit_new_server_login</zorder>
|
||||
<zorder>lineEdit_new_server_password</zorder>
|
||||
<zorder>pushButton_new_server</zorder>
|
||||
<zorder>pushButton_new_server_connect_with_new_data</zorder>
|
||||
<zorder>pushButton</zorder>
|
||||
<zorder>pushButton_back_from_new_server</zorder>
|
||||
<zorder>label_7</zorder>
|
||||
|
|
@ -1196,7 +1200,7 @@ QPushButton:hover {
|
|||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>List of most popular prohibited sites</string>
|
||||
<string>List of the most popular prohibited sites</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
|
@ -1230,7 +1234,7 @@ line-height: 25px;
|
|||
color: #181922;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Эти сайты будут открываться через VPN</string>
|
||||
<string>These sites will open via VPN</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
|
||||
|
|
@ -1287,7 +1291,7 @@ box-sizing: border-box;</string>
|
|||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>Например, rutor.org или 17.21.111.8</string>
|
||||
<string>For example, rutor.org or 17.21.111.8</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="pushButton_sites_add_custom">
|
||||
|
|
@ -1334,7 +1338,7 @@ font-size: 18pt;</string>
|
|||
<string notr="true">color: #181922;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Удалить выбранный</string>
|
||||
<string>Delete selected item</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
|
|
@ -1359,7 +1363,7 @@ line-height: 150%;
|
|||
color: #333333;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Адрес сайта или ip-адрес</string>
|
||||
<string>Hostname or IP address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
@ -1675,7 +1679,7 @@ color: #A7A7A7;
|
|||
</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Тот, кто зайдёт с этим кодом, будет иметь те же права на испольтование VPN, что и вы. Чтобы создать новый код смените логин и/или пароль для подлючения в настройках вашего сервера.</string>
|
||||
<string>Anyone who logs in with this code will have the same rights to use the VPN as you. To create a new code, change your login and / or password for connection in your server settings.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignJustify|Qt::AlignVCenter</set>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue