source: trunk/module-monitor.c@ 1742

Last change on this file since 1742 was 1742, checked in by alno, 10 years ago

reworked "setuser" command in monitor module. Syntax setuser <username> <parameter>=<value>

File size: 18.0 KB
Line 
1#include "globals.h"
2#ifdef CS_WITH_GBOX
3# include "csgbox/gbox.h"
4# define CS_VERSION_X CS_VERSION "-gbx-" GBXVERSION
5#else
6# define CS_VERSION_X CS_VERSION
7#endif
8
9static int auth = 0;
10
11static void monitor_check_ip()
12{
13 int ok=0;
14 struct s_ip *p_ip;
15
16 if (auth) return;
17 for (p_ip=cfg->mon_allowed; (p_ip) && (!ok); p_ip=p_ip->next)
18 ok=((client[cs_idx].ip>=p_ip->ip[0]) && (client[cs_idx].ip<=p_ip->ip[1]));
19 if (!ok)
20 {
21 cs_auth_client((struct s_auth *)0, "invalid ip");
22 cs_exit(0);
23 }
24}
25
26static void monitor_auth_client(char *usr, char *pwd)
27{
28 struct s_auth *account;
29
30 if (auth) return;
31 if ((!usr) || (!pwd))
32 {
33 cs_auth_client((struct s_auth *)0, NULL);
34 cs_exit(0);
35 }
36 for (account=cfg->account, auth=0; (account) && (!auth);)
37 {
38 if (account->monlvl)
39 auth=!(strcmp(usr, account->usr) | strcmp(pwd, account->pwd));
40 if (!auth)
41 account=account->next;
42 }
43 if (!auth)
44 {
45 cs_auth_client((struct s_auth *)0, "invalid account");
46 cs_exit(0);
47 }
48 if (cs_auth_client(account, NULL))
49 cs_exit(0);
50}
51
52static int secmon_auth_client(uchar *ucrc)
53{
54 ulong crc;
55 struct s_auth *account;
56
57 if (auth)
58 {
59 int s=memcmp(client[cs_idx].ucrc, ucrc, 4);
60 if (s)
61 cs_log("wrong user-crc or garbage !?");
62 return(!s);
63 }
64 client[cs_idx].crypted=1;
65 crc=(ucrc[0]<<24) | (ucrc[1]<<16) | (ucrc[2]<<8) | ucrc[3];
66 for (account=cfg->account; (account) && (!auth); account=account->next)
67 if ((account->monlvl) &&
68 (crc==crc32(0L, MD5((unsigned char *)account->usr, strlen(account->usr), NULL), 16)))
69 {
70 memcpy(client[cs_idx].ucrc, ucrc, 4);
71 aes_set_key((char *)MD5((unsigned char *)account->pwd, strlen(account->pwd), NULL));
72 if (cs_auth_client(account, NULL))
73 cs_exit(0);
74 auth=1;
75 }
76 if (!auth)
77 {
78 cs_auth_client((struct s_auth *)0, "invalid user");
79 cs_exit(0);
80 }
81 return(auth);
82}
83
84int monitor_send_idx(int idx, char *txt)
85{
86 int l;
87 unsigned char buf[256+32];
88 if (!client[idx].udp_fd)
89 return(-1);
90 struct timespec req_ts;
91 req_ts.tv_sec = 0;
92 req_ts.tv_nsec = 500000;
93 nanosleep (&req_ts, NULL);//avoid lost udp-pakkets
94 if (!client[idx].crypted)
95 return(sendto(client[idx].udp_fd, txt, strlen(txt), 0,
96 (struct sockaddr *)&client[idx].udp_sa,
97 sizeof(client[idx].udp_sa)));
98 buf[0]='&';
99 buf[9]=l=strlen(txt);
100 l=boundary(4, l+5)+5;
101 memcpy(buf+1, client[idx].ucrc, 4);
102 strcpy((char *)buf+10, txt);
103 memcpy(buf+5, i2b(4, crc32(0L, buf+10, l-10)), 4);
104 aes_encrypt_idx(idx, buf+5, l-5);
105 return(sendto(client[idx].udp_fd, buf, l, 0,
106 (struct sockaddr *)&client[idx].udp_sa,
107 sizeof(client[idx].udp_sa)));
108}
109
110#define monitor_send(t) monitor_send_idx(cs_idx, t)
111
112static int monitor_recv(uchar *buf, int l)
113{
114 int n;
115 uchar nbuf[3] = { 'U', 0, 0 };
116 static int bpos=0;
117 static uchar *bbuf=NULL;
118 if (!bbuf)
119 {
120 bbuf=(uchar *)malloc(l);
121 if (!bbuf)
122 {
123 cs_log("Cannot allocate memory (errno=%d)", errno);
124 cs_exit(1);
125 }
126 }
127 if (bpos)
128 memcpy(buf, bbuf, n=bpos);
129 else
130 n=recv_from_udpipe(buf);
131 bpos=0;
132 if (!n) return(buf[0]=0);
133 if (buf[0]=='&')
134 {
135 int bsize;
136 if (n<21) // 5+16 is minimum
137 {
138 cs_log("packet to short !");
139 return(buf[0]=0);
140 }
141 if (!secmon_auth_client(buf+1))
142 return(buf[0]=0);
143 aes_decrypt(buf+5, 16);
144 bsize=boundary(4, buf[9]+5)+5;
145 // cs_log("n=%d bsize=%d", n, bsize);
146 if (n>bsize)
147 {
148 // cs_log("DO >>>> copy-back");
149 memcpy(bbuf, buf+bsize, bpos=n-bsize);
150 n=bsize;
151 if (!write(client[cs_idx].ufd, nbuf, sizeof(nbuf))) cs_exit(1); // trigger new event
152 }
153 else if (n<bsize)
154 {
155 cs_log("packet-size mismatch !");
156 return(buf[0]=0);
157 }
158 aes_decrypt(buf+21, n-21);
159 if (memcmp(buf+5, i2b(4, crc32(0L, buf+10, n-10)), 4))
160 {
161 cs_log("CRC error ! wrong password ?");
162 return(buf[0]=0);
163 }
164 n=buf[9];
165 memmove(buf, buf+10, n);
166 }
167 else
168 {
169 uchar *p;
170 monitor_check_ip();
171 buf[n]='\0';
172 if ((p=(uchar *)strchr((char *)buf, 10)) && (bpos=n-(p-buf)-1))
173 {
174 memcpy(bbuf, p+1, bpos);
175 n=p-buf;
176 if (!write(client[cs_idx].ufd, nbuf, sizeof(nbuf))) cs_exit(1); // trigger new event
177 }
178 }
179 buf[n]='\0';
180 n=strlen(trim((char *)buf));
181 if (n) client[cs_idx].last=time((time_t *) 0);
182 return(n);
183}
184
185static void monitor_send_info(char *txt, int last)
186{
187 static int seq=0, counter=0;
188 static char btxt[256] = {0};
189 char buf[8];
190 if (txt)
191 {
192 if (!btxt[0])
193 {
194 counter=0;
195 txt[2]='B';
196 }
197 else
198 counter++;
199 sprintf(buf, "%03d", counter);
200 memcpy(txt+4, buf, 3);
201 txt[3]='0'+seq;
202 }
203 else
204 if (!last)
205 return;
206
207 if (!last)
208 {
209 if (btxt[0]) monitor_send(btxt);
210 cs_strncpy(btxt, txt, sizeof(btxt));
211 return;
212 }
213
214 if (txt && btxt[0])
215 {
216 monitor_send(btxt);
217 txt[2]='E';
218 cs_strncpy(btxt, txt, sizeof(btxt));
219 }
220 else
221 {
222 if (txt)
223 cs_strncpy(btxt, txt, sizeof(btxt));
224 btxt[2]=(btxt[2]=='B') ? 'S' : 'E';
225 }
226
227 if (btxt[0])
228 {
229 monitor_send(btxt);
230 seq=(seq+1)%10;
231 }
232 btxt[0]=0;
233}
234
235int cs_idx2ridx(int idx){
236 int i;
237 for (i = 0; i < CS_MAXREADER; i++)
238 if (reader[i].cs_idx==idx)
239 return(i);
240 return(-1);
241}
242
243char *monitor_get_srvname(int srvid, int caid){
244 int i;
245 struct s_srvid *this = cfg->srvid;
246 static char name[83];
247
248 for (name[0] = 0; this && (!name[0]); this = this->next)
249 if (this->srvid == srvid)
250 for (i=0; i<this->ncaid; i++)
251 if (this->caid[i] == caid)
252 cs_strncpy(name, this->name, 32);
253
254 if (!name[0]) sprintf(name, "[%04X:%04X]", caid, srvid);
255 if (!srvid) name[0] = '\0';
256 return(name);
257}
258
259char *monitor_get_proto(int idx)
260{
261 int i;
262 char *ctyp;
263 switch(client[idx].typ) {
264 case 's' : ctyp = "server" ; break;
265 case 'n' : ctyp = "resolver" ; break;
266 case 'l' : ctyp = "logger" ; break;
267 case 'p' :
268 case 'r' :
269 if ((i = cs_idx2ridx(idx)) < 0) // should never happen
270 ctyp = (client[idx].typ == 'p') ? "proxy" : "reader";
271 else {
272 switch(reader[i].typ) { /* TODO like ph*/
273 case R_MOUSE : ctyp = "mouse"; break;
274 case R_INTERNAL : ctyp = "intern"; break;
275 case R_SMART : ctyp = "smartreader"; break;
276 case R_CAMD35 : ctyp = "camd 3.5x"; break;
277 case R_CAMD33 : ctyp = "camd 3.3x"; break;
278 case R_NEWCAMD : ctyp = "newcamd"; break;
279 case R_RADEGAST : ctyp = "radegast"; break;
280 case R_SERIAL : ctyp = "serial"; break;
281#ifdef CS_WITH_GBOX
282 case R_GBOX : ctyp = "gbox"; break;
283#endif
284#ifdef HAVE_PCSC
285 case R_PCSC : ctyp = "pcsc"; break;
286#endif
287 case R_CCCAM : ctyp = "cccam"; break;
288 case R_CS378X : ctyp = "cs378x"; break;
289 case R_DB2COM1 : ctyp = "dbox COM1"; break;
290 case R_DB2COM2 : ctyp = "dbox COM2"; break;
291 default : ctyp = "unknown"; break;
292 }
293 }
294 break;
295 default : ctyp = ph[client[idx].ctyp].desc;
296 }
297 return(ctyp);
298}
299
300static char *monitor_client_info(char id, int i){
301 static char sbuf[256];
302 sbuf[0] = '\0';
303
304 if (client[i].pid){
305 char ldate[16], ltime[16], *usr;
306 int lsec, isec, cnr, con, cau;
307 time_t now;
308 struct tm *lt;
309 now=time((time_t)0);
310
311 if ((cfg->mon_hideclient_to <= 0) ||
312 (now-client[i].lastecm < cfg->mon_hideclient_to) ||
313 (now-client[i].lastemm < cfg->mon_hideclient_to) ||
314 (client[i].typ != 'c'))
315 {
316 lsec=now-client[i].login;
317 isec=now-client[i].last;
318 usr=client[i].usr;
319 if (((client[i].typ == 'r') || (client[i].typ == 'p')) && (con=cs_idx2ridx(i)) >= 0)
320 usr=reader[con].label;
321 if (client[i].dup)
322 con=2;
323 else
324 if ((client[i].tosleep) && (now-client[i].lastswitch>client[i].tosleep))
325 con = 1;
326 else
327 con = 0;
328 if (i - cdiff > 0)
329 cnr = i - cdiff;
330 else
331 cnr=(i > 1) ? i - 1 : 0;
332 if( (cau = client[i].au + 1) )
333 if ((now-client[i].lastemm) /60 > cfg->mon_aulow)
334 cau=-cau;
335 lt = localtime(&client[i].login);
336 sprintf(ldate, "%2d.%02d.%02d", lt->tm_mday, lt->tm_mon+1, lt->tm_year % 100);
337 sprintf(ltime, "%2d:%02d:%02d", lt->tm_hour, lt->tm_min, lt->tm_sec);
338 sprintf(sbuf, "[%c--CCC]%d|%c|%d|%s|%d|%d|%s|%d|%s|%s|%s|%d|%04X:%04X|%s|%d|%d\n",
339 id, client[i].pid, client[i].typ, cnr, usr, cau, client[i].crypted,
340 cs_inet_ntoa(client[i].ip), client[i].port, monitor_get_proto(i),
341 ldate, ltime, lsec, client[i].last_caid, client[i].last_srvid,
342 monitor_get_srvname(client[i].last_srvid, client[i].last_caid), isec, con);
343 }
344 }
345 return(sbuf);
346}
347
348static void monitor_process_info(){
349 int i;
350 time_t now = time((time_t)0);
351
352 for (i = 0; i < CS_MAXPID; i++){
353 if ((cfg->mon_hideclient_to <= 0) ||
354 ( now-client[i].lastecm < cfg->mon_hideclient_to) ||
355 ( now-client[i].lastemm < cfg->mon_hideclient_to) ||
356 ( client[i].typ != 'c')){
357 if (client[i].pid) {
358 if ((client[cs_idx].monlvl < 2) && (client[i].typ != 's')) {
359 if ((strcmp(client[cs_idx].usr, client[i].usr)) ||
360 ((client[i].typ != 'c') && (client[i].typ != 'm')))
361 continue;
362 }
363 monitor_send_info(monitor_client_info('I', i), 0);
364 }
365 }
366 }
367 monitor_send_info(NULL, 1);
368}
369
370static void monitor_send_details(char *txt, int pid){
371 char buf[256];
372 snprintf(buf, 255, "[D-----]%d|%s\n", pid, txt);
373 monitor_send_info(buf, 0);
374}
375
376static void monitor_send_details_version(){
377 char buf[256];
378 sprintf(buf, "[V-0000]version=%s, build=%s, system=%s%s\n", CS_VERSION_X, CS_SVN_VERSION, cs_platform(buf + 100), buf + 200);
379 monitor_send_info(buf, 1);
380}
381
382static void monitor_process_details_master(char *buf, int pid){
383 if (cfg->nice != 99)
384 sprintf(buf + 200, ", nice=%d", cfg->nice);
385 else
386 buf[200] = '\0';
387 sprintf(buf, "version=%s#%s, system=%s%s", CS_VERSION_X, CS_SVN_VERSION, cs_platform(buf + 100), buf + 200);
388 monitor_send_details(buf, pid);
389
390 sprintf(buf, "max. clients=%d, client max. idle=%ld sec", CS_MAXPID - 2, cfg->cmaxidle);
391 monitor_send_details(buf, pid);
392
393 if( cfg->max_log_size )
394 sprintf(buf + 200, "%d Kb", cfg->max_log_size);
395 else
396 strcpy(buf + 200, "unlimited");
397 sprintf(buf, "max. logsize=%s", buf + 200);
398 monitor_send_details(buf, pid);
399
400 sprintf(buf, "client timeout=%lu ms, cache delay=%ld ms", cfg->ctimeout, cfg->delay);
401 monitor_send_details(buf, pid);
402
403 //#ifdef CS_NOSHM
404 // sprintf(buf, "shared memory initialized (size=%d, fd=%d)", shmsize, shmid);
405 //#else
406 // sprintf(buf, "shared memory initialized (size=%d, id=%d)", shmsize, shmid);
407 //#endif
408 // monitor_send_details(buf, pid);
409}
410
411#ifdef CS_RDR_INIT_HIST
412static void monitor_process_details_reader(int pid, int idx){
413 int r_idx;
414 char *p;
415 if ((r_idx=cs_idx2ridx(idx))>=0)
416 for (p=(char *)reader[r_idx].init_history; *p; p+=strlen(p)+1)
417 monitor_send_details(p, pid);
418 else
419 monitor_send_details("Missing reader index !", pid);
420}
421#endif
422
423static void monitor_process_details(char *arg){
424 int pid, idx;
425 char sbuf[256];
426 if (!arg) return;
427 if ((idx = idx_from_pid(pid = atoi(arg))) < 0)
428 monitor_send_details("Invalid PID", pid);
429 else
430 {
431 monitor_send_info(monitor_client_info('D', idx), 0);
432 switch(client[idx].typ)
433 {
434 case 's':
435 monitor_process_details_master(sbuf, pid);
436 break;
437 case 'c': case 'm':
438 break;
439 case 'r':
440#ifdef CS_RDR_INIT_HIST
441 monitor_process_details_reader(pid, idx);
442#endif
443 break;
444 case 'p':
445 break;
446 }
447 }
448 monitor_send_info(NULL, 1);
449}
450
451static void monitor_send_login(void){
452 char buf[64];
453 if (auth)
454 sprintf(buf, "[A-0000]1|%s logged in\n", client[cs_idx].usr);
455 else
456 strcpy(buf, "[A-0000]0|not logged in\n");
457 monitor_send_info(buf, 1);
458}
459
460static void monitor_login(char *usr){
461 char *pwd=NULL;
462 if ((usr) && (pwd=strchr(usr, ' ')))
463 *pwd++=0;
464 if (pwd)
465 monitor_auth_client(trim(usr), trim(pwd));
466 else
467 monitor_auth_client(NULL, NULL);
468 monitor_send_login();
469}
470
471static void monitor_logsend(char *flag){
472#ifdef CS_LOGHISTORY
473 int i;
474#endif
475 if (strcmp(flag, "on")) {
476 if (strcmp(flag, "onwohist")) {
477 client[cs_idx].log=0;
478 return;
479 }
480 }
481
482 if (client[cs_idx].log) // already on
483 return;
484#ifdef CS_LOGHISTORY
485 if (!strcmp(flag, "on")){
486 for (i = (*loghistidx + 3) % CS_MAXLOGHIST; i != *loghistidx; i = (i + 1) % CS_MAXLOGHIST){
487 char *p_usr, *p_txt;
488 p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE));
489 p_txt = p_usr + 32;
490 if ((p_txt[0]) && ((client[cs_idx].monlvl > 1) || (!strcmp(p_usr, client[cs_idx].usr)))) {
491 char sbuf[8];
492 sprintf(sbuf, "%03d", client[cs_idx].logcounter);
493 client[cs_idx].logcounter=(client[cs_idx].logcounter + 1) % 1000;
494 memcpy(p_txt + 4, sbuf, 3);
495 monitor_send(p_txt);
496 }
497 }
498 }
499#endif
500 client[cs_idx].log=1;
501}
502
503static void monitor_set_debuglevel(char *flag){
504 cfg->debuglvl = atoi(flag);
505 kill(client[0].pid, SIGUSR1);
506}
507
508static void monitor_set_account(char *args){
509 struct s_auth *account;
510 char delimiter[] = " =";
511 char *ptr;
512 int argidx, i, found;
513 char *argarray[3];
514 char *token[]={"au", "sleep", "uniq", "monlevel", "group", "services", "betatunnel", "ident", "caid", "chid", "class", "hostname"};
515 int tokencnt = sizeof(token)/sizeof(char *);
516 char buf[256], tmp[64];
517
518 argidx = 0;
519 found = 0;
520
521 sprintf(tmp, "%s",args);
522 sprintf(buf, "[S-0000]setuser: %s check\n", tmp);
523 monitor_send_info(buf, 0);
524
525 ptr = strtok(args, delimiter);
526
527 // resolve arguments
528 while(ptr != NULL) {
529 argarray[argidx]=trim(ptr);
530 ptr = strtok(NULL, delimiter);
531 argidx++;
532 }
533
534 if(argidx != 3) {
535 sprintf(buf, "[S-0000]setuser: %s failed - wrong number of parameters (%d)\n",tmp, argidx);
536 monitor_send_info(buf, 0);
537 sprintf(buf, "[S-0000]setuser: %s end\n", tmp);
538 monitor_send_info(buf, 1);
539 return;
540 }
541
542 //search account
543 for (account=cfg->account; (account) ; account=account->next){
544 if (!strcmp(argarray[0], account->usr)){
545 found=1;
546 break;
547 }
548 }
549
550 if (found != 1){
551 sprintf(buf, "[S-0000]setuser: %s failed - user %s not found\n",tmp , argarray[0]);
552 monitor_send_info(buf, 0);
553 sprintf(buf, "[S-0000]setuser: %s end\n", tmp);
554 monitor_send_info(buf, 1);
555 return;
556 }
557
558 found = 0;
559 for (i = 0; i < tokencnt; i++){
560 if (!strcmp(argarray[1], token[i])){
561 // preparing the parameters before re-load
562 switch(i) {
563
564 case 6: clear_tuntab(&account->ttab); break; //betatunnel
565
566 case 8: clear_caidtab(&account->ctab); break; //Caid
567 }
568 found = i;
569 }
570 }
571
572 if (!found){
573 sprintf(buf, "[S-0000]setuser: %s failed - parameter %s not exist",tmp , argarray[1]);
574 monitor_send_info(buf, 0);
575 sprintf(buf, "[S-0000]setuser: %s end\n", tmp);
576 monitor_send_info(buf, 1);
577 return;
578 } else {
579 chk_account(token[found], argarray[2], account);
580 }
581
582 if (write_userdb()==0)
583 kill(client[0].pid, SIGHUP);
584
585 sprintf(buf, "[S-0000]setuser: %s done - param %s set to %s\n", tmp, argarray[1], argarray[2]);
586 monitor_send_info(buf, 0);
587
588 sprintf(buf, "[S-0000]setuser: %s end\n", tmp);
589 monitor_send_info(buf, 1);
590}
591
592static void monitor_set_server(char *args){
593 char delimiter[] = "=";
594 char *ptr;
595 int argidx, i, found;
596 char *argarray[3];
597 char *token[]={"clienttimeout", "fallbacktimeout", "clientmaxidle", "cachedelay", "bindwait", "netprio", "resolvedelay", "sleep", "unlockparental", "serialreadertimeout", "maxlogsize", "showecmdw", "waitforcards", "preferlocalcards"};
598 char buf[256];
599
600 argidx=0; found=0;
601 ptr = strtok(args, delimiter);
602
603 // resolve arguments
604 while(ptr != NULL) {
605 argarray[argidx]=trim(ptr);
606 ptr = strtok(NULL, delimiter);
607 argidx++;
608 }
609
610 if(argidx != 2) {
611 sprintf(buf, "[S-0000]setserver failed - wrong number of parameters (%d)\n", argidx);
612 monitor_send_info(buf, 1);
613 return;
614 }
615
616 trim(argarray[0]);
617 trim(argarray[1]);
618 strtolower(argarray[0]);
619
620 for (i = 0; i < 14; i++)
621 if (!strcmp(argarray[0], token[i])) break;
622
623 if (i < 14){
624 chk_t_global(token[i],argarray[1]);
625 sprintf(buf, "[S-0000]setserver done - param %s set to %s\n", argarray[0], argarray[1]);
626 monitor_send_info(buf, 1);
627 } else {
628 sprintf(buf, "[S-0000]setserver failed - parameter %s not exist", argarray[0]);
629 monitor_send_info(buf, 1);
630 return;
631 }
632
633 if (cfg->ftimeout>=cfg->ctimeout) {
634 cfg->ftimeout = cfg->ctimeout - 100;
635 sprintf(buf, "[S-0000]setserver WARNING: fallbacktimeout adjusted to %lu ms", cfg->ftimeout);
636 monitor_send_info(buf, 1);
637 }
638 if(cfg->ftimeout < cfg->srtimeout) {
639 cfg->ftimeout = cfg->srtimeout + 100;
640 sprintf(buf, "[S-0000]setserver WARNING: fallbacktimeout adjusted to %lu ms", cfg->ftimeout);
641 monitor_send_info(buf, 1);
642 }
643 if(cfg->ctimeout < cfg->srtimeout) {
644 cfg->ctimeout = cfg->srtimeout + 100;
645 sprintf(buf, "[S-0000]setserver WARNING: clienttimeout adjusted to %lu ms", cfg->ctimeout);
646 monitor_send_info(buf, 1);
647 }
648 //kill(client[0].pid, SIGUSR1);
649}
650
651static void monitor_list_commands(char *args[], int cmdcnt){
652 int i;
653 for (i = 0; i < cmdcnt; i++) {
654 char buf[64];
655 sprintf(buf, "[S-0000]commands: %s", args[i]);
656 if(i < cmdcnt-1)
657 monitor_send_info(buf, 0);
658 else
659 monitor_send_info(buf, 1);
660 }
661}
662
663static int monitor_process_request(char *req)
664{
665 int i, rc;
666 char *cmd[] = {"login", "exit", "log", "status", "shutdown", "reload", "details", "version", "debug", "setuser", "setserver", "commands"};
667 int cmdcnt = sizeof(cmd)/sizeof(char *); // Calculate the amount of items in array
668 char *arg;
669
670 if( (arg = strchr(req, ' ')) ) { *arg++ = 0; trim(arg); }
671 //trim(req);
672 if ((!auth) && (strcmp(req, cmd[0]))) monitor_login(NULL);
673
674 for (rc=1, i = 0; i < cmdcnt; i++)
675 if (!strcmp(req, cmd[i])) {
676 switch(i) {
677 case 0: monitor_login(arg); break; // login
678 case 1: rc=0; break; // exit
679 case 2: monitor_logsend(arg); break; // log
680 case 3: monitor_process_info(); break; // status
681 case 4: if (client[cs_idx].monlvl > 3) kill(client[0].pid, SIGQUIT); break; // shutdown
682 case 5: if (client[cs_idx].monlvl > 2) kill(client[0].pid, SIGHUP); break; // reload
683 case 6: monitor_process_details(arg); break; // details
684 case 7: monitor_send_details_version(); break; // version
685 case 8: if (client[cs_idx].monlvl > 3) monitor_set_debuglevel(arg); break; // debuglevel
686 case 9: if (client[cs_idx].monlvl > 3) monitor_set_account(arg); break; // setuser
687 case 10: if (client[cs_idx].monlvl > 3) monitor_set_server(arg); break; // setserver
688 case 11: if (client[cs_idx].monlvl > 3) monitor_list_commands(cmd, cmdcnt); break; // list commands
689 default: continue;
690 }
691 break;
692 }
693 return(rc);
694}
695
696static void monitor_server(){
697 int n;
698 client[cs_idx].typ='m';
699 while (((n = process_input(mbuf, sizeof(mbuf), cfg->cmaxidle)) >= 0) && monitor_process_request((char *)mbuf));
700 cs_disconnect_client();
701}
702
703void module_monitor(struct s_module *ph){
704 static PTAB ptab;
705 ptab.ports[0].s_port = cfg->mon_port;
706 ph->ptab = &ptab;
707 ph->ptab->nports = 1;
708
709 if (cfg->mon_aulow < 1)
710 cfg->mon_aulow = 30;
711 strcpy(ph->desc, "monitor");
712 ph->type=MOD_CONN_UDP;
713 ph->multi = 0;
714 ph->watchdog = 1;
715 ph->s_ip = cfg->mon_srvip;
716 ph->s_handler = monitor_server;
717 ph->recv = monitor_recv;
718 // ph->send_dcw=NULL;
719}
720
721
Note: See TracBrowser for help on using the repository browser.