1 /** 2 * ______ ___ 3 * / ____/___ / | _____________ __________ 4 * / / __/ __ \/ /| |/ ___/ ___/ _ \/ ___/ ___/ 5 * / /_/ / /_/ / ___ / /__/ /__/ __(__ |__ ) 6 * \____/\____/_/ |_\___/\___/\___/____/____/ 7 * 8 * The MIT License (MIT) 9 * Copyright (c) 2009-2020 Gerardo Orellana <hello @ goaccess.io> 10 * 11 * Permission is hereby granted, free of charge, to any person obtaining a copy 12 * of this software and associated documentation files (the "Software"), to deal 13 * in the Software without restriction, including without limitation the rights 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 15 * copies of the Software, and to permit persons to whom the Software is 16 * furnished to do so, subject to the following conditions: 17 * 18 * The above copyright notice and this permission notice shall be included in all 19 * copies or substantial portions of the Software. 20 * 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 27 * SOFTWARE. 28 */ 29 30 #ifndef SETTINGS_H_INCLUDED 31 #define SETTINGS_H_INCLUDED 32 33 #include <stdint.h> 34 #include "commons.h" 35 36 #define MAX_LINE_CONF 4096 37 #define MAX_EXTENSIONS 128 38 #define MAX_IGNORE_IPS 1024 + 128 39 #define MAX_IGNORE_REF 64 40 #define MAX_CUSTOM_COLORS 64 41 #define MAX_IGNORE_STATUS 64 42 #define MAX_OUTFORMATS 3 43 #define MAX_FILENAMES 512 44 #define MIN_DATENUM_FMT_LEN 7 45 #define NO_CONFIG_FILE "No config file used" 46 47 typedef enum LOGTYPE { 48 COMBINED, 49 VCOMBINED, 50 COMMON, 51 VCOMMON, 52 W3C, 53 SQUID, 54 CLOUDFRONT, 55 CLOUDSTORAGE, 56 AWSELB, 57 AWSS3, 58 CADDY, 59 } GLogType; 60 61 /* predefined log times */ 62 typedef struct GPreConfTime_ { 63 const char *fmt24; 64 const char *usec; 65 const char *sec; 66 } GPreConfTime; 67 68 /* predefined log dates */ 69 typedef struct GPreConfDate_ { 70 const char *apache; 71 const char *w3c; 72 const char *usec; 73 const char *sec; 74 } GPreConfDate; 75 76 /* predefined log formats */ 77 typedef struct GPreConfLog_ { 78 const char *combined; 79 const char *vcombined; 80 const char *common; 81 const char *vcommon; 82 const char *w3c; 83 const char *cloudfront; 84 const char *cloudstorage; 85 const char *awselb; 86 const char *squid; 87 const char *awss3; 88 const char *caddy; 89 } GPreConfLog; 90 91 /* *INDENT-OFF* */ 92 /* All configuration properties */ 93 typedef struct GConf_ 94 { 95 /* Array options */ 96 const char *colors[MAX_CUSTOM_COLORS]; /* colors */ 97 const char *enable_panels[TOTAL_MODULES]; /* array of panels to enable */ 98 const char *filenames[MAX_FILENAMES]; /* log files */ 99 const char *hide_referers[MAX_IGNORE_REF]; /* hide referrers from report */ 100 const char *ignore_ips[MAX_IGNORE_IPS]; /* array of ips to ignore */ 101 const char *ignore_panels[TOTAL_MODULES]; /* array of panels to ignore */ 102 const char *ignore_referers[MAX_IGNORE_REF]; /* referrers to ignore */ 103 const char *ignore_status[MAX_IGNORE_STATUS]; /* status to ignore */ 104 const char *output_formats[MAX_OUTFORMATS]; /* output format, e.g. , HTML */ 105 const char *sort_panels[TOTAL_MODULES]; /* sorting options for each panel */ 106 const char *static_files[MAX_EXTENSIONS]; /* static extensions */ 107 108 /* Log/date/time formats */ 109 char *date_format; /* date format */ 110 char *date_num_format; /* numeric date format %Y%m%d */ 111 char *time_format; /* time format as given by the user */ 112 char *spec_date_time_format; /* date format w/ specificity */ 113 char *spec_date_time_num_format; /* numeric date format w/ specificity */ 114 char *log_format; /* log format */ 115 char *iconfigfile; /* config file path */ 116 char ***user_browsers_hash; /* custom list of browsers */ 117 118 const char *debug_log; /* debug log path */ 119 const char *geoip_database; /* geoip db path */ 120 const char *html_custom_css; /* custom CSS */ 121 const char *html_custom_js; /* custom JS */ 122 const char *html_prefs; /* default HTML JSON preferences */ 123 const char *html_report_title; /* report title */ 124 const char *invalid_requests_log; /* invalid lines log path */ 125 const char *unknowns_log; /* unknown browsers/OSs log path */ 126 const char *pidfile; /* daemonize pid file path */ 127 const char *browsers_file; /* browser's file path */ 128 const char *db_path; /* db path to files */ 129 130 /* HTML real-time */ 131 const char *addr; /* IP address to bind to */ 132 const char *fifo_in; /* path FIFO in (reader) */ 133 const char *fifo_out; /* path FIFO out (writer) */ 134 const char *origin; /* WebSocket origin */ 135 const char *port; /* port to use */ 136 const char *sslcert; /* TLS/SSL path to certificate */ 137 const char *sslkey; /* TLS/SSL path to private key */ 138 const char *ws_url; /* WebSocket URL */ 139 140 /* User flags */ 141 int all_static_files; /* parse all static files */ 142 int anonymize_ip; /* anonymize ip addresses */ 143 int append_method; /* append method to the req key */ 144 int append_protocol; /* append protocol to the req key */ 145 int client_err_to_unique_count; /* count 400s as visitors */ 146 int code444_as_404; /* 444 as 404s? */ 147 int color_scheme; /* color scheme */ 148 int crawlers_only ; /* crawlers only */ 149 int daemonize; /* run program as a Unix daemon */ 150 const char *username; /* user to run program as */ 151 int double_decode; /* need to double decode */ 152 int enable_html_resolver; /* html/json/csv resolver */ 153 int geo_db; /* legacy geoip db */ 154 int hl_header; /* highlight header on term */ 155 int ignore_crawlers; /* ignore crawlers */ 156 int ignore_qstr; /* ignore query string */ 157 int ignore_statics; /* ignore static files */ 158 int json_pretty_print; /* pretty print JSON data */ 159 int list_agents; /* show list of agents per host */ 160 int load_conf_dlg; /* load curses config dialog */ 161 int load_global_config; /* use global config file */ 162 int max_items; /* max number of items to output */ 163 int mouse_support; /* add curses mouse support */ 164 int no_color; /* no terminal colors */ 165 int no_strict_status; /* don't enforce 100-599 status codes */ 166 int no_column_names; /* don't show col names on termnal */ 167 int no_csv_summary; /* don't show overall metrics */ 168 int no_html_last_updated; /* don't show HTML last updated field */ 169 int no_ip_validation; /* don't validate client IP addresses */ 170 int no_parsing_spinner; /* disable parsing spinner */ 171 int no_progress; /* disable progress metrics */ 172 int no_tab_scroll; /* don't scroll dashboard on tab */ 173 int output_stdout; /* outputting to stdout */ 174 int persist; /* ensure to persist data on exit */ 175 int process_and_exit; /* parse and exit without outputting */ 176 int real_os; /* show real OSs */ 177 int real_time_html; /* enable real-time HTML output */ 178 int restore; /* reload data from db-path */ 179 int skip_term_resolver; /* no terminal resolver */ 180 int is_json_log_format; /* is a json log format */ 181 uint32_t keep_last; /* number of days to keep in storage */ 182 uint32_t num_tests; /* number of lines to test */ 183 uint64_t html_refresh; /* refresh html report every X of seconds */ 184 uint64_t log_size; /* log size override */ 185 186 /* Internal flags */ 187 int bandwidth; /* is there bandwidth within the req line */ 188 int date_spec_hr; /* date specificity - hour */ 189 int has_geocity; 190 int has_geocountry; 191 int hour_spec_min; /* hour specificity - min */ 192 int read_stdin; /* read from stdin */ 193 int serve_usecs; /* is there time served within req line */ 194 int stop_processing; /* stop all processing */ 195 int tailing_mode; /* in tailing-mode? */ 196 197 /* Array indices */ 198 int color_idx; /* colors index */ 199 int enable_panel_idx; /* enable panels index */ 200 int filenames_idx; /* filenames index */ 201 int hide_referer_idx; /* hide referrers index */ 202 int ignore_ip_idx; /* ignored ips index */ 203 int ignore_panel_idx; /* ignored panels index */ 204 int ignore_referer_idx; /* ignored referrers index */ 205 int ignore_status_idx; /* ignore status index */ 206 int output_format_idx; /* output format index */ 207 int sort_panel_idx; /* sort panel index */ 208 int static_file_idx; /* static extensions index */ 209 int browsers_hash_idx; /* browsers hash index */ 210 211 size_t static_file_max_len; 212 213 } GConf; 214 /* *INDENT-ON* */ 215 216 char *get_selected_date_str (size_t idx); 217 char *get_selected_format_str (size_t idx); 218 char *get_selected_time_str (size_t idx); 219 const char *verify_formats (void); 220 int is_json_log_format (const char *fmt); 221 int parse_json_string (void *userdata, const char *str, int (*cb) (void *, char *, char *)); 222 size_t get_selected_format_idx (void); 223 void set_date_format_str (const char *optarg); 224 void set_log_format_str (const char *optarg); 225 void set_spec_date_format (void); 226 void set_time_format_str (const char *optarg); 227 228 extern GConf conf; 229 230 char *get_config_file_path (void); 231 int parse_conf_file (int *argc, char ***argv); 232 void free_cmd_args (void); 233 void free_formats (void); 234 void set_default_static_files (void); 235 236 #endif 237