home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / sarg1221.zip / getconf.c < prev    next >
C/C++ Source or Header  |  2002-06-13  |  12KB  |  467 lines

  1. /*
  2.  * sarg - Squid user management log
  3.  * Mar/98 - Pedro L Orso - orso@onda.com.br
  4.  */
  5.  
  6. #include "include/conf.h"
  7.  
  8. extern numlist hours, weekdays;
  9.  
  10. void getconf(debugm, ConfigFile, AccessLog, debug, BgColor, TxColor, TxBgColor, TiColor, LogoImage, LogoText, LogoTextColor, Width, Height, Title, BgImage, FontFace, HeaderColor, HeaderBgColor, FontSize, PasswdFile, TempDir, OutputDir, OutputEmail, Ip2Name, TopuserSortField, UserSortField, TopuserSortOrder, UserSortOrder, UserAgentLog, ExcludeHosts, DateFormat, ExcludeUsers, PerUserLimitFile, PerUserLimit, UserIp, MaxElapsed)
  11.    int debug;
  12.    int  debugm;
  13.    char *ConfigFile;
  14.    char *AccessLog;
  15.    char *BgColor;
  16.    char *TxColor;
  17.    char *TxBgColor;
  18.    char *TiColor;
  19.    char *LogoImage;
  20.    char *LogoText;
  21.    char *LogoTextColor;
  22.    char *Width;
  23.    char *Height;
  24.    char *Title;
  25.    char *BgImage;
  26.    char *FontFace;
  27.    char *HeaderColor;
  28.    char *HeaderBgColor;
  29.    char *FontSize;
  30.    char *PasswdFile;
  31.    char *TempDir;
  32.    char *OutputDir;
  33.    char *OutputEmail;
  34.    char *Ip2Name;
  35.    char *TopuserSortField;
  36.    char *UserSortField;
  37.    char *TopuserSortOrder;
  38.    char *UserSortOrder;
  39.    char *UserAgentLog;
  40.    char *ExcludeHosts;
  41.    char *ExcludeUsers;
  42.    char *DateFormat;
  43.    char *PerUserLimitFile;
  44.    char *PerUserLimit;
  45.    char *UserIp;
  46.    char *MaxElapsed;
  47. {
  48.  
  49.    FILE *fp_in;
  50.    char buf[MAXLEN];
  51.    char wbuf[MAXLEN];
  52.    char Msg[255];
  53.  
  54.    if(debug) {
  55.       sprintf(Msg,"Loading configuration from: %s",ConfigFile);
  56.       debuga(Msg);
  57.    }
  58.  
  59.    if ((fp_in = fopen(ConfigFile, "r")) == NULL) {
  60.       fprintf(stderr, "SARG: (getconf) Cannot open file: %s\n",ConfigFile);
  61.       exit(1);
  62.    }
  63.  
  64.    while (fgets(buf, MAXLEN, fp_in) != NULL) {
  65.       if(strstr(buf,"\n") != 0)
  66.          buf[strlen(buf)-1]='\n';
  67.  
  68.       if(debugm)
  69.          printf("SYSCONFDIR %s",buf);
  70.  
  71.       if(strncmp(buf,"#",1) == 0)
  72.          continue;
  73.  
  74.       if(strstr(buf,"background_color") != 0) {
  75.          getword(wbuf,buf,' ');
  76.          strcpy(BgColor,buf);
  77.          fixnone(BgColor);
  78.       }
  79.  
  80.       if(strstr(buf,"text_color") != 0) {
  81.          if(strstr(buf,"logo_text_color") == 0) {
  82.             getword(wbuf,buf,' ');
  83.             strcpy(TxColor,buf);
  84.             fixnone(TxColor);
  85.          }
  86.       }
  87.  
  88.       if(strstr(buf,"text_bgcolor") != 0) {
  89.          getword(wbuf,buf,' ');
  90.          strcpy(TxBgColor,buf);
  91.          fixnone(TxBgColor);
  92.       }
  93.  
  94.       if(strstr(buf,"title_color") != 0) {
  95.          getword(wbuf,buf,' ');
  96.          strcpy(TiColor,buf);
  97.          fixnone(TiColor);
  98.       }
  99.  
  100.       if(strstr(buf,"logo_image") != 0) {
  101.          getword(wbuf,buf,' ');
  102.          strcpy(LogoImage,buf);
  103.          fixnone(LogoImage);
  104.       }
  105.  
  106.       if(strstr(buf,"logo_text") != 0) {
  107.          if(strstr(buf,"logo_text_color") == 0) {
  108.             getword(wbuf,buf,'"');
  109.             getword(LogoText,buf,'"');
  110.             fixnone(LogoText);
  111.          }
  112.       }
  113.  
  114.       if(strstr(buf,"logo_text_color") != 0) {
  115.          getword(wbuf,buf,' ');
  116.          strcpy(LogoTextColor,buf);
  117.          fixnone(LogoTextColor);
  118.       }
  119.  
  120.       if(strstr(buf,"background_image") != 0) {
  121.          getword(wbuf,buf,' ');
  122.          strcpy(BgImage,buf);
  123.          fixnone(BgImage);
  124.       }
  125.  
  126.       if(strstr(buf,"font_face") != 0) {
  127.          getword(wbuf,buf,' ');
  128.          strcpy(FontFace,buf);
  129.          fixnone(FontFace);
  130.       }
  131.  
  132.       if(strstr(buf,"header_color") != 0) {
  133.          getword(wbuf,buf,' ');
  134.          strcpy(HeaderColor,buf);
  135.          fixnone(HeaderColor);
  136.       }
  137.  
  138.       if(strstr(buf,"header_bgcolor") != 0) {
  139.          getword(wbuf,buf,' ');
  140.          strcpy(HeaderBgColor,buf);
  141.          fixnone(HeaderBgColor);
  142.       }
  143.  
  144.       if(strstr(buf,"font_size") != 0) {
  145.          getword(wbuf,buf,' ');
  146.          strcpy(FontSize,buf);
  147.          fixnone(FontSize);
  148.       }
  149.  
  150.       if(strstr(buf,"image_size") != 0) {
  151.          getword(wbuf,buf,' ');
  152.          getword(Width,buf,' ');
  153.          strcpy(Height,buf);
  154.          fixnone(Width);
  155.          fixnone(Height);
  156.       }
  157.  
  158.       if(strstr(buf,"title") != 0) {
  159.          getword(wbuf,buf,'"');
  160.          getword(Title,buf,'"');
  161.          fixnone(Title);
  162.       }
  163.  
  164.       if(strstr(buf,"resolve_ip") != 0) {
  165.          getword(wbuf,buf,' ');
  166.          strcpy(Ip2Name,buf);
  167.          fixnone(Ip2Name);
  168.       }
  169.  
  170.       if(strstr(buf,"user_ip") != 0) {
  171.          getword(wbuf,buf,' ');
  172.          strcpy(UserIp,buf);
  173.          fixnone(UserIp);
  174.       }
  175.  
  176.       if(strstr(buf,"max_elapsed") != 0) {
  177.          getword(wbuf,buf,' ');
  178.          strcpy(MaxElapsed,buf);
  179.          fixnone(MaxElapsed);
  180.       }
  181.  
  182.       if(strstr(buf,"date_format") != 0) {
  183.          getword(wbuf,buf,' ');
  184.          strcpy(DateFormat,buf);
  185.          fixnone(DateFormat);
  186.       }
  187.  
  188.       if( strstr( buf, "hours" ) != 0 )
  189.        { if( getnumlist( buf, &hours, 24, 24 ) )
  190.       { fprintf( stderr, "Error: Invalid syntax in hours tag!\n" );
  191.          exit( 1 );
  192.       }
  193.        }
  194.  
  195.       if( strstr( buf, "weekdays" ) != 0 )
  196.        { if( getnumlist( buf, &weekdays, 7, 7 ) )
  197.       { fprintf( stderr, "Error: Invalid syntax in weekdays tag!\n" );
  198.         exit( 1 );
  199.       }
  200.        }
  201.  
  202.       if(strstr(buf,"topuser_sort_field") != 0) {
  203.          getword(wbuf,buf,' ');
  204.          getword(TopuserSortField,buf,' ');
  205.          strcpy(TopuserSortOrder,buf);
  206.          fixnone(TopuserSortOrder);
  207.       }
  208.  
  209.       if(strstr(buf,"user_sort_field") != 0) {
  210.          getword(wbuf,buf,' ');
  211.          getword(UserSortField,buf,' ');
  212.          strcpy(UserSortOrder,buf);
  213.          fixnone(UserSortOrder);
  214.       }
  215.  
  216.       if(strstr(buf,"access_log") != 0) {
  217.          getword(wbuf,buf,' ');
  218.          strcpy(AccessLog,buf);
  219.          fixnone(AccessLog);
  220.       }
  221.  
  222.       if(strstr(buf,"useragent_log") != 0) {
  223.          getword(wbuf,buf,' ');
  224.          strcpy(UserAgentLog,buf);
  225.          fixnone(UserAgentLog);
  226.       }
  227.  
  228.       if(strstr(buf,"exclude_hosts") != 0) {
  229.          getword(wbuf,buf,' ');
  230.          strcpy(ExcludeHosts,buf);
  231.          fixnone(ExcludeHosts);
  232.       }
  233.  
  234.       if(strstr(buf,"exclude_codes") != 0) {
  235.          getword(wbuf,buf,' ');
  236.          strcpy(ExcludeCodes,buf);
  237.          fixnone(ExcludeCodes);
  238.       }
  239.  
  240.       if(strstr(buf,"exclude_users") != 0) {
  241.          getword(wbuf,buf,' ');
  242.          strcpy(ExcludeUsers,buf);
  243.          fixnone(ExcludeUsers);
  244.       }
  245.  
  246.       if(strstr(buf,"password") != 0) {
  247.          getword(wbuf,buf,' ');
  248.          strcpy(PasswdFile,buf);
  249.          fixnone(PasswdFile);
  250.       }
  251.  
  252.       if(strstr(buf,"temporary_dir") != 0) {
  253.          getword(wbuf,buf,' ');
  254.          strcpy(TempDir,buf);
  255.          fixnone(TempDir);
  256.       }
  257.  
  258.       if(strstr(buf,"report_type") != 0) {
  259.          getword(wbuf,buf,' ');
  260.          strcpy(ReportType,buf);
  261.          fixnone(ReportType);
  262.       }
  263.  
  264.       if(strstr(buf,"output_dir") != 0) {
  265.          if(strstr(buf,"output_dir_form") == 0) {
  266.             getword(wbuf,buf,' ');
  267.             strcpy(OutputDir,buf);
  268.             fixnone(OutputDir);
  269.          }
  270.       }
  271.  
  272.       if(strstr(buf,"output_email") != 0) {
  273.          getword(wbuf,buf,' ');
  274.          strcpy(OutputEmail,buf);
  275.          fixnone(OutputEmail);
  276.       }
  277.  
  278.       if(strstr(buf,"per_user_limit") != 0) {
  279.          getword(wbuf,buf,' ');
  280.          getword(PerUserLimitFile,buf,' ');
  281.          strcpy(PerUserLimit,buf);
  282.          fixnone(PerUserLimitFile);
  283.          fixnone(PerUserLimit);
  284.       }
  285.  
  286.  
  287.       if(strstr(buf,"lastlog") != 0) {
  288.          getword(wbuf,buf,' ');
  289.          strcpy(LastLog,buf);
  290.          fixnone(LastLog);
  291.       }
  292.  
  293.       if(strstr(buf,"remove_temp_files") != 0) {
  294.          getword(wbuf,buf,' ');
  295.          strcpy(RemoveTempFiles,buf);
  296.          fixnone(RemoveTempFiles);
  297.       }
  298.  
  299.       if(strstr(buf,"replace_index") != 0) {
  300.          getword(wbuf,buf,' ');
  301.          strcpy(ReplaceIndex,buf);
  302.          fixnone(ReplaceIndex);
  303.       }      
  304.  
  305.       if(strstr(buf,"index") != 0) {
  306.          getword(wbuf,buf,' ');
  307.          strcpy(Index,buf);
  308.          fixnone(Index);
  309.       }
  310.  
  311.       if(strstr(buf,"overwrite_report") != 0) {
  312.          getword(wbuf,buf,' ');
  313.          strcpy(OverwriteReport,buf);
  314.          fixnone(OverwriteReport);
  315.       }
  316.  
  317.       if(strstr(buf,"records_without_userid") != 0) {
  318.          getword(wbuf,buf,' ');
  319.          strcpy(RecordsWithoutUser,buf);
  320.          fixnone(RecordsWithoutUser);
  321.       }
  322.  
  323.       if(strstr(buf,"use_comma") != 0) {
  324.          getword(wbuf,buf,' ');
  325.          strcpy(UseComma,buf);
  326.          fixnone(UseComma);
  327.       }
  328.  
  329.       if(strstr(buf,"mail_utility") != 0) {
  330.          getword(wbuf,buf,' ');
  331.          strcpy(MailUtility,buf);
  332.          fixnone(MailUtility);
  333.       }
  334.  
  335.       if(strstr(buf,"topsites_num") != 0) {
  336.          getword(wbuf,buf,' ');
  337.          strcpy(TopSitesNum,buf);
  338.          fixnone(TopSitesNum);
  339.       }
  340.  
  341.       if(strstr(buf,"topuser_num") != 0) {
  342.          getword(wbuf,buf,' ');
  343.          strcpy(TopUsersNum,buf);
  344.          fixnone(TopUsersNum);
  345.       }
  346.  
  347.       if(strstr(buf,"usertab") != 0) {
  348.          getword(wbuf,buf,' ');
  349.          strcpy(UserTabFile,buf);
  350.          fixnone(UserTabFile);
  351.       }
  352.  
  353.       if(strstr(buf,"topsites_sort_order") != 0) {
  354.          getword(wbuf,buf,' ');
  355.          getword(TopsitesSortField,buf,' ');
  356.          strcpy(TopsitesSortType,buf);
  357.          fixnone(TopsitesSortField);
  358.          fixnone(TopsitesSortType);
  359.       }
  360.  
  361.       if(strstr(buf,"long_url") != 0) {
  362.          getword(wbuf,buf,' ');
  363.          strcpy(LongUrl,buf);
  364.          fixnone(LongUrl);
  365.       }
  366.  
  367.       if(strstr(buf,"language") != 0) {
  368.          getword(wbuf,buf,' ');
  369.          strcpy(language,buf);
  370.          fixnone(language);
  371.       }
  372.  
  373.       if(strstr(buf,"date_time_by") != 0) {
  374.          getword(wbuf,buf,' ');
  375.          strcpy(datetimeby,buf);
  376.          fixnone(datetimeby);
  377.       }
  378.  
  379.       if(strstr(buf,"charset") != 0) {
  380.          getword(wbuf,buf,' ');
  381.          strcpy(CharSet,buf);
  382.          fixnone(CharSet);
  383.          ccharset(CharSet);
  384.       }
  385.  
  386.       if(strstr(buf,"user_invalid_char") != 0) {
  387.          getword(wbuf,buf,'"');
  388.          getword(UserInvalidChar,buf,'"');
  389.          fixnone(UserInvalidChar);
  390.       }
  391.  
  392.       if(strstr(buf,"include_users") != 0) {
  393.          getword(wbuf,buf,'"');
  394.          getword(wbuf,buf,'"');
  395.      sprintf(IncludeUsers,":%s:",wbuf);
  396.          fixnone(IncludeUsers);
  397.       }
  398.  
  399.       if(strstr(buf,"exclude_string") != 0) {
  400.          getword(wbuf,buf,'"');
  401.          getword(ExcludeString,buf,'"');
  402.          fixnone(ExcludeString);
  403.       }
  404.  
  405.       if(strstr(buf,"privacy") != 0) {
  406.          if(strstr(buf,"privacy_string") == 0 && \
  407.         strstr(buf,"privacy_string_color") == 0) {
  408.             getword(wbuf,buf,' ');
  409.             strcpy(Privacy,buf);
  410.             fixnone(Privacy);
  411.      }
  412.       }
  413.  
  414.       if(strstr(buf,"privacy_string") != 0) {
  415.      if(strstr(buf,"privacy_string_color") == 0) {
  416.             getword(wbuf,buf,'"');
  417.             getword(PrivacyString,buf,'"');
  418.             fixnone(PrivacyString);
  419.      }
  420.       }
  421.  
  422.       if(strstr(buf,"privacy_string_color") != 0) {
  423.          getword(wbuf,buf,' ');
  424.          strcpy(PrivacyStringColor,buf);
  425.          fixnone(PrivacyStringColor);
  426.       }
  427.  
  428.       if(strstr(buf,"show_successful_message") != 0) {
  429.          getword(wbuf,buf,' ');
  430.          strcpy(SuccessfulMsg,buf);
  431.          fixnone(SuccessfulMsg);
  432.       }
  433.  
  434.       if(strstr(buf,"topuser_fields") != 0) {
  435.          getword(wbuf,buf,' ');
  436.          strcpy(TopUserFields,buf);
  437.          fixnone(TopUserFields);
  438.       }
  439.  
  440.       if(strstr(buf,"datafile ") != 0) {
  441.          getword(wbuf,buf,' ');
  442.          strcpy(DataFile,buf);
  443.          fixnone(DataFile);
  444.       }
  445.  
  446.       if(strstr(buf,"datafile_delimiter") != 0) {
  447.          getword(wbuf,buf,' ');
  448.          getword(wbuf,buf,'"');
  449.          getword(DataFileDelimiter,buf,'"');
  450.          fixnone(DataFileDelimiter);
  451.       }
  452.  
  453.       if(strstr(buf,"datafile_fields") != 0) {
  454.          getword(wbuf,buf,' ');
  455.          strcpy(DataFileFields,buf);
  456.          fixnone(DataFileFields);
  457.       }
  458.  
  459.    }
  460.  
  461.    fclose(fp_in);
  462.  
  463.    language_load(language);
  464.  
  465.    return;
  466. }
  467.