char *file_begin,*file_end;
int limit;
int digit;
- int userid;
+ char *str;
+ int i;
+ enum PerUserOutputEnum output;
+ const struct
+ {
+ const char *name;
+ enum PerUserOutputEnum value;
+ } output_types[]=
+ {
+ {"id",PUOE_UserId},
+ {"ip",PUOE_UserIp},
+ };
plen=strlen(param);
if (strncmp(buf,param,plen) != 0) return(0);
}
} while (*buf && *buf!=' ');
- userid=0;
+ output=PUOE_UserId;
if (*buf==' ') {
while (*buf && (unsigned char)*buf<=' ') buf++;
- if (!isdigit(*buf)) {
- debuga(_("Invalid user ID/IP output type flag in per_user_limit\n"));
+ str=buf;
+ while (*buf && (unsigned char)*buf>' ') buf++;
+ *buf='\0';
+ for (i=sizeof(output_types)/sizeof(output_types[0])-1 ; i>=0 ; i--)
+ if (strcasecmp(output_types[i].name,str)==0) {
+ output=output_types[i].value;
+ break;
+ }
+ if (i<0) {
+ debuga(_("Invalid output type in per_user_limit\n"));
exit(EXIT_FAILURE);
}
- userid=*buf-'0';
}
if (PerUserLimitsNumber>=MAX_USER_LIMITS) {
*file_end='\0';
safe_strcpy(PerUserLimits[PerUserLimitsNumber].File,file_begin,sizeof(PerUserLimits[PerUserLimitsNumber].File));
PerUserLimits[PerUserLimitsNumber].Limit=limit;
- PerUserLimits[PerUserLimitsNumber].UserId=userid;
+ PerUserLimits[PerUserLimitsNumber].Output=output;
PerUserLimitsNumber++;
return(1);
debuga(_("(html10) Cannot open per user limit file %s: %s\n"),PerUserLimits[i].File,strerror(errno));
exit(EXIT_FAILURE);
}
- if (PerUserLimits[i].UserId)
- fprintf(fp_usr,"%s\n",uinfo->label);
- else
- fprintf(fp_usr,"%s\n",uinfo->ip);
+ switch (PerUserLimits[i].Output)
+ {
+ case PUOE_UserId:
+ fprintf(fp_usr,"%s\n",uinfo->label);
+ break;
+ case PUOE_UserIp:
+ fprintf(fp_usr,"%s\n",uinfo->ip);
+ break;
+ }
if (fclose(fp_usr)==EOF) {
debuga(_("Write error in per user limit file %s: %s\n"),PerUserLimits[i].File,strerror(errno));
exit(EXIT_FAILURE);
PUFC_AsRequired
};
+/*!
+\brief What to write into the per_user_limit file.
+*/
+enum PerUserOutputEnum
+{
+ PUOE_UserId,
+ PUOE_UserIp
+};
+
/*!
\brief How to log every user crossing the download limit.
*/
char File[255];
//! Limit above which the user is reported.
int Limit;
- //! \c True to report the user's ID or \c false to report the user's IP.
- bool UserId;
+ //! What to write into the file.
+ enum PerUserOutputEnum Output;
};
// auth.c
#
#date_format u
-# TAG: per_user_limit file MB flag
-# Saves userid (if flag is 1) or userip (if flag is 0) in file if download exceed n MB.
-# This option allow you to disable user access if user exceed a download limit.
+# TAG: per_user_limit file MB ip/id
+# Write the user's ID (if last flag is 'id') or the user's IP address (if last flag is 'ip')
+# in file if download exceed n MB.
+# This option allows you to disable user access if users exceed a download limit.
# The option may be repeated up to 16 times to generate several files with
# different content type or limit.
#
+# Examples:
+# per_user_limit userlimit_1G.txt 1000 ip
+# per_user_limit /var/log/sarg/userlimit_500M.log 500 id
+#
#per_user_limit none
# TAG: per_user_limit_file_create always/as_required