diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2016-06-02 16:54:20 -0400 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2016-06-02 16:54:20 -0400 |
| commit | c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4 (patch) | |
| tree | 9a9d90471dd6241da885950c5b52416bba28619f /src/bugcomment.c | |
| download | sober-c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4.tar.gz sober-c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4.tar.bz2 sober-c2a74cc20ebaa9898052ab758821ccfc7c3ee1f4.zip | |
Initial commit
Diffstat (limited to 'src/bugcomment.c')
| -rw-r--r-- | src/bugcomment.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/bugcomment.c b/src/bugcomment.c new file mode 100644 index 0000000..6ae16b3 --- /dev/null +++ b/src/bugcomment.c @@ -0,0 +1,90 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <stdint.h> +#include "config.h" +#include "shared.h" + +int main(){ + char* data = getenv("QUERY_STRING"); + 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); + + //Check captcha + char captchapath[100]; + char* captchadecoded = replaceHTML(captcha); + sprintf(captchapath,"%s/captchas/%s.txt",REL_BINPATH,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"); + 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"); + return; + } + fclose(captchafile); + //If the program got here, the captcha was correct + + //Delete the captcha file so you can't use the same captcha twice + char command[100]; + sprintf(command,"rm \"%s\"",captchapath); + system(command); + + sprintf(command,"rm \"%s/captchas/%lu.png\"",REL_BINPATH,inputhash); + system(command); + + //Add comment to bug file + char filepath[100]; + sprintf(filepath,"%s/bugs/%s",REL_BINPATH,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); + + //Redirect the user + printf("Location: %s/bugview.html?id=%s\n\n",REL_BINPATH,bugid); + + //And create the bug + fprintf(bugfile,"\n%s\n%s\n%s\n",dname,duid,dcomment); + fclose(bugfile); + + //Make this bug recent, so everyone gets a notification + unsigned long long nbugid = 0; + sscanf(bugid,"%llu",&nbugid); + makeRecent(nbugid); + + free(dname); + free(duid); + free(dcomment); + return 0; +} |
