diff -crN srg-1.0-orig/configuration.cc srg-1.0/configuration.cc *** srg-1.0-orig/configuration.cc 2004-06-07 06:37:17.000000000 +0200 --- srg-1.0/configuration.cc 2004-09-15 23:24:18.000000000 +0200 *************** *** 76,81 **** --- 76,82 ---- "-T Title for inclusion in header of HTML files\n" "-u <username> Perform analysis only on requests from the\n" " specified username.\n" + "-U <login2fullname file> Look up the full user name using info in this file\n" "-v Verbose mode. Print relevant messages.\n" "-V Print Version and exit.\n" , progname); *************** *** 107,112 **** --- 108,114 ---- char *phpheadf = NULL; char *phpfootf = NULL; char *ip2userf = NULL; + char *login2fullnamef = NULL; int debugf = 0; int locationf = 0; int showtimesf = 0; *************** *** 130,135 **** --- 132,138 ---- char *phpheadc = NULL; char *phpfootc = NULL; char *ip2userc = NULL; + char *login2fullnamec = NULL; char *groupbynetc=NULL; char *timesc = NULL; int filterbyc = 0; *************** *** 168,173 **** --- 171,177 ---- {"show_rates", TYPE_BOOL|TYPE_NULL, &showratesf}, {"nonameexists_showip", TYPE_BOOL|TYPE_NULL, &nonameshowipf}, {"iptouser_file", TYPE_STR|TYPE_NULL, &ip2userf}, + {"logintofullname_file", TYPE_STR|TYPE_NULL, &login2fullnamef}, {"dontshow_onlydeniedusers", TYPE_BOOL|TYPE_NULL, &hidedeniedf}, {"php_authentication", TYPE_BOOL|TYPE_NULL, &authf}, *************** *** 191,197 **** /* Parse command line arguments */ while((ch = getopt_long(argc, argv, ! "a:Ac:C:dDeE:f:g:hH:Lm:Mn:o:O:p:P:Rs:St:T:u:vV", long_options, &optindex)) != -1) { switch(ch) { --- 195,201 ---- /* Parse command line arguments */ while((ch = getopt_long(argc, argv, ! "a:Ac:C:dDeE:f:g:hH:Lm:Mn:o:O:p:P:Rs:St:T:u:U:vV", long_options, &optindex)) != -1) { switch(ch) { *************** *** 298,303 **** --- 302,310 ---- filtercritc = strdup(optarg); filterbyc += BY_USER; break; + case 'U': + login2fullnamec = strdup(optarg); + break; case 'v': verbosec = 1; break; *************** *** 462,467 **** --- 469,488 ---- } free(ip2userc); free(ip2userf); + + if (login2fullnamec != NULL) { + if (srg.debug) + fprintf(stderr, "Setting login to full user name file to %s " + "from command line\n",login2fullnamec); + srg.login2fullname = strdup(login2fullnamec); + } else if (login2fullnamef != NULL) { + if (srg.debug) + fprintf(stderr, "Setting login to full user name file to %s " + "from config file\n",login2fullnamef); + srg.login2fullname = strdup(login2fullnamef); + } + free(login2fullnamec); + free(login2fullnamef); if (maxagec > 0) { if (srg.debug) *************** *** 754,759 **** --- 775,781 ---- srg.phpfooter=NULL; srg.indexfname = "index.html"; srg.ip2user=NULL; + srg.login2fullname=NULL; srg.locationStats=0; srg.hideDeniedOnly=0; srg.authenticate=0; diff -crN srg-1.0-orig/examples/login2fullname.txt srg-1.0/examples/login2fullname.txt *** srg-1.0-orig/examples/login2fullname.txt 1970-01-01 01:00:00.000000000 +0100 --- srg-1.0/examples/login2fullname.txt 2004-09-19 21:35:24.000000000 +0200 *************** *** 0 **** --- 1,3 ---- + user1 John Doe + user2 Drizzt Do'Urden + user3 Thomas Covenant diff -crN srg-1.0-orig/examples/srg_reports.sh srg-1.0/examples/srg_reports.sh *** srg-1.0-orig/examples/srg_reports.sh 1970-01-01 01:00:00.000000000 +0100 --- srg-1.0/examples/srg_reports.sh 2004-09-19 21:20:29.000000000 +0200 *************** *** 0 **** --- 1,69 ---- + #!/bin/sh + + # This script should be run every day, right after midnight. + # It uses SRG to generate: + # - on each day: daily stats (for "yesterday") + # - on each monday: weekly stats (for the past week) + # - on the first day of the month: monthly stats (for the past month) + + # NOTE: squid logs have to be rotated accordingly! If you want monthly statistics/reports + # you have to keep them unrotated for a month... + + # Giuliano Cioffi -- g.cioffi@tiscali.it + + export LC_ALL='en_US' + export LOCALE='en_US' + + # switch it to "0" when everything is working as expected + DEBUG=1 + + # how do you run SRG ? The -t option will be appended to this variable + SRG='./srg -S -gU -HL -D -T "Proxy utilization" -f "logs/access.log" -U "examples/login2fullname.txt"' + + # where to store the reports + DAILYOUT="srg_reports/daily" + WEEKLYOUT="srg_reports/weekly" + MONTHLYOUT="srg_reports/monthly" + + + DOM=`date '+%d' | sed 's/^0//'` + DOW=`date '+%u'` + YESTERDAY=`date '+%d/%m/%Y' -d yesterday` + + # timespan, outputdir + run_srg() { + (( "$DEBUG" )) && echo "running: $SRG -t \"$1\" -o \"$2\"" + eval "$SRG -t \"$1\" -o \"$2\"" + } + + do_daily() { + run_srg "$YESTERDAY-$YESTERDAY" "$DAILYOUT" + } + + do_weekly() { + LASTMONDAY=`date '+%d/%m/%Y' -d "-7 days"` + run_srg "$LASTMONDAY-$YESTERDAY" "$WEEKLYOUT" + } + + do_monthly() { + LASTMONTH=$((`date '+%m' | sed 's/^0//'` - 1)) + YEAR=`date '+%Y'` + if (( "$LASTMONTH" == 0 )) ; then + LASTMONTH=12 + let 'YEAR -= 1' + fi + run_srg "1/$LASTMONTH/$YEAR-$YESTERDAY" "$MONTHLYOUT" + } + + do_daily + + if (( "$DOW" == 1 )) ; then + # monday + do_weekly + fi + + if (( "$DOM" == 1 )) ; then + # first day of the month + do_monthly + fi + diff -crN srg-1.0-orig/include/prototypes.h srg-1.0/include/prototypes.h *** srg-1.0-orig/include/prototypes.h 2004-06-07 06:37:17.000000000 +0200 --- srg-1.0/include/prototypes.h 2004-09-16 11:38:10.000000000 +0200 *************** *** 44,49 **** --- 44,50 ---- void recurse_unlink(const char *); void cull_oldreports(int); bool ip2username(const in_addr, char **); + bool login2fullname(const char *login, char **fullname); char * md5this(const char *); int shortmonth2int(const char *); int getMonthByName(const char *name); diff -crN srg-1.0-orig/include/srg.h srg-1.0/include/srg.h *** srg-1.0-orig/include/srg.h 2004-06-07 06:37:17.000000000 +0200 --- srg-1.0/include/srg.h 2004-09-15 22:53:19.000000000 +0200 *************** *** 103,108 **** --- 103,109 ---- char * indexfname; bool usephp; char * ip2user; + char * login2fullname; filter_info filter; in_addr groupByNetmask; unsigned int locationStats; *************** *** 143,147 **** --- 144,153 ---- char *username; }; + struct login2fullname_line { + char *login; + char *fullname; + }; + #endif diff -crN srg-1.0-orig/main.cc srg-1.0/main.cc *** srg-1.0-orig/main.cc 2004-06-07 06:37:17.000000000 +0200 --- srg-1.0/main.cc 2004-09-19 21:57:36.000000000 +0200 *************** *** 44,49 **** --- 44,50 ---- list<UserReport*> groups; UserReport* stats; list<ip2user_line> ip2users; + list<login2fullname_line> login2fullnames; Resolver *dnscache; /* Version information */ *************** *** 130,136 **** Line *iLine = new Line(srg.ip2user); if (iLine->getError() || iLine->eof()) { fprintf(stderr, "%s: Could not open the ip to user " ! "conversion file: %s", argv[0], srg.ip2user); exit(1); } --- 131,137 ---- Line *iLine = new Line(srg.ip2user); if (iLine->getError() || iLine->eof()) { fprintf(stderr, "%s: Could not open the ip to user " ! "conversion file: %s\n", argv[0], srg.ip2user); exit(1); } *************** *** 169,174 **** --- 170,207 ---- delete iLine; } + if (srg.login2fullname) { + Line *iLine = new Line(srg.login2fullname); + if (iLine->getError() || iLine->eof()) { + fprintf(stderr, "%s: Could not open the login to full user name " + "conversion file: %s\n", argv[0], srg.login2fullname); + exit(1); + } + + while(!iLine->eof()) { + login2fullname_line thisline; + char *loginLine = iLine->getline(); + + /* Check for comment lines */ + if (loginLine[0] == '\0' || loginLine[0] == '#') continue; + + char login[1024]; memset(login, 0, sizeof(login)); + char fullname[1024]; memset(fullname, 0, sizeof(fullname)); + if (sscanf(loginLine, "%1023s %1023c", login, fullname) != 2) { + fprintf(stderr, "%s: Error parsing login to full " + "user name file: %s\n", argv[0], + srg.login2fullname); + exit(1); + } + thisline.login = strdup(login); + thisline.fullname = strdup(fullname); + if (srg.debug) fprintf(stderr, "%s:%s\n", thisline.login, thisline.fullname); + /* Add this entry to the list */ + login2fullnames.push_back(thisline); + } + delete iLine; + } + Line *iLine = new Line(srg.accessLog); int linesT=0; int linesP=0; *************** *** 524,529 **** --- 557,565 ---- inet_ntoa(line->clientAddress)); } } + if (srg.login2fullname) { + login2fullname(group,&group); + } } else if (srg.groupBy == BY_IP) { group = strdup(inet_ntoa(line->clientAddress)); } else if (srg.groupBy == BY_SUBNET) { *************** *** 836,842 **** fprintf(outfile, "<td class=\"cellNum\">%s%%</td>", t); free(t); t = FormatOutput((int)ss.timeSpent); ! fprintf(outfile, "<td class=\"cellNum\">%s%%</td>", t); free(t); } /* Transfer Rate */ --- 872,878 ---- fprintf(outfile, "<td class=\"cellNum\">%s%%</td>", t); free(t); t = FormatOutput((int)ss.timeSpent); ! fprintf(outfile, "<td class=\"cellNum\">%s</td>", t); free(t); } /* Transfer Rate */ *************** *** 1124,1130 **** free(*lastiter); lastiter = iter; } - free(*lastiter); /* Finish off the HTML */ html_footer(outfile); --- 1160,1165 ---- *************** *** 1322,1327 **** --- 1357,1379 ---- return false; } + /* Looks up the specified login name in the login to full user name mapping. + * Returns it via the fullname parameter. Returns true if a match was found, + * false otherwise */ + bool login2fullname(const char *login, char **fullname) { + + list<login2fullname_line>::const_iterator iter; + for (iter=login2fullnames.begin(); iter != login2fullnames.end(); iter++) { + if (strcmp(login,(*iter).login) == 0) { + *fullname = strdup((*iter).fullname); + return true; + } + } + + /* otherwise leave *login as is... */ + return false; + } + /* Return the MD5 Hash of the specified string */ char *md5this(const char plaintextstr[]) { diff -crN srg-1.0-orig/resolver-test.cpp srg-1.0/resolver-test.cpp *** srg-1.0-orig/resolver-test.cpp 2004-06-07 06:37:17.000000000 +0200 --- srg-1.0/resolver-test.cpp 2004-09-13 15:34:48.000000000 +0200 *************** *** 32,38 **** } /* Use Root Servers because they are unlikey to change IP */ ! i.s_addr = dottedquad(128,9,0,107); t = r.get_name(i); if (t) { if (strcasecmp(t, "b.root-servers.net")!=0) { --- 32,38 ---- } /* Use Root Servers because they are unlikey to change IP */ ! i.s_addr = dottedquad(192,228,79,201); t = r.get_name(i); if (t) { if (strcasecmp(t, "b.root-servers.net")!=0) { diff -crN srg-1.0-orig/srg-FAQ.html srg-1.0/srg-FAQ.html *** srg-1.0-orig/srg-FAQ.html 2004-06-07 06:37:17.000000000 +0200 --- srg-1.0/srg-FAQ.html 2004-09-19 21:49:47.000000000 +0200 *************** *** 32,38 **** <LI><A HREF="#ss2.3">2.3 What do I need to install SRG?</A> </UL> <P> ! <H2><A NAME="toc4">4.</A> <A HREF="#ss4">SRG Configuration</A></H2> <UL> <LI><A HREF="#ss3.1">3.1 SRG Command Line Options</A> --- 32,38 ---- <LI><A HREF="#ss2.3">2.3 What do I need to install SRG?</A> </UL> <P> ! <H2><A NAME="toc3">3.</A> <A HREF="#ss3">SRG Configuration</A></H2> <UL> <LI><A HREF="#ss3.1">3.1 SRG Command Line Options</A> *************** *** 47,56 **** <LI><A HREF="#ss4.2">4.2 Using a PHP header file with authentication?</A> <LI><A HREF="#ss4.3">4.3 PHP header files and CSS</A> <LI><A HREF="#ss4.4">4.4 How do I use an IP2Username file?</A> ! <LI><A HREF="#ss4.5">4.5 What do these options for the -H switch do?</A> ! <LI><A HREF="#ss4.6">4.6 What is the -L switch for?</A> ! <LI><A HREF="#ss4.7">4.7 How does the -m option function?</A> ! <LI><A HREF="#ss4.8">4.8 What settings should I use for Squid?</A> </UL> --- 47,57 ---- <LI><A HREF="#ss4.2">4.2 Using a PHP header file with authentication?</A> <LI><A HREF="#ss4.3">4.3 PHP header files and CSS</A> <LI><A HREF="#ss4.4">4.4 How do I use an IP2Username file?</A> ! <LI><A HREF="#ss4.5">4.5 How do I use a login2fullname file?</A> ! <LI><A HREF="#ss4.6">4.6 What do these options for the -H switch do?</A> ! <LI><A HREF="#ss4.7">4.7 What is the -L switch for?</A> ! <LI><A HREF="#ss4.8">4.8 How does the -m option function?</A> ! <LI><A HREF="#ss4.9">4.9 What settings should I use for Squid?</A> </UL> *************** *** 172,196 **** Comments can be added using a '#' at the start of the line. </p> ! <h2><A NAME="ss4.5">4.5 What do these options for the -H switch do?</A></h2> <p>The -H<L|N> switch forces SRG to show the hostname that requested an URL in the corresponding Location report.<br> By passing -HL, SRG will perform a DNS lookup on any hostnames which are IP addresses (to try to get a more meaningful report). -HN will ignore this, and simply show the IP address. </p> ! <h2><A NAME="ss4.6">4.6 What is the -L switch for?</A></h2> <p>The -L switch tells SRG to show a report for the URL location, rather than just a link to the site.<br> This location report can hold very useful information, such as the times the site was accessed. </p> ! <h2><A NAME="ss4.7">4.7 How does the -m option function?</A></h2> <p>SRG automatically creates directories in the format of YYYYMMDD-YYYMMDD. If, while creating the latest report, a directory is found to be older than the value specified by -m (in days), that directory is deleted, and will no longer show up in reports. So, if you use this option and require archival, make sure to do it before the folders expire. </p> ! <h2><A NAME="ss4.8">4.8 What settings should I use for Squid?</A></h2> <p>Squid needs to output the log files using two options:<br> 1) Native log file format. The 'emulate_httpd_log' option breaks this.<br> 2) No spaces in URLs. This is the default configuration for uri_whitespace.<br> --- 173,209 ---- Comments can be added using a '#' at the start of the line. </p> ! <h2><A NAME="ss4.5">4.5 How do I use a login2fullname file?</A></h2> ! <p>SRG can extract login names from the proxy's log file. Should you need to ! expand them to some other value (e.g.: full user names), you may supply ! a filename for the -U switch.</p> ! <p>e.g. "./srg -U login2fullname.txt". </p> ! <p>The structure of the file is as follows: <br><br> ! <b>login</b> <b>FirstName</b> <b>LastName</b><br> ! <i>user1 John Doe</i><br><br> ! In reports, <b>login</b> will be substituted with the values you supplied ! on the line (they'll be concatenated). Comments can be added using a '#' at the start of the line.<br> ! </p> ! ! <h2><A NAME="ss4.6">4.6 What do these options for the -H switch do?</A></h2> <p>The -H<L|N> switch forces SRG to show the hostname that requested an URL in the corresponding Location report.<br> By passing -HL, SRG will perform a DNS lookup on any hostnames which are IP addresses (to try to get a more meaningful report). -HN will ignore this, and simply show the IP address. </p> ! <h2><A NAME="ss4.7">4.7 What is the -L switch for?</A></h2> <p>The -L switch tells SRG to show a report for the URL location, rather than just a link to the site.<br> This location report can hold very useful information, such as the times the site was accessed. </p> ! <h2><A NAME="ss4.8">4.8 How does the -m option function?</A></h2> <p>SRG automatically creates directories in the format of YYYYMMDD-YYYMMDD. If, while creating the latest report, a directory is found to be older than the value specified by -m (in days), that directory is deleted, and will no longer show up in reports. So, if you use this option and require archival, make sure to do it before the folders expire. </p> ! <h2><A NAME="ss4.9">4.9 What settings should I use for Squid?</A></h2> <p>Squid needs to output the log files using two options:<br> 1) Native log file format. The 'emulate_httpd_log' option breaks this.<br> 2) No spaces in URLs. This is the default configuration for uri_whitespace.<br>