Code: Select all
bool SetIPHandler(int sock, char *url, char *pData, char *rxBuffer)
{
char ippart1[20], ippart2[20], ippart3[20], ippart4[20];
char ip[20];
ConfigRecord *cr = RawGetConfig(0);
ConfigRecord NewRec;
// IP Address
int res = ExtractPostData("ipaddr1",pData,ippart1,20);
if( res <= 0 ) return false;
res = ExtractPostData("ipaddr2",pData,ippart2,20);
if( res <= 0 ) return false;
res = ExtractPostData("ipaddr3",pData,ippart3,20);
if( res <= 0 ) return false;
res = ExtractPostData("ipaddr4",pData,ippart4,20);
if( res <= 0 ) return false;
sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
NewRec.ip_Addr = AsciiToIp( ip );
// Netmask
res = ExtractPostData("netmask1",pData,ippart1,20);
if( res <= 0 ) return false;
res = ExtractPostData("netmask2",pData,ippart2,20);
if( res <= 0 ) return false;
res = ExtractPostData("netmask3",pData,ippart3,20);
if( res <= 0 ) return false;
res = ExtractPostData("netmask4",pData,ippart4,20);
if( res <= 0 ) return false;
sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
NewRec.ip_Mask = AsciiToIp( ip );
// Gateway
res = ExtractPostData("ipgate1",pData,ippart1,20);
if( res <= 0 ) return false;
res = ExtractPostData("ipgate2",pData,ippart2,20);
if( res <= 0 ) return false;
res = ExtractPostData("ipgate3",pData,ippart3,20);
if( res <= 0 ) return false;
res = ExtractPostData("ipgate4",pData,ippart4,20);
if( res <= 0 ) return false;
sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
NewRec.ip_GateWay = AsciiToIp( ip );
// DNS
res = ExtractPostData("dns1",pData,ippart1,20);
if( res <= 0 ) return false;
res = ExtractPostData("dns2",pData,ippart2,20);
if( res <= 0 ) return false;
res = ExtractPostData("dns3",pData,ippart3,20);
if( res <= 0 ) return false;
res = ExtractPostData("dns4",pData,ippart4,20);
if( res <= 0 ) return false;
sprintf(ip,"%s.%s.%s.%s",ippart1,ippart2,ippart3,ippart4);
NewRec.ip_DNS_server = AsciiToIp( ip );
dbprintf("Old Settings:\r\n");
dbprintf(" IP: %s\r\n", IPtoAscii(cr->ip_Addr));
dbprintf(" Mask: %s\r\n", IPtoAscii(cr->ip_Mask));
dbprintf(" Gate: %s\r\n", IPtoAscii(cr->ip_GateWay));
dbprintf(" DNS : %s\r\n", IPtoAscii(cr->ip_DNS_server));
// Write new values to Flash system configuration sector
UpdateConfigRecord_Num(&NewRec, 0);
dbprintf("New Settings:\r\n");
dbprintf(" IP: %s\r\n", IPtoAscii(cr->ip_Addr));
dbprintf(" Mask: %s\r\n", IPtoAscii(cr->ip_Mask));
dbprintf(" Gate: %s\r\n", IPtoAscii(cr->ip_GateWay));
dbprintf(" DNS : %s\r\n", IPtoAscii(cr->ip_DNS_server));
return true;
}
if( SetIPHandler(sock,url,pData,rxBuffer) == true )
{
OSTimeDly( TICKS_PER_SECOND * 2 );
//RedirectResponse( sock, "lriipok.htm" );
ForceReboot();
}
else
{
//OSTimeDly( TICKS_PER_SECOND * 2 );
RedirectResponse( sock, "lriipfail.htm" );
}