/* 3APA3A simpliest proxy server (c) 2002-2004 by ZARAZA <3APA3A@security.nnov.ru> please read License Agreement $Id: webadmin.c,v 1.14 2005/04/21 10:57:40 vlad Exp $ */ #include "proxy.h" #define RETURN(xxx) { param->res = xxx; goto CLEANRET; } #define LINESIZE 2048 extern FILE *writable; FILE * confopen(); extern void decodeurl(unsigned char *s, int filter); struct printparam { char buf[1024]; int inbuf; struct clientparam *cp; }; static void stdpr(struct printparam* pp, char *buf, int inbuf){ if((pp->inbuf + inbuf > 1024) || !buf) { socksend(pp->cp->clisock, pp->buf, pp->inbuf, conf.timeouts[STRING_S]); pp->inbuf = 0; if(!buf) return; } if(inbuf >= 1000){ socksend(pp->cp->clisock, buf, inbuf, conf.timeouts[STRING_S]); } else { memcpy(pp->buf + pp->inbuf, buf, inbuf); pp->inbuf += inbuf; } } static void stdcbf(void *cb, char *buf, int inbuf){ int delay = 0; int i; for(i = 0; i < inbuf; i++){ switch(buf[i]){ case '&': if(delay){ stdpr((struct printparam*)cb, buf+i-delay, delay); delay = 0; } stdpr((struct printparam*)cb, "&", 5); break; case '<': if(delay){ stdpr((struct printparam*)cb, buf+i-delay, delay); delay = 0; } stdpr((struct printparam*)cb, "<", 4); break; case '>': if(delay){ stdpr((struct printparam*)cb, buf+i-delay, delay); delay = 0; } stdpr((struct printparam*)cb, ">", 4); break; default: delay++; break; } } if(delay){ stdpr((struct printparam*)cb, buf+i-delay, delay); } } static char * templateprint(struct printparam* pp, int *level, struct dictionary *dict, char * template){ char *s, *s2; for(; template && *template; ){ if(!( s = strchr(template, '<'))){ stdpr(pp, template, strlen(template)); return template + strlen(template); } if(s[1] != '%' || s[2] == '%'){ stdpr(pp, template, (s - template) + 1); template = s + 1; continue; } if(s[2] == '/' && (s2 = strchr(s + 2, '>')) && *(s2 - 1) == '%'){ if(--*level < 0) return NULL; return s2 + 1; } } return template; } static void printstr(struct printparam* pp, char* str){ stdpr(pp, str, str?strlen(str):0); } static void printval(void *value, int type, int level, struct printparam* pp){ struct node pn, cn; struct property *p; int i; pn.iteration = NULL; pn.parent = NULL; pn.type = type; pn.value = value; for(p = datatypes[type].properties; p; ) { cn.iteration = NULL; cn.parent = &pn; cn.type = p->type; cn.value = (*p->e_f)(&pn); if(cn.value){ for(i = 0; i < level; i++) printstr(pp, "\t"); if(strcmp(p->name, "next")){ printstr(pp, p->name); printstr(pp, " ["); printstr(pp, datatypes[p->type].type); printstr(pp, "]: "); } if(datatypes[p->type].p_f){ (*datatypes[p->type].p_f)(&cn, stdcbf, pp); printstr(pp, "\n"); } else { if(!strcmp(p->name, "next")){ printstr(pp, "--------------------\n"); p = datatypes[type].properties; pn.value = value = cn.value; continue; } else { printstr(pp, "\n"); printval(cn.value, cn.type, level+1, pp); } } } p=p->next; } } char authreq[] = "HTTP/1.0 401 Authentication Required\r\n" "WWW-Authenticate: Basic realm=\"proxy\"\r\n" "Proxy-Connection: close\r\n" "Content-type: text/html; unsigned charset=us-ascii\r\n" "\r\n" "
\r\n"
"" "\r\n" "Counters\r\n" "Reload \r\n" "Statistics \r\n" "Config\r\n" " | "
"%s %s configuration" ; char tail[] = "\r\n" "(c)2000-2004 by 3APA3A\r\n" " |