summaryrefslogtreecommitdiff
path: root/ws2a/showbug.c
blob: 2e5707653238d7bb25705b1c90f1e7fb6588ffa1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>

int main(){
  char* data = getenv("QUERY_STRING");
  //char data[20] = "?id=1";
  char* hardip = getenv("REMOTE_ADDR");
  printf("%s%c%c\n",
  "Content-Type:text/html;charset=iso-8859-1",13,10);
  FILE* lastfilenum;
  lastfilenum = fopen("../ws2a/bugs/lastbug","r");
  if(lastfilenum == NULL){
    printf("Error reteriveing bugs, contact the admin!");
    return 1;
  }
  long long last = 0;
  if(fscanf(lastfilenum,"%lld",&last) < 1){
    printf("Error finding file id");
    return 1;
  }
  fclose(lastfilenum);
  long long thisid = 0;
  sscanf(data,"id=%lld",&thisid);
  if(thisid > last){
    printf("Invalid!");
    return 1;
  }

  char filestring[64] = "../ws2a/bugs/";
  char filename[10];
  sprintf(filename,"%lld",thisid);
  strcat(filestring,filename);
  FILE* bugfile;
  bugfile = fopen(filestring,"r");
  if(bugfile == NULL){
    printf("Unable to open bug file!");
    return 1;
  }
  while(!feof(bugfile)){
    putchar(fgetc(bugfile));
  }
  fclose(bugfile);
  return 0;
}