Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
99 lines (97 sloc) 3.01 KB
#pragma once
#include "includes.hpp"
using namespace dlib;
namespace srv
{
class nodeServer : public server_http
{
private:
std::map<std::string, std::string> database;
public:
const std::string on_request(const incoming_things &incoming, outgoing_things &outgoing)
{
#ifdef DEBUG_RNG
database["rnd"] = dev::str::cast_to_string(dev::math::random::random(0, 1000000));
#endif
#ifdef DEBUG_WEBOUT
std::cout << "Path: " << incoming.path << std::endl;
std::cout << "Incoming IP: " << incoming.foreign_ip << std::endl;
std::cout << "Foreign PORT: " << incoming.foreign_port << std::endl;
std::cout << "Requested Protocol: " << incoming.protocol << std::endl;
std::cout << "Request Type: " << incoming.request_type << std::endl;
#endif
if (!strcmp(incoming.path.c_str(), "/put"))
{
std::string key = incoming.queries["key"];
std::string data = incoming.queries["data"];
if (key.size() != 0 && data.size() != 0)
{
database[key] = data;
return "Y";
}
else
{
return "N";
}
}
else if(!strcmp(incoming.path.c_str(), "/put_wf"))
{
std::string key = incoming.queries["key"];
std::string data = incoming.queries["data"];
if (key.size() != 0 && data.size() != 0)
{
database[key] = data;
return "<span style=\"background-color: #98BF21; font-size: 36px;\">Successfully added [" + data + "] : [" + key + "]</span>";
}
else
{
return "<span style=\"background-color: red; font-size: 36px;\">Failed adding value. Form incomplete!</span>";
}
}
else if(!strcmp(incoming.path.c_str(), "/get"))
{
std::string key = incoming.queries["key"];
return database[key];
}
else if(!strcmp(incoming.path.c_str(), "/monitor_tbl"))
{
return srv::montbl(database);
}
else if (!strcmp(incoming.path.c_str(), "/shdn"))
{
#ifndef DISABLE_REMOTE_SHUTDOWN
exit(EXIT_SUCCESS);
return "Shutdown Not Permitted!";
#endif
}
else if (!strcmp(incoming.path.c_str(), "/"))
{
return srv::reqform();
}
else if(!strcmp(incoming.path.c_str(), "/inject_frm"))
{
return srv::reqinject();
}
else if(!strcmp(incoming.path.c_str(), "/monitor_frm"))
{
return srv::reqmon();
}
else if(!strcmp(incoming.path.c_str(), "/ref"))
{
load();
return "";
}
else if(!strcmp(incoming.path.c_str(), "/shdn_auto"))
{
#ifdef ALLOW_AUTO_SHUTDOWN
exit(EXIT_SUCCESS);
#endif
}
else
{
return "404! Not Found!";
}
return "";
}
};
}