Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 524 lines (465 sloc) 14.115 kb
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
1 #include "globals.h"
2 #include <syslog.h>
4ce2f50 cccam: Bugfix cccam-client (card-reporting)/signal 11
schlocke authored
3 #include <stdlib.h>
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
4 #include "module-datastruct-llist.h"
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
5
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
6 char *LOG_LIST = "log_list";
7
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
8 static FILE *fp=(FILE *)0;
9 static FILE *fps=(FILE *)0;
10 #ifdef CS_ANTICASC
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
11 static FILE *fpa=(FILE *)0;
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
12 #endif
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
13 static int8_t logStarted = 0;
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
14 static LLIST *log_list;
15
16 struct s_log {
17 char *txt;
18 int8_t header_len;
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
19 int8_t direct_log;
8b26202 fixed user-log
corsair authored
20 struct s_client *cl;
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
21 };
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
22
23 CS_MUTEX_LOCK loghistory_lock;
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
24
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
25 #define LOG_BUF_SIZE 512
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
26
d474ded I noticed that monitor encryption is not working on 64bit plattforms …
Admin authored
27 static void switch_log(char* file, FILE **f, int32_t (*pfinit)(void))
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
28 {
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
29 if(cfg.max_log_size) //only 1 thread needs to switch the log; even if anticasc, statistics and normal log are running
292b129 remove cs_debug_nolf (not threadsafe) and fix some debug messages
_network authored
30 //at the same time, it is ok to have the other logs switching 1 entry later
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
31 {
f39180f fixed logging on some platforms
corsair authored
32 if(*f != NULL && ftell(*f) >= cfg.max_log_size*1024) {
d474ded I noticed that monitor encryption is not working on 64bit plattforms …
Admin authored
33 int32_t rc;
fc91df8 Introducing cs_malloc/cs_realloc functions so that it's easier to log…
Admin authored
34 char prev_log[strlen(file) + 6];
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
35 snprintf(prev_log, sizeof(prev_log), "%s-prev", file);
36 fprintf(*f, "switch log file\n");
37 fflush(*f);
38 fclose(*f);
39 *f = (FILE *)0;
40 rc = rename(file, prev_log);
41 if( rc!=0 ) {
42 fprintf(stderr, "rename(%s, %s) failed (errno=%d %s)\n", file, prev_log, errno, strerror(errno));
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
43 }
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
44 else
45 if( pfinit()){
46 fprintf(stderr, "Initialisation of log file failed, continuing without logging thread %8X. Log will be output to stdout!", (unsigned int)pthread_self());
47 cfg.logtostdout = 1;
48 }
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
49 }
50 }
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
51 }
52
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
53 static void cs_write_log(char *txt, int8_t do_flush)
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
54 {
7a573b7 remove anticascader thread
zetack authored
55 // filter out entries with leading 's' and forward to statistics
56 if(txt[0] == 's') {
57 if (fps) {
58 switch_log(cfg.usrfile, &fps, cs_init_statistics);
0049b77 fix writing of statistics to main log on oscam exit
_network authored
59 if (fps) {
7a573b7 remove anticascader thread
zetack authored
60 fputs(txt + 1, fps); // remove the leading 's' and write to file
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
61 if (do_flush) fflush(fps);
0049b77 fix writing of statistics to main log on oscam exit
_network authored
62 }
7a573b7 remove anticascader thread
zetack authored
63 }
64 } else {
65 if(!cfg.disablelog){
66 if (fp){
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
67 switch_log(cfg.logfile, &fp, cs_open_logfiles); // only call the switch code if lock = 1 is specified as otherwise we are calling it internally
7a573b7 remove anticascader thread
zetack authored
68 if (fp) {
69 fputs(txt, fp);
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
70 if (do_flush) fflush(fp);
69e7e3d Allow to log parallel to syslog, stdout and one file (example: logfil…
Admin authored
71 }
7a573b7 remove anticascader thread
zetack authored
72 }
73 if(cfg.logtostdout){
74 fputs(txt+11, stdout);
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
75 if (do_flush) fflush(stdout);
a86e79f Merge Webinterface into Trunk - Use -DWEBIF=1 with cmake to build wit…
merek authored
76 }
77 }
7a573b7 remove anticascader thread
zetack authored
78 }
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
79 }
80
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
81 static void cs_write_log_int(char *txt)
82 {
83 struct s_log * log = cs_malloc(&log, sizeof(struct s_log), 0);
84 log->txt = strnew(txt);
85 log->header_len = 0;
86 log->direct_log = 1;
87 ll_append(log_list, log);
88 }
89
d474ded I noticed that monitor encryption is not working on 64bit plattforms …
Admin authored
90 int32_t cs_open_logfiles()
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
91 {
a55a732 Correctly handle maxlogsize = 10 as default value. Improve message on…
Admin authored
92 char *starttext;
93 if(logStarted) starttext = "log switched";
94 else starttext = "started";
f8c3b19 All files: make cfg static for easier valgrind analysis
dingo35 authored
95 if (!fp && cfg.logfile != NULL) { //log to file
96 if ((fp = fopen(cfg.logfile, "a+")) <= (FILE *)0) {
69e7e3d Allow to log parallel to syslog, stdout and one file (example: logfil…
Admin authored
97 fp = (FILE *)0;
034523f Add speaking error messages using strerror() to all errors containing…
Admin authored
98 fprintf(stderr, "couldn't open logfile: %s (errno %d %s)\n", cfg.logfile, errno, strerror(errno));
69e7e3d Allow to log parallel to syslog, stdout and one file (example: logfil…
Admin authored
99 } else {
100 time_t t;
101 char line[80];
102 memset(line, '-', sizeof(line));
103 line[(sizeof(line)/sizeof(char)) - 1] = '\0';
104 time(&t);
24352c8 Prevent future usage of some non-threadsafe functions and remove thei…
Admin authored
105 if (!cfg.disablelog){
106 char buf[28];
cf6ae10 Replace some functions by internal ones as some platforms strip them …
Admin authored
107 cs_ctime_r(&t, buf);
24352c8 Prevent future usage of some non-threadsafe functions and remove thei…
Admin authored
108 fprintf(fp, "\n%s\n>> OSCam << cardserver %s at %s%s\n", line, starttext, buf, line);
109 }
a86e79f Merge Webinterface into Trunk - Use -DWEBIF=1 with cmake to build wit…
merek authored
110 }
69e7e3d Allow to log parallel to syslog, stdout and one file (example: logfil…
Admin authored
111 }
6ec82a2 WebIf: Add wiki links in user section. Small change in oscam-log rega…
Admin authored
112 // according to syslog docu: calling closelog is not necessary and calling openlog multiple times is safe
113 // We use openlog to set the default syslog settings so that it's possible to allow switching syslog on and off
114 openlog("oscam", LOG_NDELAY, LOG_DAEMON);
115
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
116 cs_log_nolock(">> OSCam << cardserver %s, version " CS_VERSION ", build #" CS_SVN_VERSION " (" CS_OSTYPE ")", starttext);
69e7e3d Allow to log parallel to syslog, stdout and one file (example: logfil…
Admin authored
117 cs_log_config();
118 return(fp <= (FILE *)0);
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
119 }
120
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
121 #ifdef CS_ANTICASC
122 int32_t ac_init_log(void){
a1ad9eb WebIf: Make refresh mechanism more subtle
Admin authored
123 FILE *tmp = fpa;
124 fpa=(FILE *)0;
125 if(tmp)
7a573b7 remove anticascader thread
zetack authored
126 fclose(tmp);
a1ad9eb WebIf: Make refresh mechanism more subtle
Admin authored
127
7a573b7 remove anticascader thread
zetack authored
128 if(cfg.ac_logfile[0]) {
129 if( (fpa=fopen(cfg.ac_logfile, "a+"))<=(FILE *)0 ) {
130 fpa=(FILE *)0;
131 fprintf(stderr, "can't open anti-cascading logfile: %s\n", cfg.ac_logfile);
132 } else
133 cs_log("anti-cascading log initialized");
134 }
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
135
7a573b7 remove anticascader thread
zetack authored
136 return(fpa<=(FILE *)0);
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
137 }
138 #endif
139
8504d47 Fix segfault when changing loghistsize. Note that the log is not pres…
Admin authored
140 /*
141 This function allows to reinit the in-memory loghistory with a new size.
142 */
143 void cs_reinit_loghist(uint32_t size)
144 {
145 char *tmp, *tmp2;
146 if(size != cfg.loghistorysize){
147 if(cs_malloc(&tmp, size, -1)){
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
148 cs_writelock(&loghistory_lock);
8504d47 Fix segfault when changing loghistsize. Note that the log is not pres…
Admin authored
149 tmp2 = loghist;
150 // On shrinking, the log is not copied and the order is reversed
151 if(size < cfg.loghistorysize){
152 cfg.loghistorysize = size;
153 cs_sleepms(20); // Monitor or webif may be currently outputting the loghistory but don't use locking so we sleep a bit...
154 loghistptr = tmp;
155 loghist = tmp;
156 } else {
157 if(loghist){
158 memcpy(tmp, loghist, cfg.loghistorysize);
159 loghistptr = tmp + (loghistptr - loghist);
160 } else loghistptr = tmp;
161 loghist = tmp;
162 cs_sleepms(20); // Monitor or webif may be currently outputting the loghistory but don't use locking so we sleep a bit...
163 cfg.loghistorysize = size;
164 }
aec17c3 Add locking mechanism from r5437 to more places. Add stronger locking…
Admin authored
165 cs_writeunlock(&loghistory_lock);
022c82f Fix memleak
Admin authored
166 if(tmp2 != NULL) add_garbage(tmp2);
8504d47 Fix segfault when changing loghistsize. Note that the log is not pres…
Admin authored
167 }
168 }
169 }
170
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
171 static int32_t get_log_header(int32_t m, char *txt)
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
172 {
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
173 struct s_client *cl = cur_client();
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
174 time_t t;
175 struct tm lt;
176 int32_t pos;
177
178 time(&t);
179 localtime_r(&t, &lt);
180
72bcc0f little change log format, compatibility with fail2ban
lightman33 authored
181 pos = snprintf(txt, LOG_BUF_SIZE, "[LOG000]%4d/%02d/%02d %02d:%02d:%02d ", lt.tm_year+1900, lt.tm_mon+1, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec);
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
182
89542bf oscma-log.c Further simplify code and make output uniform for 'm' lin…
dingo35 authored
183 if(m)
42c5e8f Fix log segfault when there is no client.
Admin authored
184 return pos + snprintf(txt+pos, LOG_BUF_SIZE-pos, "%8X %c ", cl?cl->tid:0, cl?cl->typ:' ');
89542bf oscma-log.c Further simplify code and make output uniform for 'm' lin…
dingo35 authored
185 else
42c5e8f Fix log segfault when there is no client.
Admin authored
186 return pos + snprintf(txt+pos, LOG_BUF_SIZE-pos, "%8X%-3.3s ", cl?cl->tid:0, "");
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
187 }
188
8b26202 fixed user-log
corsair authored
189 static void write_to_log(char *txt, int8_t header_len, int8_t do_flush, struct s_client *cur_cl)
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
190 {
dea5bd0 killed reader restart now works! If you kill a reader by kill(pid, SI…
schlocke authored
191 char sbuf[16];
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
192
57e7e66 Fix compiler error if anticasc was not selected
merek authored
193 #ifdef CS_ANTICASC
7a573b7 remove anticascader thread
zetack authored
194 if (!strncmp(txt + header_len, "acasc:", 6)) {
195 strcat(txt, "\n");
196 switch_log(cfg.ac_logfile, &fpa, ac_init_log);
197 if (fpa) {
198 fputs(txt + 8, fpa);
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
199 if (do_flush) fflush(fpa);
7a573b7 remove anticascader thread
zetack authored
200 }
201 } else
57e7e66 Fix compiler error if anticasc was not selected
merek authored
202 #endif
7a573b7 remove anticascader thread
zetack authored
203 {
204 if (cfg.logtosyslog)
205 syslog(LOG_INFO, "%s", txt+24);
206 strcat(txt, "\n");
207 }
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
208 cs_write_log(txt + 8, do_flush);
9a4c19c WebIf: add some classes to tables to have more possibilities for skin…
alno authored
209
7701379 size of loghistory buffer can now be set in configuration (loghistory…
_network authored
210 if (loghist) {
211 char *usrtxt = NULL;
212
213 if (!cur_cl)
214 usrtxt = "undef";
215 else {
216 switch(cur_cl->typ) {
217 case 'c':
218 case 'm':
219 usrtxt = cur_cl->account ? cur_cl->account->usr : "";
220 break;
221 case 'p':
222 case 'r':
223 usrtxt = cur_cl->reader ? cur_cl->reader->label : "";
224 break;
225 default:
226 usrtxt = "server";
227 break;
228 }
229 }
230
231 char *target_ptr = NULL;
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
232 int32_t target_len = strlen(usrtxt) + (strlen(txt) - 8) + 1;
8504d47 Fix segfault when changing loghistsize. Note that the log is not pres…
Admin authored
233
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
234 cs_writelock(&loghistory_lock);
8504d47 Fix segfault when changing loghistsize. Note that the log is not pres…
Admin authored
235 char *lastpos = loghist + (cfg.loghistorysize) - 1;
7701379 size of loghistory buffer can now be set in configuration (loghistory…
_network authored
236 if (!loghistptr)
237 loghistptr = loghist;
238
239 if (loghistptr+target_len > lastpos - 1) {
240 *loghistptr='\0';
241 loghistptr=loghist + target_len + 1;
242 *loghistptr='\0';
243 target_ptr=loghist;
244 } else {
245 target_ptr = loghistptr;
246 loghistptr=loghistptr + target_len + 1;
247 *loghistptr='\0';
248 }
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
249 cs_writeunlock(&loghistory_lock);
7701379 size of loghistory buffer can now be set in configuration (loghistory…
_network authored
250
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
251 snprintf(target_ptr, target_len + 1, "%s\t%s", usrtxt, txt + 8);
7701379 size of loghistory buffer can now be set in configuration (loghistory…
_network authored
252 }
e91ad3c fix possible memory corruption when CS_LOGHISTORY is enabled
_network authored
253
dbe7760 oscam.c : simplify cl for-next loops; free cl variables at end of cle…
dingo35 authored
254 struct s_client *cl;
7701379 size of loghistory buffer can now be set in configuration (loghistory…
_network authored
255 for (cl=first_client; cl ; cl=cl->next) {
256 if ((cl->typ == 'm') && (cl->monlvl>0) && cl->log) //this variable is only initialized for cl->typ = 'm'
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
257 {
53357dc monitor: fix missing lines
dingo35 authored
258 if (cl->monlvl<2) {
ea46069 webif/reader restart crash fix (possible fix, please test)
schlocke authored
259 if (cur_cl && (cur_cl->typ != 'c') && (cur_cl->typ != 'm'))
04dd918 oscam-log.c Fix monitor lines only c and m were printed
dingo35 authored
260 continue;
ea46069 webif/reader restart crash fix (possible fix, please test)
schlocke authored
261 if (cur_cl && cur_cl->account && cl->account && strcmp(cur_cl->account->usr, cl->account->usr))
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
262 continue;
53357dc monitor: fix missing lines
dingo35 authored
263 }
fc91df8 Introducing cs_malloc/cs_realloc functions so that it's easier to log…
Admin authored
264 snprintf(sbuf, sizeof(sbuf), "%03d", cl->logcounter);
4b5a566 Unlimited clients step12: oscam-log.c get rid of client[]
dingo35 authored
265 cl->logcounter = (cl->logcounter+1) % 1000;
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
266 memcpy(txt + 4, sbuf, 3);
267 monitor_send_idx(cl, txt);
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
268 }
269 }
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
270 }
271
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
272 static void write_to_log_int(char *txt, int8_t header_len)
273 {
274 struct s_log *log = cs_malloc(&log, sizeof(struct s_log), 0);
275 log->txt = strnew(txt);
276 log->header_len = header_len;
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
277 log->direct_log = 0;
8b26202 fixed user-log
corsair authored
278 log->cl = cur_client();
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
279 ll_append(log_list, log);
280 }
281
8b26202 fixed user-log
corsair authored
282 void cs_log_int(uint16_t mask, int8_t lock __attribute__((unused)), const uchar *buf, int32_t n, const char *fmt, ...)
69e4370 Merge from ump rev. 1545: now with new debug masks, added the prefix …
landlord authored
283 {
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
284 va_list params;
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
285
f2d788a Fixed log buffer overflow in some case
lattjo authored
286 char log_txt[LOG_BUF_SIZE];
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
287 int32_t i, len = 0;
288 if (((mask & cs_dblevel) || !mask) && (fmt))
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
289 {
290 va_start(params, fmt);
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
291 len = get_log_header(1, log_txt);
292 vsnprintf(log_txt + len, sizeof(log_txt) - len, fmt, params);
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
293 write_to_log_int(log_txt, len);
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
294 va_end(params);
295 }
7a21974 dynamic-threads: fix waitforcards and add some pointer checks
zetack authored
296 if (buf && (mask & cs_dblevel || !mask))
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
297 {
298 for (i=0; i<n; i+=16)
299 {
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
300 len = get_log_header(0, log_txt);
301 cs_hexdump(1, buf+i, (n-i>16) ? 16 : n-i, log_txt + len, sizeof(log_txt) - len);
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
302 write_to_log_int(log_txt, len);
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
303 }
304 }
69e4370 Merge from ump rev. 1545: now with new debug masks, added the prefix …
landlord authored
305 }
a2ae6c2 dynamic-threads: make reader restart more robust
zetack authored
306
a86e79f Merge Webinterface into Trunk - Use -DWEBIF=1 with cmake to build wit…
merek authored
307 void cs_close_log(void)
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
308 {
69e7e3d Allow to log parallel to syslog, stdout and one file (example: logfil…
Admin authored
309 if (!fp) return;
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
310 fclose(fp);
311 fp=(FILE *)0;
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
312 }
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
313
314 void log_emm_request(struct s_reader *rdr){
4ae4309 - Fixed segfault (due to capital S in format string instead of lowerc…
kpc authored
315 cs_log("%s emm-request sent (reader=%s, caid=%04X, auprovid=%06X)",
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
316 username(cur_client()), rdr->label, rdr->caid,
317 rdr->auprovid ? rdr->auprovid : b2i(4, rdr->prid[0]));
318 }
319
320 /*
321 * This function writes the current CW from ECM struct to a cwl file.
322 * The filename is re-calculated and file re-opened every time.
323 * This will consume a bit cpu time, but nothing has to be stored between
324 * each call. If not file exists, a header is prepended
325 */
6cd19a0 save reader answers in extra struct and not in ecmtask so it is not n…
zetack authored
326 void logCWtoFile(ECM_REQUEST *er, uchar *cw){
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
327 FILE *pfCWL;
328 char srvname[128];
329 /* %s / %s _I %04X _ %s .cwl */
330 char buf[256 + sizeof(srvname)];
758d69b Fix too small date buffer on cw logging.
Admin authored
331 char date[9];
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
332 unsigned char i, parity, writeheader = 0;
333 time_t t;
334 struct tm timeinfo;
335
336 /*
337 * search service name for that id and change characters
338 * causing problems in file name
339 */
340
341 get_servicename(cur_client(), er->srvid, er->caid, srvname);
342
343 for (i = 0; srvname[i]; i++)
344 if (srvname[i] == ' ') srvname[i] = '_';
345
346 /* calc log file name */
347 time(&t);
348 localtime_r(&t, &timeinfo);
349 strftime(date, sizeof(date), "%Y%m%d", &timeinfo);
350 snprintf(buf, sizeof(buf), "%s/%s_I%04X_%s.cwl", cfg.cwlogdir, date, er->srvid, srvname);
351
352 /* open failed, assuming file does not exist, yet */
353 if((pfCWL = fopen(buf, "r")) == NULL) {
354 writeheader = 1;
355 } else {
356 /* we need to close the file if it was opened correctly */
357 fclose(pfCWL);
358 }
359
360 if ((pfCWL = fopen(buf, "a+")) == NULL) {
361 /* maybe this fails because the subdir does not exist. Is there a common function to create it?
362 for the moment do not print32_t to log on every ecm
363 cs_log(""error opening cw logfile for writing: %s (errno=%d %s)", buf, errno, strerror(errno)); */
364 return;
365 }
366 if (writeheader) {
367 /* no global macro for cardserver name :( */
368 fprintf(pfCWL, "# OSCam cardserver v%s - http://streamboard.gmc.to/oscam/\n", CS_VERSION);
369 fprintf(pfCWL, "# control word log file for use with tsdec offline decrypter\n");
370 strftime(buf, sizeof(buf),"DATE %Y-%m-%d, TIME %H:%M:%S, TZ %Z\n", &timeinfo);
371 fprintf(pfCWL, "# %s", buf);
372 fprintf(pfCWL, "# CAID 0x%04X, SID 0x%04X, SERVICE \"%s\"\n", er->caid, er->srvid, srvname);
373 }
374
375 parity = er->ecm[0]&1;
376 fprintf(pfCWL, "%d ", parity);
377 for (i = parity * 8; i < 8 + parity * 8; i++)
6cd19a0 save reader answers in extra struct and not in ecmtask so it is not n…
zetack authored
378 fprintf(pfCWL, "%02X ", cw[i]);
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
379 /* better use incoming time er->tps rather than current time? */
380 strftime(buf,sizeof(buf),"%H:%M:%S\n", &timeinfo);
381 fprintf(pfCWL, "# %s", buf);
382 fflush(pfCWL);
383 fclose(pfCWL);
384 }
385
386 void cs_log_config()
387 {
388 uchar buf[20];
389
390 if (cfg.nice!=99)
391 snprintf((char *)buf, sizeof(buf), ", nice=%d", cfg.nice);
392 else
393 buf[0]='\0';
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
394 cs_log_nolock("version=%s, build #%s, system=%s-%s-%s%s", CS_VERSION, CS_SVN_VERSION, CS_OS_CPU, CS_OS_HW, CS_OS_SYS, buf);
395 cs_log_nolock("client max. idle=%d sec, debug level=%d", cfg.cmaxidle, cs_dblevel);
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
396
397 if( cfg.max_log_size )
398 snprintf((char *)buf, sizeof(buf), "%d Kb", cfg.max_log_size);
399 else
400 cs_strncpy((char *)buf, "unlimited", sizeof(buf));
fdfa041 Continuation of r5309&r5310: Get rid of cl->dump completely. Some cle…
Admin authored
401 cs_log_nolock("max. logsize=%s, loghistorysize=%d bytes", buf, cfg.loghistorysize);
4ae4309 - Fixed segfault (due to capital S in format string instead of lowerc…
kpc authored
402 cs_log_nolock("client timeout=%u ms, fallback timeout=%u ms, cache delay=%d ms",
a0b4528 Some internal restructuring regarding globals.h file to make it a bit…
Admin authored
403 cfg.ctimeout, cfg.ftimeout, cfg.delay);
404 }
405
d474ded I noticed that monitor encryption is not working on 64bit plattforms …
Admin authored
406 int32_t cs_init_statistics(void)
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
407 {
f8c3b19 All files: make cfg static for easier valgrind analysis
dingo35 authored
408 if ((!fps) && (cfg.usrfile != NULL))
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
409 {
f8c3b19 All files: make cfg static for easier valgrind analysis
dingo35 authored
410 if ((fps=fopen(cfg.usrfile, "a+"))<=(FILE *)0)
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
411 {
412 fps=(FILE *)0;
f8c3b19 All files: make cfg static for easier valgrind analysis
dingo35 authored
413 cs_log("couldn't open statistics file: %s", cfg.usrfile);
6d1d771 New parameter in [monitor] "appendchaninfo=0|1" appends the channelna…
alno authored
414 }
415 }
416 return(fps<=(FILE *)0);
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
417 }
418
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
419 void cs_statistics(struct s_client * client)
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
420 {
f8c3b19 All files: make cfg static for easier valgrind analysis
dingo35 authored
421 if (!cfg.disableuserfile){
ec2d689 fix for userfile issue after split logfile - see http://streamboard.g…
alno authored
422 time_t t;
0347f4a Replace all occurences of localtime() with the threadsafe version loc…
Admin authored
423 struct tm lt;
f2d788a Fixed log buffer overflow in some case
lattjo authored
424 char buf[LOG_BUF_SIZE];
f94e1c9 some repair in write_config (httpallowed), Implement disableuserfile …
alno authored
425
426 float cwps;
427
428 time(&t);
0347f4a Replace all occurences of localtime() with the threadsafe version loc…
Admin authored
429 localtime_r(&t, &lt);
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
430 if (client->cwfound+client->cwnot>0)
f94e1c9 some repair in write_config (httpallowed), Implement disableuserfile …
alno authored
431 {
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
432 cwps=client->last-client->login;
433 cwps/=client->cwfound+client->cwnot;
f94e1c9 some repair in write_config (httpallowed), Implement disableuserfile …
alno authored
434 }
435 else
436 cwps=0;
0ba0c65 Add channelname to userfile (log) too depending on appendchaninfo
alno authored
437
64e711c Get rid of some static variables and cl->dump usage as they are not t…
Admin authored
438 char channame[32];
f8c3b19 All files: make cfg static for easier valgrind analysis
dingo35 authored
439 if(cfg.mon_appendchaninfo)
64e711c Get rid of some static variables and cl->dump usage as they are not t…
Admin authored
440 get_servicename(client, client->last_srvid,client->last_caid, channame);
441 else
442 channame[0] = '\0';
0ba0c65 Add channelname to userfile (log) too depending on appendchaninfo
alno authored
443
d474ded I noticed that monitor encryption is not working on 64bit plattforms …
Admin authored
444 int32_t lsec;
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
445 if ((client->last_caid == 0xFFFF) && (client->last_srvid == 0xFFFF))
446 lsec = client->last - client->login; //client leave calc total duration
bb66851 moved the cs_init_statistics to an earlier point. Add additional log …
alno authored
447 else
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
448 lsec = client->last - client->lastswitch;
bb66851 moved the cs_init_statistics to an earlier point. Add additional log …
alno authored
449
d474ded I noticed that monitor encryption is not working on 64bit plattforms …
Admin authored
450 int32_t secs = 0, fullmins = 0, mins = 0, fullhours = 0;
cf0d56e make the userfile (Log) more comfortable by adding duration time
alno authored
451
452 if((lsec > 0) && (lsec < 1000000)) {
453 secs = lsec % 60;
454 if (lsec > 60) {
455 fullmins = lsec / 60;
456 mins = fullmins % 60;
457 if(fullmins > 60) {
458 fullhours = fullmins / 60;
459 }
460 }
461 }
462
ec2d689 fix for userfile issue after split logfile - see http://streamboard.g…
alno authored
463 /* statistics entry start with 's' to filter it out on other end of pipe
464 * so we can use the same Pipe as Log
465 */
fc91df8 Introducing cs_malloc/cs_realloc functions so that it's easier to log…
Admin authored
466 snprintf(buf, sizeof(buf), "s%02d.%02d.%02d %02d:%02d:%02d %3.1f %s %s %d %d %d %d %d %d %d %ld %ld %02d:%02d:%02d %s %04X:%04X %s\n",
0347f4a Replace all occurences of localtime() with the threadsafe version loc…
Admin authored
467 lt.tm_mday, lt.tm_mon+1, lt.tm_year%100,
468 lt.tm_hour, lt.tm_min, lt.tm_sec, cwps,
0b588c1 user-statistic now persistent for the whole runtime
schlocke authored
469 client->account->usr,
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
470 cs_inet_ntoa(client->ip),
471 client->port,
472 client->cwfound,
473 client->cwcache,
474 client->cwnot,
475 client->cwignored,
476 client->cwtout,
477 client->cwtun,
478 client->login,
479 client->last,
cf0d56e make the userfile (Log) more comfortable by adding duration time
alno authored
480 fullhours, mins, secs,
6db315e globals.h remove client->cidx since it is silly to store index of cli…
dingo35 authored
481 ph[client->ctyp].desc,
482 client->last_caid,
483 client->last_srvid,
64e711c Get rid of some static variables and cl->dump usage as they are not t…
Admin authored
484 channame);
ec2d689 fix for userfile issue after split logfile - see http://streamboard.g…
alno authored
485
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
486 cs_write_log_int(buf);
f94e1c9 some repair in write_config (httpallowed), Implement disableuserfile …
alno authored
487 }
1a97269 Start repository for OSCam (Open Source Cam)
smurzch2 authored
488 }
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
489
490 void log_list_thread()
491 {
492 char buf[LOG_BUF_SIZE];
493
494 while (1) {
495 LL_ITER it = ll_iter_create(log_list);
496 struct s_log *log;
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
497 while ((log=ll_iter_next_remove(&it))) {
498 int8_t do_flush = ll_count(log_list) == 0; //flush on writing last element
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
499
500 cs_strncpy(buf, log->txt, LOG_BUF_SIZE);
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
501 if (log->direct_log)
502 cs_write_log(buf, do_flush);
503 else
8b26202 fixed user-log
corsair authored
504 write_to_log(buf, log->header_len, do_flush, log->cl);
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
505 free(log->txt);
506 free(log);
507 }
508 cs_sleepms(500);
509 }
510 }
511
512 int32_t cs_init_log(void)
513 {
514 if(logStarted == 0){
515 cs_lock_create(&loghistory_lock, 5, "loghistory_lock");
516
4c65df8 some optimizations on logging code, refactored missing user log part
corsair authored
517 log_list = ll_create(LOG_LIST);
f5da037 logging facility refactored, now log requests are stored in memory and
corsair authored
518 start_thread((void*)&log_list_thread, "log_list_thread");
519 }
520 int32_t rc = cs_open_logfiles();
521 logStarted = 1;
522 return rc;
523 }
Something went wrong with that request. Please try again.