monitor.cpp
author Markus Bröker <mbroeker@largo.homelinux.org>
Sat, 13 Dec 2008 15:45:18 +0100
changeset 0 826dd5531eb0
child 4 fdf04a93faeb
permissions -rw-r--r--
svn copy of qmonitor
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     1
/*
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     2
 *  $Id: monitor.cpp 54 2008-01-10 00:24:52Z mbroeker $
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     3
 * $URL: http://localhost/svn/cpp/qMonitor/trunk/monitor.cpp $
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     4
 */
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     5
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     6
#include "include/monitor.h"
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     7
#include "include/readerthread.h"
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     8
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
     9
#ifndef ICON_PATH
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    10
#define ICON_PATH "/usr/share/icons/qMonitor_icon.png"
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    11
#endif
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    12
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    13
#define HTML_MESSAGE \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    14
"<p align='center'><h1>qMonitor</h1><br></p>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    15
"<p align='center'>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    16
"<li>W&auml;hlen Sie das Protokoll</li>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    17
"<li>W&auml;hlen Sie einen Port (0=ALLE)</li>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    18
"<li>Dr&uuml;cken Sie Start</li>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    19
"<br><br>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    20
"<h5>Dieses Programm zeigt den Traffic im Netz an und unterst&uuml;tzt Sie bei t&auml;glichen Aufgaben:</h5><br><br>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    21
"<li>Kontrolle der TCP/UDP Verbindungen</li>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    22
"<li>&Uuml;berwachung von textbasierten Serverdiensten</li>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    23
"<li>Protokollanalyse</li>" \
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    24
"</p>"
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    25
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    26
Monitor::Monitor (QWidget * parent)
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    27
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    28
    setupUi ((QDialog *) this);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    29
    textEdit->setReadOnly (true);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    30
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    31
    listWidget1->insertItem (0, "TCP");
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    32
    listWidget1->insertItem (1, "UDP");
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    33
    listWidget1->insertItem (2, "ICMP");
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    34
    listWidget1->insertItem (3, "RAW");
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    35
    listWidget1->insertItem (4, "IP");
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    36
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    37
    Protocol["TCP"] = IPPROTO_TCP;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    38
    Protocol["UDP"] = IPPROTO_UDP;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    39
    Protocol["ICMP"] = IPPROTO_ICMP;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    40
    Protocol["RAW"] = IPPROTO_RAW;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    41
    Protocol["IP"] = IPPROTO_IP;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    42
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    43
    listWidget1->setCurrentRow (0);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    44
    lineEdit1->setText ("0");
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    45
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    46
    setWindowIcon (QPixmap (ICON_PATH));
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    47
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    48
    textEdit->insertHtml (HTML_MESSAGE);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    49
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    50
    try {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    51
        reader = new readerThread (this);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    52
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    53
    catch (std::exception const &e) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    54
        textEdit->append (e.what ());
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    55
        reader = NULL;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    56
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    57
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    58
    connect (pushButton1, SIGNAL (clicked ()), this, SLOT (startCapture ()));
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    59
    connect (pushButton2, SIGNAL (clicked ()), this, SLOT (stopCapture ()));
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    60
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    61
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    62
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    63
Monitor::~Monitor ()
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    64
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    65
    if (reader != NULL)
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    66
        delete reader;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    67
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    68
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    69
void Monitor::startCapture ()
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    70
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    71
    textEdit->clear ();
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    72
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    73
    if (reader != NULL) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    74
        if (!reader->isRunning ())
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    75
            reader->start (QThread::NormalPriority);
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    76
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    77
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    78
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    79
void Monitor::stopCapture ()
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    80
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    81
    if (reader != NULL) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    82
        if (reader->isRunning ())
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    83
            reader->terminate ();
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    84
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    85
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    86
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    87
int Monitor::getProtocol ()
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    88
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    89
    return Protocol[listWidget1->item (listWidget1->currentRow ())->text ()];
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    90
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    91
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    92
int Monitor::getPort ()
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    93
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    94
    return lineEdit1->text ().toInt ();
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    95
}
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    96
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    97
void Monitor::customEvent (QEvent * e)
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    98
{
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
    99
    if (e->type () == MSG_EVENT) {
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
   100
        DataChangeEvent *me = (DataChangeEvent *) e;
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
   101
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
   102
        textEdit->append (me->Text ());
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
   103
    }
826dd5531eb0 svn copy of qmonitor
Markus Bröker <mbroeker@largo.homelinux.org>
parents:
diff changeset
   104
}