12 |
#include <iomanip> |
#include <iomanip> |
13 |
#include <stdlib.h> |
#include <stdlib.h> |
14 |
|
|
15 |
void show_secret(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { |
void show_status(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { |
16 |
Common* cmn = Common::instance(); |
Common* cmn = Common::instance(); |
17 |
|
|
18 |
|
|
45 |
mg_printf(conn, "%s", "Content-Type: text/html\r\n\r\n"); |
mg_printf(conn, "%s", "Content-Type: text/html\r\n\r\n"); |
46 |
|
|
47 |
mg_printf(conn, "%s", "<html><body><h2>smsdaemon</h2>\n"); |
mg_printf(conn, "%s", "<html><body><h2>smsdaemon</h2>\n"); |
48 |
mg_printf(conn, "%s", "<a href='/status'>smsdaemon status</a>\n"); |
mg_printf(conn, "%s", "<a href='/status'>smsdaemon status</a><br>\n"); |
49 |
|
mg_printf(conn, "%s", "<a href='/log'>smsdaemon log</a><br>\n"); |
50 |
|
|
51 |
mg_printf(conn, "%s", "</body></html>"); |
mg_printf(conn, "%s", "</body></html>"); |
52 |
} |
} |
53 |
|
|
58 |
mg_printf(conn, "%s", "Oops. File not found! "); |
mg_printf(conn, "%s", "Oops. File not found! "); |
59 |
} |
} |
60 |
|
|
61 |
|
void show_log(struct mg_connection *conn, const struct mg_request_info *request_info, void *user_data) { |
62 |
|
mg_printf(conn, "%s", "HTTP/1.1 200 OK\r\n"); |
63 |
|
mg_printf(conn, "%s", "Content-Type: text/plain\r\n\r\n"); |
64 |
|
|
65 |
|
for (unsigned i=0; i<Logger::logBuffer.size(); i++) { |
66 |
|
mg_printf(conn, "%s", Logger::logBuffer[i].c_str() ); |
67 |
|
} |
68 |
|
} |
69 |
|
|
70 |
void EmbeddedHttp::startServer() { |
void EmbeddedHttp::startServer() { |
71 |
std::string portStr = Common::instance()->GetConfigfile()->GetValue("smsdaemon", "httpport"); |
std::string portStr = Common::instance()->GetConfigfile()->GetValue("smsdaemon", "httpport"); |
81 |
|
|
82 |
m_context = mg_start(); |
m_context = mg_start(); |
83 |
mg_set_option(m_context, "ports", oss.str().c_str() ); |
mg_set_option(m_context, "ports", oss.str().c_str() ); |
84 |
|
mg_set_option(m_context, "root", "/nosuchpatch"); //set root to non-existant path to disable normal file serving - only callbacks are now serviced |
85 |
|
|
86 |
mg_set_uri_callback(m_context, "/", &show_index, 0); |
mg_set_uri_callback(m_context, "/", &show_index, 0); |
87 |
mg_set_uri_callback(m_context, "/status", &show_secret, 0); |
mg_set_uri_callback(m_context, "/status", &show_status, 0); |
88 |
|
mg_set_uri_callback(m_context, "/log", &show_log, 0); |
89 |
mg_set_error_callback(m_context, 404, show_404, NULL); |
mg_set_error_callback(m_context, 404, show_404, NULL); |
90 |
|
|
91 |
|
|