/* Example Ex14-02.C */ #include <stdio.h> /* Ç¥ÁØ Çì´õÆÄÀÏ */ #include <stdlib.h> /* getenv() ÇÔ¼ö µîÀÇ Çì´õÆÄÀÏ */ #include <string.h> /* ¹®ÀÚ¿ ÇÔ¼ö Çì´õÆÄÀÏ */ #define MAX 1000 /* ÀԷº¯¼ö°¡ ÃÖ´ë 1000°³·Î °¡Á¤ */
typedef struct { /* entry ¶ó´Â ±¸Á¶Ã¼ÇüÀ» ¼±¾ð */ char *name; /* º¯¼ö¸í; INPUT¹®¿¡¼ÀÇ name */ char *val; /* °ª; INPUT¹®¿¡¼ÀÇ value */ } entry;
int nEntries; /* ½ÇÁ¦ ÀԷ°ªÀÇ °³¼ö¸¦ ´ãÀ» º¯¼ö */ entry entries[MAX]; /* entryÇüÀÇ entries ¹è¿º¯¼ö ¼±¾ð */ void getEntries(); /* º¯¼ö ¹× °ª ÀÔ·Â ÇÔ¼ö */ void printout(); /* º¯¼ö ¹× °ª Ãâ·Â ÇÔ¼ö */ char *makeword (char *, char); /* º¯¼ö¿Í °ª ºÐ¸®ÇÔ¼ö */ char *fmakeword(FILE *, char, int *); /* º¯¼ö¿Í °ªÀÇ ½ÖÀ» ¸¸µê */ char *qURLdecode(char *); /* ÇÑ±Û DECODE ÇÔ¼ö */ char _x2c(char, char); /* 16Áø¼ö Á¶ÇÕ ÇÔ¼ö */
void file(char** id, char** password);
main() { getEntries(); /* ¸Å°³º¯¼ö¸¦ Àü´Þ¹ÞÀ½ */ printout(); /* ȸéÃâ·Â ÇÔ¼ö¸¦ È£Ãâ */ return 0; }
void getEntries() { register int x, m=0; int cl;
/* FORM¿¡¼ METHOD=POST·Î ÁöÁ¤µÇ¾ú´ÂÁö È®ÀÎ */ if(strcmp(getenv("REQUEST_METHOD"), "POST")) { printf("ÀÌ ÇÁ·Î±×·¥À» ½ÇÇà½ÃÅ°·Á¸é FORM¹®¿¡¼ "); printf("POST ¹æ½ÄÀ» ÁöÁ¤Çؾ߸¸ ÇÕ´Ï´Ù.\n"); exit(1); } /* TYPEÀº application/x-www-form-urlencoded À̾î¾ß ÇÔ */ if (strcmp(getenv("CONTENT_TYPE"), "application/x-www-form-urlencoded")) { printf("ÀÌ ÇÁ·Î±×·¥Àº FORMÀÇ °á°ú¸¦ "); printf("Çؼ®Çϱâ À§Çؼ¸¸ »ç¿ëµË´Ï´Ù.\n"); exit(1); } /* ÀԷµǴ º¯¼ö¿Í °ªÀÇ ±æÀ̸¦ ¹Þ¾ÆµéÀÓ */ cl=atoi(getenv("CONTENT_LENGTH"));
/* stdinÀ¸·Î ÀԷµǴ ¹®ÀÚ¿À» º¯¼ö¿Í °ªÀ¸·Î À߶󳻾î entries ±¸Á¶Ã¼¿¡ ÀúÀå */ for(x=0; cl && (!feof(stdin)); x++) { m=x; entries[x].val=fmakeword(stdin, '&', &cl); entries[x].name=makeword(entries[x].val, '='); } nEntries=m+1;
/* 16Áø¼ö·Î ÄÚµåÈµÈ ÇѱÛÀ» ¿ø»óÅ·Πº¹¿ø */ for (x=0; x<nEntries; x++) { qURLdecode(entries[x].name); qURLdecode(entries[x].val); } }
char *fmakeword(FILE *f, char stop, int *cl) { int wsize=102400, ll=0; char *word=(char *) malloc(sizeof(char) * (wsize+1)); /* º¯¼ö¿Í °ªÀÇ ½ÖÀ¸·Î Àü¼Û ¹®ÀÚ¿À» Àß¶ó³¿ */ while(1) { word[ll]=(char) fgetc(f); if(ll==wsize) { word[ll+1]='\0'; wsize+=102400; word=(char *) realloc(word,sizeof(char)*(wsize+1)); } --(*cl); if((word[ll]==stop) || (feof(f)) || (!(*cl))) { if(word[ll] != stop) ll++; word[ll]='\0'; return word; } ++ll; } }
char *makeword(char *line, char stop) { int x=0, y=0; char *word=(char *) malloc(sizeof(char) * (strlen(line)+1)); for(x=0; ((line[x]) && (line[x] != stop)); x++) word[x]=line[x]; word[x]='\0'; if (line[x]) ++x; while(line[y++]=line[x++]); return word; }
char *qURLdecode(char *str) { int i, j; if(!str) return; for(i=j=0; str[j]; i++, j++) switch(str[j]){ /* ´õÇϱâ(+) ±âÈ£¸¦ °ø¹é(' ')À¸·Î º¯È¯ */ case '+': str[i]=' '; break; /* '%'·Î ½ÃÀ۵Ǵ µÎ ¹®ÀÚ¸¦ ÇÑ±Û ÇѱÛÀÚ·Î º¯È¯ */ case '%': str[i]=_x2c(str[j+1], str[j+2]); j+=2; break; } str[i]='\0'; return str; }
char _x2c(char hex_up, char hex_low) { char digit; /* µÎ °³ÀÇ 16Áø¼ö °ªÀ» ÇϳªÀÇ 16Áø¼ö °ªÀ¸·Î º¯È¯ÇÑ´Ù */ digit = 16 * (hex_up >= 'A' ? ((hex_up & 0xdf) - 'A') + 10 : (hex_up - '0')); digit += (hex_low >= 'A' ? ((hex_low & 0xdf) - 'A') + 10 : (hex_low - '0')); return (digit); }
void printout() { FILE *fp; char* id; char* password;
id = malloc(10 * sizeof(char)); password = malloc(10 * sizeof(char));
file(&id, &password); /* Ãâ·ÂµÇ´Â ³»¿ëÀÌ ÅؽºÆ® ÇüÅÂÀÇ HTML ¹®ÀåÀÓÀ» ¾Ë·ÁÁÖ¸ç, ÀÌÈķδ printf()¹® ³»¿¡ HTML ¸í·ÉÀ» ±â¼úÇÑ´Ù */ printf("Content-type: text/html%c%c", 10, 10); printf("<HTML>\n"); printf("<HEAD>\n"); printf(" <TITLE> ÆĶó¸ÞÅ͵éÀÇ °ªÀ» Ãâ·ÂÇÔ </TITLE>\n"); printf("</HEAD>\n"); if(strcmp(id, entries[0].val)==0) //¾ÆÀ̵ð ¸í { if(strcmp(password, entries[1].val)==0) //ºñ¹Ð¹øÈ£ { printf("<BODY>\n"); printf("<script language=\"javascript\">\n"); printf("location.href=\"../1.html\"\n"); } else if(strcmp(password, entries[1].val)!=0) //ºñ¹Ð¹øÈ£ { printf("<BODY>\n"); printf("<script language=\"javascript\">\n"); printf("location.href=\"../index.html\"\n"); } } else if(strcmp(id, entries[0].val)!=0) //¾ÆÀ̵ð ¸í { printf("<BODY>\n"); printf("<script language=\"javascript\">\n"); printf("location.href=\"../index.html\"\n"); }
printf("</script>\n"); printf("</BODY>\n"); printf("</HTML>\n"); free(password); free(id); }
void file(char** id, char** password) { FILE *input; input = fopen("../¾ÆÀ̵ðÇÏ°í¾ÏÈ£.txt", "rt");//ÆÄÀÏÀбâ// ../ <--ÀÌ°ÍÀº »óÀ§Æú´õ ¸®´ª½º¿¡¼
fscanf(input, "%s", *id); fscanf(input, "%s", *password); fclose(input); }
=========================================================================
ÈÞ °Ü¿ìÇß½À´Ï´Ù.. ¾Æ¹«µµ ¾È¾Ë·ÁÁ༠À̸®Àú¸® ÇÏ´Ù°¡ °ÜÀ¯ ÇßÁÒ....¤Ñ.¤Ñ; °á±¹ ¹®¹ý¹®Á¦ ¿´½À´Ï´Ù.
ÀÌ·±¾¿À¸·ÎÇÏ¸é ·Î±×ÀÎ ÀÎÁõÁ¤º¸¸¦ ¼û±æ¼ö°¡ ÀÖ½À´Ï´Ù.....(¹°·Ð Á¦»ý°¢...)
Àú°°ÀÌ »ý°í»ýÇϽôºÐÀÌ ¾ø±æ¹Ù¶ó¸é¼.. Âü°íµé Çϼſ°
|