Files
Autopilot-Data-ParserOLD/initializeHTTP.cpp

371 lines
21 KiB
C++
Raw Normal View History

//
//
// Created by Jakob Oberbuchner's Generator
//
//
#include "initializeHTTP.h"
#include "compiled.h"
void initializeServerHTTP_GET(AsyncWebServer *server_) {
// Must have Index page for this to work
server_->on("/", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_indexhtml, sizeof(a_indexhtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_indexhtml));
request->send(response);
});
server_->on("/networkSetup.js", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", a_networkSetupjs, sizeof(a_networkSetupjs));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_networkSetupjs));
request->send(response);
});
server_->on("/Update.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_Updatehtml, sizeof(a_Updatehtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Updatehtml));
request->send(response);
});
server_->on("/index.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_indexhtml, sizeof(a_indexhtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_indexhtml));
request->send(response);
});
server_->on("/images/default-image-3.jpg", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesdefaultimage3jpg, sizeof(a_imagesdefaultimage3jpg));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesdefaultimage3jpg));
request->send(response);
});
server_->on("/images/default-image-4.jpg", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesdefaultimage4jpg, sizeof(a_imagesdefaultimage4jpg));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesdefaultimage4jpg));
request->send(response);
});
server_->on("/images/OberbuiltLogoMod.png", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesOberbuiltLogoModpng, sizeof(a_imagesOberbuiltLogoModpng));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesOberbuiltLogoModpng));
request->send(response);
});
server_->on("/images/default-image.jpg", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesdefaultimagejpg, sizeof(a_imagesdefaultimagejpg));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesdefaultimagejpg));
request->send(response);
});
server_->on("/images/Custom/MinusBox.png", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesCustomMinusBoxpng, sizeof(a_imagesCustomMinusBoxpng));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesCustomMinusBoxpng));
request->send(response);
});
server_->on("/images/Custom/x.png", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesCustomxpng, sizeof(a_imagesCustomxpng));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesCustomxpng));
request->send(response);
});
server_->on("/images/Custom/AddBox.png", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesCustomAddBoxpng, sizeof(a_imagesCustomAddBoxpng));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesCustomAddBoxpng));
request->send(response);
});
server_->on("/images/Custom/Arrow.png", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesCustomArrowpng, sizeof(a_imagesCustomArrowpng));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesCustomArrowpng));
request->send(response);
});
server_->on("/images/Custom/checkmark.png", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/jpg", a_imagesCustomcheckmarkpng, sizeof(a_imagesCustomcheckmarkpng));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_imagesCustomcheckmarkpng));
request->send(response);
});
server_->on("/Update.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_Updatecss, sizeof(a_Updatecss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Updatecss));
request->send(response);
});
server_->on("/login.css", HTTP_GET, [](AsyncWebServerRequest *request) {
// Accessible without login!!
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_logincss, sizeof(a_logincss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_logincss));
request->send(response);
});
server_->on("/nicepage.js", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", a_nicepagejs, sizeof(a_nicepagejs));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_nicepagejs));
request->send(response);
});
server_->on("/index.js", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", a_indexjs, sizeof(a_indexjs));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_indexjs));
request->send(response);
});
server_->on("/Reboot.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_Reboothtml, sizeof(a_Reboothtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Reboothtml));
request->send(response);
});
server_->on("/index.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_indexcss, sizeof(a_indexcss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_indexcss));
request->send(response);
});
server_->on("/Live-Data.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_LiveDatahtml, sizeof(a_LiveDatahtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_LiveDatahtml));
request->send(response);
});
server_->on("/Reboot.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_Rebootcss, sizeof(a_Rebootcss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Rebootcss));
request->send(response);
});
server_->on("/Commands.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
if(!request->authenticate(http_username, http_password)) { return request->requestAuthentication(); } AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_Commandshtml, sizeof(a_Commandshtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Commandshtml));
request->send(response);
});
server_->on("/networkSetup.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_networkSetuphtml, sizeof(a_networkSetuphtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_networkSetuphtml));
request->send(response);
});
server_->on("/nicepage.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_nicepagecss, sizeof(a_nicepagecss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_nicepagecss));
request->send(response);
});
server_->on("/Live-Data.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_LiveDatacss, sizeof(a_LiveDatacss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_LiveDatacss));
request->send(response);
});
server_->on("/chart.umd.min.js", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", a_chartumdminjs, sizeof(a_chartumdminjs));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_chartumdminjs));
request->send(response);
});
server_->on("/Commands.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
if(!request->authenticate(http_username, http_password)) { return request->requestAuthentication(); } AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_Commandscss, sizeof(a_Commandscss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Commandscss));
request->send(response);
});
server_->on("/Settings.html", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/html", a_Settingshtml, sizeof(a_Settingshtml));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_Settingshtml));
request->send(response);
});
server_->on("/networkSetup.css", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/css", a_networkSetupcss, sizeof(a_networkSetupcss));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_networkSetupcss));
request->send(response);
});
server_->on("/jquery.js", HTTP_GET, [](AsyncWebServerRequest *request) {
if (!authenticateLogin(request)) return; // Make sure the user requesting this has logged in
AsyncWebServerResponse *response = request->beginResponse(200, "text/javascript", a_jqueryjs, sizeof(a_jqueryjs));
response->addHeader(F("Content-Encoding"), F("gzip"));
response->addHeader("Connection", "close");
response->addHeader("Cache-Control", "max-age=30"); // 30 second cache life
response->setContentLength(sizeof(a_jqueryjs));
request->send(response);
});
}
void initializeServerHTTP_POST(AsyncWebServer *server_, bool* requiresRestart) {
server_->on("/UpdateFirmware", HTTP_POST, [requiresRestart](AsyncWebServerRequest *request) {
parse_a_Updatehtml_FirmwareUpdater_POST(request);
request->send(204);
*requiresRestart = true;
},
[](AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) {
//Add redirection?
if (!index) {
Serial.printf("Updating: %s\n", filename.c_str());
if (!Update.begin(UPDATE_SIZE_UNKNOWN)) {
Update.printError(Serial);
}
}
if (Update.write(data, len) != len) {
Update.printError(Serial);
}
if (final) {
if (!Update.end(true)) {
Update.printError(Serial);
} else {
Serial.println("Update complete! Needs a Restart.");
}
}
});
server_->on("/FactoryReset", HTTP_POST, [](AsyncWebServerRequest *request) {
if (parse_a_Updatehtml_resetform_POST(request)) {
request->send(204);
} else {
request->send(500); //Internal server error, indicates the post was not successful
}
});
server_->on("/Settings", HTTP_POST, [](AsyncWebServerRequest *request) {
if (parse_a_indexhtml_Config_POST(request)) {
request->send(204);
} else {
request->send(500); //Internal server error, indicates the post was not successful
}
});
server_->on("/Execute", HTTP_POST, [](AsyncWebServerRequest *request) {
if (parse_a_Commandshtml_Execute_POST(request)) {
request->send(204);
} else {
request->send(500); //Internal server error, indicates the post was not successful
}
});
}