[go: up one dir, main page]

Menu

[b48fe1]: / auth.c  Maximize  Restore  History

Download this file

79 lines (70 with data), 2.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* SARG Squid Analysis Report Generator http://sarg.sourceforge.net
* 1998, 2015
*
* SARG donations:
* please look at http://sarg.sourceforge.net/donations.php
* Support:
* http://sourceforge.net/projects/sarg/forums/forum/363374
* ---------------------------------------------------------------------
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
*
*/
#include "include/conf.h"
#include "include/defs.h"
char AuthUserTemplateFile[1024] = "sarg_htaccess";
bool UserAuthentication = false;
void htaccess(const struct userinfostruct *uinfo)
{
char htname[MAXLEN];
char line[MAXLEN];
FILE *fp_in;
FILE *fp_auth;
size_t i,nread;
if (!UserAuthentication)
return;
if (snprintf(htname,sizeof(htname),"%s/%s/.htaccess",outdirname,uinfo->filename)>=sizeof(htname)) {
debuga(__FILE__,__LINE__,_("Path too long: "));
debuga_more("%s/%s/.htaccess\n",outdirname,uinfo->filename);
exit(EXIT_FAILURE);
}
if ((fp_auth=fopen(htname,"w"))==NULL) {
debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),htname,strerror(errno));
exit(EXIT_FAILURE);
}
if ((fp_in=fopen(AuthUserTemplateFile,"r"))==NULL) {
debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),AuthUserTemplateFile,strerror(errno));
exit(EXIT_FAILURE);
}
while ((nread=fread(line,1,sizeof(line),fp_in))!=0) {
for (i=0 ; i<nread ; i++)
if (line[i]=='%' && i+2<nread && line[i+1]=='u' && !isalpha(line[i+2])) {
fputs(uinfo->id,fp_auth);
i++;
} else {
fputc(line[i],fp_auth);
}
}
if (fclose(fp_auth)==EOF) {
debuga(__FILE__,__LINE__,_("Write error in \"%s\": %s\n"),htname,strerror(errno));
exit(EXIT_FAILURE);
}
if (fclose(fp_in)==EOF) {
debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),AuthUserTemplateFile,strerror(errno));
exit(EXIT_FAILURE);
}
return;
}