static void usb_status_fn(HTTPD_SESSION_STRUCT *session) { if (usbstick_attached()) { httpd_sendstr(session->sock, "visible"); } else { httpd_sendstr(session->sock, "hidden"); } }
static void usb_status_fn(HTTPD_SESSION_STRUCT *session) { #if DEMOCFG_ENABLE_USB_FILESYSTEM if (_lwsem_poll(&USB_Stick)) { httpd_sendstr(session->sock, "visible"); _lwsem_post(&USB_Stick); } else #endif httpd_sendstr(session->sock, "hidden"); }
_mqx_int cgi_udpstat(HTTPD_SESSION_STRUCT *session) { #if RTCSCFG_ENABLE_UDP_STATS { UDP_STATS_PTR udp = UDP_stats(); CGI_SEND_NUM(udp->COMMON.ST_RX_TOTAL); CGI_SEND_NUM(udp->COMMON.ST_RX_MISSED); CGI_SEND_NUM(udp->COMMON.ST_RX_ERRORS); CGI_SEND_NUM(udp->COMMON.ST_RX_DISCARDED); CGI_SEND_NUM(udp->ST_RX_BAD_PORT + udp->ST_RX_BAD_CHECKSUM + udp->ST_RX_SMALL_DGRAM + udp->ST_RX_SMALL_PKT); CGI_SEND_NUM(udp->ST_RX_NO_PORT); CGI_SEND_NUM(udp->COMMON.ST_TX_TOTAL); CGI_SEND_NUM(udp->COMMON.ST_TX_MISSED); CGI_SEND_NUM(udp->COMMON.ST_TX_ERRORS); CGI_SEND_NUM(udp->COMMON.ST_TX_DISCARDED); } #else int i; for (i = 0; i < 9; i++) { httpd_sendstr(session->sock, "unk\n"); } #endif return session->request.content_len; }
_mqx_int cgi_hvac_data(HTTPD_SESSION_STRUCT *session) { uint_32 Td = HVAC_GetDesiredTemperature(); uint_32 Ta = HVAC_GetActualTemperature(); char str[50]; session->response.contenttype = CONTENT_TYPE_PLAIN; httpd_sendhdr(session, 0, 0); CGI_SEND_STR(HVAC_HVACModeName(HVAC_GetHVACMode())); sprintf(str, "%d.%d °%c\n%d.%d °%c\n", Td/10, Td%10, HVAC_GetTemperatureSymbol(), Ta/10, Ta%10, HVAC_GetTemperatureSymbol()); httpd_sendstr(session->sock, str); CGI_SEND_STR(HVAC_GetFanMode() == Fan_Automatic ? "auto" : "on"); // CGI_SEND_STR(HVAC_GetOutputName(0)); // CGI_SEND_STR(HVAC_GetOutputName(1)); // CGI_SEND_STR(HVAC_GetOutputName(2)); CGI_SEND_STR(HVAC_GetOutput(HVAC_FAN_OUTPUT) ? "on" : "off"); CGI_SEND_STR(HVAC_GetOutput(HVAC_HEAT_OUTPUT) ? "on" : "off"); CGI_SEND_STR(HVAC_GetOutput(HVAC_COOL_OUTPUT) ? "on" : "off"); return session->request.content_len; }
void httpd_send404(HTTPD_STRUCT *server, HTTPD_SESSION_STRUCT *session) { HTTPD_DEBUG(3, "http_send404\n"); session->response.file = fopen(server->params->page404, "r"); session->response.len = 0; if (session->response.file) { httpd_sendfile(server, session); } else { httpd_sendhdr(session, 0, 0); httpd_sendstr(session->sock, "<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>\n"); httpd_sendstr(session->sock, "<BODY><H1>The request URL was not found!</H1>\n"); httpd_sendstr(session->sock, "</BODY></HTML>\n"); } }
void httpd_send403(HTTPD_STRUCT *server, HTTPD_SESSION_STRUCT *session) { HTTPD_DEBUG(3, "http_send403\n"); session->response.file = fopen(server->params->page403, "r"); session->response.len = 0; if (session->response.file) { httpd_sendfile(server, session); } else { httpd_sendhdr(session, 0, 0); httpd_sendstr(session->sock, "<HTML><HEAD><TITLE>403 Forbidden</TITLE></HEAD>\n"); httpd_sendstr(session->sock, "<BODY><H1>Forbidden!</H1>\n"); httpd_sendstr(session->sock, "</BODY></HTML>\n"); } }
static _mqx_int cgi_icmpstat(HTTPD_SESSION_STRUCT *session) { session->response.contenttype = CONTENT_TYPE_PLAIN; httpd_sendhdr(session, 0, 0); #if RTCSCFG_ENABLE_ICMP_STATS { #if RTCSCFG_ENABLE_IP4 ICMP_STATS_PTR icmp = ICMP_stats(); CGI_SEND_NUM(icmp->COMMON.ST_RX_TOTAL); CGI_SEND_NUM(icmp->COMMON.ST_RX_MISSED); CGI_SEND_NUM(icmp->COMMON.ST_RX_ERRORS); CGI_SEND_NUM(icmp->COMMON.ST_RX_DISCARDED); CGI_SEND_NUM(icmp->ST_RX_BAD_CHECKSUM + icmp->ST_RX_SMALL_DGRAM); CGI_SEND_NUM(icmp->ST_RX_BAD_CODE); CGI_SEND_NUM(icmp->ST_RX_RD_NOTGATE); CGI_SEND_NUM(icmp->COMMON.ST_TX_TOTAL); CGI_SEND_NUM(icmp->COMMON.ST_TX_MISSED); CGI_SEND_NUM(icmp->COMMON.ST_TX_ERRORS); CGI_SEND_NUM(icmp->COMMON.ST_TX_DISCARDED); CGI_SEND_NUM(icmp->ST_RX_DESTUNREACH); CGI_SEND_NUM(icmp->ST_RX_TIMEEXCEED); CGI_SEND_NUM(icmp->ST_RX_PARMPROB); CGI_SEND_NUM(icmp->ST_RX_SRCQUENCH); CGI_SEND_NUM(icmp->ST_RX_REDIRECT); CGI_SEND_NUM(icmp->ST_RX_ECHO_REQ); CGI_SEND_NUM(icmp->ST_RX_ECHO_REPLY); CGI_SEND_NUM(icmp->ST_RX_TIME_REQ); CGI_SEND_NUM(icmp->ST_RX_TIME_REPLY); CGI_SEND_NUM(icmp->ST_RX_INFO_REQ); CGI_SEND_NUM(icmp->ST_RX_INFO_REPLY); CGI_SEND_NUM(icmp->ST_RX_OTHER); CGI_SEND_NUM(icmp->ST_TX_DESTUNREACH); CGI_SEND_NUM(icmp->ST_TX_TIMEEXCEED); CGI_SEND_NUM(icmp->ST_TX_PARMPROB); CGI_SEND_NUM(icmp->ST_TX_SRCQUENCH); CGI_SEND_NUM(icmp->ST_TX_REDIRECT); CGI_SEND_NUM(icmp->ST_TX_ECHO_REQ); CGI_SEND_NUM(icmp->ST_TX_ECHO_REPLY); CGI_SEND_NUM(icmp->ST_TX_TIME_REQ); CGI_SEND_NUM(icmp->ST_TX_TIME_REPLY); CGI_SEND_NUM(icmp->ST_TX_INFO_REQ); CGI_SEND_NUM(icmp->ST_TX_INFO_REPLY); CGI_SEND_NUM(icmp->ST_TX_OTHER); #endif } #else int i; for (i = 0; i < 34; i++) { httpd_sendstr(session->sock, "unk\n"); } #endif return session->request.content_len; }
static _mqx_int cgi_index(HTTPD_SESSION_STRUCT *session) { session->response.contenttype = CONTENT_TYPE_HTML; httpd_sendhdr(session, 0, 0); html_head(session->sock, "MQX Demo"); httpd_sendstr(session->sock, "<BODY><table width=\"600\" border=\"0\">\n" "<tr align=\"center\">\n" "<td height=\"85\" colspan=\"3\"><p align=\"center\"> \n" "<strong><font size=6 font color=#0000CC><u>MQX Demo Home Page</u></font> </p></td>\n" "</tr>\n" "<tr>\n" "<td></td>\n" "<td align=\"center\" height=\"35\" bgcolor=\"#FFDD00\"><strong><A HREF=\"ipstat.cgi\">Network Stats</A></strong></td>\n" "<td></td>\n" "</tr>\n" "<tr>\n" "<td></td>\n" "<td align=\"center\" height=\"35\" bgcolor=\"#D0D88E\"><strong><A HREF=\"hvac.cgi\">HVAC Info</A></strong></td>\n" "<td></td>\n" "</tr>\n"); /*tries = 0; while ((!USB_Stick.VALUE) && (tries<8)){ _time_delay(250); tries++; }*/ if (USB_Stick.VALUE) { httpd_sendstr(session->sock, "<tr>\n" "<td></td>\n" "<td align=\"center\" height=\"35\" bgcolor=\"#B8D2E4\"><strong><A HREF=\"index.htm\">Browse USB</A></strong></td>\n" "<td></td>\n" "</tr>\n" "<td></td>\n" "<td><div align=\"center\"><img src=\"Logo1.jpg\"></div></td>\n" "<td></td>\n" "</table>\n</BODY>\n"); } httpd_sendstr(session->sock, "</html>"); return session->request.content_len; }
static _mqx_int cgi_tcpstat(HTTPD_SESSION_STRUCT *session) { session->response.contenttype = CONTENT_TYPE_PLAIN; httpd_sendhdr(session, 0, 0); #if RTCSCFG_ENABLE_TCP_STATS { TCP_STATS_PTR tcp = TCP_stats(); CGI_SEND_NUM(tcp->COMMON.ST_RX_TOTAL); CGI_SEND_NUM(tcp->COMMON.ST_RX_MISSED); CGI_SEND_NUM(tcp->COMMON.ST_RX_ERRORS); CGI_SEND_NUM(tcp->COMMON.ST_RX_DISCARDED); CGI_SEND_NUM(tcp->ST_RX_BAD_PORT + tcp->ST_RX_BAD_CHECKSUM + tcp->ST_RX_SMALL_HDR + tcp->ST_RX_SMALL_DGRAM + tcp->ST_RX_SMALL_PKT); CGI_SEND_NUM(tcp->ST_RX_BAD_ACK); CGI_SEND_NUM(tcp->ST_RX_BAD_DATA); CGI_SEND_NUM(tcp->ST_RX_LATE_DATA); CGI_SEND_NUM(tcp->ST_RX_DATA); CGI_SEND_NUM(tcp->ST_RX_DATA_DUP); CGI_SEND_NUM(tcp->ST_RX_ACK); CGI_SEND_NUM(tcp->ST_RX_ACK_DUP); CGI_SEND_NUM(tcp->ST_RX_RESET); CGI_SEND_NUM(tcp->ST_RX_PROBE); CGI_SEND_NUM(tcp->ST_RX_WINDOW); CGI_SEND_NUM(tcp->COMMON.ST_TX_TOTAL); CGI_SEND_NUM(tcp->COMMON.ST_TX_MISSED); CGI_SEND_NUM(tcp->COMMON.ST_TX_ERRORS); CGI_SEND_NUM(tcp->COMMON.ST_TX_DISCARDED); CGI_SEND_NUM(tcp->ST_TX_DATA); CGI_SEND_NUM(tcp->ST_TX_DATA_DUP); CGI_SEND_NUM(tcp->ST_TX_ACK); CGI_SEND_NUM(tcp->ST_TX_ACK_DELAYED); CGI_SEND_NUM(tcp->ST_TX_RESET); CGI_SEND_NUM(tcp->ST_TX_PROBE); CGI_SEND_NUM(tcp->ST_TX_WINDOW); CGI_SEND_NUM(tcp->ST_CONN_ACTIVE); CGI_SEND_NUM(tcp->ST_CONN_PASSIVE); CGI_SEND_NUM(tcp->ST_CONN_OPEN); CGI_SEND_NUM(tcp->ST_CONN_CLOSED); CGI_SEND_NUM(tcp->ST_CONN_RESET); CGI_SEND_NUM(tcp->ST_CONN_FAILED); } #else int i; for (i = 0; i < 23; i++) { httpd_sendstr(session->sock, "unk\n"); } #endif return session->request.content_len; }
static _mqx_int cgi_ipstat(HTTPD_SESSION_STRUCT *session) { session->response.contenttype = CONTENT_TYPE_PLAIN; httpd_sendhdr(session, 0, 0); #if RTCSCFG_ENABLE_IP_STATS { #if RTCSCFG_ENABLE_IP4 IP_STATS_PTR ip = IP_stats(); CGI_SEND_NUM(ip->COMMON.ST_RX_TOTAL); CGI_SEND_NUM(ip->ST_RX_DELIVERED); CGI_SEND_NUM(ip->ST_RX_FORWARDED); CGI_SEND_NUM(ip->COMMON.ST_RX_MISSED); CGI_SEND_NUM(ip->COMMON.ST_RX_ERRORS); CGI_SEND_NUM(ip->COMMON.ST_RX_DISCARDED); CGI_SEND_NUM(ip->ST_RX_HDR_ERRORS); CGI_SEND_NUM(ip->ST_RX_ADDR_ERRORS); CGI_SEND_NUM(ip->ST_RX_NO_PROTO); CGI_SEND_NUM(ip->ST_RX_FRAG_RECVD); CGI_SEND_NUM(ip->ST_RX_FRAG_REASMD); CGI_SEND_NUM(ip->ST_RX_FRAG_DISCARDED); CGI_SEND_NUM(ip->COMMON.ST_TX_TOTAL); CGI_SEND_NUM(ip->COMMON.ST_TX_MISSED); CGI_SEND_NUM(ip->COMMON.ST_TX_ERRORS); CGI_SEND_NUM(ip->COMMON.ST_TX_DISCARDED); CGI_SEND_NUM(ip->ST_TX_FRAG_FRAGD); CGI_SEND_NUM(ip->ST_TX_FRAG_SENT); CGI_SEND_NUM(ip->ST_TX_FRAG_DISCARDED); #endif } #else int i; for (i = 0; i < 18; i++) { httpd_sendstr(session->sock, "unk\n"); } #endif return session->request.content_len; }
void httpd_sendhdr(HTTPD_SESSION_STRUCT *session, _mqx_int content_len, _mqx_int mod_time) { char tmpBuf[100]; HTTPD_ASSERT(session); if (session->response.hdrsent) return; sprintf(tmpBuf, "HTTP/1.0 %d %s\n", session->response.statuscode, get_tbl_string((tbl_str_itm_t*)reason_phrase, session->response.statuscode)); httpd_sendstr(session->sock, tmpBuf); httpd_sendstr(session->sock, session->response.header); if (session->keep_alive) { httpd_sendstr(session->sock, "Connection: Keep-Alive\n"); } else { httpd_sendstr(session->sock, "Connection: close\n"); } sprintf(tmpBuf, "Content-Type: %s\n", get_tbl_string((tbl_str_itm_t*)content_type, session->response.contenttype)); httpd_sendstr(session->sock, tmpBuf); //only non zero length cause to send Content-Length header field if (0 < content_len) { sprintf(tmpBuf, "Content-Length: %d\n", content_len); httpd_sendstr(session->sock, tmpBuf); } httpd_sendstr(session->sock, "\n"); session->response.hdrsent = 1; HTTPD_DEBUG(4, "httpd_sendhdr\n"); }
_mqx_int cgi_hvac_output(HTTPD_SESSION_STRUCT *session) { uint_32 len = 0; char hvac[10], unit[10], fan[10], t[40]; uint_32 temp,temp_fract=0; boolean bParams = FALSE; char buffer[100]; session->response.contenttype = CONTENT_TYPE_HTML; httpd_sendhdr(session, 0, 0); httpd_sendstr(session->sock, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" "<html><head><title>HVAC Settings response</title>" "<meta http-equiv=\"REFRESH\" content=\"0;url=hvac.html\"></head>\n<body>\n"); // html_link(session->sock,"Home","index.cgi"); // html_link(session->sock,"HVAC Status","hvac.cgi"); // html_link(session->sock,"HVAC Settings","hvac_input.cgi"); //html_link(session->sock,"HVAC Log","hvac_log.txt"); httpd_sendstr(session->sock, "<br><br>\n"); if (session->request.content_len) { len = session->request.content_len; len = httpd_read(session, buffer, (int)((len > sizeof(buffer)) ? sizeof(buffer) : len)); buffer[len] = 0; session->request.content_len -= len; len = 0; if (httpd_get_varval(session, buffer, "hvac", hvac, sizeof(hvac)) && httpd_get_varval(session, buffer, "unit", unit, sizeof(unit)) && httpd_get_varval(session, buffer, "temp", t, sizeof(t)) && httpd_get_varval(session, buffer, "fan", fan, sizeof(fan))) { bParams = TRUE; if (strcmp(hvac,"heat") == 0) { HVAC_SetHVACMode(HVAC_Heat); } else if (strcmp(hvac,"cool") == 0) { HVAC_SetHVACMode(HVAC_Cool); } else { HVAC_SetHVACMode(HVAC_Off); } if (strcmp(unit,"f") == 0) HVAC_SetTemperatureScale(Fahrenheit); else HVAC_SetTemperatureScale(Celsius); if (strcmp(fan,"auto") == 0) { HVAC_SetFanMode(Fan_Automatic); } else { HVAC_SetFanMode(Fan_On); } if (sscanf(t, "%d.%d", &temp, &temp_fract) >= 1) { if (temp_fract<10) { HVAC_SetDesiredTemperature(temp * 10 + temp_fract); } } } } if (!bParams) { httpd_sendstr(session->sock, "No parameters received.<br>\n"); } httpd_sendstr(session->sock, "</body></html>"); return session->request.content_len; }