1 #ifndef MODULE_WEBIF_LIB_H_
2 #define MODULE_WEBIF_LIB_H_
5 #include <openssl/crypto.h>
6 #include <openssl/ssl.h>
7 #include <openssl/err.h>
10 #include "cscrypt/md5.h"
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 150
28 /* The refresh delay (in seconds) when stopping OSCam via http. */
29 #define SHUTDOWNREFRESH 30
44 char *params
[MAXGETPARAMS
];
45 char *values
[MAXGETPARAMS
];
50 char nonce
[(MD5_DIGEST_LENGTH
* 2) + 1];
51 char opaque
[(MD5_DIGEST_LENGTH
* 2) + 1];
52 time_t expirationdate
;
57 // should be filled with informations for stats block
60 uint32_t info_procs
; // running procs
65 int64_t cpu_total_time
;
66 uint64_t vsize
; // virtual memory size in bytes
67 uint64_t rss
; // Resident Set Size in bytes
68 uint64_t mem_total
; // Total Memory in bytes
69 uint64_t mem_free
; // Free Memory in bytes
70 uint64_t mem_used
; // Used Memory in bytes
71 uint64_t mem_buff
; // Buffered Memory in bytes
72 uint64_t mem_cached
; // Cached Memory in bytes
73 uint64_t mem_freem
; // Buffered Memory in bytes
74 uint64_t mem_share
; // Shared Memory in bytes
75 uint64_t mem_total_swap
; // Total Swap Memory in bytes
76 uint64_t mem_free_swap
; // Free Swap Memory in bytes
77 uint64_t mem_used_swap
; // Used Swap Memory in bytes
78 float cpu_avg
[3]; // CPU load from "load average"
79 struct timeb time_started
; // needed for calculating time between function call
80 int64_t gone_refresh
; // time difference between CPU usage calculations in sec
81 double cpu_usage_user
; // user_CPU usage to display in %
82 double cpu_usage_sys
; // sys_CPU usage to display in %
83 uint16_t check_available
; // default is 0, if value x is not available,
84 // set corresponding bit to 1 --> module-webif.c / set_status_info()
87 extern time_t parse_modifiedsince(char *value
);
88 extern void calculate_opaque(IN_ADDR_T addr
, char *opaque
);
89 extern void init_noncelocks(void);
90 extern void calculate_nonce(char *nonce
, char *result
, char *opaque
);
91 extern int32_t check_auth(char *authstring
, char *method
, char *path
, IN_ADDR_T addr
, char *expectednonce
, char *opaque
);
92 extern int32_t webif_write_raw(char *buf
, FILE *f
, int32_t len
);
93 extern int32_t webif_write(char *buf
, FILE *f
);
94 extern int32_t webif_read(char *buf
, int32_t num
, FILE *f
);
95 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
);
96 extern void send_error(FILE *f
, int32_t status
, char *title
, char *extra
, char *text
, int8_t forcePlain
);
97 extern void send_error500(FILE *f
);
98 extern void send_header304(FILE *f
, char *extraheader
);
99 extern void send_file(FILE *f
, char *filename
, char *subdir
, time_t modifiedheader
, uint32_t etagheader
, char *extraheader
);
100 extern void urldecode(char *s
);
101 extern void parseParams(struct uriparams
*params
, char *pch
);
102 extern char *getParam(struct uriparams
*params
, char *name
);
103 extern int32_t oscam_get_uptime(void);
104 extern int8_t get_stats_linux(const pid_t pid
, struct pstat
* result
);
105 extern void calc_cpu_usage_pct(struct pstat
* cur_usage
, struct pstat
* last_usage
);
108 extern SSL
*cur_ssl(void);
109 extern SSL_CTX
*SSL_Webif_Init(void);