#define SET_LIST(list) list,sizeof(list)/sizeof(list[0])
+//! The configuration file from which the graph option was loaded
+char GraphConfigFile[MAXLEN]="";
+
+//! How many include directives were followed.
+static int IncludeLevel=0;
+
extern numlist hours, weekdays;
extern FileListObject AccessLog;
extern int PerUserLimitsNumber;
return;
}
-static void parmtest(char *buf)
+static void parmtest(char *buf,const char *File)
{
char wbuf[2048];
struct getwordstruct gwarea;
if (getparam_bool("user_authentication",buf,&UserAuthentication)>0) return;
if (getparam_string("AuthUserTemplateFile",buf,wbuf,sizeof(wbuf))>0) {
- char dir[MAXLEN];
-
if (is_absolute(wbuf)) {
if (strlen(wbuf)>=sizeof(AuthUserTemplateFile)) {
debuga(__FILE__,__LINE__,_("Template file name is too long in parameter \"AuthUserTemplateFile\"\n"));
}
safe_strcpy(AuthUserTemplateFile,wbuf,sizeof(AuthUserTemplateFile));
} else {
- safe_strcpy(dir,ConfigFile,sizeof(dir));
+ char dir[MAXLEN];
+
+ safe_strcpy(dir,File,sizeof(dir));
if (snprintf(AuthUserTemplateFile,sizeof(AuthUserTemplateFile),"%s/%s",dirname(dir),wbuf)>=sizeof(AuthUserTemplateFile)) {
debuga(__FILE__,__LINE__,_("Template file name is too long in parameter \"AuthUserTemplateFile\"\n"));
exit(EXIT_FAILURE);
#ifndef HAVE_GD
if (Graphs)
debugaz(__FILE__,__LINE__,_("No graphs available as sarg was not compiled with libgd. Set \"graphs\" to \"no\" in %s to disable this warning\n"),
- ConfigFile);
+ File);
#endif
+ safe_strcpy(GraphConfigFile,File,sizeof(GraphConfigFile));
return;
}
printf(_("SARG: Unknown option %s\n"),buf);
}
-void getconf(void)
+void getconf(const char *File)
{
FILE *fp_in;
char buf[MAXLEN];
+ char IncludeFile[MAXLEN];
+
+ IncludeLevel++;
+ if (debug) {
+ if (IncludeLevel<=1)
+ debuga(__FILE__,__LINE__,_("Loading configuration file \"%s\"\n"),File);
+ else
+ debuga(__FILE__,__LINE__,_("Including configuration file \"%s\"\n"),File);
+ }
- if(debug)
- debuga(__FILE__,__LINE__,_("Loading configuration from \"%s\"\n"),ConfigFile);
+ // stop if include files are producing a loop
+ if (IncludeLevel>5) {
+ debuga(__FILE__,__LINE__,_("Too many nested configuration files included in \"%s\""),ConfigFile);
+ exit(EXIT_FAILURE);
+ }
- if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
- debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),ConfigFile,strerror(errno));
+ if ((fp_in = fopen(File, "r")) == NULL) {
+ debuga(__FILE__,__LINE__,_("Cannot open file \"%s\": %s\n"),File,strerror(errno));
exit(EXIT_FAILURE);
}
while (fgets(buf, sizeof(buf), fp_in) != NULL) {
fixendofline(buf);
+ if (getparam_string("include",buf,IncludeFile,sizeof(IncludeFile))>0) {
+ getconf(IncludeFile);
+ continue;
+ }
+
if (debugz>=LogLevel_Data)
printf("SYSCONFDIR %s\n",buf);
- parmtest(buf);
-
+ parmtest(buf,File);
}
if (fclose(fp_in)==EOF) {
- debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),ConfigFile,strerror(errno));
+ debuga(__FILE__,__LINE__,_("Read error in \"%s\": %s\n"),File,strerror(errno));
exit(EXIT_FAILURE);
}
- return;
+ IncludeLevel--;
}
iconv_t localtoutf=(iconv_t)-1;
#endif
+extern char GraphConfigFile[MAXLEN];
+
static void Sarg_gdImageStringFT (struct GraphDataStruct *gdata, int fg, char *fontlist,
double ptsize, double angle, int x, int y, const char *string,enum TextRefPos RefPos)
{
#ifdef HAVE_GD
if (!Graphs) {
if (debugz>=LogLevel_Process)
- debugaz(__FILE__,__LINE__,_("Graphs disabled as requested in %s\n"),ConfigFile);
+ debugaz(__FILE__,__LINE__,_("Graphs disabled as requested in %s\n"),GraphConfigFile);
return;
}
if (GraphFont[0]=='\0') {
- if (debugz>=LogLevel_Process)
- debugaz(__FILE__,__LINE__,_("Graphs disabled as no font names were provided in %s\n"),ConfigFile);
+ if (debugz>=LogLevel_Process) {
+ const char *File=(GraphConfigFile[0]) ? GraphConfigFile : ConfigFile;
+ debugaz(__FILE__,__LINE__,_("Graphs disabled as no font names were provided in %s\n"),File);
+ }
return;
}
# Note that the max_successive_log_errors is still taken into account and
# cannot be disabled.
#max_total_log_errors 50
+
+# TAG: include conffile
+# Include the specified conffile. The full path must be provided to
+# make sure the correct file is loaded.
+#
+# Use this option to store common options in one file and include it
+# in multiple sarg.conf dedicated to various reporting tasks.
+#
+# Options declared last take precedence. Use it to include a file and
+# then override some options after the include statement. Beware that
+# some options are cumulative such as access_log, useragent_log or
+# redirector_log. You can't override those options as explained here.
+# Declaring them in the common file and the including file will merely
+# add the latter to the list.
+#include /etc/sarg/sarg-common.conf