"Fossies" - the Fresh Open Source Software Archive

Member "squidview-0.86/squidview.h" (14 Oct 2013, 8789 Bytes) of package /linux/privat/squidview-0.86.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  *  This program is free software; you can redistribute it and/or modify
    3  *  it under the terms of the GNU General Public License as published by
    4  *  the Free Software Foundation; either version 2 of the License, or
    5  *  (at your option) any later version.
    6  *
    7  *  This program is distributed in the hope that it will be useful,
    8  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    9  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   10  *  GNU Library General Public License for more details.
   11  *
   12  *  You should have received a copy of the GNU General Public License
   13  *  along with this program; if not, write to the Free Software
   14  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   15 
   16  squidview 0.8x
   17  
   18  A program to nicely browse your squid log
   19   
   20  (c) 2001 - 2013 Graeme Sheppard
   21 
   22  */
   23 
   24 #ifdef HAVE_CONFIG_H
   25 #include <config.h>
   26 #endif
   27 
   28 #include <stdio.h>
   29 #include <stdint.h>
   30 #include <inttypes.h>
   31 #include <curses.h>
   32 #include <sys/types.h>
   33 #include <sys/stat.h>
   34 #include <fcntl.h>
   35 #include <time.h>
   36 #include <string>
   37 
   38 using namespace std;
   39 
   40 #define nInputLen 80
   41 #define nReadBuffer 2048
   42 
   43 // fields/columns of squid log lines 
   44 int iTimeCol = -1;
   45 int iCacheHitCol = -1;
   46 int iSizeCol = -1;
   47 int iTargetCol = -1;
   48 int iUserCol = -1;
   49 int iIPCol = -1;
   50 
   51 int iUserNameLen = 8;  // maximum displayed width of a login name
   52 #define nSizeCols 11   // width given to display size of requests
   53 
   54 typedef off_t tFilePos;            // positions in log file are of this type
   55 
   56 typedef uint64_t tByteTotal;       // for summing bytes transferred
   57 typedef uint32_t tIPnum;           // IP aliases only 32 bit at this stage
   58 
   59 const time_t nSecsInDay = 60 * 60 * 24;
   60 
   61 const char cEOL = 10;           // End Of Line character 
   62 const char cCR = 13;
   63 const char cSeperator = 10;
   64 
   65 string sHomeDir;
   66 const char szSquidHome[] = ".squidview";
   67 string sPathToFiles;
   68 const string sLogLocations[] = {"/var/log/squid/access.log",
   69   "/usr/local/squid/var/logs/access.log", ""};
   70 // disribution builders: put your log location first in the list
   71 // last entry must be ""
   72 
   73 const char szLog1[] = "log1";
   74 const char szLog2[] = "log2";
   75 const char szLog3[] = "log3";
   76 const char szLabel1[] = "Pri";
   77 const char szLabel2[] = "Sec";
   78 const char szLabel3[] = "Tri";
   79 const char* pszCurrentLog;
   80 const char* pszCurrentName;
   81 const char szWordFile[] = "words";         // search words 
   82 const char szUsersFile[] = "users";        // list of real names 
   83 const char szAliasesFile[] = "aliases";    // map IPs to user names
   84 const char szHowToFile[] = "HOWTO";      // link name 
   85 
   86 string sLogFile1, sLogFile2, sLogFile3;
   87 string sWordFile, sUsersFile, sAliasesFile, sSetFileName, sHowToLink;
   88 int fReadingFile = -1;
   89 char const *pszReadingFile = 0;
   90 
   91 string sViewer = "less";
   92 string sCurrentReport = "";
   93 string sCurrentEmail = "";
   94 const string sReportExt = ".txt";
   95 
   96 char cDiskBuffer [nReadBuffer +8];     // buffer for log read
   97 char szEmpty = '\0';                   // null string...
   98 char* pcEmpty = &szEmpty;              // ...pointed to by this
   99 char* pcReqBuff = pcEmpty;             // normally the start of the request
  100                                        // or above if the read op fails
  101 
  102 string sWords;
  103 string sStatusMessage = "";
  104 
  105 int iSizeHitGrade = 0;
  106 int iSizeHitBytes = 0;
  107 string sSizeHits = "50000 250000 1000000 10000000";
  108 
  109 WINDOW* wTemp = 0; // dummy window 
  110 
  111 tFilePos iPagePos,        // point in log file of top of current screen 
  112          iLastPage,       //  " "   "   "  "   of last screen 
  113          iLogFileSize,
  114          iLinePos,        // where the current highlighted line is 
  115          iLastLinePos;    // the last line in log file 
  116 
  117 int iMainLines,       // no. of lines in main window 
  118     iLinesDown,       // which line the highlight bar is at 
  119     iMaxLinesDown,    // in the case of very small log files 
  120     iMonitorMode = 1, // like the Unix command tail 
  121     iCurrentLog = 1;  // which log?
  122 
  123 class ct
  124 {
  125   public:
  126     ct& operator << (char);
  127     ct& operator << (bool);
  128     ct& operator << (const char*);
  129     ct& operator << (const string&);
  130     ct& operator << (int);
  131 };
  132 
  133 string sDebugText = "";
  134 
  135 enum eSearch {hit, miss, veto};
  136 enum eFocus {no_focus, user, cache};
  137 enum eWordHits {no_word, text, CSV};
  138 enum eBandUserTotals {nBUT_none, nBUT_notveto, nBUT_all};
  139 enum eBandDomainTotals {nBDT_none, nBDT_all, nBDT_user};
  140 enum eBandDomainIncludes {nBDI_notveto, nBDI_all};
  141 
  142 // log a report options
  143 
  144 tFilePos iRepStart = 0,             // report from where
  145          iRepEnd = 0;               // report to where
  146 int iRepColumns = 80,               // columns of screen?
  147     iRepCSVcols = 100;              // columns of CSV target
  148 bool bRepSplit = false,             // split long lines
  149      bRepShowSize = false,          // indent for request size
  150      bRepKeepExt = true,            // remove innards to show .mp3 etc
  151      bRepCacheReport = true;
  152 string sRepFileName = "temp.txt",   // report file name
  153        sRepFilter = "",             // filter report
  154        sRepSeperator = "|",         // for CSV
  155        sRepFocus = "",
  156        sRepBDTuser = "",
  157        sRepTitle = "";
  158 int iRepWordHits = text,
  159     iRepBUT = nBUT_notveto,
  160     iRepBDT = nBDT_all,
  161     iRepBDI = nBDI_notveto,
  162     iRepFocus = no_focus;
  163 bool bLookupIP = true;
  164 bool bAliases = false;
  165 int iRepFast = 10000;
  166 bool bRepMySort = true;
  167 
  168 struct sRecordPointer
  169 {
  170   tByteTotal iBytes;
  171   int iHits;
  172   int iRecordNumber;
  173 
  174   sRecordPointer operator= (const sRecordPointer&);
  175 };
  176 
  177 struct sListRecords
  178 {
  179   vector <sRecordPointer> vList;
  180   
  181   enum eSortType {nSortHits, nSortBytes};
  182   
  183   void Sort (eSortType nSelect);
  184   void Empty();
  185 };
  186 
  187 struct sUserRecord
  188 {
  189   string sLoginName;
  190   string sFullName;
  191 };
  192 
  193 struct sDomainRecord
  194 {
  195   string sDomainName;
  196 };
  197 
  198 
  199 struct rUserTotal
  200 {
  201   tByteTotal iBytes;
  202   int iHits;
  203   string sLoginName;
  204   string sFullName;
  205 
  206   rUserTotal operator= (const rUserTotal&);
  207 };
  208 
  209 struct rDomainTotal
  210 {
  211   tByteTotal iBytes;
  212   int iHits;
  213   string sDomain;
  214 
  215   rDomainTotal operator= (const rDomainTotal&);
  216 };
  217 
  218 
  219 struct rAliasRecord
  220 {
  221   tIPnum iIPnum;
  222   int iUserNum;
  223 };
  224 
  225 vector <rAliasRecord> vAliasList;
  226 vector <string> vAliasUserName;
  227 
  228 int iSortFlag = 0;
  229 
  230 
  231 // story of recent activity by one user
  232 class cUserHistory
  233 {
  234   public:
  235     bool Run (const string&);
  236     void CalcScreen();
  237     bool Browse();
  238     void AddHistory();
  239     int AddHistoryNorth();
  240     int AddHistorySouth();
  241     void DisplayHistory();
  242     void DisplayHelp();
  243     void ZeroAll();
  244 
  245     string sUser;
  246     static const int nMaxRows = 200;
  247     static const int nMaxNorth = 1000;
  248     static const int nMaxSouth = 1000;
  249     vector <tFilePos> vRequests;
  250     tFilePos iOneUserFileSize, iNorthMark, iSouthMark, iSouthMarkEnd;
  251     int iTotalRows, iSelectedAddress;
  252     int iScreenHeight, iSelectedRow;
  253     int iScreenStart, iLastScreenRow;
  254 };
  255 
  256 
  257 // tally of users' activity
  258 class cUsersMode
  259 {
  260   public:
  261     cUsersMode();
  262     bool Enter();
  263     bool Browse();
  264     void DisplayPoints();
  265     void DisplayFullNames();
  266     void DisplayGreatestURLs();
  267     void DisplayLastURLs();
  268     void DisplayHeading (const string& sTitle);
  269     void DisplayData (int iData);
  270     void DisplayHelp();
  271     void CalcScreen();
  272     void AddData (tFilePos iFrom, tFilePos iTo);
  273     void SortData();
  274     void SortMenu();
  275     const char* SortMode();
  276     void AgeData (int iCurrentTime);
  277     void FindFullNames();
  278     void ZeroAll();
  279 
  280     struct rUserHistory
  281     {
  282       string sUser, sFullName;
  283       int iPoints, iBytes, iRequests, iURLsize;
  284       tFilePos iGreatestURL, iLastURL;
  285       time_t iLastTime;
  286       void Zero()
  287       {
  288         sUser = sFullName = "";
  289         iPoints = iBytes = iRequests = iURLsize = iLastTime = 0;
  290         iGreatestURL = iLastURL = -1;
  291       }
  292       rUserHistory& operator= (const rUserHistory& aSrc)
  293       {
  294         sUser = aSrc.sUser;
  295         sFullName = aSrc.sFullName;
  296         iPoints = aSrc.iPoints;
  297         iBytes = aSrc.iBytes;
  298         iRequests = aSrc.iRequests;
  299         iURLsize = aSrc.iURLsize;
  300         iLastTime = aSrc.iLastTime;  
  301         iGreatestURL = aSrc.iGreatestURL;
  302         iLastURL = aSrc.iLastURL;
  303         return *this; 
  304       }
  305     };
  306     string LookupUser (const rUserHistory& aUser);
  307 
  308     inline int CalcAeon (int iRough)
  309     {
  310       return int (iRough / iHistoryPeriod) * iHistoryPeriod;
  311     }
  312         
  313     enum eSM {nPoints = 0, nFullNames, nGreatest, nLast, nSMend} iScreenMode;
  314     enum eSort {nSortN, nSortU, nSortP, nSortB, nSortR, nSortURL, nSortI}
  315       iSortMode;
  316     int iScreenStart, iSelectedRow, iTotalRows;
  317     int iScreenHeight, iSelectedAddress, iLastScreenRow;
  318     vector <rUserHistory> vHistory;
  319     time_t iLastAdjustTime, iNextAdjustTime;
  320     int iHistoryPeriod;
  321     float fFadeFactor, fEntryFactor;
  322     tFilePos iCurrentLogPos, iUsersFileSize;
  323     bool bUsersMonitorMode;
  324     bool bAcceptDenies;
  325 };
  326