home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 35 Internet
/
35-Internet.zip
/
sarg1221.zip
/
index.c
< prev
next >
Wrap
Text File
|
2002-10-11
|
5KB
|
137 lines
/*
* sarg - Squid user management log
* Mar/98 - Pedro L Orso - orso@onda.com.br
*/
#include "include/conf.h"
#if !defined(__OS2__)
#define SORTINDEX
#endif
#ifdef SORTINDEX
#include <dirent.h>
#include <sys/stat.h>
static char dir[PATH_MAX];
int timesort(const struct dirent **d1, const struct dirent **d2)
{
struct stat f1, f2 ;
char fp1[PATH_MAX], fp2[PATH_MAX];
strcpy(fp1, dir) ; strcat( fp1, "/" ) ; strcat( fp1, (*d1)->d_name ) ;
strcpy(fp2, dir) ; strcat( fp2, "/" ) ; strcat( fp2, (*d2)->d_name ) ;
stat( fp1, &f1 ) ;
stat( fp2, &f2 ) ;
// printf( "%s %d %s %d\n",
// (*d1)->d_name,f1.st_mtime,
// (*d2)->d_name,f2.st_mtime ) ;
if ( f1.st_mtime == f2.st_mtime ) return 0 ;
if ( f1.st_mtime < f2.st_mtime ) return -1 ;
return 1 ;
}
#endif // SORTINDEX
void geraindex(char *dirname, int debug, char *BgColor, char *TxColor, char *TxBgColor, char *TiColor, char *LogoImage, char *LogoText, char *LogoTextColor, char *Width, char *Height, char *Title, char *BgImage, char *FontFace, char *HeaderColor, char *HeaderBgColor, char *FontSize, char *TempDir, char *DateFormat, const char *periodo)
{
FILE *fp_ou;
DIR *dirp;
#ifdef SORTINDEX
struct dirent **namelist;
int ne,i ;
#endif
struct dirent *direntp;
char html[MAXLEN];
char wdir[MAXLEN];
char data[80];
char tuser[20];
char tbytes[20];
char media[20];
char ftime[128];
if(LastLog[0] != '\0')
mklastlog(dirname,debug);
sprintf(wdir,"%sindex.html",dirname);
if(strcmp(Index,"no") == 0) {
if(access(wdir, R_OK) == 0)
unlink(wdir);
return;
}
if(debug)
debuga(text[53]);
if((fp_ou=fopen(wdir,"w"))==NULL) {
fprintf(stderr, "SARG: (index) %s: %s\n",text[45],wdir);
exit(1);
}
fputs("<html>\n",fp_ou);
fputs("<head>\n",fp_ou);
sprintf(html," <meta http-equiv=\"Content-Type\" content=\"text/html; charset=%s\">\n",CharSet);
fputs(html,fp_ou);
fputs("</head>\n",fp_ou);
// DAS: Using style=font-family more corresponds to standards.
sprintf(html,"<body bgcolor=%s text=%s background='%s' style='font-family:%s;'>\n",BgColor,TxColor,BgImage,FontFace);
fputs(html,fp_ou);
fputs("<center><table cellpadding=0 cellspacing=0>\n",fp_ou);
if(strlen(LogoImage) > 0) {
sprintf(html,"<tr><th align=left><img src='%s' border=0 align=absmiddle width=%s height=%s><font color=%s>%s</font>\n",LogoImage,Width,Height,LogoTextColor,LogoText);
fputs(html,fp_ou);
}
sprintf(html,"<tr><th align=center><b><font color=%s size=+1>%s</font></b></th></tr>\n",TiColor,Title);
fputs(html,fp_ou);
fputs("</table></center>\n",fp_ou);
fputs("<center><table cellpadding=1 cellspacing=1>\n",fp_ou);
fputs("<tr><td></td><td></td></tr>",fp_ou);
sprintf(html,"<tr><th bgcolor=%s><font size=%s color=%s>%s</font></th><th bgcolor=%s><font size=%s color=%s>%s</font></th><th bgcolor=%s><font size=%s color=%s>%s</font></th><th bgcolor=%s><font size=%s color=%s>%s</font></th><th bgcolor=%s><font size=%s color=%s>%s</font></th></tr>\n",HeaderBgColor,FontSize,HeaderColor,text[101],HeaderBgColor,FontSize,HeaderColor,text[102],HeaderBgColor,FontSize,HeaderColor,text[103],HeaderBgColor,FontSize,HeaderColor,text[93],HeaderBgColor,FontSize,HeaderColor,text[96]);
fputs(html,fp_ou);
#ifdef SORTINDEX
strcpy(dir, dirname);
ne = scandir(dirname, &namelist, 0, (int)timesort);
i = 0 ;
while(i<ne) {
direntp = namelist[i++] ;
#else
dirp = opendir(dirname);
while ( (direntp = readdir( dirp )) != NULL ){
#endif
if(strstr(direntp->d_name,"-") == 0)
continue;
obtdate(dirname,direntp->d_name,data);
obtuser(dirname,direntp->d_name,tuser);
obttotal(dirname,direntp->d_name,tbytes,tuser,media);
sprintf(html,"<tr><td bgcolor=%s><font size=%s><a href='%s/%s'>%s</a></font></a></td><td bgcolor=%s><font size=%s>%s</font></td><td align=right bgcolor=%s><font size=%s>%s</font></td><td align=right bgcolor=%s><font size=%s>%s</font></td><td align=right bgcolor=%s><font size=%s>%s</font></td></tr>\n",TxBgColor,FontSize,direntp->d_name,ReplaceIndex,direntp->d_name,TxBgColor,FontSize,data,TxBgColor,FontSize,tuser,TxBgColor,FontSize,tbytes,TxBgColor,FontSize,media);
fputs(html,fp_ou);
}
#ifndef SORTINDEX
(void)closedir( dirp );
#endif
strcpy(html,"</table></center>");
fputs(html,fp_ou);
zdate(ftime, DateFormat);
sprintf(html,"<br><br><center><font size=-2>%s <a href='%s'>%s-%s</a> %s %s</font></center>\n",text[108],URL,PGM,VERSION,text[109],ftime);
fputs(html,fp_ou);
strcpy(html,"</html>\n");
fputs(html,fp_ou);
return;
}