2 * Name: HTML creation functions
4 * Purpose: Create a nice HTML page with all the statistics
6 * Author: Pedro de Oliveira <falso@rdk.homeip.net>
8 * Copyright (c) 2004-2008 Pedro de Oliveira ( falso@rdk.homeip-net )
10 * This file is part of aMule.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the
24 * Free Software Foundation, Inc.,
25 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
33 #include <sys/types.h>
38 #include "functions.h"
41 int create_html(char *stats
[20], char *lines
[6], char template[120], char *path_for_html
)
45 char version
[25], upload
[25], download
[25];
46 char *search
[] = {"#VERSION#", "#CLIENT#", "#NICK#", "#UPLOADRATE#" ,
47 "#DOWNLOADRATE#" , "#QUEUE#" , "#NUMSHARE#" , "#SESSIONUP#" ,
48 "#SESSIONDOWN#" , "#TOTALUP#", "#TOTALDOWN#" , "#SERVER#" , "#IP#",
51 snprintf(version
, 25, "cas %s", CAS_VERSION
);
52 snprintf(upload
, 25, "%s kB/s", stats
[7]);
53 snprintf(download
, 25, "%s kB/s", stats
[6]);
55 char *repl
[] = { version
, lines
[0] , stats
[10] , upload
, download
,
56 stats
[8] , stats
[9] , stats
[15] , stats
[14] , stats
[12] , stats
[11] ,
57 stats
[1] , stats
[2] , stats
[3] };
59 /* get some memory to read the template into */
61 if ((fdTmpl
= open(template, O_RDONLY
)) < 0)
63 printf("\n\n%s\n",template);
64 perror("Could not open file");
69 if (fstat(fdTmpl
, &sb
) < 0)
71 perror("Could not stat file");
76 /* 2 times the size of the template should be enough */
77 /* st_size is defined as off_t, but size_t seems more reasonable */
78 size_t size
= sb
.st_size
*2;
79 char *mem
= calloc(size
, 1);
82 perror("Could not calloc\n");
86 /* read the template into the memory */
89 FILE *fTmpl
= fopen(template,"r");
90 while ((ler
=fgetc(fTmpl
)) != EOF
&& len
+1 < size
)
96 /* printf ("HTML: %s\n", mem); */
101 /* replace the special tags */
102 replace(mem
, search
[t
], repl
[t
]);
105 /* printf("FINAL: %s\n",mem); */
107 path
= get_amule_path("aMule-online-sign.html", 0, path_for_html
);
111 perror("could not get the HTML path\n");
117 if ((fHTML
= fopen(path
, "w")) == NULL
)
119 perror("Unable to create file\n");
126 fprintf(fHTML
, "%s", mem
);
130 printf("HTML file created.\n");