60 |
|
|
61 |
void analyseLine(string line) { |
void analyseLine(string line) { |
62 |
vector<string> words = getTokens(line); |
vector<string> words = getTokens(line); |
63 |
|
|
64 |
|
if (words.size() < 7) { |
65 |
|
cout << "Illegal line format " << line << endl; |
66 |
|
return; |
67 |
|
} |
68 |
|
|
69 |
//print date and time |
//print date and time |
70 |
cout << words[0] << " " << words[1] << " " << words[2] << " "; |
cout << words[0] << " " << words[1] << " " << words[2] << " "; |
78 |
|
|
79 |
|
|
80 |
void printUsage() { |
void printUsage() { |
81 |
cout << "Usage: analyser [-l] <logfile>" << endl; |
cout << "Usage: analyser [-l] <logfile>|-" << endl; |
82 |
|
cout << "Use '-' for reading logdata from std input" << endl; |
83 |
cout << "Options:" << endl; |
cout << "Options:" << endl; |
84 |
cout << " -l : geoip lookup on source IP adresses" << endl; |
cout << " -l : geoip lookup on source IP adresses" << endl; |
85 |
} |
} |
105 |
file = argv[1]; |
file = argv[1]; |
106 |
} |
} |
107 |
|
|
108 |
|
istream* in; |
109 |
|
ifstream infile; |
110 |
|
|
111 |
ifstream in(file.c_str()); |
if ( file == "-") { |
112 |
|
in = &cin; |
113 |
|
} else { |
114 |
|
infile.open(file.c_str()); |
115 |
|
|
116 |
if (!in) { |
if (!infile) { |
117 |
cout << "Could not open " << file << endl; |
cout << "Could not open " << file << endl; |
118 |
return 1; |
return 1; |
119 |
|
} |
120 |
|
|
121 |
|
in = &infile; |
122 |
} |
} |
123 |
|
|
124 |
|
|
125 |
|
|
126 |
if (lookup){ |
if (lookup){ |
127 |
gi = GeoIP_new(GEOIP_STANDARD); |
gi = GeoIP_new(GEOIP_STANDARD); |
128 |
} |
} |
129 |
|
|
130 |
while (!in.eof()) { |
char buffer[1024]; |
131 |
char buffer[1024]; |
|
132 |
in.getline(buffer,1024); |
while (!in->eof()) { |
133 |
|
in->getline(buffer,1024); |
134 |
if (buffer[0] == 0) |
if (buffer[0] == 0) |
135 |
continue; //empty line |
continue; //empty line |
136 |
analyseLine(buffer); |
analyseLine(buffer); |
137 |
} |
} |
138 |
|
|
139 |
if (lookup) { |
if (lookup) { |
140 |
|
GeoIP_delete(gi); |
141 |
} |
} |
142 |
|
|
143 |
return 0; |
return 0; |