2024-02-14 05:05:01 +00:00
|
|
|
#ifndef CGI_H
|
|
|
|
#define CGI_H
|
|
|
|
|
2024-02-14 02:01:59 +00:00
|
|
|
#include "lwip/apps/httpd.h"
|
2024-02-14 05:05:01 +00:00
|
|
|
#include "handlers.h"
|
|
|
|
|
2024-02-14 21:33:20 +00:00
|
|
|
const char * cgi_power_handler (int iIndex, int iNumParams, char * pcParam [], char * pcValue []) {
|
2024-02-14 05:05:01 +00:00
|
|
|
// Check if an request for power has been made (/power?requested_state=x)
|
|
|
|
if (strcmp(pcParam[0] , "requested_state") == 0){
|
2024-02-14 21:33:20 +00:00
|
|
|
if (strcmp(pcValue[0], "0") == 0) {
|
2024-02-14 05:05:01 +00:00
|
|
|
bmc_power_handler(false);
|
2024-02-14 21:33:20 +00:00
|
|
|
return "/power.ssi";
|
2024-02-14 05:05:01 +00:00
|
|
|
}
|
2024-02-14 21:33:20 +00:00
|
|
|
else if (strcmp(pcValue[0], "1") == 0) {
|
2024-02-14 05:05:01 +00:00
|
|
|
bmc_power_handler(true);
|
2024-02-14 21:33:20 +00:00
|
|
|
return "/power.ssi";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return "/error_requested_state_invalid.ssi";
|
2024-02-14 05:05:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Send the index page back to the user
|
2024-02-14 21:33:20 +00:00
|
|
|
else {
|
|
|
|
return "/error_missing_requested_state.ssi";
|
|
|
|
}
|
2024-02-14 05:05:01 +00:00
|
|
|
}
|
2024-02-14 02:01:59 +00:00
|
|
|
|
2024-02-14 05:05:01 +00:00
|
|
|
const char * cgi_status_handler (int iIndex, int iNumParams, char *pcParam[], char *pcValue[]) {
|
|
|
|
return "/status.ssi";
|
2024-02-14 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const tCGI cgi_handlers[] = {
|
2024-02-14 05:05:01 +00:00
|
|
|
{
|
|
|
|
"/power", cgi_power_handler
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"/status", cgi_status_handler
|
|
|
|
}
|
2024-02-14 02:01:59 +00:00
|
|
|
};
|
|
|
|
|
2024-02-14 05:05:01 +00:00
|
|
|
void cgi_init(void) {
|
|
|
|
http_set_cgi_handlers(cgi_handlers, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|