summaryrefslogtreecommitdiffstats
path: root/src/networkdiscovery.h
blob: 3e34e7d795f5c70a00ff4187491e48ff6ba7c95a (plain) (blame)
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
#ifndef NetworkDiscovery_H
#define NetworkDiscovery_H

#include <QtNetwork>
#include <QtCore>

#include <arpa/inet.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <syslog.h>
#include <sysfs/libsysfs.h>

#include "loggerengine.h"
#include "interfaceconfiguration.h"
#include "networkmanager.h"


#include "dhcp.h"

#include "../common/fbgui.h"


//#define DEFAULT_PATHTODHCPCDEXE "/home/niklas/fbgui/customdhcpcd/src/build/cdhcpcd"
#define DEFAULT_PATHTODHCPCDEXE "/bin/cdhcpcd"

class NetworkDiscovery: public QObject {
Q_OBJECT

public:
	NetworkDiscovery(QObject *parent=0);
	~NetworkDiscovery();

	void initAndRun(QString serverIp, bool userChoice,
			bool autoUp,
			QString pathToLogFile,
			QString serverPath = DEFAULT_QTSOCKETADDRESS,
			QString pathToExe = DEFAULT_PATHTODHCPCDEXE,
			QStringList* args = NULL);
	int ip4_replaceDefaultRoute(QString ifName, QString gateway, int mss);
	QString getGatewayForInterface(QString ifName);

	int ip4_setManualConfiguration(QVariantMap result);
	QString readLogFile();
	void tryAgain();
	bool checkConnectivityViaTcp();
	QVariantMap getInterfaceConfig(QString ifName);

private slots:
	void handleNewConnection();
	void handleNewInput();
	void handleNewInputLine(QLocalSocket * client, QString data);
	void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
	void handleProcessStarted();
	void handleClientDisconnect();

	void slotReadyForRun();

	void checkForIsRunning();


signals:
    void addInterface(const QString &ifName);
    void changeProgressBarValue(const QString & ifName, const int $newValue);
    void connectionEstablished(QString ifName);
    void abortBoot(QString msg);
    void updateStatusLabel(QString ifName, QString status);
    void allProcessesFinished();
    void continueBoot(QString ifName, int userChoice);
    void setManualConfInterfaces(QString jsonArr);

    void readyForRun();

private:
    QString _tag;
    QLocalServer *_server;
    QMap<QLocalSocket*,QLocalSocket*> _clients;
    QLocalSocket *_client;
    QMap<QString,QLocalSocket*> _ifNameToClient;
    QMap<QProcess*,QString> _clientProcessToIfNameMap;
    QString _pathToDhcpcdExe;
    QStringList _dhcpcdArguments;
    int _numberOfProcesses;
    NetworkManager _networkManager;
    bool _userChoice;
    bool _blocked;
    bool _autoUp;
    QString _serverIp;
    QString _pathToLogFile;
    QList<QString> _ifUpList;
    QList<QString> _ifDownList;
    int _ifUpCountdown;
    QTimer *_timer;
    QList<Q_PID> _pidsList;
    QMap<QString,interfaceconfiguration*> _ifcMap;
    void mainWork();

	void handleNewInput(QLocalSocket * client);

	void runDHCPCD(QList<QString> &interfaces);
	void runDHCPCD(QString interface);

	bool checkCarrierState(QString interface);
	bool checkConnectivity(QString ifName);
	bool checkConnectivityViaTcp(QString server);
	
	bool checkBlackList(QString i);

	void getListOfNetworkInterfaces();
	void getListOfNetworkInterfacesWithAutoUp();


};

#endif // NetworkDiscovery_H