Skip to content

Commit

Permalink
WebIf: Make refresh mechanism more subtle
Browse files Browse the repository at this point in the history
git-svn-id: http://streamboard.gmc.to/svn/oscam/trunk@5480 4b0bc96b-bc66-0410-9d44-ebda105a78c1
  • Loading branch information
Admin authored and Admin committed Jun 25, 2011
1 parent 4839174 commit a1ad9eb
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 87 deletions.
2 changes: 1 addition & 1 deletion global-functions.h
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion module-dvbapi.c
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion module-monitor.c
Expand Up @@ -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))
Expand Down
42 changes: 24 additions & 18 deletions oscam-config.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -4585,15 +4582,15 @@ 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);)
{
int32_t i, skip;
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;

Expand Down Expand Up @@ -4644,26 +4641,35 @@ 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);
nr++;
}
}
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;
}
Expand Down
120 changes: 56 additions & 64 deletions oscam-http.c
Expand Up @@ -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:
Expand All @@ -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;
Expand Down Expand Up @@ -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", "<BR><BR><B>Configuration CCCam done. You should restart OSCam now.</B><BR><BR>");
if(write_config()==0) refresh_oscam(REFR_SERVER);
else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
cc_update_nodeid();
Expand Down Expand Up @@ -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", "<BR><BR><B>Configuration Anticascading done. You should restart OSCam now.</B><BR><BR>");
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<BR><BR><B>Configuration Anticascading done.</B><BR><BR>");
refresh_oscam(REFR_ANTICASC);
if(write_config()==0) refresh_oscam(REFR_SERVER);
else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
if(write_config()!=0)
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
}
if (cfg.ac_enabled > 0) tpl_addVar(vars, TPLADD, "CHECKED", "checked");
tpl_printf(vars, TPLADD, "NUMUSERS", "%d", cfg.ac_users);
Expand Down Expand Up @@ -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", "<B>Write Config failed</B><BR><BR>");
if(write_server()!=0)
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
}
}
}
Expand All @@ -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);
}
}
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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", "<B>Write Config failed</B><BR><BR>");
}

Expand Down Expand Up @@ -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;
Expand All @@ -1546,12 +1545,9 @@ static char *send_oscam_user_config_edit(struct templatevars *vars, struct uripa
#endif
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>New user has been added with default settings</b><BR>");

if (write_userdb(cfg.account)==0)
refresh_oscam(REFR_ACCOUNTS);
else
if (write_userdb()!=0)
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
// 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)) {
Expand All @@ -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", "<B>Settings updated</B><BR><BR>");
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Account updated</B><BR><BR>");

refresh_oscam(REFR_CLIENTS);

if (write_userdb(cfg.account)==0)
refresh_oscam(REFR_ACCOUNTS);
else
if (write_userdb()!=0)
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");

// 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);
Expand Down Expand Up @@ -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", "<B>Write Config failed</B><BR><BR>");

} else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
Expand All @@ -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", "<B>Write Config failed</B><BR><BR>");
} else {
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Sorry but the specified user doesn't exist. No deletion will be made!</b><BR>");
}
Expand Down Expand Up @@ -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", "<b>New service has been added</b><BR>");
if (write_services()==0) refresh_oscam(REFR_SERVICES);
else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<b>Writing services to disk failed!</b><BR>");

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", "<b>Writing services to disk failed!</b><BR>");
}

if (strcmp(getParam(params, "action"), "Save") == 0) {
Expand All @@ -2707,8 +2698,9 @@ static char *send_oscam_services_edit(struct templatevars *vars, struct uriparam
}
}
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Services updated</B><BR><BR>");
if (write_services()==0) refresh_oscam(REFR_SERVICES);
else tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");
// We don't any refresh here as accounts/clients sidtabok/sidtabno are unaffected!
if (write_services()!=0)
tpl_addVar(vars, TPLAPPEND, "MESSAGE", "<B>Write Config failed</B><BR><BR>");

for (sidtab = cfg.sidtab; sidtab != NULL && strcmp(label, sidtab->label) != 0; sidtab=sidtab->next);
}
Expand Down
2 changes: 1 addition & 1 deletion oscam-http.h
Expand Up @@ -2056,7 +2056,7 @@ function isNumber(a) {\n\
</script>\
</svg>"

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",
Expand Down
7 changes: 6 additions & 1 deletion oscam-log.c
Expand Up @@ -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);
Expand Down

0 comments on commit a1ad9eb

Please sign in to comment.