]>
git.ipfire.org Git - thirdparty/sarg.git/blob - lastlog.c
2 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
6 * please look at http://sarg.sourceforge.net/donations.php
8 * http://sourceforge.net/projects/sarg/forums/forum/363374
9 * ---------------------------------------------------------------------
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
27 #include "include/conf.h"
28 #include "include/defs.h"
30 void mklastlog(const char *outdir
)
34 struct dirent
*direntp
;
44 struct getwordstruct gwarea
;
49 snprintf(temp
,sizeof(temp
),"%slastlog1",outdir
);
50 if((fp_ou
=fopen(temp
,"w"))==NULL
) {
51 debuga(_("(lastlog) Cannot open temporary file %s\n"),temp
);
55 if ((dirp
= opendir(outdir
)) == NULL
) {
56 debuga(_("Failed to open directory %s - %s\n"),outdir
,strerror(errno
));
59 while ((direntp
= readdir( dirp
)) != NULL
){
60 if(strchr(direntp
->d_name
,'-') == 0)
63 snprintf(warea
,sizeof(warea
),"%s%s",outdir
,direntp
->d_name
);
64 if (stat(warea
,&statb
) == -1) {
65 debuga(_("Failed to get the creation time of %s\n"),warea
);
69 local
= localtime(&t
);
70 strftime(ftime
, sizeof(ftime
), "%Y%m%d%H%M%S", local
);
71 fprintf(fp_ou
,"%s\t%s\n",ftime
,direntp
->d_name
);
78 snprintf(buf
,sizeof(buf
),"sort -n -t \"\t\" -k 1,1 -o \"%slastlog\" \"%s\"",outdir
,temp
);
80 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
81 debuga(_("sort command return status %d\n"),WEXITSTATUS(cstatus
));
82 debuga(_("sort command: %s\n"),buf
);
87 debuga(_("Cannot delete \"%s\": %s\n"),temp
,strerror(errno
));
92 snprintf(temp
,sizeof(temp
),"%slastlog",outdir
);
93 if(access(temp
, R_OK
) == 0) {
95 debuga(_("Cannot delete \"%s\": %s\n"),temp
,strerror(errno
));
104 snprintf(temp
,sizeof(temp
),"%slastlog",outdir
);
105 if((fp_in
=fopen(temp
,"r"))==NULL
) {
106 debuga(_("(lastlog) Cannot open temporary file %s\n"),temp
);
110 while(ftot
>0 && fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
112 getword_start(&gwarea
,buf
);
113 if (getword(warea
,sizeof(warea
),&gwarea
,'\t')<0) {
114 debuga(_("Maybe you have a broken record or garbage in your %s file\n"),temp
);
119 debuga(_("Removing old report file %s\n"),gwarea
.current
);
120 if (snprintf(temp
,sizeof(temp
),"%s%s",outdir
,gwarea
.current
)>=sizeof(temp
)) {
121 debuga(_("Directory name too long: %s%s\n"),outdir
,gwarea
.current
);
129 snprintf(temp
,sizeof(temp
),"%slastlog",outdir
);
130 if (unlink(temp
) == -1) {
131 debuga(_("Cannot delete \"%s\": %s\n"),temp
,strerror(errno
));