|
@@ -7,7 +7,7 @@ using namespace FreeRDPWrap;
|
|
|
#include "CModTools.h"
|
|
|
#include "SpIni.h"
|
|
|
#include <vector>
|
|
|
-
|
|
|
+#include <list>
|
|
|
#include <memory>
|
|
|
#include <iostream>
|
|
|
#include <mutex>
|
|
@@ -16,10 +16,21 @@ using namespace FreeRDPWrap;
|
|
|
#include <boost/process.hpp>
|
|
|
#include <boost/thread.hpp>
|
|
|
|
|
|
+#include "../mod_upload/Upload_client_g.h"
|
|
|
+
|
|
|
|
|
|
|
|
|
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("sudo ").Append(basePath);
|
|
|
+ strChromiumPath.Append(CSimpleStringA(SPLIT_SLASH_STR) + "bin" + SPLIT_SLASH_STR + "Chromium" + SPLIT_SLASH_STR);
|
|
|
+ return strChromiumPath;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
auto detectUrls = [](std::string urls) -> std::string {
|
|
|
std::vector<std::string> urlArr;
|
|
|
urlArr.push_back(urls);
|
|
@@ -36,6 +47,25 @@ namespace Chromium{
|
|
|
|
|
|
void CModTools::InitCModTools(CEntityBase* pEntity){
|
|
|
this->m_pEntity = pEntity;
|
|
|
+
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_Root, spConfig);
|
|
|
+ if (Error == Error_Succeed)
|
|
|
+ {
|
|
|
+ Error = spConfig->ReadConfigValue("Terminal", "MachineType", m_strMachineType);
|
|
|
+ if (Error == Error_Succeed)
|
|
|
+ {
|
|
|
+ Error = spConfig->ReadConfigValue("Terminal", "Site", m_strSite);
|
|
|
+ if (Error != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("ReadConfigValue, get Site value failed");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dbg("ReadConfigValue, get MachineType value failed");
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -90,7 +120,7 @@ std::pair<bool, std::string> CModTools::getErrUrl()
|
|
|
std::pair<bool, std::string> CModTools::GenerateErrPage(ERR_PAGE_REASON errType)
|
|
|
{
|
|
|
auto errUrlRet = getErrUrl();
|
|
|
- CSimpleStringA errPagePath = errUrlRet.second.c_str();
|
|
|
+ CSimpleStringA errPagePath = errUrlRet.second.c_str(), strChromiumPath = GetCefHead(this->m_pEntity).Append(CEFCLIENT_NAME);
|
|
|
|
|
|
switch (errType)
|
|
|
{
|
|
@@ -109,7 +139,8 @@ std::pair<bool, std::string> CModTools::GenerateErrPage(ERR_PAGE_REASON errType)
|
|
|
this->m_pEntity->GetFunction()->GetSysVar("TerminalStage", ts);
|
|
|
auto rc = this->m_pEntity->GetFunction()->GetSysVar("AuthErrMsg", m_sAuthErrMsg);
|
|
|
Dbg("准入没过,展示交易暂停页面 TerminalStage=%c, AuthErrMsg=%s", ts[0], m_sAuthErrMsg);
|
|
|
- errPagePath.Append(CSimpleStringA("?reason=") + errType._to_string() + "&errmsg=" + m_sAuthErrMsg + "&reboottime=" + GetSpShellBootTime().c_str());
|
|
|
+ errPagePath.Append(CSimpleStringA("?reason=") + errType._to_string());// +"&errmsg=" + m_sAuthErrMsg + "&reboottime=" + GetSpShellBootTime().c_str());
|
|
|
+ errPagePath = CSimpleStringA("\'file:///") + errPagePath + CSimpleStringA("\'");
|
|
|
}
|
|
|
break;
|
|
|
case ERR_PAGE_REASON::CameraConfig:
|
|
@@ -137,16 +168,23 @@ std::pair<bool, std::string> CModTools::GenerateErrPage(ERR_PAGE_REASON errType)
|
|
|
case ERR_PAGE_REASON::TerminalManagerKickOut:
|
|
|
case ERR_PAGE_REASON::TerminalManagerOff:
|
|
|
errPagePath.Append(" --logextend=").Append((+PAGE_TYPE::TerminalManager)._to_string());
|
|
|
+ break;
|
|
|
case ERR_PAGE_REASON::CameraConfig:
|
|
|
errPagePath.Append(" --logextend=").Append((+PAGE_TYPE::CameraConfig)._to_string());
|
|
|
+ break;
|
|
|
+ case ERR_PAGE_REASON::disabled:
|
|
|
+ case ERR_PAGE_REASON::jobuncomplete:
|
|
|
+ errPagePath.Append(" --logextend=").Append((+PAGE_TYPE::TradeManager)._to_string());
|
|
|
+ break;
|
|
|
default:
|
|
|
errPagePath.Append(" --logextend=").Append((+PAGE_TYPE::errPage)._to_string());
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
+ CSimpleString dstCmd = strChromiumPath + " --url=" + errPagePath;
|
|
|
+ Dbg("GenerateErrPage type=%s, dstPage=%s", errType._to_string(), dstCmd.GetData());
|
|
|
|
|
|
- Dbg("GenerateErrPage type=%s, dstPage=%s", errType._to_string(), errPagePath.GetData());
|
|
|
-
|
|
|
- return std::make_pair(true, (const char*)errPagePath.GetData());
|
|
|
+ return std::make_pair(true, (const char*)dstCmd.GetData());
|
|
|
}
|
|
|
|
|
|
std::string formatTime(SYSTEMTIME time)
|
|
@@ -245,13 +283,7 @@ std::pair<bool, std::string> CModTools::getMainUrl()
|
|
|
return std::make_pair(isOpenExtend, strUrl.GetData());
|
|
|
}
|
|
|
|
|
|
-auto GetCefHead = [](CEntityBase* curEntity)->CSimpleStringA {
|
|
|
- CSimpleStringA strChromiumPath, basePath;
|
|
|
- curEntity->GetFunction()->GetPath("Base", basePath);
|
|
|
- strChromiumPath.Append("sudo ").Append(basePath);
|
|
|
- strChromiumPath.Append(CSimpleStringA(SPLIT_SLASH_STR) + "bin" + SPLIT_SLASH_STR + "Chromium" + SPLIT_SLASH_STR);
|
|
|
- return strChromiumPath;
|
|
|
-};
|
|
|
+
|
|
|
|
|
|
std::string CModTools::generateAdCmd(std::string AdUrl) {
|
|
|
CSimpleStringA strChromiumPath = GetCefHead(this->m_pEntity), strCmdLine = "";
|
|
@@ -344,7 +376,7 @@ std::pair<ErrorCodeEnum, int> CModTools::StartChromiumBrowser(ERR_PAGE_REASON re
|
|
|
|
|
|
auto strCmdLine = generateCefclientCmd(mainUrlRet.first, mainUrlRet.second);
|
|
|
|
|
|
- auto openCefRet = openCef(strCmdLine);
|
|
|
+ auto openCefRet = openCef(strCmdLine, false);
|
|
|
if (Error_Succeed == openCefRet.first)
|
|
|
return std::make_pair(Error_Succeed, openCefRet.second);
|
|
|
}
|
|
@@ -352,13 +384,14 @@ std::pair<ErrorCodeEnum, int> CModTools::StartChromiumBrowser(ERR_PAGE_REASON re
|
|
|
{
|
|
|
//open err page
|
|
|
auto errPageUrl = GenerateErrPage(reason);
|
|
|
+
|
|
|
if (!errPageUrl.first)
|
|
|
{
|
|
|
DbgEx("errPage get url failed!");
|
|
|
return std::make_pair(Error_Unexpect, 0);
|
|
|
}
|
|
|
auto errPageRet = openCef(errPageUrl.second);
|
|
|
- return errPageRet;
|
|
|
+ return std::make_pair(Error_Succeed, 0);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -392,12 +425,231 @@ void CModTools::cefClientGuardian(std::string cmdline)
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-std::pair<ErrorCodeEnum, int> CModTools::openCef(std::string cmdline)
|
|
|
+// 输入为北京时间 输出为北京时间戳
|
|
|
+int CModTools::StandardToStamp(const char* str_time, bool dateOnly)
|
|
|
{
|
|
|
- //mod_chromium相当于cefclient的守护进程
|
|
|
- std::string guardianStr = cmdline;
|
|
|
- boost::thread cefGuardian(boost::bind(&CModTools::cefClientGuardian, this, guardianStr));
|
|
|
- cefGuardian.detach();
|
|
|
+ Dbg("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::isOutsidePad() {
|
|
|
+
|
|
|
+ if ((m_strSite.IsEndWith("FLB", true) || m_strSite.IsEndWith("SMM", true)) &&
|
|
|
+ m_strMachineType.IsEndWith("PAD", true))
|
|
|
+ {
|
|
|
+ Dbg("isOutsidePad Yes");
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ Dbg("isOutsidePad No");
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+TradeManageCodeEnum CModTools::CheckJobLimited()
|
|
|
+{
|
|
|
+ if (!isOutsidePad())
|
|
|
+ {
|
|
|
+ return TradeManageCodeEnum::Undefined;
|
|
|
+ }
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ ErrorCodeEnum BootTimeCfgError = m_pEntity->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
+ CSimpleStringA strLastRecordTime = "", strControl = "", strExpirationDate = "";
|
|
|
+ time_t now = time(0);
|
|
|
+ localtime(&now);
|
|
|
+ ErrorCodeEnum errorRead = Error_Succeed;
|
|
|
+ if (Error_Succeed != spConfig->ReadConfigValue("Record", "LastRecordTime", strLastRecordTime))
|
|
|
+ {
|
|
|
+ Dbg("Read Record LastRecordTime -> Failed! Maybe LastRecordTime not exist!");
|
|
|
+ strLastRecordTime = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Error_Succeed != spConfig->ReadConfigValue("Record", "Control", strControl))
|
|
|
+ {
|
|
|
+ Dbg("Read Record Control -> Failed! Maybe Control not exist!");
|
|
|
+ strControl = "";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Error_Succeed != spConfig->ReadConfigValue("Record", "ExpirationDate", strExpirationDate))
|
|
|
+ {
|
|
|
+ Dbg("Read Record ExpirationDate -> Failed! Maybe ExpirationDate not exist!");
|
|
|
+ strExpirationDate = "";
|
|
|
+ }
|
|
|
+ if (strControl.Compare("on") == 0)
|
|
|
+ {
|
|
|
+ // 控制标识为on时,检查过期时间,过期时间之前都设置为启用
|
|
|
+ if (strExpirationDate == "")
|
|
|
+ {
|
|
|
+ Dbg("CheckJobLimited -> on -> strExpirationDate=null ");
|
|
|
+ setLimitReason("");
|
|
|
+ return TradeManageCodeEnum::Trade;
|
|
|
+ }
|
|
|
+ int timestamp_expiration = StandardToStamp(strExpirationDate.Append(" 23:59:59"), false);
|
|
|
+
|
|
|
+ if (now < timestamp_expiration)
|
|
|
+ {
|
|
|
+ // 过期之前都可以进行交易
|
|
|
+ Dbg("CheckJobLimited -> on -> strExpirationDate>now ");
|
|
|
+ setLimitReason("");
|
|
|
+ return TradeManageCodeEnum::Trade;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ // 过期之后 设置为normal
|
|
|
+ spConfig->WriteConfigValue("Record", "Control", "normal");
|
|
|
+ strControl = "normal";
|
|
|
+ Dbg("CheckJobLimited -> on -> strExpirationDate<now -> control to normal");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strControl.Compare("off") == 0)
|
|
|
+ {
|
|
|
+ // 展示交易暂停页面
|
|
|
+ Dbg("CheckJobLimited -> off ");
|
|
|
+ setLimitReason("disabled");
|
|
|
+ return TradeManageCodeEnum::Disabled;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (strControl.Compare("normal") == 0 || strControl.IsNullOrEmpty())
|
|
|
+ {
|
|
|
+ if (strLastRecordTime == "")
|
|
|
+ {
|
|
|
+ Dbg("CheckJobLimited -> normal -> strLastRecordTime=null ");
|
|
|
+ setLimitReason("");
|
|
|
+ return TradeManageCodeEnum::Trade;
|
|
|
+ }
|
|
|
+ int timestamp_lastRecordTime = StandardToStamp(strLastRecordTime, true);
|
|
|
+
|
|
|
+ if (now < timestamp_lastRecordTime + 3600 * 24 * 2)
|
|
|
+ {
|
|
|
+ Dbg("CheckJobLimited -> normal -> now < lastRecordTime + 3600*24*2 ");
|
|
|
+ setLimitReason("");
|
|
|
+ return TradeManageCodeEnum::Trade;
|
|
|
+ }
|
|
|
+ else if (CheckTradeRecord()) {
|
|
|
+ // 展示交易暂停页面
|
|
|
+ Dbg("CheckJobLimited -> normal -> now < CheckTradeRecord = true ");
|
|
|
+ setLimitReason("jobuncomplete");
|
|
|
+ return TradeManageCodeEnum::JobUncomplete;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 理论上不会流转到这里来
|
|
|
+ setLimitReason("");
|
|
|
+ return TradeManageCodeEnum::Trade;
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
+ {
|
|
|
+ Dbg("connect to Upload entity fail: %d", rc);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ UploadService_UploadDateList_Req req = {};
|
|
|
+ UploadService_UploadDateList_Ans ans = {};
|
|
|
+
|
|
|
+ rc = pClient->UploadDateList(req, ans, 10000);
|
|
|
+
|
|
|
+ if (rc != Error_Succeed)
|
|
|
+ Dbg("UploadDateList fail from Upload: %d", rc);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ Dbg("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.push_back(t);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ pClient->SafeDelete();
|
|
|
+ pClient = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 比较时间戳 登记时间 <= 列表时间 < 今天 返回true
|
|
|
+ time_t now = time(0);
|
|
|
+ localtime(&now);
|
|
|
+ now -= now % (3600 * 24);
|
|
|
+ now -= 3600 * 8; //处理东八区问题
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ ErrorCodeEnum BootTimeCfgError = m_pEntity->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
+ CSimpleStringA strLastRecordTime = "";
|
|
|
+ ErrorCodeEnum errorRead = Error_Succeed;
|
|
|
+ errorRead = spConfig->ReadConfigValue("Record", "LastRecordTime", strLastRecordTime);
|
|
|
+ if (errorRead != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("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)
|
|
|
+ {
|
|
|
+ Dbg("CheckTradeRecord lastRecordTime=%d, time_list=%d, now=%d", timestamp_lastRecordTime, *it, now);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+std::pair<ErrorCodeEnum, int> CModTools::openCef(std::string cmdline, bool isGuard)
|
|
|
+{
|
|
|
+ if (isGuard) {
|
|
|
+ //mod_chromium相当于cefclient的守护进程
|
|
|
+ boost::thread cefGuardian(boost::bind(&CModTools::cefClientGuardian, this, cmdline));
|
|
|
+ cefGuardian.detach();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ auto systemStartChromium = [](std::string str) {
|
|
|
+ system(str.c_str());
|
|
|
+ };
|
|
|
+ boost::thread(systemStartChromium, cmdline).detach();
|
|
|
+ }
|
|
|
+
|
|
|
return std::make_pair(Error_Succeed, 0);
|
|
|
}
|
|
|
|