120 lines
2.4 KiB
C++
120 lines
2.4 KiB
C++
#include <cgicc/Cgicc.h>
|
|
#include <cgicc/CgiDefs.h>
|
|
#include <cgicc/HTTPHTMLHeader.h>
|
|
#include <cgicc/HTMLClasses.h>
|
|
#include <hv/hv.h>
|
|
#include "openjson.h"
|
|
#include "opmysql.h"
|
|
|
|
#include "handleHeader.h"
|
|
#include "handlers.h"
|
|
|
|
|
|
// 添加更多处理函数...
|
|
|
|
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;
|
|
std::cout << h2(BuildInfo) << std::endl;
|
|
|
|
// Close the document
|
|
std::cout << body() << html();
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
int main()
|
|
{
|
|
#if 0
|
|
handleTest();
|
|
|
|
return 1;
|
|
#endif
|
|
using namespace cgicc;
|
|
using namespace std;
|
|
|
|
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();
|
|
|
|
Cgicc formData;
|
|
#if 0
|
|
handleLoginRequest(formData);
|
|
|
|
return 0;
|
|
#endif
|
|
|
|
#if 1
|
|
//获得api方法
|
|
form_iterator fi = formData.getElement("do");
|
|
|
|
if (!fi->isEmpty() && fi != (*formData).end())
|
|
{
|
|
if (**fi == "version")
|
|
{
|
|
handleVersion(formData);
|
|
}
|
|
|
|
if (**fi == "login")
|
|
{
|
|
handleLoginRequest(formData);
|
|
}
|
|
|
|
if (**fi == "devices")
|
|
{
|
|
handleDevicesRequest(formData);
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
#endif
|
|
} |