Code: Alles auswählen
***************************************************************************
Änderungen in httpd.c
__________________________________________________________________________
//Hier wird das codierte Passwort aus config.h gespeichert.
unsigned char http_auth_passwort_1[30];
unsigned char http_auth_passwort_2[30];
//---------------------------------------------------------------------------------------------------------------------
//Initialisierung des Httpd Testservers
void httpd_init (void)
{
decode_base64((unsigned char*)HTTP_AUTH_STRING_1,http_auth_passwort_1);
decode_base64((unsigned char*)HTTP_AUTH_STRING_2,http_auth_passwort_2);
//Serverport und Anwendung eintragen
add_tcp_app (HTTPD_PORT, (void(*)(unsigned char))httpd);
}
//----------------------------------------------------------------------------
//HTTPD_STACK löschen
void httpd_stack_clear (unsigned char index)
{
http_entry[index].http_header_type = 0;
http_entry[index].first_switch = 0;
http_entry[index].http_auth_1 = HTTP_AUTH_DEFAULT_1;
http_entry[index].http_auth_2 = HTTP_AUTH_DEFAULT_2;
http_entry[index].new_page_pointer = 0;
http_entry[index].old_page_pointer = 0;
http_entry[index].post = 0;
http_entry[index].auth_ptr_1 = http_auth_passwort_1;
http_entry[index].auth_ptr_2 = http_auth_passwort_2;
http_entry[index].post_ptr = post_in;
http_entry[index].post_ready_ptr = post_ready;
http_entry[index].hdr_end_pointer = rx_header_end;
HTTP_DEBUG("\r\n**** NEUE HTTP ANFORDERUNG ****\r\n\r\n");
return;
}
//----------------------------------------------------------------------------
//Eintreffenden Header vom Client checken
void httpd_header_check (unsigned char index)
{
unsigned int a = 0;
if(strcasestr_P((char*)ð_buffer[TCP_DATA_START_VAR],PSTR("POST"))!=0)
{
http_entry[index].post = 1;
}
//finden der Authorization und das Ende im Header auch über mehrere Packete hinweg!!
if(*http_entry[index].hdr_end_pointer != 0)
{
for(a=TCP_DATA_START_VAR;a<(TCP_DATA_END_VAR);a++)
{
HTTP_DEBUG("%c",eth_buffer[a]);
if(!http_entry[index].http_auth_1)
{
if (eth_buffer[a] != *http_entry[index].auth_ptr_1++)
{
http_entry[index].auth_ptr_1 = http_auth_passwort_1;
}
if(*http_entry[index].auth_ptr_1 == 0)
{
http_entry[index].http_auth_1 = 1;
HTTP_DEBUG(" <---LOGIN OK!--->\r\n");
}
}
if(!http_entry[index].http_auth_2)
{
if (eth_buffer[a] != *http_entry[index].auth_ptr_2++)
{
http_entry[index].auth_ptr_2 = http_auth_passwort_2;
}
if(*http_entry[index].auth_ptr_2 == 0)
{
http_entry[index].http_auth_2 = 1;
HTTP_DEBUG(" <---LOGIN OK!--->\r\n");
}
}
if (eth_buffer[a] != *http_entry[index].hdr_end_pointer++)
{
http_entry[index].hdr_end_pointer = rx_header_end;
}
//Das Headerende wird mit (CR+LF+CR+LF) angezeigt!
if(*http_entry[index].hdr_end_pointer == 0)
{
HTTP_DEBUG("<---HEADER ENDE ERREICHT!--->\r\n");
break;
}
}
}
….
}
//----------------------------------------------------------------------------
//Wurde ein Passwort in den ganzen Headerpacketen gefunden?
//Wenn nicht dann ausführen und Passwort anfordern!
if(((!http_entry[index].http_auth_2) && tcp_entry[index].status&PSH_FLAG) && ((!http_entry[index].http_auth_1) && tcp_entry[index].status&PSH_FLAG))
{
//HTTP_AUTH_Header senden!
http_entry[index].new_page_pointer = Page0;
memcpy_P((char*)ð_buffer[TCP_DATA_START_VAR],http_header2,(sizeof(http_header2)-1));
tcp_entry[index].status = ACK_FLAG | PSH_FLAG;
create_new_tcp_packet((sizeof(http_header2)-1),index);
tcp_entry[index].app_status = 2;
return;
}
if(((!http_entry[index].http_auth_1) && tcp_entry[index].status&PSH_FLAG) && (http_entry[index].new_page_pointer))
{
//HTTP_AUTH_Header senden!
http_entry[index].new_page_pointer = Page0;
memcpy_P((char*)ð_buffer[TCP_DATA_START_VAR],http_header2,(sizeof(http_header2)-1));
tcp_entry[index].status = ACK_FLAG | PSH_FLAG;
create_new_tcp_packet((sizeof(http_header2)-1),index);
tcp_entry[index].app_status = 2;
return;
}
//Standard INDEX.HTM Seite wenn keine andere gefunden wurde
if (!http_entry[index].new_page_pointer)
{
http_entry[index].new_page_pointer = Page1;
http_entry[index].http_header_type = TEXT_HTML;
}
tcp_entry[index].app_status = 2;
/*
//Passwort wurde im Header nicht gefunden
if((!http_entry[index].http_auth) && (http_entry[index].new_page_pointer))
{
http_entry[index].new_page_pointer = Page0;
}
*/
**************************************************************
Änderungen in httpd.h
---------------------------------------------------------------------------------------------------
struct http_table
{
PGM_P old_page_pointer ;
PGM_P new_page_pointer ;
unsigned char *auth_ptr_1 ;
unsigned char *auth_ptr_2 ;
unsigned char *hdr_end_pointer ;
unsigned char http_auth_1 : 1 ;
unsigned char http_auth_2 : 1 ;
unsigned char http_header_type : 3 ;
unsigned char first_switch : 1 ;
unsigned char post : 1 ;
unsigned char *post_ptr ;
unsigned char *post_ready_ptr ;
};
------------------------------------------------------------------------------------------------------
****************************************************************
Änderungen in config.h
_________________________________________________________________
//Webserver mit Passwort? (0 == mit Passwort)
#define HTTP_AUTH_DEFAULT_1 0
#define HTTP_AUTH_DEFAULT_2 0
//AUTH String "USERNAME1:PASSWORT1" max 14Zeichen für Username1:Passwort1
#define HTTP_AUTH_STRING_1 "admin1:admin1"
//AUTH String "USERNAME2:PASSWORT2" max 14Zeichen für Username2:Passwort2
#define HTTP_AUTH_STRING_2 "admin2:admin2"
_________________________________________________________________
TPB hat geschrieben:@Andi
Ich bin wirklich kein C Spezialist, aber ich habe das mit den Passwörten beim ETH_M32_EX für zwei verschiedene Seiten so gelöst.
Achtung, das ist nicht der vollständige Code, sondern nur die Stellen an den Änderungen vorgenommen wurden. Bitte selbst raussuchen wo das genau ist.
code...
Vielleicht hilft es dir.
Viele Erfolg!
Gruß
Tom
Code: Alles auswählen
void httpd_header_check (unsigned char index)
{
int a = 0;
// 14.04.2012 BN #008 keine Authentifizierung, wenn hausinterne IP
if(( (unsigned char)IP_INTERN_1 == (unsigned char)eth_buffer[IP_OFFSET+12])&&
((unsigned char)IP_INTERN_2 == (unsigned char)eth_buffer[IP_OFFSET+13])&&
((unsigned char)IP_INTERN_3 == (unsigned char)eth_buffer[IP_OFFSET+14]))
{
http_entry[index].http_auth = 1; // Keine Authentifikation wenn hausinterner IP-Bereich
}