diff options
Diffstat (limited to 'ws2a/bugcomment.c')
| -rw-r--r-- | ws2a/bugcomment.c | 186 |
1 files changed, 0 insertions, 186 deletions
diff --git a/ws2a/bugcomment.c b/ws2a/bugcomment.c deleted file mode 100644 index 38dd97d..0000000 --- a/ws2a/bugcomment.c +++ /dev/null @@ -1,186 +0,0 @@ -#include <stdio.h> -#include <string.h> -#include <stdlib.h> -#include <stdint.h> - -char* replaceHTML(char* str){ - printf("Replaceing:%s\n",str); - char* nstr = malloc((sizeof(char)*strlen(str)) + 1); - if(nstr == NULL){ - printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); - printf("Failed to allocate memory!\n"); - } - - int strp = 0; - int nstrp = 0; - while(str[strp] != '\0'){ - //printf("Strp=%d nstrp=%d\n",strp,nstrp); - if(str[strp] == '+'){ - nstr[nstrp] = ' '; - strp++; - nstrp++; - }else if(str[strp] == '%'){ - //printf("Hit encodeing!\n"); - int hex = 0; - sscanf(str+strp,"%%%2x",&hex); - //printf("Was:%c(%d)\n",(char)hex,hex); - if(hex == 0x0D){ - strp+=3; - continue; - } - if(hex == 0x0A){ - nstr[nstrp] = '\\'; - nstr[nstrp+1] = 'n'; - nstrp+=2; - strp+=3; - continue; - } - nstr[nstrp] = (char)hex; - nstrp++; - strp+=3; - }else if(str[strp] == '\n'){ - nstr[nstrp] = '\\'; - nstr[nstrp+1] = 'n'; - nstrp+=2; - strp++; - }else{ - nstr[nstrp] = str[strp]; - nstrp++; - strp++; - } - } - nstr[nstrp] = '\0'; - printf("Done, str is now:%s\n",nstr); - return nstr; -} - -unsigned long hash(unsigned char *str){ - unsigned long hash = 5381; - int c; - - while (c = *str++) - hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ - - return hash; -} - -char* useridhash(char* str){ - printf("useridhash\n"); - char* hash = calloc(sizeof(char)*20,sizeof(char)); - int i = (int)str[0]; - int len = strlen(str); - int tloop = i*20; - unsigned int hashp = 0; - unsigned int strp = 0; - i = 0; - while(i < tloop){ - //printf("i:%d hashp:%u strp:%u tloop:%d\n",i,hashp,strp,tloop); - char tchar = str[strp%len]; - hash[hashp%20] += str[strp%len]; - str[strp%len]+=1; - hashp+=(int)tchar; - strp+=(int)(hashp*hashp); - i++; - } - i = 0; - //printf("Before characterizeing the hash, it was: %s\n",hash); - while(i < 20){ - //printf("Normalizeing %c(%u) as %c(%u)\n",hash[i],(unsigned int)hash[i],(hash[i] % 92) + 32,(hash[i] % 92) + 32); - unsigned int hashnum = hash[i]; - unsigned int modedhashnum = hashnum % 92; - //printf("hashnum was %u, after mod it is:%u\n",hashnum,modedhashnum); - hash[i] = modedhashnum + 32; - i++; - } - printf("Resulting hash was:%s\n",hash); - return hash; -} - -int main(){ - char* data = getenv("QUERY_STRING"); - //char data[20] = "?id=1"; - char* hardip = getenv("REMOTE_ADDR"); - //char data[] = "name=Apickx&id=test&comment=Can+I+comment+on+other+bugs%3F&captcha=clean+night&bugid=7"; - - char name[15]; - char userid[20]; - char comment[2048]; - char captcha[30]; - char bugid[5]; - - char* iname = strtok(data,"&"); - char* iuserid = strtok(NULL,"&"); - char* icomment = strtok(NULL,"&"); - char* icaptcha = strtok(NULL,"&"); - char* ibugid = strtok(NULL,"&"); - - sscanf(iname,"name=%s",name); - sscanf(iuserid,"id=%s",userid); - sscanf(icomment,"comment=%s",comment); - sscanf(icaptcha,"captcha=%s",captcha); - sscanf(ibugid,"bugid=%s",bugid); - - /* - char* name = "Apickx"; - char* userid = "ThestID"; - char* comment = "This+Is+My+Comment"; - char* captcha = "teeny-tiny+currency"; - char* bugid = "1"; - */ - - //printf("<p>name:%s<p>userid:%s<p>comment:%s<p>captcha:%s<p>bugid:%s",name,userid,comment,captcha,bugid); - - //Check captcha - char captchapath[100]; - char* captchadecoded = replaceHTML(captcha); - sprintf(captchapath,"../ws2a/captchas/%s.txt",captchadecoded); - //printf("Generated path...\n"); - FILE* captchafile = fopen(captchapath,"r"); - if(captchafile == NULL){ - printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); - printf("Captcha incorrect"); - return; - } - //Hash of "teeny-tiny currency" is 2053680550 - unsigned long inputhash = hash(captchadecoded); - free(captchadecoded); - unsigned long filehash = 0; - fscanf(captchafile,"%lu",&filehash); - if(filehash != inputhash){ - printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); - printf("Captcha incorrect"); - return; - } - fclose(captchafile); - char command[100]; - sprintf(command,"rm \"%s\"",captchapath); - system(command); - //printf("After first command\n"); - sprintf(command,"rm \"../ws2a/captchas/%lu.png\"",inputhash); - system(command); - //printf("After second command\n"); - - //Add comment to bug file - char filepath[100]; - sprintf(filepath,"../ws2a/bugs/%s",bugid); - FILE* bugfile = fopen(filepath,"a"); - if(bugfile == NULL){ - printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); - printf("<p>Unable to find bug!"); - return; - } - char* dname = replaceHTML(name); - char* duid = useridhash(userid); - char* dcomment = replaceHTML(comment); - //printf("%s%c%c\n","Content-Type:text/html;charset=iso-8859-1",13,10); - printf("Location: ../ws2a/bugview.html?id=%s\n\n",bugid); - //printf("<p>data:%s",data); - //printf("<p>comment:%s<p>dcomment:%s",comment,dcomment); - //printf("Everything ok, inserting comment!"); - fprintf(bugfile,"\n%s\n%s\n%s\n",dname,duid,dcomment); - fclose(bugfile); - free(dname); - free(duid); - free(dcomment); - return 0; -} |
