⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webserver.cpp

📁 非常出名开源客户端下载的程序emule
💻 CPP
📖 第 1 页 / 共 5 页
字号:

CString CWebServer::_GetGraphs(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString Out = pThis->m_Templates.sGraphs;

	XBMDraw drawUp, drawDown;
	drawUp.CreateImage("image_up", WEB_GRAPH_WIDTH, WEB_GRAPH_HEIGHT);
	drawDown.CreateImage("image_down", WEB_GRAPH_WIDTH, WEB_GRAPH_HEIGHT);
	CString sGraphDownload = "", sGraphUpload = "";
	int nPrevValUp = 0, nPrevValDown = 0;
	for(int i = 0; i < WEB_GRAPH_WIDTH; i++)
	{
		if(i % 4 == 0)
		{
			for(int j = 1; j < 6; j++)
			{
				drawDown.Plot(i, (WEB_GRAPH_HEIGHT / 6) * j);
				drawUp.Plot(i, (WEB_GRAPH_HEIGHT / 6) * j);
			}
		}
		int nVal;
		if(i < pThis->m_Params.PointsForWeb.GetCount())
		{
			int nI = i;
			if(pThis->m_Params.PointsForWeb.GetCount() < WEB_GRAPH_WIDTH)
				nI = WEB_GRAPH_WIDTH - pThis->m_Params.PointsForWeb.GetCount() + i;
			// download
			nVal = (pThis->m_Params.PointsForWeb[i].download * WEB_GRAPH_HEIGHT) / (theApp.glob_prefs->GetMaxGraphDownloadRate() + 4);
			if(nVal > WEB_GRAPH_HEIGHT)
				nVal = WEB_GRAPH_HEIGHT;
			drawDown.Plot(nI, nVal);

			if(i != 0)
				drawDown.Line(nI - 1, nPrevValDown, nI, nVal);
			nPrevValDown = nVal;
			// upload
			nVal = (pThis->m_Params.PointsForWeb[i].upload * WEB_GRAPH_HEIGHT) / (theApp.glob_prefs->GetMaxGraphUploadRate() + 4);
			if(nVal > WEB_GRAPH_HEIGHT)
				nVal = WEB_GRAPH_HEIGHT;
			drawUp.Plot(nI, nVal);
			if(i != 0)
				drawUp.Line(nI - 1, nPrevValUp, nI, nVal);
			nPrevValUp = nVal;
		}
	}

	CString sUp, sDown;
	drawUp.GetImage(sUp);
	drawDown.GetImage(sDown);

	for (int ix=0;ix<sUp.GetLength()-1;ix++) {
		if (sUp.Mid(ix,2).Compare("0x")==0) {
			if (sUp.GetAt(ix+3)==','||sUp.GetAt(ix+3)==' ') {sUp.Insert(ix+2,'0');ix+=4;}
		}
	}
	for (int ix=0;ix<sDown.GetLength()-1;ix++) {
		if (sDown.Mid(ix,2).Compare("0x")==0) {
			if (sDown.GetAt(ix+3)==','||sDown.GetAt(ix+3)==' ') {sDown.Insert(ix+2,'0');ix+=4;}
		}
	}
	Out.Replace("[GraphDownload]", sDown + drawDown.GetImageTag());
	Out.Replace("[GraphUpload]", sUp + drawUp.GetImageTag());
	Out.Replace("[TxtDownload]", _GetPlainResString(IDS_DOWNLOAD));
	Out.Replace("[TxtUpload]", _GetPlainResString(IDS_PW_CON_UPLBL));
	CString sScale;

	sScale.Format("%s %s", _GetPlainResString(IDS_TIME).GetBuffer(0), 
		CastSecondsToHM(theApp.glob_prefs->GetTrafficOMeterInterval() * WEB_GRAPH_WIDTH) );

	CString s1, s2;
	s1.Format("%d " + _GetPlainResString(IDS_KBYTESEC) + ", ", theApp.glob_prefs->GetMaxGraphDownloadRate() + 4);
	s2.Format("%d " + _GetPlainResString(IDS_KBYTESEC) + ", ", theApp.glob_prefs->GetMaxGraphUploadRate() + 4);
	s1 += sScale; s2 += sScale;
	Out.Replace("[MaxDownload]", s1);
	Out.Replace("[MaxUpload]", s2);

	return Out;
}

CString CWebServer::_GetAddServerBox(ThreadData Data)
{

	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");

	if (!IsSessionAdmin(Data,sSession)) return "";

	CString Out = pThis->m_Templates.sAddServerBox;
	if(_ParseURL(Data.sURL, "addserver") == "true")
	{
		CServer* nsrv = new CServer(atoi(_ParseURL(Data.sURL, "serverport")), _ParseURL(Data.sURL, "serveraddr").GetBuffer() );
		theApp.serverlist->AddServer(nsrv);
		CString resultlog = _SpecialChars(theApp.emuledlg->logtext);	//Pick-up last line of the log
		resultlog = resultlog.TrimRight('\n');
		resultlog = resultlog.Mid(resultlog.ReverseFind('\n'));
		Out.Replace("[Message]",resultlog);
	}
	else
		if(_ParseURL(Data.sURL, "updateservermetfromurl") == "true")
		{
				theApp.emuledlg->serverwnd.UpdateServerMetFromURL(_ParseURL(Data.sURL, "servermeturl"));
				CString resultlog = _SpecialChars(theApp.emuledlg->logtext);
				resultlog = resultlog.TrimRight('\n');
				resultlog = resultlog.Mid(resultlog.ReverseFind('\n'));
				Out.Replace("[Message]",resultlog);
		}
		else
		Out.Replace("[Message]", "");
    Out.Replace("[AddServer]", _GetPlainResString(IDS_SV_NEWSERVER));
	Out.Replace("[IP]", _GetPlainResString(IDS_SV_ADDRESS));
	Out.Replace("[Port]", _GetPlainResString(IDS_SV_PORT));
	Out.Replace("[Name]", _GetPlainResString(IDS_SW_NAME));
	Out.Replace("[Add]", _GetPlainResString(IDS_SV_ADD));
	Out.Replace("[UpdateServerMetFromURL]", _GetPlainResString(IDS_SV_MET));
	Out.Replace("[URL]", _GetPlainResString(IDS_SV_URL));
	Out.Replace("[Apply]", _GetPlainResString(IDS_PW_APPLY));

	return Out;
}
CString	CWebServer::_GetWebSearch(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");
    
	CString Out = pThis->m_Templates.sWebSearch;
	if(_ParseURL(Data.sURL, "tosearch") != "")
	{
		CString query;
		CString tosearch = _ParseURL(Data.sURL, "tosearch");
		query = "http://www.filedonkey.com/fdsearch/index.php?media=";
		query += _ParseURL(Data.sURL, "media");
		tosearch = URLEncode(tosearch);
		tosearch.Replace("%20","+");
		query += "&pattern=";
		query += _ParseURL(Data.sURL, "tosearch");
		query += "&action=search&name=FD-Search&op=modload&file=index&requestby=emule";
		Out += "\n<script language=\"javascript\">";
		Out += "\n searchwindow=window.open('"+ query + "','searchwindow');";
		Out += "\n</script>";
	}
	Out.Replace("[Session]", sSession);
	Out.Replace("[WebSearch]", _GetPlainResString(IDS_SW_WEBBASED));
	Out.Replace("[Name]", _GetPlainResString(IDS_SW_NAME));
	Out.Replace("[Type]", _GetPlainResString(IDS_TYPE));
	Out.Replace("[Any]", _GetPlainResString(IDS_SEARCH_ANY));
	Out.Replace("[Audio]", _GetPlainResString(IDS_SEARCH_AUDIO));
	Out.Replace("[Video]", _GetPlainResString(IDS_SEARCH_VIDEO));
	Out.Replace("[Other]", "Other");
	Out.Replace("[Search]", _GetPlainResString(IDS_SW_START));
	
	return Out;
}

CString CWebServer::_GetLog(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");

	CString Out = pThis->m_Templates.sLog;

	if (_ParseURL(Data.sURL, "clear") == "yes")
	{
		theApp.emuledlg->ResetLog();
	}
	Out.Replace("[Clear]", _GetPlainResString(IDS_PW_RESET));
	Out.Replace("[Log]", _SpecialChars(theApp.emuledlg->logtext));
	Out.Replace("[Session]", sSession);

	return Out;
}

CString CWebServer::_GetServerInfo(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");

	CString Out = pThis->m_Templates.sServerInfo;

	if (_ParseURL(Data.sURL, "clear") == "yes")
	{
		theApp.emuledlg->serverwnd.servermsgbox.SetWindowText("");
	}
	Out.Replace("[Clear]", _GetPlainResString(IDS_PW_RESET));
	Out.Replace("[ServerInfo]", _SpecialChars(theApp.emuledlg->serverwnd.servermsgbox.GetHyperText()->GetText()));
	Out.Replace("[Session]", sSession);

	return Out;
}

CString CWebServer::_GetDebugLog(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");

	CString Out = pThis->m_Templates.sDebugLog;

	if (_ParseURL(Data.sURL, "clear") == "yes")
	{
		theApp.emuledlg->ResetDebugLog();
	}
	Out.Replace("[Clear]", _GetPlainResString(IDS_PW_RESET));
	Out.Replace("[DebugLog]", _SpecialChars(theApp.emuledlg->debuglog));
	Out.Replace("[Session]", sSession);

	return Out;

}

CString CWebServer::_GetStats(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");

	// refresh statistics
	theApp.emuledlg->ShowStatistics();

	CString Out = pThis->m_Templates.sStats;
	Out.Replace("[Stats]", theApp.emuledlg->statisticswnd.ExportHTML());

	return Out;

}

CString CWebServer::_GetPreferences(ThreadData Data)
{
	CWebServer *pThis = (CWebServer *)Data.pThis;
	if(pThis == NULL)
		return "";

	CString sSession = _ParseURL(Data.sURL, "ses");

	CString Out = pThis->m_Templates.sPreferences;
	Out.Replace("[Session]", sSession);

	if ((_ParseURL(Data.sURL, "saveprefs") == "true") && IsSessionAdmin(Data,sSession) ) {
		if(_ParseURL(Data.sURL, "gzip") == "true" || _ParseURL(Data.sURL, "gzip") == "on")
		{
			theApp.glob_prefs->SetWebUseGzip(true);
		}
		if(_ParseURL(Data.sURL, "gzip") == "false" || _ParseURL(Data.sURL, "gzip") == "")
		{
			theApp.glob_prefs->SetWebUseGzip(false);
		}
		if(_ParseURL(Data.sURL, "showuploadqueue") == "true" || _ParseURL(Data.sURL, "showuploadqueue") == "on" )
		{
			pThis->m_Params.bShowUploadQueue = true;
		}
		if(_ParseURL(Data.sURL, "showuploadqueue") == "false" || _ParseURL(Data.sURL, "showuploadqueue") == "")
		{
			pThis->m_Params.bShowUploadQueue = false;
		}
		if(_ParseURL(Data.sURL, "refresh") != "")
		{
			theApp.glob_prefs->SetWebPageRefresh(atoi(_ParseURL(Data.sURL, "refresh")));
		}
		if(_ParseURL(Data.sURL, "maxdown") != "")
		{
			if(atoi(_ParseURL(Data.sURL, "maxdown"))>0)
				theApp.glob_prefs->SetMaxDownload(atoi(_ParseURL(Data.sURL, "maxdown")));
			else
				theApp.glob_prefs->SetMaxDownload(65535);
		}
		if(_ParseURL(Data.sURL, "maxup") != "")
		{
			if(atoi(_ParseURL(Data.sURL, "maxup"))>0)
				theApp.glob_prefs->SetMaxUpload(atoi(_ParseURL(Data.sURL, "maxup")));
			else
				theApp.glob_prefs->SetMaxUpload(65535);
		}
		if(_ParseURL(Data.sURL, "maxcapdown") != "")
		{
			theApp.glob_prefs->SetMaxGraphDownloadRate(atoi(_ParseURL(Data.sURL, "maxcapdown")));
		}
		if(_ParseURL(Data.sURL, "maxcapup") != "")
		{
			theApp.glob_prefs->SetMaxGraphUploadRate(atoi(_ParseURL(Data.sURL, "maxcapup")));
		}

		if(_ParseURL(Data.sURL, "maxsources") != "")
		{
			theApp.glob_prefs->SetMaxSourcesPerFile(atoi(_ParseURL(Data.sURL, "maxsources")));
		}
		if(_ParseURL(Data.sURL, "maxconnections") != "")
		{
			theApp.glob_prefs->SetMaxConnections(atoi(_ParseURL(Data.sURL, "maxconnections")));
		}
		if(_ParseURL(Data.sURL, "maxconnectionsperfive") != "")
		{
			theApp.glob_prefs->SetMaxConsPerFive(atoi(_ParseURL(Data.sURL, "maxconnectionsperfive")));
		}

		theApp.glob_prefs->SetTransferFullChunks((_ParseURL(Data.sURL, "fullchunks") == "on"));
		theApp.glob_prefs->SetPreviewPrio((_ParseURL(Data.sURL, "firstandlast") == "on"));
	}

	// Fill form
	if(theApp.glob_prefs->GetWebUseGzip())
	{
		Out.Replace("[UseGzipVal]", "checked");
	}
	else
	{
		Out.Replace("[UseGzipVal]", "");
	}
    if(pThis->m_Params.bShowUploadQueue)
	{
		Out.Replace("[ShowUploadQueueVal]", "checked");
	}
	else
	{
		Out.Replace("[ShowUploadQueueVal]", "");
	}
	if(theApp.glob_prefs->GetPreviewPrio())
	{
		Out.Replace("[FirstAndLastVal]", "checked");
	}
	else
	{
		Out.Replace("[FirstAndLastVal]", "");
	}
	if(theApp.glob_prefs->TransferFullChunks())
	{
		Out.Replace("[FullChunksVal]", "checked");
	}
	else
	{
		Out.Replace("[FullChunksVal]", "");
	}
	CString sRefresh;
	
	sRefresh.Format("%d", theApp.glob_prefs->GetWebPageRefresh());
	Out.Replace("[RefreshVal]", sRefresh);

	sRefresh.Format("%d", theApp.glob_prefs->GetMaxSourcePerFile());
	Out.Replace("[MaxSourcesVal]", sRefresh);

	sRefresh.Format("%d", theApp.glob_prefs->GetMaxConnections());
	Out.Replace("[MaxConnectionsVal]", sRefresh);

	sRefresh.Format("%d", theApp.glob_prefs->GetMaxConperFive());
	Out.Replace("[MaxConnectionsPer5Val]", sRefresh);

	Out.Replace("[KBS]", _GetPlainResString(IDS_KBYTESEC)+":");
	Out.Replace("[FileSettings]", CString(_GetPlainResString(IDS_WEB_FILESETTINGS)+":"));
	Out.Replace("[LimitForm]", _GetPlainResString(IDS_WEB_CONLIMITS)+":");
	Out.Replace("[MaxSources]", _GetPlainResString(IDS_PW_MAXSOURCES)+":");
	Out.Replace("[MaxConnections]", _GetPlainResString(IDS_PW_MAXC)+":");
	Out.Replace("[MaxConnectionsPer5]", _GetPlainResString(IDS_MAXCON5SECLABEL)+":");
	Out.Replace("[UseGzipForm]", _GetPlainResString(IDS_WEB_GZIP_COMPRESSION));
	Out.Replace("[UseGzipComment]", _GetPlainResString(IDS_WEB_GZIP_COMMENT));
	Out.Replace("[ShowUploadQueueForm]", _GetPlainResString(IDS_WEB_SHOW_UPLOAD_QUEUE));
	Out.Replace("[ShowUploadQueueComment]", _GetPlainResString(IDS_WEB_UPLOAD_QUEUE_COMMENT));
	Out.Replace("[ShowQueue]", _GetPlainResString(IDS_WEB_SHOW_UPLOAD_QUEUE));
	Out.Replace("[HideQueue]", _GetPlainResString(IDS_WEB_HIDE_UPLOAD_QUEUE));
	Out.Replace("[RefreshTimeForm]", _GetPlainResString(IDS_WEB_REFRESH_TIME));
	Out.Replace("[RefreshTimeComment]", _GetPlainResString(IDS_WEB_REFRESH_COMMENT));
	Out.Replace("[SpeedForm]", _GetPlainResString(IDS_SPEED_L

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -