KSystemLog – system log viewer tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
4.3KB

  1. /***************************************************************************
  2. * Copyright (C) 2005 by Nicolas Ternisien *
  3. * nicolas.ternisien@gmail.com *
  4. * *
  5. * This program is free software; you can redistribute it and/or modify *
  6. * it under the terms of the GNU General Public License as published by *
  7. * the Free Software Foundation; either version 2 of the License, or *
  8. * (at your option) any later version. *
  9. * *
  10. * This program is distributed in the hope that it will be useful, *
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  13. * GNU General Public License for more details. *
  14. * *
  15. * You should have received a copy of the GNU General Public License *
  16. * along with this program; if not, write to the *
  17. * Free Software Foundation, Inc., *
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
  19. ***************************************************************************/
  20. #include <tdelocale.h>
  21. #include <tdemessagebox.h>
  22. #include "parsingHelper.h"
  23. #include "apacheAccessReader.h"
  24. ApacheAccessReader::ApacheAccessReader(TQObject *parent, const char *name) :
  25. DefaultReader(parent, name)
  26. {
  27. }
  28. ApacheAccessReader::~ApacheAccessReader() {
  29. }
  30. void ApacheAccessReader::initColumns(LogViewColumns* columns) {
  31. columns->append(new LogViewColumn(i18n("Date"), true, false));
  32. columns->append(new LogViewColumn(i18n("Host Name"), true, true));
  33. columns->append(new LogViewColumn(i18n("Id."), true, true)); //=Identification protocol [From RFC1413 (see Google for more infos)]
  34. columns->append(new LogViewColumn(i18n("User"), true, true));
  35. columns->append(new LogViewColumn(i18n("Response"), true, true));
  36. columns->append(new LogViewColumn(i18n("Bytes Sent"), true, false));
  37. columns->append(new LogViewColumn(i18n("Agent Identity"), true, true));
  38. columns->append(new LogViewColumn(i18n("HTTP Request"), true, false));
  39. columns->append(new LogViewColumn(i18n("URL"), true, true));
  40. }
  41. LogLine* ApacheAccessReader::parseMessage(TQString& logLine, LogFile* logFile) {
  42. int spacePos=logLine.find(' ');
  43. TQString hostName=logLine.left(spacePos);
  44. logLine=logLine.remove(0, spacePos+1);
  45. spacePos=logLine.find(' ');
  46. TQString identd=logLine.left(spacePos);
  47. logLine=logLine.remove(0, spacePos+1);
  48. spacePos=logLine.find(' ');
  49. TQString userName=logLine.left(spacePos);
  50. logLine=logLine.remove(0, spacePos+1);
  51. int endDate=logLine.find(']');
  52. TQString strDateTime=logLine.left(endDate);
  53. logLine=logLine.remove(0, endDate+3);
  54. TQDateTime dateTime=ParsingHelper::parseDateTimeFromHTTP(strDateTime);
  55. TQDate date=dateTime.date();
  56. TQTime time=dateTime.time();
  57. int endQuote=logLine.find('\"');
  58. TQString message=logLine.left(endQuote);
  59. logLine=logLine.remove(0, endQuote+2);
  60. spacePos=logLine.find(' ');
  61. TQString httpResponse=ParsingHelper::parseHTTPResponse(logLine.left(spacePos));
  62. logLine=logLine.remove(0, spacePos+1);
  63. spacePos=logLine.find(' ');
  64. TQString bytesSent=ParsingHelper::parseSize(logLine.left(spacePos));
  65. logLine=logLine.remove(0, spacePos+2);
  66. TQString url;
  67. endQuote=logLine.find('\"');
  68. if (endQuote!=-1) {
  69. url=logLine.left(endQuote);
  70. logLine=logLine.remove(0, endQuote+3);
  71. }
  72. TQString agent;
  73. //TODO Convert this value to find a more simple name for the Agent
  74. endQuote=logLine.find('\"');
  75. if (endQuote!=-1) {
  76. agent=ParsingHelper::parseAgent(logLine.left(endQuote));
  77. }
  78. TQStringList list;
  79. list.push_back(hostName);
  80. list.push_back(identd);
  81. list.push_back(userName);
  82. list.push_back(httpResponse);
  83. list.push_back(bytesSent);
  84. list.push_back(agent);
  85. list.push_back(message);
  86. list.push_back(url);
  87. TQString filePath=logFile->url.path();
  88. LogLine* line=new LogLine(date, time, list, filePath, Globals::informationLogLevel, Globals::apacheAccessMode->id);
  89. return(line);
  90. }
  91. #include "apacheAccessReader.moc"