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