PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/ettercap/src/interfaces/curses/ec_curses_logging.c

#
C | 165 lines | 95 code | 29 blank | 41 comment | 8 complexity | c70b66b6a07670a3b7575ba27402be33 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, GPL-2.0
  1. /*
  2. ettercap -- curses GUI
  3. Copyright (C) ALoR & NaGA
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  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. $Id: ec_curses_logging.c,v 1.4 2004/04/23 14:44:18 alor Exp $
  16. */
  17. #include <ec.h>
  18. #include <wdg.h>
  19. #include <ec_curses.h>
  20. #include <ec_log.h>
  21. #define FILE_LEN 40
  22. /* proto */
  23. static void toggle_compress(void);
  24. static void curses_log_all(void);
  25. static void log_all(void);
  26. static void curses_log_info(void);
  27. static void log_info(void);
  28. static void curses_log_msg(void);
  29. static void log_msg(void);
  30. static void curses_stop_log(void);
  31. static void curses_stop_msg(void);
  32. /* globals */
  33. static char tag_compress[] = " ";
  34. static char *logfile;
  35. struct wdg_menu menu_logging[] = { {"Logging", 'L', "", NULL},
  36. {"Log all packets and infos...", 'I', "I", curses_log_all},
  37. {"Log only infos...", 'i', "i", curses_log_info},
  38. {"Stop logging infos", 0, "", curses_stop_log},
  39. {"-", 0, "", NULL},
  40. {"Log user messages...", 'm', "m", curses_log_msg},
  41. {"Stop logging messages", 0, "", curses_stop_msg},
  42. {"-", 0, "", NULL},
  43. {"Compressed file", 0, tag_compress, toggle_compress},
  44. {NULL, 0, NULL, NULL},
  45. };
  46. /*******************************************/
  47. static void toggle_compress(void)
  48. {
  49. if (GBL_OPTIONS->compress) {
  50. tag_compress[0] = ' ';
  51. GBL_OPTIONS->compress = 0;
  52. } else {
  53. tag_compress[0] = '*';
  54. GBL_OPTIONS->compress = 1;
  55. }
  56. }
  57. /*
  58. * display the log dialog
  59. */
  60. static void curses_log_all(void)
  61. {
  62. DEBUG_MSG("curses_log_all");
  63. /* make sure to free if already set */
  64. SAFE_FREE(logfile);
  65. SAFE_CALLOC(logfile, FILE_LEN, sizeof(char));
  66. curses_input("Log File :", logfile, FILE_LEN, log_all);
  67. }
  68. static void log_all(void)
  69. {
  70. /* a check on the input */
  71. if (strlen(logfile) == 0) {
  72. ui_error("Please specify a filename");
  73. return;
  74. }
  75. set_loglevel(LOG_PACKET, logfile);
  76. SAFE_FREE(logfile);
  77. }
  78. /*
  79. * display the log dialog
  80. */
  81. static void curses_log_info(void)
  82. {
  83. DEBUG_MSG("curses_log_info");
  84. /* make sure to free if already set */
  85. SAFE_FREE(logfile);
  86. SAFE_CALLOC(logfile, FILE_LEN, sizeof(char));
  87. curses_input("Log File :", logfile, FILE_LEN, log_info);
  88. }
  89. static void log_info(void)
  90. {
  91. /* a check on the input */
  92. if (strlen(logfile) == 0) {
  93. ui_error("Please specify a filename");
  94. return;
  95. }
  96. set_loglevel(LOG_INFO, logfile);
  97. SAFE_FREE(logfile);
  98. }
  99. static void curses_stop_log(void)
  100. {
  101. set_loglevel(LOG_STOP, "");
  102. curses_message("Logging was stopped.");
  103. }
  104. /*
  105. * display the log dialog
  106. */
  107. static void curses_log_msg(void)
  108. {
  109. DEBUG_MSG("curses_log_msg");
  110. /* make sure to free if already set */
  111. SAFE_FREE(logfile);
  112. SAFE_CALLOC(logfile, FILE_LEN, sizeof(char));
  113. curses_input("Log File :", logfile, FILE_LEN, log_msg);
  114. }
  115. static void log_msg(void)
  116. {
  117. /* a check on the input */
  118. if (strlen(logfile) == 0) {
  119. ui_error("Please specify a filename");
  120. return;
  121. }
  122. set_msg_loglevel(LOG_TRUE, logfile);
  123. SAFE_FREE(logfile);
  124. }
  125. static void curses_stop_msg(void)
  126. {
  127. set_msg_loglevel(LOG_FALSE, NULL);
  128. curses_message("Message logging was stopped.");
  129. }
  130. /* EOF */
  131. // vim:ts=3:expandtab