/* Copyright (C) 1995 NetWin, New Zealand, All rights reserved. */ /* What is quoted printable format, must detec Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable =3D --> = = --> newline Test on cern on hortnet. test turning logging off */ #include #include #include #include #include #include #include #include "dnews.h" #include "conf.h" #include "lib.h" #include "emsg.h" #include "nntp.h" #ifndef TRUE #define FALSE 0 #define TRUE (!FALSE) #endif static int docache=FALSE; static int dodebug=FALSE; /* Commands that we need to support xover comp.os.vms [nnn-nnn] Default is last 20 messages in group article comp.os.vms nnn post message list comp.os.* Just show the ones at that level */ int decode_base64(char *buf, char *out); int decode_uu(char *line, char *out); static char tplname[BFSZ]; void get_line_clear(void); void show_dline(char *s); void r_listall(void); void netwin_advert(void); void f_follow(int follow); char *xstrtok(char *line, char *in); char *towww(char *s); void r_find(void); /* from=nnn max=nnn*/ void f_find(void); void show_xsearch(void); void f_search(void); void r_search(void); void tpl_show_item_image(void); void f_post(void); void h_printf(char * arg_list, ...); void db_setscript(char *script); int show_headfile(char *type, char *title); void show_end(char *type); int show_top(char *type, char * arg_list, ...); void show_article2(void); char *lib_encode(char *s); char *value_encode(char *s); char *mygetenv(char *v); char *query_find(char *s); int query_get(void); void getword(char *word, char *line, char stop) ; char x2c(char *what) ; char *email_name(char *email); void unescape_url(char *url) ; void plustospace(char *str) ; void tpl_quote_body(void); int tpl_show_file(char *xfname); char *file_tpl(char *fname); char *tpl_replace(char *bf); void tpl_init(void); char *tpl_replace_vars(char *orig); void tpl_replace_var(char *bf, int len, char *var); void tpl_show_list(void); void tpl_init_item(void); void tpl_show_item(void); void tpl_init_sbar(int from, int to, int total, char *key); char *head_decode(char *s); void tpl_show_group(void); void tpl_set_buttons(void); void tpl_show(char *xfname); void var_set(char *var, char *val); char *var_find(char *var); void show_sbar(int from, int to, int total, char *key); void form_get(void); char *form_find(char *s); void show_article(void); int do_authent(void); static char path_script[BFSZ]; static char rootname[BFSZ]; int ini_read(char *s); int ini_find(char *s); char *ini_get(int x); void r_post(void); void zmsg(char * arg_list, ...); void r_article(void); int read_lines(void); int read_status(void); int read_xover(void); void show_xover(void); void r_xover(void); /* from=nnn max=nnn*/ void r_list(void); char *mygetenv(char *s); char *h_date_trim(char *instr); char *h_trim(char *s, int len); char *h_from_trim(char *s); #define MAX_ITEMS 4010 #ifdef WIN32 #define FIX_STDOUT TRUE #endif #ifdef OS2 #define FIX_STDOUT TRUE #define _setmode setmode #endif void xover_add(char *item, char *subject, char *from, char *lines, char *date, char *mid, char *ref); void xover_showord(void); enum {I_HEADERS, I_XOVER_PRE, I_XOVER_POST, I_NEWSHOST, I_DEBUG, I_PAGESIZE , I_GROUPS, I_ALLOW, I_SORT, I_NOADVERT, I_SEARCH, I_CGI_PATH, I_TEMPLATES , I_POST_GROUPS, I_POST_USERS,I_LOG_FILE,I_SORT_REV,I_WRAP_POST,I_WRAP_TEXT , I_CONTENT_TYPE, I_ADD_MID, I_TELLNEWS_PASS, I_PRE_DISABLE }; char *ini_names[]={ "headers","xover_pre","xover_post","newshost", "debug", "pagesize" ,"groups", "allow" , "sort", "noadvert", "search", "cgi_path" ,"templates" ,"post_groups", "post_users","log_file" ,"sort_rev","wrap_post","wrap_text" ,"content_type", "add_mid", "tellnews_pass" ,"pre_disable" , NULL }; #define PAGESIZE page_size() char *content_type(void); char *content_type(void) { static char bf[BFSZ]; strcpy(bf,ini_get(I_CONTENT_TYPE)); if (strlen(bf)==0) strcpy(bf,"text/html"); return bf; } int page_size(void) { int i = atoi(ini_get(I_PAGESIZE)); if (i==0) i = 30; return i; } static int done_content; static int x_item[MAX_ITEMS]; static char *x_score[MAX_ITEMS]; static char *x_group[MAX_ITEMS]; static double x_f[MAX_ITEMS]; static int x_fi[MAX_ITEMS]; static int x_depth[MAX_ITEMS]; static char *x_subject[MAX_ITEMS]; static char *x_subjectsrt[MAX_ITEMS]; static char *x_from[MAX_ITEMS]; static char *x_date[MAX_ITEMS]; static char *x_ref[MAX_ITEMS]; static char *x_lines[MAX_ITEMS]; static char *x_mid[MAX_ITEMS]; static int nitem; void emsg_reset(void); static int chan; static char thisuser[BFSZ]; static char group[BFSZ]; static int gfrom,gto,gmax,group_from,group_to; static int dosort; static char log_file[BFSZ]; static int search_result = FALSE; static int pre_disable=FALSE; int main(int argc, char *argv[]) { char method[BFSZ]; char cmd[BFSZ]; #ifndef WIN32 signal(SIGFPE,SIG_IGN); #endif strcpy(log_file,"dnewsweb.log"); db_setscript(mygetenv("SCRIPT_NAME")); sprintf(log_file,"%s.log",rootname); if (!ini_read(argv[0])) return 0; if (strlen(ini_get(I_CGI_PATH))>0) { strcpy(path_script,ini_get(I_CGI_PATH)); } if (strlen(ini_get(I_LOG_FILE))>0) { strcpy(log_file,ini_get(I_LOG_FILE)); } if (strcmp("true",ini_get(I_DEBUG))==0) dodebug = TRUE; if (strcmp("true",ini_get(I_SORT))==0) dosort = TRUE; if (strcmp("true",ini_get(I_PRE_DISABLE))==0) pre_disable = TRUE; if (!dodebug) emsg_reset(); imsg("DNEWSWEB, Startup, Looking for winsock dll\n"); nntp_startup(); nntp_alwaysblock(); strcpy(thisuser,mygetenv("REMOTE_USER")); strcpy(method,mygetenv("REQUEST_METHOD")); strlwr(method); query_get(); /* Get the ?xxx=yyy... parameters */ if (strcmp(method,"post")==0) { imsg("Processing POST\n"); if (docache) printf("Pragma: cache\n"); done_content = TRUE; printf("Content-type: %s\n\n",content_type()); chan = nntp_open(ini_get(I_NEWSHOST)); if (chan<0) { goto failed;} nntp_setblock(chan,TRUE); /* Set to blocking IO */ form_get(); /* get any form fields */ strcpy(cmd,form_find("cmd")); if (strcmp(cmd,"post")==0) r_post(); } else { imsg("Processing command (%s)\n",query_find("cmd")); strcpy(cmd,query_find("cmd")); if (strcmp(cmd,"article")!=0) { if (docache) printf("Pragma: cache\n"); done_content = TRUE; printf("Content-type: %s\n\n",content_type()); } chan = nntp_open(ini_get(I_NEWSHOST)); if (chan<0) { goto failed;} nntp_setblock(chan,TRUE); /* Set to blocking IO */ if (strcmp(cmd,"xover")==0) r_xover(); else if (strcmp(cmd,"list")==0) r_list(); else if (strcmp(cmd,"listall")==0) r_listall(); else if (strcmp(cmd,"article")==0) r_article(); else if (strcmp(cmd,"post")==0) f_post(); else if (strcmp(cmd,"search")==0) f_search(); else if (strcmp(cmd,"f_search")==0) f_search(); else if (strcmp(cmd,"r_search")==0) r_search(); else if (strcmp(cmd,"r_find")==0) r_find(); else if (strcmp(cmd,"xsearch")==0) r_find(); else if (strcmp(cmd,"f_find")==0) f_find(); else if (strcmp(cmd,"follow")==0) f_follow(TRUE); else r_list(); } imsg("Program finished ok\n"); return 0; failed: if (strcmp(cmd,"article")==0) { if (docache) printf("Pragma: cache\n"); done_content = TRUE; printf("Content-type: %s\n\n",content_type()); } printf("Could not open connection to your news server (%s). \n",ini_get(I_NEWSHOST)); printf("It may be down at the moment, in which case you could try\n"); printf("again later. Also check you have given the correct name in dnewsweb.ini\n"); return 0; } /* sprintf(bf,"group rec.humor\015\012"); nntp_write_s(c,bf,strlen(bf)); sprintf(bf,"article\015\012"); nntp_write_s(c,bf,strlen(bf)); sprintf(bf,"quit\015\012"); nntp_write_s(c,bf,strlen(bf)); n = nntp_read(c,out,1000); for (;n>=0;) { out[n] = 0; printf("%s",out); n = nntp_read(c,out,1000); } return 0; */ static String *instr; int read_lines(void) { int n; char bf[3000]; char *s; wantmore: n = nntp_read(chan,bf,2000); if (n<0) return FALSE; bf[n] = 0; str_addsn(instr,bf); s = str_s(instr) + str_len(instr) - 1; dmsg("Last char {%d}\n",*s); if (*s != '\012') goto wantmore; return TRUE; } static char nntp_status[BFSZ]; int group_match(char *a, char *b); int group_allow(char *group) { char bf[BFSZ]; char g[BFSZ]; ncpy(g,group,BFSZ-1); ncpy(bf,ini_get(I_ALLOW),BFSZ-1); if (!group_match(bf,g)) { printf("Sorry, you are not permitted access to (%s) ",group); printf("via this DNEWSWEB gateway\n"); return FALSE; } return TRUE; } int read_status(void) { char *s,*s2; int slen; if (instr==NULL) instr = str_new(); get_line_clear(); str_copysn(instr,""); read_lines(); s = str_s(instr); s2 = strchr(s,'\012'); if (s2==NULL) return FALSE; *s2 = 0; ncpy(nntp_status,s,BFSZ-1); slen = s2-s+1; if (str_len(instr)>(slen)) { memmove(s,s2+1,str_len(instr)-slen+1); str_setlen(instr,str_len(instr)-slen); } else str_copysn(instr,""); if (nntp_status[0]=='2') return TRUE; if (nntp_status[0]=='3') return TRUE; return FALSE; } char *get_linex(String *instr) { static char bf[BFSZ]; char *s; char *s2; int slen; s = str_s(instr); if (s==NULL) return NULL; s2 = strchr(s,'\012'); if (s2==NULL) return NULL; *s2 = 0; ncpy(bf,s,BFSZ-1); slen = s2-s+1; if (str_len(instr)>(slen)) { memmove(s,s2+1,str_len(instr)-slen+1); str_setlen(instr,str_len(instr)-slen); } else str_copysn(instr,""); return bf; } static int gupto; void get_line_clear(void) { gupto = 0; if (instr==NULL) return; str_copysn(instr,""); } char *get_line(String *instr) { static char bf[BFSZ]; char *s; int noskip = FALSE; char was; char *s2; int slen; if (instr==NULL) return NULL; s = str_s(instr); if (s==NULL) goto fail; s+=gupto; if (*s=='\r') {s++; gupto++;} if (*s=='\n') {s++; gupto++;} for (s2=s;*s2!=0;s2++) if ((*s2=='\n') || (*s2=='\r')) break; if (*s2==0) goto fail; if ((s2-s)>500) { /* Long line, wrap it on the last space if possible*/ s2 = strchr(s+500,' '); if (s2==NULL) {s2 = s+500; noskip = TRUE;} if (s2>(s+599)) {s2 = s+500; noskip = TRUE;} was = *s2; *s2 = 0; ncpy(bf,s,BFSZ-1); *s2 = was; gupto += s2-s+1; if (noskip) gupto--; } else { *s2 = 0; ncpy(bf,s,BFSZ-1); gupto += s2-s+1; } strcat(bf,"\r"); if (gupto==str_len(instr)) str_copysn(instr,""); return bf; fail: str_copysn(instr,""); return NULL; } int read_xover(void) { char *s; dmsg("inside read_xover\n"); if (instr==NULL) instr = str_new(); for (;TRUE;) { dmsg("inside read_xover\n"); if (str_len(instr)==3) if (strcmp(str_s(instr),".\015\012")==0) break; if (str_len(instr)>=5) { s = str_s(instr) + str_len(instr) - 5; if (strcmp(s,"\015\012.\015\012")==0) break; if (strcmp(s,"\015\012.\015\012")==0) break; } read_lines(); } if (str_len(instr)>3) str_setlen(instr,str_len(instr)-3); return TRUE; } void show_xline(char *s); void show_xbar(void) { printf(""); printf(""); if (gfrom>group_from) { printf("
Previous Page",path_script,towww(group),gfrom-gmax); } if (gtoNext Page",path_script,towww(group),gto); printf("Recent Items",path_script,towww(group)); } printf("Standard Groups",path_script); printf("All Groups",path_script); printf("Post",path_script,towww(group)); printf("Search Group",path_script,towww(group)); printf("
\n"); } void tpl_init_sbar(int from, int to, int total, char *key) { char bf[BFSZ]; if (from>1) { sprintf(bf,"%s?cmd=r_search&key=%s&from=%d&to=%d",path_script,lib_encode(key),from-page_size(),from); var_set("b_prev",bf); } if (to"); printf(""); if (from>1) { printf("Previous Page %d-%d",path_script,lib_encode(key),from-page_size(),from,from-page_size(),from); } if (toNext Page %d-%d",path_script,lib_encode(key),to,to+page_size(),to,to+page_size()); } printf("Standard Groups",path_script); printf("All Groups",path_script); printf("Search Group",path_script,towww(group)); printf(" \n"); } void show_xover(void) { char *s; s = get_line(instr); for (;s!=NULL;) { dmsg("Show sxline %s\n",s); show_xline(s); s = get_line(instr); } } void show_search(void) { char *s; s = get_line(instr); for (;s!=NULL;) { show_xline(s); /* decode xover information */ s = get_line(instr); } show_xsearch(); } void show_xsearch(void) { int i; char bf[BFSZ]; char *s; printf("\n"); } void show_dlist(void) { char *s; s = get_line(instr); for (;s!=NULL;) { show_dline(s); s = get_line(instr); } } void netwin_advert(void) { printf("
\n"); printf(" "); printf("DNEWSWEB %s Copyright © NetWin Ltd\n",DNEWS_VERSION); printf(" \n"); printf(" \n"); } int head_get(char *field, char *val, char *line) { char bf[BFSZ]; char bf2[BFSZ]; ncpy(bf,line,BFSZ-1); strlwr(bf); if (strncmp(bf,field,strlen(field))==0) { ncpy(bf2,line+strlen(field)+1,100); ncpy(val,head_decode(bf2),200); } return TRUE; } #define MAXIMG 500000 void show_article_part(int wanted); void show_article_part(int wanted) { char *s; char *s2; int gothead; int n; char subject[BFSZ]; int isuu = FALSE; char from[BFSZ]; char tmp[BFSZ]; char date[BFSZ]; char boundary[BFSZ]; char content[BFSZ]; char newsgroups[BFSZ]; char *out; int nout; int findimage = FALSE; int item = atoi(query_find("item")); int related = item; int got=0; if (wanted==200) {findimage = TRUE; gothead = TRUE;} if (wanted==99) wanted = 0; out = mymalloc(MAXIMG); strcpy(boundary,"none"); strcpy(subject,""); strcpy(from,""); strcpy(content,""); strcpy(date,""); strcpy(newsgroups,""); related = item ; if (related<1) related = 1; #ifdef FIX_STDOUT _setmode(_fileno(stdout),_O_BINARY); #endif /* printf("Content-type: text/html\n\n"); */ /* fopen printf("MIME-Version: 1.0\n"); */ /* printf("Content-Type: image/x-xbitmap\n"); printf("\n"); printf("#define back_width 20\n"); printf("#define back_height 23\n"); printf("static char back_bits[] = {\n"); printf(" 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x0f,0x00,0x80,0x0f, \n"); printf(" 0x00,0x80,0x0f,0x00,0x80,0x0f,0x00,0x80,0x0f,0x00,0x80,0x0f,0x60,0x80,0x0f, \n"); printf(" 0x70,0x80,0x0f,0x78,0x00,0x00,0xfc,0xff,0x0f,0xfe,0xff,0x07,0xff,0xff,0x03, \n"); printf(" 0xfe,0xff,0x01,0xfc,0xff,0x00,0x78,0x00,0x00,0x70,0x00,0x00,0x60,0x00,0x00, \n"); printf(" 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; \n"); return; printf("Content-type: image/jpeg; name=\"test.jpg\"\n"); f = fopen("test.jpg","rb"); if (f==NULL) {perror("test.jpg"); return;} n = fread(bf,1,100000,f); printf("Content-length: %d\n",n); printf("\n"); fwrite(bf,1,n,stdout); return; */ s = get_line(instr); for (;s!=NULL;) { s2 = strchr(s,'\015') ; if (s2!=NULL) *s2 = 0; s2 = strchr(s,'\012') ; if (s2!=NULL) *s2 = 0; if (strlen(s)==0) break; s2 = strstr(s,"boundary="); if (s2==NULL) s2 = strstr(s,"Boundary="); if (s2!=NULL) { s2 = strchr(s2,'"'); strcpy(boundary,"--"); if (s2!=NULL) ncpy(boundary+2,s2+1,BFSZ-10); s2 = strchr(boundary,'"'); if (s2!=NULL) *s2 = 0; head_get("content-type:",content,s); } /* head_get("subject:",subject,s); */ s = get_line(instr); } nout = 0; if (findimage) if (strlen(content)>0) wanted = 0; if (wanted==0) { emsg("Content-type: %s\n",content); printf("Content-type: image/jpeg; name=\"test.jpg\"\n"); gothead = TRUE; } for (;s!=NULL;) { s2 = strchr(s,'\015') ; if (s2!=NULL) *s2 = 0; s2 = strchr(s,'\012') ; if (s2!=NULL) *s2 = 0; if (!isuu) { if (strncmp(s,"begin",5)==0) { isuu = TRUE; strlwr(s); if (strstr(s,".gif")!=NULL) printf("Content-type: image/GIF\n"); else if (strstr(s,".zip")!=NULL) printf("Content-type: application/x-zip-compressed\n"); else if (strstr(s,".exe")!=NULL) printf("Content-type: application/octet-stream\n"); else if (strstr(s,".doc")!=NULL) printf("Content-type: application/octet-stream\n"); else if (strstr(s,".xls")!=NULL) printf("Content-type: application/octet-stream\n"); else if (strstr(s,".com")!=NULL) printf("Content-type: application/octet-stream\n"); else if (strstr(s,".txt")!=NULL) printf("Content-type: text/plain\n"); else if (strstr(s,".ini")!=NULL) printf("Content-type: text/plain\n"); else if (strstr(s,".jpg")!=NULL) printf("Content-type: image/JPEG\n"); /*else if (strstr(s,".avi")!=NULL) printf("Content-type: audio/avi\n"); else if (strstr(s,".mpg")!=NULL) printf("Content-type: video/mpeg\n"); else if (strstr(s,".mpeg")!=NULL) printf("Content-type: video/mpeg\n"); */ else if (strstr(s,".htm")!=NULL) printf("Content-type: text/html\n"); else if (strstr(s,".html")!=NULL) printf("Content-type: text/html\n"); else if (strstr(s,".jpeg")!=NULL) printf("Content-type: image/JPEG\n"); else { printf("Content-type: image/JPEG\n"); } } } else { if (isuu) { if (strncmp(s,"end",3)==0) break; if (strcmp(s,"`")==0) break; if (s[0]!=0) { n = decode_uu(s,out+nout); nout += n; } } } if (!isuu) { if (findimage) if (!gothead) { ncpy(tmp,s,BFSZ-1); strlwr(tmp); if ( (strstr(tmp,"jpeg")!=NULL) || (strstr(tmp,"jpg")!=NULL) || (strstr(tmp,"image")!=NULL) || (strstr(tmp,"gif")!=NULL) ) { wanted = got; goto showit; } if (strlen(s)==0) gothead = TRUE; } if (strstr(s,boundary)!=NULL) { gothead = FALSE; got++; } else if (got==wanted) { showit: if (strlen(s)==0) gothead = TRUE; else { if (!gothead) { /* {char *zz; zz = strchr(s,';'); if (zz!=NULL) *zz = 0; } */ printf("%s\n",s); imsg("Attach Head(%s)\n",s); ncpy(tmp,s,BFSZ-1); strlwr(tmp); if (strstr(tmp,"x-uue")!=NULL) got = wanted+1; } else { n = decode_base64(s,out+nout); if (n<0) emsg("Base 64 encoding is corrupt {%s} \n",s); nout += n; } } } if (nout<0) break; } s = get_line(instr); } printf("Content-length: %d\n",nout); printf("\n"); fwrite(out,1,nout,stdout); return; } void show_article2(void) { char *s,*x; char subject[BFSZ]; static char from[BFSZ]; static char date[BFSZ]; static char mime[BFSZ]; static char content[BFSZ]; static char encoding[BFSZ]; char bf[BFSZ]; int isimage = FALSE; char *s2; int gothead = FALSE; int multi,got,istext; static char boundary[BFSZ]; char newsgroups[BFSZ]; int item = atoi(query_find("item")); int related = item; int part = atoi(query_find("part")); if (part>0) { show_article_part(part); return;} multi = got = istext = FALSE; strcpy(subject,""); strcpy(from,""); strcpy(date,""); strcpy(newsgroups,""); related = item; done_content = TRUE; if (docache) printf("Pragma: cache\n"); printf("Content-type: %s\n\n",content_type()); show_top("article","Newsgroup Article %s:%s ",group,query_find("item")); printf("\n"); printf(" \n"); printf("
Related Items\n",path_script,towww(group),related); printf("Recent Items\n",path_script,towww(group)); printf("Standard Groups\n",path_script); printf("All Groups\n",path_script); printf("Post Followup\n",path_script,towww(group),query_find("item")); printf("
\n"); s = get_line(instr); for (;s!=NULL;) { if (strcmp(s,"\015")==0) break; head_get("subject:",subject,s); head_get("date:",date,s); head_get("from:",from,s); head_get("newsgroups:",newsgroups,s); head_get("mime-version:",mime,s); head_get("content-type:",content,s); head_get("content-transfer-encoding:",encoding,s); s2 = strstr(s,"boundary="); if (s2==NULL) s2 = strstr(s,"Boundary="); if (s2!=NULL) { s2 = strchr(s2,'"'); strcpy(boundary,"--"); if (s2!=NULL) ncpy(boundary+2,s2+1,BFSZ-10); s2 = strchr(boundary,'"'); if (s2!=NULL) *s2 = 0; } s = get_line(instr); } printf(""); printf("
Subject:%s\n",value_encode(subject)); printf("
Date:%s\n",date); printf("
From:%s\n",value_encode(from)); printf("
Newsgroups:%s\n",newsgroups); printf("
\n"); strlwr(encoding); multi = FALSE; if (strlen(mime)>0) if (strlen(boundary)>0) multi = TRUE; if (!multi) if (strstr(encoding,"base64")!=NULL) { printf("
",path_script,towww(group),item); goto endbit; } got = 0; if (multi) { for (;s!=NULL;) { s2 = strchr(s,'\015') ; if (s2!=NULL) *s2 = 0; s2 = strchr(s,'\012') ; if (s2!=NULL) *s2 = 0; if (strstr(s,boundary)!=NULL) { if (!pre_disable) if (istext) printf("\n"); gothead = FALSE; istext = FALSE; got++; isimage = FALSE; } if (strlen(s)==0) { if (!pre_disable) if (istext) printf("
\n");
			gothead = TRUE;
			if (isimage) 
			  printf("
",path_script,towww(group),item,got); } else { if (!gothead) { /* printf("%s
\n",s);*/ strlwr(s); if (strstr(s,"text/")!=NULL) istext = TRUE; if (strstr(s,"image/")!=NULL) isimage = TRUE; } else { if (istext) { printf("%s",value_encode(s)); } } } s = get_line(instr); } goto endbit; } if (!pre_disable) printf("
\n");
	s = get_line(instr);
	isimage = FALSE;
	for (;s!=NULL;) {
		if (strncmp(s,"begin ",6)==0) {
			imsg("Found begin (%s) \n",s);
			ncpy(bf,s,BFSZ-1);
			x = strtok(bf," \012\015"); if (x==NULL) goto skip;
			x = strtok(NULL," \012\015"); if (x==NULL) goto skip;
			imsg("Found begin nn(%s) \n",x);
			if (atoi(x)<100) goto skip;
			x = strtok(NULL," \012\015"); if (x==NULL) goto skip;
			strlwr(x);
			imsg("Searching file name (%s) \n",x);
			if (strstr(x,".jpg")!=NULL) goto isok;
			if (strstr(x,".jpeg")!=NULL) goto isok;
			if (strstr(x,".exe")!=NULL) goto isok;
			if (strstr(x,".html")!=NULL) goto isok;
			if (strstr(x,".htm")!=NULL) goto isok;
			if (strstr(x,".mpg")!=NULL) goto isok;
			if (strstr(x,".mpeg")!=NULL) goto isok;
			if (strstr(x,".avi")!=NULL) goto isok;
			if (strstr(x,".com")!=NULL) goto isok;
			if (strstr(x,".zip")!=NULL) goto isok;
			if (strstr(x,".doc")!=NULL) goto isok;
			if (strstr(x,".xls")!=NULL) goto isok;
			if (strstr(x,".gif")!=NULL) goto isok;
			goto skip;
isok:			isimage = TRUE;

			printf("
",path_script,x,towww(group),item,got); } skip: if (!isimage) printf("%s",value_encode(s)); if (isimage) { if (strncmp(s,"end",3)==0) isimage = FALSE; } s = get_line(instr); } if (!pre_disable) printf("
\n"); endbit: printf("\n"); printf(""); printf(" "); printf("
Related Items\n",path_script,towww(group),related); printf("Recent Items",path_script,towww(group)); printf("All Groups",path_script); printf("Post Followup",path_script,towww(group),query_find("item")); printf("
\n"); show_end("article"); } static char msgid[BFSZ]; static char subject[BFSZ]; static char from[BFSZ]; static char h_ref[BFSZ]; void show_article1(void) { char *s; char date[BFSZ]; char bf[4000]; char newsgroups[BFSZ]; strcpy(subject,""); strcpy(from,""); strcpy(date,""); strcpy(msgid,""); strcpy(newsgroups,""); s = get_line(instr); for (;s!=NULL;) { if (strcmp(s,"\015")==0) break; head_get("subject:",subject,s); head_get("date:",date,s); head_get("from:",from,s); head_get("references:",h_ref,s); head_get("message-id:",msgid,s); head_get("newsgroups:",newsgroups,s); s = get_line(instr); } var_set("h_subject",value_encode(subject)); var_set("h_date",date); var_set("h_message-id",value_encode(msgid)); var_set("h_from",value_encode(from)); sprintf(bf,"%s %s",h_ref,msgid); var_set("h_references",value_encode(bf)); var_set("h_message-id",msgid); var_set("h_newsgroups",newsgroups); } void show_article3(void) { char *s; s = strchr(from,'\015'); if (s!=NULL) *s = 0; printf("%s wrote:",from); s = get_line(instr); for (;s!=NULL;) { printf(">%s",s); s = get_line(instr); } } void f_post(void) { f_follow(FALSE); } void f_postXX(void) { ncpy(group,query_find("group"),BFSZ-1); printf(" Post new item to group %s ",group); printf(""); printf("
\n",path_script); printf(" \n"); printf(" \n",group); printf("Newsgroup: %s
\n",group); printf("From: (Give EMail address)
\n"); printf("Subject (Required)
\n"); printf("Please enter your message text here: (press enter at the end of each line)
\n"); printf("
\n"); printf("\n"); printf("
\n"); netwin_advert(); printf(""); printf(""); } void f_search(void) { tpl_init(); tpl_show("search.tpl"); /* if (!show_top("fsearch","Search Entire News Database Using: DNEWS Full Text Search Engine")) printf("

Search All News Items

"); printf("
\n",path_script); printf(" \n"); printf(" \n"); printf(" \n"); printf("Key Words:
\n"); printf("\n"); printf("
\n"); printf("

\n"); printf("A higher weighting\n"); printf("is given to words early in your list of key words. \n"); printf("Some common words like 'and' may return '0' matches, this\n"); printf("is normal, these are not kept in the index as they have\n"); printf("no search value.
\n"); show_end("fsearch"); */ } void f_find(void) { tpl_init() ; tpl_show("xsearch.tpl"); } void f_find_xold(void) { if (!show_top("ffind","Search News Group Headers")) printf("

Search headers in %s

",query_find("group")); printf("
\n",path_script); printf(" \n"); printf(" \n",query_find("group")); printf("Search String:
\n"); printf("\n"); printf("
\n"); printf("

\n"); printf("The search is performed on the headers in the news group.\n"); printf("It is not case sensitive. If you give several words they\n"); printf("will only match if the same 'phrase' appears in the news headers
\n"); show_end("ffind"); } void r_search(void) /* from=nnn max=nnn*/ { char bf[BFSZ]; int from = atoi(query_find("from")); int to = atoi(query_find("to")); char key[BFSZ],xkey[BFSZ],zkey[BFSZ]; char *s; int total; int i; char *kw[100]; int nkw; int matches[100]; strcpy(key,query_find("key")); strcpy(zkey,key); s = strtok(key,",+ \t\n"); strcpy(xkey,""); for (nkw=0;s!=NULL;) { strcat(xkey,s); kw[nkw++] = strdup(s); s = strtok(NULL,",+ \t\n"); if (s!=NULL) strcat(xkey,","); } if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} if (!do_authent()) {zmsg("News host authentication failed: %s",nntp_status); return;} sprintf(bf,"xdsearch %d-%d %s\015\012",from,to,xkey); nntp_write_s(chan,bf,strlen(bf)); dmsg("Wait for dindex status\n"); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} s = strchr(nntp_status,':'); if (s!=NULL) total = atoi(s+1); s = strchr(s+1,':'); if (s!=NULL) s = strtok(s,": \015\012"); for (i=0;(s!=NULL) && (i1800) return; x_item[nitem] = atoi(item); x_subject[nitem] = strdup(head_decode(subject)); x_subjectsrt[nitem] = strdup(lib_nore(subject)); x_from[nitem] = strdup(head_decode(from)); x_date[nitem] = strdup(date); x_lines[nitem] = strdup(lines); x_ref[nitem] = strdup(ref); x_mid[nitem] = strdup(mid); nitem++; } int xover_cmp(const void *a,const void *b) { int *aa = (int *) a; int *bb = (int *) b; if (x_f[*aa] < x_f[*bb]) return -1; if (x_f[*aa] > x_f[*bb]) return 1; return 0; } int xover_cmp_old(const void *a,const void *b) { int *aa = (int *) a; int *bb = (int *) b; return strcmp(x_subjectsrt[*aa],x_subjectsrt[*bb]); } void xover_showord(void) { int p[MAX_ITEMS]; int i,ii; for (i=0; i\n"); for (i=0; i",path_script,towww(group),x_item[ii]); printf("%s - %s (%s)
\n",value_encode(x_subject[ii]), email_name(x_from[ii]),x_lines[ii]); } printf("\n"); } void r_find(void) /* from=nnn max=nnn*/ { char bf[BFSZ]; char find[BFSZ]; ncpy(find,query_find("key"),BFSZ-1); ncpy(group,query_find("group"),BFSZ-1); if (!group_allow(group)) return; if (!read_status()) {zmsg("News host not responding1: %s",nntp_status); return;} if (!do_authent()) {zmsg("News host authentication failed: %s",nntp_status); return;} sprintf(bf,"group %s\015\012",group); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding2: %s",nntp_status); return;} sprintf(bf,"xdfind 1- %s\015\012",lib_encode(find)); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding3: %s",nntp_status); return;} read_xover(); show_xover(); tpl_init(); tpl_set_buttons(); var_set("keywords",find); tpl_show("xresults.tpl"); /* if (!show_top("find"," Search results %s ",group)) printf("

Search Results: %s

",group); show_xbar(); xover_showord(); show_xbar(); show_end("find"); */ sprintf(bf,"quit\015\012"); nntp_write_s(chan,bf,strlen(bf)); read_status(); /* Wait for the channel to close */ } void r_xover(void) /* from=nnn max=nnn*/ { char bf[BFSZ]; char rsubject[BFSZ]; char rmsgid[BFSZ]; int from = atoi(query_find("from")); int max = atoi(query_find("max")); int to,xfrom,xto,lastfrom; char *s; int nloop = 0; int fwd = FALSE; int related; dmsg("called r_xover"); related = atoi(query_find("related")); if (strcmp(query_find("forward"),"TRUE")==0) fwd = TRUE; ncpy(group,query_find("group"),BFSZ-1); if (!group_allow(group)) return; if (max==0) max = PAGESIZE; if (max>1000) max = 1000; gmax = max; dmsg("Wait for hello\n"); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} if (!do_authent()) {zmsg("News host authentication failed: %s",nntp_status); return;} sprintf(bf,"group %s\015\012",group); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} if (related>0) { sprintf(bf,"xover %d\015\012",related); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} read_xover(); s = get_line(instr); s = xstrtok(s,"\t"); if (s!=NULL) s = xstrtok(NULL,"\t"); if (s!=NULL) { strlwr(s); if (strncmp(s,"re:",3)==0) s += 3; if (*s == ' ') s++; ncpy(rsubject,s,BFSZ-1); } if (s!=NULL) s = xstrtok(NULL,"\t"); if (s!=NULL) s = xstrtok(NULL,"\t"); if (s!=NULL) s = xstrtok(NULL,"\t"); if (s!=NULL) ncpy(rmsgid,s,BFSZ-1); str_clear(instr); sprintf(bf,"xdfind 1- %s %s\015\012",lib_encode(rsubject),lib_encode(rmsgid)); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} } else { group_from = xfrom = atoi(get_word(nntp_status,2)); group_to = xto = atoi(get_word(nntp_status,3)); if (strlen(query_find("from"))==0) if (from==0) from = xto-max; if (fromgroup_from) gfrom -=max; if (gfrom0) sprintf(bf,"Related items in %s",group); else sprintf(bf,"Items in %s",group); tpl_set_buttons(); tpl_show("items.tpl"); sprintf(bf,"quit\015\012"); nntp_write_s(chan,bf,strlen(bf)); read_status(); /* Wait for the channel to close */ } void r_listall(void) /* from=nnn max=nnn*/ { char bf[BFSZ]; ncpy(group,query_find("group"),BFSZ-1); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} if (!do_authent()) {zmsg("News host authentication failed: %s",nntp_status); return;} sprintf(bf,"xdlist %s\015\012",group); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) { printf("Sorry, this server does not support the nntp DLIST command
"); printf("Try DNEWS 2.5 or later or possibly you need to give your web server access to dnews with no password restrictions
%s
",nntp_status); return; } read_xover(); tpl_init(); tpl_show("list.tpl"); sprintf(bf,"quit\015\012"); nntp_write_s(chan,bf,strlen(bf)); read_status(); /* Wait for the channel to close */ } void r_article(void) /* from=nnn max=nnn*/ { char bf[BFSZ]; int item = atoi(query_find("item")); ncpy(group,query_find("group"),BFSZ-1); imsg("r_article() group=%s item=%d \n",group,item); if (!group_allow(group)) return; if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} if (!do_authent()) {zmsg("News host authentication failed: %s",nntp_status); return;} sprintf(bf,"group %s\015\012",group); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} sprintf(bf,"article %d\015\012",item); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} read_xover(); show_article(); sprintf(bf,"quit\015\012"); nntp_write_s(chan,bf,strlen(bf)); read_status(); /* Wait for the channel to close */ } char *post_template(char *xfname); #define xisspace(x) ((x==' ') || (x=='\t')) void do_wrap(char *msg); void do_wrap(char *msg) { int len; int wrap; char *s; wrap = atoi(ini_get(I_WRAP_POST)); dmsg("wrap at %d\n",wrap); if (wrap==0) return; wrap += 2; for (len=0,s=msg; (*s!=0); len++,s++) { if (len>wrap) if (xisspace(*s)) { *s = '\n'; len = 0; } if ((*s=='\r') || (*s=='\n')) len = 0; } } char *fix_email(char *s) { static char bf[BFSZ]; static char bf2[BFSZ]; char *orig=s; ncpy(bf,s,200); s = strtok(s,"<> \t\n"); for (;s!=NULL;) { if (strchr(s,'@')!=NULL) { sprintf(bf2,"<%s>",s); return bf2; } s = strtok(NULL,"<> \t\n"); } return orig; } char *stripeol(char *s) { char *orig=s; for (;*s!=0;s++) { if (*s=='\r') *s = 0; if (*s=='\n') *s = 0; } return orig; } void r_post(void) /* from=nnn max=nnn*/ { char uinfo[BFSZ]; char ruser[BFSZ]; char bf[BFSZ]; char *s; char xsubj[BFSZ]; char xfile[BFSZ]; char newsgroups[BFSZ]; char xfrom[BFSZ],xname[BFSZ]; int lp; int addmid = FALSE; if (strcmp("true",ini_get(I_ADD_MID))==0) addmid=TRUE; imsg("mid %d, (%s) \n",addmid,ini_get(I_ADD_MID)); strcpy(ruser,mygetenv("REMOTE_ADDR")); if (strlen(ini_get(I_POST_USERS))>0) if (!group_match(ini_get(I_POST_USERS),ruser)) { printf("Sorry, you (%s) have no permission to post.\n
",ruser); return; } tpl_init(); imsg("mid2 \n"); if (strlen(form_find("from"))==0) { var_set("missing","from"); tpl_show("required.tpl"); return; } if (strlen(form_find("subject"))==0) { var_set("missing","subject"); tpl_show("required.tpl"); return; } imsg("mid3 \n"); strcpy(bf,form_find("required")); s = strtok(bf,","); for (;s!=NULL;) { if (strlen(form_find(s))==0) { var_set("missing",s); tpl_show("required.tpl"); return; } var_set(s,form_find(s)); s = strtok(NULL,","); } strcpy(bf,form_find("optional")); s = strtok(bf,","); for (;s!=NULL;) { if (strlen(form_find(s))!=0) { var_set(s,form_find(s)); } s = strtok(NULL,","); } imsg("mid5 \n"); ncpy(group,form_find("group"),BFSZ-1); stripeol(group); if (strlen(ini_get(I_POST_GROUPS))>0) if (!group_match(ini_get(I_POST_GROUPS),group)) { printf("Sorry, posting is not permitted to (%s) \n
",group); return; } if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} if (!do_authent()) {zmsg("News host authentication failed: %s",nntp_status); return;} sprintf(bf,"group %s\015\012",group); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("News host not responding: %s",nntp_status); return;} sprintf(bf,"post\015\012"); nntp_write_s(chan,bf,strlen(bf)); if (!read_status()) {zmsg("Post status bad %s\n",nntp_status); return;} imsg("From %s\n",form_find("from")); ncpy(xfrom,form_find("from"),200); ncpy(xname,form_find("from_name"),200); stripeol(xfrom); stripeol(xname); if (strlen(xname)>0) { sprintf(xfrom,"\"%s\" %s",xname,fix_email(xfrom)); } sprintf(bf,"From: %s\015\012",xfrom); nntp_write_s(chan,bf,strlen(bf)); ncpy(xsubj,stripeol(form_find("subject")),BFSZ-1); strcpy(bf,xsubj); strlwr(bf); s = strtok(bf," \t"); if (strncmp(s,"cmsg",3)==0) { ncpy(bf,stripeol(form_find("subject")),BFSZ-10); strcpy(xsubj,"x-"); strcat(xsubj,bf); } sprintf(bf,"Subject: %s\015\012",xsubj); nntp_write_s(chan,bf,strlen(bf)); strcpy(newsgroups,form_find("newsgroups")); stripeol(newsgroups); if (strlen(newsgroups)>0) { sprintf(bf,"Newsgroups: %s\015\012",newsgroups); nntp_write_s(chan,bf,strlen(bf)); } else { sprintf(bf,"Newsgroups: %s\015\012",stripeol(form_find("group"))); nntp_write_s(chan,bf,strlen(bf)); } if (addmid) { sprintf(bf,"Message-ID: <%d@%s>\015\012",time(NULL),ini_get(I_NEWSHOST)); nntp_write_s(chan,bf,strlen(bf)); } strcpy(uinfo,mygetenv("REMOTE_ADDR")); strcat(uinfo," "); strcat(uinfo,mygetenv("REMOTE_HOST")); strcat(uinfo," "); strcat(uinfo,mygetenv("REMOTE_IDENT")); strcat(uinfo," "); strcat(uinfo,mygetenv("REMOTE_USER")); strcat(uinfo," "); sprintf(bf,"X-User-Info: %s\015\012",uinfo); nntp_write_s(chan,bf,strlen(bf)); if (strlen(form_find("ref"))>0) { sprintf(bf,"References: %s\015\012",stripeol(form_find("ref"))); nntp_write_s(chan,bf,strlen(bf)); } sprintf(bf,"\015\012"); nntp_write_s(chan,bf,strlen(bf)); imsg("Message \n"); s = form_find("message"); imsg("message length %d\n",strlen(s)); do_wrap(s); imsg("message warpeed (%d)\n",strlen(s)); strcpy(xfile,form_find("template")); if (strlen(xfile)>0) { var_set("message",s); s = post_template(xfile); } imsg("message send (%d)\n",strlen(s)); if (s!=NULL) nntp_write_s(chan,s,strlen(s)); sprintf(bf,"\015\012.\015\012"); nntp_write_s(chan,bf,strlen(bf)); for (lp=0;nntp_isbusy(chan) && lp<10000;lp++) { nntp_write_now(chan); } imsg("readstatus (%d)\n",strlen(s)); read_status(); /* Wait for the channel to close */ imsg("readstatxxxus (%d)\n",strlen(s)); var_set("post_status",nntp_status); if (atoi(nntp_status)==240) { var_set("ok","TRUE"); } tpl_show("posted.tpl"); sprintf(bf,"quit\015\012"); nntp_write_s(chan,bf,strlen(bf)); read_status(); /* Wait for the channel to close */ } void show_dline(char *s) { char bf[BFSZ]; char gname[BFSZ]; char mod[BFSZ]; char from[BFSZ]; char to[BFSZ]; char items[BFSZ]; ncpy(bf,s,BFSZ-1); s = strtok(bf," "); if (s==NULL) return; ncpy(gname,s,BFSZ-1); s = strtok(NULL," "); if (s==NULL) return; ncpy(to,s,BFSZ-1); s = strtok(NULL," "); if (s==NULL) goto doit; ncpy(from,s,BFSZ-1); s = strtok(NULL," "); if (s==NULL) goto doit; strcpy(mod,""); if (*s=='m') strcpy(mod,"(Moderated)"); s = strtok(NULL," "); if (s==NULL) goto doit; ncpy(items,s,BFSZ-1); doit:; if (gname[0]=='+') { strcat(to,"."); if (group_match(ini_get(I_ALLOW),to)) { printf("
  • %s.. %s groups
    ",path_script,towww(to),to,from); } } else { if (group_match(ini_get(I_ALLOW),gname)) { printf("
  • %s, %s items %s
    ",path_script,towww(gname),gname,items,mod); } } } static char topname[BFSZ]; void r_list(void) { tpl_init(); tpl_show(topname); dmsg("top done\n"); } /* ---------------------------------------- xxx.ini file processing -- */ void db_setscript(char *script) { char *last; char *s; char bf[BFSZ]; strcpy(path_script,script); ncpy(bf,script,BFSZ-1); last = bf-1; for (s=bf;*s!=0;s++) { if (*s=='/') last = s; if (*s=='\\') last = s; } ncpy(rootname,last+1,BFSZ-1); s = strchr(rootname,'.'); if (s!=NULL) *s = 0; if (strlen(rootname)==0) strcpy(rootname,"dnewsweb"); } char *ini_values[200]; int ini_find(char *s) { int i; for (i=0; ini_names[i]!=NULL; i++) { if (strcmp(ini_names[i],s)==0) return i; } return -1; } char *ini_get(int x) { if (ini_values[x]!=NULL) return ini_values[x]; return ""; } int ini_read(char *epath) { char bf[BFSZ]; char bf2[BFSZ]; char bf3[BFSZ]; char xroot[BFSZ]; char xin[5000]; char *last; FILE *f; int i; char *s; db_setscript(mygetenv("SCRIPT_NAME")); sprintf(bf,"%s.ini",rootname); f = fopen(bf,"r"); strcpy(bf3,bf); if (f==NULL) { imsg("ini file not in working dir, searching in path {%s} \n",epath); strcpy(xroot,epath); last = xroot; for (s=xroot; *s!=0; s++) { if (*s=='/') last = s; if (*s=='\\') last = s; } *last = 0; sprintf(bf,"%s/%s.ini",xroot,rootname); imsg("Looking in (%s) for ini file\n",bf); f = fopen(bf,"r"); strcpy(bf2,bf); } if (f==NULL) { sprintf(bf,"/etc/%s.ini",rootname); imsg("Last resort, looking in (%s) for ini file\n",bf); f = fopen(bf,"r"); } if (f==NULL) { done_content = TRUE; if (docache) printf("Pragma: cache\n"); printf("Content-type: %s\n\n",content_type()); emsg("Unable to find ini file in
    {%s} \n",bf3); emsg("Also looked in {%s}
    and {%s}
    \n",bf2,bf); #ifdef WIN32 GetCurrentDirectory(200,bf); emsg("Place dnewsweb.ini file in this directory {%s} \n",bf); #endif return FALSE; } for (;!feof(f);) { if (fgets(xin,4000,f)!=NULL) { ncpy(bf,xin,BFSZ-20); s = strtok(bf," \t\n"); if (s==NULL) continue; if (*s==0 || *s=='#') continue; i = ini_find(s); if (i<0) { emsg("Unknown ini file setting {%s} \n",s); continue; } s = strtok(NULL,"\n"); if (s==NULL) continue; ini_values[i] = strdup(s); } } fclose(f); return TRUE; } /* ---------------------- Missing bits that are needed ---------------------- */ #define OUTSIZE 5000 static char output[OUTSIZE]; void emsg_do(int x, char *s); void emsg(char * arg_list, ...) { va_list arg_ptr; char *format; int len; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); emsg_do(D_ERROR,output); } void filemsg(char * arg_list, ...) { va_list arg_ptr; char *format; int len; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); emsg_do(D_ERROR,output); } void imsg(char * arg_list, ...) { va_list arg_ptr; char *format; int len; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); emsg_do(D_INFO,output); } void h_printf(char * arg_list, ...) { va_list arg_ptr; char *format; int len; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); printf("%s",output); emsg_do(D_DEBUG,output); } void zmsg(char * arg_list, ...) { va_list arg_ptr; char *format; int len; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); if (!done_content) { if (docache) printf("Pragma: cache\n"); printf("Content-type: %s\n\n",content_type()); } printf("%s",output); emsg_do(D_INFO,output); } void wmsg(char * arg_list, ...) { va_list arg_ptr; char *format; int len; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); emsg_do(D_INFO,output); } void dmsg(char * arg_list, ...) { va_list arg_ptr; char *format; int len; if (!dodebug) return; va_start(arg_ptr, arg_list); format = arg_list; len = vsprintf(output, format, arg_ptr); if (len>=OUTSIZE) emsg_do(D_ERROR,"FATAL, EMSG ERROR TOO LONG\n"); emsg_do(D_DEBUG,output); } void emsg_reset(void) { remove(log_file); } void emsg_do(int x, char *s) { time_t ltime; char bf[BFSZ]; FILE *f; time( <ime ); strcpy(bf,ctime(<ime)); bf[19] = 0; if (x==D_ERROR) printf("
    Error: %s
    ",s); f = fopen(log_file,"a"); if (f==NULL) {perror(log_file); return; } fprintf(f,"%s, %s",bf+4,s); fclose(f); } /* ---------------------- Missing bits that are needed ---------------------- */ char *group_name(int i) { return "(none)"; } #ifndef unix int lib_mail_file(char *to, char *subj, char *fname) { return TRUE; } int lib_freespace(char *s) { return 100000; } #endif int diskuse_get(void) { return 0; } char *nt_pcname(void); char *lib_findfile(char *x) { return NULL; } void dnews_manager_report(char *s) { } int post_local(String *xitem, char *addr, int ismod) { return TRUE; } void dnews_exit(char *reason, char *file, int line) { printf("Crashing\n"); exit(1); } #ifdef WIN32 char *nt_pcname(void) { return "pcname"; } #endif /* ------------------ library of stuff for web --------------------*/ static char *query_name[1000]; static char *query_val[1000]; static int nquery; /* Query string */ char *lib_encode(char *s) { char *ss=s; for (;*s!=0;s++) { if (isspace(*s)) *s = '+'; } return ss; } char *value_encode(char *s) { static char bf[2010]; int noencode=FALSE; int i; int iniso; int addend=FALSE; char *out=bf; for (i=0; i<2000 && *s!=0;i++,s++) { if (noencode) { if (*s==27) { if (strncmp(s+1,"(B",2)==0) noencode = FALSE; } *out++ = *s; continue; } if (*s=='<') { strcpy(out,"<"); out += strlen(out); } else if (*s=='>') { strcpy(out,">"); out += strlen(out); } else if (*s=='&') { strcpy(out,"&"); out += strlen(out); } else if (*s=='"') { strcpy(out,"""); out += strlen(out); } else if (*s==27) { if (strncmp(s+1,"$B",2)==0) noencode = TRUE; *out++ = *s; } else *out++ = *s; } *out++ = 0; return bf; } char *head_decode(char *s) { return s; /* static char bf[10000]; char *out,*s2; int iniso=FALSE; for (out=bf;*s!=0;s++) { if ((strncmp(s,"=?iso",5)==0) || (strncmpnc(s,"=?ISO",5)==0)) { s2 = strchr(s+3,'?'); if (s2!=NULL) s = s2; iniso = TRUE; strcpy(out,"\033$B"); out+= strlen(out); continue; } if (iniso) if ((strncmp(s,"?=",2)==0)) { s = s+1; iniso = FALSE; strcpy(out,"\033(B"); out+= strlen(out); continue; } *out++ = *s; } *out++ = 0; return bf; */ } /* Same as value encode except. user@a.b.c --> user@a.b.c http://netwin.co.nz --> htp://netwin.co.nz */ char *ref_encode_http(char *instr); char *ref_encode_mail(char *instr); char *ref_encode(char *s); char *ref_encode(char *s) { static char bf[5000]; strcpy(bf,s); if (strchr(s,27)!=NULL) return bf; s = ref_encode_mail(bf); s = ref_encode_http(s); return s; } char *ref_encode_mail(char *instr) { char bf[BFSZ]; char bf2[BFSZ]; char *s,*s1,*s2; s = instr; again: s = strchr(s,'@'); if (s==NULL) return instr; if (s>instr) if (s[-1]<0) { s++; goto again; } for (s1=s;s1>instr;s1--) { if (isspace(*s1)) { s1++; break; } } for (s2=s;*s2!=0;s2++) { if (isspace(*s2)) break; } s2--; ncpy(bf,s1,s2-s1+1); sprintf(bf2,"%s",bf,bf); memmove(s1+strlen(bf2),s2+1,strlen(s2+1)+1); strncpy(s1,bf2,strlen(bf2)); s = s1 + strlen(bf2); goto again; } char *ref_encode_http(char *instr) { char *s,*s1,*s2; char bf[BFSZ]; char bf2[BFSZ]; s = instr; again: s = strstr(s,"http:"); if (s==NULL) return instr; if (s>instr) if (s[-1]<0) { s++; goto again; } s1 = s; for (s2=s;*s2!=0;s2++) { if (isspace(*s2)) break; } s2--; ncpy(bf,s1,s2-s1+1); sprintf(bf2,"%s",bf,bf); memmove(s1+strlen(bf2),s2+1,strlen(s2+1)+1); strncpy(s1,bf2,strlen(bf2)); s = s1 + strlen(bf2); goto again; } char *decode_base64s(char *s); char *decode_base64s(char *s) { static char bf[2000]; int n = decode_base64(s,bf); bf[n] = 0; return bf; } char *decode_quote(char *s) { static char bf[2000]; int i; char *out=bf; for (i=0; i<2000 && *s!=0;i++,s++) { if (*s<0) { *out++ = *s++; *out++ = *s; } else if (strncmp(s,"=3D",3)==0) *out++ = '='; else if (*s=='=') *out++ = '\n'; else *out++ = *s; } *out++ = 0; return bf; } char *wrap_encode(char *s); char *text_encode(char *s) { int noencode=FALSE; static char bf[2010]; int i; char *out=bf; for (i=0; i<2000 && *s!=0;i++,s++) { if (noencode) { if (*s==27) { if (strncmp(s+1,"(B",2)==0) noencode = FALSE; } *out++ = *s; continue; } if (*s<0) { *out++ = *s++; *out++ = *s; } else if (*s=='<') { strcpy(out,"<"); out += strlen(out); } else if (*s=='>') { strcpy(out,">"); out += strlen(out); } else if (*s=='&') { strcpy(out,"&"); out += strlen(out); } else if (*s==27) { if (strncmp(s+1,"$B",2)==0) noencode = TRUE; *out++ = *s; } else *out++ = *s; } *out++ = 0; return ref_encode(wrap_encode(bf)); } char *wrap_encode(char *s) { static char bf[4000]; int i; char *out=bf; int len; int w = atoi(ini_get(I_WRAP_TEXT)); if (w==0) return s; dmsg("Wrap text at %d\n",w); len = 0; for (i=0; (i<2000) && (*s!=0);i++,s++,len++) { if (*s=='\n') len = 0; if (*s=='\r') len = 0; if (len>w) { if (isspace(*s)) { *out++ = '\n'; len = 0; continue; } } *out++ = *s; } *out++ = 0; return bf; } char *mygetenv(char *v) { char *s = getenv(v); if (s==NULL) return ""; return s; } char *query_find(char *s) { int i; for (i=0; i= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); digit *= 16; digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); return(digit); } void unescape_url(char *url) { register int x,y; for(x=0,y=0;url[y];++x,++y) { if((url[x] = url[y]) == '%') { url[x] = x2c(&url[y+1]); y+=2; } } url[x] = '\0'; } void plustospace(char *str) { register int x; for(x=0;str[x];x++) if(str[x] == '+') str[x] = ' '; } static char *form_name[1000]; static char *form_val[1000]; static int nform; char *makeword(char *line, char stop) ; char *fmakeword(FILE *f, char stop, int *cl); void convert_crlf(char *s); /* turn crlf into lf's */ void form_get(void) { int x,cl; char *s = mygetenv("CONTENT_LENGTH"); if (s==NULL) return; cl = atoi(s); for(x=0;cl && (!feof(stdin));x++) { form_val[x]= fmakeword(stdin,'&',&cl); plustospace(form_val[x]); unescape_url(form_val[x]); form_name[x] = makeword(form_val[x],'='); convert_crlf(form_val[x]); } nform = x; } void convert_crlf(char *s) { char *out=s; for (;*s!=0;s++) { if (*s == '\015') s++; *out++ = *s; } *out++ = 0; } char *makeword(char *line, char stop) { int x = 0,y; char *word = (char *) malloc(sizeof(char) * (strlen(line) + 1)); for(x=0;((line[x]) && (line[x] != stop));x++) word[x] = line[x]; word[x] = '\0'; if(line[x]) ++x; y=0; while(line[y++] = line[x++]); return word; } char *fmakeword(FILE *f, char stop, int *cl) { int wsize; char *word; int ll; wsize = 8024; ll=0; word = (char *) malloc(sizeof(char) * (wsize + 1)); while(1) { word[ll] = (char)fgetc(f); if(ll==wsize) { word[ll+1] = '\0'; wsize+=8024; word = (char *)realloc(word,sizeof(char)*(wsize+1)); } --(*cl); if((word[ll] == stop) || (feof(f)) || (!(*cl))) { if(word[ll] != stop) ll++; word[ll] = '\0'; return word; } ++ll; } } char *form_find(char *s) { int i; for (i=0; i%s",output); printf(""); return FALSE; } void show_end(char *type) { show_headfile(type,NULL); if (strlen(ini_get(I_NOADVERT))==0) netwin_advert(); printf(""); printf(""); } int show_headfile(char *type, char *title) { char fname[BFSZ]; char bf[BFSZ],bf2[BFSZ]; char *s; FILE *f; char *ext = ".top"; if (title==NULL) ext = ".end"; if (strlen(ini_get(I_HEADERS))==0) return FALSE; sprintf(fname,"%s/%s%s",ini_get(I_HEADERS),type,ext); dmsg("Top file (%s)",fname); f = fopen(fname,"r"); if (f==NULL) { if (title!=NULL) printf("Top or End file missing {%s}
    \n",fname); return FALSE; } for (;!feof(f);) { if (fgets(bf,BFSZ-1,f)==NULL) break; if (title!=NULL) { s = strstr(bf,"$title$"); if (s!=NULL) { strcpy(bf2,s+7); strcpy(s,title); strcat(s,bf2); } } printf("%s",bf); } fclose(f); return TRUE; } char *file_tpl(char *fname) { char bf[BFSZ]; static char rslt[BFSZ]; strcpy(bf,tplname); if (strlen(bf)>0) strcat(bf,"/"); if (strlen(ini_get(I_TEMPLATES))>0) sprintf(rslt,"%s/%s%s",ini_get(I_TEMPLATES),bf,fname); else sprintf(rslt,"%s/%s%s",ini_get(I_HEADERS),bf,fname); #ifdef VMS sprintf(rslt,"%s%s%s",ini_get(I_TEMPLATES),bf,fname); #endif return rslt; } int tpl_show_file(char *xfname) { FILE *f; char fname[BFSZ]; char bf[BFSZ]; strcpy(fname,file_tpl(xfname)); f = fopen(fname,"r"); if (f==NULL) { printf("Include file missing {%s}
    \n",fname); return FALSE; } for (;!feof(f);) { if (fgets(bf,BFSZ-1,f)==NULL) break; printf("%s",bf); } fclose(f); return TRUE; } char *towww(char *s) { static char bf[BFSZ],*out; for (out=bf;*s!=0;s++) { if (isspace(*s)) *s = '+'; if (*s=='+') {sprintf(out,"%%%x",*s); out += strlen(out);} else if (*s=='&') {sprintf(out,"%%%x",*s); out += strlen(out);} else *out++ = *s; } *out++ = 0; return bf; } char *post_template(char *xfname) { FILE *f; char fname[BFSZ]; char bf[90000]; static char msg[90000]; char *s; strcpy(fname,file_tpl(xfname)); tpl_init(); f = fopen(fname,"r"); if (f==NULL) { printf("Cannot open template {%s}
    \n",fname); #ifndef NOSTRERROR printf("%s
    ",strerror(errno)); #endif return NULL; } strcpy(msg,""); for (;!feof(f);) { if (fgets(bf,BFSZ-1,f)==NULL) break; s = strchr(bf,'\n'); if (s!=NULL) *s = 0; s = strchr(bf,'\r'); if (s!=NULL) *s = 0; s = tpl_replace(bf); strcat(msg,s); strcat(msg,"\n"); } return msg; } void tpl_show(char *xfname) { FILE *f; char fname[BFSZ]; char bf[10000]; char *s; dmsg("tpl_show called (%s)\n",xfname); tpl_init(); strcpy(fname,file_tpl(xfname)); dmsg("tpl_show called (%s)\n",fname); dmsg("tpl_show init done\n"); f = fopen(fname,"r"); if (f==NULL) { printf("Cannot open {%s} check your templates setting in dnewsweb.ini is correct and that this file is readable by the web server user code \n",fname); #ifndef NOSTRERROR printf("%s
    ",strerror(errno)); #endif return; } for (;!feof(f);) { if (fgets(bf,BFSZ-1,f)==NULL) break; s = strchr(bf,'\n'); if (s!=NULL) *s = 0; s = strchr(bf,'\r'); if (s!=NULL) *s = 0; s = tpl_replace(bf); if (strlen(s)>0) printf("%s\n",s); } dmsg("tpl_show done\n"); } static int tpl_mode; static char tpl_item[MAX_ITEMS]; static char tpl_dir[MAX_ITEMS]; static char* tpl_indent_on[20]; static char* tpl_indent_off[20]; char *tpl_indenton(int i) { if (i<0) return ""; if (i>9) return ""; if (tpl_indent_on[i]!= NULL) return tpl_indent_on[i]; return ""; } char *tpl_indentoff(int i) { if (i<0) return ""; if (i>9) return ""; if (tpl_indent_off[i]!= NULL) return tpl_indent_off[i]; return ""; } enum {T_NORM,T_ITEM,T_DIR,T_LIST,T_IF}; void tpl_setindent(char *s) { int i; /* %%indent%%1%%on%%off%% */ int n; char *s2; char *s3,*s4; s += 10; n = atoi(s); if (n<0) return; if (n>9) return; s2 = strstr(s,"%%"); if (s2==NULL) return; s2 += 2; s3 = strstr(s2,"%%"); if (s3==NULL) return; *s3 = 0; s3 += 2; s4 = strstr(s3,"%%"); if (s4==NULL) return; *s4 = 0; tpl_indent_on[n] = mystrdup(s2); tpl_indent_off[n] = mystrdup(s3); for (i=n+1; i<10; i++) { if (tpl_indent_on[i]==NULL) { tpl_indent_on[i] = ""; tpl_indent_off[i] = ""; } } return; } void tpl_set_buttons(void) { char bf[BFSZ]; if (gfrom>group_from) { sprintf(bf,"%s?cmd=xover&group=%s&from=%d",path_script,towww(group),gfrom-gmax); var_set("b_prev",bf); } if (gto \n DNEWSWEB %s Copyright © NetWin Ltd\n ",DNEWS_VERSION,path_script); var_set("copyright",bf); ncpy(topname,query_find("top"),BFSZ-1); if (strlen(topname)==0) { ncpy(topname,form_find("top"),BFSZ-1); } if (strlen(topname)==0) strcpy(topname,"top.tpl"); var_set("top",topname); ncpy(tplname,query_find("tpl"),BFSZ-1); if (strlen(tplname)==0) { ncpy(tplname,form_find("tpl"),BFSZ-1); } if (strlen(tplname)==0) strcpy(tplname,""); var_set("tpl",tplname); ncpy(group,query_find("group"),BFSZ-1); var_set("group",group); if (strlen(group)==0) { ncpy(group,form_find("group"),BFSZ-1); var_set("group",group); } sprintf(bf,"%s?cmd=f_find&group=%s",path_script,towww(group)); var_set("b_searchgrp",bf); var_set("action",path_script); if (strlen(ini_get(I_SEARCH))>0) { sprintf(bf,"%s?cmd=f_search",path_script); var_set("b_search",bf); } } /* Add options like %%if var_name xxxx %%endif */ char *tpl_replace(char *bf) { char *s,*s2; char var[BFSZ]; char head[BFSZ]; char list[BFSZ]; static int lvl; switch (tpl_mode) { case T_IF: if (strncmp(bf,"%%ifdef%%",9)==0) { lvl++; } else if (strcmp(bf,"%%endif%%")==0) { lvl--; if (lvl==0) tpl_mode = T_NORM; } if (lvl==1) if (strcmp(bf,"%%else%%")==0) tpl_mode = T_NORM; break; case T_NORM: if (strcmp(bf,"%%begin_item%%")==0) { tpl_mode = T_ITEM; strcpy(tpl_item,""); return ""; } else if (strncmp(bf,"%%else%%",9)==0) { tpl_mode = T_IF; lvl = 1; } else if (strncmp(bf,"%%ifdef%%",9)==0) { /* %%if%%var%% */ s = bf+9; s2 = strstr(s,"%%"); if (s2==NULL) return bf; ncpy(var,s,s2-s); if (strcmp(var_find(var),"")==0) { tpl_mode = T_IF; lvl = 1; dmsg("Variable undefined {%s}\n",var); } else dmsg("Variable is defined {%s}\n",var); } else if (strncmp(bf,"%%ifgroup%%",11)==0) { s = bf+11; s2 = strstr(s,"%%"); if (s2==NULL) return bf; ncpy(var,s,s2-s); if (!group_match(var,group)) { tpl_mode = T_IF; lvl = 1; dmsg("Group didn't match {%s} {%s}\n",var,group); } else dmsg("Group matched {%s} {%s}\n",var,group); } else if (strncmp(bf,"%%ifcgi%%",9)==0) { s = bf+9; s2 = strstr(s,"%%"); if (s2==NULL) return bf; ncpy(head,s,s2-s); s = s2+2; s2 = strstr(s,"%%"); if (s2==NULL) return bf; ncpy(list,s,s2-s); imsg("ifhead Test (%s) (%s) (%s)\n",list,head,mygetenv(head)); if (!group_match(list,mygetenv(head))) { tpl_mode = T_IF; lvl = 1; imsg("ENV didn't match {%s} {%s}\n",list,mygetenv(head)); } else imsg("ENV matched {%s} {%s}\n",list,mygetenv(head)); } else if (strncmp(bf,"%%include%%",11)==0) { s = bf+11; s2 = strstr(s,"%%"); if (s2==NULL) return bf; ncpy(var,s,s2-s); tpl_show_file(var); } else if (strcmp(bf,"%%quote_body%%")==0) { tpl_quote_body(); return ""; } else if (strcmp(bf,"%%show_item_image%%")==0) { tpl_show_item_image(); return ""; } else if (strcmp(bf,"%%show_item%%")==0) { tpl_show_item(); return ""; } else if (strcmp(bf,"%%begin_dir%%")==0) { tpl_mode = T_DIR; return ""; } else if (strncmp(bf,"%%indent%%",10)==0) { tpl_setindent(bf); return ""; } else return tpl_replace_vars(bf); break; case T_ITEM: if (strcmp(bf,"%%end_item%%")==0) { tpl_mode = T_NORM; tpl_show_group(); return ""; } strcat(tpl_item,bf); break; case T_DIR: if (strcmp(bf,"%%end_dir%%")==0) { tpl_mode = T_NORM; tpl_show_list(); return ""; } break; } return ""; } static char *var_names[200]; static char *var_values[200]; static int nvar; char *var_find(char *var) { int i; for (i=0; i 60000) { s = var_values[i]; s[60000] = 0; } } char *tpl_replace_vars(char *orig) { char var[BFSZ]; char *s=orig; char *s2; again: s = strstr(s,"%%"); if (s==NULL) return orig; s += 2; s2 = strstr(s,"%%"); if (s2==NULL) return orig; ncpy(var,s,s2-s); tpl_replace_var(s-2,(s2+2) - (s-2) ,var_find(var)); s -= 2; goto again; } void tpl_replace_var(char *bf, int len, char *var) { int nlen = strlen(var); memmove(bf+nlen,bf+len,strlen(bf+len)+1); strncpy(bf,var,nlen); } int ref_find(char *ref) { int i; int j; char bf[BFSZ]; int np; char *p[1000]; strcpy(bf,ref); np = token_split(bf,p," "); for (j=np-1; j>=0; j--) { for (i=0; i9) tot = 9; return tot; } static int rev = 1; void tpl_show_group(void) { int p[9000]; char bf[10000]; char bf2[10000]; char *s; int repeat; int nloop=0; int j; int i2; int z; int depth,d,newdepth; int i,ii; double px,py; rev = 1; if (strcmp("true",ini_get(I_SORT_REV))==0) rev = -1; if (nitem>MAX_ITEMS) nitem = MAX_ITEMS; for (i=0; i0) { x_depth[i] = ref_depth(x_ref[i]); j = ref_find(x_ref[i]); if (j>=0) x_fi[i] = j; else x_f[i] = rev*i; } else x_f[i] = rev*i; /* dmsg("[%d] points to %d\n",i,x_fi[i]);*/ } for (repeat=TRUE;repeat && (nloop<10);nloop++) { repeat = FALSE; for (i=0; i7) py = 7; px = pow(40,py); if (px<=1) px = 1; if (x_f[x_fi[i]] == -9999) repeat = TRUE; else { if (px==0) px = 1; x_f[i] = x_f[x_fi[i]] + ((double) i)/(double) px; if (x_f[i] > pow(40,8)) x_f[i] = pow(40,8); } /* if (x_f[i]<0) repeat = TRUE;*/ /* dmsg("[%d] set to %d = %g %g [%g]+%g %g\n",i,x_fi[i],x_f[i],(double) pow(50,x_depth[i]),x_f[x_fi[i]],i/(double) pow(50,x_depth[i]),(double) pow(50,(double) x_depth[i])) ;*/ } } } if (!search_result) { if (nitem>2) qsort(p,nitem,sizeof(int),xover_cmp); printf("%s",tpl_indenton(1)); } depth = 1; for (i=0; i0) i2 = p[i-1]; if (search_result) goto skip; newdepth = ref_depth(x_ref[ii]); if (i==0) newdepth = 1; if (newdepth!=1) { if (rev) { if (((int) (x_f[ii]+0.0000001)) != ((int) (x_f[i2]+0.0000001))) { newdepth = 1; } } else { if (((int) x_f[ii]) != ((int) x_f[i2])) { newdepth = 1; } } } if (newdepth>9) newdepth = 9; for (d = depth+1; d <= newdepth; d++) { printf("%s",tpl_indenton(d)); } for (d = depth; d > newdepth; d--) { printf("%s",tpl_indentoff(d)); } depth = newdepth; skip: if (x_group[ii]!=NULL) if (strlen(x_group[ii])>0) { strcpy(bf2,x_group[ii]); s = strchr(bf2,':'); if (s!=NULL) { *s = 0; s++; strcpy(group,bf2); x_item[ii] = atoi(s); goto skip2; } } skip2: var_set("h_group",value_encode(group)); sprintf(bf,"%s?cmd=article&group=%s&item=%d",path_script,towww(group),x_item[ii]); var_set("b_item",bf); var_set("h_subject",value_encode(x_subject[ii])); /*sprintf(bf,"%g %s",x_f[ii],value_encode(x_subject[ii])); var_set("h_subject",bf); */ if (depth>1) { z = (depth-1) * 1; if (z>10) z=10; memset(bf,'-',z); bf[z] = '>'; bf[z+1] = 0; var_set("arrows",value_encode(bf)); } else var_set("arrows",""); if (depth>1) { z = (depth-1) * 1 + 1; if (z>10) z=10; memset(bf,' ',z); bf[z] = 0; var_set("spaces",value_encode(bf)); } else var_set("spaces",""); var_set("h_from",value_encode(x_from[ii])); var_set("h_message-id",value_encode(x_mid[ii])); var_set("h_lines",x_lines[ii]); var_set("h_score",x_score[ii]); var_set("h_date",value_encode(x_date[ii])); var_set("h_date_trim",value_encode(h_date_trim(x_date[ii]))); var_set("h_from_trim",value_encode(h_from_trim(x_from[ii]))); var_set("h_subject_60",value_encode(h_trim(x_subject[ii],60))); var_set("h_subject_40",value_encode(h_trim(x_subject[ii],40))); var_set("h_subject_30",value_encode(h_trim(x_subject[ii],30))); strcpy(bf,tpl_item); s = tpl_replace_vars(bf); printf("%s\n",s); } if (search_result) return; for (d = depth; d > 1; d--) { printf("%s",tpl_indentoff(d)); } printf("%s",tpl_indentoff(1)); } /* x y = x y a@b = a a@b (name) = name */ char *h_from_trim(char *s) { static char bf[BFSZ]; char *s2; strcpy(bf,s); /* a@b (name) */ s = strchr(bf,'('); if (s!=NULL) { s2 = strchr(s,')'); if (s2==NULL) return bf; *s2 = 0; return s+1; } /* x y = x y*/ s = strchr(bf,'<'); if (s!=NULL) { for (s=bf;*s!=0; s++) if (!isspace(*s)) break; if (*s!='<') { s2 = strchr(s,'<'); if (s2==NULL) return bf; *s2 = 0; return s; } else { /* */ s2 = strchr(s,'>'); if (s2==NULL) return bf; *s2 = 0; return s+1; } } if (strchr(bf,'@')==NULL) return bf; /*a@b*/ for (s=bf;*s!=0; s++) if (!isspace(*s)) break; for (s2=s;*s2!=0;s2++) if (isspace(*s2)) break; *s2 = 0; return s; } char *h_trim(char *s, int len) { static char bf[BFSZ]; ncpy(bf,s,len); if (strlen(s)>len) strcat(bf,"*"); return bf; } /* Tue, 3 Jan 98 23:33:33 GMT */ /* 3 Jan 93 */ char *h_date_trim(char *instr) { static char bf[BFSZ]; char *s; s = strchr(instr,','); if (s==NULL) s = instr; else s++; for (;*s==' ';) s++; strcpy(bf,s); s = strchr(bf,' '); if (s==NULL) return bf; s = strchr(s+1,' '); if (s==NULL) return bf; s = strchr(s+1,' '); if (s==NULL) return bf; *s = 0; return bf; } void tpl_show_list(void) { show_dlist(); } void tpl_show_top(void) { printf("show list of top news groups\n"); } void show_article(void) { int part = atoi(query_find("part")); if (part>0) { imsg("Show article part\n"); show_article_part(part); imsg("Show article part done\n"); return; } tpl_init_item(); tpl_show("item.tpl"); } static char boundary[BFSZ]; static int isimage = FALSE; static char mime[BFSZ]; static char xhtml[BFSZ]; static char encoding[BFSZ]; void get_attach_name(char *in); static char attach_name[BFSZ]; void tpl_init_item(void) { char *s,*x; char subject[BFSZ]; static char from[BFSZ]; static char date[BFSZ]; static char ref[BFSZ]; static char mid[BFSZ]; static char content[BFSZ]; char bf[BFSZ]; char *s2; int gothead = FALSE; int multi,got,istext; char newsgroups[BFSZ]; int item = atoi(query_find("item")); int related = item; multi = got = istext = FALSE; strcpy(subject,""); strcpy(from,""); strcpy(date,""); strcpy(newsgroups,""); related = item; if (docache) printf("Pragma: cache\n"); printf("Content-type: %s\n\n",content_type()); strcpy(attach_name,"attach.jpg"); var_set("group",group); var_set("item",query_find("item")); sprintf(bf,"%s?cmd=xover&group=%s&related=%d",path_script,towww(group),related); var_set("b_related",bf); sprintf(bf,"%s?cmd=xover&group=%s",path_script,towww(group)); var_set("b_recent",bf); sprintf(bf,"%s?cmd=list",path_script); var_set("b_topgroups",bf); sprintf(bf,"%s?cmd=listall",path_script); var_set("b_allgroups",bf); sprintf(bf,"%s?cmd=post&group=%s",path_script,towww(group),query_find("item")); var_set("b_post",bf); sprintf(bf,"%s?cmd=follow&group=%s&item=%s",path_script,towww(group),query_find("item")); var_set("b_follow",bf); s = get_line(instr); for (;s!=NULL;) { if (strcmp(s,"\015")==0) break; head_get("subject:",subject,s); head_get("date:",date,s); head_get("message-id:",mid,s); head_get("from:",from,s); head_get("references:",ref,s); head_get("newsgroups:",newsgroups,s); head_get("mime-version:",mime,s); head_get("x-html:",xhtml,s); head_get("content-type:",content,s); head_get("content-transfer-encoding:",encoding,s); get_attach_name(s); s2 = strstr(s,"boundary="); if (s2==NULL) s2 = strstr(s,"Boundary="); if (s2!=NULL) { s2 = strchr(s2,'"'); strcpy(boundary,"--"); if (s2!=NULL) ncpy(boundary+2,s2+1,BFSZ-10); s2 = strchr(boundary,'"'); if (s2!=NULL) *s2 = 0; } s = get_line(instr); } var_set("h_from",value_encode(from)); var_set("h_references",value_encode(ref)); var_set("h_subject",value_encode(subject)); var_set("h_date",value_encode(date)); var_set("h_message-id",value_encode(mid)); var_set("h_newsgroups",value_encode(newsgroups)); var_set("h_content-type",value_encode(content)); strlwr(content); if (strlen(xhtml)==0) if (strstr(content,"text/html")!=NULL) strcpy(xhtml,content); } char *quote_encode(char *s); void tpl_quote_body(void) { char *s; if (instr==NULL) return; s = strchr(from,'\015'); if (s!=NULL) *s = 0; printf("%s wrote:\n",from); s = get_line(instr); for (;s!=NULL;) { printf("%s",quote_encode(s)); s = get_line(instr); } } char *quote_encode(char *s) { static char bf[4000]; int i; char *out=bf; int len; int w = atoi(ini_get(I_WRAP_TEXT)); w -= 8; if (w<=0) w = 1000; len = 0; *out++ = '>'; for (i=0; (i<2000) && (*s!=0);i++,s++,len++) { if (*s=='\n') len = 0; if (*s=='\r') len = 0; if (len>w) { if (isspace(*s)) { *out++ = '\n'; *out++ = '>'; len = 0; continue; } } *out++ = *s; } *out++ = 0; return bf; } /* For clarinet *.web groups
    ",path_script,attach_name,towww(group),item); } void tpl_show_item(void) { static int multi; int istext = FALSE; int ishtml = FALSE; char *x; int gothead = FALSE; int isquoted=FALSE; int isref = FALSE; char *z; int isbase64=FALSE; char bf[BFSZ]; int got; char *s; int item = atoi(query_find("item")); char *s2; int israw = FALSE; imsg("tpl_show_item()\n"); strlwr(encoding); multi = FALSE; if (strlen(xhtml)>0) israw = TRUE; if (strlen(mime)>0) if (strlen(boundary)>0) multi = TRUE; if (!multi) if (strstr(encoding,"base64")!=NULL) { printf("
    ",path_script,attach_name,towww(group),item); goto endbit; } got = 0; if (multi) { s = get_line(instr); for (;s!=NULL;) { s2 = strchr(s,'\015') ; if (s2!=NULL) *s2 = 0; s2 = strchr(s,'\012') ; if (s2!=NULL) *s2 = 0; if (strstr(s,boundary)!=NULL) { if (!pre_disable) if (istext) if (!ishtml) printf("
  • \n"); gothead = FALSE; istext = FALSE; got++; isimage = FALSE; isbase64 = FALSE; } if (!gothead) if (strlen(s)==0) { if (istext) { if (!pre_disable) if (!ishtml) printf("
    \n");
    				else printf("
    "); } gothead = TRUE; if (isimage) printf("
    ",path_script,attach_name,towww(group),item,got); else if (isbase64) { printf("

    %s

    ",path_script,attach_name,towww(group),item,got,attach_name); } goto next_line; } if (!gothead) { /* printf("%s
    \n",s);*/ strlwr(s); if (strstr(s,"text/")!=NULL) istext = TRUE; if (strstr(s,"image/")!=NULL) isimage = TRUE; if (strstr(s,"text/html")!=NULL) ishtml = TRUE; if (strstr(s,"base64")!=NULL) isbase64 = TRUE; if (strstr(s,"quoted-printable")!=NULL) isquoted = TRUE; get_attach_name(s); } else { if (ishtml) { if (isquoted) printf("%s",decode_quote(s)); else if (isbase64) printf("%s",decode_base64s(s)); else printf("%s",s); } else if (istext) { printf("%s\n",text_encode(s)); } } next_line: s = get_line(instr); } goto endbit; } if (!pre_disable) if (!israw) printf("

    \n");
    	s = get_line(instr);
    	isimage = FALSE;
    	for (;s!=NULL;) {
    		if (strncmp(s,"begin ",6)==0) {
    			ncpy(bf,s,BFSZ-1);
    			isref = FALSE;
    			x = strtok(bf," \012\015"); if (x==NULL) goto skip;
    			x = strtok(NULL," \012\015"); if (x==NULL) goto skip;
    			if (atoi(x)<100) goto skip;
    			x = strtok(NULL," \012\015"); if (x==NULL) goto skip;
    			strlwr(x);
    			if (strchr(x,'.')==NULL) {
    				x = strtok(NULL," \012\015"); if (x==NULL) goto skip;
    			}
    			if (strstr(x,".jpg")!=NULL) {strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".jpeg")!=NULL) {strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".gif")!=NULL) {strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".avi")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".mpg")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".mpeg")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".zip")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".exe")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".doc")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".xls")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".com")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".txt")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".ini")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".log")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".html")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".htm")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			if (strstr(x,".pdb")!=NULL) {isref = TRUE; strcpy(attach_name,x); goto isok;}
    			z = strstr(x,".");
    			if (z!=NULL) if (strlen(z+1)==3) {isref = TRUE; strcpy(attach_name,x); goto isok;}	
    			goto skip;
    
    isok:			isimage = TRUE;
    			if (!isref) 
    				printf("
    ",path_script,attach_name,towww(group),item); else printf("%s

    ",path_script,attach_name,towww(group),item,attach_name); } skip: if (!israw) { if (!isimage) if (!isref) printf("%s",text_encode(s)); } else { printf("%s",clari_encode(s)); } if (isimage) { if (strncmp(s,"end",3)==0) isimage = FALSE; } s = get_line(instr); } if (!pre_disable) if (!israw) printf("

    \n"); endbit:; } void clari_insert(char *s, char *in); void clari_insert(char *s, char *in) { memmove(s+strlen(in),s,strlen(s)+1); strncpy(s,in,strlen(in)); } char *clari_encode(char *ss) { char *s2; char *s=ss; again: s = strstr(ss,"17) {clari_insert(s+10,"news:"); goto again;} } s = strstr(ss,"17) {clari_insert(s+9,"news:"); goto again;} } return ss; } /* =0)) return sys_errlist[x]; return "No error"; } #endif void fimsg(char * arg_list, ...) { }