-rw-r--r-- | noncore/net/wellenreiter/gui/mainwindow.cpp | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp index 88a474d..bb46dd7 100644 --- a/noncore/net/wellenreiter/gui/mainwindow.cpp +++ b/noncore/net/wellenreiter/gui/mainwindow.cpp | |||
@@ -1,155 +1,159 @@ | |||
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 <qlabel.h> | ||
29 | #include <qlayout.h> | ||
30 | #include <qlineedit.h> | ||
28 | #include <qiconset.h> | 31 | #include <qiconset.h> |
29 | #include <qmenubar.h> | 32 | #include <qmenubar.h> |
30 | #include <qmessagebox.h> | 33 | #include <qmessagebox.h> |
31 | #include <qpopupmenu.h> | 34 | #include <qpopupmenu.h> |
35 | #include <qpushbutton.h> | ||
32 | #include <qstatusbar.h> | 36 | #include <qstatusbar.h> |
33 | #include <qtextstream.h> | 37 | #include <qtextstream.h> |
34 | #include <qtoolbutton.h> | 38 | #include <qtoolbutton.h> |
35 | 39 | ||
36 | #ifdef QWS | 40 | #ifdef QWS |
37 | #include <qpe/resource.h> | 41 | #include <qpe/resource.h> |
38 | #include <opie/ofiledialog.h> | 42 | #include <opie/ofiledialog.h> |
39 | #else | 43 | #else |
40 | #include "resource.h" | 44 | #include "resource.h" |
41 | #include <qapplication.h> | 45 | #include <qapplication.h> |
42 | #include <qfiledialog.h> | 46 | #include <qfiledialog.h> |
43 | #endif | 47 | #endif |
44 | 48 | ||
45 | WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) | 49 | WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) |
46 | :QMainWindow( parent, name, f ) | 50 | :QMainWindow( parent, name, f ) |
47 | { | 51 | { |
48 | cw = new WellenreiterConfigWindow( this ); | 52 | cw = new WellenreiterConfigWindow( this ); |
49 | mw = new Wellenreiter( this ); | 53 | mw = new Wellenreiter( this ); |
50 | mw->setConfigWindow( cw ); | 54 | mw->setConfigWindow( cw ); |
51 | setCentralWidget( mw ); | 55 | setCentralWidget( mw ); |
52 | 56 | ||
53 | // setup application icon | 57 | // setup application icon |
54 | 58 | ||
55 | #ifndef QWS | 59 | #ifndef QWS |
56 | setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); | 60 | setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) ); |
57 | setIconText( "Wellenreiter/X11" ); | 61 | setIconText( "Wellenreiter/X11" ); |
58 | #endif | 62 | #endif |
59 | 63 | ||
60 | // setup tool buttons | 64 | // setup tool buttons |
61 | 65 | ||
62 | startButton = new QToolButton( 0 ); | 66 | startButton = new QToolButton( 0 ); |
63 | #ifdef QWS | 67 | #ifdef QWS |
64 | startButton->setAutoRaise( true ); | 68 | startButton->setAutoRaise( true ); |
65 | #endif | 69 | #endif |
66 | startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); | 70 | startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) ); |
67 | startButton->setEnabled( false ); | 71 | startButton->setEnabled( false ); |
68 | connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); | 72 | connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) ); |
69 | 73 | ||
70 | stopButton = new QToolButton( 0 ); | 74 | stopButton = new QToolButton( 0 ); |
71 | #ifdef QWS | 75 | #ifdef QWS |
72 | stopButton->setAutoRaise( true ); | 76 | stopButton->setAutoRaise( true ); |
73 | #endif | 77 | #endif |
74 | stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); | 78 | stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) ); |
75 | stopButton->setEnabled( false ); | 79 | stopButton->setEnabled( false ); |
76 | connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); | 80 | connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) ); |
77 | 81 | ||
78 | QToolButton* d = new QToolButton( 0 ); | 82 | QToolButton* d = new QToolButton( 0 ); |
79 | #ifdef QWS | 83 | #ifdef QWS |
80 | d->setAutoRaise( true ); | 84 | d->setAutoRaise( true ); |
81 | #endif | 85 | #endif |
82 | d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); | 86 | d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) ); |
83 | connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); | 87 | connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) ); |
84 | 88 | ||
85 | uploadButton = new QToolButton( 0 ); | 89 | uploadButton = new QToolButton( 0 ); |
86 | #ifdef QWS | 90 | #ifdef QWS |
87 | uploadButton->setAutoRaise( true ); | 91 | uploadButton->setAutoRaise( true ); |
88 | #endif | 92 | #endif |
89 | uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); | 93 | uploadButton->setIconSet( Resource::loadIconSet( "up" ) ); |
90 | //uploadButton->setEnabled( false ); | 94 | uploadButton->setEnabled( false ); |
91 | uploadButton->setEnabled( true ); | 95 | //uploadButton->setEnabled( true ); // DEBUGGING |
92 | connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); | 96 | connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) ); |
93 | 97 | ||
94 | // setup menu bar | 98 | // setup menu bar |
95 | 99 | ||
96 | int id; | 100 | int id; |
97 | 101 | ||
98 | QMenuBar* mb = menuBar(); | 102 | QMenuBar* mb = menuBar(); |
99 | 103 | ||
100 | QPopupMenu* fileSave = new QPopupMenu( mb ); | 104 | QPopupMenu* fileSave = new QPopupMenu( mb ); |
101 | fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); | 105 | fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) ); |
102 | fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); | 106 | fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) ); |
103 | fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); | 107 | fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) ); |
104 | 108 | ||
105 | QPopupMenu* fileLoad = new QPopupMenu( mb ); | 109 | QPopupMenu* fileLoad = new QPopupMenu( mb ); |
106 | fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); | 110 | fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) ); |
107 | //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); | 111 | //fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) ); |
108 | 112 | ||
109 | QPopupMenu* file = new QPopupMenu( mb ); | 113 | QPopupMenu* file = new QPopupMenu( mb ); |
110 | file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); | 114 | file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) ); |
111 | id = file->insertItem( tr( "&Load" ), fileLoad ); | 115 | id = file->insertItem( tr( "&Load" ), fileLoad ); |
112 | file->insertItem( tr( "&Save" ), fileSave ); | 116 | file->insertItem( tr( "&Save" ), fileSave ); |
113 | file->insertSeparator(); | 117 | file->insertSeparator(); |
114 | uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); | 118 | uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) ); |
115 | file->insertSeparator(); | 119 | file->insertSeparator(); |
116 | file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); | 120 | file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) ); |
117 | 121 | ||
118 | QPopupMenu* view = new QPopupMenu( mb ); | 122 | QPopupMenu* view = new QPopupMenu( mb ); |
119 | view->insertItem( tr( "&Configure..." ) ); | 123 | view->insertItem( tr( "&Configure..." ) ); |
120 | 124 | ||
121 | QPopupMenu* sniffer = new QPopupMenu( mb ); | 125 | QPopupMenu* sniffer = new QPopupMenu( mb ); |
122 | sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); | 126 | sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) ); |
123 | sniffer->insertSeparator(); | 127 | sniffer->insertSeparator(); |
124 | startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); | 128 | startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) ); |
125 | sniffer->setItemEnabled( startID, false ); | 129 | sniffer->setItemEnabled( startID, false ); |
126 | stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); | 130 | stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) ); |
127 | sniffer->setItemEnabled( stopID, false ); | 131 | sniffer->setItemEnabled( stopID, false ); |
128 | 132 | ||
129 | QPopupMenu* demo = new QPopupMenu( mb ); | 133 | QPopupMenu* demo = new QPopupMenu( mb ); |
130 | demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); | 134 | demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) ); |
131 | 135 | ||
132 | id = mb->insertItem( tr( "&File" ), file ); | 136 | id = mb->insertItem( tr( "&File" ), file ); |
133 | //id = mb->insertItem( tr( "&View" ), view ); | 137 | //id = mb->insertItem( tr( "&View" ), view ); |
134 | //mb->setItemEnabled( id, false ); | 138 | //mb->setItemEnabled( id, false ); |
135 | id = mb->insertItem( tr( "&Sniffer" ), sniffer ); | 139 | id = mb->insertItem( tr( "&Sniffer" ), sniffer ); |
136 | 140 | ||
137 | id = mb->insertItem( tr( "&Demo" ), demo ); | 141 | id = mb->insertItem( tr( "&Demo" ), demo ); |
138 | mb->setItemEnabled( id, true ); | 142 | mb->setItemEnabled( id, true ); |
139 | mb->setItemEnabled( uploadID, false ); | 143 | mb->setItemEnabled( uploadID, false ); |
140 | 144 | ||
141 | #ifdef QWS | 145 | #ifdef QWS |
142 | mb->insertItem( startButton ); | 146 | mb->insertItem( startButton ); |
143 | mb->insertItem( stopButton ); | 147 | mb->insertItem( stopButton ); |
144 | mb->insertItem( uploadButton ); | 148 | mb->insertItem( uploadButton ); |
145 | mb->insertItem( d ); | 149 | mb->insertItem( d ); |
146 | #else // Qt3 changed the insertion order. It's now totally random :( | 150 | #else // Qt3 changed the insertion order. It's now totally random :( |
147 | mb->insertItem( d ); | 151 | mb->insertItem( d ); |
148 | mb->insertItem( uploadButton ); | 152 | mb->insertItem( uploadButton ); |
149 | mb->insertItem( stopButton ); | 153 | mb->insertItem( stopButton ); |
150 | mb->insertItem( startButton ); | 154 | mb->insertItem( startButton ); |
151 | #endif | 155 | #endif |
152 | 156 | ||
153 | updateToolButtonState(); | 157 | updateToolButtonState(); |
154 | 158 | ||
155 | // setup status bar (for now only on X11) | 159 | // setup status bar (for now only on X11) |
@@ -315,182 +319,220 @@ void WellenreiterMainWindow::fileSaveHex() | |||
315 | QTextStream t( &f ); | 319 | QTextStream t( &f ); |
316 | t << mw->hexWindow()->getLog(); | 320 | t << mw->hexWindow()->getLog(); |
317 | f.close(); | 321 | f.close(); |
318 | qDebug( "Saved hex log to file '%s'", (const char*) fname ); | 322 | qDebug( "Saved hex log to file '%s'", (const char*) fname ); |
319 | } | 323 | } |
320 | else | 324 | else |
321 | { | 325 | { |
322 | qDebug( "Problem saving hex log to file '%s'", (const char*) fname ); | 326 | qDebug( "Problem saving hex log to file '%s'", (const char*) fname ); |
323 | } | 327 | } |
324 | } | 328 | } |
325 | } | 329 | } |
326 | 330 | ||
327 | void WellenreiterMainWindow::fileLoadSession() | 331 | void WellenreiterMainWindow::fileLoadSession() |
328 | { | 332 | { |
329 | QString fname = getFileName( false ); | 333 | QString fname = getFileName( false ); |
330 | if ( !fname.isEmpty() ) | 334 | if ( !fname.isEmpty() ) |
331 | { | 335 | { |
332 | QFile f( fname ); | 336 | QFile f( fname ); |
333 | if ( f.open(IO_ReadOnly) ) | 337 | if ( f.open(IO_ReadOnly) ) |
334 | { | 338 | { |
335 | QDataStream t( &f ); | 339 | QDataStream t( &f ); |
336 | t >> *mw->netView(); | 340 | t >> *mw->netView(); |
337 | f.close(); | 341 | f.close(); |
338 | qDebug( "Loaded session from file '%s'", (const char*) fname ); | 342 | qDebug( "Loaded session from file '%s'", (const char*) fname ); |
339 | } | 343 | } |
340 | else | 344 | else |
341 | { | 345 | { |
342 | qDebug( "Problem loading session from file '%s'", (const char*) fname ); | 346 | qDebug( "Problem loading session from file '%s'", (const char*) fname ); |
343 | } | 347 | } |
344 | } | 348 | } |
345 | } | 349 | } |
346 | 350 | ||
347 | 351 | ||
348 | void WellenreiterMainWindow::fileNew() | 352 | void WellenreiterMainWindow::fileNew() |
349 | { | 353 | { |
350 | mw->netView()->clear(); | 354 | mw->netView()->clear(); |
351 | mw->logWindow()->clear(); | 355 | mw->logWindow()->clear(); |
352 | mw->hexWindow()->clear(); | 356 | mw->hexWindow()->clear(); |
353 | } | 357 | } |
354 | 358 | ||
355 | 359 | ||
356 | void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) | 360 | void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) |
357 | { | 361 | { |
358 | if ( mw->isDaemonRunning() ) | 362 | if ( mw->isDaemonRunning() ) |
359 | { | 363 | { |
360 | QMessageBox::warning( this, "Wellenreiter/Opie", | 364 | QMessageBox::warning( this, "Wellenreiter/Opie", |
361 | tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) ); | 365 | tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) ); |
362 | e->ignore(); | 366 | e->ignore(); |
363 | } | 367 | } |
364 | else | 368 | else |
365 | { | 369 | { |
366 | QMainWindow::closeEvent( e ); | 370 | QMainWindow::closeEvent( e ); |
367 | } | 371 | } |
368 | } | 372 | } |
369 | 373 | ||
370 | static const char* CAP_hostname = "www.vanille.de"; | 374 | static const char* CAP_hostname = "www.vanille.de"; |
371 | 375 | ||
372 | #include <netdb.h> | 376 | #include <netdb.h> |
373 | #include <unistd.h> | 377 | #include <unistd.h> |
374 | #include <sys/types.h> | 378 | #include <sys/types.h> |
375 | #include <sys/socket.h> | 379 | #include <sys/socket.h> |
376 | 380 | ||
377 | void WellenreiterMainWindow::uploadSession() | 381 | void WellenreiterMainWindow::uploadSession() |
378 | { | 382 | { |
383 | QLineEdit* from; | ||
384 | QLineEdit* location; | ||
385 | QLineEdit* comments; | ||
386 | QPushButton* accept; | ||
387 | QPushButton* reject; | ||
388 | |||
389 | QDialog* d = new QDialog( 0, "session upload", true ); | ||
390 | d->setCaption( tr( "Upload Session" ) ); | ||
391 | QGridLayout* g = new QGridLayout( d, 4, 2, 3 ); | ||
392 | g->addWidget( new QLabel( tr( "From: " ), d ), 0, 0 ); | ||
393 | g->addWidget( from = new QLineEdit( d ), 0, 1 ); | ||
394 | g->addWidget( new QLabel( tr( "Location: " ), d ), 1, 0 ); | ||
395 | g->addWidget( location = new QLineEdit( d ), 1, 1 ); | ||
396 | g->addWidget( new QLabel( tr( "Comments: " ), d ), 2, 0 ); | ||
397 | g->addWidget( comments = new QLineEdit( d ), 2, 1 ); | ||
398 | g->addWidget( accept = new QPushButton( tr( "&Ok" ), d ), 3, 0 ); | ||
399 | g->addWidget( reject = new QPushButton( tr( "&Cancel" ), d ), 3, 1 ); | ||
400 | accept->setDefault( true ); | ||
401 | accept->setAutoDefault( true ); | ||
402 | from->setText( "WL II User" ); | ||
403 | location->setText( "WL II Location" ); | ||
404 | comments->setText( "No Comments." ); | ||
405 | connect( accept, SIGNAL( clicked() ), d, SLOT( accept() ) ); | ||
406 | connect( reject, SIGNAL( clicked() ), d, SLOT( reject() ) ); | ||
407 | int result = d->exec(); | ||
408 | |||
409 | if ( !result ) | ||
410 | { | ||
411 | qDebug( "Session upload cancelled :(" ); | ||
412 | return; | ||
413 | } | ||
414 | |||
379 | qDebug( "Starting upload..." ); | 415 | qDebug( "Starting upload..." ); |
380 | 416 | ||
381 | struct sockaddr_in raddr; | 417 | struct sockaddr_in raddr; |
382 | struct hostent *rhost_info; | 418 | struct hostent *rhost_info; |
383 | int sock = -1; | 419 | int sock = -1; |
384 | bool ok = false; | 420 | bool ok = false; |
385 | 421 | ||
386 | rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname ); | 422 | rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname ); |
387 | if ( rhost_info ) | 423 | if ( rhost_info ) |
388 | { | 424 | { |
389 | if ( !QFile::exists( "/var/log/dump.wellenreiter" ) ) | 425 | if ( !QFile::exists( "/var/log/dump.wellenreiter" ) ) |
390 | { | 426 | { |
391 | qDebug( "no file to upload!" ); | 427 | QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Logfile doesn't exist</p>") ); |
392 | return; | 428 | return; |
393 | } | 429 | } |
394 | 430 | ||
395 | QFile f( "/var/log/dump.wellenreiter" ); | 431 | QFile f( "/var/log/dump.wellenreiter" ); |
396 | if ( !f.open( IO_ReadOnly ) ) | 432 | if ( !f.open( IO_ReadOnly ) ) |
397 | { | 433 | { |
398 | qDebug( "can't open file!" ); | 434 | QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Can't open Logfile</p>") ); |
399 | return; | 435 | return; |
400 | } | 436 | } |
401 | 437 | ||
402 | int content_length = f.size(); | 438 | int content_length = f.size(); |
403 | 439 | ||
404 | ::memset( &raddr, 0, sizeof (struct sockaddr_in) ); | 440 | ::memset( &raddr, 0, sizeof (struct sockaddr_in) ); |
405 | ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); | 441 | ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length ); |
406 | raddr.sin_family = rhost_info-> h_addrtype; | 442 | raddr.sin_family = rhost_info-> h_addrtype; |
407 | raddr.sin_port = htons ( 80 ); | 443 | raddr.sin_port = htons ( 80 ); |
408 | 444 | ||
409 | sock = ::socket( AF_INET, SOCK_STREAM, 0 ); | 445 | sock = ::socket( AF_INET, SOCK_STREAM, 0 ); |
410 | 446 | ||
411 | if ( sock >= 0 ) | 447 | if ( sock >= 0 ) |
412 | { | 448 | { |
413 | if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) | 449 | if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 ) |
414 | { | 450 | { |
415 | QString header; | 451 | QString header; |
416 | QString content; | 452 | QString content; |
417 | QString preambel; | 453 | QString preambel; |
418 | 454 | ||
419 | header = "" | 455 | header = "" |
420 | "POST /projects/capturedump.spy HTTP/1.1\r\n" | 456 | "POST /projects/capturedump.spy HTTP/1.1\r\n" |
421 | "Host: www.vanille.de\r\n" | 457 | "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" | 458 | "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" | 459 | "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" | 460 | "Accept-Language: en\r\n" |
425 | "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n" | 461 | "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" | 462 | "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n" |
427 | "Keep-Alive: 300\r\n" | 463 | "Keep-Alive: 300\r\n" |
428 | "Connection: keep-alive\r\n" | 464 | "Connection: keep-alive\r\n" |
429 | "Referer: http://www.vanille.de/projects/capturedump.spy\r\n" | 465 | "Referer: http://www.vanille.de/projects/capturedump.spy\r\n" |
430 | "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n" | 466 | "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n" |
431 | "Content-Length: %1\r\n" | 467 | "Content-Length: %1\r\n" |
432 | "\r\n"; | 468 | "\r\n"; |
433 | 469 | ||
434 | content = "" | 470 | content = "" |
435 | "-----------------------------97267758015830030481215568065\r\n" | 471 | "-----------------------------97267758015830030481215568065\r\n" |
436 | "Content-Disposition: form-data; name=\"Name\"\r\n" | 472 | "Content-Disposition: form-data; name=\"Name\"\r\n" |
437 | "\r\n" | 473 | "\r\n" |
438 | "Anonymous Wellenreiter II User\r\n" | 474 | "%1\r\n" |
439 | "-----------------------------97267758015830030481215568065\r\n" | 475 | "-----------------------------97267758015830030481215568065\r\n" |
440 | "Content-Disposition: form-data; name=\"Location\"\r\n" | 476 | "Content-Disposition: form-data; name=\"Location\"\r\n" |
441 | "\r\n" | 477 | "\r\n" |
442 | "Anonymous Wellenreiter II Location\r\n" | 478 | "%2\r\n" |
443 | "-----------------------------97267758015830030481215568065\r\n" | 479 | "-----------------------------97267758015830030481215568065\r\n" |
444 | "Content-Disposition: form-data; name=\"Comments\"\r\n" | 480 | "Content-Disposition: form-data; name=\"Comments\"\r\n" |
445 | "\r\n" | 481 | "\r\n" |
446 | "Anonymous Wellenreiter II Comments\r\n" | 482 | "%3\r\n" |
447 | "-----------------------------97267758015830030481215568065\r\n" | 483 | "-----------------------------97267758015830030481215568065\r\n" |
448 | "Content-Disposition: form-data; name=\"upfile\"; filename=\"/var/log/dump.wellenreiter\"\r\n" | 484 | "Content-Disposition: form-data; name=\"upfile\"; filename=\"/var/log/dump.wellenreiter\"\r\n" |
449 | "Content-Type: application/octet-stream\r\n" | 485 | "Content-Type: application/octet-stream\r\n" |
450 | "\r\n"; | 486 | "\r\n"; |
451 | 487 | ||
452 | preambel = "" | 488 | preambel = "" |
453 | "\r\n-----------------------------97267758015830030481215568065--\r\n"; | 489 | "\r\n-----------------------------97267758015830030481215568065--\r\n"; |
454 | 490 | ||
491 | content = content.arg( from->text().isEmpty() ? QString( "Anonymous Wellenreiter II User" ) : from->text() ); | ||
492 | content = content.arg( location->text().isEmpty() ? QString( "Anonymous Wellenreiter II Location" ) : location->text() ); | ||
493 | content = content.arg( comments->text().isEmpty() ? QString( "Anonymous Wellenreiter II Comments" ) : comments->text() ); | ||
494 | |||
455 | header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) ); | 495 | header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) ); |
456 | 496 | ||
457 | // write header | 497 | // write header |
458 | 498 | ||
459 | const char* ascii = header.latin1(); | 499 | const char* ascii = header.latin1(); |
460 | uint ascii_len = ::strlen( ascii ); | 500 | uint ascii_len = ::strlen( ascii ); |
461 | ::write ( sock, ascii, ascii_len ); | 501 | ::write ( sock, ascii, ascii_len ); |
462 | 502 | ||
463 | // write fixed content | 503 | // write fixed content |
464 | 504 | ||
465 | ascii = content.latin1(); | 505 | ascii = content.latin1(); |
466 | ascii_len = ::strlen( ascii ); | 506 | ascii_len = ::strlen( ascii ); |
467 | ::write ( sock, ascii, ascii_len ); | 507 | ::write ( sock, ascii, ascii_len ); |
468 | 508 | ||
469 | // write variable content | 509 | // write variable content |
470 | 510 | ||
471 | char ch; | 511 | char ch; |
472 | while ( !f.atEnd() ) | 512 | while ( !f.atEnd() ) |
473 | { | 513 | { |
474 | f.readBlock( &ch, 1 ); | 514 | f.readBlock( &ch, 1 ); |
475 | ::write ( sock, &ch, 1 ); | 515 | ::write ( sock, &ch, 1 ); |
476 | } | 516 | } |
477 | 517 | ||
478 | // write preambel | 518 | // write preambel |
479 | 519 | ||
480 | ascii = preambel.latin1(); | 520 | ascii = preambel.latin1(); |
481 | ascii_len = ::strlen( ascii ); | 521 | ascii_len = ::strlen( ascii ); |
482 | ::write ( sock, ascii, ascii_len ); | 522 | ::write ( sock, ascii, ascii_len ); |
483 | 523 | ||
484 | // done! | 524 | // done! |
485 | 525 | ||
486 | ok = true; | 526 | ok = true; |
487 | } | 527 | } |
488 | } | 528 | } |
489 | ::close ( sock ); | 529 | ::close ( sock ); |
490 | } | 530 | } |
491 | if ( ok ) | 531 | if ( ok ) |
492 | QMessageBox::information ( 0, tr( "Success" ), QString ( "<p>%1</p>" ). arg( tr( "Capture Dump was uploaded to %1" )).arg ( CAP_hostname )); | 532 | QMessageBox::information( 0, tr( "Success" ), |
533 | QString ( "<p>%1</p>" ).arg( tr( "Capture Dump was uploaded to %1" ) ).arg( CAP_hostname ) ); | ||
493 | else | 534 | else |
494 | QMessageBox::warning ( 0, tr( "Error" ), QString ( "<p>%1</p>" ). arg ( tr( "Connection to %1 failed." )). arg ( CAP_hostname )); | 535 | QMessageBox::warning( 0, tr( "Error" ), |
536 | QString ( "<p>%1</p>" ).arg ( tr( "Connection to %1 failed" ) ).arg( CAP_hostname ) ); | ||
495 | } | 537 | } |
496 | 538 | ||