summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.cpp127
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
@@ -42,97 +42,98 @@
42#include <qfiledialog.h> 42#include <qfiledialog.h>
43#endif 43#endif
44 44
45WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f ) 45WellenreiterMainWindow::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 );
@@ -321,55 +322,175 @@ void WellenreiterMainWindow::fileSaveHex()
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
326void WellenreiterMainWindow::fileLoadSession() 327void 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
347void WellenreiterMainWindow::fileNew() 348void 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
355void WellenreiterMainWindow::closeEvent( QCloseEvent* e ) 356void 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
370static 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
370void WellenreiterMainWindow::uploadSession() 377void 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