/src/ntopng/include/HTTPserver.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * |
3 | | * (C) 2013-24 - 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 _HTTP_SERVER_H_ |
23 | | #define _HTTP_SERVER_H_ |
24 | | |
25 | | #include "ntop_includes.h" |
26 | | |
27 | | /* Global used for enabling/disabling user authentication */ |
28 | | extern bool enable_users_login; |
29 | | |
30 | | class HTTPserver { |
31 | | private: |
32 | | bool use_http, can_accept_requests; |
33 | | char *docs_dir, *scripts_dir; |
34 | | struct mg_context *httpd_v4; |
35 | | bool ssl_enabled, gui_access_restricted; |
36 | | char *wispr_captive_data; |
37 | | bool check_ssl_cert(char *ssl_cert_path, size_t ssl_cert_path_len); |
38 | | char ports[256], acl_management[256], ssl_cert_path[2 * MAX_PATH], |
39 | | access_log_path[2 * MAX_PATH]; |
40 | | const char *http_binding_addr1, *http_binding_addr2; |
41 | | const char *https_binding_addr1, *https_binding_addr2; |
42 | | const char *http_options[32]; |
43 | | int cur_http_options; |
44 | | |
45 | | void addHTTPOption(const char *k, const char *v); |
46 | | void startHttpServer(); |
47 | | |
48 | | static void parseACL(char *const acl, u_int acl_len); |
49 | | #ifdef HAVE_NEDGE |
50 | | char *captive_redirect_addr; |
51 | | struct mg_context *httpd_captive_v4; |
52 | | #endif |
53 | | |
54 | | public: |
55 | | HTTPserver(const char *_docs_dir, const char *_scripts_dir); |
56 | | ~HTTPserver(); |
57 | | |
58 | | bool valid_user_pwd(char *user, char *pass); |
59 | | static bool authorized_localhost_user_login(const struct mg_connection *conn); |
60 | | static void traceLogin(const char *user, bool authorized); |
61 | | |
62 | | bool authorize_noconn(char *username, char *session_id, u_int session_id_size, |
63 | | u_int session_duration); |
64 | | /* |
65 | | Creates an REST API token for user identified with `username` |
66 | | */ |
67 | | bool create_api_token(const char *username, char *api_token, |
68 | | u_int api_token_size); |
69 | | |
70 | 0 | inline char *get_docs_dir() { return (docs_dir); }; |
71 | 0 | inline char *get_scripts_dir() { return (scripts_dir); }; |
72 | 0 | inline bool is_ssl_enabled() { return (ssl_enabled); }; |
73 | 0 | inline bool is_gui_access_restricted() { return (gui_access_restricted); }; |
74 | 0 | inline void start_accepting_requests() { can_accept_requests = true; }; |
75 | | bool accepts_requests(); |
76 | | |
77 | | #ifdef HAVE_NEDGE |
78 | | void addCaptiveRedirectAddress(const char *addr); |
79 | | inline const char *getCaptiveRedirectAddress() { |
80 | | return (captive_redirect_addr ? captive_redirect_addr : ""); |
81 | | } |
82 | | const char *getCaptiveLoginAddress(char *buf, int buf_size, const char *ip, |
83 | | bool *custom_url); |
84 | | const char *getWisprCaptiveData(char *buf, int buf_size, const char *addr); |
85 | | void startCaptiveServer(); |
86 | | void stopCaptiveServer(); |
87 | | #endif |
88 | | }; |
89 | | |
90 | | extern int send_error(struct mg_connection *conn, int status, |
91 | | const char *reason, const char *fmt, ...); |
92 | | extern int redirect_to_error_page(struct mg_connection *conn, |
93 | | const struct mg_request_info *request_info, |
94 | | const char *i18n_message, char *script_path, |
95 | | char *error_message); |
96 | | |
97 | | const char *get_secure_cookie_attributes( |
98 | | const struct mg_request_info *request_info); |
99 | | |
100 | | /* mongoose */ |
101 | | extern int url_decode(const char *src, int src_len, char *dst, int dst_len, |
102 | | int is_form_url_encoded); |
103 | | |
104 | | #endif /* _HTTP_SERVER_H_ */ |