diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/main.cpp | 11 | ||||
-rw-r--r-- | client/mainwindow.cpp | 204 | ||||
-rw-r--r-- | client/mainwindow.h | 55 | ||||
-rw-r--r-- | client/mainwindow.ui | 100 | ||||
-rw-r--r-- | client/resources.qrc | 7 | ||||
-rw-r--r-- | client/restarter.pro | 29 |
6 files changed, 406 insertions, 0 deletions
diff --git a/client/main.cpp b/client/main.cpp new file mode 100644 index 0000000..9ae175b --- /dev/null +++ b/client/main.cpp @@ -0,0 +1,11 @@ +#include <QtGui/QApplication> +#include "mainwindow.h" + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/client/mainwindow.cpp b/client/mainwindow.cpp new file mode 100644 index 0000000..c6aa5cc --- /dev/null +++ b/client/mainwindow.cpp @@ -0,0 +1,204 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); +#ifdef MINIMAL + ui->halt->hide(); + ui->reboot->hide(); + ui->reboot->hide(); + ui->restart_cups->hide(); + ui->restart_ppp->hide(); + ui->state_lbl->hide(); + this->setFixedSize(ui->restart_vbox_btn->geometry().width() +17, ui->restart_vbox_btn->geometry().height() +17); +#else + this->setFixedSize(this->size()); +#endif + ui->state_lbl->setText(" "); +} + +QSslSocket *MainWindow::get_socket() +{ + QSslSocket *s = new QSslSocket; + QFile in(":/res/ca.crt"); + in.open(QIODevice::ReadOnly); + QByteArray buf = in.readAll(); + in.close(); + QList<QSslCertificate> ca_list; + ca_list.push_back(QSslCertificate(buf)); + s->setCaCertificates(ca_list); + in.setFileName(":/res/client.crt"); + in.open(QIODevice::ReadOnly); + buf = in.readAll(); + in.close(); + QSslCertificate c(buf); + s->setLocalCertificate(c); + in.setFileName(":/res/client.key"); + in.open(QIODevice::ReadOnly); + buf = in.readAll(); + QSslKey key(buf, QSsl::Rsa); + s->setPrivateKey(key); + s->setPeerVerifyMode(QSslSocket::VerifyPeer); + s->setProtocol(QSsl::SslV3); + connect(s, SIGNAL(peerVerifyError(QSslError)), this, SLOT(ssl_verify_error_handler(QSslError))); + + return s; +} + +void MainWindow::ssl_verify_error_handler(const QSslError error) +{ + switch(error.error()) + { + case QSslError::InvalidCaCertificate: case QSslError::NoPeerCertificate: case QSslError::UnspecifiedError: + case QSslError::AuthorityIssuerSerialNumberMismatch: + ui->state_lbl->setText(QString::fromUtf8("Ошибка соединения !")); + sock->abort(); + return; + default: + break; + } + sock->ignoreSslErrors(); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::enable_buttons(bool enable) +{ + ui->restart_vbox_btn->setEnabled(enable); + ui->reboot->setEnabled(enable); + ui->halt->setEnabled(enable); + ui->restart_cups->setEnabled(enable); + ui->restart_ppp->setEnabled(enable); + ui->restart_vbox_btn->setEnabled(enable); +} + + +void MainWindow::on_restart_vbox_btn_clicked() +{ + ui->state_lbl->setText(QString::fromUtf8("Подготовка..")); + sock = get_socket(); + ui->state_lbl->setText(QString::fromUtf8("Соединение..")); + sock->connectToHostEncrypted(host, 1313); + connect(sock, SIGNAL(encrypted()), SLOT(restart_vbox_sock_connected())); + connect(sock, SIGNAL(disconnected()), SLOT(disconnected())); +} + +void MainWindow::restart_vbox_sock_connected() +{ + ui->state_lbl->setText(QString::fromUtf8("Выполнение..")); + enable_buttons(false); + sock->write("restart vbox\0"); +} +void MainWindow::reboot() +{ + ui->state_lbl->setText(QString::fromUtf8("Выполнение..")); + enable_buttons(false); + sock->write("reboot now\0"); +} + +void MainWindow::halt() +{ + ui->state_lbl->setText(QString::fromUtf8("Выполнение..")); + enable_buttons(false); + sock->write("halt now\0"); +} + +void MainWindow::restart_cups() +{ + ui->state_lbl->setText(QString::fromUtf8("Выполнение..")); + enable_buttons(false); + sock->write("restart cups\0"); +} + +void MainWindow::restart_ppp() +{ + ui->state_lbl->setText(QString::fromUtf8("Выполнение..")); + enable_buttons(false); + sock->write("restart ppp\0"); +} + + +void MainWindow::disconnected() +{ + enable_buttons(true); + ui->state_lbl->setText(QString::fromUtf8(" ")); + sock->deleteLater(); +} + +void MainWindow::on_reboot_clicked() +{ +#ifndef MINIMAL + QMessageBox msg; + msg.setText(QString::fromUtf8("Вы видели куда ткнули ?")); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + if(msg.exec() == QMessageBox::Yes) + { + QMessageBox msg; + msg.setText(QString::fromUtf8("Уверены что хотите перезагрузить сервер ?")); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + if(msg.exec() == QMessageBox::Yes) + { + ui->state_lbl->setText(QString::fromUtf8("Подготовка..")); + sock = get_socket(); + ui->state_lbl->setText(QString::fromUtf8("Соединение..")); + sock->connectToHostEncrypted(host, 1313); + connect(sock, SIGNAL(encrypted()), SLOT(reboot())); + connect(sock, SIGNAL(disconnected()), SLOT(disconnected())); + } + } +#endif +} + +void MainWindow::on_halt_clicked() +{ +#ifndef MINIMAL + QMessageBox msg; + msg.setText(QString::fromUtf8("Вы видели куда ткнули ?")); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + if(msg.exec() == QMessageBox::Yes) + { + QMessageBox msg; + msg.setText(QString::fromUtf8("Уверены что хотите выключить сервер ?")); + msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No); + if(msg.exec() == QMessageBox::Yes) + { + ui->state_lbl->setText(QString::fromUtf8("Подготовка..")); + sock = get_socket(); + ui->state_lbl->setText(QString::fromUtf8("Соединение..")); + sock->connectToHostEncrypted(host, 1313); + connect(sock, SIGNAL(encrypted()), SLOT(halt())); + connect(sock, SIGNAL(disconnected()), SLOT(disconnected())); + } + } +#endif +} + +void MainWindow::on_restart_cups_clicked() +{ +#ifndef MINIMAL + ui->state_lbl->setText(QString::fromUtf8("Подготовка..")); + sock = get_socket(); + ui->state_lbl->setText(QString::fromUtf8("Соединение..")); + sock->connectToHostEncrypted(host, 1313); + connect(sock, SIGNAL(encrypted()), SLOT(restart_cups())); + connect(sock, SIGNAL(disconnected()), SLOT(disconnected())); +#endif +} + +void MainWindow::on_restart_ppp_clicked() +{ +#ifndef MINIMAL + ui->state_lbl->setText(QString::fromUtf8("Подготовка..")); + sock = get_socket(); + ui->state_lbl->setText(QString::fromUtf8("Соединение..")); + sock->connectToHostEncrypted(host, 1313); + connect(sock, SIGNAL(encrypted()), SLOT(restart_ppp())); + connect(sock, SIGNAL(disconnected()), SLOT(disconnected())); +#endif +} diff --git a/client/mainwindow.h b/client/mainwindow.h new file mode 100644 index 0000000..dea9301 --- /dev/null +++ b/client/mainwindow.h @@ -0,0 +1,55 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QMainWindow> +#include <QMessageBox> +#include <QSslSocket> +#include <QFile> +#include <QSslKey> + +#ifdef MINIMAL +const QString host = "192.168.0.1"; +#else +const QString host = "gluzskaya.ru"; +#endif + +namespace Ui { + class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +protected slots: + void ssl_verify_error_handler(const QSslError); + +private slots: + void on_restart_vbox_btn_clicked(); + void restart_vbox_sock_connected(); + void reboot(); + void halt(); + void restart_cups(); + void restart_ppp(); + void disconnected(); + + void on_reboot_clicked(); + + void on_halt_clicked(); + + void on_restart_cups_clicked(); + + void on_restart_ppp_clicked(); + +private: + void enable_buttons(bool); + QSslSocket *get_socket(); + Ui::MainWindow *ui; + QSslSocket *sock; +}; + +#endif // MAINWINDOW_H diff --git a/client/mainwindow.ui b/client/mainwindow.ui new file mode 100644 index 0000000..5894198 --- /dev/null +++ b/client/mainwindow.ui @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QMainWindow" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>685</width> + <height>389</height> + </rect> + </property> + <property name="windowTitle"> + <string>Окно</string> + </property> + <widget class="QWidget" name="centralWidget"> + <widget class="QPushButton" name="restart_vbox_btn"> + <property name="geometry"> + <rect> + <x>10</x> + <y>10</y> + <width>181</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Перезапустить vm (1c)</string> + </property> + </widget> + <widget class="QPushButton" name="reboot"> + <property name="geometry"> + <rect> + <x>520</x> + <y>320</y> + <width>161</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Перезагрузить сервер</string> + </property> + </widget> + <widget class="QPushButton" name="halt"> + <property name="geometry"> + <rect> + <x>520</x> + <y>350</y> + <width>161</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Выключить серверер</string> + </property> + </widget> + <widget class="QPushButton" name="restart_cups"> + <property name="geometry"> + <rect> + <x>10</x> + <y>40</y> + <width>231</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Перезапустить сервер печати</string> + </property> + </widget> + <widget class="QPushButton" name="restart_ppp"> + <property name="geometry"> + <rect> + <x>10</x> + <y>70</y> + <width>191</width> + <height>25</height> + </rect> + </property> + <property name="text"> + <string>Перезапустить интернет</string> + </property> + </widget> + <widget class="QLabel" name="state_lbl"> + <property name="geometry"> + <rect> + <x>10</x> + <y>370</y> + <width>491</width> + <height>16</height> + </rect> + </property> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </widget> + </widget> + <layoutdefault spacing="6" margin="11"/> + <resources/> + <connections/> +</ui> diff --git a/client/resources.qrc b/client/resources.qrc new file mode 100644 index 0000000..34e2d9e --- /dev/null +++ b/client/resources.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file>res/ca.crt</file> + <file>res/client.key</file> + <file>res/client.crt</file> + </qresource> +</RCC> diff --git a/client/restarter.pro b/client/restarter.pro new file mode 100644 index 0000000..31052b5 --- /dev/null +++ b/client/restarter.pro @@ -0,0 +1,29 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2011-12-15T07:02:21 +# +#------------------------------------------------- + +QT += core gui network + +TARGET = restarter +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui + +#DEFINES += MINIMAL + +QMAKE_CXXFLAGS += -Os -fomit-frame-pointer -std=gnu++0x +QMAKE_CFLAGS += -Os -fomit-frame-pointer -std=gnu99 + +LIBS += -Wl,-O1 + +RESOURCES += \ + resources.qrc + |