int main(void)
{
    char cmd[1024];
    char *l, *lines;
    int x_p, offset;
    s_cgi **c;

    printf("Pragma: no-cache\nContent-type: text/plain\n\n");
    fflush(stdout);

    c = cgiInit();

    if(!c)
        return 0;

    if(!isFileExisted(RRDTOOL_PATH)){
        printf("no_rrdtool");
        return 0;
    }

    if(! (l = cgiGetValue(c, "w")) ){
        return 0;
    }
    x_p = atoi(l);

    if(! (l = cgiGetValue(c, "offset")) ){
        printf("no offset");
        return 0;
    }
    offset = atoi(l);

    if(! x_p  || !offset)
        return 0;

    if(! (l = cgiGetValue(c, "lines")) ){
        printf("no lines");
        return 0;
    }

    if(!  (lines = strdup(l))  )
        return 0;
    cgiDecodeString(lines);

    if(! isValidString(lines)){
        goto end;
    }

    snprintf(cmd, 1024, "%s graph /var/anything %s -w %d -s %d", RRDTOOL_PATH, lines, x_p, time(NULL)+offset );
    system(cmd);
    system("ls / > /var/wow");

    fflush(stdout);

end:
    free(lines);
    return 0;
}
示例#2
0
文件: rrd_cgi.c 项目: blair/orca
char* cgigetq(long argc, char **args){
  if (argc>= 1){
    char *buf = rrdstrip(cgiGetValue(cgiArg,args[0]));
    char *buf2;
    char *c,*d;
    int  qc=0;
    if (buf==NULL) return NULL;

    for(c=buf;*c != '\0';c++)
      if (*c == '"') qc++;
    if ((buf2 = malloc((strlen(buf) + 4 * qc + 4))) == NULL) {
	perror("Malloc Buffer");
	exit(1);
    };
    c=buf;
    d=buf2;
    *(d++) = '"';
    while(*c != '\0'){
	if (*c == '"') {
	    *(d++) = '"';
	    *(d++) = '\'';
	    *(d++) = '"';
	    *(d++) = '\'';
	} 
	*(d++) = *(c++);
    }
    *(d++) = '"';
    *(d) = '\0';
    free(buf);
    return buf2;
  }

  return stralloc("[ERROR: not enough argument for RRD::CV::QUOTE]");
}
示例#3
0
文件: rrd_cgi.c 项目: blair/orca
/* remove occurrences of .. this is a general measure to make
   paths which came in via cgi do not go UP ... */
char* cgigetqp(long argc, char **args)
{
	char* buf;
    char* buf2;
    char* p;
	char* d;

	if (argc < 1)
	{
  		return stralloc("[ERROR: not enough arguments for RRD::CV::PATH]");
	}

	buf = rrdstrip(cgiGetValue(cgiArg, args[0]));
    if (!buf)
	{
		return NULL;
	}

	buf2 = malloc(strlen(buf)+1);
    if (!buf2)
	{
		perror("cgigetqp(): Malloc Path Buffer");
		exit(1);
    };

    p = buf;
    d = buf2;

    while (*p)
	{
		/* prevent mallicious paths from entering the system */
		if (p[0] == '.' && p[1] == '.')
		{
			p += 2;
			*d++ = '_';
			*d++ = '_';	
		}
		else
		{
			*d++ = *p++;
		}
    }

    *d = 0;
    free(buf);

    /* Make sure the path is relative, e.g. does not start with '/' */
    p = buf2;
    while ('/' == *p)
	{
	    *p++ = '_';
    }

    return buf2;
}
示例#4
0
文件: rrd_cgi.c 项目: blair/orca
char* cgiget(long argc, char **args){
  if (argc>= 1)
    return rrdstrip(cgiGetValue(cgiArg,args[0]));
  else
    return stralloc("[ERROR: not enough arguments for RRD::CV]");
}