-account enabled from hh:mm to hh:mm, default:none
+allowedtimeframe = DAY@hh:mm-hh:mm[,hh:mm-hh:mm][,hh:mm-hh:mm][;DAY@hh:mm-hh:mm[,hh:mm-hh:mm][,hh:mm-hh:mm]]
+
+where DAY is SUN,MON,TUE,WED,THU,FRI,SAT or ALL (for all possible days)
+
+account enabled from hh:mm to hh:mm for the specified days, default:none
+
+comma (,) to separate times and semicolon(; ) to separate the different days.
+You can use ALL@ if you want the same time frames for everyday.
+
+Example:
+allowedtimeframe = ALL@10:00-22:00;MON@00:00-02:00,02:45-04:37;FRI@00:00-10:00,22:00-24:00;SAT@00:00-24:00
+
+If you use: DAY@22:00-05:00 this will be turned into DAY@00:00-05:00,22:00-24:00
+
+ALL@ is always checked and used, so you can watch TV the whole day on FRIday in this exemple. There is no problem to overlap ALL@ in a day definition, like for SAT@ definition.
Index: /trunk/Distribution/doc/txt/oscam.user.txt
===================================================================
--- /trunk/Distribution/doc/txt/oscam.user.txt (revision 11355)
+++ /trunk/Distribution/doc/txt/oscam.user.txt (revision 11356)
@@ -36,6 +36,18 @@
list of all allowed connection protocols, default:all connection protocols
- allowedtimeframe = hh:mm-hh:mm
- account enabled from hh:mm to hh:mm, default:none
+ allowedtimeframe = DAY@HH:MM-HH:MM[,HH:MM-HH:MM][,HH:MM-HH:MM][;DAY@HH:MM-HH:MM[,HH:MM-HH:MM][,HH:MM-HH:MM]]
+ where DAY=SUN,MON,TUE,WED,THU,FRI,SAT or ALL (for all possible days)
+
+ account enabled from hh:mm to hh:mm for the specified day(s), default:none
+
+ comma (,) to separate times and semicolon(; ) to separate the different days.
+ You can use ALL@ if you want the same time frames for everyday.
+
+ Example:
+ allowedtimeframe = ALL@10:00-22:00;MON@00:00-02:00,02:45-04:37;FRI@00:00-10:00,22:00-24:00;SAT@00:00-24:00
+
+ If you use: DAY@22:00-05:00 this will be turned into DAY@00:00-05:00,22:00-24:00
+
+ ALL@ is always checked and used, so you can watch TV the whole day on FRIday in this exemple. There is no problem to overlap ALL@ in a day definition, like for SAT@ definition.
max_connections = count
Index: /trunk/globals.h
===================================================================
--- /trunk/globals.h (revision 11355)
+++ /trunk/globals.h (revision 11356)
@@ -357,4 +357,6 @@
#endif
+#define CHECK_BIT(var,pos) (((var) & (1<<(pos)))? 1 : 0)
+
/* ===========================
* constants
@@ -602,4 +604,9 @@
#define CW_ALGO_MODE_ECB 0
#define CW_ALGO_MODE_CBC 1
+
+#define SIZE_SHORTDAY 8
+#define MAXALLOWEDTF 1001 // 10 allowed time frame slots for everyday + all [(3 + 1 + 10*(12) + 1)*8]
+extern const char *shortDay[SIZE_SHORTDAY];
+extern const char *weekdstr;
/* ===========================
@@ -1174,5 +1181,6 @@
time_t lastecm;
time_t expirationdate;
- int32_t allowedtimeframe[2];
+ uint32_t allowedtimeframe[SIZE_SHORTDAY][24][2]; //day[0-sun to 6-sat, 7-ALL],hours,minutes use as binary flags to reduce mem usage
+ uint8_t allowedtimeframe_set; //flag for internal use to mention if allowed time frame is used
int8_t c35_suppresscmd08;
uint8_t c35_sleepsend;
@@ -1773,5 +1781,6 @@
time_t expirationdate;
time_t firstlogin;
- int32_t allowedtimeframe[2];
+ uint32_t allowedtimeframe[SIZE_SHORTDAY][24][2]; //day[0-sun to 6-sat, 7-ALL],hours,minutes use as binary flags to reduce mem usage
+ uint8_t allowedtimeframe_set; //flag for internal use to mention if allowed time frame is used
int8_t c35_suppresscmd08;
uint8_t c35_sleepsend;
Index: /trunk/module-webif.c
===================================================================
--- /trunk/module-webif.c (revision 11355)
+++ /trunk/module-webif.c (revision 11356)
@@ -3147,14 +3147,9 @@
strftime(buf, 80, "%Y-%m-%d", &timeinfo);
if(strcmp(buf, "1970-01-01")) { tpl_addVar(vars, TPLADD, "EXPDATE", buf); }
-
+
//Allowed TimeFrame
- if(account->allowedtimeframe[0] && account->allowedtimeframe[1])
- {
- tpl_printf(vars, TPLADD, "ALLOWEDTIMEFRAME", "%02d:%02d-%02d:%02d",
- account->allowedtimeframe[0] / 60,
- account->allowedtimeframe[0] % 60,
- account->allowedtimeframe[1] / 60,
- account->allowedtimeframe[1] % 60);
- }
+ char *allowedtf = mk_t_allowedtimeframe(account);
+ tpl_printf(vars, TPLADD, "ALLOWEDTIMEFRAME", "%s", allowedtf);
+ free_mk_t(allowedtf);
//Group
Index: /trunk/oscam-client.c
===================================================================
--- /trunk/oscam-client.c (revision 11355)
+++ /trunk/oscam-client.c (revision 11356)
@@ -324,4 +324,6 @@
int32_t rc = 0;
unsigned char md5tmp[MD5_DIGEST_LENGTH];
+ uint8_t i;
+ uint8_t j;
char buf[32];
char *t_crypt = "encrypted";
@@ -405,6 +407,13 @@
client->expirationdate = account->expirationdate;
client->disabled = account->disabled;
- client->allowedtimeframe[0] = account->allowedtimeframe[0];
- client->allowedtimeframe[1] = account->allowedtimeframe[1];
+ client->allowedtimeframe_set=account->allowedtimeframe_set;
+ for(i=0;iallowedtimeframe[i][j][0]=account->allowedtimeframe[i][j][0];
+ client->allowedtimeframe[i][j][1]=account->allowedtimeframe[i][j][1];
+ }
+ }
if(account->firstlogin == 0) { account->firstlogin = time((time_t *)0); }
client->failban = account->failban;
@@ -500,4 +509,6 @@
struct s_auth *account;
unsigned char md5tmp[MD5_DIGEST_LENGTH];
+ uint8_t i;
+ uint8_t j;
struct s_client *cl;
@@ -520,6 +531,13 @@
cl->autoau = account->autoau;
cl->expirationdate = account->expirationdate;
- cl->allowedtimeframe[0] = account->allowedtimeframe[0];
- cl->allowedtimeframe[1] = account->allowedtimeframe[1];
+ cl->allowedtimeframe_set=account->allowedtimeframe_set;
+ for(i=0;iallowedtimeframe[i][j][0]=account->allowedtimeframe[i][j][0];
+ cl->allowedtimeframe[i][j][1]=account->allowedtimeframe[i][j][1];
+ }
+ }
cl->ncd_keepalive = account->ncd_keepalive;
cl->c35_suppresscmd08 = account->c35_suppresscmd08;
Index: /trunk/oscam-conf-mk.c
===================================================================
--- /trunk/oscam-conf-mk.c (revision 11355)
+++ /trunk/oscam-conf-mk.c (revision 11356)
@@ -5,4 +5,7 @@
#include "oscam-net.h"
#include "oscam-string.h"
+
+const char *shortDay[8] = {"SUN","MON","TUE","WED","THU","FRI","SAT","ALL"};
+const char *weekdstr = "SUNMONTUEWEDTHUFRISATALL";
/*
@@ -889,4 +892,72 @@
/*
+ * return allowed time frame string from internal array content
+ *
+ */
+
+char *mk_t_allowedtimeframe(struct s_auth *account)
+{
+ char *result;
+ if(!cs_malloc(&result, MAXALLOWEDTF))
+ { return ""; }
+
+ if(account->allowedtimeframe_set)
+ {
+ char mytime[6];
+ uint8_t day;
+ uint8_t value_in_day = 0;
+ uint8_t intime = 0;
+ uint16_t minutes =0;
+ uint16_t hours;
+ char septime[2] = {'\0'};
+ char sepday[2] = {'\0'};
+
+ for(day=0;dayallowedtimeframe[day][hours][minutes/30],(minutes % 30))) {
+ if(value_in_day == 0) {
+ strcat(result,&sepday[0]);
+ strcat(result,shortDay[day]);
+ strcat(result,"@");
+ value_in_day = 1;
+ intime=0;
+ sepday[0]=';';
+ septime[0]='\0';
+ }
+ if(!intime) {
+ strcat(result,&septime[0]);
+ snprintf(mytime,6,"%02d:%02d", hours, minutes);
+ strcat(result,mytime);
+ strcat(result,"-");
+ septime[0]=',';
+ intime=1;
+ }
+ // Special case 23H59 is enabled we close the day at 24H00
+ if(((hours*60)+minutes)==1439) {
+ strcat(result,"24:00");
+ intime=0;
+ septime[0]='\0';
+ value_in_day = 0;
+ }
+ }
+ else if(intime) {
+ snprintf(mytime,6,"%02d:%02d", hours, minutes);
+ strcat(result,mytime);
+ septime[0]=',';
+ intime=0;
+ }
+ }
+ }
+ value_in_day = 0;
+ }
+ }
+ else {
+ result="";
+ }
+ return result;
+}
+
+/*
* mk_t-functions give back a constant empty string when allocation fails or when the result is an empty string.
* This function thus checks the stringlength and only frees if necessary.
Index: /trunk/oscam-conf-mk.h
===================================================================
--- /trunk/oscam-conf-mk.h (revision 11355)
+++ /trunk/oscam-conf-mk.h (revision 11356)
@@ -29,4 +29,5 @@
extern char *mk_t_emmbylen(struct s_reader *rdr);
extern char *mk_t_allowedprotocols(struct s_auth *account);
+extern char *mk_t_allowedtimeframe(struct s_auth *account);
extern void free_mk_t(char *value);
Index: /trunk/oscam-config-account.c
===================================================================
--- /trunk/oscam-config-account.c (revision 11355)
+++ /trunk/oscam-config-account.c (revision 11356)
@@ -204,28 +204,104 @@
{
struct s_auth *account = setting;
- if(value)
- {
- account->allowedtimeframe[0] = 0;
- account->allowedtimeframe[1] = 0;
- if(strlen(value))
- {
- int32_t allowed[4];
- if(sscanf(value, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4)
+ int32_t i, j, t, startt, endt;
+ char *dest;
+ uint8_t day_idx;
+ int32_t allowed[4];
+ uint32_t tempo = 0;
+
+ char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL, *saveptr2 = NULL;
+
+ if(value)
+ {
+ //First empty allowedtimeframe array very important otherwise new config won't be properly set
+ for(i=0;iallowedtimeframe[i][j][0]=0;
+ account->allowedtimeframe[i][j][1]=0;
+ }
+ }
+ account->allowedtimeframe_set=0;
+ strtoupper(value);
+
+ for(i = 0, ptr1 = strtok_r(value, ";", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ";", &saveptr1), i++)
+ {
+ if((ptr2 = strchr(trim(ptr1), '@')))
{
- account->allowedtimeframe[0] = allowed[0] * 60 + allowed[1];
- account->allowedtimeframe[1] = allowed[2] * 60 + allowed[3];
- }
- else
+ *ptr2++ = '\0'; //clean up @ symbol
+ //ptr1 is the day
+ dest = strstr(weekdstr,ptr1);
+ day_idx = (dest - weekdstr)/3;
+
+ for(j = 0, ptr3 = strtok_r(ptr2, ",", &saveptr2); (ptr3); ptr3 = strtok_r(NULL, ",", &saveptr2), j++)
+ {
+ if((sscanf(ptr3, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4) && (day_idx 1439)) { startt = 0; } //could not start later than 23H59, avoid overflow
+ if((endt <0) || (endt > 1440)) { endt = 1440; } //could not be higher than 24H00, avoid overflow
+ account->allowedtimeframe_set=1;
+ if(startt > endt) {
+ for(t=startt; t<1440 ;t++)
+ {
+ tempo = (1 << (t % 30));
+ account->allowedtimeframe[day_idx][t/60][(t/30)%2]=account->allowedtimeframe[day_idx][t/60][(t/30)%2]|tempo;
+ }
+ startt=0;
+ }
+ for(t=startt; tallowedtimeframe[day_idx][t/60][((t/30)%2)]=account->allowedtimeframe[day_idx][t/60][(t/30)%2]|tempo;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (DAY@HH:MM-HH:MM)\n", value);
+ }
+ }
+ }
+ else //No day specified so whole week (ALL)
{
- fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value);
- }
- }
- return;
- }
- if(account->allowedtimeframe[0] && account->allowedtimeframe[1])
- {
- fprintf_conf(f, token, "%02d:%02d-%02d:%02d\n",
- account->allowedtimeframe[0] / 60, account->allowedtimeframe[0] % 60,
- account->allowedtimeframe[1] / 60, account->allowedtimeframe[1] % 60);
+ if(sscanf(ptr1, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4)
+ {
+ startt = allowed[0] * 60 + allowed[1];
+ endt = allowed[2] * 60 + allowed[3];
+ if(startt == endt) { endt++; } //end time cannot be the same as the star time
+ if((startt <0) || (startt > 1439)) { startt = 0; } //could not start later than 23H59, avoid overflow
+ if((endt <0) || (endt > 1440)) { endt = 1440; } //could not be higher than 24H00, avoid overflow
+ account->allowedtimeframe_set=1;
+ dest = strstr(weekdstr,"ALL");
+ day_idx = (dest - weekdstr)/3;
+ if(startt > endt)
+ {
+ for(t=startt; t<1440 ;t++)
+ {
+ tempo = (1 << (t % 30));
+ account->allowedtimeframe[day_idx][t/60][(t/30)%2]=account->allowedtimeframe[7][t/60][(t/30)%2]|tempo;
+ }
+ startt=0;
+ }
+ for(t=startt; tallowedtimeframe[day_idx][t/60][(t/30)%2]=account->allowedtimeframe[7][t/60][(t/30)%2]|tempo;
+ }
+ }
+ else
+ {
+ fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value);
+ }
+
+ }
+ }
+ return;
+ }
+ if(account->allowedtimeframe_set)
+ {
+ value = mk_t_allowedtimeframe(account);
+ fprintf_conf(f, token, "%s\n", value);
+ free_mk_t(value);
}
else if(cfg.http_full_cfg)
@@ -356,5 +432,5 @@
DEF_OPT_FUNC("expdate" , 0, account_expdate_fn),
DEF_OPT_FUNC("allowedprotocols" , 0, account_allowedprotocols_fn),
- DEF_OPT_FUNC("allowedtimeframe" , 0, account_allowedtimeframe_fn),
+ DEF_OPT_FUNC("allowedtimeframe" , 0, account_allowedtimeframe_fn),
DEF_OPT_FUNC("betatunnel" , OFS(ttab), account_tuntab_fn),
DEF_OPT_FUNC("group" , OFS(grp), group_fn),
Index: /trunk/oscam-ecm.c
===================================================================
--- /trunk/oscam-ecm.c (revision 11355)
+++ /trunk/oscam-ecm.c (revision 11356)
@@ -2092,16 +2092,24 @@
// out of timeframe
- if(client->allowedtimeframe[0] && client->allowedtimeframe[1])
+ if(client->allowedtimeframe_set)
{
struct tm acttm;
localtime_r(&now, &acttm);
- int32_t curtime = (acttm.tm_hour * 60) + acttm.tm_min;
- int32_t mintime = client->allowedtimeframe[0];
- int32_t maxtime = client->allowedtimeframe[1];
- if(!((mintime <= maxtime && curtime > mintime && curtime < maxtime) || (mintime > maxtime && (curtime > mintime || curtime < maxtime))))
+ int32_t curday = acttm.tm_wday;
+ char *dest = strstr(weekdstr,"ALL");
+ int32_t all_idx = (dest - weekdstr)/3;
+ uint8_t allowed=0;
+
+ // checkout if current time is allowed in the current day
+ allowed = CHECK_BIT(client->allowedtimeframe[curday][acttm.tm_hour][acttm.tm_min/30], (acttm.tm_min % 30));
+
+ // or checkout if current time is allowed for all days
+ allowed |= CHECK_BIT(client->allowedtimeframe[all_idx][acttm.tm_hour][acttm.tm_min/30], (acttm.tm_min % 30));
+
+ if(!(allowed))
{
er->rc = E_EXPDATE;
}
- cs_log_dbg(D_TRACE, "Check Timeframe - result: %d, start: %d, current: %d, end: %d\n", er->rc, mintime, curtime, maxtime);
+ cs_log_dbg(D_TRACE, "Check Timeframe - result: %d, day:%s time: %02dH%02d, allowed: %s\n", er->rc, shortDay[curday], acttm.tm_hour, acttm.tm_min, allowed ? "true" : "false");
}
Index: /trunk/webif/user_edit/user_edit.html
===================================================================
--- /trunk/webif/user_edit/user_edit.html (revision 11355)
+++ /trunk/webif/user_edit/user_edit.html (revision 11356)
@@ -17,5 +17,5 @@