12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589 |
- #include "stdafx.h"
- #include "uuid4.h"
- #if (defined _WIN32 || defined _WIN64)
- #include "processControl.h"
- #define SPLIT_SLASH_STR "\\"
- #else
- #include <mutex>
- #include <thread>
- #include "path.h"
- #include "fileutil.h"
- #include <boost/process.hpp>
- #include <boost/thread.hpp>
- #include "CommEntityUtil.hpp"
- #include <SDL2/SDL.h>
- //#include <winpr/wnd.h>
- #define HWND_TOP (0)
- #define HWND_BOTTOM (1)
- #define HWND_TOPMOST (-1)
- #define HWND_NOTOPMOST (-2)
- #endif
- #include "baseEx.h"
- #include "CModTools.h"
- #include "SpIni.h"
- #include <vector>
- #include <list>
- #include <memory>
- #include <iostream>
- #include "../mod_upload/Upload_client_g.h"
- #include "mod_chromium.h"
- #include <boost/thread/mutex.hpp>
- #include "EventCode.h"
- #include "url_encoder.h"
- #include "SpUtility.h"
- void SystemRunTest(const std::string& systemCmd);
- extern std::pair<bool, std::string> DetectActiveHttp(std::vector<std::string> urlArr);
- auto GetCefHead = [](CEntityBase* curEntity)->CSimpleStringA {
- CSimpleStringA strChromiumPath, basePath;
- curEntity->GetFunction()->GetPath("Base", basePath);
- strChromiumPath.Append(basePath);
- #if defined(_MSC_VER)
- strChromiumPath.Append(CSimpleStringA(SPLIT_SLASH_STR) + "bin" + SPLIT_SLASH_STR + "Chromium" + SPLIT_SLASH_STR);
- strChromiumPath.Append(CEFCLIENT_NAME);
- #else
- strChromiumPath.Append(CSimpleStringA(SPLIT_SLASH_STR) + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR);
- strChromiumPath.Append("startMixBrower.sh");
- #endif //_MSC_VER
- return strChromiumPath;
- };
- auto detectUrls = [](std::string urls) -> std::string {
- std::vector<std::string> urlArr;
- urlArr.emplace_back(urls);
- auto checkRet = DetectActiveHttp(urlArr);
- LogWarn(Severity_Low, Error_Debug, LOG_SLV_CHROMIUM_URLCHECK,
- CSimpleStringA::Format("check chromium url %d, %s", checkRet.first, checkRet.first ? checkRet.second.c_str() : urls.c_str()));
- if (checkRet.first)
- return checkRet.second.c_str();
- else
- return urlArr[0];
- };
- namespace Chromium {
- boost::mutex g_mutexFreerdp, m_guardInterruptLock;
- void CModTools::lockGuard()
- {
- m_guardInterruptLock.lock();
- }
- void CModTools::unlockGuard()
- {
- m_guardInterruptLock.unlock();
- }
- void CModTools::InitCModTools(CEntityBase* pEntity) {
- this->m_pEntity = pEntity;
- m_UseUOSBrowser = 0;
- m_isGuardMainBrowser = false;
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_Root, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->ReadConfigValue("Terminal", "MachineType", ConfigManager::getInstance().m_strMachineType);
- if (Error == Error_Succeed)
- {
- Error = spConfig->ReadConfigValue("Terminal", "Site", ConfigManager::getInstance().m_strSite);
- if (Error != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ReadConfigValue, get Site value failed");
- }
- }
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("ReadConfigValue, get MachineType value failed");
- }
- }
- auto configRet = ReadCenterConfigStr();
- ConfigManager::getInstance().m_UserMgrUrlStr = std::get<0>(configRet);
- ConfigManager::getInstance().m_UserMgrUrlNoSidebarStr = std::get<1>(configRet);
- ConfigManager::getInstance().m_UserMgrUrlNoSidebarMutiStr = std::get<2>(configRet);
- ConfigManager::getInstance().m_UserMgrUrlFultureStr = std::get<3>(configRet);
- ConfigManager::getInstance().m_UserMgrAdStr = std::get<4>(configRet);
- notifyExist = breakdownExist = m_isAdOpen = false;
- m_magicStr = uuid4_generate(8);
- ConfigManager::getInstance().m_withMin = false;
- #if defined(RVC_OS_LINUX)
- InitBrowserUseMode();
- #endif //RVC_OS_LINUX
- SetSpecialPageParam("", "", "", 0);
- }
- bool CModTools::killAllChromium()
- {
- #if (defined _WIN32 || defined _WIN64)
- const char* killCmd = "taskkill /F /IM cefclient.exe /T";
- SYSTEM_ON(killCmd);
- return true;
- #else
- do
- {
- boost::process::child child_process("sudo killall -9 uosbrowser");
- child_process.wait();
- } while (false);
- do
- {
- boost::process::child child_process("sudo killall -9 cefclient");
- child_process.wait();
- } while (false);
- do {
- boost::process::child child_process("sudo killall -9 browser");
- child_process.wait();
- } while (false);
- breakdownExist = m_isAdOpen = notifyExist = false;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("run killAllChromium success ex");
- return true;
- #endif
- }
- void CModTools::killAllChromiumByThread(int seconds)
- {
- #if (defined _WIN32 || defined _WIN64)
- #else
- auto cur = std::async([]() {
- CModTools::get_mutable_instance().killAllChromium();
- });
- std::future_status a1 = cur.wait_for(std::chrono::seconds(seconds));
- if (a1 == std::future_status::deferred)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("killAllChromiumByThread run delay");
- else
- {
- if (a1 == std::future_status::ready)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("killAllChromiumByThread run end");
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("killAllChromiumByThread do not end, over than %d seconds", seconds);
- }
- #endif
- }
- bool CModTools::killChromiumByName(std::string name)
- {
- return true;
- }
- std::pair<bool, std::string> CModTools::getAdUrl()
- {
- auto AdUrl = ConfigManager::getInstance().m_UserMgrAdStr;
- std::string strUrl = AdUrl.GetData();
- //auto strUrl = detectUrls(AdUrl.GetData());
- return strUrl.length() > 0 ? std::make_pair(true, strUrl) : std::make_pair(false, strUrl);
- }
- std::pair<bool, std::string> CModTools::getErrUrl(ERR_PAGE_REASON errType)
- {
- CSimpleStringA errPagePath;
- m_pEntity->GetFunction()->GetPath("Base", errPagePath);
- errPagePath.Append(SPLIT_SLASH_STR).Append("res").Append(SPLIT_SLASH_STR);
- errPagePath.Append("ManagerDesktop").Append(SPLIT_SLASH_STR);
- if (errType._to_integral() == ERR_PAGE_REASON::breakdown)
- errPagePath.Append("entityCheck.html");
- else if (errType._to_integral() == ERR_PAGE_REASON::warnPrompt)
- errPagePath.Append("serverNoAccess.html");
- else if (errType._to_integral() == ERR_PAGE_REASON::audioErr)
- errPagePath.Append("audioErr.html");
- else if (errType._to_integral() == ERR_PAGE_REASON::CardStoreIsBusy)
- errPagePath.Append("cardStore.html");
- else if (errType._to_integral() == ERR_PAGE_REASON::main)
- errPagePath.Append("homePageErr.html");
- else if (errType._to_integral() == ERR_PAGE_REASON::startup)
- errPagePath.Append("startPage.html");
- else if (errType._to_integral() == ERR_PAGE_REASON::redirect)
- errPagePath.Append("redirect.html");
- else
- errPagePath.Append("entityCheck.html");
- return std::make_pair(true, errPagePath.GetData());
- }
- std::pair<bool, std::string> CModTools::GenerateErrPage(ERR_PAGE_REASON errType, std::tuple < std::string, std::string> norParam, std::tuple<std::string, std::string, std::string, DWORD, DWORD> exParam)
- {
- auto generate_url_prefix = []() -> CSimpleStringA {
- #if defined(RVC_OS_WIN)
- return CSimpleStringA("");
- #else
- return CSimpleStringA("\\");
- #endif
- };
- auto errUrlRet = getErrUrl(errType);
- CSimpleStringA errPagePathBase = errUrlRet.second.c_str();
- CSimpleStringA errPageParams(true);
- CSimpleStringA needGuardian = "Y";
- auto rc = this->m_pEntity->GetFunction()->GetSysVar("NeedGuardian", needGuardian);
- bool showRebootTime = true;
- if (rc == Error_Succeed && needGuardian.Compare("Y", false))
- showRebootTime = false;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("NeedGuardian:%s", needGuardian.GetData());
- switch (errType)
- {
- case ERR_PAGE_REASON::CardStoreIsBusy:
- break;
- case ERR_PAGE_REASON::breakdown:
- case ERR_PAGE_REASON::warnPrompt:
- case ERR_PAGE_REASON::audioErr:
- {
- errPageParams.Append(CSimpleStringA("showlimit=1"));
- if (ConfigManager::getInstance().m_withMin) {
- errPageParams.Append(CSimpleStringA(generate_url_prefix())).Append(CSimpleStringA("&showmin=1"));
- }
- }
- break;
- default:
- return std::make_pair(false, std::string("unknown err_page_reason:").append(errType._to_string()));
- }
- CSimpleStringA errPageUrl(true);
- if (!errPageParams.IsNullOrEmpty()) {
- errPageUrl = CSimpleStringA("file:///") + errPagePathBase + "?" + errPageParams;
- } else {
- errPageUrl = CSimpleStringA("file:///") + errPagePathBase;
- }
- #if defined(RVC_OS_WIN)
- std::string in = errPageUrl.GetData();
- errPageUrl = UrlEncoder::Encode(in).c_str();
- errPageUrl.Append(" ");
- CSimpleStringA cachePath;
- this->m_pEntity->GetFunction()->GetPath("Temp", cachePath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("cefCache_").
- Append(ConfigManager::getInstance().m_strCacheHead.length() > 0 ? ConfigManager::getInstance().m_strCacheHead.c_str() : "").Append(errType._to_string());
- errPageUrl.Append(" --cache-path=").Append(cachePath);
- if (ConfigManager::getInstance().m_extension_withTerminal && ConfigManager::getInstance().m_extension_headerStr.length() > 0)
- errPageUrl.Append(" --modify-header=").Append(ConfigManager::getInstance().m_extension_headerStr.c_str());
- if (ConfigManager::getInstance().m_extension_debugOpen)
- errPageUrl.Append(" --right-menu");
- if (ConfigManager::getInstance().isUseMagic())
- errPageUrl.Append(" --magic-str=").Append(m_magicStr.c_str());
- if (ConfigManager::getInstance().m_withMedia)
- errPageUrl.Append(" --enable-media-stream=1 --enable-speech-input=1");
- if (ConfigManager::getInstance().m_withConsole)
- errPageUrl.Append(" --with-console");
- if(ConfigManager::getInstance().getSogouForce() != 0)
- errPageUrl.Append(" --adapt-sogou=").Append(std::to_string(ConfigManager::getInstance().getSogouForce()).c_str());
- errPageUrl.Append(" --no-sandbox").Append(" --hide-controls --hide-overlays --hide-frame --winhttp-proxy-resolver").Append(" --always-on-top");
- switch (errType) {
- case ERR_PAGE_REASON::TerminalManagerKickOut:
- case ERR_PAGE_REASON::TerminalManagerOff:
- errPageUrl.Append(" --logextend=").Append((+PAGE_TYPE::TerminalManager)._to_string());
- break;
- case ERR_PAGE_REASON::CardStoreIsBusy:
- errPageUrl.Append(" --logextend=").Append((+PAGE_TYPE::CardStoreIsBusy)._to_string());
- break;
- case ERR_PAGE_REASON::CameraConfig:
- errPageUrl.Append(" --logextend=").Append((+PAGE_TYPE::CameraConfig)._to_string());
- break;
- case ERR_PAGE_REASON::disabled:
- case ERR_PAGE_REASON::jobuncomplete:
- errPageUrl.Append(" --logextend=").Append((+PAGE_TYPE::TradeManager)._to_string());
- break;
- case ERR_PAGE_REASON::warnPrompt:
- case ERR_PAGE_REASON::breakdown:
- case ERR_PAGE_REASON::audioErr:
- errPageUrl.Append(" --logextend=").Append((+PAGE_TYPE::breakdown)._to_string());
- break;
- default:
- errPageUrl.Append(" --logextend=").Append((+PAGE_TYPE::errPage)._to_string());
- break;
- }
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity);
- CSimpleString dstCmd = strChromiumPath + " --url=" + errPageUrl;
- #else
- CSimpleString dstCmd = generateBrowserCMDForEverything(errPageUrl.GetData(), 2, false).c_str();
- #endif //RVC_OS_WIN
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GenerateErrPage dstPage=%s", dstCmd.GetData());
- return std::make_pair(true, (const char*)dstCmd.GetData());
- }
- std::string formatTime(SYSTEMTIME time)
- {
- char tBuf[1024] = "";
- //sprintf(tBuf, "%04u-%02u-%02u %02u:%02u:%02u:%03u", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
- sprintf(tBuf, "%04u-%02u-%02u %02u:%02u:%02u", time.wYear, time.wMonth, time.wDay, time.wHour, time.wMinute, time.wSecond);
- return tBuf;
- }
- std::string CModTools::GetSpShellNextRebootTime()
- {
- static std::string shellBootTime;
- if (0 == shellBootTime.length())
- {
- CAutoArray<CSimpleStringA> t_names;
- CAutoArray<int> t_Idx;
- CAutoArray<CEntityStartInfo> t_Infos;
- this->m_pEntity->GetFunction()->GetAllEntityStartInfo(t_names, t_Idx, t_Infos);
- for (int i = 0; i < t_Infos.GetCount(); i++) {
- //if (0 == t_Idx[i])//shell
- if (t_names[i].Compare("HealthManager") == 0) {
- SYSTEMTIME startTime = t_Infos[i].startTime;
- CSmallDateTime dateTime;
- dateTime.FromSystemTime(startTime);
- /** 十分钟后重启 [Gifur@2022324]*/
- CSmallDateTime dateNewTime((DWORD)dateTime + 10 * 60);
- shellBootTime = dateNewTime.ToTimeString().GetData();
- #if defined(RVC_OS_LINUX)
- SP::Utility::replaceInPlace(shellBootTime, " ", "-");
- #endif //RVC_OS_LINUX
- break;
- }
- }
- }
- return shellBootTime;
- }
- void CModTools::setLimitReason(const char* reason) {
- CSimpleStringA m_strLimitReason = reason;
- if (m_strLimitReason.Compare("breakdown") != 0 && !m_strLimitReason.IsNullOrEmpty())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("reason:%d, setState:%s", reason, "L");
- this->m_pEntity->GetFunction()->SetSysVar("TradeManageState", "L", true);
- }
- if (m_strLimitReason.Compare("breakdown") == 0) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("reason:%d, no setState", reason);
- }
- if (m_strLimitReason.IsNullOrEmpty())
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("reason:%d, setState:%s", reason, "T");
- this->m_pEntity->GetFunction()->SetSysVar("TradeManageState", "T", true);
- }
- }
- void CModTools::stopCommonPage(std::string name)
- {
- #if defined(_MSC_VER)
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --kill");
- strCmdLine.Append(" --logextend=").Append(name.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("stopCommonPage cmdline:%s", strCmdLine.GetData());
- SYSTEM_ON(strCmdLine.GetData());
- #endif //_MSC_VER
- }
- /** 这个接口将移除,信创不再使用CEFClient [Gifur@2023626]*/
- void CModTools::StopChromiumBrowser(ERR_PAGE_REASON reason, bool stopAll)
- {
- #if defined(_MSC_VER)
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --kill");
- if (!stopAll)
- strCmdLine.Append(" --logextend=").Append(reason._to_string());
- if (reason._to_integral() == ERR_PAGE_REASON::main)
- m_isGuardMainBrowser = false;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopChromiumBrowser cmdline:%s, current guardian main browser : %d", strCmdLine.GetData(), m_isGuardMainBrowser);
- SYSTEM_ON(strCmdLine.GetData());
- if (reason._to_integral() == ERR_PAGE_REASON::breakdown || reason._to_integral() == ERR_PAGE_REASON::warnPrompt || reason._to_integral() == ERR_PAGE_REASON::audioErr)
- breakdownExist = false;
- if (reason._to_integral() == ERR_PAGE_REASON::ErrNotify)
- notifyExist = false;
- if (stopAll)
- breakdownExist = notifyExist = m_isAdOpen = false;
- #else
- if (stopAll)
- killAllChromium();
- else
- LogWarn(Severity_Low, Error_NotSupport, LOG_WARN_CHROMIUM_NOT_SUPPORT_TOKILL_SPECIFIED_BROWSER,
- CSimpleStringA::Format("StopChromiumBrowser: %s", reason._to_string()));
- #endif //_MSC_VER
- }
- void CModTools::StopChromiumBrowser_security(ERR_PAGE_REASON reason, int times)
- {
- for (int i = 0; i < times; )
- {
- StopChromiumBrowser(reason, false);
- i++;
- if(i < times)
- std::this_thread::sleep_for(std::chrono::seconds(2));
- }
- }
- /** 这个接口将移除,信创不再使用CEFClient [Gifur@2023626]*/
- void CModTools::StopSingleChromiumBrowserByName(std::string cefName)
- {
- #if defined(_MSC_VER)
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --kill");
- strCmdLine.Append(" --logextend=").Append(cefName.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopChromiumBrowser cmdline:%s, current guardian main browser : %d", strCmdLine.GetData(), m_isGuardMainBrowser);
- SYSTEM_ON(strCmdLine.GetData());
- #else
- LogWarn(Severity_Low, Error_NotSupport, LOG_WARN_CHROMIUM_NOT_SUPPORT_TOKILL_SPECIFIED_BROWSER,
- CSimpleStringA::Format("StopSingleChromiumBrowserByName: %s", cefName.c_str()));
- #endif //_MSC_VER
- }
- std::pair<bool, std::string> CModTools::getMainUrl()
- {
- CSimpleStringA strUrl;
- bool isOpenExtend = false;
- auto mainUrl = ConfigManager::getInstance().m_UserMgrUrlFultureStr;
- //strUrl = detectUrls(mainUrl.GetData()).c_str();
- strUrl = mainUrl;
- isOpenExtend = false;
- return std::make_pair(isOpenExtend, strUrl.GetData());
- }
- std::pair<bool, std::string> CModTools::getExtendUrl()
- {
- CSimpleStringA strUrl;
- if (ConfigManager::getInstance().m_UserMgrUrlNoSidebarStr.Compare(""))
- {
- auto mainUrl = ConfigManager::getInstance().m_UserMgrUrlNoSidebarStr;
- auto exUrl = ConfigManager::getInstance().m_UserMgrUrlNoSidebarMutiStr;
- auto t_Arr = exUrl.Split('|');
- std::vector<std::string> urlArr;
- urlArr.emplace_back(mainUrl.GetData());
- for (int i = 0; i < t_Arr.GetCount(); i++)
- urlArr.emplace_back(t_Arr[i].GetData());
- auto checkRet = DetectActiveHttp(urlArr);
- if (checkRet.first)
- strUrl = checkRet.second.c_str();
- else
- strUrl = mainUrl;
- }
- else
- strUrl = ConfigManager::getInstance().m_UserMgrUrlStr;
- return std::make_pair(strUrl.GetLength() > 0, strUrl.GetData());
- }
- std::string CModTools::generateAdCmd(std::string AdUrl) {
- #if defined(RVC_OS_LINUX)
- return generateBrowserCMDForEverything(AdUrl, 1, ConfigManager::getInstance().m_withUnsafeAd);
- #else
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --url=").Append(AdUrl.c_str());
- if (ConfigManager::getInstance().m_extension_debugOpen)
- strCmdLine.Append(" --right-menu");
- if (ConfigManager::getInstance().m_extension_withTerminal && ConfigManager::getInstance().m_extension_headerStr.length() > 0)
- strCmdLine.Append(" --modify-header=").Append(ConfigManager::getInstance().m_extension_headerStr.c_str());
- CSimpleStringA cachePath;
- this->m_pEntity->GetFunction()->GetPath("Temp", cachePath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("cefCache_").
- Append(ConfigManager::getInstance().m_strCacheHead.length() > 0 ? ConfigManager::getInstance().m_strCacheHead.c_str() : "").Append((+ERR_PAGE_REASON::Ad)._to_string());
- strCmdLine.Append(" --cache-path=").Append(cachePath);
- if (ConfigManager::getInstance().isUseMagic())
- strCmdLine.Append(" --magic-str=").Append(m_magicStr.c_str());
- if (ConfigManager::getInstance().m_withMedia)
- strCmdLine.Append(" --enable-media-stream=1 --enable-speech-input=1");
- if (ConfigManager::getInstance().m_withConsole)
- strCmdLine.Append(" --with-console");
- if (ConfigManager::getInstance().getSogouForce() != 0)
- strCmdLine.Append(" --adapt-sogou=").Append(std::to_string(ConfigManager::getInstance().getSogouForce()).c_str());
- strCmdLine.Append(" --no-sandbox").Append(" --hide-controls --hide-overlays --hide-frame --winhttp-proxy-resolver");
- strCmdLine.Append(" --logextend=").Append((+PAGE_TYPE::Ad)._to_string());
- strCmdLine.Append(" --top=-1");
- strCmdLine.Append(" --run-extend");
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("cmdline : %s", strCmdLine.GetData());
- return strCmdLine.GetData();
- #endif //RVC_OS_LINUX
- }
- #if defined(RVC_OS_WIN)
- std::string CModTools::generateCefclientCmd(bool isExtend, std::string mainUrl)
- {
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --url=").Append(mainUrl.c_str());
- if (ConfigManager::getInstance().m_withUnsafeMain)
- strCmdLine.Append(" --allow-running-insecure-content");
- if (ConfigManager::getInstance().m_extension_debugOpen)
- strCmdLine.Append(" --right-menu");
- if (ConfigManager::getInstance().m_extension_withTerminal && ConfigManager::getInstance().m_extension_headerStr.length() > 0)
- strCmdLine.Append(" --modify-header=").Append(ConfigManager::getInstance().m_extension_headerStr.c_str());
- if (isExtend) {
- //not support
- }
- CSimpleStringA cachePath;
- this->m_pEntity->GetFunction()->GetPath("Temp", cachePath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("cefCache_").
- Append(ConfigManager::getInstance().m_strCacheHead.length() > 0 ? ConfigManager::getInstance().m_strCacheHead.c_str() : "")
- .Append(isExtend ? (+ERR_PAGE_REASON::extend)._to_string() : (+ERR_PAGE_REASON::main)._to_string());
- //strCmdLine.Append(" --hide-controls=true")
- strCmdLine.Append(" --cache-path=").Append(cachePath);
- strCmdLine.Append(" --no-sandbox").Append(" --hide-controls --hide-overlays --hide-frame --winhttp-proxy-resolver --hide-tabs");
- if (ConfigManager::getInstance().isUseMagic())
- strCmdLine.Append(" --magic-str=").Append(m_magicStr.c_str());
- if (ConfigManager::getInstance().m_withMedia)
- strCmdLine.Append(" --enable-media-stream=1 --enable-speech-input=1");
- if (ConfigManager::getInstance().m_withConsole)
- strCmdLine.Append(" --with-console");
- if (ConfigManager::getInstance().getSogouForce() != 0)
- strCmdLine.Append(" --adapt-sogou=").Append(std::to_string(ConfigManager::getInstance().getSogouForce()).c_str());
- if (ConfigManager::getInstance().m_withDebugMode)
- strCmdLine.Append(" --remote-debugging-port=9222");
- if (isExtend) {
- strCmdLine.Append(" --logextend=").Append((+PAGE_TYPE::extend)._to_string());
- } else
- strCmdLine.Append(" --logextend=").Append((+PAGE_TYPE::slv)._to_string());
- strCmdLine.Append(" --errurl=file:\/\/\/").Append(getErrUrl(ERR_PAGE_REASON::main).second.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("cmdline : %s", strCmdLine.GetData());
- return strCmdLine.GetData();
- }
- #endif //RVC_OS_WIN
- std::string CModTools::generateMainCmd(std::string mainUrl)
- {
- #if defined(_MSC_VER)
- return generateCefclientCmd(false, mainUrl);
- #else
- return generateBrowserCMDForEverything(mainUrl, 0, ConfigManager::getInstance().m_withUnsafeMain);
- #endif //_MSC_VER
- }
- std::string CModTools::generateInstallCmd(std::string installUrl)
- {
- #if defined(RVC_OS_LINUX)
- return generateBrowserCMDForEverything(installUrl, 0, false);
- #else
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --url=").Append(installUrl.c_str());
- if (ConfigManager::getInstance().m_extension_debugOpen)
- strCmdLine.Append(" --right-menu");
- if (ConfigManager::getInstance().m_extension_withTerminal && ConfigManager::getInstance().m_extension_headerStr.length() > 0)
- strCmdLine.Append(" --modify-header=").Append(ConfigManager::getInstance().m_extension_headerStr.c_str());
- CSimpleStringA cachePath;
- this->m_pEntity->GetFunction()->GetPath("Temp", cachePath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("cefCache_").
- Append(ConfigManager::getInstance().m_strCacheHead.length() > 0 ? ConfigManager::getInstance().m_strCacheHead.c_str() : "").
- Append((+ERR_PAGE_REASON::Ad)._to_string());
- strCmdLine.Append(" --cache-path=").Append(cachePath);
- strCmdLine.Append(" --no-sandbox").Append(" --hide-controls --hide-overlays --hide-frame --winhttp-proxy-resolver --hide-tabs");
- strCmdLine.Append(" --lang=zh-CN");//install page need language chinese
- strCmdLine.Append(" --logextend=").Append((+PAGE_TYPE::Install)._to_string());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("cmdline : %s", strCmdLine.GetData());
- return strCmdLine.GetData();
- #endif //RVC_OS_LINUX
- }
- bool startsWithHttpCaseInsensitive(std::string url) {
- std::transform(url.begin(), url.end(), url.begin(), ::tolower);
- return url.find("http") == 0;
- }
- std::string CModTools::generateCommonPage(std::string url, std::string name, int width, int height, int point_x, int point_y, int top)
- {
- #if defined(RVC_OS_LINUX)
- std::string dstUrl = url;
- CSimpleStringA strBasePath(true);
- this->m_pEntity->GetFunction()->GetPath("BaseDir", strBasePath);
- std::string strPath(strBasePath.GetData());
- const std::string execute_newbrowser_path = strPath + SPLIT_SLASH_STR + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR + "startBrower.sh";
- const std::string execute_oldbrowser_path = strPath + SPLIT_SLASH_STR + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR + "startUOSBrower.sh";
- CSimpleStringA strParams(true);
- if (width > 0 && height > 0)
- strParams.Append(" --window-size=").Append(std::to_string(width).c_str()).Append(",").Append(std::to_string(height).c_str());
-
- do
- {
- if (point_x != -1 && point_y != -1)
- {
- strParams.Append(" --window-position=").Append(std::to_string(point_x).c_str()).Append(",").Append(std::to_string(point_y).c_str());
- break;
- }
- if (SDL_Init(SDL_INIT_VIDEO) < 0) {
- break;
- }
- SDL_DisplayMode mode;
- if (SDL_GetDesktopDisplayMode(0, &mode) != 0) {
- // 错误处理
- SDL_Quit();
- break;
- }
- // 获取屏幕的宽度和高度
- int screen_width = mode.w;
- int screen_height = mode.h;
- SDL_Quit();
- point_x = (screen_width - width) / 2;
- point_y = (screen_height - height) / 2;
- strParams.Append(" --window-position=").Append(std::to_string(point_x).c_str()).Append(",").Append(std::to_string(point_y).c_str());
- } while (false);
-
- //旧版浏览器(系统自带)
- if (m_UseUOSBrowser == 1) {
- CSimpleStringA strUOSBrowserPath(execute_oldbrowser_path.c_str());
- strParams.Append(" --new-window --no-first-run --disable-popup-blocking --disable-notifications --disable-desktop-notifications ");
- if (ConfigManager::getInstance().m_extension_withTerminal)
- {
- strParams.Append(" --load-extension=").Append(ConfigManager::getInstance().m_extensionPath.c_str());
- if (startsWithHttpCaseInsensitive(url))
- {
- auto redirctUrlRet = getErrUrl(ERR_PAGE_REASON::redirect);
- dstUrl = "\"file:///" + redirctUrlRet.second + "?redirect_open=" + url + "&redirect_type=" + name + "\"";
- }
- }
- strParams.Append(" --allow-running-insecure-content --disable-infobars --disable-suggestions-service --disable-save-password-bubble --disable-component-update");
-
-
- CSimpleStringA tempPath;
- this->m_pEntity->GetFunction()->GetPath("Temp", tempPath);
- CSimpleStringA cachePath(tempPath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowser_").Append(name.c_str());
- strParams.Append(" --disk-cache-dir=").Append(cachePath);
- strParams.Append(" --disk-cache-size=").Append("2147483647"); //2G
- if (ConfigManager::getInstance().m_withMedia)
- strParams.Append(" --use-fake-ui-for-media-stream");
- CSimpleStringA usrDataPath(tempPath);
- usrDataPath.Append(SPLIT_SLASH_STR).Append("UOSBrowserConfig_").Append(name.c_str());
- strParams.Append(" --user-data-dir=").Append(usrDataPath);
- CSimpleStringA debug_log_path = usrDataPath + "/chrome_debug.log";
- if (ConfigManager::getInstance().m_withDebugMode)
- strParams.Append(" --enable-logging --vmodule=*/webrtc/*=2,*/media/*=2 --log-file=").Append(debug_log_path);
- strParams.Append(" --app=").Append(dstUrl.c_str());
- strUOSBrowserPath.Append(strParams);
- return strUOSBrowserPath.GetData();
- }
- //新版浏览器
- if (m_UseUOSBrowser == 2) {
- CSimpleStringA strUOSBrowserPath(execute_newbrowser_path.c_str());
- strParams.Append(" --allow-running-insecure-content --new-window");
- if (ConfigManager::getInstance().m_extension_withTerminal)
- {
- strParams.Append(" --load-extension=").Append(ConfigManager::getInstance().m_extensionPath.c_str());
- if (startsWithHttpCaseInsensitive(url))
- {
- auto redirctUrlRet = getErrUrl(ERR_PAGE_REASON::redirect);
- dstUrl = "\"file:///" + redirctUrlRet.second + "?redirect_open=" + url + "&redirect_type=" + name + "\"";
- }
- }
- CSimpleStringA tempPath;
- this->m_pEntity->GetFunction()->GetPath("Temp", tempPath);
- CSimpleStringA cachePath(tempPath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("Browser_").Append(name.c_str());
- strParams.Append(" --disk-cache-dir=").Append(cachePath);
- strParams.Append(" --disk-cache-size=").Append("2147483647"); //2G
- if (ConfigManager::getInstance().m_withMedia)
- strParams.Append(" --use-fake-ui-for-media-stream");
- CSimpleStringA usrDataPath(tempPath);
- usrDataPath.Append(SPLIT_SLASH_STR).Append("BrowserConfig_").Append(name.c_str());
- strParams.Append(" --user-data-dir=").Append(usrDataPath);
- CSimpleStringA debug_log_path = usrDataPath + "/chrome_debug.log";
- if (ConfigManager::getInstance().m_withDebugMode)
- strParams.Append(" --enable-logging --vmodule=*/webrtc/*=2,*/media/*=2 --log-file=").Append(debug_log_path);
- strParams.Append(" --app=").Append(dstUrl.c_str());
- strUOSBrowserPath.Append(strParams);
- return strUOSBrowserPath.GetData();
- }
- return std::string("");
- #else
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --url=").Append(url.c_str());
- if (ConfigManager::getInstance().m_extension_debugOpen)
- strCmdLine.Append(" --right-menu");
- if (ConfigManager::getInstance().m_extension_withTerminal && ConfigManager::getInstance().m_extension_headerStr.length() > 0)
- strCmdLine.Append(" --modify-header=").Append(ConfigManager::getInstance().m_extension_headerStr.c_str());
- if (width > 0 && height > 0)
- strCmdLine.Append(" --center-size=").Append(std::to_string(width).c_str()).Append("*").Append(std::to_string(height).c_str());
- if (point_x != -1 && point_y != -1)
- {
- strCmdLine.Append(" --src-pos=").Append(std::to_string(point_x).c_str()).Append("*").Append(std::to_string(point_y).c_str());
- }
- CSimpleStringA cachePath;
- this->m_pEntity->GetFunction()->GetPath("Temp", cachePath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("cefCache_").
- Append(ConfigManager::getInstance().m_strCacheHead.length() > 0 ? ConfigManager::getInstance().m_strCacheHead.c_str() : "").Append(name.c_str());
- strCmdLine.Append(" --cache-path=").Append(cachePath);
- strCmdLine.Append(" --no-sandbox").Append(" --hide-controls --hide-overlays --hide-frame --winhttp-proxy-resolver --hide-tabs");
- strCmdLine.Append(" --lang=zh-CN");//install page need language chinese
- strCmdLine.Append(" --logextend=").Append(name.c_str());
- strCmdLine.Append(" --top=").Append(std::to_string(top).c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s cmdline : %s", name.c_str(), strCmdLine.GetData());
- return strCmdLine.GetData();
- #endif
- }
- std::string CModTools::generateSpecialPageFromOtherEntityCmd(std::string mainUrl)
- {
- #if defined(RVC_OS_WIN)
- CSimpleStringA cachePath;
- CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
- strCmdLine.Append(strChromiumPath).Append(" --url=").Append(mainUrl.c_str());
- if (ConfigManager::getInstance().m_extension_debugOpen)
- strCmdLine.Append(" --right-menu");
- if (ConfigManager::getInstance().m_extension_withTerminal && ConfigManager::getInstance().m_extension_headerStr.length() > 0)
- strCmdLine.Append(" --modify-header=").Append(ConfigManager::getInstance().m_extension_headerStr.c_str());
- this->m_pEntity->GetFunction()->GetPath("Temp", cachePath);
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("cefCache_").
- Append(ConfigManager::getInstance().m_strCacheHead.length() > 0 ? ConfigManager::getInstance().m_strCacheHead.c_str() : "").
- Append(m_specialPage_temp_name.c_str());
- //strCmdLine.Append(" --hide-controls=true")
- strCmdLine.Append(" --cache-path=").Append(cachePath);
- strCmdLine.Append(" --no-sandbox").Append(" --hide-controls --hide-overlays --hide-frame --winhttp-proxy-resolver --hide-tabs");;//don't use single-process, it will affect the cef log
- if (ConfigManager::getInstance().isUseMagic())
- strCmdLine.Append(" --magic-str=").Append(m_magicStr.c_str());
- if (ConfigManager::getInstance().m_withMedia)
- strCmdLine.Append(" --enable-media-stream=1 --enable-speech-input=1");
- if (ConfigManager::getInstance().m_withConsole)
- strCmdLine.Append(" --with-console");
- if (ConfigManager::getInstance().getSogouForce() != 0)
- strCmdLine.Append(" --adapt-sogou=").Append(std::to_string(ConfigManager::getInstance().getSogouForce()).c_str());
- strCmdLine.Append(" --logextend=").Append(m_specialPage_temp_name.c_str());
- if (m_specialPage_temp_size.length() > 0)
- strCmdLine.Append(" --center-size=").Append(m_specialPage_temp_size.c_str());
- if (m_specialPage_temp_point.length() > 0)
- strCmdLine.Append(" --src-pos=").Append(m_specialPage_temp_point.c_str());
- strCmdLine.Append(" --top=").Append(std::to_string((unsigned long long)m_specialPage_temp_top).c_str());
- strCmdLine.Append(" --errurl=file:\/\/\/").Append(getErrUrl(ERR_PAGE_REASON::main).second.c_str());
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("cmdline : %s", strCmdLine.GetData());
- return strCmdLine.GetData();
- #else
- return generateBrowserCMDForEverything(mainUrl, 3, false);
- #endif //RVC_OS_WIN
- }
- #if defined(RVC_OS_LINUX)
- std::string CModTools::generateBrowserCMDForEverything(const std::string& url, int pageType, bool ignoreSecurity)
- {
- std::string dstUrl = url;
- CSimpleStringA strBasePath(true);
- this->m_pEntity->GetFunction()->GetPath("BaseDir", strBasePath);
- std::string strPath(strBasePath.GetData());
- const std::string execute_newbrowser_path = strPath + SPLIT_SLASH_STR + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR + "startBrower.sh";
- const std::string execute_oldbrowser_path = strPath + SPLIT_SLASH_STR + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR + "startUOSBrower.sh";
- std::string name = "";
- if (pageType == 0 || pageType == 2 || pageType == 3) {
- name = (+ERR_PAGE_REASON::main)._to_string();
- }
- else if (pageType == 1) {
- name = (+ERR_PAGE_REASON::Ad)._to_string();
- }
- else if (pageType == 2) {
- name = (+ERR_PAGE_REASON::breakdown)._to_string();
- }
- else if (pageType == 3) {
- name = (+ERR_PAGE_REASON::OutsideRequest)._to_string();
- }
- auto getUnsafeDomain = [](const std::string& url)
- {
- // 移除协议部分
- std::string::size_type pos = url.find("://");
- if (pos != std::string::npos) {
- pos += 3;
- }
- else {
- pos = 0;
- }
- // 查找域名结束位置
- std::string::size_type endPos = url.find('/', pos);
- if (endPos == std::string::npos) {
- endPos = url.length();
- }
- // 提取域名
- std::string domain = url.substr(pos, endPos - pos);
- domain = "http://" + domain;
- return domain;
- };
- //旧版浏览器(系统自带)
- if (m_UseUOSBrowser == 1) {
- CSimpleStringA strUOSBrowserPath(execute_oldbrowser_path.c_str());
- CSimpleStringA strParams(" --new-window --no-first-run --disable-popup-blocking --disable-notifications --disable-desktop-notifications --allow-running-insecure-content --disable-infobars --disable-suggestions-service --disable-save-password-bubble --disable-component-update");
- if (!ConfigManager::getInstance().m_extension_debugOpen)
- strParams.Append(" --kiosk");
- if (ConfigManager::getInstance().m_extension_withTerminal)
- {
- strParams.Append(" --load-extension=").Append(ConfigManager::getInstance().m_extensionPath.c_str());
- if (startsWithHttpCaseInsensitive(url))
- {
- auto redirctUrlRet = getErrUrl(ERR_PAGE_REASON::redirect);
- dstUrl = "\"file:///" + redirctUrlRet.second + "?redirect_open=" + url + "&redirect_type=" + name + "\"";
- }
- }
- if (pageType == 0 || pageType == 2 || pageType == 3) {
- } else if (pageType == 1) {
- strParams.Append(" --window-position=1280,1024");
- }
- CSimpleStringA tempPath;
- this->m_pEntity->GetFunction()->GetPath("Temp", tempPath);
- CSimpleStringA cachePath(tempPath);
- if (pageType == 0 || pageType == 2 || pageType == 3) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserMain_").Append((+ERR_PAGE_REASON::main)._to_string());
- } else if (pageType == 1) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserVice_").Append((+ERR_PAGE_REASON::Ad)._to_string());
- } else if (pageType == 2) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserMain_").Append((+ERR_PAGE_REASON::breakdown)._to_string());
- } else if (pageType == 3) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserMain_").Append((+ERR_PAGE_REASON::OutsideRequest)._to_string());
- }
- strParams.Append(" --disk-cache-dir=").Append(cachePath);
- strParams.Append(" --disk-cache-size=").Append("2147483647"); //2G
- if (ConfigManager::getInstance().m_withMedia)
- {
- strParams.Append(" --use-fake-ui-for-media-stream");
- }
- if (ignoreSecurity)
- {
- auto unsafeDomain = getUnsafeDomain(url);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("srcurl:%s, unsafeDomain:%s", url.c_str(), unsafeDomain.c_str());
- strParams.Append(" --unsafely-treat-insecure-origin-as-secure=").Append(unsafeDomain.c_str());
- }
- CSimpleStringA usrDataPath(tempPath);
- if (pageType == 0) {
- usrDataPath.Append(SPLIT_SLASH_STR).Append("UOSBrowserConfigMain_").Append((+ERR_PAGE_REASON::main)._to_string());
- } else if (pageType == 1) {
- usrDataPath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserConfigVice_").Append((+ERR_PAGE_REASON::Ad)._to_string());
- } else if (pageType == 2) {
- usrDataPath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserConfigMain_").Append((+ERR_PAGE_REASON::breakdown)._to_string());
- } else if (pageType == 3) {
- usrDataPath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("UOSBrowserConfigMain_").Append((+ERR_PAGE_REASON::OutsideRequest)._to_string());
- }
- strParams.Append(" --user-data-dir=").Append(usrDataPath);
- CSimpleStringA debug_log_path = usrDataPath + "/chrome_debug.log";
- if (ConfigManager::getInstance().m_withDebugMode)
- strParams.Append(" --enable-logging --vmodule=*/webrtc/*=2,*/media/*=2 --log-file=").Append(debug_log_path);
- strParams.Append(" ");
- strParams.Append(dstUrl.c_str());
- strUOSBrowserPath.Append(strParams);
- if (pageType == 0) {
- LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_CHROMIUM_OPEN_MAIN_WITH_UOS, strUOSBrowserPath);
- } else if (pageType == 1) {
- LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_CHROMIUM_OPEN_AD_WITH_UOS, strUOSBrowserPath);
- }
- return strUOSBrowserPath.GetData();
- }
- //新版浏览器
- if (m_UseUOSBrowser == 2) {
- CSimpleStringA strUOSBrowserPath(execute_newbrowser_path.c_str());
- CSimpleStringA strParams(" --allow-running-insecure-content --new-window");
- if (!ConfigManager::getInstance().m_extension_debugOpen)
- strParams.Append(" --kiosk");
- if (ConfigManager::getInstance().m_extension_withTerminal)
- {
- strParams.Append(" --load-extension=").Append(ConfigManager::getInstance().m_extensionPath.c_str());
- if (startsWithHttpCaseInsensitive(url))
- {
- auto redirctUrlRet = getErrUrl(ERR_PAGE_REASON::redirect);
- dstUrl = "\"file:///" + redirctUrlRet.second + "?redirect_open=" + url + "&redirect_type=" + name + "\"";
- }
- }
- if (pageType == 0 || pageType == 2 || pageType == 3) {
- } else if (pageType == 1) {
- strParams.Append(" --window-position=1280,1024");
- }
- CSimpleStringA tempPath;
- this->m_pEntity->GetFunction()->GetPath("Temp", tempPath);
- CSimpleStringA cachePath(tempPath);
- if (pageType == 0) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserMain_").Append((+ERR_PAGE_REASON::main)._to_string());
- } else if (pageType == 1) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserVice_").Append((+ERR_PAGE_REASON::Ad)._to_string());
- } else if (pageType == 2) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserMain_").Append((+ERR_PAGE_REASON::breakdown)._to_string());
- } else if (pageType == 3) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserMain_").Append((+ERR_PAGE_REASON::OutsideRequest)._to_string());
- }
- strParams.Append(" --disk-cache-dir=").Append(cachePath);
- strParams.Append(" --disk-cache-size=").Append("2147483647"); //2G
- if (ConfigManager::getInstance().m_withMedia)
- {
- strParams.Append(" --use-fake-ui-for-media-stream");
- }
- if (ignoreSecurity)
- {
- auto unsafeDomain = getUnsafeDomain(url);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("srcurl:%s, unsafeDomain:%s", url.c_str(), unsafeDomain.c_str());
- strParams.Append(" --unsafely-treat-insecure-origin-as-secure=").Append(unsafeDomain.c_str());
- }
- CSimpleStringA usrDataPath(tempPath);
- if (pageType == 0) {
- usrDataPath.Append(SPLIT_SLASH_STR).Append("BrowserConfigMain_").Append((+ERR_PAGE_REASON::main)._to_string());
- } else if (pageType == 1) {
- usrDataPath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserConfigVice_").Append((+ERR_PAGE_REASON::Ad)._to_string());
- } else if (pageType == 2) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserConfigMain_").Append((+ERR_PAGE_REASON::breakdown)._to_string());
- } else if (pageType == 3) {
- cachePath.Append(CSimpleStringA(SPLIT_SLASH_STR)).Append("BrowserConfigMain_").Append((+ERR_PAGE_REASON::OutsideRequest)._to_string());
- }
- strParams.Append(" --user-data-dir=").Append(usrDataPath);
- CSimpleStringA debug_log_path = usrDataPath + "/chrome_debug.log";
- if (ConfigManager::getInstance().m_withDebugMode)
- strParams.Append(" --enable-logging --vmodule=*/webrtc/*=2,*/media/*=2 --log-file=").Append(debug_log_path);
- strParams.Append(" ");
- strParams.Append(dstUrl.c_str());
- strUOSBrowserPath.Append(strParams);
- if (pageType == 0) {
- LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_CHROMIUM_OPEN_MAIN_WITH_UOSV2, strUOSBrowserPath);
- } else if (pageType == 1) {
- LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_CHROMIUM_OPEN_AD_WITH_UOSV2, strUOSBrowserPath);
- }
- return strUOSBrowserPath.GetData();
- }
- return std::string("");
- }
- #endif //RVC_OS_LINUX
- std::pair<bool, std::string> CModTools::openAdPage()
- {
- if (m_isAdOpen)//only open ad in first time
- return std::make_pair(false, "open AdPage failed! Already exist.");
- auto AdUrlRet = getAdUrl();
- if (AdUrlRet.first)
- {
- auto strAdCmd = generateAdCmd(AdUrlRet.second);
- auto openAdRet = openCef(strAdCmd, (m_UseUOSBrowser == 0));
- if (Error_Succeed != openAdRet.first)
- return std::make_pair(false, "open Ad err!");
- else
- {
- m_isAdOpen = true;
- return std::make_pair(true, "");
- }
- }
- else
- return std::make_pair(false, "StartChromiumBrowser Ad url err!");
- }
- std::pair<ErrorCodeEnum, int> CModTools::StartChromiumBrowser(
- ERR_PAGE_REASON reason, std::tuple < std::string, std::string> normalParam
- , std::tuple<std::string, std::string, std::string, DWORD, DWORD> exParam) {
- g_mutexFreerdp.lock();
- std::shared_ptr<void> delHandleFun((void*)0, [&](void*) {
- g_mutexFreerdp.unlock();
- });
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("start browser %d, %s", reason._to_integral(), reason._to_string());
- if (reason._to_integral() == ERR_PAGE_REASON::main)
- {
- auto mainUrlRet = getMainUrl();
- if (0 == mainUrlRet.second.length())
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), 0, 2, "none", Error_Unexpect, "StartChromiumBrowser get url failed!");
- LogWarn(Severity_High, Error_Unexpect, LOG_EVT_CHROMIUM_DETECT_MAIN_URL_EMPTY,
- CSimpleStringA::Format("StartChromiumBrowser get %s url failed!", reason._to_string()));
- return std::make_pair(Error_Unexpect, 0);
- }
- auto strCmdLine = generateMainCmd(mainUrlRet.second);
- auto openCefRet = openCef(strCmdLine, (m_UseUOSBrowser == 0));//with guard
- if (Error_Succeed == openCefRet.first) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_CHROMIUM_OPEN_MAIN_URL,
- CSimpleStringA::Format("StartChromiumBrowser %s", mainUrlRet.second.c_str()));
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "open");
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)(CSimpleStringA::Format("StartChromiumBrowser %s", mainUrlRet.second.c_str()).GetData());
- /*
- #ifndef DEVOPS_ON_PRD
- LogEvent(Severity_High, LOG_EVT_CHROMIUM_OPEN_MAIN_URL, CSimpleStringA::Format("当前打开的业务链接:%s", mainUrlRet.second.c_str()));
- #endif
- */
- return std::make_pair(Error_Succeed, openCefRet.second);
- }
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::extend)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), 0, 2, "open", Error_Unexpect, "do not support freerdp");
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::Ad)
- {
- auto AdRet = openAdPage();
- if(AdRet.first)
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), 0, 0, "open");
- else
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), 0, 2, "none", Error_Unexpect, AdRet.second);
- return std::make_pair(AdRet.first ? Error_Succeed : Error_Unexpect, 0);
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::OutsideRequest) {
- #if defined(RVC_OS_WIN)
- auto strCmdLine = generateCefclientCmd(false, std::get<0>(normalParam));
- #else
- auto strCmdLine = generateBrowserCMDForEverything(std::get<0>(normalParam), 3, false);
- #endif //RVC_OS_WIN
- auto openCefRet = openCef(strCmdLine, false);
- if (Error_Succeed == openCefRet.first)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "open");
- return std::make_pair(Error_Succeed, openCefRet.second);
- }
- else
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "none", openCefRet.first, "");
- }
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::SpecialPageFromOtherEntity)
- {
- auto strCmdLine = generateSpecialPageFromOtherEntityCmd(std::get<0>(normalParam));
- auto openCefRet = openCef(strCmdLine, false);
- if (Error_Succeed == openCefRet.first)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "open");
- return std::make_pair(Error_Succeed, openCefRet.second);
- }
- else
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "none", openCefRet.first, "");
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::startup)
- {
- auto url = std::string(R"(file:///)") + getErrUrl(reason).second;
- #if defined(RVC_OS_WIN)
- auto strCmdline = generateCommonPage(url, (+ERR_PAGE_REASON::startup)._to_string(), 900, 600, -1, -1, (int)HWND_NOTOPMOST);
- #else
- auto strCmdline = generateCommonPage(url, (+ERR_PAGE_REASON::startup)._to_string(), 900, 650, -1, -1, (int)HWND_NOTOPMOST);
- #endif
- auto openCefRet = openCef(strCmdline, false);
- if (Error_Succeed == openCefRet.first)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "open");
- return std::make_pair(Error_Succeed, openCefRet.second);
- }
- else
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "none", openCefRet.first, "");
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::performance_monitor)
- {
- auto url = std::string(R"(file:///)") + getErrUrl(reason).second;
- auto strCmdline = generateCommonPage(url, (+ERR_PAGE_REASON::performance_monitor)._to_string(), 900, 600, -1, -1, (int)HWND_NOTOPMOST);
- auto openCefRet = openCef(strCmdline, false);
- if (Error_Succeed == openCefRet.first)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "open");
- return std::make_pair(Error_Succeed, openCefRet.second);
- }
- else
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "none", openCefRet.first, "");
- }
- else if (reason._to_integral() == ERR_PAGE_REASON::Install)
- {
- std::vector<std::string> installUrls;
- #ifdef DEVOPS_ON_ST /*DevOps流水线编译,ST环境*/
- installUrls.push_back("https://deviceinstallweb.paasst.cmbchina.cn/installRequire");
- #elif defined(DEVOPS_ON_UAT)/*DevOps流水线编译,UAT环境*/
- installUrls.push_back("https://deviceinstallweb.paasuat.cmbchina.cn/installRequire");
- #elif defined(DEVOPS_ON_PRD)/*DevOps流水线编译,PRD环境*/
- installUrls.push_back("https://deviceinstallweb.paas.cmbchina.cn/installRequire");
- #else/*本地编译等非DevOps环境编译的版本*/
- installUrls.push_back("https://deviceinstallweb.paasst.cmbchina.cn/installRequire");
- #endif
- auto checkRet = DetectActiveHttp(installUrls);
- if (!checkRet.first)
- {
- LogWarn(Severity_High, Error_NetBroken, LOG_WARN_CHROMIUM_INSTALL_URLS_CHECK,
- CSimpleString::Format("install page check err, can not connect to %s or %s", installUrls[0].c_str(), installUrls[1].c_str()).GetData());
- }
- std::string dstInstallUrl = checkRet.first ? checkRet.second : installUrls[0];
- CSimpleString runningVer = "";
- m_pEntity->GetFunction()->GetRunningVersion(runningVer);
- dstInstallUrl.append("?terminalVersion=").append(runningVer.GetData());
- #if defined(RVC_OS_LINUX)
- auto replaceAll = [](std::string& str, const std::string& search, const std::string& replace) {
- size_t pos = 0;
- while ((pos = str.find(search, pos)) != std::string::npos) {
- str.replace(pos, search.length(), replace);
- pos += replace.length();
- }
- };
- replaceAll(dstInstallUrl, "&", "\\&");
- #endif // RVC_OS_WIN
- auto strCmdLine = generateInstallCmd(dstInstallUrl);
- auto openCefRet = openCef(strCmdLine, false);
- if (Error_Succeed == openCefRet.first)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "open");
- return std::make_pair(Error_Succeed, openCefRet.second);
- }
- else
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), openCefRet.second, 0, "none", openCefRet.first, "");
- }
- else
- {
- //open err page
-
- if (notifyExist)
- return std::make_pair(Error_Duplication, 0);
- if ((ERR_PAGE_REASON::breakdown == reason._to_integral()
- || reason._to_integral() == ERR_PAGE_REASON::warnPrompt
- || reason._to_integral() == ERR_PAGE_REASON::audioErr) && breakdownExist)
- return std::make_pair(Error_Duplication, 0);//只打开一个breakdown页面,后续通过cefclient改动,避免打开同种页面
- auto errPageUrl = GenerateErrPage(reason, normalParam, exParam);
- if (!errPageUrl.first)
- {
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), 2, 0, "none", Error_Unexpect, "errPage get url failed!");
- return std::make_pair(Error_Unexpect, 0);
- }
- auto errPageRet = openCef(errPageUrl.second);
- if (Error_Succeed == errPageRet.first)
- {
- if (ERR_PAGE_REASON::ErrNotify == reason._to_integral())
- notifyExist = true;
- else if (ERR_PAGE_REASON::breakdown == reason._to_integral()
- || reason._to_integral() == ERR_PAGE_REASON::warnPrompt
- || reason._to_integral() == ERR_PAGE_REASON::audioErr)
- breakdownExist = true;
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), errPageRet.second, 0, "open");
- }
- else
- LogManager::getInstance().logEntityOpenPage(reason._to_string(), errPageRet.second, 0, "none", errPageRet.first, "");
- return std::make_pair(errPageRet.first, 0);
- }
- return std::make_pair(Error_Unexpect, 0);
- }
- std::pair<ErrorCodeEnum, int> CModTools::startCommonPage(std::string name, std::string url, int width, int height, int point_x, int point_y, std::string top)
- {
- CSimpleString topStr = top.c_str();
- int top_param = (int)HWND_NOTOPMOST;
- if (topStr.Compare("top", true) == 0)
- top_param = (int)HWND_TOP;
- else if (topStr.Compare("topmost", true) == 0)
- top_param = (int)HWND_TOPMOST;
- else if (topStr.Compare("notopmost", true) == 0)
- top_param = (int)HWND_NOTOPMOST;
- else if (topStr.Compare("bottom", true) == 0)
- top_param = (int)HWND_BOTTOM;
- auto strCmdline = generateCommonPage(url, name, width, height, point_x, point_y, top_param);
- auto openCefRet = openCef(strCmdline, false);
- if (Error_Succeed == openCefRet.first)
- return std::make_pair(Error_Succeed, openCefRet.second);
- else
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("open cef %s size:%d*%d at %d*%d in layer %s failed: %d"
- , name.c_str(), width, height, height, point_x, point_y, top.c_str(), openCefRet.first);
- return std::make_pair(openCefRet.first, openCefRet.first);
- }
- }
- void CModTools::cefClientGuardian(std::string cmdline)
- {
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("create thread:%s", __FUNCTION__);
- m_isGuardMainBrowser = true;
- while (m_isGuardMainBrowser)
- {
- try
- {
- #if (defined _WIN32 || defined _WIN64)
- auto startRet = startProcessInJob(cmdline, "");
- if (!std::get<0>(startRet))
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("cefClientGuardian startProcessInJob failed!");
- else
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("cefClientGuardian open cefclient pid:%d, cmd:%s", std::get<1>(startRet), cmdline.c_str());
- WaitForSingleObject(std::get<3>(startRet), INFINITE);
- boost::mutex::scoped_lock(m_guardInterruptLock);//必须保证unlock被执行,不然就会有问题
- #else
- boost::process::child child_process(cmdline);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("open cefclient pid:%d, cmd:%s", child_process.id(), cmdline.c_str());
- child_process.wait();
- #endif
- }
- catch (const std::exception& e)
- {
- std::cout << e.what() << std::endl;
- return;
- }
- catch (...)
- {
- return;
- }
- boost::this_thread::sleep_for(boost::chrono::seconds(3));
- }
- return;
- }
- // 输入为北京时间 输出为北京时间戳
- int CModTools::StandardToStamp(const char* str_time, bool dateOnly)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StandardToStamp str = %s", str_time);
- struct tm stm;
- int iY, iM, iD, iH, iMin, iS;
- // 检查有效性
- if ('-' != str_time[4] || '-' != str_time[7])
- {
- return 0;
- }
- memset(&stm, 0, sizeof(stm));
- iY = atoi(str_time);
- iM = atoi(str_time + 5);
- iD = atoi(str_time + 8);
- if (dateOnly)
- {
- iH = 0;
- iMin = 0;
- iS = 0;
- }
- else {
- iH = atoi(str_time + 11);
- iMin = atoi(str_time + 14);
- iS = atoi(str_time + 17);
- }
- stm.tm_year = iY - 1900;
- stm.tm_mon = iM - 1;
- stm.tm_mday = iD;
- stm.tm_hour = iH;
- stm.tm_min = iMin;
- stm.tm_sec = iS;
- /*printf("%d-%0d-%0d %0d:%0d:%0d\n", iY, iM, iD, iH, iMin, iS);*/ //标准时间格式例如:2016:08:02 12:12:30
- return (int)mktime(&stm);
- }
- bool CModTools::findRestartCode(DWORD userCode) {
- DWORD authArr_noretry_norestart[] = ERRARR_ACCESSAUTH_NORETRY_NORESTART;
- DWORD authArr_retry_norestart[] = ERRARR_ACCESSAUTH_RETRY_NORESTART;
- std::vector<DWORD> norestartArr;
- #if (defined _WIN32 || defined _WIN64)
- for each (auto i in authArr_noretry_norestart)
- #else
- for (auto i : authArr_noretry_norestart)
- #endif
- norestartArr.emplace_back(i);
- #if (defined _WIN32 || defined _WIN64)
- for each (auto i in authArr_retry_norestart)
- #else
- for (auto i : authArr_retry_norestart)
- #endif
- norestartArr.emplace_back(i);
- #if (defined _WIN32 || defined _WIN64)
- for each (auto i in norestartArr)
- #else
- for (auto i : norestartArr)
- #endif
- {
- if (userCode == i) {
- return false;
- }
- }
- return true;
- }
- DWORD CModTools::spiltErrMsg(std::string errMsg)
- {
- DWORD usercode = 0;
- CSimpleString m_sAuthErrMsg = errMsg.c_str();
- auto authArr = m_sAuthErrMsg.Split('|');
- if (authArr.GetCount() > 1)
- {
- auto ErrcodeStr = authArr[0];
- if (ErrcodeStr[0] == '0' && ErrcodeStr[1] == 'x')
- usercode = std::stoi(ErrcodeStr.GetData(), 0, 0);
- }
- return usercode;
- }
- bool CModTools::CheckTradeRecord() {
- std::list<int> timeList;
- using namespace Upload;
- UploadService_ClientBase* pClient = new UploadService_ClientBase(m_pEntity);
- auto rc = pClient->Connect();
- if (rc != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to Upload entity fail: %d", rc);
- pClient->SafeDelete();
- pClient = NULL;
- }
- else
- {
- UploadService_UploadDateList_Req req = {};
- UploadService_UploadDateList_Ans ans = {};
- rc = (*pClient)(EntityResource::getLink().upgradeLink())->UploadDateList(req, ans, 10000);
- if (rc != Error_Succeed)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("get CreateProcessRunAs fail from FreeRDPWrap: %d", rc);
- else
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("UploadDateList succeed from Upload");
- for (int i = 0; i < ans.uploadDateStr.GetCount(); ++i)
- {
- CSimpleStringA str = (CSimpleStringA)ans.uploadDateStr[i];
- int t = StandardToStamp(ans.uploadDateStr[i], true);
- timeList.emplace_back(t);
- }
- }
- pClient->GetFunction()->CloseSession();
- pClient = NULL;
- }
- // 比较时间戳 登记时间 <= 列表时间 < 今天 返回true
- time_t now = time(0);
- localtime(&now);
- now -= now % (3600 * 24);
- now -= 3600 * 8; //处理东八区问题
- CSmartPointer<IConfigInfo> spConfig;
- m_pEntity->GetFunction()->OpenConfig(Config_Run, spConfig);
- CSimpleStringA strLastRecordTime = "";
- ErrorCodeEnum errorRead = Error_Succeed;
- errorRead = spConfig->ReadConfigValue("Record", "LastRecordTime", strLastRecordTime);
- if (errorRead != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("Read Record LastRecordTime -> Failed! Maybe LastRecordTime not exist!");
- strLastRecordTime = "";
- }
- int timestamp_lastRecordTime = now;
- if (!strLastRecordTime.IsNullOrEmpty())
- {
- timestamp_lastRecordTime = StandardToStamp(strLastRecordTime, false);
- }
- for (std::list<int>::iterator it = timeList.begin(); it != timeList.end(); ++it)
- {
- if (timestamp_lastRecordTime <= *it && *it < now)
- {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CheckTradeRecord lastRecordTime=%d, time_list=%d, now=%d", timestamp_lastRecordTime, *it, now);
- return true;
- }
- }
- return false;
- }
- void CModTools::InitBrowserUseMode()
- {
- #if (defined _WIN32 || defined _WIN64)
- #else
- if (m_pEntity != nullptr) {
- CSmartPointer<IConfigInfo> spConfig;
- m_pEntity->GetFunction()->OpenConfig(Config_Cache, spConfig);
- CSimpleStringA value(true);
- spConfig->ReadConfigValue("BusinessBrowserType", "FultureEx", value);
- if (!(value.IsNullOrEmpty() || (value.Compare("1") != 0))) {
- m_UseUOSBrowser = 0;
- } else {
- m_UseUOSBrowser = ToGetUOSBrowserType();
- }
- } else {
- m_UseUOSBrowser = ToGetUOSBrowserType();
- }
- #endif
- }
- int CModTools::ToGetUOSBrowserType()
- {
- #if (defined _WIN32 || defined _WIN64)
- return 0;
- #else
- const std::string execute_newbrowser_path_check = "/usr/share/browser/browser";
- const std::string execute_oldbrowser_path_check = "/usr/share/uosbrowser/uosbrowser";
- CSimpleStringA strBasePath(true);
- this->m_pEntity->GetFunction()->GetPath("BaseDir", strBasePath);
- std::string strPath(strBasePath.GetData());
- const std::string execute_newbrowser_path = strPath + SPLIT_SLASH_STR + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR + "startBrower.sh";
- const std::string execute_oldbrowser_path = strPath + SPLIT_SLASH_STR + "res" + SPLIT_SLASH_STR + "RunScript" + SPLIT_SLASH_STR + "startUOSBrower.sh";
- int result(0);
- std::string additional("");
- std::string succStr, errStr;
- std::string runStr("dpkg -l | grep org.deepin.browser | awk '{print $3}'");
- if (SP::Module::Util::ShellExecute(runStr, succStr, errStr)) {
- if (succStr.empty()) {
- if (ExistsFileA(execute_oldbrowser_path_check.c_str())) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s exists!", execute_oldbrowser_path_check.c_str());
- result = 1;
- } else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s not exists!", execute_oldbrowser_path_check.c_str());
- }
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_CHROMIUM_BROWSER_LACK_OF_NEWONE, "have not installered new version UOS browser");
- } else {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("new browser version: %s", succStr.c_str());
- additional = succStr;
- if (!ExistsFileA(execute_newbrowser_path.c_str())) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("%s not exists!", execute_newbrowser_path.c_str());
- }
- result = 2;
- }
- } else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("execute '%s' failed!", runStr.c_str());
- }
- UploadBrowserInfo(result, additional.c_str());
- return result;
- #endif
- }
- void CModTools::UploadBrowserInfo(int usingType, LPCTSTR info)
- {
- CSmartPointer<IConfigInfo> spConfig;
- this->m_pEntity->GetFunction()->OpenConfig(Config_Run, spConfig);
- int oldType(0);
- CSimpleStringA strVersion;
- spConfig->ReadConfigValueInt("BrowserUse", "Type", oldType);
- spConfig->ReadConfigValue("BrowserUse", "Version", strVersion);
- if (oldType != usingType || strVersion.Compare(info) != 0) {
- LogWarn(Severity_Low, Error_Unexpect, LOG_EVT_CHROMIUM_BROWSER_USING_TYPE_CHANGE,
- CSimpleStringA::Format("{ \"type\":%d, \"version\":\"%s\"}", usingType, info));
- spConfig->WriteConfigValueInt("BrowserUse", "Type", usingType);
- spConfig->WriteConfigValue("BrowserUse", "Version", info);
- }
- }
- std::pair<ErrorCodeEnum, int> CModTools::openCef(std::string cmdline, bool isGuard, bool usingSystemCmd)
- {
- if (isGuard) {
- //mod_chromium相当于cefclient的守护进程
- boost::thread cefGuardian(boost::bind(&CModTools::cefClientGuardian, this, cmdline));
- cefGuardian.detach();
- }
- else
- {
- #if (defined _WIN32 || defined _WIN64)
- auto startRet = startProcessInJob(cmdline, "");
- if (!std::get<0>(startRet))
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("startProcessInJob failed!");
- return std::make_pair(std::get<0>(startRet) ? Error_Succeed : Error_Unexpect, std::get<1>(startRet));
- #else
- auto systemStartChromium = [](std::string str, bool systemCmd) {
- if (systemCmd) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("system(%s)", str.c_str());
- system(str.c_str());
- } else {
- SystemRunTest(str);
- }
- };
- boost::thread(systemStartChromium, cmdline, usingSystemCmd).detach();
- #endif
- }
- return std::make_pair(Error_Succeed, 0);
- }
- bool CModTools::RestartProxyServer() {
- // start tcp bridge service
- ErrorCodeEnum Error;
- CSmartPointer<IEntityFunction> spEntityFunction = this->m_pEntity->GetFunction();
- Error = spEntityFunction->StopTcpBridgeServer();
- if (Error != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("stop tcp bridge server failed! error = %d", Error);
- return false;
- }
-
- Error = spEntityFunction->StartTcpBridgeServer(4504);
- if (Error != Error_Succeed)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("start tcp bridge server failed! error = %d", Error);
- return false;
- }
-
- return true;
- }
- std::tuple<CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA, CSimpleStringA> CModTools::ReadCenterConfigStr(CSimpleStringA entityName) {
- CSimpleStringA str = "", strNew = "", strEx = "", strFulture = "", strAd = "", strCacheHead;
- bool forceCleanCache = false;
- CSmartPointer<IConfigInfo> spCerConfig;
- ErrorCodeEnum err = this->m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spCerConfig);
- if (entityName == "")
- entityName = this->m_pEntity->GetEntityName();
- SpIniMappingTable table;
- // clean cache every time
- table.AddEntryString(entityName, "UserMgrUrlFulture", strFulture, "");
- table.AddEntryString(entityName, "UserMgrAd", strAd, "");
- table.AddEntryString(entityName, "CacheHead", strCacheHead, "");
- if (Error_Succeed == table.Load(spCerConfig))
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)(CSimpleString::Format("read centersetting config : UserMgrUrlFulture-%s, UserMgrAd-%s", strFulture.GetData(), strAd.GetData()));
- CChromiumEntity* pChromiumEntity = reinterpret_cast<CChromiumEntity*>(m_pEntity);
- if (pChromiumEntity != nullptr && pChromiumEntity->HasCustomMainUrl()) {
- strFulture = pChromiumEntity->GetCustomMainUrl();
- CSimpleStringA strTmp = CSimpleStringA::Format("更新业务中台链接为:[%s]", strFulture.GetData());
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_CHROMIUM_USE_CUSTOM_FULTURE_URL, strTmp);
- }
- ConfigManager::getInstance().m_strCacheHead = strCacheHead.GetData();
- return std::make_tuple(str, strNew, strEx, strFulture, strAd);
- }
- }
|