Exemplo n.º 1
0
void Qaul::QaulConfigureFirewall(void)
{
    qDebug() << "configure firewall";

    // configure iptables
    // set rules for captive portal
    qaulConfigProcess->write("iptables -t nat -I PREROUTING 1 -i ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" -p tcp -d ");
    qaulConfigProcess->write(Qaullib_GetIP());
    qaulConfigProcess->write(" --dport 80 -j REDIRECT --to-port 8081 \n");
    qaulFirewallCounter++;

    qaulConfigProcess->write("iptables -t nat -I PREROUTING 1 -i ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" -p udp -d ");
    qaulConfigProcess->write(Qaullib_GetIP());
    qaulConfigProcess->write(" --dport 53 -j REDIRECT --to-port 8053 \n");
    qaulFirewallCounter++;

    // start portfwd for DHCP
    // (netconfig/iptables can't handle 0.0.0.0 packages)
    QString myPath = QApplication::applicationDirPath();
    QString myCmd;
    myCmd = myPath +"/portfwd -c " +myPath +"/portfwd.conf \n";
    qaulConfigProcess->write(myCmd.toUtf8().constData());

    qDebug() << "command: " << myCmd;

    qDebug() << "firewall configured";
}
Exemplo n.º 2
0
// ------------------------------------------------------------
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++;
	}
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
void Qaul::QaulWifiConfigure(void)
{
    qDebug() << "process started";
/*
    //!!! did not work
    // stop network manager
    qaulConfigProcess->write("/usr/bin/service network-manager stop \n");
    // take wifi interface down
    qaulConfigProcess->write("/bin/ip link set ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" down \n");
    // set adhoc mode
    qaulConfigProcess->write("/usr/sbin/iw dev ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" mode ad-hoc \n");
    // bring wifi interface up
    qaulConfigProcess->write("/bin/ip link set ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" up \n");
    // join / create network
    qaulConfigProcess->write("/usr/sbin/iw dev ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" ibss join qaul.net 2462 \n");
    // set ip address
    qaulConfigProcess->write("/bin/ip addr add ");
    qaulConfigProcess->write(Qaullib_GetIP());
    qaulConfigProcess->write("/8 dev ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" \n");
*/
    // -------------------------------------------------------
    // configure with iwconfig
    // -------------------------------------------------------
    // stop network manager
    qaulConfigProcess->write("/usr/bin/service network-manager stop \n");
    // take wifi interface down
    qaulConfigProcess->write("/bin/ip link set ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" down \n");
    // set adhoc mode
    qaulConfigProcess->write("/sbin/iwconfig ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" mode ad-hoc \n");
    // set channel
    qaulConfigProcess->write("/sbin/iwconfig ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" channel 11 \n");
    // set essid
    qaulConfigProcess->write("/sbin/iwconfig ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" essid 'qaul.net' \n");
    // bring wifi interface up
    qaulConfigProcess->write("/bin/ip link set ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" up \n");
    // set ip address
    qaulConfigProcess->write("/bin/ip addr add ");
    qaulConfigProcess->write(Qaullib_GetIP());
    qaulConfigProcess->write("/8 dev ");
    qaulConfigProcess->write(qaulWifiInterface.toUtf8().constData());
    qaulConfigProcess->write(" broadcast 10.255.255.255 \n");

    // write wifi sucess token
    qaulConfigProcess->write("/bin/echo 'qaulTokenWifi' \n");

    // set dns server manually
    // TODO: preserve old tail / make all configuration via nm
    qaulConfigProcess->write("/bin/rm /etc/resolvconf/resolv.conf.d/tail \n");
    QString myPath = QApplication::applicationDirPath();
    QString myCmd;
    myCmd = "/bin/cp " +myPath +"/tail /etc/resolvconf/resolv.conf.d/tail \n";
    qaulConfigProcess->write(myCmd.toUtf8().constData());
    qaulConfigProcess->write("resolvconf -u \n");

    qDebug() << "process cmd written";

    //qaulConfigureCounter = 30;
    //QaulConfigure();
}