コード例 #1
0
ファイル: main.c プロジェクト: WachterJud/qaul.net_legacy
gboolean qaul_configure(gpointer data)
{
    // initialize qaul library
    if(qaulConfigureCounter == 0)
    {
        // everything is fine
        Qaullib_ConfigStart();
        qaulConfigureCounter = 3;
    }

    // check authorization
    if(qaulConfigureCounter == 10)
    {
        // nothing to be done here
    	qaulConfigureCounter = 20;
    }

    // TODO: enable networking

    // get network interface
    if(qaulConfigureCounter == 20)
    {
        // check if interface has been configured manually
    	if(Qaullib_GetInterfaceManual())
    	{
    		printf("[configure] interface manually configured\n");
    		if(qaul_network_device_get_by_interface(Qaullib_GetInterface(), network_dbus_connection, &network_device))
    			network_interface_found = 1;
    		else
    			printf("[configure] manually configured interface \"%s\" not found\n", Qaullib_GetInterface());
    	}
    	// find wifi interface
    	else
    	{
    		if(qaul_network_find_wifi(network_dbus_connection, &network_device))
    			network_interface_found = 1;
    		else
    			printf("[configure] no wifi interface found\n");
    	}

    	// TODO: enable wifi

    	qaulConfigureCounter = 21;
    }

    // configure network interface
    if(qaulConfigureCounter == 21)
    {
        if(network_interface_found)
        {
        	printf("[configure] network interface %s\n", network_device.interface);

        	// get network configuration
        	strncpy(network_settings.ipv4_address, Qaullib_GetIP(), sizeof(network_settings.ipv4_address));
        	Qaullib_GetConfString("net.gateway", network_settings.ipv4_gateway);
        	network_settings.ipv4_netmask = Qaullib_GetConfInt("net.mask");
        	strncpy(network_settings.ipv4_dns1, "5.45.96.220", sizeof(network_settings.ipv4_dns1));
        	strncpy(network_settings.ipv4_dns2, "185.82.22.133", sizeof(network_settings.ipv4_dns2));
        	network_settings.wifi_channel = Qaullib_GetConfInt("wifi.channel");
        	Qaullib_GetConfString("wifi.ssid", network_settings.wifi_ssid);

        	// add network configuration
        	if(qaul_network_settings_add(network_dbus_connection, &network_settings, &network_device))
        	{
        		printf("[configure] network connection setting added: %s\n", network_settings.dbus_connection_path);

        		// activate configuration
        		if(qaul_network_connection_activate(network_dbus_connection, &network_settings, &network_device))
        			printf("[configure] network connection activated: %s\n", network_settings.dbus_active_connection_path);
        		else
        			printf("[configure] network connection not activated\n");
        	}
        	else
        		printf("[configure] network connection settings not added\n");
        }

    	qaulConfigureCounter = 29;
    }

    // check if username is set
    if(qaulConfigureCounter == 30)
    {
        if(Qaullib_ExistsUsername())
			qaulConfigureCounter = 40;
        else
        {
            // wait
            qaulConfigureCounter--;
        }
    }

    // start olsrd
    if(qaulConfigureCounter == 40)
    {
        printf("[configure] start olsrd \n");

        // start olsrd
        qaul_olsrdStart();

        qaulConfigureCounter = 44;
    }

    // connect ipc
    if(qaulConfigureCounter == 45)
    {
        printf("[configure] connect ipc \n");
        Qaullib_IpcConnect();
        qaulConfigureCounter = 46;
    }

    // start captive portal
    if(qaulConfigureCounter == 46)
    {
    	printf("[configure] start captive portal \n");
    	Qaullib_SetConfVoIP();
        Qaullib_UDP_StartServer();
        Qaullib_CaptiveStart();

        // configure firewall
        qaul_startPortForwarding();

        qaulConfigureCounter = 50;
    }

    // start timers
    if(qaulConfigureCounter == 50)
    {
        printf("[configure] timers \n");

		// start timers
		qaulTimerEvents = g_timeout_add(10, qaul_timerSocket, NULL);
		qaulTimerSockets = g_timeout_add(100, qaul_timerEvent, NULL);
		qaulTimerTopology = g_timeout_add(5000, qaul_timerTopology, NULL);

        Qaullib_ConfigurationFinished();

        qaulConfigureCounter = 60;
    }

    // end configuration
	if(qaulConfigureCounter == 60)
	{
		printf("[configure] finished \n");
		return FALSE;
	}

	qaulConfigureCounter++;
	return TRUE;
}
コード例 #2
0
ファイル: main.c プロジェクト: prodigeni/qaul.net
// ------------------------------------------------------------
int main(int argc, char *argv[])
{
	char cCurrentPath[FILENAME_MAX];

	if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)))
	{
		printf ("ERROR: couldn't get directory\n");
		return EXIT_FAILURE;
	}
	cCurrentPath[sizeof(cCurrentPath) - 1] = '\0';
	printf ("The current working directory is %s\n", cCurrentPath);

	Qaullib_Init(cCurrentPath);
	// enable debug menu
	qaul_conf_debug = 1;

	if(!Qaullib_WebserverStart())
		printf("Webserver startup failed\n");
	Qaullib_ConfigStart();

	printf("----------------------------------------------------\n");
	printf(" config started\n");
	printf("----------------------------------------------------\n");
	// The invoking of Qaullib_GetIP() is mandatory to load the IP.
	printf("IP: %s\n", Qaullib_GetIP());

	// wait until user name is set
	int username_flag = 0;
	while(Qaullib_ExistsUsername() == 0)
	{
		if(username_flag == 0)
		{
			username_flag = 1;
			printf("waiting until user name is set ...\n");
			printf("open web browser with http://localhost:8081/jqm_qaul.html to set it ...\n");
		}
		sleep(1);
	}
	printf("user name successfully set!\n");

	if(!Qaullib_IpcConnect())
		printf("Ipc connection failed\n");
	Qaullib_SetConfVoIP();
	if(!Qaullib_UDP_StartServer())
		printf("UDP server failed\n");
	if(!Qaullib_CaptiveStart())
		printf("Captive portal failed\n");
	Qaullib_ConfigurationFinished();

	// test config
	printf("IP: %s\n", Qaullib_GetIP());
	printf("Qaul started\n");

	// loop variables
	int socketCounter = 0;
	int ipcCounter = 0;

	printf("kill app to exit!\n");

	// main loop
	while (1) {
		usleep(10000);

		// get event
		int event = Qaullib_TimedCheckAppEvent();
		if(event == QAUL_EVENT_QUIT)
			printf("quit app\n");
		else if(event == QAUL_EVENT_CHOOSEFILE)
			printf("open file chooser\n");
		else if(event == QAUL_EVENT_OPENFILE)
			printf("open file\n");

		// check sockets
		if(socketCounter >= 10)
		{
			Qaullib_TimedSocketReceive();
			socketCounter = 0;
		}
		else
			socketCounter++;

		// get network node IPs
		// schedule downloads
		if(ipcCounter >= 500)
		{
			Qaullib_IpcSendCom(1);
			Qaullib_TimedDownload();
			ipcCounter = 0;
		}
		else
			ipcCounter++;
	}
}
コード例 #3
0
ファイル: qaul.cpp プロジェクト: prodigeni/qaul.net
// -----------------------------------------------------------------
// configuration
// -----------------------------------------------------------------
void Qaul::QaulConfigure(void)
{
    // init
    if(qaulConfigureCounter == 0)
    {
        // everything is fine
        Qaullib_ConfigStart();
        qaulConfigureCounter = 10;
    }

    // check autorization
    if(qaulConfigureCounter == 10)
    {
        qaulConfigureCounter = 20;
    }

    // configure wifi
    // search interface
    if(qaulConfigureCounter == 20)
    {
        qDebug() << "[configure] search interface";
        if(QaulWifiGetInterface()) qaulConfigureCounter = 21;
        else
        {
            qDebug() << "no wifi interface found";
            // TODO: display error screen
        }
    }

    // configure interface
    if(qaulConfigureCounter == 21)
    {
        qDebug() << "[configure] configure interface";
        qaulConfigureCounter = 22;
        // open console with sudo
        qDebug() << "open console";
        qaulConfigProcess = new QProcess(this);
        connect(qaulConfigProcess, SIGNAL(started()), this, SLOT(QaulWifiConfigure()));
        connect(qaulConfigProcess, SIGNAL(readyReadStandardOutput()), this, SLOT(QaulConfigureProcessRead()));
        qaulConfigProcess->start("pkexec /bin/bash");
    }

    // wifi configures
    // wait 2 seconds
    if(qaulConfigureCounter == 29) QaulConfigureDelay(2000);

    // check if username is set
    if(qaulConfigureCounter == 30)
    {
        qDebug() << "[configure] check username";
        if(Qaullib_ExistsUsername()) qaulConfigureCounter = 40;
        else
        {
            qaulConfigureCounter--;
            QaulConfigureDelay(500);
        }
    }

    // start olsrd
    if(qaulConfigureCounter == 40)
    {
        qDebug() << "[configure] start olsrd";
        qaulConfigureCounter = 41;
        QaulOlsrdStart();
    }

    if(qaulConfigureCounter == 44) QaulConfigureDelay(2000);

    // connect ipc
    if(qaulConfigureCounter == 45)
    {
        qDebug() << "[configure] connect ipc";
        Qaullib_IpcConnect();
        qaulConfigureCounter = 46;
    }

    // start captive portal
    if(qaulConfigureCounter == 46)
    {
        Qaullib_SetConfVoIP();
        Qaullib_UDP_StartServer();
        Qaullib_CaptiveStart();
        QaulConfigureFirewall();
        qaulConfigureCounter = 50;
    }

    // start timers & finish
    if(qaulConfigureCounter == 50)
    {
        qDebug() << "[configure] timers & finish";
        QaulStartTimers();
        Qaullib_ConfigurationFinished();

        qaulConfigureCounter = 60;
    }

    // finished
}