void BServerSocket::newConnection( int socket )
{
	QSocket *s = new QSocket(this);
	connect(s,SIGNAL(readyRead()),this,SLOT(onReadyRead()));
	connect(s,SIGNAL(connectionClosed()),this,SLOT(onConnectionClosed()));
	s->setSocket(socket);

}
Beispiel #2
0
Q_ULONG QSocket::waitForMore( int msecs, bool *timeout ) const
{
    if ( d->socket == 0 )
	return 0;
    QSocket * that = (QSocket *)this;
    if ( that->d->socket->waitForMore( msecs, timeout ) > 0 )
	(void)that->sn_read( TRUE );
    return that->d->rba.size();
}
Beispiel #3
0
Q_ULONG QSocket::bytesAvailable() const
{
    if ( d->socket == 0 )
	return 0;
    QSocket * that = (QSocket *)this;
    if ( that->d->socket->bytesAvailable() ) // a little slow, perhaps...
	(void)that->sn_read();
    return that->d->rba.size();
}
Beispiel #4
0
bool QSocket::atEnd() const
{
    if ( d->socket == 0 )
	return TRUE;
    QSocket * that = (QSocket *)this;
    if ( that->d->socket->bytesAvailable() )	// a little slow, perhaps...
	that->sn_read();
    return that->d->rba.size() == 0;
}
Beispiel #5
0
	void HttpServer::slotSocketReadyToRead()
	{
		QSocket* client = (QSocket*)sender();
		HttpClientHandler* handler = clients.find(client);
		if (!handler)
		{
			client->deleteLater();
			return;
		}
		
		handler->readyToRead();
	}
void BServerSocket::onConnectionClosed()
{
	QSocket *s = (QSocket *)sender();
	qDebug("Closed here");

//	system("echo testing > /tmp/serverini");
	QSqlQuery query(QString("SELECT computer_logout('") + s->name() + QString("');"), db);
	
	s->close();
	s->deleteLater();
	
}
Beispiel #7
0
	void HttpServer::newConnection(int s)
	{
		QSocket* socket = new QSocket(this);
		socket->setSocket(s);
	
		connect(socket, SIGNAL(readyRead()), this, SLOT(slotSocketReadyToRead()));
		connect(socket, SIGNAL(delayedCloseFinished()), this, SLOT(slotConnectionClosed()));
		connect(socket, SIGNAL(connectionClosed()), this, SLOT(slotConnectionClosed()));
	
		HttpClientHandler* handler = new HttpClientHandler(this,socket);
		clients.insert(socket,handler);
		Out(SYS_WEB|LOG_NOTICE) << "connection from "<< socket->peerAddress().toString()  << endl;
	}
Beispiel #8
0
void ICQServerSocket::activated(int)
{
#ifndef HAVE_KEXTSOCK_H
    if (sock == NULL) return;
    int fd = sock->accept();
    if (fd >= 0){
        log(L_DEBUG, "accept ready");
        if (notify){
            QSocket *s = new QSocket;
            s->setSocket(fd);
            notify->accept(new ICQClientSocket(s));
        }else{
#ifdef WIN32
            ::closesocket(fd);
#else
            ::close(fd);
#endif
        }
    }
#endif
}
Beispiel #9
0
void SIMServerSocket::activated(int)
{
    if (sock == NULL) return;
    int fd = sock->accept();
    if (fd >= 0){
        log(L_DEBUG, "accept ready");
        if (notify){
            QSocket *s = new QSocket;
            s->setSocket(fd);
            if (notify->accept(new SIMClientSocket(s), htonl(s->address().ip4Addr()))){
                if (notify)
                    notify->m_listener = NULL;
                getSocketFactory()->remove(this);
            }
        }else{
#ifdef WIN32
            ::closesocket(fd);
#else
            ::close(fd);
#endif
        }
    }
}
void BServerSocket::onReadyRead()
{
	QSocket *s = (QSocket *)sender();
	if (s->canReadLine())
	{
		QString line = s->readLine();
		qDebug(line);
		line.remove("\n");
		line.remove("\r");
		if (line == "ping")
			writeLineToSocket("pong",s);

		QSqlQuery query(db);
		QString sql;
		QString ipaddress;
		QString username;
		QStringList tokens = QStringList::split(" ",line);
		QString iptablescmd = "iptables ";
		switch (convert(tokens[0]))
		{
		case SN_1 :
			// tokens[1] -> ip / user@ip, tokens[2]-> menit (15,30,60,90,120,99999999), tokens[3]-> tipe (INT,KTK)
			//masukkan ke database karena ada yang login
			//cek disini validitas data klo sala kembalikan pesan error ER_1 / "ER01"
			//send ke client OK_1 / "OK01"
			
			if (tokens[1].contains("@"))
			{
				username = tokens[1].section("@",0,0);
				ipaddress = tokens[1].section("@",1,1); 
				if (tokens[3]=="INT")
				{	
					//iptablescmd += "-D -o $FREEBILLING_IFACE -p tcp -m owner --uid-owner=";
					//iptablescmd += username; /* ganti ke uid */ 
					//iptablescms += " -j DROP";
					//printf("%s\n",iptablescmd.ascii());
					//system (iptablescmd);
				} else
				{
					
					//iptablescmd += "-A -o $FREEBILLING_IFACE -p tcp -m owner --uid-owner=";
					//iptablescmd += username; /* ganti ke uid */ 
					//iptablescmd += " -j DROP";	
					//printf("%s\n",iptablescmd.ascii());
					//system (iptablescmd);
				}


			} else
			{
				
				ipaddress = tokens[1];
				if (tokens[3]=="INT")
				{	
					iptablescmd += "-A POSTROUTING -t nat -s ";
					iptablescmd += ipaddress;
					iptablescmd += " -o $FREEBILLING_IFACE -j MASQUERADE";
					printf("%s\n",iptablescmd.ascii());
					system (iptablescmd);
				} else
				{
					iptablescmd += "-D POSTROUTING -t nat -s ";
					iptablescmd += ipaddress;
					iptablescmd += " -o $FREEBILLING_IFACE -j MASQUERADE";	
					printf("%s\n",iptablescmd.ascii());
					system (iptablescmd);
				}
			}
			
			s->setName(ipaddress);
			
			sql = "SELECT computer_login('" + ipaddress + "','" + tokens[3] + "'," + tokens[2] + ");";

			query.exec(sql);	
			
			writeLineToSocket("OK01",s);
		break;
		case SN_4 :
			query.exec(QString("SELECT computer_logout('") + s->name() + QString("');"));
			s->close();
			s->deleteLater();
		break;
		case CS_1 :
			//resend this message to client
			this->writeLineToSocket("CS01",(QSocket *)this->child(tokens[1]));
			s->close();
			s->deleteLater();
		break;
		}
	}
}