summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Pickering <alexandermpickering@gmail.com>2016-05-11 20:59:46 -0400
committerAlexander Pickering <alexandermpickering@gmail.com>2016-05-11 20:59:46 -0400
commit08179823849c92caa30c3c71ddb3cfd95b8a27e8 (patch)
treecf5450549f665884ff7a097bbaae27e23864af74
parent34ab0b3c5c24b0a325912bab5b06f858008a99ce (diff)
downloadwebpage-08179823849c92caa30c3c71ddb3cfd95b8a27e8.tar.gz
webpage-08179823849c92caa30c3c71ddb3cfd95b8a27e8.tar.bz2
webpage-08179823849c92caa30c3c71ddb3cfd95b8a27e8.zip
Started work on bug creation
-rw-r--r--cgi-bin/a.exebin0 -> 69591 bytes
-rw-r--r--ws2a/bugcomment.c15
-rw-r--r--ws2a/bugs.html28
-rw-r--r--ws2a/bugview.html4
-rw-r--r--ws2a/newbug.c182
-rw-r--r--ws2a/testhtmlreplace.c25
6 files changed, 225 insertions, 29 deletions
diff --git a/cgi-bin/a.exe b/cgi-bin/a.exe
new file mode 100644
index 0000000..2c9794d
--- /dev/null
+++ b/cgi-bin/a.exe
Binary files differ
diff --git a/ws2a/bugcomment.c b/ws2a/bugcomment.c
index c15e6ab..bb789ad 100644
--- a/ws2a/bugcomment.c
+++ b/ws2a/bugcomment.c
@@ -65,7 +65,7 @@ unsigned long hash(unsigned char *str){
}
char* useridhash(char* str){
- char* hash = malloc(sizeof(char)*20);
+ char* hash = calloc(sizeof(char)*20,sizeof(char));
int i = (int)str[0];
int len = strlen(str);
int tloop = i*20;
@@ -73,19 +73,25 @@ char* useridhash(char* str){
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;
}
@@ -97,7 +103,7 @@ int main(){
char name[15];
char userid[20];
char comment[2048];
- char captcha[25];
+ char captcha[30];
char bugid[5];
char* iname = strtok(data,"&");
@@ -143,10 +149,12 @@ int main(){
printf("Captcha incorrect");
return;
}
-
+ fclose(captchafile);
char command[100];
sprintf(command,"rm \"%s.txt\"",captchapath);
system(command);
+ sprintf(command,"rm \"%s.png\"",inputhash);
+ system(command);
//Add comment to bug file
char filepath[100];
@@ -166,6 +174,7 @@ int main(){
//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);
diff --git a/ws2a/bugs.html b/ws2a/bugs.html
index 7833614..f62b304 100644
--- a/ws2a/bugs.html
+++ b/ws2a/bugs.html
@@ -57,20 +57,20 @@
</table>
</div>
- <div class="container">
- <form class="form-signin" action="/cgi-bin/newbug.cgi">
- <h2 class="form-signin-heading">Create a bug</h2>
- <label for="inputName" class="sr-only">Name</label>
- <input id="inputName" name="name" class="form-control" placeholder="Screen Name" required="" autofocus="" type="text">
- <label for="inputID" class="sr-only">Identifier</label>
- <input id="inputID" name="id" class="form-control" placeholder="Identifier" required="" type="password">
- <textarea name="comment" rows="5" cols="50"></textarea>
- <div id="captcha"></div>
- <input id="solvecaptcha" name="captcha" class="form-control" placeholder="captcha" type="text">
- <input type="hidden" name="bugid" id=bgid>
- <button class="btn btn-lg btn-primary btn-block" type="Post">Post</button>
- </form>
- </div>
+ <form class="form-signin" action="/cgi-bin/newbug.cgi">
+ <h2 class="form-signin-heading">Create a bug report</h2>
+ <label for="inputName" class="sr-only">Name</label>
+ <input id="inputName" name="name" class="form-control" placeholder="Screen Name" required="" autofocus="" type="text">
+ <label for="inputID" class="sr-only">Identifier</label>
+ <input id="inputID" name="id" class="form-control" placeholder="Identifier" required="" type="password">
+ <label for="shortdesc" class="sr-only">Short Description</label>
+ <input id="shortdesc" name="shortdesc" class="form-control" placeholder="Short description" required="" type="password">
+ <textarea class="form-control" name="longdesc" rows="5" cols="50" placeholder="Long description"></textarea>
+ <div id="captcha"></div>
+ <input id="solvecaptcha" name="captcha" class="form-control" placeholder="captcha" type="text">
+ <input type="hidden" name="bugid" id=bgid>
+ <button class="btn btn-lg btn-primary btn-block" type="Post">Post</button>
+ </form>
<footer class="footer">
<p>Contact the admin at <a href="mailto:apickx@cogarr.org">Apickx@cogarr.org</a></p>
diff --git a/ws2a/bugview.html b/ws2a/bugview.html
index 2e17c6d..c0cf3fa 100644
--- a/ws2a/bugview.html
+++ b/ws2a/bugview.html
@@ -76,9 +76,9 @@
<input id="inputName" name="name" class="form-control" placeholder="Screen Name" required="" autofocus="" type="text">
<label for="inputID" class="sr-only">Identifier</label>
<input id="inputID" name="id" class="form-control" placeholder="Identifier" required="" type="password">
- <textarea name="comment" rows="5" cols="50"></textarea>
+ <textarea class="form-control" name="comment" rows="5" cols="50"></textarea>
<div id="captcha"></div>
- <input id="solvecaptcha" name="captcha" class="form-control" placeholder="captcha" type="text">
+ <input class="form-group" id="solvecaptcha" name="captcha" class="form-control" placeholder="captcha" type="text">
<input type="hidden" name="bugid" id=bgid>
<button class="btn btn-lg btn-primary btn-block" type="Post">Post</button>
</form>
diff --git a/ws2a/newbug.c b/ws2a/newbug.c
index e69de29..8ffa7f0 100644
--- a/ws2a/newbug.c
+++ b/ws2a/newbug.c
@@ -0,0 +1,182 @@
+#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){
+ 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&shortdesc=test+creation&longdesc=this+is+a+long+description&captcha=damaged+crazy";
+
+ char name[20];
+ char userid[20];
+ char shortdesc[128];
+ char longdesc[4096];
+ char captcha[30];
+
+ char* iname = strtok(data,"&");
+ char* iuserid = strtok(NULL,"&");
+ char* ishortdesc = strtok(NULL,"&");
+ char* ilongdesc = strtok(NULL,"&");
+ char* icaptcha = strtok(NULL,"&");
+
+ sscanf(iname,"name=%s",name);
+ sscanf(iuserid,"id=%s",userid);
+ sscanf(ishortdesc,"shortdesc=%s",shortdesc);
+ sscanf(ilongdesc,"longdesc=%s",longdesc);
+ sscanf(icaptcha,"captcha=%s",captcha);
+
+ printf("name:%s\nid:%s\nshort:%s\nlong:%s\ncaptcha:%s\n",name,userid,shortdesc,longdesc,captcha);
+
+ //Check captcha
+ char captchapath[100];
+ char* captchadecoded = replaceHTML(captcha);
+ sprintf(captchapath,"../ws2a/captchas/%s.txt",captchadecoded);
+
+ 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:No file found");
+ return;
+ }
+ 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:Bad hash");
+ return;
+ }
+
+ //If we had the correct captcha, remove it.
+ char command[100];
+ sprintf(command,"rm \"%s.txt\"",captchapath);
+ system(command);
+
+ //Create new bug
+ FILE* lastbugfile = fopen("../ws2a/bugs/lastbug","r+");
+ if(lastbugfile == NULL){
+ printf("Unable to open LastBugFile!");
+ }
+ unsigned long long lastbug = 0;
+ fscanf(lastbugfile,"%llu",&lastbug);
+ fseek(lastbugfile,0,SEEK_SET);
+ lastbug++;
+ fprintf(lastbugfile,"%llu",lastbug);
+ fclose(lastbugfile);
+
+ char* dname = replaceHTML(name);
+ char* duid = useridhash(userid);
+ time_t rawtime;
+ struct tm * timeinfo;
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ char* dshortd = replaceHTML(shortdesc);
+ char* dlongd = replaceHTML(longdesc);
+ printf("Right before printing to file\n");
+ char newfilepath[100];
+ sprintf(newfilepath,"../ws2a/bugs/%llu",lastbug);
+ FILE* newfile = fopen(newfilepath,"w");
+ fprintf(lastbugfile,"%s\n%s\n%s%s\n0:\n%s\n",dname,duid,asctime(timeinfo),dshortd,dlongd);
+ fclose(newfile);
+ free(dname);
+ free(duid);
+ free(dshortd);
+ free(dlongd);
+
+ return 0;
+}
diff --git a/ws2a/testhtmlreplace.c b/ws2a/testhtmlreplace.c
index 28b3419..2106185 100644
--- a/ws2a/testhtmlreplace.c
+++ b/ws2a/testhtmlreplace.c
@@ -55,7 +55,7 @@ char* replaceHTML(char* str){
}
char* useridhash(char* str){
- char* hash = malloc(sizeof(char)*20);
+ char* hash = calloc(sizeof(char)*20,sizeof(char));
int i = (int)str[0];
int len = strlen(str);
int tloop = i*20;
@@ -63,15 +63,16 @@ char* useridhash(char* str){
unsigned int strp = 0;
i = 0;
while(i < tloop){
- //printf("i:%d hashp:%u strp:%u tloop:%d\n",i,hashp,strp,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);
+ 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];
@@ -80,24 +81,28 @@ char* useridhash(char* str){
hash[i] = modedhashnum + 32;
i++;
}
- //printf("Resulting hash was:%s\n",hash);
+ printf("Resulting hash was:%s\n",hash);
return hash;
}
int main(){
- char teststring[] = "This+is+a+test\nWith\nSome\nNewlines";
+ char teststring[] = "Test";
printf("Original:%s\n",teststring);
- char* parsed = replaceHTML(teststring);
+ char* parsed = useridhash(teststring);
printf("%s\n",parsed);
-
- char teststring2[] = "This%0D%0Ais+another%0D%0Atest";
+/*
+ char teststring2[] = "Tost";
printf("Original:%s\n",teststring2);
- char* parsed2 = replaceHTML(teststring2);
+ char* parsed2 = useridhash(teststring2);
printf("%s\n",parsed2);
char teststring3[] = "This%0D%0AIs%0D%0AAnother%0D%0AMulti%0D%0ALine%0D%0AComment";
printf("Original:%s\n",teststring3);
- char* parsed3 = replaceHTML(teststring3);
+ char* parsed3 = useridhash(teststring3);
printf("%s\n",parsed3);
+ free(parsed);
+ free(parsed2);
+ free(parsed3);
return 0;
+*/
}