diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-11 14:48:15 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-05-11 14:48:15 -0400 |
| commit | 7b9a50527b056e6fde71fb57d0ebf761d6d39369 (patch) | |
| tree | 4487074e461e31ea357f1b7cb30586da713107e7 /ws2a | |
| parent | eb124f52957d579bf973260a24fe84cee7c1fd8b (diff) | |
| download | webpage-7b9a50527b056e6fde71fb57d0ebf761d6d39369.tar.gz webpage-7b9a50527b056e6fde71fb57d0ebf761d6d39369.tar.bz2 webpage-7b9a50527b056e6fde71fb57d0ebf761d6d39369.zip | |
Finishing up commenting on bugs
Diffstat (limited to 'ws2a')
| -rw-r--r-- | ws2a/a.exe | bin | 0 -> 69591 bytes | |||
| -rw-r--r-- | ws2a/bugcomment.c | 108 | ||||
| -rw-r--r-- | ws2a/testhtmlreplace.c | 75 |
3 files changed, 183 insertions, 0 deletions
diff --git a/ws2a/a.exe b/ws2a/a.exe Binary files differnew file mode 100644 index 0000000..2b28d5e --- /dev/null +++ b/ws2a/a.exe diff --git a/ws2a/bugcomment.c b/ws2a/bugcomment.c index 971ef51..d4fa5ab 100644 --- a/ws2a/bugcomment.c +++ b/ws2a/bugcomment.c @@ -3,6 +3,75 @@ #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("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; + sscanf(str+strp,"%%%x",&hex); + printf("Was:%c\n",(char)hex); + nstr[nstrp] = (char)hex; + nstrp++; + strp+=3; + }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){ + char* hash = malloc(sizeof(char)*20); + 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){ + char tchar = str[strp%len]; + hash[hashp%20] += str[strp%len]; + hashp+=(int)tchar; + strp+=(int)(hashp*hashp); + i++; + } + i = 0; + while(i < 20){ + unsigned int hashnum = hash[i]; + unsigned int modedhashnum = hashnum % 92; + hash[i] = modedhashnum + 32; + i++; + } + return hash; +} + int main(){ char* data = getenv("QUERY_STRING"); //char data[20] = "?id=1"; @@ -29,6 +98,45 @@ int main(){ sscanf(ibugid,"bugid=%s",bugid); 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",captchadecoded); + free(captchadecoded); + FILE* captchafile = fopen(captchapath,"r"); + if(captchafile == NULL){ + printf("Captcha incorrect"); + return; + } + unsigned long inputhash = hash(captchadecoded); + unsigned long filehash = 0; + fscanf(captchafile,"%lu",&filehash); + if(inputhash != filehash){ + printf("Captcha incorrect"); + return; + } + char command[100]; + sprintf(command,"rm \"%s\"",captchapath); + system(command); + printf("Captcha correct, and deleted"); + + //Add comment to bug file + char filepath[100]; + sprintf(filepath,"../ws2a/bugs/%s",bugid); + FILE* bugfile = fopen(filepath,"a"); + if(bugfile == NULL){ + printf("<p>Unable to find bug!"); + return; + } + char* dname = replaceHTML(name); + char* duid = useridhash(userid); + char* dcomment = replaceHTML(comment); + printf("Everything ok, inserting comment!"); + fprintf(bugfile,"\n%s\n%s\n%s\n",dname,duid,dcomment); + free(dname); + free(duid); + free(dcomment); /* FILE* lastfilenum; lastfilenum = fopen("../ws2a/bugs/lastbug","r"); diff --git a/ws2a/testhtmlreplace.c b/ws2a/testhtmlreplace.c new file mode 100644 index 0000000..56bd5cd --- /dev/null +++ b/ws2a/testhtmlreplace.c @@ -0,0 +1,75 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdint.h> + +void replaceHTML(char* str){ + printf("Replaceing:%s\n",str); + char* nstr = malloc((sizeof(char)*strlen(str)) + 1); + if(nstr == NULL){ + 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; + sscanf(str+strp,"%%%x",&hex); + printf("Was:%c\n",(char)hex); + nstr[nstrp] = (char)hex; + nstrp++; + strp+=3; + }else{ + nstr[nstrp] = str[strp]; + nstrp++; + strp++; + } + } + nstr[nstrp] = '\0'; + printf("Done, str is now:%s\n",nstr); +} + +char* useridhash(char* str){ + char* hash = malloc(sizeof(char)*20); + 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]; + 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 teststring[] = "This+is+a+test"; + useridhash(teststring); + char teststring2[] = "This+is+a+tost"; + useridhash(teststring2); + return 0; +} |
