Changeset 10639
- Timestamp:
- 03/22/15 11:06:50 (9 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-gbox-cards.c
r10628 r10639 18 18 uchar checkcode[7]; 19 19 20 void gbox_write_cards_info(void) 21 { 22 uint16_t card_count_local = 0; 20 void gbox_write_share_cards_info(void) 21 { 23 22 uint16_t card_count_shared = 0; 24 23 uint16_t card_count_expired = 0; 24 char *fext = FILE_SHARED_CARDS_INFO; 25 char *fname = get_gbox_tmp_fname(fext); 26 FILE *fhandle_shared; 27 fhandle_shared = fopen(fname, "w"); 28 if(!fhandle_shared) 29 { 30 cs_log("Couldn't open %s: %s", fname, strerror(errno)); 31 return; 32 } 33 34 struct gbox_card *card; 35 cs_readlock(&gbox_cards_lock); 36 LL_ITER it = ll_iter_create(gbox_cards); 37 while((card = ll_iter_next(&it))) 38 { 39 if (card->type == GBOX_CARD_TYPE_GBOX) 40 { 41 fprintf(fhandle_shared, "CardID %2d at %s Card %08X Sl:%2d Lev:%1d dist:%1d id:%04X\n", 42 card_count_shared, card->origin_peer->hostname, card->caprovid, 43 card->id.slot, card->lvl, card->dist, card->id.peer); 44 card_count_shared++; 45 } 46 } 47 cs_readunlock(&gbox_cards_lock); 48 fclose(fhandle_shared); 49 50 fext = FILE_BACKUP_CARDS_INFO; 51 fname = get_gbox_tmp_fname(fext); 52 FILE *fhandle_expired; 53 fhandle_expired = fopen(fname, "w"); 54 if(!fhandle_expired) 55 { 56 cs_log("Couldn't open %s: %s", fname, strerror(errno)); 57 return; 58 } 59 cs_readlock(&gbox_cards_lock); 60 LL_ITER it2 = ll_iter_create(gbox_backup_cards); 61 while((card = ll_iter_next(&it2))) 62 { 63 if (card->type == GBOX_CARD_TYPE_GBOX) 64 { 65 fprintf(fhandle_expired, "CardID %2d at %s Card %08X Sl:%2d Lev:%1d dist:%1d id:%04X\n", 66 card_count_expired, card->origin_peer->hostname, card->caprovid, 67 card->id.slot, card->lvl, card->dist, card->id.peer); 68 card_count_expired++; 69 } 70 } 71 cs_readunlock(&gbox_cards_lock); 72 fclose(fhandle_expired); 73 return; 74 } 75 76 void gbox_write_local_cards_info(void) 77 { 78 uint16_t card_count_local = 0; 25 79 char *fext = FILE_LOCAL_CARDS_INFO; 26 80 char *fname = get_gbox_tmp_fname(fext); … … 32 86 return; 33 87 } 34 fext = FILE_SHARED_CARDS_INFO; 35 fname = get_gbox_tmp_fname(fext); 36 FILE *fhandle_shared; 37 fhandle_shared = fopen(fname, "w"); 38 if(!fhandle_shared) 39 { 40 cs_log("Couldn't open %s: %s", fname, strerror(errno)); 41 return; 42 } 43 44 struct gbox_card *card; 45 88 89 struct gbox_card *card; 46 90 cs_readlock(&gbox_cards_lock); 47 91 LL_ITER it = ll_iter_create(gbox_cards); … … 51 95 { 52 96 case GBOX_CARD_TYPE_GBOX: 53 fprintf(fhandle_shared, "CardID %2d at %s Card %08X Sl:%2d Lev:%1d dist:%1d id:%04X\n",54 card_count_shared, card->origin_peer->hostname, card->caprovid,55 card->id.slot, card->lvl, card->dist, card->id.peer);56 card_count_shared++;57 97 break; 58 98 case GBOX_CARD_TYPE_LOCAL: … … 83 123 cs_readunlock(&gbox_cards_lock); 84 124 fclose(fhandle_local); 85 fclose(fhandle_shared);86 87 fext = FILE_BACKUP_CARDS_INFO;88 fname = get_gbox_tmp_fname(fext);89 FILE *fhandle_expired;90 fhandle_expired = fopen(fname, "w");91 if(!fhandle_expired)92 {93 cs_log("Couldn't open %s: %s", fname, strerror(errno));94 return;95 }96 cs_readlock(&gbox_cards_lock);97 LL_ITER it2 = ll_iter_create(gbox_backup_cards);98 while((card = ll_iter_next(&it2)))99 {100 if (card->type == GBOX_CARD_TYPE_GBOX)101 {102 fprintf(fhandle_expired, "CardID %2d at %s Card %08X Sl:%2d Lev:%1d dist:%1d id:%04X\n",103 card_count_expired, card->origin_peer->hostname, card->caprovid,104 card->id.slot, card->lvl, card->dist, card->id.peer);105 card_count_expired++;106 }107 }108 cs_readunlock(&gbox_cards_lock);109 fclose(fhandle_expired);110 return;111 125 } 112 126 … … 116 130 struct gbox_good_srvid *srvid_good = NULL; 117 131 struct gbox_bad_srvid *srvid_bad = NULL; 132 char *fext = FILE_STATS; 133 char *fname = get_gbox_tmp_fname(fext); 118 134 FILE *fhandle; 119 fhandle = fopen( get_gbox_tmp_fname(FILE_STATS), "w");135 fhandle = fopen(fname, "w"); 120 136 if(!fhandle) 121 137 { 122 cs_log("Couldn't open %s: %s", get_gbox_tmp_fname(FILE_STATS), strerror(errno));138 cs_log("Couldn't open %s: %s", fname, strerror(errno)); 123 139 return; 124 140 } 125 141 126 142 struct gbox_card *card; 127 128 143 cs_readlock(&gbox_cards_lock); 129 144 LL_ITER it = ll_iter_create(gbox_cards); … … 188 203 static int8_t closer_path_known(uint32_t caprovid, uint16_t id_peer, uint8_t slot, uint8_t distance) 189 204 { 205 uint8_t ret = 0; 206 struct gbox_card *card; 190 207 cs_readlock(&gbox_cards_lock); 191 208 LL_ITER it = ll_iter_create(gbox_cards); 192 struct gbox_card *card;193 209 while((card = ll_iter_next(&it))) 194 210 { 195 211 if (card->caprovid == caprovid && card->id.peer == id_peer && card->id.slot == slot && card->dist <= distance) 196 212 { 197 cs_readunlock(&gbox_cards_lock);198 return 1;213 ret = 1; 214 break; 199 215 } 200 216 } 201 217 cs_readunlock(&gbox_cards_lock); 202 return 0;218 return ret; 203 219 } 204 220 … … 206 222 { 207 223 uint8_t ret = 0; 224 struct gbox_card *card; 208 225 cs_writelock(&gbox_cards_lock); 209 226 LL_ITER it = ll_iter_create(gbox_backup_cards); 210 struct gbox_card *card;211 227 while((card = ll_iter_next(&it))) 212 228 { … … 222 238 } 223 239 } 224 cs_writeunlock(&gbox_cards_lock); 225 240 cs_writeunlock(&gbox_cards_lock); 226 241 return ret; 227 242 } -
trunk/module-gbox-cards.h
r10617 r10639 3 3 4 4 #ifdef MODULE_GBOX 5 void gbox_write_cards_info(void); 5 void gbox_write_share_cards_info(void); 6 void gbox_write_local_cards_info(void); 6 7 void gbox_write_stats(void); 7 8 void init_gbox_cards(void); -
trunk/module-gbox-helper.c
r10568 r10639 55 55 case 0x18: 56 56 caprovid = (caid >> 8) << 24 | (caid & 0xFF) << 16; 57 break; 57 58 default: 58 59 caprovid = (caid >> 8) << 24 | (caid & 0xFF) << 16 | -
trunk/module-gbox.c
r10635 r10639 166 166 void gbox_write_version(void) 167 167 { 168 FILE *fhandle = fopen(get_gbox_tmp_fname(FILE_GBOX_VERSION), "w"); 168 char *fext= FILE_GBOX_VERSION; 169 char *fname = get_gbox_tmp_fname(fext); 170 FILE *fhandle = fopen(fname, "w"); 169 171 if(!fhandle) 170 172 { … … 231 233 } 232 234 235 static int8_t gbox_peer_online(struct gbox_peer *peer, uint8_t online) 236 { 237 if (!peer) { return -1; } 238 239 peer->online = online; 240 gbox_write_peer_onl(); 241 return 0; 242 } 243 233 244 static int8_t gbox_reinit_peer(struct gbox_peer *peer) 234 245 { 235 246 if (!peer) { return -1; } 236 247 237 peer->online = 0;238 248 peer->ecm_idx = 0; 239 249 peer->next_hello = 0; 240 250 gbox_delete_cards(GBOX_DELETE_FROM_PEER, peer->gbox.id); 241 gbox_ write_peer_onl();251 gbox_peer_online(peer, 0); 242 252 243 253 return 0; … … 482 492 memset(&tmpbuf[0], 0, 7); 483 493 if (data[11] == 0x80 && !memcmp(data+12,tmpbuf,7)) 484 { 485 cs_log("-> HelloL in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, peer->filtered_cards); 486 peer->online = 1; 487 gbox_write_peer_onl(); 488 } 494 { 495 cs_log("-> HelloL in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, peer->filtered_cards); 496 gbox_peer_online(peer, 1); 497 } 489 498 else 490 499 { cs_log("-> HelloS in %d packets from %s (%s:%d) V2.%02X with %d cards filtered to %d cards", (data[0x0B] & 0x0f)+1, cli->reader->label, cs_inet_ntoa(cli->ip), cli->reader->r_port, peer->gbox.minor_version, peer->total_cards, peer->filtered_cards); } … … 498 507 if(!peer->online) 499 508 { 500 peer->online = 1;501 509 gbox_send_hello(cli, GBOX_STAT_HELLOS); 502 gbox_ write_peer_onl();510 gbox_peer_online(peer, 1); 503 511 } 504 512 cli->reader->tcp_connected = 2; //we have card … … 509 517 } 510 518 peer->next_hello = 0; 511 gbox_write_ cards_info();519 gbox_write_share_cards_info(); 512 520 cli->last = time((time_t *)0); //hello is activity on proxy 513 521 } … … 624 632 { 625 633 case MSG_BOXINFO: 634 cs_log("-> BOXINFO from %s",username(proxy)); 626 635 gbox_send_hello(proxy, GBOX_STAT_HELLOR); 627 636 break; … … 706 715 } 707 716 708 static uint32_t gbox_get_pw(uchar *buf)709 {710 return buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3];711 }712 713 717 //returns -1 in case of error, 1 if authentication was performed, 0 else 714 718 static int8_t gbox_check_header(struct s_client *cli, struct s_client *proxy, uchar *data, int32_t l) … … 731 735 cs_log_dump_dbg(D_READER, data, n, "-> decrypted data (%d bytes):", n); 732 736 //verify my pass received 733 my_received_pw = gbox_get_pw(&data[2]);737 my_received_pw = b2i(4, data + 2); 734 738 if (my_received_pw == local_gbox.password) 735 739 { … … 740 744 if (cli->gbox_peer_id == NO_GBOX_ID) 741 745 { 742 if (gbox_auth_client(cli, gbox_get_pw(&data[6])) < 0)746 if (gbox_auth_client(cli, b2i(4, data + 6)) < 0) 743 747 { 744 748 cs_log_dbg(D_READER, "Authentication failed. Please check user in oscam.server and oscam.user"); … … 751 755 } 752 756 if (!peer) { return -1; } 753 peer_received_pw = gbox_get_pw(&data[6]);757 peer_received_pw = b2i(4, data + 6); 754 758 if (peer_received_pw != peer->gbox.password) 755 759 { … … 882 886 gbox_send(cli, outbuf, 17); 883 887 } 884 /* 885 static void gbox_send_boxinfo(struct s_client *cli) 886 { 887 struct gbox_peer *peer = cli->gbox; 888 uchar outbuf[256]; 889 int32_t hostname_len = strlen(cfg.gbox_hostname); 890 891 gbox_message_header(outbuf, MSG_BOXINFO, peer); 892 outbuf[0xA] = local_gbox.minor_version; 893 outbuf[0xB] = local_gbox.type; 894 memcpy(&outbuf[0xC], cfg.gbox_hostname, hostname_len); 895 gbox_send(cli, outbuf, hostname_len + 0xC); 896 } 897 */ 888 898 889 static int32_t gbox_recv(struct s_client *cli, uchar *buf, int32_t l) 899 890 { … … 1101 1092 } 1102 1093 } 1103 } // end add proxy reader cards 1094 } // end add proxy reader cards 1095 gbox_write_local_cards_info(); 1104 1096 } //end add local gbox cards 1105 1097 … … 1577 1569 cl->last = time((time_t *)0); 1578 1570 } 1579 /* 1571 1580 1572 static int8_t gbox_send_peer_good_night(struct s_client *proxy) 1581 1573 { … … 1608 1600 } 1609 1601 1610 void gbox_cleanup(struct s_client *cl) 1611 { 1612 Commented because the remove doubled clients causes trouble 1613 NEEDFIX: How to cleanup when oscam ends 1614 gbox_free_cardlist(); 1615 if(cl && cl->gbox && cl->typ == 'p') 1616 { gbox_send_peer_good_night(cl); } 1617 } 1618 1602 void gbox_send_good_night(void) 1603 { 1604 struct s_client *cli; 1605 cs_readlock(&clientlist_lock); 1606 for(cli = first_client; cli; cli = cli->next) 1607 { 1608 if(cli->gbox && cli->typ == 'p') 1609 { gbox_send_peer_good_night(cli); } 1610 } 1611 cs_readunlock(&clientlist_lock); 1612 } 1613 /* 1619 1614 void gbox_send_goodbye(uint16_t boxid) //to implement later 1620 1615 { … … 1662 1657 cs_readunlock(&clientlist_lock); 1663 1658 } 1659 //This is most likely the same as MSG_HERE. Don't know what would be the difference 1660 static void gbox_send_boxinfo(struct s_client *cli) 1661 { 1662 struct gbox_peer *peer = cli->gbox; 1663 uchar outbuf[256]; 1664 int32_t hostname_len = strlen(cfg.gbox_hostname); 1665 1666 gbox_message_header(outbuf, MSG_BOXINFO, peer); 1667 outbuf[0xA] = local_gbox.minor_version; 1668 outbuf[0xB] = local_gbox.type; 1669 memcpy(&outbuf[0xC], cfg.gbox_hostname, hostname_len); 1670 gbox_send(cli, outbuf, hostname_len + 0xC); 1671 } 1664 1672 */ 1665 1673 void module_gbox(struct s_module *ph) … … 1684 1692 1685 1693 ph->recv = gbox_recv; 1686 /*ph->cleanup = gbox_cleanup;*/1687 1694 ph->c_init = gbox_client_init; 1688 1695 ph->c_recv_chk = gbox_recv_chk; -
trunk/module-gbox.h
r10617 r10639 162 162 void gbox_free_cards_pending(ECM_REQUEST *er); 163 163 void gbox_send_hello_packet(struct s_client *proxy, int8_t number, uchar *outbuf, uchar *ptr, int32_t nbcards, uint8_t hello_stat); 164 void gbox_send_good_night(void); 164 165 #else 165 166 static inline void gbox_free_cards_pending(ECM_REQUEST *UNUSED(er)) { } 167 static inline void gbox_send_good_night(void) { } 166 168 #endif 167 169 -
trunk/oscam.c
r10622 r10639 1689 1689 1690 1690 cccam_done_share(); 1691 gbox_send_good_night(); 1691 1692 1692 1693 kill_all_clients();
Note:
See TracChangeset
for help on using the changeset viewer.