File: squidview.h

package info (click to toggle)
squidview 0.86-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 600 kB
  • ctags: 423
  • sloc: cpp: 5,041; sh: 1,243; makefile: 23
file content (326 lines) | stat: -rw-r--r-- 8,789 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Library General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

 squidview 0.8x
 
 A program to nicely browse your squid log
  
 (c) 2001 - 2013 Graeme Sheppard

 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
#include <curses.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <time.h>
#include <string>

using namespace std;

#define nInputLen 80
#define nReadBuffer 2048

// fields/columns of squid log lines 
int iTimeCol = -1;
int iCacheHitCol = -1;
int iSizeCol = -1;
int iTargetCol = -1;
int iUserCol = -1;
int iIPCol = -1;

int iUserNameLen = 8;  // maximum displayed width of a login name
#define nSizeCols 11   // width given to display size of requests

typedef off_t tFilePos;            // positions in log file are of this type

typedef uint64_t tByteTotal;       // for summing bytes transferred
typedef uint32_t tIPnum;           // IP aliases only 32 bit at this stage

const time_t nSecsInDay = 60 * 60 * 24;

const char cEOL = 10;           // End Of Line character 
const char cCR = 13;
const char cSeperator = 10;

string sHomeDir;
const char szSquidHome[] = ".squidview";
string sPathToFiles;
const string sLogLocations[] = {"/var/log/squid/access.log",
  "/usr/local/squid/var/logs/access.log", ""};
// disribution builders: put your log location first in the list
// last entry must be ""

const char szLog1[] = "log1";
const char szLog2[] = "log2";
const char szLog3[] = "log3";
const char szLabel1[] = "Pri";
const char szLabel2[] = "Sec";
const char szLabel3[] = "Tri";
const char* pszCurrentLog;
const char* pszCurrentName;
const char szWordFile[] = "words";         // search words 
const char szUsersFile[] = "users";        // list of real names 
const char szAliasesFile[] = "aliases";    // map IPs to user names
const char szHowToFile[] = "HOWTO";      // link name 

string sLogFile1, sLogFile2, sLogFile3;
string sWordFile, sUsersFile, sAliasesFile, sSetFileName, sHowToLink;
int fReadingFile = -1;
char const *pszReadingFile = 0;

string sViewer = "less";
string sCurrentReport = "";
string sCurrentEmail = "";
const string sReportExt = ".txt";

char cDiskBuffer [nReadBuffer +8];     // buffer for log read
char szEmpty = '\0';                   // null string...
char* pcEmpty = &szEmpty;              // ...pointed to by this
char* pcReqBuff = pcEmpty;             // normally the start of the request
                                       // or above if the read op fails

string sWords;
string sStatusMessage = "";

int iSizeHitGrade = 0;
int iSizeHitBytes = 0;
string sSizeHits = "50000 250000 1000000 10000000";

WINDOW* wTemp = 0; // dummy window 

tFilePos iPagePos,        // point in log file of top of current screen 
         iLastPage,       //  " "   "   "  "   of last screen 
         iLogFileSize,
         iLinePos,        // where the current highlighted line is 
         iLastLinePos;    // the last line in log file 

int iMainLines,       // no. of lines in main window 
    iLinesDown,       // which line the highlight bar is at 
    iMaxLinesDown,    // in the case of very small log files 
    iMonitorMode = 1, // like the Unix command tail 
    iCurrentLog = 1;  // which log?

class ct
{
  public:
    ct& operator << (char);
    ct& operator << (bool);
    ct& operator << (const char*);
    ct& operator << (const string&);
    ct& operator << (int);
};

string sDebugText = "";

enum eSearch {hit, miss, veto};
enum eFocus {no_focus, user, cache};
enum eWordHits {no_word, text, CSV};
enum eBandUserTotals {nBUT_none, nBUT_notveto, nBUT_all};
enum eBandDomainTotals {nBDT_none, nBDT_all, nBDT_user};
enum eBandDomainIncludes {nBDI_notveto, nBDI_all};

// log a report options

tFilePos iRepStart = 0,             // report from where
         iRepEnd = 0;               // report to where
int iRepColumns = 80,               // columns of screen?
    iRepCSVcols = 100;              // columns of CSV target
bool bRepSplit = false,             // split long lines
     bRepShowSize = false,          // indent for request size
     bRepKeepExt = true,            // remove innards to show .mp3 etc
     bRepCacheReport = true;
string sRepFileName = "temp.txt",   // report file name
       sRepFilter = "",             // filter report
       sRepSeperator = "|",         // for CSV
       sRepFocus = "",
       sRepBDTuser = "",
       sRepTitle = "";
int iRepWordHits = text,
    iRepBUT = nBUT_notveto,
    iRepBDT = nBDT_all,
    iRepBDI = nBDI_notveto,
    iRepFocus = no_focus;
bool bLookupIP = true;
bool bAliases = false;
int iRepFast = 10000;
bool bRepMySort = true;

struct sRecordPointer
{
  tByteTotal iBytes;
  int iHits;
  int iRecordNumber;

  sRecordPointer operator= (const sRecordPointer&);
};

struct sListRecords
{
  vector <sRecordPointer> vList;
  
  enum eSortType {nSortHits, nSortBytes};
  
  void Sort (eSortType nSelect);
  void Empty();
};

struct sUserRecord
{
  string sLoginName;
  string sFullName;
};

struct sDomainRecord
{
  string sDomainName;
};


struct rUserTotal
{
  tByteTotal iBytes;
  int iHits;
  string sLoginName;
  string sFullName;

  rUserTotal operator= (const rUserTotal&);
};

struct rDomainTotal
{
  tByteTotal iBytes;
  int iHits;
  string sDomain;

  rDomainTotal operator= (const rDomainTotal&);
};


struct rAliasRecord
{
  tIPnum iIPnum;
  int iUserNum;
};

vector <rAliasRecord> vAliasList;
vector <string> vAliasUserName;

int iSortFlag = 0;


// story of recent activity by one user
class cUserHistory
{
  public:
    bool Run (const string&);
    void CalcScreen();
    bool Browse();
    void AddHistory();
    int AddHistoryNorth();
    int AddHistorySouth();
    void DisplayHistory();
    void DisplayHelp();
    void ZeroAll();

    string sUser;
    static const int nMaxRows = 200;
    static const int nMaxNorth = 1000;
    static const int nMaxSouth = 1000;
    vector <tFilePos> vRequests;
    tFilePos iOneUserFileSize, iNorthMark, iSouthMark, iSouthMarkEnd;
    int iTotalRows, iSelectedAddress;
    int iScreenHeight, iSelectedRow;
    int iScreenStart, iLastScreenRow;
};


// tally of users' activity
class cUsersMode
{
  public:
    cUsersMode();
    bool Enter();
    bool Browse();
    void DisplayPoints();
    void DisplayFullNames();
    void DisplayGreatestURLs();
    void DisplayLastURLs();
    void DisplayHeading (const string& sTitle);
    void DisplayData (int iData);
    void DisplayHelp();
    void CalcScreen();
    void AddData (tFilePos iFrom, tFilePos iTo);
    void SortData();
    void SortMenu();
    const char* SortMode();
    void AgeData (int iCurrentTime);
    void FindFullNames();
    void ZeroAll();

    struct rUserHistory
    {
      string sUser, sFullName;
      int iPoints, iBytes, iRequests, iURLsize;
      tFilePos iGreatestURL, iLastURL;
      time_t iLastTime;
      void Zero()
      {
        sUser = sFullName = "";
        iPoints = iBytes = iRequests = iURLsize = iLastTime = 0;
        iGreatestURL = iLastURL = -1;
      }
      rUserHistory& operator= (const rUserHistory& aSrc)
      {
        sUser = aSrc.sUser;
        sFullName = aSrc.sFullName;
        iPoints = aSrc.iPoints;
        iBytes = aSrc.iBytes;
        iRequests = aSrc.iRequests;
        iURLsize = aSrc.iURLsize;
        iLastTime = aSrc.iLastTime;  
        iGreatestURL = aSrc.iGreatestURL;
        iLastURL = aSrc.iLastURL;
        return *this; 
      }
    };
    string LookupUser (const rUserHistory& aUser);

    inline int CalcAeon (int iRough)
    {
      return int (iRough / iHistoryPeriod) * iHistoryPeriod;
    }
        
    enum eSM {nPoints = 0, nFullNames, nGreatest, nLast, nSMend} iScreenMode;
    enum eSort {nSortN, nSortU, nSortP, nSortB, nSortR, nSortURL, nSortI}
      iSortMode;
    int iScreenStart, iSelectedRow, iTotalRows;
    int iScreenHeight, iSelectedAddress, iLastScreenRow;
    vector <rUserHistory> vHistory;
    time_t iLastAdjustTime, iNextAdjustTime;
    int iHistoryPeriod;
    float fFadeFactor, fEntryFactor;
    tFilePos iCurrentLogPos, iUsersFileSize;
    bool bUsersMonitorMode;
    bool bAcceptDenies;
};