|
@@ -143,764 +143,47 @@ static void close_conn(struct tcp_pcb *pcb, struct http_state *hs)
|
|
|
*/
|
|
|
static err_t http_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
|
|
|
{
|
|
|
- char *data, *ptr;
|
|
|
- struct http_state *hs;
|
|
|
- char CookieBuf[50];
|
|
|
- char *CookiePtr = NULL;
|
|
|
- char name[MAX_WEB_COOKIE_LEN];
|
|
|
- char id[MAX_WEB_COOKIE_LEN];
|
|
|
- uint8_t nameLen = 0, idLen = 0;
|
|
|
- uint32_t DataOffset;
|
|
|
- struct fs_file file = {0, 0};
|
|
|
- uint32_t i;
|
|
|
-
|
|
|
- hs = arg;
|
|
|
-
|
|
|
- if (err == ERR_OK && p != NULL)
|
|
|
- {
|
|
|
- tcp_recved(pcb, p->tot_len);
|
|
|
-
|
|
|
- if (hs->file == NULL)
|
|
|
- {
|
|
|
- data = p->payload;
|
|
|
-/*
|
|
|
- printLen = p->tot_len;
|
|
|
- memcpy(printBuf, p->payload , printLen);
|
|
|
- printf(printBuf);
|
|
|
-*/
|
|
|
- receivedBufLen = p->tot_len;
|
|
|
- memcpy(receiveBuf, p->payload , receivedBufLen);
|
|
|
-
|
|
|
- receiveBuf[receivedBufLen] = '\0';
|
|
|
- // printf("receive %s \r\n", receiveBuf);
|
|
|
- /* Get cookie "uname" value */
|
|
|
- CookiePtr = strstr(receiveBuf, "uname=");
|
|
|
- strncpy(CookieBuf, CookiePtr, 50);
|
|
|
- //printf("********CookieBuf1= %s\r\n", CookieBuf);
|
|
|
- memset(name, 0, MAX_WEB_COOKIE_LEN);
|
|
|
- GetCookieValue(CookieBuf, "uname=", name, &nameLen);
|
|
|
- //printf("********CookieBuf2= %s\r\n", CookieBuf);
|
|
|
- //printf("********uname= %s\r\n", name);
|
|
|
-
|
|
|
- /* Get cookie "id" value */
|
|
|
- CookiePtr = strstr(receiveBuf, "id=");
|
|
|
- strncpy(CookieBuf, CookiePtr, 50);
|
|
|
- //printf("********CookieBuf1= %s\r\n", CookieBuf);
|
|
|
- memset(id, 0, MAX_WEB_COOKIE_LEN);
|
|
|
- GetCookieValue(CookieBuf, "id=", id, &idLen);
|
|
|
- //printf("********CookieBuf2= %s\r\n", CookieBuf);
|
|
|
- //printf("********id= %s\r\n", id);
|
|
|
-
|
|
|
-
|
|
|
- /* Id of currently logged-in user */
|
|
|
- uint8_t user_id;
|
|
|
-
|
|
|
- if( DataFlag == 0 && DataFlag2 == 0 ){
|
|
|
- /* Level of currently logged-in user */
|
|
|
- seclevel = 0xFF;
|
|
|
- for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
|
|
|
- HTTP_GetUserCookie(user_id, CookieBuf, &idLen);
|
|
|
- if (strncmp(id, CookieBuf, idLen) == 0 ) {
|
|
|
- GetUserLevelInt(user_id, &seclevel);
|
|
|
- Authenticated = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- Authenticated = false;
|
|
|
- seclevel = 0xFF;
|
|
|
- }
|
|
|
- }
|
|
|
- if (DataFlag >= 1)
|
|
|
- Authenticated = true;
|
|
|
- else if(DataFlag2 >= 1)
|
|
|
- Authenticated = true;
|
|
|
-
|
|
|
- if ( Authenticated == false && sSettings.sRADIUS.Auth_enable == false)
|
|
|
- {
|
|
|
- HTTP_LOGIN(sendBuf, &sendBufLoadLen);
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
-
|
|
|
- else if ( Authenticated == false )//&& sSettings.sRADIUS.Auth_enable == true
|
|
|
- {
|
|
|
- if (strncmp(data, "GET /main.css", 13) == 0) // +
|
|
|
- {
|
|
|
- fs_open("/main.css", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /rotek.png", 14) == 0) // +
|
|
|
- {
|
|
|
- fs_open("/rotek.png", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /favicon.ico", 16) == 0) // ?
|
|
|
- {
|
|
|
- fs_open("/favicon.ico", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /role.js", 12) == 0)
|
|
|
- {
|
|
|
- fs_open("/role.js", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
-
|
|
|
- }
|
|
|
- else if ((strncmp(data, "POST /login.cgi", 15) == 0) || (log_post_reqn > 0))
|
|
|
- {
|
|
|
- uint32_t i, offset = 0, req_data_received = 0;
|
|
|
-
|
|
|
- //printf("request 1: %d\r\n", receivedBufLen);
|
|
|
-
|
|
|
- /* parse packet for Content-length field */
|
|
|
- post_data_count = Parse_Content_Length(data, p->tot_len);
|
|
|
- //printf("Content-length: %d\r\n", (int)post_data_count);
|
|
|
-
|
|
|
- if (post_data_count < MAX_POST_REQ_LEN) {
|
|
|
-
|
|
|
- memset(post_req_data, 0, MAX_POST_REQ_LEN);
|
|
|
-
|
|
|
- /* parse packet for "\r\n\r\n" */
|
|
|
- for (i = 0; i < receivedBufLen; i++)
|
|
|
- {
|
|
|
- if (strncmp ((char*)(data+i), "\r\n\r\n", 4) == 0)
|
|
|
- {
|
|
|
- offset = i+4;
|
|
|
- //printf("offset: %d\r\n", (int)offset);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- req_data_received = receivedBufLen - offset;
|
|
|
- //printf("req data received: %d\r\n", (int)req_data_received);
|
|
|
-
|
|
|
- /* Check if "\r\n\r\n" was found */
|
|
|
- if (offset != 0) {
|
|
|
-
|
|
|
- /* if data was splited in two packets */
|
|
|
- if (req_data_received < post_data_count) {
|
|
|
- /* Copy request data to buffer */
|
|
|
- snprintf(post_req_data, req_data_received, "%s", receiveBuf);
|
|
|
- //printf("copied: %d\r\n", (int)req_data_received);
|
|
|
-
|
|
|
- post_data_count -= req_data_received;
|
|
|
- }
|
|
|
- /* if data received completely */
|
|
|
- else {
|
|
|
-
|
|
|
- strncat(post_req_data, (char *)(data + offset), post_data_count);
|
|
|
- //printf("post_req_data: %s\r\n", post_req_data);
|
|
|
-
|
|
|
- if (HTTP_ConfirmWebPwd(post_req_data, sendBuf, strlen(post_req_data), &sendBufLoadLen) == SEND_REQUIRED_YES) {
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- /* Redirect to login page */
|
|
|
- fs_open("/login.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
-
|
|
|
- /* End reqest */
|
|
|
- post_data_count = 0;
|
|
|
- log_post_reqn = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- /* request was fragmented before "\r\n\r\n" */
|
|
|
- else {
|
|
|
- //printf("no data found!\r\n");
|
|
|
-
|
|
|
- /* wait next packet */
|
|
|
- log_post_reqn++;
|
|
|
-
|
|
|
- /* wait max 2 requests */
|
|
|
- if (log_post_reqn > 1) {
|
|
|
- /* Redirect to login page */
|
|
|
- fs_open("/login.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
-
|
|
|
- /* End reqest */
|
|
|
- post_data_count = 0;
|
|
|
- log_post_reqn = 0;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- printf("Too long POST request!\r\n");
|
|
|
- /* Ignore request */
|
|
|
- post_data_count = 0;
|
|
|
- log_post_reqn = 0;
|
|
|
-
|
|
|
- /* Redirect to login page */
|
|
|
- fs_open("/login.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (post_data_count > 0)
|
|
|
- {
|
|
|
- strncat(post_req_data, data, post_data_count);
|
|
|
- //printf("copied: %d\r\n", (int)post_data_count);
|
|
|
- //printf("post_req_data: %s\r\n", post_req_data);
|
|
|
-
|
|
|
- if (HTTP_ConfirmWebPwd(post_req_data, sendBuf, strlen(post_req_data), &sendBufLoadLen) == SEND_REQUIRED_YES) {
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- /* Redirect to login page */
|
|
|
- fs_open("/login.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
-
|
|
|
- /* End reqest */
|
|
|
- post_data_count = 0;
|
|
|
- log_post_reqn = 0;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- fs_open("/login.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
+ char *data;
|
|
|
+ struct http_state *hs;
|
|
|
+ struct fs_file file = {0, 0};
|
|
|
|
|
|
- else if ( Authenticated == true ) {
|
|
|
+ hs = arg;
|
|
|
|
|
|
- if (strncmp(data, "GET /main.css", 13) == 0) // +
|
|
|
+ if (err == ERR_OK && p != NULL)
|
|
|
{
|
|
|
- fs_open("/main.css", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /rotek.png", 14) == 0) // +
|
|
|
- {
|
|
|
- fs_open("/rotek.png", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /favicon.ico", 16) == 0) // ?
|
|
|
- {
|
|
|
- fs_open("/favicon.ico", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /main.js", 12) == 0) // +
|
|
|
- {
|
|
|
- fs_open("/main.js", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
-
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /role.js", 12) == 0)
|
|
|
- {
|
|
|
- fs_open("/role.js", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
+ tcp_recved(pcb, p->tot_len);
|
|
|
+
|
|
|
+ if (hs->file == NULL)
|
|
|
+ {
|
|
|
+ data = p->payload;
|
|
|
+ /*
|
|
|
+ printLen = p->tot_len;
|
|
|
+ memcpy(printBuf, p->payload , printLen);
|
|
|
+ printf(printBuf);
|
|
|
+ */
|
|
|
+ receivedBufLen = p->tot_len;
|
|
|
+ memcpy(receiveBuf, p->payload , receivedBufLen);
|
|
|
+
|
|
|
+ // На производстве
|
|
|
+ if (strncmp(data, "GET /setProdate.cgi", 19) == 0)
|
|
|
+ {
|
|
|
+ HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /settings.html", 18) == 0) // +
|
|
|
- {
|
|
|
- HTTP_UpdateUserLoginTime(user_id);
|
|
|
- if (seclevel == 0){
|
|
|
- fs_open("/settings.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
+ hs->file = sendBuf;
|
|
|
+ hs->left = sendBufLoadLen;
|
|
|
send_data(pcb, hs);
|
|
|
tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else {
|
|
|
- fs_open("/index.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /info.html", 14) == 0) // +
|
|
|
- {
|
|
|
- HTTP_UpdateUserLoginTime(user_id);
|
|
|
- fs_open("/info.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /history.html", 17) == 0)
|
|
|
- {
|
|
|
- HTTP_UpdateUserLoginTime(user_id);
|
|
|
- fs_open("/history.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /ups_history.html", 21) == 0)
|
|
|
- {
|
|
|
- HTTP_UpdateUserLoginTime(user_id);
|
|
|
- fs_open("/ups_history.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /getJson.cgi", 16) == 0) // +
|
|
|
- {
|
|
|
- HTTP_GetParamsPage1(sendBuf);
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = strlen(sendBuf);
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /settings.cgi", 17) == 0) // +
|
|
|
- {
|
|
|
- if (seclevel == 0) {
|
|
|
- SET_PAGE = SET_PAGE_PAGE2;
|
|
|
- if (HTTP_SettingsPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen) == SEND_REQUIRED_YES)
|
|
|
- {
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /*else
|
|
|
- {
|
|
|
- fs_open("/settings.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }*/
|
|
|
- }
|
|
|
- }
|
|
|
- else if (strncmp(data, "POST /settings.cgi", 18) == 0 || (DataFlag2 >= 1))
|
|
|
- {
|
|
|
- if (seclevel == 0) {
|
|
|
- DataOffset = 0;
|
|
|
-
|
|
|
- /* POST Packet received */
|
|
|
- if (DataFlag2 == 0)
|
|
|
- {
|
|
|
- BrowserFlag = 0;
|
|
|
- TotalReceived = 0;
|
|
|
- memset(sendBuf, 0, strlen(sendBuf));
|
|
|
-
|
|
|
- /* parse packet for Content-length field */
|
|
|
- size = Parse_Content_Length(data, p->tot_len);
|
|
|
-
|
|
|
- /* parse packet for the octet-stream field */
|
|
|
- for (i = 0; i < receivedBufLen; i++)
|
|
|
- {
|
|
|
- if (strncmp ((char*)(data+i), "managerIP", 8)==0)
|
|
|
- {
|
|
|
- DataOffset = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- /* case of MSIE8 : we do not receive data in the POST packet*/
|
|
|
- if (DataOffset == 0)
|
|
|
- {
|
|
|
- DataFlag2++;
|
|
|
- BrowserFlag = 1;
|
|
|
- pbuf_free(p);
|
|
|
- return ERR_OK;
|
|
|
- }
|
|
|
- /* case of Mozilla Firefox v3.6 : we receive data in the POST packet*/
|
|
|
- else
|
|
|
- {
|
|
|
- //TotalReceived = receivedBufLen - (ContentLengthOffset + 4);
|
|
|
- TotalReceived = receivedBufLen - DataOffset;
|
|
|
- }
|
|
|
- }
|
|
|
- if (((DataFlag2 ==1)&&(BrowserFlag==1)) || ((DataFlag2 ==0)&&(BrowserFlag==0)))
|
|
|
- {
|
|
|
- if ((DataFlag2 ==0)&&(BrowserFlag==0))
|
|
|
- {
|
|
|
- DataFlag2++;
|
|
|
- }
|
|
|
- else if ((DataFlag2 ==1)&&(BrowserFlag==1))
|
|
|
- {
|
|
|
- /* parse packet for the octet-stream field */
|
|
|
- for (i = 0; i < receivedBufLen; i++)
|
|
|
- {
|
|
|
- if (strncmp ((char*)(data+i), "managerIP", 8)==0)
|
|
|
- {
|
|
|
- DataOffset = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- TotalReceived += receivedBufLen;
|
|
|
- DataFlag2++;
|
|
|
- }
|
|
|
- TotalData =0 ;
|
|
|
- }
|
|
|
- /* DataFlag >1 => the packet is data only */
|
|
|
- else
|
|
|
- {
|
|
|
- TotalReceived +=receivedBufLen;
|
|
|
- }
|
|
|
-
|
|
|
- ptr = (char*)(data + DataOffset);
|
|
|
- receivedBufLen-= DataOffset;
|
|
|
-
|
|
|
- /* update Total data received counter */
|
|
|
- TotalData +=receivedBufLen;
|
|
|
-
|
|
|
- /* check if last data packet */
|
|
|
- if (TotalReceived == size)
|
|
|
- {
|
|
|
- //DBG printf("State: Received %d bytes\r\n", (int)TotalReceived);
|
|
|
-
|
|
|
- strncat(sendBuf, ptr, receivedBufLen);
|
|
|
- strncat(sendBuf, " ", 1);
|
|
|
- //ВBG printf("receive %s /r/n", sendBuf);
|
|
|
- HTTP_SetSettings(sendBuf, strlen(sendBuf));
|
|
|
-
|
|
|
- DataFlag2=0;
|
|
|
- BrowserFlag = 0;
|
|
|
- memset(sendBuf, 0, size);
|
|
|
-
|
|
|
- strcpy(sendBuf, "HTTP/1.1 200 OK\r\n");
|
|
|
- strcat(sendBuf, "\r\n\r\n");
|
|
|
- strcat(sendBuf,"<!DOCTYPE html><html lang=""><head><meta http-equiv=\"refresh\" content=\"0;url=/settings.html\"/></head></html>\r\n\r\n");
|
|
|
-
|
|
|
- sendBufLoadLen = strlen(sendBuf);
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
-
|
|
|
- /* Tell TCP that we wish be to informed of data that has been
|
|
|
- successfully sent by a call to the http_sent() function. */
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* not last data packet */
|
|
|
- else
|
|
|
- {
|
|
|
- /* write data in flash */
|
|
|
- if(receivedBufLen)
|
|
|
- {
|
|
|
-
|
|
|
- strncat(sendBuf, ptr, receivedBufLen);
|
|
|
- //memcpy(receiveBufTemp, ptr, receivedBufLen);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /info.cgi", 13) == 0) // +
|
|
|
- {
|
|
|
- if (HTTP_InfoPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen) == SEND_REQUIRED_YES)
|
|
|
- {
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* else
|
|
|
- {
|
|
|
- fs_open("/info.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }*/
|
|
|
- }
|
|
|
- else if (strncmp(data, "POST /info.cgi", 14) == 0 || (DataFlag >= 1))
|
|
|
- {
|
|
|
- if (seclevel == 0) {
|
|
|
- DataOffset = 0;
|
|
|
-
|
|
|
- /* POST Packet received */
|
|
|
- if (DataFlag == 0)
|
|
|
- {
|
|
|
- BrowserFlag = 0;
|
|
|
- TotalReceived = 0;
|
|
|
- memset(sendBuf, 0, strlen(sendBuf));
|
|
|
-
|
|
|
- /* parse packet for Content-length field */
|
|
|
- size = Parse_Content_Length(data, p->tot_len);
|
|
|
-
|
|
|
- /* parse packet for the octet-stream field */
|
|
|
- for (i = 0; i < receivedBufLen; i++)
|
|
|
- {
|
|
|
- if (strncmp ((char*)(data+i), "owner", 5)==0)
|
|
|
- {
|
|
|
- DataOffset = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- /* case of MSIE8 : we do not receive data in the POST packet*/
|
|
|
- if (DataOffset == 0)
|
|
|
- {
|
|
|
- DataFlag++;
|
|
|
- BrowserFlag = 1;
|
|
|
- pbuf_free(p);
|
|
|
- return ERR_OK;
|
|
|
- }
|
|
|
- /* case of Mozilla Firefox v3.6 : we receive data in the POST packet*/
|
|
|
- else
|
|
|
- {
|
|
|
- //TotalReceived = receivedBufLen - (ContentLengthOffset + 4);
|
|
|
- TotalReceived = receivedBufLen - DataOffset;
|
|
|
- }
|
|
|
- }
|
|
|
- if (((DataFlag ==1)&&(BrowserFlag==1)) || ((DataFlag ==0)&&(BrowserFlag==0)))
|
|
|
- {
|
|
|
- if ((DataFlag ==0)&&(BrowserFlag==0))
|
|
|
- {
|
|
|
- DataFlag++;
|
|
|
- }
|
|
|
- else if ((DataFlag ==1)&&(BrowserFlag==1))
|
|
|
- {
|
|
|
- /* parse packet for the octet-stream field */
|
|
|
- for (i = 0; i < receivedBufLen; i++)
|
|
|
- {
|
|
|
- if (strncmp ((char*)(data+i), "owner", 5)==0)
|
|
|
- {
|
|
|
- DataOffset = i;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- TotalReceived += receivedBufLen;
|
|
|
- DataFlag++;
|
|
|
- }
|
|
|
- TotalData =0 ;
|
|
|
- }
|
|
|
- /* DataFlag >1 => the packet is data only */
|
|
|
- else
|
|
|
- {
|
|
|
- TotalReceived +=receivedBufLen;
|
|
|
- }
|
|
|
-
|
|
|
- ptr = (char*)(data + DataOffset);
|
|
|
- receivedBufLen-= DataOffset;
|
|
|
-
|
|
|
- /* update Total data received counter */
|
|
|
- TotalData +=receivedBufLen;
|
|
|
-
|
|
|
- /* check if last data packet */
|
|
|
- if (TotalReceived == size)
|
|
|
- {
|
|
|
-
|
|
|
- strncat(sendBuf, ptr, receivedBufLen);
|
|
|
- strncat(sendBuf, " ", 1);
|
|
|
- HTTP_SetInfo(sendBuf, strlen(sendBuf));
|
|
|
- DataFlag=0;
|
|
|
- BrowserFlag = 0;
|
|
|
- memset(sendBuf, 0, size);
|
|
|
-
|
|
|
- strcpy(sendBuf, "HTTP/1.1 200 OK\r\n");
|
|
|
- strcat(sendBuf, "\r\n\r\n");
|
|
|
- strcat(sendBuf,"<!DOCTYPE html><html lang=""><head><meta http-equiv=\"refresh\" content=\"0;url=/info.html\"/></head></html>\r\n\r\n");
|
|
|
-
|
|
|
- sendBufLoadLen = strlen(sendBuf);
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
-
|
|
|
- /* Tell TCP that we wish be to informed of data that has been
|
|
|
- successfully sent by a call to the http_sent() function. */
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* not last data packet */
|
|
|
- else
|
|
|
- {
|
|
|
- /* write data in flash */
|
|
|
- if(receivedBufLen)
|
|
|
- {
|
|
|
-
|
|
|
- strncat(sendBuf, ptr, receivedBufLen);
|
|
|
- //memcpy(receiveBufTemp, ptr, receivedBufLen);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- else if (strncmp(data, "GET /history.cgi", 16) == 0)
|
|
|
- {
|
|
|
- int res;
|
|
|
-
|
|
|
- res = HTTP_HistoryPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- if (res == SEND_REQUIRED_FILE)
|
|
|
- {
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent_history);
|
|
|
- tcp_err(pcb, http_sent_log_err);
|
|
|
- }
|
|
|
- else if (res == SEND_REQUIRED_YES) {
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
}
|
|
|
}
|
|
|
- else if (strncmp(data, "GET /ups_history.cgi", 19) == 0)
|
|
|
- {
|
|
|
- int res;
|
|
|
-
|
|
|
- res = HTTP_UpsHistoryPage(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- if (res == SEND_REQUIRED_FILE)
|
|
|
- {
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent_log);
|
|
|
- tcp_err(pcb, http_sent_log_err);
|
|
|
- }
|
|
|
- else if (res == SEND_REQUIRED_YES) {
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- }
|
|
|
- /* Тест АКБ ИБП */
|
|
|
- else if (strncmp(data, "GET /bat_test.cgi", 17) == 0)
|
|
|
- {
|
|
|
- HTTP_UPSTest(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* Выключение ИБП */
|
|
|
- else if (strncmp(data, "GET /ups_power.cgi", 18) == 0)
|
|
|
- {
|
|
|
- HTTP_UPSshutdown(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* Сброс настроек и сохранине */
|
|
|
- else if (strncmp(data, "GET /reset.cgi", 14) == 0)
|
|
|
- {
|
|
|
- HTTP_ResetSettings();
|
|
|
- HTTP_SaveSettings();
|
|
|
-
|
|
|
- fs_open("/settings.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* Перезагрузка контроллера */
|
|
|
- else if (strncmp(data, "GET /reboot.cgi", 15) == 0)
|
|
|
- {
|
|
|
- HTTP_Reboot();
|
|
|
- }
|
|
|
- /* Подтверждение новых сетевых настроек */
|
|
|
- else if (strncmp(data, "GET /confirm.cgi", 16) == 0)
|
|
|
- {
|
|
|
- SetWebReinitFlag(false);
|
|
|
- SetConfirmWebParamsFlag();
|
|
|
-
|
|
|
- fs_open("/index.html", &file);
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- /* Проверка пароля, переход в bootloader */
|
|
|
- else if (strncmp(data, "GET /fw_update.cgi", 18) == 0)
|
|
|
- {
|
|
|
- HTTP_ConfirmBootPwd(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
+ pbuf_free(p);
|
|
|
+ close_conn(pcb,hs);
|
|
|
}
|
|
|
- /* Смена пароля пользователя */
|
|
|
- else if (strncmp(data, "GET /changepwd.cgi", 18) == 0)
|
|
|
+ if (err == ERR_OK && p == NULL)
|
|
|
{
|
|
|
- HTTP_ChangeUserPwd(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- // На производстве
|
|
|
- else if (strncmp(data, "GET /setProdate.cgi", 19) == 0)
|
|
|
- {
|
|
|
- HTTP_Prodate(receiveBuf, sendBuf, receivedBufLen, &sendBufLoadLen);
|
|
|
-
|
|
|
- hs->file = sendBuf;
|
|
|
- hs->left = sendBufLoadLen;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- HTTP_UpdateUserLoginTime(user_id);
|
|
|
- fs_open("/index.html", &file); // +
|
|
|
- hs->file = file.data;
|
|
|
- hs->left = file.len;
|
|
|
- send_data(pcb, hs);
|
|
|
- tcp_sent(pcb, http_sent);
|
|
|
+ close_conn(pcb, hs);
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
- pbuf_free(p);
|
|
|
- // close_conn(pcb,hs);
|
|
|
- }
|
|
|
-/* if (err == ERR_OK && p == NULL)
|
|
|
- {
|
|
|
- close_conn(pcb, hs);
|
|
|
- }*/
|
|
|
- return ERR_OK;
|
|
|
-}
|
|
|
+ return ERR_OK;
|
|
|
+}
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -1182,15 +465,16 @@ void HTTP_Init()
|
|
|
pcb = tcp_listen(pcb);
|
|
|
/* define callback function for TCP connection setup */
|
|
|
tcp_accept(pcb, http_accept);
|
|
|
- for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
|
|
|
- /* Flush user cookie by random value */
|
|
|
+/* for (user_id = 0; user_id < MAX_WEB_USERS; user_id++) {
|
|
|
+ //Flush user cookie by random value
|
|
|
sprintf(buf, "%X", (unsigned int)GetRandomNumber());
|
|
|
HTTP_SetUserCookie(buf, user_id);
|
|
|
|
|
|
- /* Create user logout timers */
|
|
|
+ // Create user logout timers
|
|
|
users[user_id].LogoutTimer =
|
|
|
xTimerCreate("LogoutTmr", WEB_LOGOUT_TIME, pdFALSE, ( void * ) user_id, LogoutTimerCallback);
|
|
|
}
|
|
|
+ */
|
|
|
}
|
|
|
|
|
|
/**
|