Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

main.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer.  All rights reserved.
00003 **
00004 ** This file is part of Wellenreiter II.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 **********************************************************************/
00015 
00016 #include "mainwindow.h"
00017 
00018 #ifdef QWS
00019 #include <opie2/odebug.h>
00020 #include <opie2/oapplication.h>
00021 #include <opie2/oprocess.h>
00022 #else
00023 #include <qapplication.h>
00024 #endif
00025 
00026 /* QT */
00027 #include <qmessagebox.h>
00028 #include <qstringlist.h>
00029 
00030 /* STD */
00031 #include <errno.h>
00032 #include <signal.h>
00033 #include <string.h>
00034 #include <unistd.h>
00035 
00036 using namespace Opie::Core;
00037 
00038 int main( int argc, char **argv )
00039 {
00040     #ifdef QWS
00041     OApplication a( argc, argv, "Wellenreiter II" );
00042     #else
00043     QApplication a( argc, argv );
00044     #endif
00045     WellenreiterMainWindow* w = new WellenreiterMainWindow();
00046     #ifdef QWS
00047     a.showMainWidget( w );
00048     #else
00049     a.setMainWidget( w );
00050     w->setCaption( "Wellenreiter II" );
00051     w->show();
00052     #endif
00053 
00054     a.processEvents(); // show the window before doing the safety checks
00055     int result = -1;
00056     static int killed = false;
00057 
00058     bool check = true;
00059     for ( int i = 1; i < argc; ++i )
00060     {
00061         odebug << "Wellenreiter::main() parsing argument " << i << " = '" << argv[i] << "'" << oendl; 
00062         if ( !strcmp( "-nocheck", argv[i] ) )
00063         {
00064             odebug << "-nocheck found" << oendl; 
00065             check = false;
00066             break;
00067         }
00068     }
00069 
00070     if ( check )
00071     {
00072         // root check
00073         if ( getuid() )
00074         {
00075             owarn << QObject::tr( "Wellenreiter: trying to run as non-root!" ) << oendl; 
00076             result = QMessageBox::warning( w, " - Wellenreiter II -  (non-root)", QObject::tr( "You have started Wellenreiter II\n"
00077             "as non-root. You will have\nonly limited functionality.\nProceed anyway?" ),
00078             QMessageBox::Yes, QMessageBox::No );
00079             if ( result == QMessageBox::No ) return -1;
00080         }
00081 
00082         int dhcpid = OProcess::processPID( "dhcpc" );
00083 
00084         if ( dhcpid )
00085         {
00086             result = QMessageBox::warning( w, " - Wellenreiter II -  (dhcp)", QObject::tr( "You have a dhcp client running.\n"
00087             "(PID = %1)\nThis can severly limit scanning!\nShould I kill it for you?" ).arg( dhcpid ),
00088             QMessageBox::Yes, QMessageBox::No );
00089             if ( result == QMessageBox::Yes )
00090             {
00091                 if ( -1 == ::kill( dhcpid, SIGTERM ) )
00092                     owarn << "Wellenreiter: can't kill process #" << result << " (" << strerror( errno ) << ")" << oendl; 
00093                 else
00094                     killed = true;
00095             }
00096         }
00097     }
00098 
00099     a.exec();
00100 
00101     if ( check )
00102     {
00103 
00104         if ( killed )
00105         {
00106             result = QMessageBox::warning( w, " - Wellenreiter II -  (dhcp)", QObject::tr( "Restart your dhcp client?" ), QMessageBox::Yes, QMessageBox::No );
00107             if ( result == QMessageBox::Yes )
00108             {
00109                 ::system( QString().sprintf( "dhclient &; udhcpcd &; dhcpcd &" ) );
00110             }
00111         }
00112 
00113         delete w;
00114     }
00115     return 0;
00116 }

Generated on Sat Nov 5 16:15:25 2005 for OPIE by  doxygen 1.4.2