Changeset 11356 for trunk/oscam-config-account.c
- Timestamp:
- 02/09/17 16:53:29 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/oscam-config-account.c
r11303 r11356 204 204 { 205 205 struct s_auth *account = setting; 206 if(value) 207 { 208 account->allowedtimeframe[0] = 0; 209 account->allowedtimeframe[1] = 0; 210 if(strlen(value)) 211 { 212 int32_t allowed[4]; 213 if(sscanf(value, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4) 206 int32_t i, j, t, startt, endt; 207 char *dest; 208 uint8_t day_idx; 209 int32_t allowed[4]; 210 uint32_t tempo = 0; 211 212 char *ptr1, *ptr2, *ptr3, *saveptr1 = NULL, *saveptr2 = NULL; 213 214 if(value) 215 { 216 //First empty allowedtimeframe array very important otherwise new config won't be properly set 217 for(i=0;i<SIZE_SHORTDAY;i++) { 218 for(j=0;j<24;j++) { 219 account->allowedtimeframe[i][j][0]=0; 220 account->allowedtimeframe[i][j][1]=0; 221 } 222 } 223 account->allowedtimeframe_set=0; 224 strtoupper(value); 225 226 for(i = 0, ptr1 = strtok_r(value, ";", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ";", &saveptr1), i++) 227 { 228 if((ptr2 = strchr(trim(ptr1), '@'))) 214 229 { 215 account->allowedtimeframe[0] = allowed[0] * 60 + allowed[1]; 216 account->allowedtimeframe[1] = allowed[2] * 60 + allowed[3]; 217 } 218 else 230 *ptr2++ = '\0'; //clean up @ symbol 231 //ptr1 is the day 232 dest = strstr(weekdstr,ptr1); 233 day_idx = (dest - weekdstr)/3; 234 235 for(j = 0, ptr3 = strtok_r(ptr2, ",", &saveptr2); (ptr3); ptr3 = strtok_r(NULL, ",", &saveptr2), j++) 236 { 237 if((sscanf(ptr3, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4) && (day_idx<SIZE_SHORTDAY)) 238 { 239 startt = allowed[0] * 60 + allowed[1]; 240 endt = allowed[2] * 60 + allowed[3]; 241 if(startt == endt) { endt++; } //end time cannot be the same as the star time 242 if((startt <0) || (startt > 1439)) { startt = 0; } //could not start later than 23H59, avoid overflow 243 if((endt <0) || (endt > 1440)) { endt = 1440; } //could not be higher than 24H00, avoid overflow 244 account->allowedtimeframe_set=1; 245 if(startt > endt) { 246 for(t=startt; t<1440 ;t++) 247 { 248 tempo = (1 << (t % 30)); 249 account->allowedtimeframe[day_idx][t/60][(t/30)%2]=account->allowedtimeframe[day_idx][t/60][(t/30)%2]|tempo; 250 } 251 startt=0; 252 } 253 for(t=startt; t<endt ;t++) 254 { 255 tempo = (1 << (t % 30)); 256 account->allowedtimeframe[day_idx][t/60][((t/30)%2)]=account->allowedtimeframe[day_idx][t/60][(t/30)%2]|tempo; 257 } 258 } 259 else 260 { 261 fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (DAY@HH:MM-HH:MM)\n", value); 262 } 263 } 264 } 265 else //No day specified so whole week (ALL) 219 266 { 220 fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value); 221 } 222 } 223 return; 224 } 225 if(account->allowedtimeframe[0] && account->allowedtimeframe[1]) 226 { 227 fprintf_conf(f, token, "%02d:%02d-%02d:%02d\n", 228 account->allowedtimeframe[0] / 60, account->allowedtimeframe[0] % 60, 229 account->allowedtimeframe[1] / 60, account->allowedtimeframe[1] % 60); 267 if(sscanf(ptr1, "%2d:%2d-%2d:%2d", &allowed[0], &allowed[1], &allowed[2], &allowed[3]) == 4) 268 { 269 startt = allowed[0] * 60 + allowed[1]; 270 endt = allowed[2] * 60 + allowed[3]; 271 if(startt == endt) { endt++; } //end time cannot be the same as the star time 272 if((startt <0) || (startt > 1439)) { startt = 0; } //could not start later than 23H59, avoid overflow 273 if((endt <0) || (endt > 1440)) { endt = 1440; } //could not be higher than 24H00, avoid overflow 274 account->allowedtimeframe_set=1; 275 dest = strstr(weekdstr,"ALL"); 276 day_idx = (dest - weekdstr)/3; 277 if(startt > endt) 278 { 279 for(t=startt; t<1440 ;t++) 280 { 281 tempo = (1 << (t % 30)); 282 account->allowedtimeframe[day_idx][t/60][(t/30)%2]=account->allowedtimeframe[7][t/60][(t/30)%2]|tempo; 283 } 284 startt=0; 285 } 286 for(t=startt; t<endt ;t++) 287 { 288 tempo = (1 << (t % 30)); 289 account->allowedtimeframe[day_idx][t/60][(t/30)%2]=account->allowedtimeframe[7][t/60][(t/30)%2]|tempo; 290 } 291 } 292 else 293 { 294 fprintf(stderr, "WARNING: Value '%s' is not valid for allowedtimeframe (hh:mm-hh:mm)\n", value); 295 } 296 297 } 298 } 299 return; 300 } 301 if(account->allowedtimeframe_set) 302 { 303 value = mk_t_allowedtimeframe(account); 304 fprintf_conf(f, token, "%s\n", value); 305 free_mk_t(value); 230 306 } 231 307 else if(cfg.http_full_cfg) … … 356 432 DEF_OPT_FUNC("expdate" , 0, account_expdate_fn), 357 433 DEF_OPT_FUNC("allowedprotocols" , 0, account_allowedprotocols_fn), 358 DEF_OPT_FUNC("allowedtimeframe" , 0, 434 DEF_OPT_FUNC("allowedtimeframe" , 0, account_allowedtimeframe_fn), 359 435 DEF_OPT_FUNC("betatunnel" , OFS(ttab), account_tuntab_fn), 360 436 DEF_OPT_FUNC("group" , OFS(grp), group_fn),
Note:
See TracChangeset
for help on using the changeset viewer.