summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show 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
@@ -1,186 +1,187 @@
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "configwindow.h"
#include "gps.h"
#include "logwindow.h"
#include "hexwindow.h"
#include "mainwindow.h"
#include "wellenreiter.h"
#include "scanlist.h"
#include <qcombobox.h>
#include <qdatastream.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qiconset.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qstatusbar.h>
#include <qtextstream.h>
#include <qtoolbutton.h>
#ifdef QWS
#include <qpe/resource.h>
#include <opie/ofiledialog.h>
#else
#include "resource.h"
#include <qapplication.h>
#include <qfiledialog.h>
#endif
WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f )
:QMainWindow( parent, name, f )
{
cw = new WellenreiterConfigWindow( this );
mw = new Wellenreiter( this );
mw->setConfigWindow( cw );
setCentralWidget( mw );
// setup application icon
#ifndef QWS
setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) );
setIconText( "Wellenreiter/X11" );
#endif
// setup tool buttons
startButton = new QToolButton( 0 );
#ifdef QWS
startButton->setAutoRaise( true );
#endif
startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) );
startButton->setEnabled( false );
connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) );
stopButton = new QToolButton( 0 );
#ifdef QWS
stopButton->setAutoRaise( true );
#endif
stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) );
stopButton->setEnabled( false );
connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) );
QToolButton* d = new QToolButton( 0 );
#ifdef QWS
d->setAutoRaise( true );
#endif
d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) );
connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) );
uploadButton = new QToolButton( 0 );
#ifdef QWS
uploadButton->setAutoRaise( true );
#endif
uploadButton->setIconSet( Resource::loadIconSet( "up" ) );
- uploadButton->setEnabled( false );
+ //uploadButton->setEnabled( false );
+ uploadButton->setEnabled( true );
connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) );
// setup menu bar
int id;
QMenuBar* mb = menuBar();
QPopupMenu* fileSave = new QPopupMenu( mb );
fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) );
fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) );
fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) );
QPopupMenu* fileLoad = new QPopupMenu( mb );
fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) );
//fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) );
QPopupMenu* file = new QPopupMenu( mb );
file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) );
id = file->insertItem( tr( "&Load" ), fileLoad );
file->insertItem( tr( "&Save" ), fileSave );
file->insertSeparator();
uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) );
file->insertSeparator();
file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) );
QPopupMenu* view = new QPopupMenu( mb );
view->insertItem( tr( "&Configure..." ) );
QPopupMenu* sniffer = new QPopupMenu( mb );
sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) );
sniffer->insertSeparator();
startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) );
sniffer->setItemEnabled( startID, false );
stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) );
sniffer->setItemEnabled( stopID, false );
QPopupMenu* demo = new QPopupMenu( mb );
demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) );
id = mb->insertItem( tr( "&File" ), file );
//id = mb->insertItem( tr( "&View" ), view );
//mb->setItemEnabled( id, false );
id = mb->insertItem( tr( "&Sniffer" ), sniffer );
id = mb->insertItem( tr( "&Demo" ), demo );
mb->setItemEnabled( id, true );
mb->setItemEnabled( uploadID, false );
#ifdef QWS
mb->insertItem( startButton );
mb->insertItem( stopButton );
mb->insertItem( uploadButton );
mb->insertItem( d );
#else // Qt3 changed the insertion order. It's now totally random :(
mb->insertItem( d );
mb->insertItem( uploadButton );
mb->insertItem( stopButton );
mb->insertItem( startButton );
#endif
updateToolButtonState();
// setup status bar (for now only on X11)
#ifndef QWS
statusBar()->message( tr( "Ready." ) );
#endif
connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) );
connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) );
};
void WellenreiterMainWindow::showConfigure()
{
qDebug( "show configure..." );
cw->setCaption( tr( "Configure" ) );
#ifdef QWS
cw->showMaximized();
#endif
int result = cw->exec();
if ( result ) updateToolButtonState();
}
void WellenreiterMainWindow::updateToolButtonState()
{
const QString& interface = cw->interfaceName->currentText();
const int cardtype = cw->driverType();
if ( ( interface != "<select>" ) && ( cardtype != 0 ) )
{
startButton->setEnabled( true );
@@ -273,103 +274,223 @@ void WellenreiterMainWindow::fileSaveLog()
QTextStream t( &f );
t << mw->logWindow()->getLog();
f.close();
qDebug( "Saved log to file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem saving log to file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileSaveSession()
{
QString fname = getFileName( true );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_WriteOnly) )
{
QDataStream t( &f );
t << *mw->netView();
f.close();
qDebug( "Saved session to file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem saving session to file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileSaveHex()
{
QString fname = getFileName( true );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_WriteOnly) )
{
QTextStream t( &f );
t << mw->hexWindow()->getLog();
f.close();
qDebug( "Saved hex log to file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem saving hex log to file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileLoadSession()
{
QString fname = getFileName( false );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_ReadOnly) )
{
QDataStream t( &f );
t >> *mw->netView();
f.close();
qDebug( "Loaded session from file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem loading session from file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileNew()
{
mw->netView()->clear();
mw->logWindow()->clear();
mw->hexWindow()->clear();
}
void WellenreiterMainWindow::closeEvent( QCloseEvent* e )
{
if ( mw->isDaemonRunning() )
{
QMessageBox::warning( this, "Wellenreiter/Opie",
tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) );
e->ignore();
}
else
{
QMainWindow::closeEvent( e );
}
}
+static const char* CAP_hostname = "www.vanille.de";
+
+#include <netdb.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
void WellenreiterMainWindow::uploadSession()
{
- QMessageBox::warning( this, "Wellenreiter/Opie",
- tr( "This feature is\nunder construction... ;-)" ) );
+ qDebug( "Starting upload..." );
+
+ struct sockaddr_in raddr;
+ struct hostent *rhost_info;
+ int sock = -1;
+ bool ok = false;
+
+ rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname );
+ if ( rhost_info )
+ {
+ if ( !QFile::exists( "/var/log/dump.wellenreiter" ) )
+ {
+ qDebug( "no file to upload!" );
+ return;
+ }
+
+ QFile f( "/var/log/dump.wellenreiter" );
+ if ( !f.open( IO_ReadOnly ) )
+ {
+ qDebug( "can't open file!" );
+ return;
+ }
+
+ int content_length = f.size();
+
+ ::memset( &raddr, 0, sizeof (struct sockaddr_in) );
+ ::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length );
+ raddr.sin_family = rhost_info-> h_addrtype;
+ raddr.sin_port = htons ( 80 );
+
+ sock = ::socket( AF_INET, SOCK_STREAM, 0 );
+
+ if ( sock >= 0 )
+ {
+ if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 )
+ {
+ QString header;
+ QString content;
+ QString preambel;
+
+ header = ""
+ "POST /projects/capturedump.spy HTTP/1.1\r\n"
+ "Host: www.vanille.de\r\n"
+ "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n"
+ "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"
+ "Accept-Language: en\r\n"
+ "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n"
+ "Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n"
+ "Keep-Alive: 300\r\n"
+ "Connection: keep-alive\r\n"
+ "Referer: http://www.vanille.de/projects/capturedump.spy\r\n"
+ "Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n"
+ "Content-Length: %1\r\n"
+ "\r\n";
+
+ content = ""
+ "-----------------------------97267758015830030481215568065\r\n"
+ "Content-Disposition: form-data; name=\"Name\"\r\n"
+ "\r\n"
+ "Anonymous Wellenreiter II User\r\n"
+ "-----------------------------97267758015830030481215568065\r\n"
+ "Content-Disposition: form-data; name=\"Location\"\r\n"
+ "\r\n"
+ "Anonymous Wellenreiter II Location\r\n"
+ "-----------------------------97267758015830030481215568065\r\n"
+ "Content-Disposition: form-data; name=\"Comments\"\r\n"
+ "\r\n"
+ "Anonymous Wellenreiter II Comments\r\n"
+ "-----------------------------97267758015830030481215568065\r\n"
+ "Content-Disposition: form-data; name=\"upfile\"; filename=\"/var/log/dump.wellenreiter\"\r\n"
+ "Content-Type: application/octet-stream\r\n"
+ "\r\n";
+
+ preambel = ""
+ "\r\n-----------------------------97267758015830030481215568065--\r\n";
+
+ header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) );
+
+ // write header
+
+ const char* ascii = header.latin1();
+ uint ascii_len = ::strlen( ascii );
+ ::write ( sock, ascii, ascii_len );
+
+ // write fixed content
+
+ ascii = content.latin1();
+ ascii_len = ::strlen( ascii );
+ ::write ( sock, ascii, ascii_len );
+
+ // write variable content
+
+ char ch;
+ while ( !f.atEnd() )
+ {
+ f.readBlock( &ch, 1 );
+ ::write ( sock, &ch, 1 );
+ }
+
+ // write preambel
+
+ ascii = preambel.latin1();
+ ascii_len = ::strlen( ascii );
+ ::write ( sock, ascii, ascii_len );
+
+ // done!
+
+ ok = true;
+ }
+ }
+ ::close ( sock );
+ }
+ if ( ok )
+ QMessageBox::information ( 0, tr( "Success" ), QString ( "<p>%1</p>" ). arg( tr( "Capture Dump was uploaded to %1" )).arg ( CAP_hostname ));
+ else
+ QMessageBox::warning ( 0, tr( "Error" ), QString ( "<p>%1</p>" ). arg ( tr( "Connection to %1 failed." )). arg ( CAP_hostname ));
}