]>
git.ipfire.org Git - thirdparty/sarg.git/blob - lastlog.c
2 * AUTHOR: Pedro Lineu Orso pedro.orso@gmail.com
4 * SARG Squid Analysis Report Generator http://sarg.sourceforge.net
7 * please look at http://sarg.sourceforge.net/donations.php
8 * ---------------------------------------------------------------------
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
26 #include "include/conf.h"
28 void mklastlog(const char *outdir
)
33 struct dirent
*direntp
;
43 if(strcmp(LastLog
,"0") == 0)
46 sprintf(temp
,"%slastlog1",outdir
);
47 if((fp_ou
=fopen(temp
,"w"))==NULL
) {
48 fprintf(stderr
, "SARG: (lastlog) %s: %s\n",text
[9],temp
);
52 dirp
= opendir(outdir
);
53 while ((direntp
= readdir( dirp
)) != NULL
){
54 if(strstr(direntp
->d_name
,"-") == 0)
57 sprintf(warea
,"%s%s",outdir
,direntp
->d_name
);
60 local
= localtime(&t
);
61 strftime(ftime
, 127, "%Y%m%d%H%M%S", local
);
62 fprintf(fp_ou
,"%s %s\n",ftime
,direntp
->d_name
);
66 (void)rewinddir( dirp
);
67 (void)closedir( dirp
);
70 sprintf(buf
,"sort -n -k 1,1 -o '%slastlog' '%s'",outdir
,temp
);
72 if (!WIFEXITED(cstatus
) || WEXITSTATUS(cstatus
)) {
73 fprintf(stderr
, "SARG: sort command return status %d\n",WEXITSTATUS(cstatus
));
74 fprintf(stderr
, "SARG: sort command: %s\n",buf
);
80 if(ftot
<=atoi(LastLog
)) {
81 sprintf(temp
,"%slastlog",outdir
);
82 if(access(temp
, R_OK
) == 0)
89 sprintf(temp
,"%slastlog",outdir
);
90 if((fp_in
=fopen(temp
,"r"))==NULL
) {
91 fprintf(stderr
, "SARG: (lastlog) %s: %s\n",text
[9],temp
);
95 while(fgets(buf
,sizeof(buf
),fp_in
)!=NULL
) {
96 if (getword(warea
,sizeof(warea
),buf
,' ')<0) {
97 printf("SARG: Maybe you have a broken record or garbage in your %s file.\n",temp
);
100 buf
[strlen(buf
)-1]='\0';
104 sprintf(msg
,"%s: %s",text
[81],buf
);
107 // sprintf(temp,"%s%s",outdir,buf);
108 sprintf(temp
,"rm -r %s%s",outdir
,buf
);
116 sprintf(temp
,"%slastlog",outdir
);