author | mickeyl <mickeyl> | 2003-12-11 16:50:19 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-12-11 16:50:19 (UTC) |
commit | a54fcb766991ed3d813be5f0b066998082378933 (patch) (unidiff) | |
tree | 6e8027d27da67d1e5d09e68aef9d9395143b80a8 | |
parent | 0983ec0c341b6509d2ba8df2c8ca06b137623681 (diff) | |
download | opie-a54fcb766991ed3d813be5f0b066998082378933.zip opie-a54fcb766991ed3d813be5f0b066998082378933.tar.gz opie-a54fcb766991ed3d813be5f0b066998082378933.tar.bz2 |
more work on uploading dumps to The Capture Dump(TM)
-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 127 |
1 files changed, 124 insertions, 3 deletions
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index ab7e0c7..88a474d 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp | |||
@@ -1,375 +1,496 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. | 2 | ** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. |
3 | ** | 3 | ** |
4 | ** This file is part of Opie Environment. | 4 | ** This file is part of Opie Environment. |
5 | ** | 5 | ** |
6 | ** This file may be distributed and/or modified under the terms of the | 6 | ** This file may be distributed and/or modified under the terms of the |
7 | ** GNU General Public License version 2 as published by the Free Software | 7 | ** GNU General Public License version 2 as published by the Free Software |
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | 8 | ** Foundation and appearing in the file LICENSE.GPL included in the |
9 | ** packaging of this file. | 9 | ** packaging of this file. |
10 | ** | 10 | ** |
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | 11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | 12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
13 | ** | 13 | ** |
14 | **********************************************************************/ | 14 | **********************************************************************/ |
15 | 15 | ||
16 | #include "configwindow.h" | 16 | #include "configwindow.h" |
17 | #include "gps.h" | 17 | #include "gps.h" |
18 | #include "logwindow.h" | 18 | #include "logwindow.h" |
19 | #include "hexwindow.h" | 19 | #include "hexwindow.h" |
20 | #include "mainwindow.h" | 20 | #include "mainwindow.h" |
21 | #include "wellenreiter.h" | 21 | #include "wellenreiter.h" |
22 | #include "scanlist.h" | 22 | #include "scanlist.h" |
23 | 23 | ||
24 | #include <qcombobox.h> | 24 | #include <qcombobox.h> |
25 | #include <qdatastream.h> | 25 | #include <qdatastream.h> |
26 | #include <qfile.h> | 26 | #include <qfile.h> |
27 | #include <qfileinfo.h> | 27 | #include <qfileinfo.h> |
28 | #include <qiconset.h> | 28 | #include <qiconset.h> |
29 | #include <qmenubar.h> | 29 | #include <qmenubar.h> |
30 | #include <qmessagebox.h> | 30 | #include <qmessagebox.h> |
31 | #include <qpopupmenu.h> | 31 | #include <qpopupmenu.h> |
32 | #include <qstatusbar.h> | 32 | #include <qstatusbar.h> |
33 | #include <qtextstream.h> | 33 | #include <qtextstream.h> |
34 | #include <qtoolbutton.h> | 34 | #include <qtoolbutton.h> |
35 | 35 | ||
36 | #ifdef QWS | 36 | #ifdef QWS |
37 | #include <qpe/resource.h> | 37 | #include <qpe/resource.h> |
38 | #include <opie/ofiledialog.h> | 38 | #include <opie/ofiledialog.h> |
39 | #else | 39 | #else |
40 | #include "resource.h" | 40 | #include "resource.h" |
41 | #include <qapplication.h> | 41 | #include <qapplication.h> |
42 | #include <qfiledialog.h> | 42 | #include <qfiledialog.h> |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) | 45 | WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) |
46 | :QMainWindow( parent, name, f ) | 46 | :QMainWindow( parent, name, f ) |
47 | { | 47 | { |
48 | cw = new WellenreiterConfigWindow( this ); | 48 | cw = new WellenreiterConfigWindow( this ); |
49 | mw = new Wellenreiter( this ); | 49 | mw = new Wellenreiter( this ); |
50 | mw->setConfigWindow( cw ); | 50 | mw->setConfigWindow( cw ); |
51 | setCentralWidget( mw ); | 51 | setCentralWidget( mw ); |
52 | 52 | ||
53 | // setup application icon | 53 | // setup application icon |
54 | 54 | ||
55 | #ifndef QWS | 55 | #ifndef QWS |
56 | setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); | 56 | setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); |
57 | setIconText( "Wellenreiter/X11" ); | 57 | setIconText( "Wellenreiter/X11" ); |
58 | #endif | 58 | #endif |
59 | 59 | ||
60 | // setup tool buttons | 60 | // setup tool buttons |
61 | 61 | ||
62 | startButton = new QToolButton( 0 ); | 62 | startButton = new QToolButton( 0 ); |
63 | #ifdef QWS | 63 | #ifdef QWS |
64 | startButton->setAutoRaise( true ); | 64 | startButton->setAutoRaise( true ); |
65 | #endif | 65 | #endif |
66 | startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); | 66 | startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); |
67 | startButton->setEnabled( false ); | 67 | startButton->setEnabled( false ); |
68 | connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); | 68 | connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); |
69 | 69 | ||
70 | stopButton = new QToolButton( 0 ); | 70 | stopButton = new QToolButton( 0 ); |
71 | #ifdef QWS | 71 | #ifdef QWS |
72 | stopButton->setAutoRaise( true ); | 72 | stopButton->setAutoRaise( true ); |
73 | #endif | 73 | #endif |
74 | stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); | 74 | stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); |
75 | stopButton->setEnabled( false ); | 75 | stopButton->setEnabled( false ); |
76 | connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); | 76 | connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); |
77 | 77 | ||
78 | QToolButton* d = new QToolButton( 0 ); | 78 | QToolButton* d = new QToolButton( 0 ); |
79 | #ifdef QWS | 79 | #ifdef QWS |
80 | d->setAutoRaise( true ); | 80 | d->setAutoRaise( true ); |
81 | #endif | 81 | #endif |
82 | d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); | 82 | d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); |
83 | connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); | 83 | connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); |
84 | 84 | ||
85 | uploadButton = new QToolButton( 0 ); | 85 | uploadButton = new QToolButton( 0 ); |
86 | #ifdef QWS | 86 | #ifdef QWS |
87 | uploadButton->setAutoRaise( true ); | 87 | uploadButton->setAutoRaise( true ); |
88 | #endif | 88 | #endif |
89 | uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); | 89 | uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); |
90 | uploadButton->setEnabled( false ); | 90 | //uploadButton->setEnabled( false ); |
91 | uploadButton->setEnabled( true ); | ||
91 | connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); | 92 | connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); |
92 | 93 | ||
93 | // setup menu bar | 94 | // setup menu bar |
94 | 95 | ||
95 | int id; | 96 | int id; |
96 | 97 | ||
97 | QMenuBar* mb = menuBar(); | 98 | QMenuBar* mb = menuBar(); |
98 | 99 | ||
99 | QPopupMenu* fileSave = new QPopupMenu( mb ); | 100 | QPopupMenu* fileSave = new QPopupMenu( mb ); |
100 | fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); | 101 | fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); |
101 | fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); | 102 | fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); |
102 | fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); | 103 | fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); |
103 | 104 | ||
104 | QPopupMenu* fileLoad = new QPopupMenu( mb ); | 105 | QPopupMenu* fileLoad = new QPopupMenu( mb ); |
105 | fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); | 106 | fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); |
106 | //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); | 107 | //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); |
107 | 108 | ||
108 | QPopupMenu* file = new QPopupMenu( mb ); | 109 | QPopupMenu* file = new QPopupMenu( mb ); |
109 | file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); | 110 | file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); |
110 | id = file->insertItem( tr( "&Load" ), fileLoad ); | 111 | id = file->insertItem( tr( "&Load" ), fileLoad ); |
111 | file->insertItem( tr( "&Save" ), fileSave ); | 112 | file->insertItem( tr( "&Save" ), fileSave ); |
112 | file->insertSeparator(); | 113 | file->insertSeparator(); |
113 | uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); | 114 | uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); |
114 | file->insertSeparator(); | 115 | file->insertSeparator(); |
115 | file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); | 116 | file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); |
116 | 117 | ||
117 | QPopupMenu* view = new QPopupMenu( mb ); | 118 | QPopupMenu* view = new QPopupMenu( mb ); |
118 | view->insertItem( tr( "&Configure..." ) ); | 119 | view->insertItem( tr( "&Configure..." ) ); |
119 | 120 | ||
120 | QPopupMenu* sniffer = new QPopupMenu( mb ); | 121 | QPopupMenu* sniffer = new QPopupMenu( mb ); |
121 | sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); | 122 | sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); |
122 | sniffer->insertSeparator(); | 123 | sniffer->insertSeparator(); |
123 | startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); | 124 | startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); |
124 | sniffer->setItemEnabled( startID, false ); | 125 | sniffer->setItemEnabled( startID, false ); |
125 | stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); | 126 | stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); |
126 | sniffer->setItemEnabled( stopID, false ); | 127 | sniffer->setItemEnabled( stopID, false ); |
127 | 128 | ||
128 | QPopupMenu* demo = new QPopupMenu( mb ); | 129 | QPopupMenu* demo = new QPopupMenu( mb ); |
129 | demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); | 130 | demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); |
130 | 131 | ||
131 | id = mb->insertItem( tr( "&File" ), file ); | 132 | id = mb->insertItem( tr( "&File" ), file ); |
132 | //id = mb->insertItem( tr( "&View" ), view ); | 133 | //id = mb->insertItem( tr( "&View" ), view ); |
133 | //mb->setItemEnabled( id, false ); | 134 | //mb->setItemEnabled( id, false ); |
134 | id = mb->insertItem( tr( "&Sniffer" ), sniffer ); | 135 | id = mb->insertItem( tr( "&Sniffer" ), sniffer ); |
135 | 136 | ||
136 | id = mb->insertItem( tr( "&Demo" ), demo ); | 137 | id = mb->insertItem( tr( "&Demo" ), demo ); |
137 | mb->setItemEnabled( id, true ); | 138 | mb->setItemEnabled( id, true ); |
138 | mb->setItemEnabled( uploadID, false ); | 139 | mb->setItemEnabled( uploadID, false ); |
139 | 140 | ||
140 | #ifdef QWS | 141 | #ifdef QWS |
141 | mb->insertItem( startButton ); | 142 | mb->insertItem( startButton ); |
142 | mb->insertItem( stopButton ); | 143 | mb->insertItem( stopButton ); |
143 | mb->insertItem( uploadButton ); | 144 | mb->insertItem( uploadButton ); |
144 | mb->insertItem( d ); | 145 | mb->insertItem( d ); |
145 | #else // Qt3 changed the insertion order. It's now totally random :( | 146 | #else // Qt3 changed the insertion order. It's now totally random :( |
146 | mb->insertItem( d ); | 147 | mb->insertItem( d ); |
147 | mb->insertItem( uploadButton ); | 148 | mb->insertItem( uploadButton ); |
148 | mb->insertItem( stopButton ); | 149 | mb->insertItem( stopButton ); |
149 | mb->insertItem( startButton ); | 150 | mb->insertItem( startButton ); |
150 | #endif | 151 | #endif |
151 | 152 | ||
152 | updateToolButtonState(); | 153 | updateToolButtonState(); |
153 | 154 | ||
154 | // setup status bar (for now only on X11) | 155 | // setup status bar (for now only on X11) |
155 | 156 | ||
156 | #ifndef QWS | 157 | #ifndef QWS |
157 | statusBar()->message( tr( "Ready." ) ); | 158 | statusBar()->message( tr( "Ready." ) ); |
158 | #endif | 159 | #endif |
159 | 160 | ||
160 | connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) ); | 161 | connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) ); |
161 | connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) ); | 162 | connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) ); |
162 | }; | 163 | }; |
163 | 164 | ||
164 | 165 | ||
165 | 166 | ||
166 | void WellenreiterMainWindow::showConfigure() | 167 | void WellenreiterMainWindow::showConfigure() |
167 | { | 168 | { |
168 | qDebug( "show configure..." ); | 169 | qDebug( "show configure..." ); |
169 | cw->setCaption( tr( "Configure" ) ); | 170 | cw->setCaption( tr( "Configure" ) ); |
170 | #ifdef QWS | 171 | #ifdef QWS |
171 | cw->showMaximized(); | 172 | cw->showMaximized(); |
172 | #endif | 173 | #endif |
173 | int result = cw->exec(); | 174 | int result = cw->exec(); |
174 | 175 | ||
175 | if ( result ) updateToolButtonState(); | 176 | if ( result ) updateToolButtonState(); |
176 | } | 177 | } |
177 | 178 | ||
178 | 179 | ||
179 | void WellenreiterMainWindow::updateToolButtonState() | 180 | void WellenreiterMainWindow::updateToolButtonState() |
180 | { | 181 | { |
181 | const QString& interface = cw->interfaceName->currentText(); | 182 | const QString& interface = cw->interfaceName->currentText(); |
182 | const int cardtype = cw->driverType(); | 183 | const int cardtype = cw->driverType(); |
183 | 184 | ||
184 | if ( ( interface != "<select>" ) && ( cardtype != 0 ) ) | 185 | if ( ( interface != "<select>" ) && ( cardtype != 0 ) ) |
185 | { | 186 | { |
186 | startButton->setEnabled( true ); | 187 | startButton->setEnabled( true ); |
187 | menuBar()->setItemEnabled( startID, true ); | 188 | menuBar()->setItemEnabled( startID, true ); |
188 | } | 189 | } |
189 | else | 190 | else |
190 | { | 191 | { |
191 | startButton->setEnabled( false ); | 192 | startButton->setEnabled( false ); |
192 | menuBar()->setItemEnabled( startID, false ); | 193 | menuBar()->setItemEnabled( startID, false ); |
193 | } | 194 | } |
194 | } | 195 | } |
195 | 196 | ||
196 | 197 | ||
197 | void WellenreiterMainWindow::changedSniffingState() | 198 | void WellenreiterMainWindow::changedSniffingState() |
198 | { | 199 | { |
199 | startButton->setEnabled( !mw->sniffing ); | 200 | startButton->setEnabled( !mw->sniffing ); |
200 | menuBar()->setItemEnabled( startID, !mw->sniffing ); | 201 | menuBar()->setItemEnabled( startID, !mw->sniffing ); |
201 | stopButton->setEnabled( mw->sniffing ); | 202 | stopButton->setEnabled( mw->sniffing ); |
202 | menuBar()->setItemEnabled( stopID, mw->sniffing ); | 203 | menuBar()->setItemEnabled( stopID, mw->sniffing ); |
203 | 204 | ||
204 | if ( !mw->sniffing ) | 205 | if ( !mw->sniffing ) |
205 | { | 206 | { |
206 | menuBar()->setItemEnabled( uploadID, true ); | 207 | menuBar()->setItemEnabled( uploadID, true ); |
207 | uploadButton->setEnabled( true ); | 208 | uploadButton->setEnabled( true ); |
208 | } | 209 | } |
209 | } | 210 | } |
210 | 211 | ||
211 | 212 | ||
212 | WellenreiterMainWindow::~WellenreiterMainWindow() | 213 | WellenreiterMainWindow::~WellenreiterMainWindow() |
213 | { | 214 | { |
214 | qDebug( "Wellenreiter:: bye." ); | 215 | qDebug( "Wellenreiter:: bye." ); |
215 | }; | 216 | }; |
216 | 217 | ||
217 | 218 | ||
218 | void WellenreiterMainWindow::demoAddStations() | 219 | void WellenreiterMainWindow::demoAddStations() |
219 | { | 220 | { |
220 | //mw = 0; // test SIGSGV handling | 221 | //mw = 0; // test SIGSGV handling |
221 | 222 | ||
222 | mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 10.10, 20.20 ) ); | 223 | mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 10.10, 20.20 ) ); |
223 | mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) ); | 224 | mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) ); |
224 | mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:A0:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); | 225 | mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:A0:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) ); |
225 | mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:AA:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); | 226 | mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:AA:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) ); |
226 | mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:B0:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); | 227 | mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:B0:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) ); |
227 | } | 228 | } |
228 | 229 | ||
229 | 230 | ||
230 | QString WellenreiterMainWindow::getFileName( bool save ) | 231 | QString WellenreiterMainWindow::getFileName( bool save ) |
231 | { | 232 | { |
232 | QMap<QString, QStringList> map; | 233 | QMap<QString, QStringList> map; |
233 | map.insert( tr("All"), QStringList() ); | 234 | map.insert( tr("All"), QStringList() ); |
234 | QStringList text; | 235 | QStringList text; |
235 | text << "text/*"; | 236 | text << "text/*"; |
236 | map.insert( tr("Text"), text ); | 237 | map.insert( tr("Text"), text ); |
237 | text << "*"; | 238 | text << "*"; |
238 | map.insert( tr("All"), text ); | 239 | map.insert( tr("All"), text ); |
239 | 240 | ||
240 | QString str; | 241 | QString str; |
241 | if ( save ) | 242 | if ( save ) |
242 | { | 243 | { |
243 | #ifdef QWS | 244 | #ifdef QWS |
244 | str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); | 245 | str = OFileDialog::getSaveFileName( 2, "/", QString::null, map ); |
245 | #else | 246 | #else |
246 | str = QFileDialog::getSaveFileName(); | 247 | str = QFileDialog::getSaveFileName(); |
247 | #endif | 248 | #endif |
248 | if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ ) | 249 | if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ ) |
249 | return ""; | 250 | return ""; |
250 | } | 251 | } |
251 | else | 252 | else |
252 | { | 253 | { |
253 | #ifdef QWS | 254 | #ifdef QWS |
254 | str = OFileDialog::getOpenFileName( 2, "/", QString::null, map ); | 255 | str = OFileDialog::getOpenFileName( 2, "/", QString::null, map ); |
255 | #else | 256 | #else |
256 | str = QFileDialog::getOpenFileName(); | 257 | str = QFileDialog::getOpenFileName(); |
257 | #endif | 258 | #endif |
258 | if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() ) | 259 | if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() ) |
259 | return ""; | 260 | return ""; |
260 | } | 261 | } |
261 | return str; | 262 | return str; |
262 | } | 263 | } |
263 | 264 | ||
264 | 265 | ||
265 | void WellenreiterMainWindow::fileSaveLog() | 266 | void WellenreiterMainWindow::fileSaveLog() |
266 | { | 267 | { |
267 | QString fname = getFileName( true ); | 268 | QString fname = getFileName( true ); |
268 | if ( !fname.isEmpty() ) | 269 | if ( !fname.isEmpty() ) |
269 | { | 270 | { |
270 | QFile f( fname ); | 271 | QFile f( fname ); |
271 | if ( f.open(IO_WriteOnly) ) | 272 | if ( f.open(IO_WriteOnly) ) |
272 | { | 273 | { |
273 | QTextStream t( &f ); | 274 | QTextStream t( &f ); |
274 | t << mw->logWindow()->getLog(); | 275 | t << mw->logWindow()->getLog(); |
275 | f.close(); | 276 | f.close(); |
276 | qDebug( "Saved log to file '%s'", (const char*) fname ); | 277 | qDebug( "Saved log to file '%s'", (const char*) fname ); |
277 | } | 278 | } |
278 | else | 279 | else |
279 | { | 280 | { |
280 | qDebug( "Problem saving log to file '%s'", (const char*) fname ); | 281 | qDebug( "Problem saving log to file '%s'", (const char*) fname ); |
281 | } | 282 | } |
282 | } | 283 | } |
283 | } | 284 | } |
284 | 285 | ||
285 | void WellenreiterMainWindow::fileSaveSession() | 286 | void WellenreiterMainWindow::fileSaveSession() |
286 | { | 287 | { |
287 | QString fname = getFileName( true ); | 288 | QString fname = getFileName( true ); |
288 | if ( !fname.isEmpty() ) | 289 | if ( !fname.isEmpty() ) |
289 | { | 290 | { |
290 | 291 | ||
291 | QFile f( fname ); | 292 | QFile f( fname ); |
292 | if ( f.open(IO_WriteOnly) ) | 293 | if ( f.open(IO_WriteOnly) ) |
293 | { | 294 | { |
294 | QDataStream t( &f ); | 295 | QDataStream t( &f ); |
295 | t << *mw->netView(); | 296 | t << *mw->netView(); |
296 | f.close(); | 297 | f.close(); |
297 | qDebug( "Saved session to file '%s'", (const char*) fname ); | 298 | qDebug( "Saved session to file '%s'", (const char*) fname ); |
298 | } | 299 | } |
299 | else | 300 | else |
300 | { | 301 | { |
301 | qDebug( "Problem saving session to file '%s'", (const char*) fname ); | 302 | qDebug( "Problem saving session to file '%s'", (const char*) fname ); |
302 | } | 303 | } |
303 | } | 304 | } |
304 | } | 305 | } |
305 | 306 | ||
306 | void WellenreiterMainWindow::fileSaveHex() | 307 | void WellenreiterMainWindow::fileSaveHex() |
307 | { | 308 | { |
308 | QString fname = getFileName( true ); | 309 | QString fname = getFileName( true ); |
309 | if ( !fname.isEmpty() ) | 310 | if ( !fname.isEmpty() ) |
310 | { | 311 | { |
311 | QFile f( fname ); | 312 | QFile f( fname ); |
312 | if ( f.open(IO_WriteOnly) ) | 313 | if ( f.open(IO_WriteOnly) ) |
313 | { | 314 | { |
314 | QTextStream t( &f ); | 315 | QTextStream t( &f ); |
315 | t << mw->hexWindow()->getLog(); | 316 | t << mw->hexWindow()->getLog(); |
316 | f.close(); | 317 | f.close(); |
317 | qDebug( "Saved hex log to file '%s'", (const char*) fname ); | 318 | qDebug( "Saved hex log to file '%s'", (const char*) fname ); |
318 | } | 319 | } |
319 | else | 320 | else |
320 | { | 321 | { |
321 | qDebug( "Problem saving hex log to file '%s'", (const char*) fname ); | 322 | qDebug( "Problem saving hex log to file '%s'", (const char*) fname ); |
322 | } | 323 | } |
323 | } | 324 | } |
324 | } | 325 | } |
325 | 326 | ||
326 | void WellenreiterMainWindow::fileLoadSession() | 327 | void WellenreiterMainWindow::fileLoadSession() |
327 | { | 328 | { |
328 | QString fname = getFileName( false ); | 329 | QString fname = getFileName( false ); |
329 | if ( !fname.isEmpty() ) | 330 | if ( !fname.isEmpty() ) |
330 | { | 331 | { |
331 | QFile f( fname ); | 332 | QFile f( fname ); |
332 | if ( f.open(IO_ReadOnly) ) | 333 | if ( f.open(IO_ReadOnly) ) |
333 | { | 334 | { |
334 | QDataStream t( &f ); | 335 | QDataStream t( &f ); |
335 | t >> *mw->netView(); | 336 | t >> *mw->netView(); |
336 | f.close(); | 337 | f.close(); |
337 | qDebug( "Loaded session from file '%s'", (const char*) fname ); | 338 | qDebug( "Loaded session from file '%s'", (const char*) fname ); |
338 | } | 339 | } |
339 | else | 340 | else |
340 | { | 341 | { |
341 | qDebug( "Problem loading session from file '%s'", (const char*) fname ); | 342 | qDebug( "Problem loading session from file '%s'", (const char*) fname ); |
342 | } | 343 | } |
343 | } | 344 | } |
344 | } | 345 | } |
345 | 346 | ||
346 | 347 | ||
347 | void WellenreiterMainWindow::fileNew() | 348 | void WellenreiterMainWindow::fileNew() |
348 | { | 349 | { |
349 | mw->netView()->clear(); | 350 | mw->netView()->clear(); |
350 | mw->logWindow()->clear(); | 351 | mw->logWindow()->clear(); |
351 | mw->hexWindow()->clear(); | 352 | mw->hexWindow()->clear(); |
352 | } | 353 | } |
353 | 354 | ||
354 | 355 | ||
355 | void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) | 356 | void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) |
356 | { | 357 | { |
357 | if ( mw->isDaemonRunning() ) | 358 | if ( mw->isDaemonRunning() ) |
358 | { | 359 | { |
359 | QMessageBox::warning( this, "Wellenreiter/Opie", | 360 | QMessageBox::warning( this, "Wellenreiter/Opie", |
360 | tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) ); | 361 | tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) ); |
361 | e->ignore(); | 362 | e->ignore(); |
362 | } | 363 | } |
363 | else | 364 | else |
364 | { | 365 | { |
365 | QMainWindow::closeEvent( e ); | 366 | QMainWindow::closeEvent( e ); |
366 | } | 367 | } |
367 | } | 368 | } |
368 | 369 | ||
370 | static const char* CAP_hostname = "www.vanille.de"; | ||
371 | |||
372 | #include <netdb.h> | ||
373 | #include <unistd.h> | ||
374 | #include <sys/types.h> | ||
375 | #include <sys/socket.h> | ||
369 | 376 | ||
370 | void WellenreiterMainWindow::uploadSession() | 377 | void WellenreiterMainWindow::uploadSession() |
371 | { | 378 | { |
372 | QMessageBox::warning( this, "Wellenreiter/Opie", | 379 | qDebug( "Starting upload..." ); |
373 | tr( "This feature is\nunder construction... ;-)" ) ); | 380 | |
381 | struct sockaddr_in raddr; | ||
382 | struct hostent *rhost_info; | ||
383 | int sock = -1; | ||
384 | bool ok = false; | ||
385 | |||
386 | rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname ); | ||
387 | if ( rhost_info ) | ||
388 | { | ||
389 | if ( !QFile::exists( "/var/log/dump.wellenreiter" ) ) | ||
390 | { | ||
391 | qDebug( "no file to upload!" ); | ||
392 | return; | ||
393 | } | ||
394 | |||
395 | QFile f( "/var/log/dump.wellenreiter" ); | ||
396 | if ( !f.open( IO_ReadOnly ) ) | ||
397 | { | ||
398 | qDebug( "can't open file!" ); | ||
399 | return; | ||
400 | } | ||
401 | |||
402 | int content_length = f.size(); | ||
403 | |||
404 | ::memset( &raddr, 0, sizeof (struct sockaddr_in) ); | ||
405 | ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); | ||
406 | raddr.sin_family = rhost_info-> h_addrtype; | ||
407 | raddr.sin_port = htons ( 80 ); | ||
408 | |||
409 | sock = ::socket( AF_INET, SOCK_STREAM, 0 ); | ||
410 | |||
411 | if ( sock >= 0 ) | ||
412 | { | ||
413 | if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) | ||
414 | { | ||
415 | QString header; | ||
416 | QString content; | ||
417 | QString preambel; | ||
418 | |||
419 | header = "" | ||
420 | "POST /projects/capturedump.spy HTTP/1.1\r\n" | ||
421 | "Host: www.vanille.de\r\n" | ||
422 | "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n" | ||
423 | "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n" | ||
424 | "Accept-Language: en\r\n" | ||
425 | "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n" | ||
426 | "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n" | ||
427 | "Keep-Alive: 300\r\n" | ||
428 | "Connection: keep-alive\r\n" | ||
429 | "Referer: http://www.vanille.de/projects/capturedump.spy\r\n" | ||
430 | "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n" | ||
431 | "Content-Length: %1\r\n" | ||
432 | "\r\n"; | ||
433 | |||
434 | content = "" | ||
435 | "-----------------------------97267758015830030481215568065\r\n" | ||
436 | "Content-Disposition: form-data; name=\"Name\"\r\n" | ||
437 | "\r\n" | ||
438 | "Anonymous Wellenreiter II User\r\n" | ||
439 | "-----------------------------97267758015830030481215568065\r\n" | ||
440 | "Content-Disposition: form-data; name=\"Location\"\r\n" | ||
441 | "\r\n" | ||
442 | "Anonymous Wellenreiter II Location\r\n" | ||
443 | "-----------------------------97267758015830030481215568065\r\n" | ||
444 | "Content-Disposition: form-data; name=\"Comments\"\r\n" | ||
445 | "\r\n" | ||
446 | "Anonymous Wellenreiter II Comments\r\n" | ||
447 | "-----------------------------97267758015830030481215568065\r\n" | ||
448 | "Content-Disposition: form-data; name=\"upfile\"; filename=\"/var/log/dump.wellenreiter\"\r\n" | ||
449 | "Content-Type: application/octet-stream\r\n" | ||
450 | "\r\n"; | ||
451 | |||
452 | preambel = "" | ||
453 | "\r\n-----------------------------97267758015830030481215568065--\r\n"; | ||
454 | |||
455 | header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) ); | ||
456 | |||
457 | // write header | ||
458 | |||
459 | const char* ascii = header.latin1(); | ||
460 | uint ascii_len = ::strlen( ascii ); | ||
461 | ::write ( sock, ascii, ascii_len ); | ||
462 | |||
463 | // write fixed content | ||
464 | |||
465 | ascii = content.latin1(); | ||
466 | ascii_len = ::strlen( ascii ); | ||
467 | ::write ( sock, ascii, ascii_len ); | ||
468 | |||
469 | // write variable content | ||
470 | |||
471 | char ch; | ||
472 | while ( !f.atEnd() ) | ||
473 | { | ||
474 | f.readBlock( &ch, 1 ); | ||
475 | ::write ( sock, &ch, 1 ); | ||
476 | } | ||
477 | |||
478 | // write preambel | ||
479 | |||
480 | ascii = preambel.latin1(); | ||
481 | ascii_len = ::strlen( ascii ); | ||
482 | ::write ( sock, ascii, ascii_len ); | ||
483 | |||
484 | // done! | ||
485 | |||
486 | ok = true; | ||
487 | } | ||
488 | } | ||
489 | ::close ( sock ); | ||
490 | } | ||
491 | if ( ok ) | ||
492 | QMessageBox::information ( 0, tr( "Success" ), QString ( "<p>%1</p>" ). arg( tr( "Capture Dump was uploaded to %1" )).arg ( CAP_hostname )); | ||
493 | else | ||
494 | QMessageBox::warning ( 0, tr( "Error" ), QString ( "<p>%1</p>" ). arg ( tr( "Connection to %1 failed." )). arg ( CAP_hostname )); | ||
374 | } | 495 | } |
375 | 496 | ||