emsApplication/applications/WebConfigure/cgiCommon/main.cpp

123 lines
2.4 KiB
C++
Raw Normal View History

2024-05-24 12:19:45 +08:00
#include <cgicc/Cgicc.h>
#include <cgicc/CgiDefs.h>
#include <cgicc/HTTPHTMLHeader.h>
#include <cgicc/HTMLClasses.h>
2024-06-07 16:44:21 +08:00
#include <hv/hv.h>
2024-05-24 12:19:45 +08:00
#include "handleHeader.h"
2024-06-05 20:52:33 +08:00
#include "openjson.h"
#include "opmysql.h"
2024-05-24 12:19:45 +08:00
// 你的CGI处理函数声明
void handleLoginRequest(cgicc::Cgicc& cgi);
void handleSignupRequest(cgicc::Cgicc& cgi);
// 添加更多处理函数...
2024-06-04 13:36:17 +08:00
void handleVersion(cgicc::Cgicc& cgi)
{
using namespace cgicc;
using namespace std;
// Output the HTTP headers for an HTML document, and the HTML 4.0 DTD info
std::cout << HTTPHTMLHeader() << HTMLDoctype(HTMLDoctype::eStrict) << std::endl;
//cout << html().set("lang", "en").set("dir", "ltr") << endl;
std::cout << "<meta charset=\"UTF-8\">" << std::endl;
// Set up the page's header and title.
std::cout << head() << std::endl;
std::cout << title() << "Shanghai Huijue EMS device" << title() << std::endl;
std::cout << head() << std::endl << std::endl;
std::cout << body() << std::endl;
#define cgiVersion "1.0.531"
const char* VersionInfo = "Version: " cgiVersion;
const char* BuildInfo = "Build Info: " __DATE__ " " __TIME__;
std::cout << h1(VersionInfo) << std::endl;
2024-06-05 20:52:33 +08:00
std::cout << h2(BuildInfo) << std::endl;
2024-06-04 13:36:17 +08:00
// Close the document
std::cout << body() << html();
}
2024-05-24 12:19:45 +08:00
2024-06-05 20:52:33 +08:00
void handleTest()
{
// 处理登录逻辑...
//从数据库中查询
bool dbok = OpDatabase::getInstance()->OpenDatabase("127.0.0.1", "root");
std::string jsonResult;
if (!dbok)
{
std::cout << ("failed to retrieve user info");
}
else
{
if (!OpDatabase::getInstance()->queryUser("hkc", "1c915f2c045ea7628e3cf170bfa59f51", jsonResult))
{
std::cout << ("invalid user") << std::endl;
}
else
{
std::cout << ("Login Successful!") << std::endl;
}
}
std::cout << jsonResult << std::endl;
}
2024-05-24 12:19:45 +08:00
int main()
{
2024-06-05 20:52:33 +08:00
#if 0
handleTest();
return 1;
#endif
2024-05-24 12:19:45 +08:00
using namespace cgicc;
using namespace std;
2024-06-07 16:44:21 +08:00
hlog_set_file("/var/log/webcfg.log");
hlog_set_level_by_str("DEBUG");
hlog_set_max_filesize_by_str("16M");
hlog_set_remain_days(10);
logger_enable_fsync(hlog, 1);
//hlogi("=========--- Welcome to the Earth ---=========");
hlog_fsync();
2024-05-24 12:19:45 +08:00
Cgicc formData;
2024-06-04 13:36:17 +08:00
#if 0
handleLoginRequest(formData);
2024-05-24 12:19:45 +08:00
2024-06-04 13:36:17 +08:00
return 0;
#endif
#if 1
2024-05-24 12:19:45 +08:00
//获得api方法
form_iterator fi = formData.getElement("do");
if (!fi->isEmpty() && fi != (*formData).end())
{
2024-06-04 13:36:17 +08:00
if (**fi == "version")
{
handleVersion(formData);
}
2024-05-24 12:19:45 +08:00
if (**fi == "login")
{
handleLoginRequest(formData);
}
if (**fi == "getDevices")
{
}
}
return 0;
2024-06-04 13:36:17 +08:00
#endif
2024-05-24 12:19:45 +08:00
}