int cgiMain() { /* Send the content type, letting the browser know this is HTML */ cgiHeaderContentType("text/html;charset=gb2312"); /* Top of the page */ fprintf(cgiOut, "<HTML><HEAD>\n"); fprintf(cgiOut, "<TITLE>NC600 Web Server</TITLE>\n"); print_css(); print_backgrounf(); fprintf(cgiOut, "</HEAD><BODY>\n"); get_user(name, passwd); if(cgiFormSubmitClicked("host") == cgiFormSuccess) { char o_name[16]="", o_passwd[16]="", n_name[16]="", n_passwd[16]="", nck_passwd[16]=""; getformstrchar("name", o_name, 16); getformstrchar("passwd", o_passwd, 16); getformstrchar("n_name", n_name, 16); getformstrchar("n_passwd", n_passwd, 16); getformstrchar("nck_passwd", nck_passwd, 16); printf("[%s]\t[%s]\t[%s]\t[%s]\t[%s]\n", o_name, o_passwd, n_name, n_passwd, nck_passwd); printf("[%s]\t[%s]\t[%s]\n", name, passwd, (char*)crypt(o_passwd, "NC600")); if((strcmp(name, o_name) == 0) && (strcmp(passwd, (char*)crypt(o_passwd, "NC600")) == 0) && (strcmp(n_passwd, nck_passwd) == 0)) { set_user(n_name, n_passwd); get_user(name, passwd); fprintf(cgiOut, "<script type=\"text/javascript\">\n"); fprintf(cgiOut, "window.alert(\"口令修改成功!\");\n"); fprintf(cgiOut, "</script>\n"); } else { fprintf(cgiOut, "<script type=\"text/javascript\">\n"); fprintf(cgiOut, "window.alert(\"口令修改失败!\");\n"); fprintf(cgiOut, "</script>\n"); } } ShowForm(); fprintf(cgiOut, "</BODY></HTML>\n"); return 0; }
int main() { init(); FILE *fp = fopen("home.css","r"); if(fp == NULL) { printf("%s","打开文件失败"); return 1; } char buf[10000]; char value[10000]; char keys[100000]; int line_number = 0; int desciption_type = END_DESCIRP; bool desciption_begin = false; int bracket_type = END_DESCIRP; int latst_bracket_type = RIGHT_BRACKET; int count = 0; while(fgets(buf,sizeof(buf),fp)!=NULL) { line_number++; bool has_key = false; bool has_value = false; str_trim(buf); if(strlen(buf) ==0) { continue; } desciption_type = is_desciption(buf); if(desciption_type == BEGIN_DESCIRP) { desciption_begin = true; continue; } else if(desciption_type == END_DESCIRP ) { desciption_begin = false; continue; } else { if(desciption_begin) { continue; } } bracket_type = deal_bracket(buf); if(bracket_type == LEFT_BRACKET) { if(strlen(buf) <= 1) { latst_bracket_type = LEFT_BRACKET; continue; } else { strcatN(keys, buf, strlen(buf)-1); } } else if(bracket_type == RIGHT_BRACKET) { count++; deal_keys_value(keys, value,count, line_number); memset(keys,0,10000); memset(value,0,10000); } else { if(latst_bracket_type == RIGHT_BRACKET) { strcatN(keys, buf, strlen(buf)); } else if(latst_bracket_type == LEFT_BRACKET) { strcatN(value, buf, strlen(buf)); } } if(bracket_type != NO_BRACKET) { latst_bracket_type = bracket_type; } } sort_value(); print_css(); printf("_______________%s_______________","处理完毕"); system("pause"); return 0; }