fnct0.c
上传用户:shbosideng
上传日期:2013-05-04
资源大小:1555k
文件大小:5k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /*
  2. Iulian Radu [v2.0@07.1999]
  3. */
  4. void fcomment(char* buf){
  5. comment=1;
  6. }
  7. void finclude(char* buf){
  8. parsex(buf);
  9. }
  10. void fmrtgcfg(char* buf){
  11. char dst[257],src[257],tmp[257];
  12. if(fm) fclose(fm);
  13. sscanf(buf,"%s %s",dst,src);
  14. if(strcmp(dst,src)){
  15.     sprintf(tmp,"cp %s %s",src,dst);
  16.     system(tmp);}
  17. fm=fopen(dst,"a+t");
  18. if(!fm) return;
  19. fprintf(fm,"#----------------------------------------------------------------------n");
  20. }
  21. void fhtmlfile(char* buf){
  22. closehtml();
  23. fh=fopen(buf,"wt");
  24. mkhtmlh();
  25. }
  26. void fxdebug(char* buf){
  27. if(!strcasecmp(buf,"on")) xdebug=1;
  28. if(!strcasecmp(buf,"off")) xdebug=0;
  29. }
  30. void fcfgdir(char* buf){
  31. strcpy(cfgdir,buf);
  32. }
  33. void fnocfgdir(char* buf){
  34. cfgdir[0]=0;
  35. }
  36. void fhtmlcode0(char* buf){
  37. int i;
  38. if(!fh) return;
  39. for(;identl;identl--){
  40.     for(i=1;i<identl;i++) fprintf(fh,"t");
  41.     fprintf(fh,"</UL>n");}
  42. fprintf(fh,"%sn",buf);
  43. }
  44. void fmrtgtext(char* buf){
  45. if(!fm) return;
  46. fprintf(fm,"#%sn",buf);
  47. }
  48. void fbody(char* buf){
  49. strcpy(body,buf);
  50. }
  51. void fnobody(char* buf){
  52. body[0]=0;
  53. }
  54. void fbase(char* buf){
  55. strcpy(base,buf);
  56. }
  57. void fnobase(char* buf){
  58. base[0]=0;
  59. }
  60. void fexec(char* buf){
  61. system(buf);
  62. }
  63. void fmsg(char* buf){
  64. printf("%sn",buf);
  65. }
  66. void ftitle(char* buf){
  67. strcpy(title,buf);
  68. }
  69. void fmklink(char* buf){
  70. char dir[257],host[65],path[257],*hosti,tmp1[257],tmp2[257],crtdir[257];
  71. sscanf(buf,"%s %s %s",dir,host,path);
  72. hosti=findhost(host);
  73. if(!hosti){
  74.     fprintf(stderr,err[9],host);
  75.     return;}
  76. mkdir(dir,S_IREAD | S_IWRITE | S_IEXEC);
  77. getcwd(crtdir,256);
  78. if(chdir(dir)){
  79.     fprintf(stderr,err[10],dir);
  80.     return;}
  81. /* index.html */
  82. sprintf(tmp1,"%s/%s.html",path,hosti);
  83. unlink("index.html");
  84. symlink(tmp1,"index.html");
  85. /* gifs */
  86. sprintf(tmp1,"%s/%s-day.gif",path,hosti);
  87. sprintf(tmp2,"%s-day.gif",hosti);
  88. unlink(tmp2);
  89. symlink(tmp1,tmp2);
  90. sprintf(tmp1,"%s/%s-week.gif",path,hosti);
  91. sprintf(tmp2,"%s-week.gif",hosti);
  92. unlink(tmp2);
  93. symlink(tmp1,tmp2);
  94. sprintf(tmp1,"%s/%s-month.gif",path,hosti);
  95. sprintf(tmp2,"%s-month.gif",hosti);
  96. unlink(tmp2);
  97. symlink(tmp1,tmp2);
  98. sprintf(tmp1,"%s/%s-year.gif",path,hosti);
  99. sprintf(tmp2,"%s-year.gif",hosti);
  100. unlink(tmp2);
  101. symlink(tmp1,tmp2);
  102. /* mrtg imgs */
  103. sprintf(tmp1,"%s/mrtg-l.gif",path);
  104. unlink("mrtg-l.gif");
  105. symlink(tmp1,"mrtg-l.gif");
  106. sprintf(tmp1,"%s/mrtg-m.gif",path);
  107. unlink("mrtg-m.gif");
  108. symlink(tmp1,"mrtg-m.gif");
  109. sprintf(tmp1,"%s/mrtg-r.gif",path);
  110. unlink("mrtg-r.gif");
  111. symlink(tmp1,"mrtg-r.gif");
  112. sprintf(tmp1,"%s/mrtg-tl.gif",path);
  113. unlink("mrtg-tl.gif");
  114. symlink(tmp1,"mrtg-tl.gif");
  115. chdir(crtdir);
  116. }
  117. void wrohtml(FILE* f,char* str,char* fcfg){
  118. fprintf(f,"<HTML>n");
  119. fprintf(f,"<HEADER>n");
  120. fprintf(f,"<TITLE>n");
  121. if(title[0]) fprintf(f,"%s - %s",title,str);
  122. else fprintf(f,"%s - %s",btxt[0],str);
  123. fprintf(f,"</TITLE>n");
  124. fprintf(f,"</HEADER>n");
  125. if(body[0]) fprintf(f,"<BODY %s>n",body);
  126. else fprintf(f,"<BODY>n");
  127. fprintf(f,"<H1>%s %s %s</H1><P>n",str,btxt[2],fcfg);
  128. }
  129. void wrchtml(FILE* f){
  130. fprintf(f,"</BODY>n");
  131. fprintf(f,"</HTML>n");
  132. }
  133. void fmkd(char* buf){
  134. char fcfg[257],fhtml[257];
  135. FILE* f;
  136. int i;
  137. sscanf(buf,"%s %s",fcfg,fhtml);
  138. for(i=0;i<nmkr[0];i++)
  139.     if(!strcmp(mkrn[i][4],fhtml)){
  140. f=mkri[i][0];
  141. break;}
  142. if(i==nmkr[0]){
  143.     f=fopen(fhtml,"wt");
  144.     if(!f) return;
  145.     wrohtml(f,"day",fcfg);}
  146. i=nmkr[0]++;
  147. mkri[i][0]=f;
  148. strcpy(mkrn[i][0],fcfg);
  149. strcpy(mkrn[i][4],fhtml);
  150. }
  151. void fmkw(char* buf){
  152. char fcfg[257],fhtml[257];
  153. FILE* f;
  154. int i;
  155. sscanf(buf,"%s %s",fcfg,fhtml);
  156. for(i=0;i<nmkr[1];i++)
  157.     if(!strcmp(mkrn[i][5],fhtml)){
  158. f=mkri[i][1];
  159. break;}
  160. if(i==nmkr[0]){
  161.     f=fopen(fhtml,"wt");
  162.     if(!f) return;
  163.     wrohtml(f,"week",fcfg);}
  164. i=nmkr[1]++;
  165. mkri[i][1]=f;
  166. strcpy(mkrn[i][1],fcfg);
  167. strcpy(mkrn[i][5],fhtml);
  168. }
  169. void fmkm(char* buf){
  170. char fcfg[257],fhtml[257];
  171. FILE* f;
  172. int i;
  173. sscanf(buf,"%s %s",fcfg,fhtml);
  174. for(i=0;i<nmkr[2];i++)
  175.     if(!strcmp(mkrn[i][6],fhtml)){
  176. f=mkri[i][2];
  177. break;}
  178. if(i==nmkr[2]){
  179.     f=fopen(fhtml,"wt");
  180.     if(!f) return;
  181.     wrohtml(f,"month",fcfg);}
  182. strcpy(mkrn[nmkr[2]++][2],fcfg);
  183. i=nmkr[2]++;
  184. mkri[i][2]=f;
  185. strcpy(mkrn[i][2],fcfg);
  186. strcpy(mkrn[i][6],fhtml);
  187. }
  188. void fmky(char* buf){
  189. char fcfg[257],fhtml[257];
  190. FILE* f;
  191. int i;
  192. sscanf(buf,"%s %s",fcfg,fhtml);
  193. for(i=0;i<nmkr[3];i++)
  194.     if(!strcmp(mkrn[i][7],fhtml)){
  195. f=mkri[i][3];
  196. break;}
  197. if(i==nmkr[3]){
  198.     f=fopen(fhtml,"wt");
  199.     if(!f) return;
  200.     wrohtml(f,"year",fcfg);}
  201. i=nmkr[3]++;
  202. mkri[i][3]=f;
  203. strcpy(mkrn[i][3],fcfg);
  204. strcpy(mkrn[i][7],fhtml);
  205. }
  206. void fhtmllink0(char* buf){
  207. char link[129];
  208. int i;
  209. if(!fh) return;
  210. for(;identl;identl--){
  211.     for(i=1;i<identl;i++) fprintf(fh,"t");
  212.     fprintf(fh,"</UL>n");}
  213. sscanf(buf,"%s",link);
  214. if(base[0]) fprintf(fh,"<A HREF="http://%s/%s">",base,link);
  215. else fprintf(fh,"<A HREF="%s">",link);
  216. fprintf(fh,"%s",findnsp(buf,1));
  217. fprintf(fh,"</A>n");
  218. }
  219. void flink2dh0(char* buf){
  220. char host[129],*hosti;
  221. int i;
  222. if(!fh) return;
  223. for(;identl;identl--){
  224.     for(i=1;i<identl;i++) fprintf(fh,"t");
  225.     fprintf(fh,"</UL>n");}
  226. sscanf(buf,"%s",host);
  227. hosti=findhost(host);
  228. if(!hosti){
  229.     fprintf(stderr,err[9],host);
  230.     return;}
  231. if(base[0]) fprintf(fh,"<A HREF="http://%s/%s.html">",base,hosti);
  232. else fprintf(fh,"<A HREF="%s.html">",hosti);
  233. fprintf(fh,"%s",findnsp(buf,1));
  234. fprintf(fh,"</A>n");
  235. }
  236. void fchngtrgname(char* buf){
  237. if(!strcasecmp(buf,"yes")){
  238.     chngname=1;
  239.     return;}
  240. if(!strcasecmp(buf,"no")){
  241.     chngname=0;
  242.     return;}
  243. fprintf(stderr,err[12],buf);    
  244. }
  245. void fconvip2name(char* buf){
  246. conv=1;
  247. sscanf(buf,"%s",mrtgoutpath);
  248. }
  249. void fconvname2ip(char* buf){
  250. conv=2;
  251. sscanf(buf,"%s",mrtgoutpath);
  252. }