summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.cpp60
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
@@ -16,28 +16,32 @@
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
@@ -78,26 +82,26 @@ WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * n
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() ) );
@@ -367,44 +371,76 @@ void WellenreiterMainWindow::closeEvent( QCloseEvent* e )
367 } 371 }
368} 372}
369 373
370static const char* CAP_hostname = "www.vanille.de"; 374static 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
377void WellenreiterMainWindow::uploadSession() 381void 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
@@ -426,41 +462,45 @@ void WellenreiterMainWindow::uploadSession()
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 );
@@ -480,17 +520,19 @@ void WellenreiterMainWindow::uploadSession()
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