From a1ad9ebd6006a85264d52576534be31514b834ba Mon Sep 17 00:00:00 2001 From: Admin Date: Sat, 25 Jun 2011 03:27:00 +0000 Subject: [PATCH] WebIf: Make refresh mechanism more subtle git-svn-id: http://streamboard.gmc.to/svn/oscam/trunk@5480 4b0bc96b-bc66-0410-9d44-ebda105a78c1 --- global-functions.h | 2 +- module-dvbapi.c | 2 +- module-monitor.c | 2 +- oscam-config.c | 42 +++++++++------- oscam-http.c | 120 +++++++++++++++++++++------------------------ oscam-http.h | 2 +- oscam-log.c | 7 ++- 7 files changed, 90 insertions(+), 87 deletions(-) diff --git a/global-functions.h b/global-functions.h index 5b98195c9b..dd06db62b9 100644 --- a/global-functions.h +++ b/global-functions.h @@ -182,7 +182,7 @@ extern void cs_accounts_chk(void); extern void chk_account(const char *token, char *value, struct s_auth *account); extern void chk_sidtab(char *token, char *value, struct s_sidtab *sidtab); extern int32_t write_services(); -extern int32_t write_userdb(struct s_auth *authptr); +extern int32_t write_userdb(); extern int32_t write_config(); extern int32_t write_server(); extern void write_versionfile(); diff --git a/module-dvbapi.c b/module-dvbapi.c index 04c44383f8..4157c284d7 100644 --- a/module-dvbapi.c +++ b/module-dvbapi.c @@ -1756,7 +1756,7 @@ static void * dvbapi_main_local(void *cli) { len = read(connfd, mbuf, sizeof(mbuf)); if (len < 3) { - cs_debug_mask(D_DVBAPI, "camd.socket: too int16_t message received"); + cs_debug_mask(D_DVBAPI, "camd.socket: too small message received"); continue; } diff --git a/module-monitor.c b/module-monitor.c index 1b324fb1dd..2ec5f763b4 100644 --- a/module-monitor.c +++ b/module-monitor.c @@ -127,7 +127,7 @@ static int32_t monitor_recv(struct s_client * client, uchar *buf, int32_t l) int32_t bsize; if (n<21) // 5+16 is minimum { - cs_log("packet to int16_t !"); + cs_log("packet too small!"); return(buf[0]=0); } if (!secmon_auth_client(buf+1)) diff --git a/oscam-config.c b/oscam-config.c index bbc48b8ef7..c5de347bbe 100644 --- a/oscam-config.c +++ b/oscam-config.c @@ -2353,7 +2353,7 @@ int32_t write_config() return(safe_overwrite_with_bak(destfile, tmpfile, bakfile, 0)); } -int32_t write_userdb(struct s_auth *authptr) +int32_t write_userdb() { FILE *f; struct s_auth *account; @@ -2374,7 +2374,7 @@ int32_t write_userdb(struct s_auth *authptr) fprintf(f,"# Read more: http://streamboard.gmc.to/svn/oscam/trunk/Distribution/doc/txt/oscam.user.txt\n\n"); //each account - for (account=authptr; (account) ; account=account->next){ + for (account=cfg.account; (account) ; account=account->next){ fprintf(f,"[account]\n"); fprintf_conf(f, "user", "%s\n", account->usr); fprintf_conf(f, "pwd", "%s\n", account->pwd); @@ -3215,7 +3215,6 @@ int32_t init_sidtab() { cfg.sidtab=ptr; sidtab=ptr; nr++; - memset(sidtab, 0, sizeof(struct s_sidtab)); cs_strncpy(sidtab->label, strtolower(token+1), sizeof(sidtab->label)); continue; } @@ -3266,7 +3265,6 @@ int32_t init_provid() { cfg.provid = ptr; provid = ptr; - memset(provid, 0, sizeof(struct s_provid)); int32_t i; char *ptr1; @@ -3490,7 +3488,6 @@ int32_t init_tierid() new_cfg_tierid = ptr; tierid = ptr; - memset(tierid, 0, sizeof(struct s_tierid)); int32_t i; char *ptr1 = strtok_r(payload, "|", &saveptr1); @@ -4585,6 +4582,8 @@ void init_ac() token, errno, strerror(errno)); return; } + + struct s_cpmap *cur_cpmap, *first_cpmap = NULL, *last_cpmap = NULL; for(nr=0; fgets(token, sizeof(token), fp);) { @@ -4592,8 +4591,6 @@ void init_ac() uint16_t caid, sid, chid, dwtime; uint32_t provid; char *ptr, *ptr1; - struct s_cpmap *ptr_cpmap; - static struct s_cpmap *cpmap=(struct s_cpmap *)0; if( strlen(token)<4 ) continue; @@ -4644,19 +4641,23 @@ void init_ac() break; } } - if (!cs_malloc(&ptr_cpmap, sizeof(struct s_cpmap), -1)) return; - if( cpmap ) - cpmap->next=ptr_cpmap; + if (!cs_malloc(&cur_cpmap, sizeof(struct s_cpmap), -1)){ + for(cur_cpmap = first_cpmap; cur_cpmap; cur_cpmap = cur_cpmap->next) + free(cur_cpmap); + return; + } + if(last_cpmap) + last_cpmap->next=cur_cpmap; else - cfg.cpmap=ptr_cpmap; - cpmap=ptr_cpmap; + first_cpmap=cur_cpmap; + last_cpmap=cur_cpmap; - cpmap->caid = caid; - cpmap->provid = provid; - cpmap->sid = sid; - cpmap->chid = chid; - cpmap->dwtime = dwtime; - cpmap->next = 0; + cur_cpmap->caid = caid; + cur_cpmap->provid = provid; + cur_cpmap->sid = sid; + cur_cpmap->chid = chid; + cur_cpmap->dwtime = dwtime; + cur_cpmap->next = 0; cs_debug_mask(D_CLIENT, "nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d", nr, caid, provid, sid, chid, dwtime); @@ -4664,6 +4665,11 @@ void init_ac() } } fclose(fp); + + last_cpmap = cfg.cpmap; + cfg.cpmap = first_cpmap; + for(cur_cpmap = last_cpmap; cur_cpmap; cur_cpmap = cur_cpmap->next) + add_garbage(cur_cpmap); //cs_log("%d lengths for caid guessing loaded", nr); return; } diff --git a/oscam-http.c b/oscam-http.c index c2ff19bd61..cab74ca2ac 100644 --- a/oscam-http.c +++ b/oscam-http.c @@ -22,30 +22,17 @@ pthread_mutex_t http_lock; pthread_key_t getip; -#ifdef CS_ANTICASC -static void kill_ac_client(void) -{ - struct s_client *cl; - for (cl=first_client->next; cl ; cl=cl->next) - if (cl->typ=='a') { - cs_accounts_chk(); - break; - } -} -#endif - static void refresh_oscam(enum refreshtypes refreshtype) { switch (refreshtype) { case REFR_ACCOUNTS: cs_log("Refresh Accounts requested by WebIF from %s", cs_inet_ntoa(GET_IP())); - cs_accounts_chk(); break; - - case REFR_READERS: - cs_card_info(); - cs_log("Refresh Reader/Tiers requested by WebIF from %s", cs_inet_ntoa(GET_IP())); + + case REFR_CLIENTS: + cs_log("Refresh Clients requested by WebIF from %s", cs_inet_ntoa(GET_IP())); + cs_reinit_clients(cfg.account); break; case REFR_SERVER: @@ -63,7 +50,24 @@ static void refresh_oscam(enum refreshtypes refreshtype) { #ifdef CS_ANTICASC case REFR_ANTICASC: cs_log("Refresh Anticascading requested by WebIF from %s", cs_inet_ntoa(GET_IP())); - kill_ac_client(); + ac_init_stat(); + int8_t foundac = 0; + struct s_client *cl; + struct s_auth *account; + for (cl=first_client->next; cl ; cl=cl->next){ + if (cl->typ=='c' && (account = cl->account)) { + cl->ac_limit = (account->ac_users * 100 + 80) * cfg.ac_stime; + } else if (cl->typ=='a'){ + if(!cfg.ac_enabled) + kill_thread(cl); + else foundac = 1; + } + } + if (cfg.ac_enabled && !foundac){ + init_ac(); + start_thread((void *) &start_anticascader, "anticascader"); + } + break; #endif default: break; @@ -459,6 +463,7 @@ static char *send_oscam_config_cccam(struct templatevars *vars, struct uriparams chk_t_cccam((*params).params[i], (*params).values[i]); } } + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "

Configuration CCCam done. You should restart OSCam now.

"); if(write_config()==0) refresh_oscam(REFR_SERVER); else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); cc_update_nodeid(); @@ -707,10 +712,10 @@ static char *send_oscam_config_anticasc(struct templatevars *vars, struct uripar chk_t_ac((*params).params[i], (*params).values[i]); } } - tpl_addVar(vars, TPLAPPEND, "MESSAGE", "

Configuration Anticascading done. You should restart OSCam now.

"); + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "

Configuration Anticascading done.

"); refresh_oscam(REFR_ANTICASC); - if(write_config()==0) refresh_oscam(REFR_SERVER); - else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); + if(write_config()!=0) + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); } if (cfg.ac_enabled > 0) tpl_addVar(vars, TPLADD, "CHECKED", "checked"); tpl_printf(vars, TPLADD, "NUMUSERS", "%d", cfg.ac_users); @@ -797,8 +802,8 @@ static char *send_oscam_reader(struct templatevars *vars, struct uriparams *para free_reader(rdr); - if(write_server()==0) refresh_oscam(REFR_READERS); - else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); + if(write_server()!=0) + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); } } } @@ -813,13 +818,11 @@ static char *send_oscam_reader(struct templatevars *vars, struct uriparams *para rdr->emmskipped[i] = 0; rdr->emmblocked[i] = 0; } - /* - if( rdr->enable == 1 && rdr->client->typ == 'r' && rdr->client->fd_m2c ) { - uchar dummy[1]={0x00}; - write_to_pipe(rdr->client->fd_m2c, PIP_ID_CIN, dummy, 1); - }*/ - refresh_oscam(REFR_READERS); // refresh all reader because write pipe seams not work from here + if(rdr->enable == 1 && rdr->client && rdr->client->typ == 'r') { + uchar dummy[1]={0x00}; + write_to_pipe(rdr->client, PIP_ID_CIN, dummy, 1); + } } } @@ -914,7 +917,6 @@ static char *send_oscam_reader_config(struct templatevars *vars, struct uriparam // Add new reader struct s_reader *newrdr; if(!cs_malloc(&newrdr,sizeof(struct s_reader), -1)) return "0"; - memset(newrdr, 0, sizeof(struct s_reader)); newrdr->next = NULL; // terminate list newrdr->enable = 0; // do not start the reader because must configured before ll_append(configured_readers, newrdr); @@ -952,13 +954,10 @@ static char *send_oscam_reader_config(struct templatevars *vars, struct uriparam } chk_reader("services", servicelabels, rdr); - if(write_server()==0) { - refresh_oscam(REFR_READERS); - // fixme: restart_cardreader causes segfaults sometimes - if (rdr->typ & R_IS_NETWORK) - restart_cardreader(rdr, 1); //physical readers make trouble if re-started - } - else + if (rdr->typ & R_IS_NETWORK) + restart_cardreader(rdr, 1); //physical readers make trouble if re-started + + if(write_server()!=0) tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); } @@ -1533,7 +1532,7 @@ static char *send_oscam_user_config_edit(struct templatevars *vars, struct uripa for (ptr = cfg.account; ptr != NULL && ptr->next != NULL; ptr = ptr->next); ptr->next = account; } - memset(account, 0, sizeof(struct s_auth)); + account->disabled = 1; cs_strncpy((char *)account->usr, user, sizeof(account->usr)); account->monlvl=cfg.mon_level; account->tosleep=cfg.tosleep; @@ -1546,12 +1545,9 @@ static char *send_oscam_user_config_edit(struct templatevars *vars, struct uripa #endif tpl_addVar(vars, TPLAPPEND, "MESSAGE", "New user has been added with default settings
"); - if (write_userdb(cfg.account)==0) - refresh_oscam(REFR_ACCOUNTS); - else + if (write_userdb()!=0) tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); - // need to reget account as writing to disk changes account! - for (account = cfg.account; account != NULL && strcmp(user, account->usr) != 0; account = account->next); + // no need to refresh anything here as the account is disabled by default and there's no client with this new account anyway! } if((strcmp(getParam(params, "action"), "Save") == 0) || (strcmp(getParam(params, "action"), "Save As") == 0)) { @@ -1570,15 +1566,12 @@ static char *send_oscam_user_config_edit(struct templatevars *vars, struct uripa } } chk_account("services", servicelabels, account); - tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Settings updated

"); + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Account updated

"); + + refresh_oscam(REFR_CLIENTS); - if (write_userdb(cfg.account)==0) - refresh_oscam(REFR_ACCOUNTS); - else + if (write_userdb()!=0) tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); - - // need to reget account as writing to disk changes account! - for (account = cfg.account; account != NULL && strcmp(user, account->usr) != 0; account = account->next); } tpl_addVar(vars, TPLADD, "USERNAME", account->usr); @@ -1779,9 +1772,8 @@ static char *send_oscam_user_config(struct templatevars *vars, struct uriparams } if (found > 0) { - if (write_userdb(cfg.account)==0) - refresh_oscam(REFR_ACCOUNTS); - else + refresh_oscam(REFR_CLIENTS); + if (write_userdb()!=0) tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); } else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Sorry but the specified user doesn't exist. No deletion will be made!
"); @@ -1791,12 +1783,13 @@ static char *send_oscam_user_config(struct templatevars *vars, struct uriparams if ((strcmp(getParam(params, "action"), "disable") == 0) || (strcmp(getParam(params, "action"), "enable") == 0)) { account = get_account_by_name(getParam(params, "user")); if (account) { - if(strcmp(getParam(params, "action"), "disable") == 0) + if(strcmp(getParam(params, "action"), "disable") == 0){ account->disabled = 1; - else + refresh_oscam(REFR_CLIENTS); + } else account->disabled = 0; - if (write_userdb(cfg.account) == 0) - refresh_oscam(REFR_ACCOUNTS); + if (write_userdb() != 0) + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); } else { tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Sorry but the specified user doesn't exist. No deletion will be made!
"); } @@ -2690,14 +2683,12 @@ static char *send_oscam_services_edit(struct templatevars *vars, struct uriparam for (ptr = cfg.sidtab; ptr != NULL && ptr->next != NULL; ptr = ptr->next); ptr->next = sidtab; } - memset(sidtab, 0, sizeof(struct s_sidtab)); cs_strncpy((char *)sidtab->label, label, sizeof(sidtab->label)); tpl_addVar(vars, TPLAPPEND, "MESSAGE", "New service has been added
"); - if (write_services()==0) refresh_oscam(REFR_SERVICES); - else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Writing services to disk failed!
"); - - for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next); + // Adding is uncritical as the new service is appended to sidtabok/sidtabno and accounts/clients have zeros there + if (write_services()!=0) + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Writing services to disk failed!
"); } if (strcmp(getParam(params, "action"), "Save") == 0) { @@ -2707,8 +2698,9 @@ static char *send_oscam_services_edit(struct templatevars *vars, struct uriparam } } tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Services updated

"); - if (write_services()==0) refresh_oscam(REFR_SERVICES); - else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); + // We don't any refresh here as accounts/clients sidtabok/sidtabno are unaffected! + if (write_services()!=0) + tpl_addVar(vars, TPLAPPEND, "MESSAGE", "Write Config failed

"); for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next); } diff --git a/oscam-http.h b/oscam-http.h index 0429cf87ea..bfa4ce6cf3 100644 --- a/oscam-http.h +++ b/oscam-http.h @@ -2056,7 +2056,7 @@ function isNumber(a) {\n\ \ " -enum refreshtypes {REFR_ACCOUNTS, REFR_READERS, REFR_SERVER, REFR_ANTICASC, REFR_SERVICES}; +enum refreshtypes {REFR_ACCOUNTS, REFR_CLIENTS, REFR_SERVER, REFR_ANTICASC, REFR_SERVICES}; char *tpl[]={ "HEADER", diff --git a/oscam-log.c b/oscam-log.c index 62ce435624..df37d3fc43 100644 --- a/oscam-log.c +++ b/oscam-log.c @@ -146,7 +146,12 @@ int32_t cs_init_log(void) #ifdef CS_ANTICASC int32_t ac_init_log(void){ - if(!fpa && cfg.ac_logfile[0]){ + FILE *tmp = fpa; + fpa=(FILE *)0; + if(tmp) + fclose(tmp); + + if(cfg.ac_logfile[0]){ if( (fpa=fopen(cfg.ac_logfile, "a+"))<=(FILE *)0 ){ fpa=(FILE *)0; fprintf(stderr, "can't open anti-cascading logfile: %s\n", cfg.ac_logfile);