/src/ntopng/include/Ntop.h
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * (C) 2013-26 - ntop.org |
4 | | * |
5 | | * |
6 | | * This program is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * This program is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software Foundation, |
18 | | * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | | * |
20 | | */ |
21 | | |
22 | | #ifndef _NTOP_CLASS_H_ |
23 | | #define _NTOP_CLASS_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | /** @defgroup Ntop Ntop |
28 | | * Main ntopng group. |
29 | | */ |
30 | | |
31 | | class NtopPro; |
32 | | |
33 | | /** @class Ntop |
34 | | * @brief Main class of ntopng. |
35 | | * |
36 | | * @ingroup Ntop |
37 | | * |
38 | | */ |
39 | | class Ntop { |
40 | | private: |
41 | | #ifndef WIN32 |
42 | | int startupLockFile; |
43 | | #endif |
44 | | bool flowChecksReloadInProgress, hostChecksReloadInProgress; |
45 | | bool hostPoolsReloadInProgress; |
46 | | bool interfacesShuttedDown; |
47 | | bool offline, forced_offline; |
48 | | bool broadcast_ip_disabled; |
49 | | Bloom *resolvedHostsBloom; /* Used by all redis class instances */ |
50 | | JobQueue jobsQueue; |
51 | | AddressTree local_interface_addresses; |
52 | | char epoch_buf[11], *zoneinfo, *myTZname; |
53 | | char working_dir[MAX_PATH]; /**< Working directory. */ |
54 | | char install_dir[MAX_PATH]; /**< Install directory. */ |
55 | | char startup_dir[MAX_PATH]; /**< Startup directory. */ |
56 | | char scripts_dir[MAX_PATH + 16]; |
57 | | char *custom_ndpi_protos; /**< Pointer of a custom protocol for nDPI. */ |
58 | | NetworkInterface **iface; /**< Array of network interfaces. */ |
59 | | NetworkInterface *system_interface; /** The system interface */ |
60 | | NetworkInterface *old_iface_to_purge; |
61 | | u_int8_t num_defined_interfaces; /**< Number of defined interfaces. */ |
62 | | bool flow_id_initialized; |
63 | | std::atomic<u_int64_t> flow_id; |
64 | | std::atomic<u_int16_t> num_active_lua_vms; |
65 | | HTTPserver *httpd; /**< Pointer of httpd server. */ |
66 | | NtopGlobals *globals; /**< Pointer of Ntop globals info and variables. */ |
67 | | u_int num_cpus; /**< Number of physical CPU cores. */ |
68 | | Redis *redis; /**< Pointer to the Redis server. */ |
69 | | Mutex m, users_m, speedtest_m, pools_lock; |
70 | | std::map<std::string, u_int8_t> cachedCustomLists; /* Cache of lists filenames */ |
71 | | std::map<std::string, std::string> luaCache; /* Cache used by Lua */ |
72 | | RwLock luaCacheLock; |
73 | | u_int32_t current_time; /* Updated by current_time */ |
74 | | #ifndef HAVE_NEDGE |
75 | | ElasticSearch *elastic_search; /**< Pointer of Elastic Search. */ |
76 | | #ifdef HAVE_ZMQ |
77 | | ZMQPublisher *zmqPublisher; |
78 | | #endif |
79 | | #if !defined(WIN32) && !defined(__APPLE__) |
80 | | SyslogDump *syslog; /**< Pointer of Logstash. */ |
81 | | #endif |
82 | | |
83 | | #ifdef HAVE_ZMQ |
84 | | ExportInterface *export_interface; |
85 | | #endif |
86 | | #endif |
87 | | |
88 | | #ifdef HAVE_RADIUS |
89 | | Radius *radiusAcc; |
90 | | #endif |
91 | | |
92 | | TimelineExtract *extract; |
93 | | PeriodicActivities *pa; /**< Instance of periodical activities. */ |
94 | | AddressResolution *address; |
95 | | Prefs *prefs; |
96 | | BlacklistStats blStats; |
97 | | Geolocation *geo; |
98 | | MacManufacturers *mac_manufacturers; |
99 | | void *trackers_automa; |
100 | | long time_offset; |
101 | | time_t start_time; /**< Time when start() was called */ |
102 | | time_t last_stats_reset; |
103 | | u_int32_t last_modified_static_file_epoch; |
104 | | int udp_socket; |
105 | | NtopPro *pro; |
106 | | DeviceProtocolBitmask deviceProtocolPresets[device_max_type]; |
107 | | cpu_load_stats cpu_stats; |
108 | | float cpu_load; |
109 | | bool can_send_icmp, privileges_dropped; |
110 | | #ifndef HAVE_NEDGE |
111 | | bool refresh_ips_rules; |
112 | | #endif |
113 | | FifoSerializerQueue *internal_alerts_queue; |
114 | | Recipients recipients; /* Handle notification recipients */ |
115 | | std::atomic<u_int32_t> num_flow_exporters; |
116 | | std::atomic<u_int32_t> num_flow_interfaces; |
117 | | #ifdef NTOPNG_PRO |
118 | | #ifdef HAVE_KAFKA |
119 | | KafkaClient kafkaClient; |
120 | | #endif |
121 | | MessageBroker *message_broker; |
122 | | #endif |
123 | | #ifdef HAVE_NEDGE |
124 | | std::vector<PacketForwarder*> multicastForwarders; |
125 | | #endif |
126 | | #ifdef HAVE_SNMP_TRAP |
127 | | SNMPTrap *trap_collector; |
128 | | #endif |
129 | | |
130 | | /* Local network address list */ |
131 | | char *local_network_names[CONST_MAX_NUM_NETWORKS]; |
132 | | char *local_network_aliases[CONST_MAX_NUM_NETWORKS]; |
133 | | AddressTree local_network_tree, cloud_local_network_tree; |
134 | | |
135 | | /* Local Autonomous Systems */ |
136 | | std::map<u_int32_t, bool> local_asn; |
137 | | |
138 | | /* Alerts */ |
139 | | FlowAlertsLoader flow_alerts_loader; |
140 | | |
141 | | /* Checks */ |
142 | | FlowChecksLoader *flow_checks_loader; |
143 | | HostChecksLoader *host_checks_loader; |
144 | | |
145 | | /* Hosts Control (e.g., disabled alerts) */ |
146 | | #ifdef NTOPNG_PRO |
147 | | bool alertExclusionsReloadInProgress; |
148 | | AlertExclusions *alert_exclusions, *alert_exclusions_shadow; |
149 | | #endif |
150 | | |
151 | | bool assignUserId(u_int8_t *new_user_id); |
152 | | |
153 | | #ifndef WIN32 |
154 | | ContinuousPing *cping; |
155 | | Ping *default_ping; |
156 | | bool ping_initialized; |
157 | | std::map<std::string /* ifname */, Ping *> ping; |
158 | | #endif |
159 | | |
160 | | /* For local network */ |
161 | | inline int32_t localNetworkLookup(int family, void *addr, |
162 | | u_int8_t *network_mask_bits = NULL); |
163 | | inline int32_t cloudNetworkLookup(int family, void *addr, |
164 | | u_int8_t *network_mask_bits = NULL); |
165 | | bool addLocalNetwork(char *_net); |
166 | | |
167 | | void loadLocalInterfaceAddress(); |
168 | | void initAllowedProtocolPresets(); |
169 | | |
170 | | void reloadASNPrefsOnInterfaces(); |
171 | | |
172 | | bool getUserPasswordHashLocal(const char *user, char *password_hash, |
173 | | u_int password_hash_len) const; |
174 | | bool checkLocalAuth(const char *user, const char *password, char *group) const; |
175 | | bool checkHTTPAuth(const char *user, const char *password, char *group) const; |
176 | | bool checkLDAPAuth(const char *user, const char *password, char *group) const; |
177 | | bool checkRadiusAuth(const char *user, const char *password, char *group) const; |
178 | | bool checkUserPassword(const char *user, const char *password, char *group, |
179 | | bool *localuser, bool *redirect_to_change_pwd) const; |
180 | | |
181 | | void checkReloadFlowChecks(); |
182 | | void checkReloadHostChecks(); |
183 | | void checkReloadAlertExclusions(); |
184 | | void checkReloadHostPools(); |
185 | | void setZoneInfo(); |
186 | | char* getPersistentCustomListName(char *name, u_int8_t *list_id /* out */); |
187 | | #ifdef NTOPNG_PRO |
188 | | void connectMessageBroker(); |
189 | | void reloadMessageBroker(); |
190 | | #endif |
191 | | bool downloadCustomnDPIProtos(char *url, char *dest_file); |
192 | | |
193 | | public: |
194 | | /** |
195 | | * @brief A Constructor |
196 | | * @details Creating a new Ntop. |
197 | | * |
198 | | * @param appName Describe the application name. |
199 | | * @return A new instance of Ntop. |
200 | | */ |
201 | | Ntop(const char *appName); |
202 | | /** |
203 | | * @brief A Destructor. |
204 | | * |
205 | | */ |
206 | | ~Ntop(); |
207 | | /** |
208 | | * @brief Register the ntopng preferences. |
209 | | * @details Setting the ntopng preferences defined in a Prefs instance. |
210 | | * |
211 | | * @param _prefs Prefs instance containing the ntopng preferences. |
212 | | * @param quick_registration Set it to true to do a limited initialization |
213 | | */ |
214 | | void registerPrefs(Prefs *_prefs, bool quick_registration); |
215 | | |
216 | | /** |
217 | | * @brief Register an ntopng log file |
218 | | * @details Log file is used under windows and in daemon mode |
219 | | * |
220 | | * @param logFile A valid path to a log file |
221 | | */ |
222 | 0 | inline void registerLogFile(const char *logFile) { |
223 | 0 | getTrace()->set_log_file(logFile); |
224 | 0 | }; |
225 | 0 | inline void rotateLogs(bool mode) { getTrace()->rotate_logs(mode); }; |
226 | | |
227 | | /** |
228 | | * @brief Set the path of custom nDPI protocols file. |
229 | | * @details Set the path of protos.txt containing the defined custom |
230 | | * protocols. For more information please read the nDPI quick start (cd ntopng |
231 | | * source code directory/nDPI/doc/). |
232 | | * |
233 | | * @param path Path of protos.file. |
234 | | */ |
235 | | void setCustomnDPIProtos(char *path); |
236 | | /** |
237 | | * @brief Get the custom nDPI protocols. |
238 | | * @details Inline function. |
239 | | * |
240 | | * @return The path of custom nDPI protocols file. |
241 | | */ |
242 | | char *getCustomnDPIProtos(); |
243 | | /** |
244 | | * @brief Get the offset time. |
245 | | * @details .... |
246 | | * |
247 | | * @return The timezone offset. |
248 | | */ |
249 | 0 | inline long get_time_offset() { return (time_offset); }; |
250 | | /** |
251 | | * @brief Initialize the Timezone. |
252 | | * @details Use the localtime function to initialize the variable @ref |
253 | | * time_offset. |
254 | | * |
255 | | */ |
256 | | void initTimezone(); |
257 | | /** |
258 | | * @brief Get a valid path. |
259 | | * @details Processes the input path and return a valid path. |
260 | | * |
261 | | * @param path String path to validate. |
262 | | * @return A valid path. |
263 | | */ |
264 | | char *getValidPath(char *path); |
265 | | /** |
266 | | * @brief Load the @ref Geolocation module. |
267 | | * @details Initialize the variable @ref geo with the input directory. |
268 | | */ |
269 | | void loadGeolocation(); |
270 | | /** |
271 | | * @brief Load the @ref MacManufacturers module. |
272 | | * @details Initialize the variable @ref dir with the input directory. |
273 | | * |
274 | | * @param dir Path to database home directory. |
275 | | */ |
276 | | void loadMacManufacturers(char *dir); |
277 | | |
278 | 0 | inline void getMacManufacturer(const char *mac, lua_State *vm) { |
279 | 0 | u_int8_t mac_bytes[6]; |
280 | 0 | Utils::parseMac(mac_bytes, mac); |
281 | 0 | if (mac_manufacturers) |
282 | 0 | mac_manufacturers->getMacManufacturer(mac_bytes, vm); |
283 | 0 | else |
284 | 0 | lua_pushnil(vm); |
285 | 0 | } |
286 | | |
287 | | /** |
288 | | * @brief Set the local networks. |
289 | | * @details Set the local networks to @ref AddressResolution instance. |
290 | | * |
291 | | * @param nets String that defined the local network with this Format: |
292 | | * 131.114.21.0/24,10.0.0.0/255.0.0.0 . |
293 | | */ |
294 | | void setLocalNetworks(char *nets); |
295 | | |
296 | | /** |
297 | | * @brief Check if the ingress parameter is in the local networks. |
298 | | * @details Inline method. |
299 | | * |
300 | | * @param family Internetwork: UDP, TCP, etc. |
301 | | * @param addr Internet Address. |
302 | | * @param network_id It returns the networkId to which the host belongs to |
303 | | * @param network_mask_bits It returns the number of bits of the network mask |
304 | | * @return True if the address is in the local networks, false otherwise. |
305 | | */ |
306 | | bool isLocalAddress(int family, void *addr, int32_t *network_id, |
307 | | u_int8_t *network_mask_bits = NULL); |
308 | | |
309 | | /** |
310 | | * @brief Return true is broadcast addresses are disabled (point-to-point). |
311 | | */ |
312 | 0 | bool isBroadcastIPDisabled() { return broadcast_ip_disabled; }; |
313 | 0 | void disableBroadcastIP() { broadcast_ip_disabled = true; }; |
314 | | |
315 | | /** |
316 | | * @brief Start ntopng packet processing. |
317 | | */ |
318 | | void start(); |
319 | | |
320 | | /** |
321 | | * @brief Resolve the host name. |
322 | | * @details Use the redis database to resolve the IP address and get the host |
323 | | * name. |
324 | | * |
325 | | * @param numeric_ip Address IP. |
326 | | * @param symbolic Symbolic name. |
327 | | * @param symbolic_len Length of symbolic name. |
328 | | */ |
329 | | inline void resolveHostName(const char *numeric_ip, char *symbolic, |
330 | 0 | u_int symbolic_len) { |
331 | 0 | address->resolveHostName(numeric_ip, symbolic, symbolic_len); |
332 | 0 | } |
333 | | |
334 | 0 | inline bool resolveHost(const char *host, char *rsp, u_int rsp_len, bool v4) { |
335 | 0 | return address->resolveHost(host, rsp, rsp_len, v4); |
336 | 0 | } |
337 | | |
338 | | /** |
339 | | * @brief Get the geolocation instance. |
340 | | * |
341 | | * @return Current geolocation instance. |
342 | | */ |
343 | 134k | inline Geolocation *getGeolocation() { return (geo); }; |
344 | | /** |
345 | | * @brief Get the mac manufacturers instance. |
346 | | * |
347 | | * @return Current mac manufacturers instance. |
348 | | */ |
349 | 19.8k | inline MacManufacturers *getMacManufacturers() { |
350 | 19.8k | return (mac_manufacturers); |
351 | 19.8k | }; |
352 | | /** |
353 | | * @brief Get the ifName. |
354 | | * @details Find the ifName by id parameter. |
355 | | * |
356 | | * @param id Index of ifName. |
357 | | * @return .... |
358 | | */ |
359 | 0 | inline char *get_if_name(int id) { return (prefs->get_if_name(id)); }; |
360 | 0 | inline const char *get_if_descr(int id) { return (prefs->get_if_descr(id)); }; |
361 | 0 | inline char *get_data_dir() { return (prefs->get_data_dir()); }; |
362 | 0 | inline const char *get_callbacks_dir() { |
363 | 0 | return (prefs->get_callbacks_dir()); |
364 | 0 | }; |
365 | | #ifdef NTOPNG_PRO |
366 | | inline const char *get_pro_callbacks_dir() { |
367 | | return (prefs->get_pro_callbacks_dir()); |
368 | | }; |
369 | | #endif |
370 | | /** |
371 | | * @brief Get the current httpdocs directory. |
372 | | * |
373 | | * @return The absolute path of the httpdocs directory. |
374 | | */ |
375 | 4 | inline const char *get_docs_dir() { return (prefs->get_docs_dir()); }; |
376 | | |
377 | | /** |
378 | | * @brief Register the network interface. |
379 | | * @details Check for duplicated interface and add the network interface in to |
380 | | * @ref iface. |
381 | | * |
382 | | * @param i Network interface. |
383 | | * @return true on success, false otherwise |
384 | | */ |
385 | | bool registerInterface(NetworkInterface *i); |
386 | | |
387 | | /** |
388 | | * @brief Finalize the network interface initialization. |
389 | | * |
390 | | * @param i Network interface. |
391 | | */ |
392 | | void initInterface(NetworkInterface *i, bool disable_dump = false); |
393 | | |
394 | | /** |
395 | | * @brief Get the number of defined network interfaces. |
396 | | * |
397 | | * @return Number of defined network interfaces. |
398 | | */ |
399 | 0 | inline u_int8_t get_num_interfaces() { return (num_defined_interfaces); } |
400 | | |
401 | | /** |
402 | | * @brief Get the Id of network interface. |
403 | | * @details This method accepts both interface names or Ids. |
404 | | * |
405 | | * @param name Name of network interface. |
406 | | * @return The network interface Id if exists, -1 otherwise. |
407 | | */ |
408 | | int getInterfaceIdByName(lua_State *vm, const char *name); |
409 | | |
410 | | /** |
411 | | * @brief Get the network interface with the specified Id |
412 | | * |
413 | | * @param if_id Id of network interface. |
414 | | * @return Pointer to the network interface, NULL otherwise. |
415 | | */ |
416 | | NetworkInterface *getInterfaceById(int if_id); |
417 | | |
418 | | /** |
419 | | * @brief Get the network interface at the specified position |
420 | | * |
421 | | * @param id Position of network interface. |
422 | | * @return Pointer to the network interface, NULL otherwise. |
423 | | */ |
424 | 0 | inline NetworkInterface *getInterfaceAtId(u_int8_t id) { |
425 | 0 | return ((id < num_defined_interfaces) ? iface[id] : NULL); |
426 | 0 | } |
427 | | |
428 | | /** |
429 | | * @brief Register the HTTP server. |
430 | | * |
431 | | * @param h HTTP server instance. |
432 | | */ |
433 | 0 | inline void registerHTTPserver(HTTPserver *h) { httpd = h; }; |
434 | | |
435 | | /** |
436 | | * @brief Get the network interface identified by name or Id. |
437 | | * @details This method accepts both interface names or Ids. |
438 | | * This method shall be called from Lua-mapped methods |
439 | | * especially where constraints on user allowed interfaces |
440 | | * must be enforced. |
441 | | * @param name Names or Id of network interface. |
442 | | * @return The network interface instance if exists, NULL otherwise. |
443 | | */ |
444 | | NetworkInterface *getNetworkInterface(const char *name, lua_State *vm = NULL); |
445 | | |
446 | 0 | inline NetworkInterface *getNetworkInterface(lua_State *vm, int ifid) { |
447 | 0 | char ifname[MAX_INTERFACE_NAME_LEN]; |
448 | | |
449 | 0 | snprintf(ifname, sizeof(ifname), "%d", ifid); |
450 | 0 | return getNetworkInterface(ifname, vm /* enforce the check on the allowed interface */); |
451 | 0 | }; |
452 | | |
453 | | bool viewHasZMQInterface(NetworkInterface *viewInterface); |
454 | | |
455 | | /** |
456 | | * @brief Get the current HTTPserver instance. |
457 | | * |
458 | | * @return The current instance of HTTP server. |
459 | | */ |
460 | 0 | inline HTTPserver *get_HTTPserver() { return (httpd); }; |
461 | | |
462 | 0 | inline const char *get_bin_dir() { return (CONST_BIN_DIR); }; |
463 | | |
464 | | /** |
465 | | * @brief Get the current working directory. |
466 | | * |
467 | | * @return The absolute path of working directory. |
468 | | */ |
469 | 18 | inline char *get_working_dir() { return (working_dir); }; |
470 | | |
471 | | /** |
472 | | * @brief Get the installation path of ntopng. |
473 | | * |
474 | | * @return The path of installed directory. |
475 | | */ |
476 | 2 | inline char *get_install_dir() { return (install_dir); }; |
477 | 2 | inline void set_install_dir(char *id) { |
478 | 2 | snprintf(install_dir, MAX_PATH, "%s", id); |
479 | 2 | }; |
480 | | |
481 | 0 | inline char *get_scripts_dir() { return (scripts_dir); }; |
482 | 4.42k | inline Bloom *getResolutionBloom() { return (resolvedHostsBloom); }; |
483 | 504k | inline NtopGlobals *getGlobals() { return (globals); }; |
484 | 22.9k | inline Trace *getTrace() { |
485 | 22.9k | return ((globals != NULL) ? globals->getTrace() : NULL); |
486 | 22.9k | }; |
487 | 26.3k | inline Redis *getRedis() { return (redis); }; |
488 | 0 | inline TimelineExtract *getTimelineExtract() { return (extract); }; |
489 | | |
490 | | #ifdef HAVE_ZMQ |
491 | | #ifndef HAVE_NEDGE |
492 | 5.58k | inline ExportInterface *get_export_interface() { return (export_interface); }; |
493 | | #endif |
494 | | #endif |
495 | | |
496 | 1.38M | inline Prefs *getPrefs() { return (prefs); }; |
497 | | void initPing(); |
498 | | #ifndef WIN32 |
499 | 0 | inline bool isPingInitialized() { return (ping_initialized);}; |
500 | | void lockNtopInstance(); |
501 | | #endif |
502 | | #ifdef NTOPNG_PRO |
503 | | #ifdef WIN32 |
504 | | char *getIfName(int if_id, char *name, u_int name_len); |
505 | | #endif |
506 | | #endif |
507 | | void setScriptsDir(); |
508 | | void lua_periodic_activities_stats(NetworkInterface *iface, lua_State *vm); |
509 | | void getUsers(lua_State *vm); |
510 | | bool getLocalNetworkAlias(lua_State *vm, u_int32_t network_id); |
511 | | bool isUserAdministrator(lua_State *vm); |
512 | | void getAllowedInterface(lua_State *vm); |
513 | | void getAllowedNetworks(lua_State *vm); |
514 | | bool getInterfaceAllowed(lua_State *vm, char *ifname) const; |
515 | | bool isInterfaceAllowed(lua_State *vm, const char *ifname) const; |
516 | | bool isInterfaceAllowed(lua_State *vm, int ifid) const; |
517 | | bool isPcapDownloadAllowed(lua_State *vm, const char *ifname); |
518 | | char *preparePcapDownloadFilter(lua_State *vm, char *filter); |
519 | | bool isLocalAuthEnabled() const; |
520 | | bool isLocalUser(lua_State *vm); |
521 | | bool checkCaptiveUserPassword(const char *user, const char *password, |
522 | | char *group) const; |
523 | | bool checkGuiUserPassword(struct mg_connection *conn, const char *user, |
524 | | const char *password, char *group, |
525 | | bool *localuser, bool *redirect_to_change_pwd) const; |
526 | | bool isBlacklistedLogin(struct mg_connection *conn) const; |
527 | | bool checkUserInterfaces(const char *user) const; |
528 | | bool resetUserPassword(char *username, char *old_password, |
529 | | char *new_password); |
530 | | bool mustChangePassword(const char *user); |
531 | | bool changeUserFullName(const char *username, const char *full_name) const; |
532 | | bool changeUserRole(char *username, char *user_role) const; |
533 | | bool changeAllowedNets(char *username, char *allowed_nets) const; |
534 | | bool changeAllowedIfname(char *username, char *allowed_ifname) const; |
535 | | bool changeUserHostPool(const char *username, const char *host_pool_id) const; |
536 | | bool changeUserLanguage(const char *username, const char *language) const; |
537 | | bool changeUserPcapDownloadPermission(const char *username, |
538 | | bool allow_pcap_download, |
539 | | u_int32_t ttl = 0 /* Forever */) const; |
540 | | bool changeUserHistoricalFlowPermission( |
541 | | const char *username, bool allow_historical_flows, |
542 | | u_int32_t ttl = 0 /* Forever */) const; |
543 | | bool changeUserAlertsPermission(const char *username, bool allow_alerts, |
544 | | u_int32_t ttl = 0 /* Forever */) const; |
545 | | void resetUserPermissions(const char *user) const; |
546 | | bool hasCapability(lua_State *vm, UserCapabilities capability); |
547 | | bool getUserCapabilities(const char *username, bool *allow_pcap_download, |
548 | | bool *allow_historical_flows, |
549 | | bool *allow_alerts) const; |
550 | | bool existsUser(const char *username) const; |
551 | | bool addUser(char *username, char *full_name, char *password, char *host_role, |
552 | | char *allowed_networks, char *allowed_ifname, char *host_pool_id, |
553 | | char *language, bool allow_pcap_download, |
554 | | bool allow_historical_flows, bool allow_alerts); |
555 | | bool addUserAPIToken(const char *username, const char *api_token); |
556 | | bool isCaptivePortalUser(const char *username); |
557 | | bool deleteUser(char *username); |
558 | | bool getUserHostPool(char *username, u_int16_t *host_pool_id); |
559 | | bool getUserAllowedIfname(const char *username, char *buf, |
560 | | size_t buflen) const; |
561 | | bool getUserAPIToken(const char *username, char *buf, size_t buflen) const; |
562 | | void setWorkingDir(char *dir); |
563 | | void fixPath(char *str, bool replaceDots = true); |
564 | | void removeTrailingSlash(char *str); |
565 | | void daemonize(); |
566 | | void shutdownPeriodicActivities(); |
567 | | void shutdownInterfaces(); |
568 | | void shutdownAll(); |
569 | | void runHousekeepingTasks(); |
570 | | void runPeriodicHousekeepingTasks(); |
571 | | void runShutdownTasks(); |
572 | | void checkShutdownWhenDone(); |
573 | 30.6k | bool isLocalInterfaceAddress(int family, void *addr) { |
574 | 30.6k | return (local_interface_addresses.findAddress(family, addr) == -1 ? false |
575 | 30.6k | : true); |
576 | 30.6k | }; |
577 | | void getLocalNetworkIp(int32_t local_network_id, IpAddress **network_ip, |
578 | | u_int8_t *network_prefix); |
579 | | void addLocalNetworkList(const char *network); |
580 | | void createExportInterface(); |
581 | | void resetNetworkInterfaces(); |
582 | | void initElasticSearch(); |
583 | | |
584 | 0 | inline u_int32_t getStartTime() { return ((u_int32_t)start_time); } |
585 | 0 | inline char *getStartTimeString() { return (epoch_buf); } |
586 | 0 | inline u_int32_t getLastModifiedStaticFileEpoch() { |
587 | 0 | return (last_modified_static_file_epoch); |
588 | 0 | } |
589 | 0 | inline void setLastModifiedStaticFileEpoch(u_int32_t t) { |
590 | 0 | if (t > last_modified_static_file_epoch) |
591 | 0 | last_modified_static_file_epoch = t; |
592 | 0 | } |
593 | 0 | inline u_int32_t getUptime() { |
594 | 0 | return ((u_int32_t)((start_time > 0) ? (time(NULL) - start_time) : 0)); |
595 | 0 | } |
596 | 0 | inline int getUdpSock() { return (udp_socket); } |
597 | | #ifdef NTOPNG_PRO |
598 | | inline AlertExclusions *getAlertExclusions() { return alert_exclusions; } |
599 | | u_int32_t getMaxNumFlowExporters(); |
600 | | u_int32_t getMaxNumFlowExportersInterfaces(); |
601 | | #endif |
602 | 0 | u_int32_t getNumFlowExporters() { return num_flow_exporters; } |
603 | 0 | u_int32_t getNumFlowExportersInterfaces() { return num_flow_interfaces; } |
604 | | bool incNumFlowExporters(); |
605 | | bool incNumFlowExportersInterfaces(); |
606 | | void decNumFlowExporters(); |
607 | | void decNumFlowExportersInterfaces(); |
608 | | |
609 | 0 | inline u_int getNumCPUs() { return (num_cpus); } |
610 | 0 | inline void setNumCPUs(u_int num) { num_cpus = num; } |
611 | 0 | inline bool canSendICMP() { return (can_send_icmp); } |
612 | 0 | inline bool canSelectNetworkIfaceICMP() { |
613 | 0 | #ifdef __linux__ |
614 | 0 | return (can_send_icmp); |
615 | | #else |
616 | | return (false); |
617 | | #endif |
618 | 0 | } |
619 | | |
620 | 0 | inline NtopPro *getPro() { return ((NtopPro *)pro); }; |
621 | | |
622 | | void loadTrackers(); |
623 | | bool isATrackerHost(char *host); |
624 | | bool isExistingInterface(const char *name) const; |
625 | 0 | inline NetworkInterface *getFirstInterface() const { |
626 | 0 | return (iface ? iface[0] : NULL); |
627 | 0 | } |
628 | 0 | inline NetworkInterface *getInterface(int i) const { |
629 | 0 | return (((i < num_defined_interfaces) && iface[i]) ? iface[i] : NULL); |
630 | 0 | } |
631 | 8.92k | inline NetworkInterface *getSystemInterface() const { |
632 | 8.92k | return (system_interface); |
633 | 8.92k | } |
634 | | #ifdef HAVE_NEDGE |
635 | | void addToNotifiedInformativeCaptivePortal(u_int32_t client_ip); |
636 | | bool addIPToLRUMatches(u_int32_t client_ip, u_int16_t user_pool_id, |
637 | | char *label, char *ifname); |
638 | | #endif /* NTOPNG_PRO */ |
639 | | |
640 | 52 | DeviceProtocolBitmask *getDeviceAllowedProtocols(DeviceType t) { |
641 | 52 | return (&deviceProtocolPresets[t]); |
642 | 52 | } |
643 | | void refreshAllowedProtocolPresets(DeviceType t, bool client, lua_State *L, int index); |
644 | | DeviceProtoStatus getDeviceAllowedProtocolStatus(DeviceType dev_type, |
645 | | ndpi_protocol proto, |
646 | | u_int16_t pool_id, |
647 | | bool as_client); |
648 | | void refreshCPULoad(); |
649 | | bool getCPULoad(float *out); |
650 | 0 | inline FifoSerializerQueue *getInternalAlertsQueue() { |
651 | 0 | return (internal_alerts_queue); |
652 | 0 | } |
653 | | void lua_alert_queues_stats(lua_State *vm); |
654 | | bool recipients_are_empty(); |
655 | | bool recipients_enqueue(AlertFifoItem *notification); |
656 | | AlertLevel get_default_recipient_minimum_severity(); |
657 | | bool recipient_enqueue(u_int16_t recipient_id, |
658 | | const AlertFifoItem *const notification); |
659 | | AlertFifoItem *recipient_dequeue(u_int16_t recipient_id); |
660 | | void recipient_stats(u_int16_t recipient_id, lua_State *vm); |
661 | | time_t recipient_last_use(u_int16_t recipient_id); |
662 | | void inc_recipient_stats(u_int16_t recipient_id, u_int64_t delivered, u_int64_t filtered_out, u_int64_t delivery_failures); |
663 | | void recipient_delete(u_int16_t recipient_id); |
664 | | void recipient_register(u_int16_t recipient_id, AlertLevel minimum_severity, |
665 | | Bitmap128 enabled_categories, |
666 | | Bitmap4096 enabled_host_pools, |
667 | | Bitmap128 enabled_entities, |
668 | | Bitmap128 enabled_flow_alert_types, |
669 | | Bitmap128 enabled_host_alert_types, |
670 | | Bitmap128 enabled_other_alert_types, |
671 | | bool match_alert_id, |
672 | | bool skip_alerts); |
673 | | |
674 | | void sendNetworkInterfacesTermination(); |
675 | 89.7k | inline time_t getLastStatsReset() { return (last_stats_reset); } |
676 | | void resetStats(); |
677 | | |
678 | | struct ndpi_detection_module_struct *initnDPIStruct(); |
679 | | |
680 | | void checkReloadHostsBroadcastDomain(); |
681 | | |
682 | 0 | inline void reloadFlowChecks() { flowChecksReloadInProgress = true; }; |
683 | 0 | inline void reloadHostChecks() { hostChecksReloadInProgress = true; }; |
684 | 0 | inline void reloadAlertExclusions() { |
685 | | #ifdef NTOPNG_PRO |
686 | | alertExclusionsReloadInProgress = true; |
687 | | #endif |
688 | 0 | }; |
689 | 0 | inline void reloadHostPools() { hostPoolsReloadInProgress = true; }; |
690 | | |
691 | | void addToPool(char *host_or_mac, u_int16_t user_pool_id); |
692 | | |
693 | | char *getAlertJSON(FlowAlertType fat, Flow *f) const; |
694 | | ndpi_serializer *getAlertSerializer(FlowAlertType fat, Flow *f) const; |
695 | | |
696 | | #ifndef WIN32 |
697 | 0 | inline ContinuousPing *getContinuousPing() { return (cping); } |
698 | | Ping *getPing(char *ifname); |
699 | | #endif |
700 | | |
701 | | #ifdef HAVE_RADIUS |
702 | | inline Radius *getRadius() { return radiusAcc; }; |
703 | | inline void updateRadiusLoginInfo() { radiusAcc->updateLoginInfo(); }; |
704 | | inline bool radiusAuthenticate(const char *username, const char *password, |
705 | | bool *has_unprivileged_capabilities, |
706 | | bool *is_admin) { |
707 | | return radiusAcc->authenticate(username, password, has_unprivileged_capabilities, is_admin); |
708 | | }; |
709 | | inline bool radiusAccountingStart(RadiusTraffic *info) { |
710 | | return radiusAcc->startSession(info); |
711 | | }; |
712 | | inline bool radiusAccountingUpdate(RadiusTraffic *info) { |
713 | | return radiusAcc->updateSession(info); |
714 | | }; |
715 | | inline bool radiusAccountingStop(RadiusTraffic *info) { |
716 | | return radiusAcc->stopSession(info); |
717 | | }; |
718 | | #endif |
719 | | |
720 | 0 | inline bool hasDroppedPrivileges() { return (privileges_dropped); } |
721 | 0 | inline void setDroppedPrivileges() { privileges_dropped = true; } |
722 | | |
723 | | void getUserGroupLocal(const char *user, char *group) const; |
724 | 0 | bool existsUserLocal(const char *user) { |
725 | 0 | char val[64]; |
726 | 0 | return getUserPasswordHashLocal(user, val, sizeof(val)); |
727 | 0 | } |
728 | | |
729 | | u_int32_t getMaxNumLocalNetworks(); |
730 | | |
731 | | /* Local network address list methods */ |
732 | 73.9k | inline u_int32_t getNumLocalNetworks() { |
733 | 73.9k | return local_network_tree.getNumAddresses(); |
734 | 73.9k | }; |
735 | 4 | inline const char *getLocalNetworkName(int32_t local_network_id) { |
736 | 4 | return (((u_int32_t)local_network_id < local_network_tree.getNumAddresses()) |
737 | 4 | ? local_network_names[(u_int32_t)local_network_id] |
738 | 4 | : NULL); |
739 | 4 | }; |
740 | | |
741 | | u_int32_t getLocalNetworkId(const char *network_name); |
742 | | |
743 | 0 | void addLocalCloudAddress(char *str) { cloud_local_network_tree.addAddress(str); } |
744 | | |
745 | | // void getLocalAddresses(lua_State* vm) { |
746 | | // return(local_network_tree.getAddresses(vm)); }; |
747 | | |
748 | 0 | inline FlowChecksLoader *getFlowChecksLoader() { |
749 | 0 | return (flow_checks_loader); |
750 | 0 | } |
751 | 0 | inline HostChecksLoader *getHostChecksLoader() { |
752 | 0 | return (host_checks_loader); |
753 | 0 | } |
754 | 0 | inline u_int8_t getFlowAlertScore(FlowAlertTypeEnum alert_id) const { |
755 | 0 | return flow_alerts_loader.getAlertScore(alert_id); |
756 | 0 | }; |
757 | 0 | inline ndpi_risk_enum getFlowAlertRisk(FlowAlertTypeEnum alert_id) const { |
758 | 0 | return flow_alerts_loader.getAlertRisk(alert_id); |
759 | 0 | }; |
760 | 0 | inline const char *getRiskStr(ndpi_risk_enum risk_id) { |
761 | 0 | return (ndpi_risk2str(risk_id)); |
762 | 0 | }; |
763 | | bool luaFlowCheckInfo(lua_State *vm, std::string check_name) const; |
764 | | bool luaHostCheckInfo(lua_State *vm, std::string check_name) const; |
765 | 0 | inline ndpi_risk getUnhandledRisks() const { |
766 | 0 | return flow_checks_loader ? flow_checks_loader->getUnhandledRisks() : 0; |
767 | 0 | }; |
768 | | #ifndef HAVE_NEDGE |
769 | | bool initPublisher(); |
770 | | bool broadcastControlMessage(char *msg); |
771 | | bool broadcastIPSMessage(char *msg); |
772 | 0 | inline void askToRefreshIPSRules() { refresh_ips_rules = true; } |
773 | 0 | inline bool timeToRefreshIPSRules() { |
774 | 0 | bool rc = refresh_ips_rules; |
775 | 0 | refresh_ips_rules = false; |
776 | 0 | return (rc); |
777 | 0 | } |
778 | | #endif |
779 | | |
780 | | /* This offline mode is forced by the --offline option */ |
781 | 0 | inline bool isForcedOffline() { return forced_offline; } |
782 | 0 | inline void toggleForcedOffline(bool off) { forced_offline = off; } |
783 | | |
784 | | /* Used instead to check if ntopng is offline but without the --offline option |
785 | | */ |
786 | 0 | inline bool isOffline() { return offline; } |
787 | 0 | inline void toggleOffline(bool off) { offline = off; } |
788 | | |
789 | | void cleanShadownDPI(); |
790 | | bool initnDPIReload(); |
791 | | void finalizenDPIReload(); |
792 | | bool isnDPIReloadInProgress(); |
793 | | ndpi_protocol_category_t get_ndpi_proto_category(ndpi_protocol proto); |
794 | | ndpi_protocol_category_t get_ndpi_proto_category(u_int protoid); |
795 | | void setnDPIProtocolCategory(u_int16_t protoId, |
796 | | ndpi_protocol_category_t protoCategory); |
797 | | bool nDPILoadIPCategory(char *what, ndpi_protocol_category_t id, |
798 | | char *list_name); |
799 | | bool nDPILoadHostnameCategory(char *what, ndpi_protocol_category_t id, |
800 | | char *list_name); |
801 | | int nDPISetDomainMask(const char *domain, u_int64_t domain_mask); |
802 | | void setLastInterfacenDPIReload(time_t now); |
803 | | bool needsnDPICleanup(); |
804 | | void setnDPICleanupNeeded(bool needed); |
805 | | u_int16_t getnDPIProtoByName(const char *name); |
806 | | bool isDbCreated(); |
807 | | void collectResponses(lua_State *vm); |
808 | | void collectContinuousResponses(lua_State *vm); |
809 | 0 | inline char *getZoneInfo() { return (zoneinfo); } |
810 | | |
811 | | void speedtest(lua_State *vm); |
812 | | #if defined(NTOPNG_PRO) |
813 | | MessageBroker* getMessageBroker() { return(message_broker); }; |
814 | | #endif |
815 | | |
816 | | #if defined(NTOPNG_PRO) && defined(HAVE_CLICKHOUSE) |
817 | | void setFlowId(u_int64_t id) { flow_id = id; flow_id_initialized = true; } |
818 | | bool isFlowIdInitialized() { return flow_id_initialized; } |
819 | | u_int64_t getNextFlowId() { return (flow_id++); } |
820 | | #endif |
821 | | |
822 | 0 | inline char *getTZname() { return (myTZname); } |
823 | 0 | inline Mutex *get_pools_lock() { return (&pools_lock); }; |
824 | 0 | inline u_int32_t get_current_time() { return(current_time); }; |
825 | | |
826 | | bool createRuntimeInterface(char *name, char *source, int *iface_id); |
827 | | |
828 | | void incBlacklisHits(std::string listname); |
829 | | #if defined(NTOPNG_PRO) && defined(HAVE_KAFKA) |
830 | | inline bool sendKafkaMessage(char *kafka_broker_info, char *msg, |
831 | | u_int msg_len) { |
832 | | return (kafkaClient.sendMessage(kafka_broker_info, msg, msg_len)); |
833 | | } |
834 | | #endif |
835 | | u_int64_t getNumActiveProbes() const; |
836 | 0 | inline BlacklistStats* getBlacklistStats() { return(&blStats); } |
837 | 0 | inline void resetBlacklistStats() { blStats.reset(); } |
838 | 0 | inline JobQueue* getJobsQueue() { return(&jobsQueue); } |
839 | 0 | inline PeriodicActivities* getPeriodicActivities() { return(pa); } |
840 | | |
841 | 0 | void incNumLuaVMs() { num_active_lua_vms++; } |
842 | 0 | void decNumLuaVMs() { num_active_lua_vms--; } |
843 | 0 | inline u_int16_t getNumActiveLuaVMs() { return(num_active_lua_vms); } |
844 | | const char* getPersistentCustomListNameById(u_int8_t list_id); |
845 | | #ifdef HAVE_SNMP_TRAP |
846 | | void initSNMPTrapCollector(); |
847 | | void toggleSNMPTrapCollector(bool enable); |
848 | | #endif |
849 | | u_int16_t getNumberHostPools(); |
850 | | u_int32_t getNumberHostPoolsMembers(); |
851 | | u_int8_t getNumberProfiles(); |
852 | | bool isInLocalASN(IpAddress *ip); |
853 | | void reloadASNConfiguration(); |
854 | | |
855 | | void trackAssetChange(const char *protocol, const char *action, |
856 | | Mac *mac, IpAddress *target_ip, |
857 | | Host *target, Flow *flow, char *note); |
858 | | |
859 | | static const ndpi_protocol getConstNdpiUnknownProtocol(); |
860 | | |
861 | | std::string getLuaCache(std::string); |
862 | | void setLuaCache(std::string, std::string); |
863 | | void dumpLuaCache(lua_State *vm); |
864 | | }; |
865 | | |
866 | | extern Ntop *ntop; |
867 | | |
868 | | #ifdef NTOPNG_PRO |
869 | | #include "ntoppro_defines.h" |
870 | | #endif |
871 | | |
872 | | #endif /* _NTOP_CLASS_H_ */ |