-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
108 lines (92 loc) · 2.33 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QProcess>
#include <QString>
#include <QDebug>
#include <QTimer>
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 mariadb");
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<QProcess *>( sender() );
if (p){
ui->textBrowser->append( p->readAllStandardOutput() );
}
}
void MainWindow::ReadErr(){
QProcess *p = dynamic_cast<QProcess *>( sender() );
if (p){
ui->textBrowser->append( p->readAllStandardError() );
}
}
void MainWindow::on_apache_clicked()
{
bash("service apache2 restart");
}
void MainWindow::on_mysql_clicked()
{
bash("service mariadb restart");
}
void MainWindow::on_ftp_clicked()
{
bash("service filezilla restart");
}
void MainWindow::on_startall_clicked()
{
bash("service apache2 restart");
bash("service mariadb restart");
bash("service filezilla restart");
}
void MainWindow::on_stopall_clicked()
{
bash("service apache2 stop");
bash("service mariadb stop");
bash("service filezilla stop");
}
void MainWindow::on_refreshall_clicked()
{
StatusUpdate();
}