Changeset 1691
- Timestamp:
- 02/25/10 21:46:37 (11 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Maketype
r1592 r1691 54 54 $(LIBFILE1)(oscam-nano.o) \ 55 55 $(LIBFILE1)(oscam-chk.o) \ 56 $(LIBFILE1)(oscam-http.o) \ 57 $(LIBFILE1)(oscam-http-helpers.o) \ 56 58 $(LIBFILE1)(oscam-ac.o) 57 59 -
trunk/README
r1625 r1691 10 10 - svn repository: 11 11 svn co http://streamboard.gmc.to/svn/oscam/trunk 12 13 - trac instance: 14 http://streamboard.gmc.to:8001/oscam 12 15 13 16 - wiki: -
trunk/globals.h
r1683 r1691 51 51 #include "cscrypt/cscrypt.h" 52 52 53 #ifdef HAVE_PCSC 54 #include <PCSC/pcsclite.h> 55 #ifdef OS_MACOSX 56 #include <PCSC/wintypes.h> 57 #else 58 #include <PCSC/reader.h> 59 #endif 53 #ifdef HAVE_PCSC 54 #include <PCSC/pcsclite.h> 55 #include <PCSC/wintypes.h> 56 #include <PCSC/reader.h> 60 57 #endif 61 58 … … 123 120 #define CS_ECMCACHESIZE CS_MAXPID 124 121 #define CS_EMMCACHESIZE (CS_MAXPID<<1) 122 #endif 123 125 124 #define CS_RDR_INIT_HIST 126 #endif127 128 125 #define D_TRACE 1 // Generate very detailed error/trace messages per routine 129 126 #define D_ATR 2 // Debug ATR parsing, dump of ecm, emm, cw … … 401 398 int cwignored; // count ignored ECMs per client 402 399 int cwtout; // count timeouted ECMs per client 403 uchar ucrc[4]; // needed by monitor and used by camd35 400 int cwlastresptime; //last Responsetime (ms) 401 int emmok; // count EMM ok 402 int emmnok; // count EMM nok 403 int wihidden; // hidden in webinterface status 404 uchar ucrc[4]; // needed by monitor and used by camd35 404 405 ulong pcrc; // pwd crc 405 406 AES_KEY aeskey; // needed by monitor and used by camd33, camd35 … … 421 422 struct s_reader 422 423 { 423 int smargopatch; //FIXME workaround for Smargo until native mode works 424 int smargopatch; //FIXME workaround for Smargo until native mode works 425 int pid; 424 426 int cs_idx; 425 427 int enable; … … 461 463 char * emmfile; 462 464 char pincode[5]; 463 int 465 int ucpk_valid; 464 466 int logemm; 465 467 int cachemm; 466 468 int rewritemm; 467 469 int card_status; 468 470 int deprecated; //if 0 ATR obeyed, if 1 default speed (9600) is chosen; for devices that cannot switch baudrate 469 471 struct s_module ph; 470 472 uchar ncd_key[16]; … … 481 483 int tcp_rto; // reconnect timeout 482 484 time_t last_g; // get (if last_s-last_g>tcp_rto - reconnect ) 483 time_t last_s; // send 485 time_t last_s; // send 484 486 uchar show_cls; // number of classes subscription showed on kill -31 485 487 int maxqlen; // max queue length … … 501 503 #endif 502 504 int msg_idx; 505 int emmwritten; //count written EMM 506 int emmskipped; //count skipped EMM 507 int emmerror; //count error EMM 508 int emmblocked; //count blocked EMM 503 509 #ifdef HAVE_PCSC 504 510 SCARDCONTEXT hContext; … … 569 575 int ncd_keepalive; 570 576 int disabled; 571 struct 577 struct s_auth *next; 572 578 }; 573 579 … … 593 599 { 594 600 int nice; 601 int debuglvl; 595 602 ulong netprio; 596 603 ulong ctimeout; … … 607 614 char *cwlogdir; 608 615 char *logfile; 616 int disablelog; 617 int usrfileflag; 609 618 struct s_auth *account; 610 619 struct s_srvid *srvid; … … 616 625 int mon_hideclient_to; 617 626 int mon_level; 627 #ifdef WEBIF 628 int http_port; 629 char http_user[65]; 630 char http_pwd[65]; 631 char http_css[128]; 632 char http_tpl[128]; 633 char http_script[128]; 634 int http_refresh; 635 int http_hide_idle_clients; 636 #endif 618 637 int c33_port; 619 638 in_addr_t c33_srvip; … … 660 679 int dvbapi_enabled; 661 680 int dvbapi_au; 662 char dvbapi_usr[33]; 681 char dvbapi_usr[33]; 663 682 char dvbapi_boxtype[20]; 664 683 char dvbapi_priority[64]; 665 char dvbapi_ignore[64]; 684 char dvbapi_ignore[64]; 666 685 #endif 667 686 #ifdef CS_ANTICASC … … 672 691 int ac_penalty; // 0 - write to log 673 692 int ac_fakedelay; // 100-1000 ms 674 int ac_denysamples; 693 int ac_denysamples; 675 694 char ac_logfile[128]; 676 695 struct s_cpmap *cpmap; … … 681 700 typedef struct ecm_request_t 682 701 { 683 702 684 703 uchar ecm[256]; 685 704 uchar cw[16]; … … 706 725 ushort gbxFrom; 707 726 ushort gbxTo; 708 727 709 728 uchar gbxForward[16]; 710 729 int gbxRidx; … … 749 768 extern void cs_setpriority(int); 750 769 extern struct s_auth *find_user(char *); 770 #ifdef WEBIF 771 extern int x2i(int i); 772 extern void urldecode(char *s); 773 extern char to_hex(char code); 774 extern char *urlencode(char *str); 775 extern char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]); 776 extern void create_rand_str(char *dst, int size); 777 #endif 778 extern void long2bitchar(long value, char *result); 779 extern int file_exists(const char * filename); 751 780 extern void clear_sip(struct s_ip **sip); 752 781 extern void clear_ptab(struct s_ptab *ptab); 782 extern void clear_ftab(struct s_ftab *ftab); 753 783 void clear_caidtab(struct s_caidtab *ctab); 754 784 void clear_tuntab(struct s_tuntab *ttab); 785 extern int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite); 786 extern void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...); 755 787 extern void cs_strncpy(char * destination, const char * source, size_t num); 756 788 … … 787 819 extern char* username(int); 788 820 extern int idx_from_pid(pid_t); 789 extern int idx_from_username(char *uname);790 821 extern int chk_bcaid(ECM_REQUEST *, CAIDTAB *); 791 822 extern void cs_exit(int sig); … … 819 850 extern void set_signal_handler(int , int , void (*)(int)); 820 851 extern void cs_log_config(void); 852 extern void cs_reinit_clients(void); 821 853 extern void cs_resolve(void); 822 854 extern void chk_dcw(int fd); … … 844 876 extern void init_len4caid(void); 845 877 extern int init_irdeto_guess_tab(void); 878 extern void chk_caidtab(char *caidasc, CAIDTAB *ctab); 879 extern void chk_tuntab(char *tunasc, TUNTAB *ttab); 880 extern void chk_services(char *labels, ulong *sidok, ulong *sidno); 881 extern void chk_ftab(char *zFilterAsc, FTAB *ftab, const char *zType, const char *zName, const char *zFiltName); 882 extern void chk_cltab(char *classasc, CLASSTAB *clstab); 883 extern void chk_iprange(char *value, struct s_ip **base); 884 extern void chk_port_tab(char *portasc, PTAB *ptab); 885 #ifdef CS_ANTICASC 886 extern void chk_t_ac(char *token, char *value); 887 #endif 888 extern void chk_t_camd33(char *token, char *value); 889 extern void chk_t_camd35(char *token, char *value); 890 extern void chk_t_camd35_tcp(char *token, char *value); 891 extern void chk_t_newcamd(char *token, char *value); 892 extern void chk_t_radegast(char *token, char *value); 893 extern void chk_t_serial(char *token, char *value); 894 extern void chk_t_gbox(char *token, char *value); 895 extern void chk_t_cccam(char *token, char *value); 896 extern void chk_t_global(char *token, char *value); 897 extern void chk_t_monitor(char *token, char *value); 898 extern void chk_t_dvbapi(char *token, char *value); 899 extern void chk_account(char *token, char *value, struct s_auth *account); 900 extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab); 901 extern int write_services(); 902 extern int write_userdb(); 903 extern int write_config(); 904 extern char *mk_t_caidtab(CAIDTAB *ctab); 905 extern char *mk_t_tuntab(TUNTAB *ttab); 906 extern char *mk_t_group(ulong *grp); 907 extern char *mk_t_ftab(FTAB *ftab); 846 908 847 909 // oscam-reader … … 906 968 #endif 907 969 extern struct timeval *chk_pending(struct timeb tp_ctimeout); 970 971 // module-monitor 972 extern char *monitor_get_proto(int idx); 973 extern char *monitor_get_srvname(int srvid, int caid); 974 extern int cs_idx2ridx(int idx); 975 976 #ifdef WEBIF 977 // oscam-http 978 extern void http_srv(); 979 #endif 980 908 981 #endif // CS_GLOBALS -
trunk/module-camd35.c
r1626 r1691 90 90 case 0: break; // ok 91 91 case 1: rc=-2; break; // unknown user 92 default: rc=-9; break; // error's from cs_auth() 92 default: rc=-9; break; // error's from cs_auth() 93 93 } 94 94 break; … … 199 199 mbuf[129]=(reader[au].b_nano[0xd2])?0:1; 200 200 mbuf[130]=(reader[au].b_nano[0xd3])?0:1;*/ 201 //we think client/server protocols should deliver all information, and only readers should discard EMM 201 //we think client/server protocols should deliver all information, and only readers should discard EMM 202 202 mbuf[128]=1; //if 0, GA EMM is blocked 203 203 mbuf[129]=1; //if 0, SA EMM is blocked … … 305 305 } 306 306 } 307 307 308 308 if(req) { free(req); req=0;} 309 309 310 310 cs_disconnect_client(); 311 311 } … … 385 385 reader[ridx].device, reader[ridx].r_port, 386 386 client[cs_idx].udp_fd, ptxt); 387 387 388 388 if (is_udp) pfd=client[cs_idx].udp_fd; 389 389 … … 429 429 cs_log("camd3 loghost initialized (fd=%d, port=%d)", 430 430 logfd, reader[ridx].log_port); 431 431 432 432 return(0); 433 433 } … … 435 435 static int tcp_connect() 436 436 { 437 if (!reader[ridx].tcp_connected) 437 if (!reader[ridx].tcp_connected) 438 438 { 439 439 int handle=0; … … 442 442 443 443 reader[ridx].tcp_connected = 1; 444 reader[ridx].last_s = reader[ridx].last_g = time((time_t *)0); 444 reader[ridx].last_s = reader[ridx].last_g = time((time_t *)0); 445 445 pfd = client[cs_idx].udp_fd = handle; 446 } 446 } 447 447 if (!client[cs_idx].udp_fd) return(0); 448 448 return(1); … … 501 501 if (!(ptr2=(uchar *)strchr((char *)ptr, ' '))) return(-1); // corrupt 502 502 *ptr2=0; 503 503 504 504 for (i=0, ptr2=(uchar *)strtok((char *)ptr, ":"); ptr2; i++, ptr2=(uchar *)strtok(NULL, ":")) 505 505 { … … 551 551 ph->watchdog=1; 552 552 ph->ptab=&cfg->c35_tcp_ptab; 553 if (ph->ptab->nports==0) 553 if (ph->ptab->nports==0) 554 554 ph->ptab->nports=1; // show disabled in log 555 555 ph->s_ip=cfg->c35_tcp_srvip; -
trunk/module-monitor.c
r1617 r1691 7 7 #endif 8 8 9 static int auth=0;9 static int auth = 0; 10 10 11 11 static void monitor_check_ip() … … 208 208 { 209 209 if (btxt[0]) monitor_send(btxt); 210 strncpy(btxt, txt, sizeof(btxt));210 cs_strncpy(btxt, txt, sizeof(btxt)); 211 211 return; 212 212 } … … 216 216 monitor_send(btxt); 217 217 txt[2]='E'; 218 strncpy(btxt, txt, sizeof(btxt));218 cs_strncpy(btxt, txt, sizeof(btxt)); 219 219 } 220 220 else 221 221 { 222 222 if (txt) 223 strncpy(btxt, txt, sizeof(btxt));223 cs_strncpy(btxt, txt, sizeof(btxt)); 224 224 btxt[2]=(btxt[2]=='B') ? 'S' : 'E'; 225 225 } … … 233 233 } 234 234 235 int cs_idx2ridx(int idx) 236 { 237 int i; 238 for (i=0; i<CS_MAXREADER; i++) 239 if (reader[i].cs_idx==idx) 240 return(i); 241 return(-1); 235 int 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); 242 241 } 243 242 … … 251 250 for (i=0; i<this->ncaid; i++) 252 251 if (this->caid[i] == caid) 253 strncpy(name, this->name, 32);252 cs_strncpy(name, this->name, 32); 254 253 255 254 if (!name[0]) sprintf(name, "[%04X:%04X]", caid, srvid); … … 299 298 } 300 299 301 static char *monitor_client_info(char id, int i) 302 { 303 static char sbuf[256]; 304 305 sbuf[0]='\0'; 306 if (client[i].pid) 307 { 308 char ldate[16], ltime[16], *usr; 309 int lsec, isec, cnr, con, cau; 310 time_t now; 311 struct tm *lt; 312 now=time((time_t)0); 313 314 if ((cfg->mon_hideclient_to <= 0) || 315 (((now-client[i].lastemm)/60)<cfg->mon_hideclient_to) || 316 (client[i].typ!='c')) 317 { 318 lsec=now-client[i].login; 319 isec=now-client[i].last; 320 usr=client[i].usr; 321 if (((client[i].typ=='r') || (client[i].typ=='p')) && 322 (con=cs_idx2ridx(i))>=0) 323 usr=reader[con].label; 324 if (client[i].dup) 325 con=2; 326 else 327 if ((client[i].tosleep) && 328 (now-client[i].lastswitch>client[i].tosleep)) 329 con=1; 330 else 331 con=0; 332 if (i-cdiff>0) 333 cnr=i-cdiff; 334 else 335 cnr=(i>1) ? i-1 : 0; 336 if( (cau=client[i].au+1) ) 337 if ((now-client[i].lastemm)/60>cfg->mon_aulow) 338 cau=-cau; 339 lt=localtime(&client[i].login); 340 sprintf(ldate, "%2d.%02d.%02d", 341 lt->tm_mday, lt->tm_mon+1, lt->tm_year % 100); 342 sprintf(ltime, "%2d:%02d:%02d", 343 lt->tm_hour, lt->tm_min, lt->tm_sec); 344 sprintf(sbuf, "[%c--CCC]%d|%c|%d|%s|%d|%d|%s|%d|%s|%s|%s|%d|%04X:%04X|%s|%d|%d\n", 345 id, client[i].pid, client[i].typ, cnr, usr, cau, client[i].crypted, 346 cs_inet_ntoa(client[i].ip), client[i].port, monitor_get_proto(i), 347 ldate, ltime, lsec, client[i].last_caid, client[i].last_srvid, 348 monitor_get_srvname(client[i].last_srvid, client[i].last_caid), isec, con); 349 } 350 } 351 return(sbuf); 300 static 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); 352 346 } 353 347 … … 372 366 } 373 367 monitor_send_info(NULL, 1); 374 } 375 376 static void monitor_send_details(char *txt, int pid) 377 { 378 char buf[256]; 379 snprintf(buf, 255, "[D-----]%d|%s\n", pid, txt); 380 monitor_send_info(buf, 0); 381 } 382 383 static void monitor_send_details_version() 384 { 385 char buf[256]; 386 sprintf(buf, "[A-0000]version=%s, build=%s, system=%s%s", CS_VERSION_X, CS_SVN_VERSION, cs_platform(buf+100), buf+200); 387 monitor_send_info(buf, 1); 388 } 389 390 static void monitor_process_details_master(char *buf, int pid) 391 { 392 if (cfg->nice!=99) 393 sprintf(buf+200, ", nice=%d", cfg->nice); 394 else 395 buf[200]='\0'; 396 sprintf(buf, "version=%s#%s, system=%s%s", CS_VERSION_X, CS_SVN_VERSION, cs_platform(buf+100), buf+200); 397 monitor_send_details(buf, pid); 398 399 sprintf(buf, "max. clients=%d, client max. idle=%ld sec", CS_MAXPID-2, cfg->cmaxidle); 400 monitor_send_details(buf, pid); 401 402 if( cfg->max_log_size ) 403 sprintf(buf+200, "%d Kb", cfg->max_log_size); 404 else 405 strcpy(buf+200, "unlimited"); 406 sprintf(buf, "max. logsize=%s", buf+200); 407 monitor_send_details(buf, pid); 408 409 sprintf(buf, "client timeout=%lu ms, cache delay=%ld ms", cfg->ctimeout, cfg->delay); 410 monitor_send_details(buf, pid); 368 } 369 370 static 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 376 static 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 382 static 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); 411 402 412 403 //#ifdef CS_NOSHM … … 419 410 420 411 #ifdef CS_RDR_INIT_HIST 421 static void monitor_process_details_reader(int pid, int idx) 422 { 423 int r_idx; 424 char *p; 425 if ((r_idx=cs_idx2ridx(idx))>=0) 426 for (p=(char *)reader[r_idx].init_history; *p; p+=strlen(p)+1) 427 monitor_send_details(p, pid); 428 else 429 monitor_send_details("Missing reader index !", pid); 412 static 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); 430 420 } 431 421 #endif 432 422 433 static void monitor_process_details(char *arg) 434 { 435 int pid, idx; 436 char sbuf[256]; 437 if (!arg) return; 438 if ((idx=idx_from_pid(pid=atoi(arg)))<0) 439 monitor_send_details("Invalid PID", pid); 440 else 441 { 442 monitor_send_info(monitor_client_info('D', idx), 0); 443 switch(client[idx].typ) 444 { 445 case 's': 446 monitor_process_details_master(sbuf, pid); 447 break; 448 case 'c': case 'm': 449 break; 450 case 'r': 423 static 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': 451 440 #ifdef CS_RDR_INIT_HIST 452 441 monitor_process_details_reader(pid, idx); 453 442 #endif 454 break; 455 case 'p': 456 break; 457 } 458 } 459 monitor_send_info(NULL, 1); 460 } 461 462 static void monitor_send_login(void) 463 { 464 char buf[64]; 465 if (auth) 466 sprintf(buf, "[A-0000]1|%s logged in\n", client[cs_idx].usr); 467 else 468 strcpy(buf, "[A-0000]0|not logged in\n"); 469 monitor_send_info(buf, 1); 470 } 471 472 static void monitor_login(char *usr) 473 { 474 char *pwd=NULL; 475 if ((usr) && (pwd=strchr(usr, ' '))) 476 *pwd++=0; 477 if (pwd) 478 monitor_auth_client(trim(usr), trim(pwd)); 479 else 480 monitor_auth_client(NULL, NULL); 481 monitor_send_login(); 482 } 483 484 static void monitor_logsend(char *flag) 485 { 443 break; 444 case 'p': 445 break; 446 } 447 } 448 monitor_send_info(NULL, 1); 449 } 450 451 static 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 460 static 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 471 static void monitor_logsend(char *flag){ 486 472 #ifdef CS_LOGHISTORY 487 473 int i; 488 474 #endif 489 490 491 492 493 494 495 496 497 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; 498 484 #ifdef CS_LOGHISTORY 499 if (!strcmp(flag, "on")){ 500 for (i=(*loghistidx+3) % CS_MAXLOGHIST; i!=*loghistidx; i=(i+1) % CS_MAXLOGHIST) 501 { 502 char *p_usr, *p_txt; 503 p_usr=(char *)(loghist+(i*CS_LOGHISTSIZE)); 504 p_txt=p_usr+32; 505 if ((p_txt[0]) && 506 ((client[cs_idx].monlvl>1) || (!strcmp(p_usr, client[cs_idx].usr)))) 507 { 508 char sbuf[8]; 509 sprintf(sbuf, "%03d", client[cs_idx].logcounter); 510 client[cs_idx].logcounter=(client[cs_idx].logcounter+1) % 1000; 511 memcpy(p_txt+4, sbuf, 3); 512 monitor_send(p_txt); 513 } 514 } 515 } 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 } 516 499 #endif 517 client[cs_idx].log=1; 518 } 519 static void monitor_set_debuglevel(char *flag) 520 { 521 cs_dblevel^=atoi(flag); 522 kill(client[0].pid, SIGUSR1); 500 client[cs_idx].log=1; 501 } 502 503 static void monitor_set_debuglevel(char *flag){ 504 cfg->debuglvl = atoi(flag); 505 kill(client[0].pid, SIGUSR1); 506 } 507 508 static 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", "refresh"}; 515 int tokencnt = sizeof(token)/sizeof(char *); 516 char buf[256]; 517 518 argidx = 0; 519 found = 0; 520 521 ptr = strtok(args, delimiter); 522 523 // resolve arguments 524 while(ptr != NULL) { 525 argarray[argidx]=trim(ptr); 526 ptr = strtok(NULL, delimiter); 527 argidx++; 528 } 529 530 if(!strcmp(argarray[1], "refresh")){ 531 kill(client[0].pid, SIGHUP); 532 }else{ 533 if(argidx != 3) { 534 sprintf(buf, "[S-0000]setuser failed - wrong number of parameters (%d)\n", argidx); 535 monitor_send_info(buf, 1); 536 return; 537 } 538 } 539 540 //search account 541 for (account=cfg->account; (account) ; account=account->next){ 542 if (!strcmp(argarray[0], account->usr)){ 543 found=1; 544 break; 545 } 546 } 547 548 if (found != 1){ 549 sprintf(buf, "[S-0000]setuser failed - user %s not found\n", argarray[0]); 550 monitor_send_info(buf, 1); 551 return; 552 } 553 554 found = 0; 555 for (i = 0; i < tokencnt; i++){ 556 if (!strcmp(argarray[1], token[i])){ 557 // preparing the parameters before re-load 558 switch(i) { 559 560 case 6: clear_tuntab(&account->ttab); break; //betatunnel 561 562 case 8: clear_caidtab(&account->ctab); break; //Caid 563 564 565 566 567 } 568 found = 1; 569 } 570 } 571 572 if (found != 1){ 573 sprintf(buf, "[S-0000]setuser failed - parameter %s not exist", argarray[1]); 574 monitor_send_info(buf, 1); 575 return; 576 } else { 577 chk_account(token[i],argarray[2],account); 578 } 579 580 cs_reinit_clients(); 581 582 sprintf(buf, "[S-0000]setuser %s done - param %s set to %s\n", argarray[0], argarray[1], argarray[2]); 583 monitor_send_info(buf, 1); 584 } 585 586 static void monitor_set_server(char *args){ 587 char delimiter[] = "="; 588 char *ptr; 589 int argidx, i, found; 590 char *argarray[3]; 591 char *token[]={"clienttimeout", "fallbacktimeout", "clientmaxidle", "cachedelay", "bindwait", "netprio", "resolvedelay", "sleep", "unlockparental", "serialreadertimeout", "maxlogsize", "showecmdw", "waitforcards", "preferlocalcards"}; 592 char buf[256]; 593 594 argidx=0; found=0; 595 ptr = strtok(args, delimiter); 596 597 // resolve arguments 598 while(ptr != NULL) { 599 argarray[argidx]=trim(ptr); 600 ptr = strtok(NULL, delimiter); 601 argidx++; 602 } 603 604 if(argidx != 2) { 605 sprintf(buf, "[S-0000]setserver failed - wrong number of parameters (%d)\n", argidx); 606 monitor_send_info(buf, 1); 607 return; 608 } 609 610 trim(argarray[0]); 611 trim(argarray[1]); 612 strtolower(argarray[0]); 613 614 for (i = 0; i < 14; i++) 615 if (!strcmp(argarray[0], token[i])) break; 616 617 if (i < 14){ 618 chk_t_global(token[i],argarray[1]); 619 sprintf(buf, "[S-0000]setserver done - param %s set to %s\n", argarray[0], argarray[1]); 620 monitor_send_info(buf, 1); 621 } else { 622 sprintf(buf, "[S-0000]setserver failed - parameter %s not exist", argarray[0]); 623 monitor_send_info(buf, 1); 624 return; 625 } 626 627 if (cfg->ftimeout>=cfg->ctimeout) { 628 cfg->ftimeout = cfg->ctimeout - 100; 629 sprintf(buf, "[S-0000]setserver WARNING: fallbacktimeout adjusted to %lu ms", cfg->ftimeout); 630 monitor_send_info(buf, 1); 631 } 632 if(cfg->ftimeout < cfg->srtimeout) { 633 cfg->ftimeout = cfg->srtimeout + 100; 634 sprintf(buf, "[S-0000]setserver WARNING: fallbacktimeout adjusted to %lu ms", cfg->ftimeout); 635 monitor_send_info(buf, 1); 636 } 637 if(cfg->ctimeout < cfg->srtimeout) { 638 cfg->ctimeout = cfg->srtimeout + 100; 639 sprintf(buf, "[S-0000]setserver WARNING: clienttimeout adjusted to %lu ms", cfg->ctimeout); 640 monitor_send_info(buf, 1); 641 } 642 //kill(client[0].pid, SIGUSR1); 523 643 } 524 644 525 645 static int monitor_process_request(char *req) 526 646 { 527 int i, rc; 528 char *cmd[]={"login", "exit", "log", "status", "shutdown", "reload", "details", "version", "debug"}; 529 char *arg; 530 if( (arg=strchr(req, ' ')) ) 531 { 532 *arg++=0; 533 trim(arg); 534 } 535 trim(req); 536 if ((!auth) && (strcmp(req, cmd[0]))) 537 monitor_login(NULL); 538 for (rc=1, i=0; i<9; i++) 539 if (!strcmp(req, cmd[i])) 540 { 541 switch(i) 542 { 543 case 0: monitor_login(arg); break; // login 544 case 1: rc=0; break; // exit 545 case 2: monitor_logsend(arg); break; // log 546 case 3: monitor_process_info(); break; // status 547 case 4: if (client[cs_idx].monlvl>3) 548 kill(client[0].pid, SIGQUIT); // shutdown 549 break; 550 case 5: if (client[cs_idx].monlvl>2) 551 kill(client[0].pid, SIGHUP); // reload 552 break; 553 case 6: monitor_process_details(arg); break; // details 554 case 7: monitor_send_details_version(); break; 555 case 8: if (client[cs_idx].monlvl>3) 556 monitor_set_debuglevel(arg); // debuglevel 557 break; 558 default: continue; 559 } 560 break; 561 } 562 return(rc); 563 } 564 565 static void monitor_server() 566 { 567 int n; 568 client[cs_idx].typ='m'; 569 while (((n=process_input(mbuf, sizeof(mbuf), cfg->cmaxidle))>=0) && 570 monitor_process_request((char *)mbuf)); 571 cs_disconnect_client(); 572 } 573 574 void module_monitor(struct s_module *ph) 575 { 576 static PTAB ptab; 577 ptab.ports[0].s_port = cfg->mon_port; 578 ph->ptab = &ptab; 579 ph->ptab->nports = 1; 580 581 if (cfg->mon_aulow<1) 582 cfg->mon_aulow=30; 583 strcpy(ph->desc, "monitor"); 584 ph->type=MOD_CONN_UDP; 585 ph->multi=0; 586 ph->watchdog=1; 587 ph->s_ip=cfg->mon_srvip; 588 ph->s_handler=monitor_server; 589 ph->recv=monitor_recv; 647 int i, rc; 648 char *cmd[] = {"login", "exit", "log", "status", "shutdown", "reload", "details", "version", "debug", "setuser", "setserver"}; 649 int cmdcnt = sizeof(cmd)/sizeof(char *); // Calculate the amount of items in array 650 char *arg; 651 652 if( (arg = strchr(req, ' ')) ) { *arg++ = 0; trim(arg); } 653 //trim(req); 654 if ((!auth) && (strcmp(req, cmd[0]))) monitor_login(NULL); 655 656 for (rc=1, i = 0; i < cmdcnt; i++) 657 if (!strcmp(req, cmd[i])) { 658 switch(i) { 659 case 0: monitor_login(arg); break; // login 660 case 1: rc=0; break; // exit 661 case 2: monitor_logsend(arg); break; // log 662 case 3: monitor_process_info(); break; // status 663 case 4: if (client[cs_idx].monlvl > 3) kill(client[0].pid, SIGQUIT); break; // shutdown 664 case 5: if (client[cs_idx].monlvl > 2) kill(client[0].pid, SIGHUP); break; // reload 665 case 6: monitor_process_details(arg); break; // details 666 case 7: monitor_send_details_version(); break; // version 667 case 8: if (client[cs_idx].monlvl > 3) monitor_set_debuglevel(arg); break; // debuglevel 668 case 9: if (client[cs_idx].monlvl > 3) monitor_set_account(arg); break; // setuser 669 case 10: if (client[cs_idx].monlvl > 3) monitor_set_server(arg); break; // setserver 670 default: continue; 671 } 672 break; 673 } 674 return(rc); 675 } 676 677 static void monitor_server(){ 678 int n; 679 client[cs_idx].typ='m'; 680 while (((n = process_input(mbuf, sizeof(mbuf), cfg->cmaxidle)) >= 0) && monitor_process_request((char *)mbuf)); 681 cs_disconnect_client(); 682 } 683 684 void module_monitor(struct s_module *ph){ 685 static PTAB ptab; 686 ptab.ports[0].s_port = cfg->mon_port; 687 ph->ptab = &ptab; 688 ph->ptab->nports = 1; 689 690 if (cfg->mon_aulow < 1) 691 cfg->mon_aulow = 30; 692 strcpy(ph->desc, "monitor"); 693 ph->type=MOD_CONN_UDP; 694 ph->multi = 0; 695 ph->watchdog = 1; 696 ph->s_ip = cfg->mon_srvip; 697 ph->s_handler = monitor_server; 698 ph->recv = monitor_recv; 590 699 // ph->send_dcw=NULL; 591 700 } 701 702 -
trunk/module-serial.c
r1584 r1691 191 191 oscam_ser_baud=B9600; 192 192 } 193 strncpy(oscam_ser_usr, usr, sizeof(oscam_ser_usr)-1);194 strncpy(oscam_ser_device, dev, sizeof(oscam_ser_device)-1);193 cs_strncpy(oscam_ser_usr, usr, sizeof(oscam_ser_usr)); 194 cs_strncpy(oscam_ser_device, dev, sizeof(oscam_ser_device)); 195 195 return(oscam_ser_baud); 196 196 } -
trunk/oscam-config.c
r1690 r1691 273 273 static void chk_srvip(char *value, in_addr_t *ip) 274 274 { 275 276 277 278 if (i<8) ip[i++]=inet_addr(ptr);275 int i; 276 char *ptr; 277 for (i=0, ptr=strtok(value, ","); ptr; ptr=strtok(NULL, ",")) 278 if (i<8) ip[i++] = inet_addr(ptr); 279 279 } 280 280 #endif … … 282 282 void chk_t_global(char *token, char *value) 283 283 { 284 if (!strcmp(token, "disablelog")) { 285 if (strlen(value) == 0) { 286 cfg->disablelog = 0; 287 return; 288 } else { 289 cfg->disablelog = atoi(value); 290 return; 291 } 292 } 293 284 294 if (!strcmp(token, "serverip")) { 285 295 if (strlen(value) == 0) { … … 330 340 asprintf(&(cfg->cwlogdir), "%s", value); 331 341 return; 342 } 343 344 if (!strcmp(token, "usrfileflag")) { 345 if (strlen(value) == 0) { 346 cfg->usrfileflag = 0; 347 return; 348 } else { 349 cfg->usrfileflag = atoi(value); 350 return; 351 } 332 352 } 333 353 … … 544 564 545 565 if (token[0] != '#') 546 cs_log( "Warning: keyword '%s' in anticascading section not recognized",token);566 cs_log( "Warning: keyword '%s' in anticascading section not recognized",token); 547 567 } 548 568 #endif … … 599 619 } 600 620 } 621 622 #ifdef WEBIF 623 if (!strcmp(token, "httpport")) { 624 if(strlen(value) == 0) { 625 cfg->http_port = 0; 626 return; 627 } else { 628 cfg->http_port = atoi(value); 629 return; 630 } 631 } 632 633 if (!strcmp(token, "httpuser")) { 634 cs_strncpy(cfg->http_user, value, sizeof(cfg->http_user)); 635 return; 636 } 637 638 if (!strcmp(token, "httppwd")) { 639 cs_strncpy(cfg->http_pwd, value, sizeof(cfg->http_pwd)); 640 return; 641 } 642 643 if (!strcmp(token, "httpcss")) { 644 cs_strncpy(cfg->http_css, value, sizeof(cfg->http_css)); 645 return; 646 } 647 648 if (!strcmp(token, "httpscript")) { 649 cs_strncpy(cfg->http_script, value, sizeof(cfg->http_script)); 650 return; 651 } 652 653 if (!strcmp(token, "httptpl")) { 654 cs_strncpy(cfg->http_tpl, value, sizeof(cfg->http_tpl)); 655 if(strlen(cfg->http_tpl) < (sizeof(cfg->http_tpl)-2) && cfg->http_tpl[strlen(cfg->http_tpl)-1] != '/') { 656 cfg->http_tpl[strlen(cfg->http_tpl)] = '/'; 657 cfg->http_tpl[strlen(cfg->http_tpl)] = '\0'; 658 } 659 return; 660 } 661 662 if (!strcmp(token, "httprefresh")) { 663 if(strlen(value) == 0) { 664 cfg->http_refresh = 0; 665 return; 666 } else { 667 cfg->http_refresh = atoi(value); 668 return; 669 } 670 } 671 672 if (!strcmp(token, "httphideidleclients")) { 673 if(strlen(value) == 0) { 674 cfg->http_hide_idle_clients = 0; 675 return; 676 } else { 677 cfg->http_hide_idle_clients=atoi(value); 678 return; 679 } 680 } 681 #endif 601 682 602 683 if (!strcmp(token, "hideclient_to")) { … … 660 741 661 742 if (token[0] != '#') 662 cs_log( "Warning: keyword '%s' in camd33 section not recognized",token);743 cs_log( "Warning: keyword '%s' in camd33 section not recognized",token); 663 744 } 664 745 … … 696 777 697 778 if (token[0] != '#') 698 cs_log( "Warning: keyword '%s' in camd35 section not recognized", token);779 cs_log( "Warning: keyword '%s' in camd35 section not recognized", token); 699 780 } 700 781 … … 732 813 733 814 if (token[0] != '#') 734 cs_log( "Warning: keyword '%s' in camd35 tcp section not recognized", token);815 cs_log( "Warning: keyword '%s' in camd35 tcp section not recognized", token); 735 816 } 736 817 … … 786 867 787 868 if (token[0] != '#') 788 cs_log( "Warning: keyword '%s' in newcamd section not recognized", token);869 cs_log( "Warning: keyword '%s' in newcamd section not recognized", token); 789 870 } 790 871 … … 833 914 834 915 if (token[0] != '#') 835 cs_log( "Warning: keyword '%s' in cccam section not recognized",token);916 cs_log( "Warning: keyword '%s' in cccam section not recognized",token); 836 917 } 837 918 … … 874 955 875 956 if (token[0] != '#') 876 cs_log( "Warning: keyword '%s' in radegast section not recognized", token);957 cs_log( "Warning: keyword '%s' in radegast section not recognized", token); 877 958 } 878 959 … … 888 969 } 889 970 if (token[0] != '#') 890 cs_log( "Warning: keyword '%s' in serial section not recognized", token);971 cs_log( "Warning: keyword '%s' in serial section not recognized", token); 891 972 } 892 973 … … 913 994 } 914 995 if (token[0] != '#') 915 cs_log("Warning: keyword '%s' in gbox section not recognized\n",token);996 fprintf(stderr, "Warning: keyword '%s' in gbox section not recognized\n",token); 916 997 } 917 998 #endif … … 928 1009 929 1010 if (token[0] != '#') 930 cs_log("Warning: keyword '%s' in dvbapi section not recognized\n",token);1011 fprintf(stderr, "Warning: keyword '%s' in dvbapi section not recognized\n",token); 931 1012 } 932 1013 #endif … … 951 1032 case TAG_DVBAPI : chk_t_dvbapi(token, value); break; 952 1033 #else 953 case TAG_DVBAPI : cs_log("Warning: OSCam compiled without DVB API support.\n"); break;1034 case TAG_DVBAPI : fprintf(stderr, "Warning: OSCam compiled without DVB API support.\n"); break; 954 1035 #endif 955 1036 #ifdef CS_ANTICASC … … 1062 1143 cfg->usrfile = NULL; 1063 1144 cfg->cwlogdir = NULL; 1145 #ifdef WEBIF 1146 strcpy(cfg->http_user, ""); 1147 strcpy(cfg->http_pwd, ""); 1148 strcpy(cfg->http_css, ""); 1149 cfg->http_refresh = 0; 1150 cfg->http_hide_idle_clients = 0; 1151 strcpy(cfg->http_tpl, ""); 1152 #endif 1064 1153 cfg->ncd_keepalive = 1; 1065 1154 #ifdef CS_ANTICASC … … 1297 1386 1298 1387 if (token[0] != '#') 1299 cs_log("Warning: keyword '%s' in account section not recognized",token); 1388 cs_log( "Warning: keyword '%s' in account section not recognized",token); 1389 } 1390 1391 int write_services() 1392 { 1393 int i; 1394 FILE *f; 1395 struct s_sidtab *sidtab = cfg->sidtab; 1396 char tmpfile[256]; 1397 char destfile[256]; 1398 char bakfile[256]; 1399 1400 snprintf(destfile, 255,"%s%s", cs_confdir, cs_sidt); 1401 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_sidt); 1402 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_sidt); 1403 1404 if (!(f=fopen(tmpfile, "w"))){ 1405 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno); 1406 return(1); 1407 } 1408 fprintf(f,"#oscam.services generated automatically\n\n"); 1409 1410 while(sidtab != NULL){ 1411 fprintf(f,"[%s]\n", sidtab->label); 1412 fprintf_conf(f, CONFVARWIDTH, "caid", ""); 1413 for (i=0; i<sidtab->num_caid; i++){ 1414 if (i==0) fprintf(f,"%04X", sidtab->caid[i]); 1415 else fprintf(f,",%04X", sidtab->caid[i]); 1416 } 1417 fputc((int)'\n', f); 1418 fprintf_conf(f, CONFVARWIDTH, "provid", ""); 1419 for (i=0; i<sidtab->num_provid; i++){ 1420 if (i==0) fprintf(f,"%06lX", sidtab->provid[i]); 1421 else fprintf(f,",%06lX", sidtab->provid[i]); 1422 } 1423 fputc((int)'\n', f); 1424 fprintf_conf(f, CONFVARWIDTH, "srvid", ""); 1425 for (i=0; i<sidtab->num_srvid; i++){ 1426 if (i==0) fprintf(f,"%04X", sidtab->srvid[i]); 1427 else fprintf(f,",%04X", sidtab->srvid[i]); 1428 } 1429 fprintf(f,"\n\n"); 1430 sidtab=sidtab->next; 1431 } 1432 1433 fclose(f); 1434 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0)); 1435 } 1436 1437 int write_config() 1438 { 1439 int i,j; 1440 FILE *f; 1441 char *dot = "", *dot1 = "", *dot2 = ""; //flags for delimiters 1442 char tmpfile[256]; 1443 char destfile[256]; 1444 char bakfile[256]; 1445 1446 snprintf(destfile, 255,"%s%s", cs_confdir, cs_conf); 1447 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_conf); 1448 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_conf); 1449 1450 if (!(f=fopen(tmpfile, "w"))){ 1451 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno); 1452 return(1); 1453 } 1454 fprintf(f,"#oscam.config generated automatically\n\n"); 1455 1456 /*global settings*/ 1457 fprintf(f,"[global]\n"); 1458 if (cfg->srvip != 0) 1459 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->srvip)); 1460 if (cfg->pidfile != NULL) fprintf_conf(f, CONFVARWIDTH, "pidfile", "%s\n", cfg->pidfile); 1461 if (cfg->usrfile != NULL) fprintf_conf(f, CONFVARWIDTH, "usrfile", "%s\n", cfg->usrfile); 1462 if (cfg->logfile != NULL) fprintf_conf(f, CONFVARWIDTH, "logfile", "%s\n", cfg->logfile); 1463 if (cfg->cwlogdir != NULL) fprintf_conf(f, CONFVARWIDTH, "cwlogdir", "%s\n", cfg->cwlogdir); 1464 fprintf_conf(f, CONFVARWIDTH, "usrfileflag", "%d\n", cfg->usrfileflag); 1465 fprintf_conf(f, CONFVARWIDTH, "clienttimeout", "%ld\n", cfg->ctimeout/1000); 1466 fprintf_conf(f, CONFVARWIDTH, "fallbacktimeout", "%ld\n", cfg->ftimeout/1000); 1467 fprintf_conf(f, CONFVARWIDTH, "clientmaxidle", "%d\n", cfg->cmaxidle); 1468 fprintf_conf(f, CONFVARWIDTH, "cachedelay", "%ld\n", cfg->delay); 1469 fprintf_conf(f, CONFVARWIDTH, "bindwait", "%d\n", cfg->bindwait); 1470 fprintf_conf(f, CONFVARWIDTH, "netprio", "%ld\n", cfg->netprio); 1471 fprintf_conf(f, CONFVARWIDTH, "resolvedelay", "%d\n", cfg->resolvedelay); 1472 if (cfg->tosleep) fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", cfg->tosleep); 1473 fprintf_conf(f, CONFVARWIDTH, "unlockparental", "%d\n", cfg->ulparent); 1474 fprintf_conf(f, CONFVARWIDTH, "nice", "%d\n", cfg->nice); 1475 fprintf_conf(f, CONFVARWIDTH, "serialreadertimeout", "%d\n", cfg->srtimeout); 1476 fprintf_conf(f, CONFVARWIDTH, "maxlogsize", "%d\n", cfg->max_log_size); 1477 fprintf_conf(f, CONFVARWIDTH, "waitforcards", "%d\n", cfg->waitforcards); 1478 fprintf_conf(f, CONFVARWIDTH, "preferlocalcards", "%d\n", cfg->preferlocalcards); 1479 fputc((int)'\n', f); 1480 1481 /*monitor settings*/ 1482 fprintf(f,"[monitor]\n"); 1483 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->mon_port); 1484 if (cfg->mon_srvip != 0) 1485 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->mon_srvip)); 1486 1487 fprintf_conf(f, CONFVARWIDTH, "nocrypt", ""); 1488 struct s_ip *cip; 1489 for (cip = cfg->mon_allowed; cip; cip = cip->next){ 1490 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0])); 1491 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1])); 1492 dot=","; 1493 } 1494 fputc((int)'\n', f); 1495 fprintf_conf(f, CONFVARWIDTH, "aulow", "%d\n", cfg->mon_aulow); 1496 fprintf_conf(f, CONFVARWIDTH, "hideclient_to", "%d\n", cfg->mon_hideclient_to); 1497 fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", cfg->mon_level); 1498 #ifdef WEBIF 1499 fprintf_conf(f, CONFVARWIDTH, "httpport", "%d\n", cfg->http_port); 1500 fprintf_conf(f, CONFVARWIDTH, "httpuser", "%s\n", cfg->http_user); 1501 fprintf_conf(f, CONFVARWIDTH, "httppwd", "%s\n", cfg->http_pwd); 1502 fprintf_conf(f, CONFVARWIDTH, "httpcss", "%s\n", cfg->http_css); 1503 fprintf_conf(f, CONFVARWIDTH, "httpscript", "%s\n", cfg->http_script); 1504 fprintf_conf(f, CONFVARWIDTH, "httprefresh", "%d\n", cfg->http_refresh); 1505 fprintf_conf(f, CONFVARWIDTH, "httphideidleclients", "%d\n", cfg->http_hide_idle_clients); 1506 #endif 1507 fputc((int)'\n', f); 1508 1509 /*newcamd*/ 1510 if ((cfg->ncd_ptab.nports > 0) && (cfg->ncd_ptab.ports[0].s_port > 0)){ 1511 fprintf(f,"[newcamd]\n"); 1512 fprintf_conf(f, CONFVARWIDTH, "port", ""); 1513 dot1 = ""; 1514 for(i = 0; i < cfg->ncd_ptab.nports; ++i){ 1515 fprintf(f,"%s%d@%04X", dot1, cfg->ncd_ptab.ports[i].s_port, cfg->ncd_ptab.ports[i].ftab.filts[0].caid); 1516 if (cfg->ncd_ptab.ports[i].ftab.filts[0].nprids > 0){ 1517 fprintf(f,":"); 1518 dot2 = ""; 1519 for (j = 0; j < cfg->ncd_ptab.ports[i].ftab.filts[0].nprids; ++j){ 1520 fprintf(f,"%s%06X", dot2, (int)cfg->ncd_ptab.ports[i].ftab.filts[0].prids[j]); 1521 dot2 = ","; 1522 } 1523 } 1524 dot1=";"; 1525 } 1526 1527 fputc((int)'\n', f); 1528 if (cfg->ncd_srvip != 0) 1529 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->ncd_srvip)); 1530 fprintf_conf(f, CONFVARWIDTH, "key", ""); 1531 for (i=0;i<14;i++) fprintf(f,"%02X", cfg->ncd_key[i]); 1532 fprintf(f,"\n"); 1533 fprintf_conf(f, CONFVARWIDTH, "allowed", ""); 1534 struct s_ip *cip; 1535 dot=""; 1536 for (cip = cfg->ncd_allowed; cip; cip = cip->next){ 1537 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0])); 1538 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1])); 1539 dot=","; 1540 } 1541 fprintf(f,"\n"); 1542 fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", cfg->ncd_keepalive); 1543 fprintf(f,"\n"); 1544 } 1545 1546 /*camd3.3*/ 1547 if ( cfg->c33_port > 0) { 1548 fprintf(f,"[camd33]\n"); 1549 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c33_port); 1550 if (cfg->c33_srvip != 0) 1551 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c33_srvip)); 1552 fprintf_conf(f, CONFVARWIDTH, "passive", "%d\n", cfg->c33_passive); 1553 fprintf_conf(f, CONFVARWIDTH, "key", ""); for (i = 0; i < (int) sizeof(cfg->c33_key); ++i) fprintf(f,"%02X", cfg->c33_key[i]); fputc((int)'\n', f); 1554 fprintf_conf(f, CONFVARWIDTH, "nocrypt", ""); 1555 dot=""; 1556 for (cip = cfg->c33_plain; cip; cip = cip->next){ 1557 fprintf(f,"%s%s", dot, cs_inet_ntoa(cip->ip[0])); 1558 if (cip->ip[0] != cip->ip[1]) fprintf(f,"-%s", cs_inet_ntoa(cip->ip[1])); 1559 dot=","; 1560 } 1561 fprintf(f,"\n\n"); 1562 } 1563 1564 /*camd3.5*/ 1565 if ( cfg->c35_port > 0) { 1566 fprintf(f,"[cs357x]\n"); 1567 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->c35_port); 1568 if (cfg->c35_tcp_srvip != 0) 1569 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip)); 1570 if (cfg->c35_suppresscmd08) 1571 fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", cfg->c35_suppresscmd08); 1572 fprintf(f,"\n"); 1573 } 1574 1575 /*camd3.5 TCP*/ 1576 if ((cfg->c35_tcp_ptab.nports > 0) && (cfg->c35_tcp_ptab.ports[0].s_port > 0)) { 1577 fprintf(f,"[cs378x]\n"); 1578 fprintf_conf(f, CONFVARWIDTH, "port", ""); 1579 dot1 = ""; 1580 for(i = 0; i < cfg->c35_tcp_ptab.nports; ++i){ 1581 fprintf(f,"%s%d@%04X", dot1, cfg->c35_tcp_ptab.ports[i].s_port, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].caid); 1582 if (cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids > 0){ 1583 fprintf(f,":"); 1584 dot2 = ""; 1585 for (j = 0; j < cfg->c35_tcp_ptab.ports[i].ftab.filts[0].nprids; ++j){ 1586 fprintf(f,"%s%lX", dot2, cfg->c35_tcp_ptab.ports[i].ftab.filts[0].prids[j]); 1587 dot2 = ","; 1588 } 1589 } 1590 dot1=";"; 1591 } 1592 1593 fputc((int)'\n', f); 1594 if (cfg->c35_tcp_srvip != 0) 1595 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->c35_tcp_srvip)); 1596 fputc((int)'\n', f); 1597 } 1598 1599 /*Radegast*/ 1600 if ( cfg->rad_port > 0) { 1601 fprintf(f,"[radegast]\n"); 1602 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->rad_port); 1603 if (cfg->rad_srvip != 0) 1604 fprintf_conf(f, CONFVARWIDTH, "serverip", "%s\n", inet_ntoa(*(struct in_addr *)&cfg->rad_srvip)); 1605 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->rad_usr); 1606 fprintf_conf(f, CONFVARWIDTH, "allowed", ""); 1607 struct s_ip *cip; 1608 for (cip = cfg->rad_allowed; cip; cip = cip->next){ 1609 fprintf(f,"%s%s", dot, inet_ntoa(*(struct in_addr *)&cip->ip[0])); 1610 if (cip->ip[0] == cip->ip[1]) fprintf(f,"-%s", inet_ntoa(*(struct in_addr *)&cip->ip[1])); 1611 dot=","; 1612 } 1613 fprintf(f,"\n\n"); 1614 } 1615 1616 #ifdef CS_WITH_GBOX 1617 /*Gbox*/ 1618 if ((cfg->gbox_pwd[0] > 0) || (cfg->gbox_pwd[1] > 0) || (cfg->gbox_pwd[2] > 0) || (cfg->gbox_pwd[3] > 0)){ 1619 fprintf(f,"[gbox]\n"); 1620 fprintf_conf(f, CONFVARWIDTH, "password", ""); for (i=0;i<4;i++) fprintf(f,"%02X", cfg->gbox_pwd[i]); fputc((int)'\n', f);; 1621 fprintf_conf(f, CONFVARWIDTH, "maxdist", "%d\n", cfg->maxdist); 1622 fprintf_conf(f, CONFVARWIDTH, "ignorelist", "%s\n", cfg->ignorefile); 1623 fprintf_conf(f, CONFVARWIDTH, "onlineinfos", "%s\n", cfg->gbxShareOnl); 1624 fprintf_conf(f, CONFVARWIDTH, "cardinfos", "%s\n", cfg->cardfile); 1625 fprintf_conf(f, CONFVARWIDTH, "locals", ""); 1626 char *dot = ""; 1627 for (i = 0; i < cfg->num_locals; i++){ 1628 fprintf(f,"%s%06lX", dot, cfg->locals[i]); 1629 dot=";"; 1630 } 1631 fprintf(f,"\n\n"); 1632 } 1633 #endif 1634 1635 /*serial*/ 1636 1637 1638 /*cccam*/ 1639 if ( cfg->cc_port > 0) { 1640 fprintf(f,"[cccam]\n"); 1641 fprintf_conf(f, CONFVARWIDTH, "port", "%d\n", cfg->cc_port); 1642 fprintf_conf(f, CONFVARWIDTH, "reshare", "%d\n", cfg->cc_reshare); 1643 fprintf_conf(f, CONFVARWIDTH, "version", "%s\n", cfg->cc_version); 1644 fprintf_conf(f, CONFVARWIDTH, "build", "%s\n", cfg->cc_build); 1645 fprintf(f,"\n"); 1646 } 1647 1648 #ifdef HAVE_DVBAPI 1649 /*dvb-api*/ 1650 if (cfg->dvbapi_enabled > 0) { 1651 fprintf(f,"[dvbapi]\n"); 1652 fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->dvbapi_enabled); 1653 fprintf_conf(f, CONFVARWIDTH, "au", "%d\n", cfg->dvbapi_au); 1654 fprintf_conf(f, CONFVARWIDTH, "boxtype", "%s\n", cfg->dvbapi_boxtype); 1655 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", cfg->dvbapi_usr); 1656 fputc((int)'\n', f); 1657 } 1658 #endif 1659 1660 #ifdef CS_ANTICASC 1661 fprintf(f,"[anticasc]\n"); 1662 fprintf_conf(f, CONFVARWIDTH, "enabled", "%d\n", cfg->ac_enabled); 1663 fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", cfg->ac_users); 1664 fprintf_conf(f, CONFVARWIDTH, "sampletime", "%d\n", cfg->ac_stime); 1665 fprintf_conf(f, CONFVARWIDTH, "samples", "%d\n", cfg->ac_samples); 1666 fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", cfg->ac_penalty); 1667 fprintf_conf(f, CONFVARWIDTH, "aclogfile", "%s\n", cfg->ac_logfile); 1668 fprintf_conf(f, CONFVARWIDTH, "denysamples", "%d\n", cfg->ac_denysamples); 1669 fprintf_conf(f, CONFVARWIDTH, "fakedelay", "%d\n", cfg->ac_fakedelay); 1670 fputc((int)'\n', f); 1671 #endif 1672 1673 fclose(f); 1674 1675 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0)); 1676 } 1677 1678 int write_userdb() 1679 { 1680 int i; 1681 FILE *f; 1682 struct s_auth *account; 1683 char *dot = ""; //flag for comma 1684 char tmpfile[256]; 1685 char destfile[256]; 1686 char bakfile[256]; 1687 1688 snprintf(destfile, 255,"%s%s", cs_confdir, cs_user); 1689 snprintf(tmpfile, 255, "%s%s.tmp", cs_confdir, cs_user); 1690 snprintf(bakfile, 255,"%s%s.bak", cs_confdir, cs_user); 1691 1692 if (!(f=fopen(tmpfile, "w"))){ 1693 cs_log("Cannot open file \"%s\" (errno=%d)", tmpfile, errno); 1694 return(1); 1695 } 1696 fprintf(f,"#oscam.user generated automatically\n\n"); 1697 1698 //each account 1699 for (account=cfg->account; (account) ; account=account->next){ 1700 fprintf(f,"[account]\n"); 1701 fprintf_conf(f, CONFVARWIDTH, "user", "%s\n", account->usr); 1702 fprintf_conf(f, CONFVARWIDTH, "pwd", "%s\n", account->pwd); 1703 fprintf_conf(f, CONFVARWIDTH, "disabled", "%d\n", account->disabled); 1704 struct tm * timeinfo = localtime (&account->expirationdate); 1705 char buf [80]; 1706 strftime (buf,80,"%Y-%m-%d",timeinfo); 1707 if(strcmp(buf,"1970-01-01")) 1708 fprintf_conf(f, CONFVARWIDTH, "expdate", "%s\n", buf); 1709 else 1710 fprintf_conf(f, CONFVARWIDTH, "expdate", "\n"); 1711 1712 //group 1713 char *value = mk_t_group((ulong*)account->grp); 1714 fprintf_conf(f, CONFVARWIDTH, "group", "%s\n", value); 1715 free(value); 1716 1717 fprintf_conf(f, CONFVARWIDTH, "hostname", "%s\n", account->dyndns); 1718 fprintf_conf(f, CONFVARWIDTH, "uniq", "%d\n", account->uniq); 1719 fprintf_conf(f, CONFVARWIDTH, "sleep", "%d\n", account->tosleep); 1720 fprintf_conf(f, CONFVARWIDTH, "monlevel", "%d\n", account->monlvl); 1721 1722 if (account->au > -1) 1723 if (account->au < CS_MAXREADER) 1724 fprintf_conf(f, CONFVARWIDTH, "au", "%s\n", reader[account->au].label); 1725 if (account->autoau == 1) fprintf_conf(f, CONFVARWIDTH, "au", "1\n"); 1726 1727 fprintf_conf(f, CONFVARWIDTH, "services", ""); 1728 char sidok[33]; long2bitchar(account->sidtabok,sidok); 1729 char sidno[33]; long2bitchar(account->sidtabno,sidno); 1730 struct s_sidtab *sidtab = cfg->sidtab; 1731 i=0; dot = ""; 1732 for (; sidtab; sidtab=sidtab->next){ 1733 if(sidok[i]=='1') {fprintf(f,"%s%s", dot, sidtab->label); dot = ",";} 1734 if(sidno[i]=='1') {fprintf(f,"%s!%s", dot, sidtab->label); dot = ",";} 1735 i++; 1736 } 1737 fputc((int)'\n', f); 1738 1739 //CAID 1740 value = mk_t_caidtab(&account->ctab); 1741 fprintf_conf(f, CONFVARWIDTH, "caid", "%s\n", value); 1742 free(value); 1743 1744 //betatunnel 1745 value = mk_t_tuntab(&account->ttab); 1746 fprintf_conf(f, CONFVARWIDTH, "betatunnel", "%s\n", value); 1747 free(value); 1748 1749 //ident 1750 value = mk_t_ftab(&account->ftab); 1751 fprintf_conf(f, CONFVARWIDTH, "ident", "%s\n", value); 1752 free(value); 1753 1754 if (account->c35_suppresscmd08) 1755 fprintf_conf(f, CONFVARWIDTH, "suppresscmd08", "%d\n", account->c35_suppresscmd08); 1756 1757 fprintf_conf(f, CONFVARWIDTH, "keepalive", "%d\n", account->ncd_keepalive); 1758 1759 #ifdef CS_ANTICASC 1760 fprintf_conf(f, CONFVARWIDTH, "numusers", "%d\n", account->ac_users); 1761 fprintf_conf(f, CONFVARWIDTH, "penalty", "%d\n", account->ac_penalty); 1762 #endif 1763 fputc((int)'\n', f); 1764 } 1765 fclose(f); 1766 1767 return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0)); 1300 1768 } 1301 1769 … … 1441 1909 if (!strcmp(token, "srvid")) { chk_entry4sidtab(value, sidtab, 2); return; } 1442 1910 if (token[0] != '#') 1443 cs_log("Warning: keyword '%s' in sidtab section not recognized\n",token);1911 fprintf(stderr, "Warning: keyword '%s' in sidtab section not recognized\n",token); 1444 1912 } 1445 1913 … … 2281 2749 } 2282 2750 #endif 2751 2752 /* 2753 * makes a char ready to write a token into config or webIf 2754 */ 2755 char *mk_t_caidtab(CAIDTAB *ctab){ 2756 int i = 0, needed = 1, pos = 0; 2757 while(ctab->caid[i]){ 2758 if(ctab->mask[i]) needed += 10; 2759 else needed += 5; 2760 if(ctab->cmap[i]) needed += 5; 2761 ++i; 2762 } 2763 char *value = (char *) malloc(needed * sizeof(char)); 2764 i = 0; 2765 while(ctab->caid[i]) { 2766 if(i == 0) { 2767 sprintf(value + pos, "%04X", ctab->caid[i]); 2768 pos += 4; 2769 } else { 2770 sprintf(value + pos, ",%04X", ctab->caid[i]); 2771 pos += 5; 2772 } 2773 if(ctab->mask[i]){ 2774 sprintf(value + pos, "&%04X", ctab->mask[i]); 2775 pos += 5; 2776 } 2777 if(ctab->cmap[i]){ 2778 sprintf(value + pos, ":%04X", ctab->cmap[i]); 2779 pos += 5; 2780 } 2781 ++i; 2782 } 2783 value[pos] = '\0'; 2784 return value; 2785 } 2786 2787 /* 2788 * makes a char ready to write a token into config or webIf 2789 */ 2790 char *mk_t_tuntab(TUNTAB *ttab){ 2791 int i = 0, needed = 1, pos = 0; 2792 while(ttab->bt_caidfrom[i]){ 2793 if(ttab->bt_srvid[i]) needed += 10; 2794 else needed += 5; 2795 if(ttab->bt_caidto[i]) needed += 5; 2796 ++i; 2797 } 2798 char *value = (char *) malloc(needed * sizeof(char)); 2799 i = 0; 2800 while(ttab->bt_caidfrom[i]) { 2801 if(i == 0) { 2802 sprintf(value + pos, "%04X", ttab->bt_caidfrom[i]); 2803 pos += 4; 2804 } else { 2805 sprintf(value + pos, ",%04X", ttab->bt_caidfrom[i]); 2806 pos += 5; 2807 } 2808 if(ttab->bt_srvid[i]){ 2809 sprintf(value + pos, ".%04X", ttab->bt_srvid[i]); 2810 pos += 5; 2811 } 2812 if(ttab->bt_caidto[i]){ 2813 sprintf(value + pos, ":%04X", ttab->bt_caidto[i]); 2814 pos += 5; 2815 } 2816 ++i; 2817 } 2818 value[pos] = '\0'; 2819 return value; 2820 } 2821 2822 /* 2823 * makes a char ready to write a token into config or webIf 2824 */ 2825 char *mk_t_group(ulong *grp){ 2826 int i = 0, needed = 1, pos = 0, dot = 0; 2827 char grpbit[33]; 2828 long2bitchar((long) grp, grpbit); 2829 2830 for(i = 0; i < 32; i++){ 2831 if (grpbit[i] == '1'){ 2832 needed += 2; 2833 if(i > 9) needed += 1; 2834 } 2835 } 2836 char *value = (char *) malloc(needed * sizeof(char)); 2837 2838 for(i = 0; i < 32; i++){ 2839 if (grpbit[i] == '1'){ 2840 if (dot == 0){ 2841 sprintf(value + pos, "%d", i+1); 2842 if (i > 9)pos += 2; 2843 else pos += 1; 2844 dot = 1; 2845 } else { 2846 sprintf(value + pos, ",%d", i+1); 2847 if (i > 9)pos += 3; 2848 else pos += 2; 2849 } 2850 } 2851 } 2852 value[pos] = '\0'; 2853 return value; 2854 } 2855 2856 /* 2857 * makes a char ready to write a token into config or webIf 2858 */ 2859 char *mk_t_ftab(FTAB *ftab){ 2860 int i = 0, j = 0, needed = 1, pos = 0; 2861 2862 needed = ftab->nfilts * 5; 2863 for (i = 0; i < ftab->nfilts; ++i) 2864 needed += ftab->filts[i].nprids * 7; 2865 2866 char *value = (char *) malloc(needed * sizeof(char)); 2867 2868 char *dot=""; 2869 for (i = 0; i < ftab->nfilts; ++i){ 2870 sprintf(value + pos, "%s%04X", dot, ftab->filts[i].caid); 2871 pos += 4; 2872 if (i > 0) pos += 1; 2873 dot=":"; 2874 for (j = 0; j < ftab->filts[i].nprids; ++j) { 2875 sprintf(value + pos, "%s%06lX", dot, ftab->filts[i].prids[j]); 2876 pos += 7; 2877 dot=","; 2878 } 2879 dot=";"; 2880 } 2881 2882 value[pos] = '\0'; 2883 return value; 2884 } -
trunk/oscam-log.c
r1617 r1691 36 36 rc=rename(file, prev_log); 37 37 if( rc!=0 ) { 38 fprintf(stderr, "rename(%s, %s) failed (errno=%d)\n", 38 fprintf(stderr, "rename(%s, %s) failed (errno=%d)\n", 39 39 file, prev_log, errno); 40 40 } 41 else if( pfinit(file)) 41 else if( pfinit(file)) 42 42 cs_exit(0); 43 43 44 44 45 45 } 46 46 } … … 50 50 { 51 51 #ifdef CS_ANTICASC 52 if( use_ac_log && fpa ) 53 { 54 switch_log(cfg->ac_logfile, &fpa, ac_init_log); 55 fprintf(fpa, "%s", txt); 56 fflush(fpa); 57 } 58 else 52 if( use_ac_log && fpa ) { 53 switch_log(cfg->ac_logfile, &fpa, ac_init_log); 54 fprintf(fpa, "%s", txt); 55 fflush(fpa); 56 } 57 else 59 58 #endif 60 if (fp || use_stdout) 61 { 62 if( !use_stdout && !use_syslog) switch_log(cfg->logfile, &fp, cs_init_log); 63 fprintf(fp, "%s", txt); 64 fflush(fp); 65 } 66 } 67 68 int cs_init_log(char *file) 69 { 70 static char *head = ">> OSCam << cardserver started version " CS_VERSION ", build #" CS_SVN_VERSION " (" CS_OSTYPE ")"; 71 72 if (!strcmp(file, "stdout")) 73 { 74 use_stdout=1; 75 fp=stdout; 76 cs_log(head); 77 cs_log_config(); 78 return(0); 79 } 80 if (strcmp(file, "syslog")) 81 { 82 if (!fp) 83 { 84 if ((fp=fopen(file, "a+"))<=(FILE *)0) 85 { 86 fp=(FILE *)0; 87 fprintf(stderr, "couldn't open logfile: %s (errno %d)\n", file, errno); 88 } 89 else 90 { 91 time_t t; 92 char line[80]; 93 memset(line, '-', sizeof(line)); 94 line[(sizeof(line)/sizeof(char))-1]='\0'; 95 time(&t); 96 fprintf(fp, "\n%s\n>> OSCam << cardserver started at %s%s\n", line, ctime(&t), line); 97 cs_log_config(); 98 } 99 } 100 return(fp<=(FILE *)0); 101 } 102 else 103 { 104 openlog("oscam", LOG_NDELAY, LOG_DAEMON); 105 use_syslog=1; 106 cs_log(head); 107 cs_log_config(); 108 return(0); 109 } 59 if (fp || use_stdout) { 60 if( !use_stdout && !use_syslog) 61 switch_log(cfg->logfile, &fp, cs_init_log); 62 if (!cfg->disablelog){ 63 fprintf(fp, "%s", txt); 64 fflush(fp); 65 } 66 } 67 } 68 69 int cs_init_log(char *file) 70 { 71 static char *head = ">> OSCam << cardserver started version " CS_VERSION ", build #" CS_SVN_VERSION " (" CS_OSTYPE ")"; 72 73 if (!strcmp(file, "stdout")) { 74 use_stdout = 1; 75 fp = stdout; 76 cs_log(head); 77 cs_log_config(); 78 return(0); 79 } 80 if (strcmp(file, "syslog")) { 81 if (!fp) { 82 if ((fp = fopen(file, "a+")) <= (FILE *)0) { 83 fp = (FILE *)0; 84 fprintf(stderr, "couldn't open logfile: %s (errno %d)\n", file, errno); 85 } else { 86 time_t t; 87 char line[80]; 88 memset(line, '-', sizeof(line)); 89 line[(sizeof(line)/sizeof(char)) - 1] = '\0'; 90 time(&t); 91 if (!cfg->disablelog) 92 fprintf(fp, "\n%s\n>> OSCam << cardserver started at %s%s\n", line, ctime(&t), line); 93 cs_log_config(); 94 } 95 } 96 return(fp <= (FILE *)0); 97 } else { 98 openlog("oscam", LOG_NDELAY, LOG_DAEMON); 99 use_syslog = 1; 100 cs_log(head); 101 cs_log_config(); 102 return(0); 103 } 110 104 } 111 105 112 106 static char *get_log_header(int m, char *txt) 113 107 { 114 if (m) 115 { 116 sprintf(txt, "%6d ", getpid()); 117 if (cs_idx) 118 switch (client[cs_idx].typ) 119 { 120 case 'r': 121 case 'p': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx-1); 122 break; 123 case 'm': 124 case 'c': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx-cdiff); 125 break; 108 if(m) { 109 sprintf(txt, "%6d ", getpid()); 110 if (cs_idx) { 111 switch (client[cs_idx].typ) { 112 case 'r': 113 case 'p': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx - 1); 114 break; 115 case 'm': 116 case 'c': sprintf(txt+7, "%c%02d ", client[cs_idx].typ, cs_idx - cdiff); 117 break; 126 118 #ifdef CS_ANTICASC 127 128 #endif 129 130 case 'n': sprintf(txt+7, "%c " , client[cs_idx].typ); 131 break;132 } 133 else 134 strcpy(txt+7, "s "); 135 } 136 else 137 138 139 140 119 case 'a': 120 #endif 121 case 'l': 122 case 'h': 123 case 'n': sprintf(txt+7, "%c " , client[cs_idx].typ); 124 break; 125 } 126 } else { 127 strcpy(txt+7, "s "); 128 } 129 } else { 130 sprintf(txt, "%-11.11s", ""); 131 } 132 return(txt); 141 133 } 142 134 … … 220 212 } 221 213 222 void cs_close_log(void) 214 void cs_close_log(void) 223 215 { 224 216 if (use_stdout || use_syslog || !fp) return; -
trunk/oscam-reader.c
r1687 r1691 402 402 reader_post_process(); 403 403 //if(reader[ridx].typ=='r') reader[ridx].qlen--; 404 //printf("queue: %d\n",reader[ridx].qlen); 404 405 } 405 406 … … 456 457 i, no, rtxt[rc], 1000*(tpe.time-tps.time)+tpe.millitm-tps.millitm); 457 458 } 459 460 //counting results 461 switch(rc){ 462 case 0: 463 reader[ridx].emmerror++; 464 break; 465 case 1: 466 reader[ridx].emmwritten++; 467 break; 468 case 2: 469 reader[ridx].emmskipped++; 470 break; 471 case 3: 472 reader[ridx].emmblocked++; 473 break; 474 } 475 458 476 return(rc); 459 477 } -
trunk/oscam-simples.c
r1690 r1691 360 360 #endif 361 361 362 #ifdef WEBIF 363 /* Helper function for urldecode.*/ 364 int x2i(int i){ 365 i=toupper(i); 366 i = i - '0'; 367 if(i > 9) i = i - 'A' + '9' + 1; 368 return i; 369 } 370 371 /* Decodes values in a http url */ 372 void urldecode(char *s){ 373 int c, c1, n; 374 char *s0,*t; 375 t = s0 = s; 376 n = strlen(s); 377 while(n >0){ 378 c = *s++; 379 if(c == '+') c = ' '; 380 else if(c == '%' && n > 2){ 381 c = *s++; 382 c1 = c; 383 c = *s++; 384 c = 16*x2i(c1) + x2i(c); 385 n -= 2; 386 } 387 *t++ = c; 388 n--; 389 } 390 *t = 0; 391 } 392 393 /* Helper function for urlencode.*/ 394 char to_hex(char code){ 395 static char hex[] = "0123456789abcdef"; 396 return hex[code & 15]; 397 } 398 399 /* Encode values in a http url. Note: Be sure to free() the returned string after use */ 400 char *urlencode(char *str){ 401 char *pstr = str, *buf = (char *) malloc((strlen(str) * 3 + 1) * sizeof(char)), *pbuf = buf; 402 while (*pstr) { 403 if (isalnum(*pstr) || *pstr == '-' || *pstr == '_' || *pstr == '.' || *pstr == '~') *pbuf++ = *pstr; 404 else if (*pstr == ' ') *pbuf++ = '+'; 405 else { 406 *pbuf++ = '%'; 407 *pbuf++ = to_hex(*pstr >> 4); 408 *pbuf++ = to_hex(*pstr & 15); 409 } 410 ++pstr; 411 } 412 *pbuf = '\0'; 413 pbuf = (char *) malloc((strlen(buf) + 1) * sizeof(char)); 414 strcpy(pbuf, buf); 415 free(buf); 416 return pbuf; 417 } 418 419 /* Converts a char array to a char array with hex values (needed for example for md5). The hex2ascii 420 array is a lookup table with the corresponding hex string on the array position of the integer representation 421 of the ascii value. Note that you need to "free" the resulting array after usage or you'll get a memory leak!*/ 422 char *char_to_hex(const unsigned char* p_array, unsigned int p_array_len, char hex2ascii[256][2]) { 423 unsigned char* str = (unsigned char*)malloc(p_array_len*2+1); 424 str[p_array_len*2] = '\0'; 425 const unsigned char* p_end = p_array + p_array_len; 426 size_t pos=0; 427 const unsigned char* p; 428 for( p = p_array; p != p_end; p++, pos+=2 ) { 429 str[pos] = hex2ascii[*p][0]; 430 str[pos+1] = hex2ascii[*p][1]; 431 } 432 return (char*)str; 433 } 434 435 /* Creates a random string with specified length. Note that dst must be one larger than size to hold the trailing \0*/ 436 void create_rand_str(char *dst, int size){ 437 static const char text[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; 438 int i; 439 for (i = 0; i < size; ++i){ 440 dst[i] = text[rand() % (sizeof(text) - 1)]; 441 } 442 dst[i] = '\0'; 443 } 444 #endif 445 446 /* Converts a long value to a char array in bitwise representation. 447 Note that the result array MUST be at least 33 bit large and that 448 this function assumes long values to hold only values up to 32bits and to be positive! 449 the result of e.g. long 7 is 11100000000000000000000000000000 this means the array 450 is reversed */ 451 void long2bitchar(long value, char *result){ 452 int pos; 453 for (pos=0;pos<32;pos++) result[pos]='0'; 454 result[pos] = '\0'; 455 456 pos=0; 457 while (value > 0 && pos < 32){ 458 if(value % 2 == 1) result[pos]='1'; 459 else result[pos]='0'; 460 value=value / 2; 461 pos++; 462 } 463 } 464 465 /* Return 1 if the file exists, else 0 */ 466 int file_exists(const char * filename){ 467 FILE *file; 468 if ((file = fopen(filename, "r"))){ 469 fclose(file); 470 return 1; 471 } 472 return 0; 473 } 474 362 475 /* Clears the s_ip structure provided. The pointer will be set to NULL so everything is cleared.*/ 363 476 void clear_sip(struct s_ip **sip){ 364 struct s_ip *cip = *sip, *lip; 365 for (*sip = NULL; cip != NULL; cip = lip){ 366 lip = cip->next; 367 free(cip); 368 } 477 struct s_ip *cip = *sip, *lip; 478 for (*sip = NULL; cip != NULL; cip = lip){ 479 lip = cip->next; 480 free(cip); 481 } 482 } 483 484 /* Clears the s_ftab struct provided by setting nfilts and nprids to zero. */ 485 void clear_ftab(struct s_ftab *ftab){ 486 int i, j; 487 for (i = 0; i < CS_MAXFILTERS; i++) { 488 ftab->filts[i].caid = 0; 489 for (j = 0; j < CS_MAXPROV; j++) 490 ftab->filts[i].prids[j] = 0; 491 ftab->filts[i].nprids = 0; 492 } 493 ftab->nfilts = 0; 369 494 } 370 495 371 496 /* Clears the s_ptab struct provided by setting nfilts and nprids to zero. */ 372 497 void clear_ptab(struct s_ptab *ptab){ 373 int i; 374 for (i = 0; i < ptab->nports; i++) { 375 ptab->ports[i].ftab.nfilts = 0; 376 ptab->ports[i].ftab.filts[0].nprids = 0; 377 } 378 ptab->nports = 0; 379 } 380 381 /* Clears the s_ftab struct provided by setting nfilts and nprids to zero. */ 382 void clear_ftab(struct s_ftab *ftab){ 383 int i, j; 384 for (i = 0; i < CS_MAXFILTERS; i++) { 385 ftab->filts[i].caid = 0; 386 for (j = 0; j < CS_MAXPROV; j++) 387 ftab->filts[i].prids[j] = 0; 388 ftab->filts[i].nprids = 0; 389 } 390 ftab->nfilts = 0; 498 int i; 499 for (i = 0; i < ptab->nports; i++) { 500 ptab->ports[i].ftab.nfilts = 0; 501 ptab->ports[i].ftab.filts[0].nprids = 0; 502 } 503 ptab->nports = 0; 391 504 } 392 505 393 506 /* Clears given caidtab */ 394 507 void clear_caidtab(struct s_caidtab *ctab){ 395 396 397 398 399 400 508 int i; 509 for (i = 0; i < CS_MAXCAIDTAB; i++) { 510 ctab->caid[i] = 0; 511 ctab->mask[i] = 0; 512 ctab->cmap[i] = 0; 513 } 401 514 } 402 515 403 516 /* Clears given tuntab */ 404 517 void clear_tuntab(struct s_tuntab *ttab){ 405 int i; 406 for (i = 0; i < CS_MAXTUNTAB; i++) { 407 ttab->bt_caidfrom[i] = 0; 408 ttab->bt_caidto[i] = 0; 409 ttab->bt_srvid[i] = 0; 410 } 411 } 412 413 /* 414 * Ordinary strncpy does not terminate the string if the source 415 * is exactly as long or longer as the specified size. This can raise security issues. 416 * This function is a replacement which makes sure that a \0 is always added. 417 * num should be the real size of char array (do not subtract -1). 418 */ 518 int i; 519 for (i = 0; i < CS_MAXTUNTAB; i++) { 520 ttab->bt_caidfrom[i] = 0; 521 ttab->bt_caidto[i] = 0; 522 ttab->bt_srvid[i] = 0; 523 } 524 } 525 /* Overwrites destfile with tmpfile. If forceBakOverWrite = 0, the bakfile will not be overwritten if it exists, else it will be.*/ 526 int safe_overwrite_with_bak(char *destfile, char *tmpfile, char *bakfile, int forceBakOverWrite){ 527 if(forceBakOverWrite != 0 && file_exists(bakfile)){ 528 if(remove(bakfile) < 0) cs_log("Error removing backup conf file %s (errno=%d)! Will try to proceed nonetheless...", bakfile, errno); 529 } 530 if(file_exists(bakfile)){ 531 if(remove(destfile) < 0) { 532 cs_log("Error removing original conf file %s (errno=%d). Will maintain original one!", destfile, errno); 533 if(remove(tmpfile) < 0) cs_log("Error removing temp conf file %s (errno=%d)!", tmpfile, errno); 534 return(1); 535 } 536 } else { 537 if(rename(destfile, bakfile) < 0){ 538 cs_log("Error renaming original conf file %s to %s (errno=%d). Will maintain original one!", destfile, bakfile, errno); 539 if(remove(tmpfile) < 0) cs_log("Error removing temp conf file %s (errno=%d)!", tmpfile, errno); 540 return(1); 541 } 542 } 543 if(rename(tmpfile, destfile) < 0){ 544 cs_log("Error renaming new conf file %s to %s (errno=%d). The config will be missing upon next startup as this is non-recoverable!", tmpfile, destfile, errno); 545 return(1); 546 } 547 return(0); 548 } 549 550 /* Replacement of fprintf which adds necessary whitespace to fill up the varname to a fixed width. 551 If varname is longer than varnameWidth, no whitespace is added*/ 552 void fprintf_conf(FILE *f, int varnameWidth, const char *varname, const char *fmtstring, ...){ 553 int varlen = strlen(varname); 554 int max = (varlen > varnameWidth) ? varlen : varnameWidth; 555 char varnamebuf[max + 3]; 556 char *ptr = varnamebuf + varlen; 557 va_list argptr; 558 559 strcpy(varnamebuf, varname); 560 while(varlen < varnameWidth){ 561 ptr[0] = ' '; 562 ++ptr; 563 ++varlen; 564 } 565 strcpy(ptr, "= "); 566 fwrite(varnamebuf, sizeof(char), strlen(varnamebuf), f); 567 if(strlen(fmtstring) > 0){ 568 va_start(argptr, fmtstring); 569 vfprintf(f, fmtstring, argptr); 570 va_end(argptr); 571 } 572 } 573 574 /* Ordinary strncpy does not terminate the string if the source is exactly as long or longer as the specified size. This can raise security issues. 575 This function is a replacement which makes sure that a \0 is always added. num should be the real size of char array (do not subtract -1). */ 419 576 void cs_strncpy(char * destination, const char * source, size_t num){ 420 421 422 423 424 425 } 577 uint32 l, size = strlen(source); 578 if(size > num - 1) l = num - 1; 579 else l = size; 580 memcpy(destination, source, l); 581 destination[l] = '\0'; 582 } -
trunk/oscam.c
r1687 r1691 67 67 #endif 68 68 #ifdef CS_ANTICASC 69 CS_MAXPID*(sizeof(struct s_acasc_shm)) + 69 CS_MAXPID*(sizeof(struct s_acasc_shm)) + 70 70 #endif 71 71 #ifdef CS_LOGHISTORY … … 230 230 } 231 231 232 int idx_from_username(char *uname)233 {234 int i, idx;235 for (i=0, idx=(-1); (i<CS_MAXPID) && (idx<0); i++)236 if (client[i].usr==uname)237 idx=i;238 return(idx);239 }240 241 232 static long chk_caid(ushort caid, CAIDTAB *ctab) 242 233 { … … 397 388 { 398 389 int i; 399 400 390 init_userdb(); 401 391 cs_reinit_clients(); … … 412 402 static void cs_debug_level() 413 403 { 414 int i; 415 416 switch (cs_dblevel) { 417 case 0: 418 cs_dblevel = 1; 419 break; 420 case 32: 421 cs_dblevel = 63; 422 break; 423 case 63: 424 cs_dblevel = 0; 425 break; 426 default: 427 cs_dblevel <<= 1; 404 int i; 405 406 //switch debuglevel forward one step if not set from outside 407 if(cfg->debuglvl == cs_dblevel) { 408 switch (cs_dblevel) { 409 case 0: 410 cs_dblevel = 1; 411 break; 412 case 32: 413 cs_dblevel = 63; 414 break; 415 case 63: 416 cs_dblevel = 0; 417 break; 418 default: 419 cs_dblevel <<= 1; 420 } 421 } else { 422 cs_dblevel = cfg->debuglvl; 428 423 } 429 if (master_pid==getpid()) 430 for (i=0; i<CS_MAXPID && client[i].pid; i++) 431 client[i].dbglvl=cs_dblevel; 432 else 433 client[cs_idx].dbglvl=cs_dblevel; 434 cs_log("%sdebug_level=%d", (master_pid==getpid())?"all ":"",cs_dblevel); 424 425 cfg->debuglvl = cs_dblevel; 426 427 if (master_pid == getpid()) 428 for (i=0; i<CS_MAXPID && client[i].pid; i++) 429 client[i].dbglvl = cs_dblevel; 430 else 431 client[cs_idx].dbglvl = cs_dblevel; 432 cs_log("%sdebug_level=%d", (master_pid == getpid())?"all ":"", cs_dblevel); 435 433 } 436 434 … … 438 436 { 439 437 uchar dummy[1]={0x00}; 438 440 439 for( i=1; i<CS_MAXPID; i++ ) 441 440 if( client[i].pid && client[i].typ=='r' && client[i].fd_m2c ){ … … 465 464 case 'r': txt="reader"; break; 466 465 case 'n': txt="resolver"; break; 466 #ifdef WEBIF 467 case 'h': txt="http"; break; 468 #endif 467 469 } 468 470 cs_log("PANIC: %s lost !! (pid=%d)", txt, client[i].pid); … … 478 480 if( cfg->ac_enabled ) 479 481 { 480 strncpy(usr, client[i].usr, sizeof(usr)-1);482 cs_strncpy(usr, client[i].usr, sizeof(usr)); 481 483 ac_idx = client[i].ac_idx; 482 484 ac_limit = client[i].ac_limit; … … 563 565 reader[ridx].fd=client[i].fd_m2c; 564 566 reader[ridx].cs_idx=i; 567 reader[ridx].pid=pid; 565 568 if (reader[ridx].r_port) 566 569 cs_log("proxy started (pid=%d, server=%s)", … … 600 603 client[i].ip=client[0].ip; 601 604 strcpy(client[i].usr, client[0].usr); 602 cs_log("anticascader started (pid=%d, delay=%d min)", 605 cs_log("anticascader started (pid=%d, delay=%d min)", 603 606 pid, cfg->ac_stime); 604 607 cdiff=i; 605 608 break; 606 609 #endif 610 611 #ifdef WEBIF 612 case 95: client[i].typ='h'; // http 613 client[i].ip=client[0].ip; 614 strcpy(client[i].usr, client[0].usr); 615 cs_log("http started (pid=%d)",pid); 616 cdiff=i; 617 break; 618 #endif 619 607 620 default: client[i].typ='c'; // static client 608 621 client[i].ip=client[0].ip; … … 631 644 int i; 632 645 for (i=1; i<NSIG; i++) 633 634 635 // set_signal_handler(SIGPIPE , 0, SIG_IGN);636 637 // set_signal_handler(SIGALRM , 0, cs_alarm);638 639 640 // set_signal_handler(SIGHUP , 1, cs_accounts_chk);641 642 643 644 645 646 set_signal_handler(i, 3, cs_exit); 647 set_signal_handler(SIGWINCH, 1, SIG_IGN); 648 // set_signal_handler(SIGPIPE , 0, SIG_IGN); 649 set_signal_handler(SIGPIPE , 0, cs_sigpipe); 650 // set_signal_handler(SIGALRM , 0, cs_alarm); 651 set_signal_handler(SIGALRM , 0, cs_master_alarm); 652 set_signal_handler(SIGCHLD , 1, cs_child_chk); 653 // set_signal_handler(SIGHUP , 1, cs_accounts_chk); 654 set_signal_handler(SIGHUP , 1, cs_sighup); 655 set_signal_handler(SIGUSR1, 1, cs_debug_level); 656 set_signal_handler(SIGUSR2, 1, cs_card_info); 657 set_signal_handler(SIGCONT, 1, SIG_IGN); 658 cs_log("signal handling initialized (type=%s)", 646 659 #ifdef CS_SIGBSD 647 660 "bsd" 648 661 #else 649 650 #endif 651 652 662 "sysv" 663 #endif 664 ); 665 return; 653 666 } 654 667 … … 669 682 free(buf); 670 683 671 ecmcache=(struct s_ecm *)mmap((void *)0, (size_t) shmsize, 684 ecmcache=(struct s_ecm *)mmap((void *)0, (size_t) shmsize, 672 685 PROT_READ|PROT_WRITE, MAP_SHARED, shmid, 0); 673 686 #else … … 817 830 { 818 831 ulong keep_alive = 1; 819 setsockopt(ph->ptab->ports[port_idx].fd, SOL_SOCKET, SO_KEEPALIVE, 832 setsockopt(ph->ptab->ports[port_idx].fd, SOL_SOCKET, SO_KEEPALIVE, 820 833 (void *)&keep_alive, sizeof(ulong)); 821 834 } 822 835 823 836 while (timeout--) 824 837 { … … 996 1009 use_ac_log=1; 997 1010 set_signal_handler(SIGHUP, 1, ac_init_stat); 998 1011 999 1012 ac_init_stat(); 1000 1013 while(1) … … 1014 1027 #endif 1015 1028 1029 #ifdef WEBIF 1030 static void cs_http() 1031 { 1032 http_srv(); 1033 } 1034 #endif 1035 1016 1036 static void init_cardreader() 1017 1037 { 1018 1019 1020 switch(cs_fork(0, 99)) 1021 { 1022 case -1: 1023 cs_exit(1); 1024 case 0: 1025 break; 1026 default: 1027 1028 1029 1038 for (ridx=0; ridx<CS_MAXREADER; ridx++) 1039 if ((reader[ridx].device[0]) && (reader[ridx].enable == 1)) 1040 switch(cs_fork(0, 99)) { 1041 case -1: 1042 cs_exit(1); 1043 case 0: 1044 break; 1045 default: 1046 1047 wait4master(); 1048 start_cardreader(); 1049 } 1030 1050 } 1031 1051 … … 1055 1075 #endif 1056 1076 case 98: start_resolver(); 1077 #ifdef WEBIF 1078 case 95: cs_http(); 1079 #endif 1057 1080 } 1058 1081 } … … 1077 1100 /* Uniq = 1: only one connection per user 1078 1101 * 1079 * Uniq = 2: set (new connected) user only to fake if source 1080 * ip is different (e.g. for newcamd clients with 1102 * Uniq = 2: set (new connected) user only to fake if source 1103 * ip is different (e.g. for newcamd clients with 1081 1104 * different CAID's -> Ports) 1082 1105 * 1083 * Uniq = 3: only one connection per user, but only the last 1106 * Uniq = 3: only one connection per user, but only the last 1084 1107 * login will survive (old mpcs behavior) 1085 1108 * … … 1208 1231 } 1209 1232 } 1210 } 1233 } 1211 1234 if(client[cs_idx].ncd_server) 1212 1235 { … … 1216 1239 cfg->ncd_ptab.ports[client[cs_idx].port_idx].s_port, 1217 1240 client[cs_idx].ip ? cs_inet_ntoa(client[cs_idx].ip) : "", 1218 client[cs_idx].ip ? t_grant : t_grant+1, 1241 client[cs_idx].ip ? t_grant : t_grant+1, 1219 1242 username(cs_idx), t_msg[rc]); 1220 1243 } … … 1223 1246 cs_log("%s %s-client %s%s (%s, %s)", 1224 1247 client[cs_idx].crypted ? t_crypt : t_plain, 1225 e_txt ? e_txt : ph[client[cs_idx].ctyp].desc, 1248 e_txt ? e_txt : ph[client[cs_idx].ctyp].desc, 1226 1249 client[cs_idx].ip ? cs_inet_ntoa(client[cs_idx].ip) : "", 1227 1250 client[cs_idx].ip ? t_grant : t_grant+1, … … 1282 1305 ptr[1]='\0'; 1283 1306 if ((client[cs_idx].typ=='c') || (client[cs_idx].typ=='m')) 1284 strncpy(ptr, client[cs_idx].usr, 31);1285 strncpy(ptr+32, txt, CS_LOGHISTSIZE-33);1307 cs_strncpy(ptr, client[cs_idx].usr, 31); 1308 cs_strncpy(ptr+32, txt, CS_LOGHISTSIZE-33); 1286 1309 *loghistidx=(*loghistidx+1) % CS_MAXLOGHIST; 1287 1310 #endif … … 1420 1443 for (this=cfg->srvid; this; this = this->next) { 1421 1444 if (this->srvid == er->srvid) { 1422 strncpy(srvname, this->name, sizeof(srvname));1445 cs_strncpy(srvname, this->name, sizeof(srvname)); 1423 1446 srvname[sizeof(srvname)-1] = 0; 1424 1447 for (i = 0; srvname[i]; i++) … … 1491 1514 if (cfg->cwlogdir != NULL) 1492 1515 logCWtoFile(er); 1493 1494 } 1495 1516 } 1517 1496 1518 return(write_ecm_request(fd, er)); 1497 1519 } … … 1592 1614 snprintf(erEx, sizeof(erEx)-1, "rejected %s%s", stxtWh[er->rcEx>>4], 1593 1615 stxtEx[er->rcEx&0xf]); 1616 1617 client[cs_idx].cwlastresptime = 1000*(tpe.time-er->tps.time)+tpe.millitm-er->tps.millitm; 1618 1594 1619 cs_log("%s (%04X&%06X/%04X/%02X:%04X): %s (%d ms)%s", 1595 uname, er->caid, er->prid, er->srvid, er->l, lc, 1596 er->rcEx?erEx:stxt[er->rc], 1597 1000*(tpe.time-er->tps.time)+tpe.millitm-er->tps.millitm, sby); 1620 uname, er->caid, er->prid, er->srvid, er->l, lc, 1621 er->rcEx?erEx:stxt[er->rc], client[cs_idx].cwlastresptime, sby); 1622 1598 1623 1599 1624 if(!client[cs_idx].ncd_server && client[cs_idx].autoau && er->rcEx==0) … … 1660 1685 client[cs_idx].cwignored++; 1661 1686 } 1687 1662 1688 #ifdef CS_ANTICASC 1663 1689 ac_chk(er, 1); … … 1849 1875 // network and local cards 1850 1876 default: 1851 case 0: 1852 if (er->reader[i]&flag) 1877 case 0: 1878 if (er->reader[i]&flag){ 1853 1879 write_ecm_request(reader[i].fd, er); 1880 } 1854 1881 break; 1855 // only local cards 1856 case 1: 1882 // only local cards 1883 case 1: 1857 1884 if (!(reader[i].typ & R_IS_NETWORK)) 1858 1885 if (er->reader[i]&flag) … … 1860 1887 break; 1861 1888 // only network 1862 case 2: 1889 case 2: 1863 1890 if ((reader[i].typ & R_IS_NETWORK)) 1864 1891 if (er->reader[i]&flag) … … 1884 1911 er->chid = (er->ecm[6]<<8)|er->ecm[7]; 1885 1912 1886 // Quickfix for 0100:0000651913 // quickfix for 0100:000065 1887 1914 if (er->caid == 0x100 && er->prid == 0x65 && er->srvid == 0) 1888 1915 er->srvid = 0x0642; … … 2067 2094 if ((!reader[au].fd) || // reader has no fd 2068 2095 (reader[au].caid[0]!=b2i(2,ep->caid)) || // wrong caid 2069 (memcmp(reader[au].hexserial, ep->hexserial, 8))) {// wrong serial 2070 return; 2071 } 2072 2096 (memcmp(reader[au].hexserial, ep->hexserial, 8))) /* wrong serial*/ { 2097 client[cs_idx].emmnok++; 2098 return; 2099 } 2100 2101 client[cs_idx].emmok++; 2073 2102 ep->cidx=cs_idx; 2074 2103 write_to_pipe(reader[au].fd, PIP_ID_EMM, (uchar *) ep, sizeof(EMM_PACKET)); … … 2169 2198 er->locals_done = 0; 2170 2199 er->stage++; 2171 request_cw(er, er->stage, cfg->preferlocalcards ? 1 : 0); 2200 request_cw(er, er->stage, cfg->preferlocalcards ? 1 : 0); 2172 2201 2173 2202 tpc.millitm += (cfg->ctimeout-cfg->ftimeout); … … 2225 2254 rc=select(((pfd>fd_m2c)?pfd:fd_m2c)+1, &fds, 0, 0, chk_pending(tp)); 2226 2255 if (master_pid!=getppid()) cs_exit(0); 2227 if (rc<0) 2256 if (rc<0) 2228 2257 { 2229 2258 if (errno==EINTR) continue; … … 2302 2331 int i, j, n; 2303 2332 int bg=0; 2304 int gfd; //nph, 2333 int gfd; //nph, 2305 2334 int fdp[2]; 2306 2335 uchar buf[2048]; … … 2330 2359 case 'b': bg=1; 2331 2360 break; 2332 case 'c': strncpy(cs_confdir, optarg, sizeof(cs_confdir)-1);2361 case 'c': cs_strncpy(cs_confdir, optarg, sizeof(cs_confdir)); 2333 2362 break; 2334 2363 case 'd': cs_dblevel=atoi(optarg); … … 2336 2365 case 'm': 2337 2366 #ifdef CS_NOSHM 2338 strncpy(cs_memfile, optarg, sizeof(cs_memfile)-1);2367 cs_strncpy(cs_memfile, optarg, sizeof(cs_memfile)); 2339 2368 break; 2340 2369 #endif … … 2346 2375 init_shm(); 2347 2376 init_config(); 2377 cfg->debuglvl = cs_dblevel; // give static debuglevel to outer world 2348 2378 for (i=0; mod_def[i]; i++) // must be later BEFORE init_config() 2349 2379 { … … 2353 2383 2354 2384 cs_log("auth size=%d", sizeof(struct s_auth)); 2355 //cs_log_config(); 2356 cfg->delay*=1000; 2385 2357 2386 init_sidtab(); 2358 2387 init_readerdb(); … … 2398 2427 for (i=0; i<CS_MAX_MOD; i++) 2399 2428 if( (ph[i].type & MOD_CONN_NET) && ph[i].ptab ) 2400 for(j=0; j<ph[i].ptab->nports; j++) 2429 for(j=0; j<ph[i].ptab->nports; j++) 2401 2430 { 2402 2431 start_listener(&ph[i], j); … … 2404 2433 gfd=ph[i].ptab->ports[j].fd+1; 2405 2434 } 2406 2407 client[0].last=time((time_t *)0); 2408 2435 2436 //set time for server to now to avoid 0 in monitor/webif 2437 client[0].last=time((time_t *)0); 2438 2409 2439 start_client_resolver(); 2410 2440 init_service(97); // logger 2411 2441 init_service(98); // resolver 2442 #ifdef WEBIF 2443 init_service(95); // http 2444 #endif 2412 2445 init_cardreader(); 2413 2446 2414 2447 if (cfg->waitforcards) 2415 2448 { … … 2429 2462 } while (!card_init_done); 2430 2463 cs_log("init for all local cards done"); 2431 } 2432 2464 2465 } 2433 2466 2434 2467 #ifdef CS_ANTICASC 2435 2468 if( !cfg->ac_enabled ) 2436 2469 cs_log("anti cascading disabled"); 2437 else 2470 else 2438 2471 { 2439 2472 init_ac(); … … 2513 2546 wait4master(); 2514 2547 client[cs_idx].ctyp=i; 2515 client[cs_idx].port_idx=j; 2548 client[cs_idx].port_idx=j; 2516 2549 client[cs_idx].udp_fd=ph[i].ptab->ports[j].fd; 2517 2550 client[cs_idx].udp_sa=cad; … … 2546 2579 client[cs_idx].ctyp=i; 2547 2580 client[cs_idx].udp_fd=pfd; 2548 client[cs_idx].port_idx=j; 2581 client[cs_idx].port_idx=j; 2549 2582 if (ph[client[cs_idx].ctyp].watchdog) 2550 2583 alarm(cfg->cmaxidle + cfg->ctimeout / 1000 + 1); -
trunk/reader-common.c
r1588 r1691 335 335 { 336 336 int rc=-1, r, m=0; 337 static int loadbalanced_idx = 0;337 static int loadbalanced_idx = 1; 338 338 if( (rc=reader_checkhealth()) ) 339 339 { 340 //cs_ debug("OUTER: ridx = %d (0x%x), client = 0x%x, lb_idx = %d", ridx, &reader[ridx], &client[cs_idx], loadbalanced_idx);340 //cs_log("OUT: ridx = %d (0x%x), client = 0x%x, lb_idx = %d", ridx, &reader[ridx], &client[cs_idx], loadbalanced_idx); 341 341 if(((reader[ridx].caid[0]>>8)==((er->caid>>8)&0xFF)) && (((reader[ridx].loadbalanced) && (loadbalanced_idx == ridx)) || !reader[ridx].loadbalanced)) 342 342 { 343 //cs_ debug("INNER: ridx = %d (0x%x), client = 0x%x, lb_idx = %d", ridx, &reader[ridx], &client[cs_idx], loadbalanced_idx);343 //cs_log("IN: ridx = %d (0x%x), client = 0x%x, lb_idx = %d", ridx, &reader[ridx], &client[cs_idx], loadbalanced_idx); 344 344 client[cs_idx].last_srvid=er->srvid; 345 345 client[cs_idx].last_caid=er->caid; … … 371 371 for (r=0;r<CS_MAXREADER;r++) 372 372 if (reader[r].caid[0]) m++; 373 if (loadbalanced_idx++ >= m) loadbalanced_idx = 0;373 if (loadbalanced_idx++ >= m) loadbalanced_idx = 1; 374 374 return(rc); 375 375 } -
trunk/reader-cryptoworks.c
r1399 r1691 260 260 if (read_record(0xC0)>=16) 261 261 { 262 strncpy(issuer, (const char *)cta_res+2, sizeof(issuer)-1);262 cs_strncpy(issuer, (const char *)cta_res+2, sizeof(issuer)); 263 263 trim(issuer); 264 264 } … … 568 568 if (read_record(0xD6)>=16) 569 569 { 570 strncpy(l_name+8, (const char *)cta_res+2, sizeof(l_name)-9);570 cs_strncpy(l_name+8, (const char *)cta_res+2, sizeof(l_name)-9); 571 571 l_name[sizeof(l_name)-1]=0; 572 572 trim(l_name+8); -
trunk/reader-videoguard2.c
r1664 r1691 52 52 53 53 if (!cw_is_valid(cw)) //if cw is all zero, keep it that way 54 return; 54 return; 55 55 #if __BYTE_ORDER == __BIG_ENDIAN 56 56 static unsigned char Tb1[0xC]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF,0xF8,0x61,0xCB,0x52}; … … 232 232 *tmp = ((*tmp << 8) & 0xff00) | ((*tmp >> 8) & 0x00ff); 233 233 } 234 } 234 } 235 235 236 236 static inline void __xxor(unsigned char *data, int len, const unsigned char *v1, const unsigned char *v2) … … 324 324 memcpy(cardkeys[0],data,sizeof(cardkeys[0])); 325 325 break; 326 case 0xbc: 326 case 0xbc: 327 327 { 328 328 swap_lb (data, 64); … … 487 487 outkey[count]=(outkey[count]*mult)%mod; 488 488 } 489 else 489 else 490 490 outkey[0]=val; 491 491 } … … 584 584 cs_debug("[videoguard2-reader] failed to read %02x%02x cmd length (%02x %02x)",cmd[1],cmd[2],cta_res[1],cta_res[2]); 585 585 return -1; 586 } 587 return cta_res[0]; 586 } 587 return cta_res[0]; 588 588 } 589 589 … … 636 636 *mm=(0x100*(Date[2]-*hh*8)+Date[3])/32; 637 637 *ss=(Date[3]-*mm*32)*2; 638 } 639 640 typedef struct{ 641 unsigned short id; 642 char name[32]; 643 } tier_t; 644 645 static tier_t skyit_tiers[] = 646 { 647 { 0x0320, "Promo" }, 648 { 0x000B, "Service" }, 649 { 0x0219, "Mondo HD" }, 650 { 0x021A, "Cinema HD" }, 651 { 0x021B, "Cinema" }, 652 { 0x0222, "Sport HD" }, 653 { 0x0224, "Sky Play IT" }, 654 { 0x0226, "Mondo" }, 655 { 0x0228, "Sport" }, 656 { 0x0229, "Disney Channel" }, 657 { 0x022A, "Inter Channel" }, 658 { 0x022B, "Milan Channel" }, 659 { 0x022C, "Roma Channel" }, 660 { 0x022D, "Classica" }, 661 { 0x022E, "Music & News" }, 662 { 0x022F, "Caccia e Pesca" }, 663 { 0x023D, "Juventus Channel" }, 664 { 0x023E, "Moto TV" }, 665 { 0x026B, "Calcio HD" }, 666 { 0x0275, "Promo" }, 667 { 0x0295, "Calcio" }, 668 { 0x0296, "Serie B" }, 669 { 0x02FE, "PPV" } 670 }; 671 672 static char *get_tier_name(unsigned short tier_id){ 673 static char *empty = ""; 674 unsigned int i; 675 676 switch (reader[ridx].caid[0]) 677 { 678 case 0x919: 679 case 0x93b: 680 for (i = 0; i < sizeof(skyit_tiers) / sizeof(tier_t); ++i) 681 if (skyit_tiers[i].id == tier_id) 682 return skyit_tiers[i].name; 683 break; 684 } 685 return empty; 638 686 } 639 687 … … 650 698 int num=cta_res[1]; 651 699 int i; 700 reader[ridx].init_history_pos = 0; //reset for re-read 701 memset(reader[ridx].init_history, 0, sizeof(reader[ridx].init_history)); 652 702 for(i=0; i<num; i++) { 653 703 ins76[2]=i; … … 657 707 int y,m,d,H,M,S; 658 708 rev_date_calc(&cta_res[4],&y,&m,&d,&H,&M,&S); 659 cs_ri_log("[videoguard2-reader] tier: %02x%02x, expiry date: %04d/%02d/%02d-%02d:%02d:%02d",cta_res[2],cta_res[3],y,m,d,H,M,S); 709 unsigned short tier_id = (cta_res[2] << 8) | cta_res[3]; 710 char *tier_name = get_tier_name(tier_id); 711 cs_ri_log("[videoguard2-reader] tier: %04x, expiry date: %04d/%02d/%02d-%02d:%02d:%02d %s",tier_id,y,m,d,H,M,S,tier_name); 660 712 } 661 713 } … … 738 790 /* else 739 791 { 740 // not a known videoguard 792 // not a known videoguard 741 793 return (0); 742 }*/ 794 }*/ 743 795 //a non videoguard2/NDS card will fail on read_cmd_len(ins7401) 744 796 //this way also unknown videoguard2/NDS cards will work … … 1037 1089 1038 1090 } 1039 1091 1040 1092 return(rc); 1041 1093 }
Note:
See TracChangeset
for help on using the changeset viewer.