#include <stdio.h>
#include "cgi.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <string.h>
#include "isip.h"
#include "global.h"
//#define IPMAXLEN 3;
//#define MAXLEN 4*IPMAXLEN+3;
int CheckIp(char *param){
int re1;
int re2;
int re3;
int re4;
char **arr;
int nums;
arr=explode(param,".",&nums);
//nums=sizeof(arr);
if(nums==4){
re1=IsIp(arr[0]);
re2=IsIp(arr[1]);
re3=IsIp(arr[2]);
re4=IsIp(arr[3]);
if(re1==0 || re2==0 || re3==0 || re4==0){
return 0;
}
else{
return 1;
}
}
else{
return 0;
}
}
int main(void)
{
char *netmask;
char *gataway;
char *dns;
char *ip1;
char *ip2;
char *ip3;
char *ip4;
int r1;
int r2;
int r3;
int p1;
int p2;
int p3;
int p4;
FILE *fp;
char *str;
//checkpower();
cgi_init();
cgi_init_headers();
cgi_process_form();
cgi_include("sysjb_style.inc");
puts("<table width='780' border='0'align='center' bgcolor='#43668B'>"
"<tr>"
"<td colspan='3'>"
);
cgi_include("head.inc");
puts("</td>"
"</tr>"
"<tr>"
"<td height='3' colspan='3'>"
" "
"</td>"
"</tr>"
"<tr>"
"<td width='144' rowspan='3'>"
);
cgi_include("left.inc");
puts("</td>"
"<td height='22' width='650' colspan='2'bgcolor='#43668B'>"
">>系统设置--系统基本设置"
"</td>"
"</tr>"
"<tr>"
"<td width='0'>"
" "
"</td>"
"<td width='650'>");
puts("<table width='500'border='0'align='center'cellpadding='0'cellspacing='0'>"
"<form action='sysjb.cgi' method='pos' name='FrontPage_Form1'>");
if(cgi_param("Submit")){
netmask=cgi_param("netmask");
gataway=cgi_param("gataway");
dns=cgi_param("dns");
ip1=cgi_param("ip1");
ip2=cgi_param("ip2");
ip3=cgi_param("ip3");
ip4=cgi_param("ip4");
r1=CheckIp(netmask);
r2=CheckIp(gataway);
r3=CheckIp(dns);
p1=IsIp(ip1);
p2=IsIp(ip2);
p3=IsIp(ip3);
p4=IsIp(ip4);
if(p1!=0 &&p2!=0 && p3!=0&& p4!=0){
fp=fopen("dat\\ip.dat","w");
str=strcat(ip1,".");
str=strcat(str,ip2);
str=strcat(str,".");
str=strcat(str,ip3);
str=strcat(str,".");
str=strcat(str,ip4);
fputs(str,fp);
fclose(fp);
}
if(r1!=0){
fp=fopen("dat\\netmask.dat","w");
str=netmask;
str=str_replace(str," ","");
fputs(str,fp);
fclose(fp);
}
if(r2!=0){
fp=fopen("dat\\gataway.dat","w");
str=gataway;
str=str_replace(str," ","");
fputs(str,fp);
fclose(fp);
}
if(r3!=0){
fp=fopen("dat\\dns.dat","w");
str=dns;
str=str_replace(str," ","");
fputs(str,fp);
fclose(fp);
}
//system("/usr/local/apache/htdocs/changeip.sh");
puts("<tr>""<tdalign='center' colspan='2'>IP地址配置");
puts("</td>""</tr>");
puts("<tr>"
"<td width='120' bgcolor='#43668B'align='right'>IP地址 :</td>");
puts("<td colspan='2' align='left'bgcolor='#43668B'>");
puts("<input name=ip1 type=text class='line'size='3' maxlength='3' value=");
printf ("'%s'",ip1);
puts(">.");
puts("<input type=text class='line' name=ip2size='3' maxlength='3' value=");
printf("'%s'",ip2);
puts(">.");
puts("<input type=text class='line' name=ip3size='3' maxlength='3' value=");
printf("'%s'",ip3);
puts(">.");
puts("<input type=text class='line' name=ip4size='3' maxlength='3' value=");
printf("'%s'",ip4);
puts(">");
puts("</td>"
"</tr>"
"<tr>"
"<td bgcolor='#43668B' align='right'width='120'>子网掩码:</td>"
"<td colspan='2' align='left'bgcolor='#43668B'>"
"<input name='netmask'type='text' class='line' id='netmask' size='18' maxlength='15'value=");
printf("'%s'",netmask);
puts(">");
puts("</td>"
"</tr>"
"<tr>"
"<td bgcolor='#43668B'align='right'width='120'>网 关 :</td>"
"<td colspan='2' align='left'bgcolor='#43668B'>"
"<input name='gataway' type='text'class='line' id='gataway' size='18' maxlength='15' value=");
printf("%s",gataway);
puts(">");
puts("</td>"