1 | #ifndef MODULE_WEBIF_LIB_H_
|
---|
2 | #define MODULE_WEBIF_LIB_H_
|
---|
3 |
|
---|
4 | #ifdef WITH_SSL
|
---|
5 | #include <openssl/crypto.h>
|
---|
6 | #include <openssl/ssl.h>
|
---|
7 | #include <openssl/err.h>
|
---|
8 | #endif
|
---|
9 |
|
---|
10 | #include "cscrypt/md5.h"
|
---|
11 |
|
---|
12 | /* The server string in the http header */
|
---|
13 | #define SERVER "webserver/1.0"
|
---|
14 | /* The protocol that gets output. Currently only 1.0 is possible as 1.1 requires many features we don't have. */
|
---|
15 | #define PROTOCOL "HTTP/1.0"
|
---|
16 | /* The RFC1123 time format which is used in http headers. */
|
---|
17 | #define RFC1123FMT "%a, %d %b %Y %H:%M:%S GMT"
|
---|
18 | /* The realm for http digest authentication. Gets displayed to browser. */
|
---|
19 | #define AUTHREALM "Forbidden"
|
---|
20 | /* How long a nonce is valid in seconds after a first request with this nonce has been received. If the nonce isn't valid anymore, the browser gets a "stale=true" message and must resubmit with the current nonce. */
|
---|
21 | #define AUTHNONCEVALIDSECS 15
|
---|
22 | /* When a nonce gets expired after it has been first given to the client. */
|
---|
23 | #define AUTHNONCEEXPIRATION 120
|
---|
24 | /* The amount of hash buckets (based on opaque string) for better performance. */
|
---|
25 | #define AUTHNONCEHASHBUCKETS 4
|
---|
26 | /* The maximum amount of GET parameters the webserver will parse. */
|
---|
27 | #define MAXGETPARAMS 100
|
---|
28 | /* The refresh delay (in seconds) when stopping OSCam via http. */
|
---|
29 | #define SHUTDOWNREFRESH 30
|
---|
30 |
|
---|
31 | #define TOUCH_SUBDIR "touch/"
|
---|
32 |
|
---|
33 | struct s_connection
|
---|
34 | {
|
---|
35 | int32_t socket;
|
---|
36 | struct s_client *cl;
|
---|
37 | IN_ADDR_T remote;
|
---|
38 | #ifdef WITH_SSL
|
---|
39 | SSL *ssl;
|
---|
40 | #endif
|
---|
41 | };
|
---|
42 |
|
---|
43 | struct uriparams
|
---|
44 | {
|
---|
45 | int32_t paramcount;
|
---|
46 | char *params[MAXGETPARAMS];
|
---|
47 | char *values[MAXGETPARAMS];
|
---|
48 | };
|
---|
49 |
|
---|
50 | struct s_nonce
|
---|
51 | {
|
---|
52 | char nonce[(MD5_DIGEST_LENGTH * 2) + 1];
|
---|
53 | char opaque[(MD5_DIGEST_LENGTH * 2) + 1];
|
---|
54 | time_t expirationdate;
|
---|
55 | time_t firstuse;
|
---|
56 | struct s_nonce *next;
|
---|
57 | };
|
---|
58 |
|
---|
59 | // should be filled with informations for stats block
|
---|
60 | struct pstat
|
---|
61 | {
|
---|
62 | uint32_t info_procs; // running procs
|
---|
63 | int64_t utime_ticks;
|
---|
64 | int64_t cutime_ticks;
|
---|
65 | int64_t stime_ticks;
|
---|
66 | int64_t cstime_ticks;
|
---|
67 | int64_t cpu_total_time;
|
---|
68 | uint64_t vsize; // virtual memory size in bytes
|
---|
69 | uint64_t rss; // Resident Set Size in bytes
|
---|
70 | uint64_t mem_total; // Total Memory in bytes
|
---|
71 | uint64_t mem_free; // Free Memory in bytes
|
---|
72 | uint64_t mem_used; // Used Memory in bytes
|
---|
73 | uint64_t mem_buff; // Buffered Memory in bytes
|
---|
74 | uint64_t mem_cached; // Cached Memory in bytes
|
---|
75 | uint64_t mem_freem; // Buffered Memory in bytes
|
---|
76 | uint64_t mem_share; // Shared Memory in bytes
|
---|
77 | uint64_t mem_total_swap; // Total Swap Memory in bytes
|
---|
78 | uint64_t mem_free_swap; // Free Swap Memory in bytes
|
---|
79 | uint64_t mem_used_swap; // Used Swap Memory in bytes
|
---|
80 | float cpu_avg[3]; // CPU load from "load average"
|
---|
81 | struct timeb time_started; // needed for calculating time between function call
|
---|
82 | int64_t gone_refresh; // time difference between CPU usage calculations in sec
|
---|
83 | double cpu_usage_user; // user_CPU usage to display in %
|
---|
84 | double cpu_usage_sys; // sys_CPU usage to display in %
|
---|
85 | uint16_t check_available; // default is 0, if value x is not available,
|
---|
86 | // set corresponding bit to 1 --> module-webif.c / set_status_info()
|
---|
87 | };
|
---|
88 |
|
---|
89 | extern time_t parse_modifiedsince(char *value);
|
---|
90 | extern void calculate_opaque(IN_ADDR_T addr, char *opaque);
|
---|
91 | extern void init_noncelocks(void);
|
---|
92 | extern void calculate_nonce(char *nonce, char *result, char *opaque);
|
---|
93 | extern int32_t check_auth(char *authstring, char *method, char *path, IN_ADDR_T addr, char *expectednonce, char *opaque);
|
---|
94 | extern int32_t webif_write_raw(char *buf, FILE *f, int32_t len);
|
---|
95 | extern int32_t webif_write(char *buf, FILE *f);
|
---|
96 | extern int32_t webif_read(char *buf, int32_t num, FILE *f);
|
---|
97 | extern void send_headers(FILE *f, int32_t status, char *title, char *extra, char *mime, int32_t cache, int32_t length, char *content, int8_t forcePlain);
|
---|
98 | extern void send_error(FILE *f, int32_t status, char *title, char *extra, char *text, int8_t forcePlain);
|
---|
99 | extern void send_error500(FILE *f);
|
---|
100 | extern void send_header304(FILE *f, char *extraheader);
|
---|
101 | extern void send_file(FILE *f, char *filename, char *subdir, time_t modifiedheader, uint32_t etagheader, char *extraheader);
|
---|
102 | extern void urldecode(char *s);
|
---|
103 | extern void parseParams(struct uriparams *params, char *pch);
|
---|
104 | extern char *getParam(struct uriparams *params, char *name);
|
---|
105 | extern int32_t oscam_get_uptime(void);
|
---|
106 | extern int8_t get_stats_linux(const pid_t pid, struct pstat* result);
|
---|
107 | extern void calc_cpu_usage_pct(struct pstat* cur_usage, struct pstat* last_usage);
|
---|
108 |
|
---|
109 | #ifdef WITH_SSL
|
---|
110 | extern SSL *cur_ssl(void);
|
---|
111 | extern SSL_CTX *SSL_Webif_Init(void);
|
---|
112 | #endif
|
---|
113 |
|
---|
114 | #endif
|
---|