1 #define MODULE_LOG_PREFIX "monitor"
5 #include "cscrypt/md5.h"
6 #include "module-monitor.h"
8 #include "oscam-array.h"
9 #include "oscam-client.h"
10 #include "oscam-config.h"
11 #include "oscam-conf-chk.h"
12 #include "oscam-lock.h"
13 #include "oscam-net.h"
14 #include "oscam-reader.h"
15 #include "oscam-string.h"
16 #include "oscam-work.h"
18 extern char *entitlement_type
[];
24 struct aes_keys aes_keys
;
30 static int8_t monitor_check_ip(void)
33 struct s_client
*cur_cl
= cur_client();
34 struct monitor_data
*module_data
= cur_cl
->module_data
;
36 if(module_data
->auth
) { return 0; }
37 ok
= check_ip(cfg
.mon_allowed
, cur_cl
->ip
);
40 cs_auth_client(cur_cl
, (struct s_auth
*)0, "invalid ip");
46 static int8_t monitor_auth_client(char *usr
, char *pwd
)
48 struct s_auth
*account
;
49 struct s_client
*cur_cl
= cur_client();
50 struct monitor_data
*module_data
= cur_cl
->module_data
;
52 if(module_data
->auth
) { return 0; }
55 cs_auth_client(cur_cl
, (struct s_auth
*)0, NULL
);
58 for(account
= cfg
.account
; account
; account
= account
->next
)
60 if(account
->monlvl
&& streq(usr
, account
->usr
) && streq(pwd
, account
->pwd
))
62 module_data
->auth
= 1;
66 if(!module_data
->auth
)
68 cs_auth_client(cur_cl
, (struct s_auth
*)0, "invalid account");
71 if(cs_auth_client(cur_cl
, account
, NULL
))
76 static int32_t secmon_auth_client(uchar
*ucrc
)
79 struct s_auth
*account
;
80 struct s_client
*cur_cl
= cur_client();
81 struct monitor_data
*module_data
= cur_cl
->module_data
;
82 unsigned char md5tmp
[MD5_DIGEST_LENGTH
];
86 int32_t s
= memcmp(module_data
->ucrc
, ucrc
, 4);
88 { cs_log("wrong user-crc or garbage !?"); }
92 crc
= (ucrc
[0] << 24) | (ucrc
[1] << 16) | (ucrc
[2] << 8) | ucrc
[3];
93 for(account
= cfg
.account
; (account
) && (!module_data
->auth
); account
= account
->next
)
94 if((account
->monlvl
) &&
95 (crc
== crc32(0L, MD5((unsigned char *)account
->usr
, strlen(account
->usr
), md5tmp
), MD5_DIGEST_LENGTH
)))
97 memcpy(module_data
->ucrc
, ucrc
, 4);
98 aes_set_key(&module_data
->aes_keys
, (char *)MD5((unsigned char *)ESTR(account
->pwd
), strlen(ESTR(account
->pwd
)), md5tmp
));
99 if(cs_auth_client(cur_cl
, account
, NULL
))
101 module_data
->auth
= 1;
103 if(!module_data
->auth
)
105 cs_auth_client(cur_cl
, (struct s_auth
*)0, "invalid user");
108 return module_data
->auth
;
111 int32_t monitor_send_idx(struct s_client
*cl
, char *txt
)
113 struct monitor_data
*module_data
= cl
->module_data
;
115 unsigned char buf
[256 + 32];
118 struct timespec req_ts
;
120 req_ts
.tv_nsec
= 500000;
121 nanosleep(&req_ts
, NULL
); //avoid lost udp-pakkets
123 { return sendto(cl
->udp_fd
, txt
, strlen(txt
), 0, (struct sockaddr
*)&cl
->udp_sa
, cl
->udp_sa_len
); }
129 l
= boundary(4, l
+ 5) + 5;
130 memcpy(buf
+ 1, module_data
->ucrc
, 4);
131 cs_strncpy((char *)buf
+ 10, txt
, sizeof(buf
) - 10);
132 memset(buf
+10+buf
[9], 0, l
-10-buf
[9]);
134 memcpy(buf
+ 5, i2b_buf(4, crc32(0L, buf
+ 10, l
- 10), tmp
), 4);
135 aes_encrypt_idx(&module_data
->aes_keys
, buf
+ 5, l
- 5);
136 return sendto(cl
->udp_fd
, buf
, l
, 0, (struct sockaddr
*)&cl
->udp_sa
, cl
->udp_sa_len
);
139 #define monitor_send(t) monitor_send_idx(cur_client(), t)
141 static int32_t monitor_recv(struct s_client
*client
, uchar
*buf
, int32_t UNUSED(buflen
))
143 int32_t n
= recv_from_udpipe(buf
);
145 { return buf
[0] = 0; }
146 if(!client
->module_data
&& !cs_malloc(&client
->module_data
, sizeof(struct monitor_data
)))
151 if(n
< 21) // 5+16 is minimum
153 cs_log("packet too small!");
156 int32_t res
= secmon_auth_client(buf
+ 1);
159 cs_disconnect_client(client
);
166 struct monitor_data
*module_data
= client
->module_data
;
167 aes_decrypt(&module_data
->aes_keys
, buf
+ 5, 16);
168 bsize
= boundary(4, buf
[9] + 5) + 5;
171 cs_log("packet-size mismatch !");
174 aes_decrypt(&module_data
->aes_keys
, buf
+ 21, n
- 21);
176 if(memcmp(buf
+ 5, i2b_buf(4, crc32(0L, buf
+ 10, n
- 10), tmp
), 4))
178 cs_log("CRC error ! wrong password ?");
182 memmove(buf
, buf
+ 10, n
);
186 if(monitor_check_ip() == -1)
188 cs_disconnect_client(client
);
193 n
= strlen(trim((char *)buf
));
194 if(n
) { client
->last
= time((time_t *) 0); }
198 static void monitor_send_info(char *txt
, int32_t last
)
200 struct s_client
*cur_cl
= cur_client();
201 struct monitor_data
*module_data
= cur_cl
->module_data
;
205 if(!module_data
->btxt
[0])
207 module_data
->counter
= 0;
211 { module_data
->counter
++; }
212 snprintf(buf
, sizeof(buf
), "%03d", module_data
->counter
);
213 memcpy(txt
+ 4, buf
, 3);
214 txt
[3] = '0' + module_data
->seq
;
221 if(module_data
->btxt
[0]) { monitor_send(module_data
->btxt
); }
222 cs_strncpy(module_data
->btxt
, txt
, sizeof(module_data
->btxt
));
226 if(txt
&& module_data
->btxt
[0])
228 monitor_send(module_data
->btxt
);
230 cs_strncpy(module_data
->btxt
, txt
, sizeof(module_data
->btxt
));
235 { cs_strncpy(module_data
->btxt
, txt
, sizeof(module_data
->btxt
)); }
236 module_data
->btxt
[2] = (module_data
->btxt
[2] == 'B') ? 'S' : 'E';
239 if(module_data
->btxt
[0])
241 monitor_send(module_data
->btxt
);
242 module_data
->seq
= (module_data
->seq
+ 1) % 10;
244 module_data
->btxt
[0] = 0;
247 static char *monitor_client_info(char id
, struct s_client
*cl
, char *sbuf
)
249 char channame
[CS_SERVICENAME_SIZE
];
254 char ldate
[16], ltime
[16];
256 int32_t lsec
, isec
, con
, cau
, lrt
= - 1;
259 now
= time((time_t *)0);
261 if((cfg
.hideclient_to
<= 0) ||
262 (now
- cl
->lastecm
< cfg
.hideclient_to
) ||
263 (now
- cl
->lastemm
< cfg
.hideclient_to
) ||
266 lsec
= now
- cl
->login
;
267 isec
= now
- cl
->last
;
271 else if((cl
->tosleep
) && (now
- cl
->lastswitch
> cl
->tosleep
))
276 // no AU reader == 0 / AU ok == 1 / Last EMM > aulow == -1
277 if(cl
->typ
== 'c' || cl
->typ
== 'p' || cl
->typ
== 'r')
280 if((cl
->typ
== 'c' && ll_count(cl
->aureader_list
) == 0) ||
281 ((cl
->typ
== 'p' || cl
->typ
== 'r') && cl
->reader
->audisabled
))
284 else if((now
- cl
->lastemm
) / 60 > cfg
.aulow
)
299 struct s_reader
*rdr
;
300 for(i
= 0, rdr
= first_active_reader
; rdr
; rdr
= rdr
->next
, i
++)
301 if(cl
->reader
== rdr
)
305 { lrt
= 10 + cl
->reader
->card_status
; }
308 { lrt
= cl
->cwlastresptime
; }
309 localtime_r(&cl
->login
, <
);
310 snprintf(ldate
, sizeof(ldate
), "%02d.%02d.%02d", lt
.tm_mday
, lt
.tm_mon
+ 1, lt
.tm_year
% 100);
311 int32_t cnr
= get_threadnum(cl
);
312 snprintf(ltime
, sizeof(ldate
), "%02d:%02d:%02d", lt
.tm_hour
, lt
.tm_min
, lt
.tm_sec
);
313 snprintf(sbuf
, 256, "[%c--CCC]%8X|%c|%d|%s|%d|%d|%s|%d|%s|%s|%s|%d|%04X@%06X:%04X|%s|%d|%d|%d|%d|%d|%d|%d|%d|%d|%d\n",
314 id
, cl
->tid
, cl
->typ
, cnr
, usr
, cau
, cl
->crypted
,
315 cs_inet_ntoa(cl
->ip
), cl
->port
, client_get_proto(cl
),
316 ldate
, ltime
, lsec
, cl
->last_caid
, cl
->last_provid
, cl
->last_srvid
,
317 get_servicename_or_null(cl
, cl
->last_srvid
, cl
->last_provid
, cl
->last_caid
, channame
, sizeof(channame
)), isec
, con
,
318 cl
->cwfound
, cl
->cwnot
, cl
->cwcache
, cl
->cwignored
,
319 cl
->cwtout
, cl
->emmok
, cl
->emmnok
, lrt
);
325 static void monitor_process_info(void)
327 time_t now
= time((time_t *)0);
330 struct s_client
*cl
, *cur_cl
= cur_client();
332 for(cl
= first_client
; cl
; cl
= cl
->next
)
334 if((cfg
.hideclient_to
<= 0) ||
335 (now
- cl
->lastecm
< cfg
.hideclient_to
) ||
336 (now
- cl
->lastemm
< cfg
.hideclient_to
) ||
339 if((cur_cl
->monlvl
< 2) && (cl
->typ
!= 's'))
341 if((cur_cl
->account
&& cl
->account
&& strcmp(cur_cl
->account
->usr
, cl
->account
->usr
)) ||
342 ((cl
->typ
!= 'c') && (cl
->typ
!= 'm')))
345 monitor_send_info(monitor_client_info('I', cl
, sbuf
), 0);
348 monitor_send_info(NULL
, 1);
351 static void monitor_send_details(char *txt
, uint32_t tid
)
354 snprintf(buf
, 255, "[D-----]%8X|%s\n", tid
, txt
);
355 monitor_send_info(buf
, 0);
358 static void monitor_send_details_version(void)
361 snprintf(buf
, sizeof(buf
), "[V-0000]version=%s, build=%s, system=%s\n", CS_VERSION
, CS_SVN_VERSION
, CS_TARGET
);
362 monitor_send_info(buf
, 1);
365 static void monitor_send_keepalive_ack(void)
368 snprintf(buf
, sizeof(buf
), "[K-0000]keepalive_ack\n");
369 monitor_send_info(buf
, 1);
372 static void monitor_process_details_master(char *buf
, uint32_t pid
)
374 snprintf(buf
, 256, "Version=%sr%s", CS_VERSION
, CS_SVN_VERSION
);
375 monitor_send_details(buf
, pid
);
376 snprintf(buf
, 256, "System=%s", CS_TARGET
);
377 monitor_send_details(buf
, pid
);
378 snprintf(buf
, 256, "DebugLevel=%d", cs_dblevel
);
379 monitor_send_details(buf
, pid
);
380 snprintf(buf
, 256, "MaxClients=UNLIMITED");
381 monitor_send_details(buf
, pid
);
382 snprintf(buf
, 256, "ClientMaxIdle=%d sec", cfg
.cmaxidle
);
383 monitor_send_details(buf
, pid
);
385 { snprintf(buf
+ 200, 56, "%d Kb", cfg
.max_log_size
); }
387 { cs_strncpy(buf
+ 200, "unlimited", 56); }
388 snprintf(buf
, 256, "MaxLogsize=%s", buf
+ 200);
389 monitor_send_details(buf
, pid
);
390 snprintf(buf
, 256, "ClientTimeout=%u ms", cfg
.ctimeout
);
391 monitor_send_details(buf
, pid
);
392 snprintf(buf
, 256, "CacheDelay=%d ms", cfg
.delay
);
393 monitor_send_details(buf
, pid
);
396 snprintf(buf
, 256, "CwlogDir=%s", cfg
.cwlogdir
);
397 monitor_send_details(buf
, pid
);
399 if(cfg
.preferlocalcards
)
401 snprintf(buf
, 256, "PreferlocalCards=%d", cfg
.preferlocalcards
);
402 monitor_send_details(buf
, pid
);
406 snprintf(buf
, 256, "WaitforCards=%d", cfg
.waitforcards
);
407 monitor_send_details(buf
, pid
);
409 snprintf(buf
, 256, "LogFile=%s", cfg
.logfile
);
410 monitor_send_details(buf
, pid
);
413 snprintf(buf
, 256, "MailFile=%s", cfg
.mailfile
);
414 monitor_send_details(buf
, pid
);
418 snprintf(buf
, 256, "UsrFile=%s", cfg
.usrfile
);
419 monitor_send_details(buf
, pid
);
421 monitor_send_details(buf
, pid
);
422 snprintf(buf
, 256, "Sleep=%d", cfg
.tosleep
);
423 monitor_send_details(buf
, pid
);
424 snprintf(buf
, 256, "Monitorport=%d", cfg
.mon_port
);
425 monitor_send_details(buf
, pid
);
426 snprintf(buf
, 256, "Nice=%d", cfg
.nice
);
427 monitor_send_details(buf
, pid
);
429 snprintf(buf
, 256, "Restartmode=%d", cs_get_restartmode());
430 monitor_send_details(buf
, pid
);
432 snprintf(buf
, 256, "Restartmode=%s", "no");
433 monitor_send_details(buf
, pid
);
436 // monitor_send_details(buf, pid);
440 static void monitor_process_details_reader(struct s_client
*cl
)
442 char tbuffer1
[64], tbuffer2
[64], buf
[256] = { 0 }, tmpbuf
[256] = { 0 }, valid_to
[32] = { 0 };
443 struct s_reader
*rdr
= cl
->reader
;
446 monitor_send_details("Reader do not exist or it is not started.", cl
->tid
);
450 if(rdr
->card_valid_to
)
453 localtime_r(&rdr
->card_valid_to
, &vto_t
);
454 strftime(valid_to
, sizeof(valid_to
) - 1, "%Y-%m-%d", &vto_t
);
458 strncpy(valid_to
, "n/a", 3);
461 snprintf(tmpbuf
, sizeof(tmpbuf
) - 1, "Cardsystem: %s Reader: %s ValidTo: %s HexSerial: %s ATR: %s",
462 rdr
->csystem
? rdr
->csystem
->desc
: "-",
465 cs_hexdump(1, rdr
->hexserial
, 8, tbuffer2
, sizeof(tbuffer2
)),
467 ? cs_hexdump(1, rdr
->card_atr
, rdr
->card_atr_length
, buf
, sizeof(buf
))
470 monitor_send_details(tmpbuf
, cl
->tid
);
472 if(!rdr
->ll_entitlements
)
474 monitor_send_details("No entitlements for the reader.", cl
->tid
);
479 LL_ITER itr
= ll_iter_create(rdr
->ll_entitlements
);
480 time_t now
= (time(NULL
) / 86400) * 86400;
482 while((item
= ll_iter_next(&itr
)))
484 struct tm start_t
, end_t
;
486 localtime_r(&item
->start
, &start_t
);
487 localtime_r(&item
->end
, &end_t
);
489 strftime(tbuffer1
, sizeof(tbuffer1
) - 1, "%Y-%m-%d %H:%M %z", &start_t
);
490 strftime(tbuffer2
, sizeof(tbuffer2
) - 1, "%Y-%m-%d %H:%M %z", &end_t
);
492 char *entresname
= get_tiername(item
->id
& 0xFFFF, item
->caid
, buf
);
494 { entresname
= get_provider(item
->provid
, item
->caid
, buf
, sizeof(buf
)); }
496 snprintf(tmpbuf
, sizeof(tmpbuf
) - 1, "%s Type: %s CAID: %04X Provid: %06X ID: %08X%08X Class: %08X StartDate: %s ExpireDate: %s Name: %s",
497 item
->end
> now
? "active " : "expired",
498 entitlement_type
[item
->type
],
501 (uint32_t)(item
->id
>> 32),
502 (uint32_t)(item
->id
),
508 monitor_send_details(tmpbuf
, cl
->tid
);
513 static void monitor_process_details(char *arg
)
515 uint32_t tid
= 0; //using threadid 8 positions hex see oscam-log.c //FIXME untested but pid isnt working anyway with threading
516 struct s_client
*cl
= NULL
, *cl1
;
520 { cl
= first_client
; } // no arg - show master
523 if(sscanf(arg
, "%X", &tid
) == 1)
525 for(cl1
= first_client
; cl1
; cl1
= cl1
->next
)
535 { monitor_send_details("Invalid TID", tid
); }
538 //monitor_send_info(monitor_client_info('D', idx), 0); //FIXME
542 monitor_process_details_master(sbuf
, cl
->tid
);
546 monitor_send_details(monitor_client_info(1, cl
, sbuf
), cl
->tid
);
549 monitor_process_details_reader(cl
);//with client->typ='r' client->ridx is always filled and valid, so no need checking
552 monitor_send_details(monitor_client_info(1, cl
, sbuf
), cl
->tid
);
556 monitor_send_info(NULL
, 1);
559 static void monitor_send_login(void)
562 struct s_client
*cur_cl
= cur_client();
563 struct monitor_data
*module_data
= cur_cl
->module_data
;
564 if(module_data
->auth
&& cur_cl
->account
)
565 { snprintf(buf
, sizeof(buf
), "[A-0000]1|%s logged in\n", cur_cl
->account
->usr
); }
567 { cs_strncpy(buf
, "[A-0000]0|not logged in\n", sizeof(buf
)); }
568 monitor_send_info(buf
, 1);
571 static void monitor_login(char *usr
)
575 if((usr
) && (pwd
= strchr(usr
, ' ')))
578 { res
= monitor_auth_client(trim(usr
), trim(pwd
)); }
580 { res
= monitor_auth_client(NULL
, NULL
); }
584 cs_disconnect_client(cur_client());
587 monitor_send_login();
590 static void monitor_logsend(char *flag
)
592 if(!flag
) { return; } //no arg
594 struct s_client
*cur_cl
= cur_client();
595 if(strcmp(flag
, "on"))
597 if(strcmp(flag
, "onwohist"))
604 if(cur_cl
->log
) // already on
607 if(!strcmp(flag
, "on") && cfg
.loghistorylines
)
609 if(cfg
.loghistorylines
&& log_history
)
611 LL_ITER it
= ll_iter_create(log_history
);
612 struct s_log_history
*hist
;
614 while((hist
= (struct s_log_history
*)ll_iter_next(&it
)))
616 char p_usr
[32], p_txt
[512];
617 size_t pos1
= strcspn(hist
->txt
, "\t") + 1;
619 cs_strncpy(p_usr
, hist
->txt
, pos1
> sizeof(p_usr
) ? sizeof(p_usr
) : pos1
);
621 if((p_usr
[0]) && ((cur_cl
->monlvl
> 1) || (cur_cl
->account
&& !strcmp(p_usr
, cur_cl
->account
->usr
))))
623 snprintf(p_txt
, sizeof(p_txt
), "[LOG%03d]%s", cur_cl
->logcounter
, hist
->txt
+ pos1
);
624 cur_cl
->logcounter
= (cur_cl
->logcounter
+ 1) % 1000;
634 static void monitor_set_debuglevel(char *flag
)
638 cs_dblevel
= atoi(flag
);
640 cs_log("*** Warning: Debug Support not compiled in ***");
642 cs_log("%s debug_level=%d", "all", cs_dblevel
);
647 static void monitor_get_account(void)
649 struct s_auth
*account
;
653 for(account
= cfg
.account
; (account
); account
= account
->next
)
656 snprintf(buf
, sizeof(buf
), "[U-----]%s\n", account
->usr
);
657 monitor_send_info(buf
, 0);
659 snprintf(buf
, sizeof(buf
), "[U-----] %i User registered\n", count
);
660 monitor_send_info(buf
, 1);
664 static void monitor_set_account(char *args
)
666 struct s_auth
*account
;
667 char delimiter
[] = " =";
668 char *ptr
, *saveptr1
= NULL
;
669 int32_t argidx
, i
, found
;
671 static const char *token
[] = {"au", "sleep", "uniq", "monlevel", "group", "services", "betatunnel", "ident", "caid", "chid", "class", "hostname", "expdate", "keepalive", "disabled"};
672 int32_t tokencnt
= sizeof(token
) / sizeof(char *);
673 char buf
[256], tmp
[64];
678 snprintf(tmp
, sizeof(tmp
), "%s", args
);
679 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s check\n", tmp
);
680 monitor_send_info(buf
, 0);
682 ptr
= strtok_r(args
, delimiter
, &saveptr1
);
687 argarray
[argidx
] = trim(ptr
);
688 ptr
= strtok_r(NULL
, delimiter
, &saveptr1
);
694 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s failed - wrong number of parameters (%d)\n", tmp
, argidx
);
695 monitor_send_info(buf
, 0);
696 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s end\n", tmp
);
697 monitor_send_info(buf
, 1);
702 for(account
= cfg
.account
; (account
) ; account
= account
->next
)
704 if(!strcmp(argarray
[0], account
->usr
))
713 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s failed - user %s not found\n", tmp
, argarray
[0]);
714 monitor_send_info(buf
, 0);
715 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s end\n", tmp
);
716 monitor_send_info(buf
, 1);
721 for(i
= 0; i
< tokencnt
; i
++)
723 if(!strcmp(argarray
[1], token
[i
]))
725 // preparing the parameters before re-load
730 tuntab_clear(&account
->ttab
);
734 caidtab_clear(&account
->ctab
);
743 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: parameter %s not exist. possible values:\n", argarray
[1]);
744 monitor_send_info(buf
, 0);
745 for(i
= 0; i
< tokencnt
; i
++)
747 snprintf(buf
, sizeof(buf
), "[S-0000]%s\n", token
[i
]);
748 monitor_send_info(buf
, 0);
750 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s end\n", tmp
);
751 monitor_send_info(buf
, 1);
756 chk_account(token
[found
], argarray
[2], account
);
759 if(write_userdb() == 0)
760 { cs_reinit_clients(cfg
.account
); }
762 snprintf(buf
, sizeof(buf
), "[S-0000]setuser: %s done - param %s set to %s\n", tmp
, argarray
[1], argarray
[2]);
763 monitor_send_info(buf
, 1);
766 static void monitor_set_server(char *args
)
768 char delimiter
[] = "=";
769 char *ptr
, *saveptr1
;
772 static const char *token
[] = {"clienttimeout", "fallbacktimeout", "clientmaxidle", "cachedelay", "bindwait", "netprio", "sleep", "unlockparental", "serialreadertimeout", "maxlogsize", "showecmdw", "waitforcards", "preferlocalcards"};
776 ptr
= strtok_r(args
, delimiter
, &saveptr1
);
781 argarray
[argidx
] = trim(ptr
);
782 ptr
= strtok_r(NULL
, delimiter
, &saveptr1
);
788 snprintf(buf
, sizeof(buf
), "[S-0000]setserver failed - wrong number of parameters (%d)\n", argidx
);
789 monitor_send_info(buf
, 1);
795 strtolower(argarray
[0]);
797 for(i
= 0; i
< 13; i
++)
798 if(!strcmp(argarray
[0], token
[i
])) { break; }
802 config_set("global", token
[i
], argarray
[1]);
803 snprintf(buf
, sizeof(buf
), "[S-0000]setserver done - param %s set to %s\n", argarray
[0], argarray
[1]);
804 monitor_send_info(buf
, 1);
808 snprintf(buf
, sizeof(buf
), "[S-0000]setserver failed - parameter %s not exist\n", argarray
[0]);
809 monitor_send_info(buf
, 1);
813 /*Hide by blueven. Introduce new fallbacktimeout_percaid.
815 * if (cfg.ftimeout>=cfg.ctimeout) {
816 cfg.ftimeout = cfg.ctimeout - 100;
817 snprintf(buf, sizeof(buf), "[S-0000]setserver WARNING: fallbacktimeout adjusted to %u ms\n", cfg.ftimeout);
818 monitor_send_info(buf, 1);
820 //kill(first_client->pid, SIGUSR1);
824 static void monitor_restart_server(void)
830 static void monitor_list_commands(const char *args
[], int32_t cmdcnt
)
833 for(i
= 0; i
< cmdcnt
; i
++)
836 snprintf(buf
, sizeof(buf
), "[S-0000]commands: %s\n", args
[i
]);
838 { monitor_send_info(buf
, 0); }
840 { monitor_send_info(buf
, 1); }
844 static int32_t monitor_process_request(char *req
)
847 static const char *cmd
[] = {"login",
867 int32_t cmdcnt
= sizeof(cmd
) / sizeof(char *); // Calculate the amount of items in array
869 struct s_client
*cur_cl
= cur_client();
870 struct monitor_data
*module_data
= cur_cl
->module_data
;
872 if((arg
= strchr(req
, ' ')))
879 if(!module_data
->auth
&& strcmp(req
, cmd
[0]) != 0)
880 { monitor_login(NULL
); }
882 for(rc
= 1, i
= 0; i
< cmdcnt
; i
++)
883 if(!strcmp(req
, cmd
[i
]))
891 cs_disconnect_client(cur_cl
);
894 monitor_logsend(arg
);
897 monitor_process_info();
900 if(cur_cl
->monlvl
> 3) { cs_exit_oscam(); }
903 if(cur_cl
->monlvl
> 2) { cs_accounts_chk(); }
906 monitor_process_details(arg
);
909 monitor_send_details_version();
912 if(cur_cl
->monlvl
> 3) { monitor_set_debuglevel(arg
); }
915 if(cur_cl
->monlvl
> 3) { monitor_get_account(); }
918 if(cur_cl
->monlvl
> 3) { monitor_set_account(arg
); }
921 if(cur_cl
->monlvl
> 3) { monitor_set_server(arg
); }
924 if(cur_cl
->monlvl
> 3) { monitor_list_commands(cmd
, cmdcnt
); }
925 break; // list commands
927 if(cur_cl
->monlvl
> 3) { monitor_send_keepalive_ack(); }
931 char buf
[64]; // reread
932 snprintf(buf
, sizeof(buf
), "[S-0000]reread\n");
933 monitor_send_info(buf
, 1);
939 if(cur_cl
->monlvl
> 3) { monitor_restart_server(); }
950 static void *monitor_server(struct s_client
*client
, uchar
*mbuf
, int32_t UNUSED(n
))
953 monitor_process_request((char *)mbuf
);
958 static void monitor_cleanup(struct s_client
*client
)
960 NULLFREE(client
->module_data
);
963 void module_monitor(struct s_module
*ph
)
966 ph
->ptab
.ports
[0].s_port
= cfg
.mon_port
;
967 ph
->desc
= "monitor";
968 ph
->type
= MOD_CONN_UDP
;
969 IP_ASSIGN(ph
->s_ip
, cfg
.mon_srvip
);
970 ph
->s_handler
= monitor_server
;
971 ph
->recv
= monitor_recv
;
972 ph
->cleanup
= monitor_cleanup
;
973 // ph->send_dcw=NULL;