Ejemplo n.º 1
0
	void HttpServer::handlePost(HttpClientHandler* hdlr,const QHttpRequestHeader & hdr,const QByteArray & data)
	{
		Out(SYS_WEB|LOG_DEBUG) << "POST " << hdr.path() << endl;
		KUrl url;
		url.setEncodedPathAndQuery(hdr.path());
		WebContentGenerator* gen = content_generators.find(url.path());
		if (gen)
		{
			if ((gen->getPermissions() == WebContentGenerator::LOGIN_REQUIRED && (!session.logged_in || !checkSession(hdr))) && WebInterfacePluginSettings::authentication())
			{
				// redirect to login page
				redirectToLoginPage(hdlr);
			}
			else
			{
				gen->post(hdlr,hdr,data);
			}
		}
		else
		{
			KUrl url;
			url.setEncodedPathAndQuery(hdr.path());
			QString path = commonDir() + url.path();
			// first try the common dir
			if (!bt::Exists(path)) // doesn't exist so it must be in the skin dir
				path = skinDir() + url.path();
			
			handleFile(hdlr,hdr,path);
		}
	}
Ejemplo n.º 2
0
    void TorrentPostHandler::post(HttpClientHandler* hdlr, const QHttpRequestHeader& hdr, const QByteArray& data)
    {
        const char* ptr = data.data();
        int len = data.size();
        int pos = QString(data).indexOf("\r\n\r\n");

        if (pos == -1 || pos + 4 >= len)
        {
            HttpResponseHeader rhdr(500);
            server->setDefaultResponseHeaders(rhdr, "text/html", false);
            hdlr->send500(rhdr, i18n("Invalid data received"));
            return;
        }

        // save torrent to a temporary file
        QString save_file = kt::DataDir() + "webgui_load_torrent";
        QFile tmp_file(save_file);

        if (!tmp_file.open(QIODevice::WriteOnly))
        {
            HttpResponseHeader rhdr(500);
            server->setDefaultResponseHeaders(rhdr, "text/html", false);
            hdlr->send500(rhdr, i18n("Failed to open temporary file"));
            return;
        }

        QDataStream out(&tmp_file);
        out.writeRawData(ptr + (pos + 4), len - (pos + 4));
        tmp_file.close();

        Out(SYS_WEB | LOG_NOTICE) << "Loading file " << save_file << endl;
        core->loadSilently(KUrl(save_file), QString());

        KUrl url;
        url.setEncodedPathAndQuery(hdr.path());
        QString page = url.queryItem("page");
        // there needs to be a page to send back
        if (page.isEmpty())
        {
            server->redirectToLoginPage(hdlr);
        }
        else
        {
            // redirect to page mentioned in page parameter
            HttpResponseHeader rhdr(301);
            server->setDefaultResponseHeaders(rhdr, "text/html", true);
            rhdr.setValue("Location", "/" + page);
            hdlr->send(rhdr, QByteArray());
        }
    }
Ejemplo n.º 3
0
	void HttpServer::handleGet(HttpClientHandler* hdlr,const QHttpRequestHeader & hdr)
	{
		if (rootDir.isEmpty())
		{
			HttpResponseHeader rhdr(500,hdr.majorVersion(),hdr.minorVersion());
			setDefaultResponseHeaders(rhdr,"text/html",false);
			hdlr->send500(rhdr,i18n("Cannot find web interface skins."));
			return;
		}
		
		QString file = hdr.path();
		if (file == "/" && WebInterfacePluginSettings::authentication())
			file = "/login.html";
		else if (file == "/")
			file = "/interface.html";
			
		KUrl url;
		url.setEncodedPathAndQuery(file);
		
		Out(SYS_WEB|LOG_DEBUG) << "GET " << hdr.path() << endl;
		WebContentGenerator* gen = content_generators.find(url.path());
		if (gen)
		{
			if ((gen->getPermissions() == WebContentGenerator::LOGIN_REQUIRED && (!session.logged_in || !checkSession(hdr))) && WebInterfacePluginSettings::authentication())
			{
				// redirect to login page
				redirectToLoginPage(hdlr);
			}
			else
			{
				gen->get(hdlr,hdr);
			}
		}
		else
		{
			QString path = commonDir() + url.path();
			// first try the common dir
			if (!bt::Exists(path)) // doesn't exist so it must be in the skin dir
				path = skinDir() + url.path();
			
			handleFile(hdlr,hdr,path);
		}
	}
Ejemplo n.º 4
0
	void HTTPTracker::doRequest(WaitJob* wjob)
	{
		KUrl u = url;
		if (!url.isValid())
		{
			requestPending();
			QTimer::singleShot(500, this, SLOT(emitInvalidURLFailure()));
			return;
		}

		Uint16 port = ServerInterface::getPort();

		u.addQueryItem("peer_id", peer_id.toString());
		u.addQueryItem("port", QString::number(port));
		u.addQueryItem("uploaded", QString::number(bytesUploaded()));
		u.addQueryItem("downloaded", QString::number(bytesDownloaded()));

		if (event == "completed")
			u.addQueryItem("left", "0"); // need to send 0 when we are completed
		else
			u.addQueryItem("left", QString::number(tds->bytesLeft()));

		u.addQueryItem("compact", "1");
		if (event != "stopped")
			u.addQueryItem("numwant", "200");
		else
			u.addQueryItem("numwant", "0");

		u.addQueryItem("key", QString::number(key));
		QString cip = Tracker::getCustomIP();
		if (cip.isNull())
			cip = CurrentIPv6Address();
		
		if (!cip.isEmpty())
			u.addQueryItem("ip", cip);
		
		if (event.isEmpty() && supports_partial_seed_extension && tds->isPartialSeed())
			event = "paused";

		if (!event.isEmpty())
			u.addQueryItem("event", event);
		
		QString epq = u.encodedPathAndQuery();
		const SHA1Hash & info_hash = tds->infoHash();
		epq += "&info_hash=" + info_hash.toURLString();


		u.setEncodedPathAndQuery(epq);

		if (active_job)
		{
			announce_queue.append(u);
			Out(SYS_TRK | LOG_NOTICE) << "Announce ongoing, queueing announce" << endl;
		}
		else
		{
			doAnnounce(u);
			// if there is a wait job, add this job to the waitjob
			if (wjob)
				wjob->addExitOperation(new ExitJobOperation(active_job));
		}
	}