diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..b48f94e --- /dev/null +++ b/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + + return a.exec(); +} diff --git a/mainwindow.cpp b/mainwindow.cpp new file mode 100644 index 0000000..8508d20 --- /dev/null +++ b/mainwindow.cpp @@ -0,0 +1,108 @@ +#include "mainwindow.h" +#include "ui_mainwindow.h" +#include +#include +#include +#include + +MainWindow::MainWindow(QWidget *parent) : + QMainWindow(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + QTimer *timer; + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), + this, SLOT(StatusUpdate())); + timer->start(10000); + StatusUpdate(); +} +MainWindow::~MainWindow() +{ + delete ui; +} +void MainWindow::StatusUpdate(){ + pid_t apache = system("pidof -s apache2"); + pid_t mysqld = system("pidof -s mysqld"); + pid_t ftp = system("pidof -s filezilla"); + if(apache != 256) + ui->label_8->setText("Running"); + else + ui->label_8->setText("Not Running"); + if(mysqld != 256) + ui->label_5->setText("Running"); + else + ui->label_5->setText("Not Running"); + if(ftp != 256) + ui->label_7->setText("Running"); + else + ui->label_7->setText("Not Running"); +} + +void MainWindow::bash(QString command) +{ + QProcess *p = new QProcess( this ); + + if (p) + { + p->setEnvironment( QProcess::systemEnvironment() ); + p->setProcessChannelMode( QProcess::MergedChannels ); + + p->start( command ); + p->waitForStarted(); + + connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) ); + connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) ); + } + +} + +void MainWindow::ReadOut(){ + QProcess *p = dynamic_cast( sender() ); + + if (p){ + ui->textBrowser->append( p->readAllStandardOutput() ); + } +} +void MainWindow::ReadErr(){ + QProcess *p = dynamic_cast( sender() ); + + if (p){ + ui->textBrowser->append( p->readAllStandardError() ); + } +} + +void MainWindow::on_apache_clicked() +{ + bash("service apache2 restart"); +} + +void MainWindow::on_mysql_clicked() +{ + bash("service mysql restart"); +} + +void MainWindow::on_ftp_clicked() +{ + bash("service filezilla restart"); +} + +void MainWindow::on_startall_clicked() +{ + bash("service apache2 restart"); + bash("service mysql restart"); + bash("service filezilla restart"); + +} + +void MainWindow::on_stopall_clicked() +{ + bash("service apache2 stop"); + bash("service mysql stop"); + bash("service filezilla stop"); +} + +void MainWindow::on_refreshall_clicked() +{ + StatusUpdate(); +} diff --git a/mainwindow.h b/mainwindow.h new file mode 100644 index 0000000..b3c67f1 --- /dev/null +++ b/mainwindow.h @@ -0,0 +1,34 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include + +namespace Ui { +class MainWindow; +} + +class MainWindow : public QMainWindow +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +private slots: + void on_apache_clicked(); + void on_mysql_clicked(); + void on_ftp_clicked(); + void bash(QString command); + void ReadOut(); + void ReadErr(); + void on_refreshall_clicked(); + void StatusUpdate(); + void on_startall_clicked(); + void on_stopall_clicked(); + +private: + Ui::MainWindow *ui; +}; + +#endif // MAINWINDOW_H diff --git a/mainwindow.ui b/mainwindow.ui new file mode 100644 index 0000000..1b6742e --- /dev/null +++ b/mainwindow.ui @@ -0,0 +1,148 @@ + + + MainWindow + + + + 0 + 0 + 431 + 440 + + + + Server Manager + + + + + 20 + 260 + 391 + 161 + + + + + + + 20 + 10 + 391 + 241 + + + + + + + + + Start All + + + + + + + Stop All + + + + + + + + + + + Services + + + + + + + MySQL + + + + + + + Restart + + + + + + + Restart + + + + + + + + + + + + + + + + + + + + + Restart + + + + + + + Apache + + + + + + + + + + + + + + FTP + + + + + + + Refresh Status + + + + + + + Status + + + + + + + + + + + + diff --git a/servermanager.pro b/servermanager.pro new file mode 100644 index 0000000..09bb831 --- /dev/null +++ b/servermanager.pro @@ -0,0 +1,20 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2020-08-01T22:02:13 +# +#------------------------------------------------- + +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +TARGET = ServerManager +TEMPLATE = app + + +SOURCES += main.cpp\ + mainwindow.cpp + +HEADERS += mainwindow.h + +FORMS += mainwindow.ui