#include #include "Log.h" #include "FsProxy.h" #include "Config.h" #include "TimeScheduler.h" #include "TtsBaidu.h" #include "SqlWrite.h" #include "SoftAuth.h" #include #ifdef WIN32 // #else #include #define CORE_SIZE 1024 * 1024 * 500 #endif // WIN32 void AuthFun() { bool isStop = false; while (!isStop) { std::this_thread::sleep_for(std::chrono::hours(1)); if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序 { LOG_WARN("授权到期,自动关闭程序!"); isStop = true; CFsProxy::GetInstance().release(); exit(EXIT_SUCCESS); } } } int main() { MYLog::instance()->Init("log4cpp.conf"); LOG_INFO_S("程序开始启动..."); struct rlimit crlmt; if (getrlimit(RLIMIT_CORE, &crlmt) == -1) { return -1; } //printf("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max); LOG_INFO("Before set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max); crlmt.rlim_cur = (rlim_t)CORE_SIZE; crlmt.rlim_max = (rlim_t)CORE_SIZE; if (setrlimit(RLIMIT_CORE, &crlmt) == -1) { return -1; } if (getrlimit(RLIMIT_CORE, &crlmt) == -1) { return -1; } //printf("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max); LOG_INFO("After set rlimit CORE dump current is:%d, max is:%d\n", (int)crlmt.rlim_cur, (int)crlmt.rlim_max); //if (!SoftAuth::GetInstance()->Auth()) //{ // std::cout << "该机器未授权,请授权后使用" << std::endl; // std::string hardc; // SoftAuth::GetInstance()->getMachineCode(hardc); // //std::cout << SoftAuth::GetInstance()->getMachineCode(hardc) << std::endl; // std::cout << "机器码:" << hardc << std::endl; // //SoftAuth::GetInstance()->MakeAuth(hardc); // // std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2"; // std::cout << "请输入授权码:" << std::endl; // std::cin >> code; // if (!SoftAuth::GetInstance()->Auth(code)) // { // LOG_WARN("授权验证失败,自动关闭程序!"); // CFsProxy::GetInstance().release(); // //exit(EXIT_SUCCESS); // return 0; // } //} if (!SoftAuth::GetInstance()->AuthV2()) { std::cout << "该机器未授权,请授权后使用" << std::endl; std::string hardc; if (!SoftAuth::GetInstance()->getMachineCode(hardc)) { std::cout << "机器码获取失败,请用root权限运行!" << std::endl; return 0; } std::cout << "机器码:" << hardc << std::endl; std::string code;// = "MWEyZGZmYzctYTVjNC00OWEwLTgxNTgtMTQ3YjNmYTA3Zjc4CjIwMjAwNzE2"; std::cout << "请输入授权码:" << std::endl; std::cin >> code; if (!SoftAuth::GetInstance()->AuthV2(code)) { LOG_WARN("授权验证失败,自动关闭程序!"); CFsProxy::GetInstance().release(); //exit(EXIT_SUCCESS); return 0; } } AuthInfo aInfo; SoftAuth::GetInstance()->getAuthInfo(aInfo); LOG_INFO_S("授权到期时间:" + aInfo.data); LOG_INFO_S("授权中继数量:" + std::to_string(aInfo.trunkNum)); LOG_INFO_S("授权坐席数量:" + std::to_string(aInfo.agentNum)); if (!SoftAuth::GetInstance()->isExpire()) // 授权到期,关闭程序 { LOG_WARN("授权到期,自动关闭程序!"); return 0; } std::thread(std::bind(AuthFun)).detach(); CConfig *cfg = CConfig::GetInstance(); if (!cfg->load()) { LOG_WARN_S("配置文件加载失败!"); cfg->write(); return 0; } if (CFsProxy::GetInstance().init()) { LOG_INFO_S("程序初始化完成,开始运行..."); CFsProxy::GetInstance().run(); } else LOG_ERROR_S("程序初始化失败,程序即将关闭"); CFsProxy::GetInstance().release(); exit(EXIT_SUCCESS); return 0; }