summaryrefslogtreecommitdiff
path: root/noncore/net/wellenreiter/gui/main.cpp
blob: 62db9671610d162f5c56115320c4a5f942763a06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**********************************************************************
** Copyright (C) 2002-2004 Michael 'Mickey' Lauer.  All rights reserved.
**
** This file is part of Wellenreiter II.
**
** 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 "mainwindow.h"

#ifdef QWS
#include <opie2/odebug.h>
#include <opie2/oapplication.h>
#include <opie2/oprocess.h>
#else
#include <qapplication.h>
#endif

/* QT */
#include <qmessagebox.h>
#include <qstringlist.h>

/* STD */
#include <errno.h>
#include <signal.h>
#include <string.h>
#include <unistd.h>

using namespace Opie::Core;

int main( int argc, char **argv )
{
    #ifdef QWS
    OApplication a( argc, argv, "Wellenreiter II" );
    #else
    QApplication a( argc, argv );
    #endif
    WellenreiterMainWindow* w = new WellenreiterMainWindow();
    #ifdef QWS
    a.showMainWidget( w );
    #else
    a.setMainWidget( w );
    w->setCaption( "Wellenreiter II" );
    w->show();
    #endif

    a.processEvents(); // show the window before doing the safety checks
    int result = -1;
    static int killed = false;

    bool check = true;
    for ( int i = 1; i < argc; ++i )
    {
        odebug << "Wellenreiter::main() parsing argument " << i << " = '" << argv[i] << "'" << oendl; 
        if ( !strcmp( "-nocheck", argv[i] ) )
        {
            odebug << "-nocheck found" << oendl; 
            check = false;
            break;
        }
    }

    if ( check )
    {
        // root check
        if ( getuid() )
        {
            owarn << QObject::tr( "Wellenreiter: trying to run as non-root!" ) << oendl; 
            result = QMessageBox::warning( w, " - Wellenreiter II -  (non-root)", QObject::tr( "You have started Wellenreiter II\n"
            "as non-root. You will have\nonly limited functionality.\nProceed anyway?" ),
            QMessageBox::Yes, QMessageBox::No );
            if ( result == QMessageBox::No ) return -1;
        }

        int dhcpid = OProcess::processPID( "dhcpc" );

        if ( dhcpid )
        {
            result = QMessageBox::warning( w, " - Wellenreiter II -  (dhcp)", QObject::tr( "You have a dhcp client running.\n"
            "(PID = %1)\nThis can severly limit scanning!\nShould I kill it for you?" ).arg( dhcpid ),
            QMessageBox::Yes, QMessageBox::No );
            if ( result == QMessageBox::Yes )
            {
                if ( -1 == ::kill( dhcpid, SIGTERM ) )
                    owarn << "Wellenreiter: can't kill process #" << result << " (" << strerror( errno ) << ")" << oendl; 
                else
                    killed = true;
            }
        }
    }

    a.exec();

    if ( check )
    {

        if ( killed )
        {
            result = QMessageBox::warning( w, " - Wellenreiter II -  (dhcp)", QObject::tr( "Restart your dhcp client?" ), QMessageBox::Yes, QMessageBox::No );
            if ( result == QMessageBox::Yes )
            {
                ::system( QString().sprintf( "dhclient &; udhcpcd &; dhcpcd &" ) );
            }
        }

        delete w;
    }
    return 0;
}