Changeset 9570 for trunk/module-webif.c
- Timestamp:
- 03/18/14 22:57:57 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/module-webif.c
r9568 r9570 5 5 // OSCam HTTP server module 6 6 // 7 7 #include "cscrypt/md5.h" 8 8 #include "module-anticasc.h" 9 9 #include "module-cacheex.h" … … 68 68 #define MNU_SCRIPT 8 69 69 #define MNU_SHUTDOWN 9 70 #define MNU_TOTAL_ITEMS 10 // sum of items above 70 #define MNU_LIVELOG 10 71 #define MNU_TOTAL_ITEMS 11 // sum of items above 71 72 /* constants for submenuactivating */ 72 73 #define MNU_CFG_GLOBAL 0 … … 1190 1191 struct s_reader *rdr; 1191 1192 int32_t i; 1193 unsigned char md5tmp[MD5_DIGEST_LENGTH]; 1192 1194 1193 1195 if(!apicall) { setActiveMenu(vars, MNU_READERS); } … … 1291 1293 } 1292 1294 1295 int jsondelimiter = 0; 1296 1293 1297 ll_iter_reset(&itr); //going to iterate all configured readers 1294 1298 while((rdr = ll_iter_next(&itr))) … … 1300 1304 // used for API and WebIf 1301 1305 tpl_addVar(vars, TPLADD, "READERNAME", xml_encode(vars, rdr->label)); 1306 1307 MD5((unsigned char *)rdr->label, strlen(rdr->label), md5tmp); 1308 int z; 1309 tpl_addVar(vars, TPLADD, "LABELMD5",""); 1310 for (z = 0; z < MD5_DIGEST_LENGTH; z++){ 1311 tpl_printf(vars, TPLAPPEND, "LABELMD5", "%02x", md5tmp[z]); 1312 } 1313 1302 1314 tpl_addVar(vars, TPLADD, "READERNAMEENC", urlencode(vars, rdr->label)); 1303 1315 tpl_addVar(vars, TPLADD, "CTYP", reader_get_type_desc(rdr, 0)); 1304 1316 1305 // used only for WebIf 1306 if(!apicall) 1307 { 1308 tpl_addVar(vars, TPLADD, "READERCLASS", rdr->enable ? "enabledreader" : "disabledreader"); 1309 1310 const char *readername_tpl = "READERLABEL"; 1311 if(cfg.http_showpicons && !apicall) 1312 { 1313 readername_tpl = picon_exists(xml_encode(vars, rdr->label)) ? "READERNAMEBIT" : "READERNOICON"; 1314 tpl_addVar(vars, TPLADD, "CTYP", picon_exists(xml_encode(vars, reader_get_type_desc(rdr, 0))) ? tpl_getTpl(vars, "READERCTYPBIT") : tpl_getTpl(vars, "READERCTYPNOICON")); 1315 } 1316 tpl_addVar(vars, TPLADD, "READERNAME", tpl_getTpl(vars, readername_tpl)); 1317 1318 char *value = mk_t_group(rdr->grp); 1319 tpl_addVar(vars, TPLADD, "GROUPS", value); 1320 free_mk_t(value); 1321 tpl_printf(vars, TPLADD, "EMMERRORUK", "%d", rdr->emmerror[UNKNOWN]); 1322 tpl_printf(vars, TPLADD, "EMMERRORG", "%d", rdr->emmerror[GLOBAL]); 1323 tpl_printf(vars, TPLADD, "EMMERRORS", "%d", rdr->emmerror[SHARED]); 1324 tpl_printf(vars, TPLADD, "EMMERRORUQ", "%d", rdr->emmerror[UNIQUE]); 1325 1326 tpl_printf(vars, TPLADD, "EMMWRITTENUK", "%d", rdr->emmwritten[UNKNOWN]); 1327 tpl_printf(vars, TPLADD, "EMMWRITTENG", "%d", rdr->emmwritten[GLOBAL]); 1328 tpl_printf(vars, TPLADD, "EMMWRITTENS", "%d", rdr->emmwritten[SHARED]); 1329 tpl_printf(vars, TPLADD, "EMMWRITTENUQ", "%d", rdr->emmwritten[UNIQUE]); 1330 1331 tpl_printf(vars, TPLADD, "EMMSKIPPEDUK", "%d", rdr->emmskipped[UNKNOWN]); 1332 tpl_printf(vars, TPLADD, "EMMSKIPPEDG", "%d", rdr->emmskipped[GLOBAL]); 1333 tpl_printf(vars, TPLADD, "EMMSKIPPEDS", "%d", rdr->emmskipped[SHARED]); 1334 tpl_printf(vars, TPLADD, "EMMSKIPPEDUQ", "%d", rdr->emmskipped[UNIQUE]); 1335 1336 tpl_printf(vars, TPLADD, "EMMBLOCKEDUK", "%d", rdr->emmblocked[UNKNOWN]); 1337 tpl_printf(vars, TPLADD, "EMMBLOCKEDG", "%d", rdr->emmblocked[GLOBAL]); 1338 tpl_printf(vars, TPLADD, "EMMBLOCKEDS", "%d", rdr->emmblocked[SHARED]); 1339 tpl_printf(vars, TPLADD, "EMMBLOCKEDUQ", "%d", rdr->emmblocked[UNIQUE]); 1340 1341 tpl_printf(vars, TPLADD, "ECMSOK", "%u (%.2f%%)", rdr->ecmsok, rdr->ecmshealthok); 1342 tpl_printf(vars, TPLADD, "ECMSNOK", "%u (%.2f%%)", rdr->ecmsnok, rdr->ecmshealthnok); 1343 tpl_printf(vars, TPLADD, "ECMSFILTEREDHEAD", "%d", rdr->ecmsfilteredhead); 1344 tpl_printf(vars, TPLADD, "ECMSFILTEREDLEN", "%d", rdr->ecmsfilteredlen); 1317 tpl_addVar(vars, TPLADD, "READERCLASS", rdr->enable ? "enabledreader" : "disabledreader"); 1318 1319 const char *readername_tpl = "READERLABEL"; 1320 if(cfg.http_showpicons && !apicall) 1321 { 1322 readername_tpl = picon_exists(xml_encode(vars, rdr->label)) ? "READERNAMEBIT" : "READERNOICON"; 1323 tpl_addVar(vars, TPLADD, "CTYP", picon_exists(xml_encode(vars, reader_get_type_desc(rdr, 0))) ? tpl_getTpl(vars, "READERCTYPBIT") : tpl_getTpl(vars, "READERCTYPNOICON")); 1324 } 1325 tpl_addVar(vars, TPLADD, "READERNAME", tpl_getTpl(vars, readername_tpl)); 1326 1327 char *value = mk_t_group(rdr->grp); 1328 tpl_addVar(vars, TPLADD, "GROUPS", value); 1329 free_mk_t(value); 1330 tpl_printf(vars, TPLADD, "EMMERRORUK", "%d", rdr->emmerror[UNKNOWN]); 1331 tpl_printf(vars, TPLADD, "EMMERRORG", "%d", rdr->emmerror[GLOBAL]); 1332 tpl_printf(vars, TPLADD, "EMMERRORS", "%d", rdr->emmerror[SHARED]); 1333 tpl_printf(vars, TPLADD, "EMMERRORUQ", "%d", rdr->emmerror[UNIQUE]); 1334 1335 tpl_printf(vars, TPLADD, "EMMWRITTENUK", "%d", rdr->emmwritten[UNKNOWN]); 1336 tpl_printf(vars, TPLADD, "EMMWRITTENG", "%d", rdr->emmwritten[GLOBAL]); 1337 tpl_printf(vars, TPLADD, "EMMWRITTENS", "%d", rdr->emmwritten[SHARED]); 1338 tpl_printf(vars, TPLADD, "EMMWRITTENUQ", "%d", rdr->emmwritten[UNIQUE]); 1339 1340 tpl_printf(vars, TPLADD, "EMMSKIPPEDUK", "%d", rdr->emmskipped[UNKNOWN]); 1341 tpl_printf(vars, TPLADD, "EMMSKIPPEDG", "%d", rdr->emmskipped[GLOBAL]); 1342 tpl_printf(vars, TPLADD, "EMMSKIPPEDS", "%d", rdr->emmskipped[SHARED]); 1343 tpl_printf(vars, TPLADD, "EMMSKIPPEDUQ", "%d", rdr->emmskipped[UNIQUE]); 1344 1345 tpl_printf(vars, TPLADD, "EMMBLOCKEDUK", "%d", rdr->emmblocked[UNKNOWN]); 1346 tpl_printf(vars, TPLADD, "EMMBLOCKEDG", "%d", rdr->emmblocked[GLOBAL]); 1347 tpl_printf(vars, TPLADD, "EMMBLOCKEDS", "%d", rdr->emmblocked[SHARED]); 1348 tpl_printf(vars, TPLADD, "EMMBLOCKEDUQ", "%d", rdr->emmblocked[UNIQUE]); 1349 1350 tpl_printf(vars, TPLADD, "ECMSOK", "%u (%.2f%%)", rdr->ecmsok, rdr->ecmshealthok); 1351 tpl_printf(vars, TPLADD, "ECMSNOK", "%u (%.2f%%)", rdr->ecmsnok, rdr->ecmshealthnok); 1352 tpl_printf(vars, TPLADD, "ECMSFILTEREDHEAD", "%d", rdr->ecmsfilteredhead); 1353 tpl_printf(vars, TPLADD, "ECMSFILTEREDLEN", "%d", rdr->ecmsfilteredlen); 1345 1354 #ifdef WITH_LB 1346 tpl_printf(vars, TPLADD, "LBWEIGHT", "%d", rdr->lb_weight); 1347 #endif 1348 if(!is_network_reader(rdr)) //reader is physical 1349 { 1350 tpl_addVar(vars, TPLADD, "REFRICO", "image?i=ICREF"); 1351 tpl_addVar(vars, TPLADD, "READERREFRESH", tpl_getTpl(vars, "READERREFRESHBIT")); 1355 tpl_printf(vars, TPLADD, "LBWEIGHT", "%d", rdr->lb_weight); 1356 #endif 1357 if(!is_network_reader(rdr)) //reader is physical 1358 { 1359 tpl_addVar(vars, TPLADD, "REFRICO", "image?i=ICREF"); 1360 tpl_addVar(vars, TPLADD, "READERREFRESH", tpl_getTpl(vars, "READERREFRESHBIT")); 1361 tpl_addVar(vars, TPLADD, "ENTICO", "image?i=ICENT"); 1362 tpl_addVar(vars, TPLADD, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT")); 1363 } 1364 else 1365 { 1366 tpl_addVar(vars, TPLADD, "READERREFRESH", ""); 1367 if(rdr->typ == R_CCCAM) 1368 { 1352 1369 tpl_addVar(vars, TPLADD, "ENTICO", "image?i=ICENT"); 1353 1370 tpl_addVar(vars, TPLADD, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT")); … … 1355 1372 else 1356 1373 { 1357 tpl_addVar(vars, TPLADD, "READERREFRESH", ""); 1358 if(rdr->typ == R_CCCAM) 1359 { 1360 tpl_addVar(vars, TPLADD, "ENTICO", "image?i=ICENT"); 1361 tpl_addVar(vars, TPLADD, "ENTITLEMENT", tpl_getTpl(vars, "READERENTITLEBIT")); 1362 } 1363 else 1364 { 1365 tpl_addVar(vars, TPLADD, "ENTITLEMENT", ""); 1366 } 1367 } 1368 1369 if(rdr->enable == 0) 1370 { 1371 tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICENA"); 1372 tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Enable this reader"); 1373 tpl_addVar(vars, TPLADD, "SWITCH", "enable"); 1374 tpl_addVar(vars, TPLADD, "WRITEEMM", ""); 1375 } 1376 else 1377 { 1378 tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICDIS"); 1379 tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Disable this reader"); 1380 tpl_addVar(vars, TPLADD, "SWITCH", "disable"); 1381 1382 tpl_addVar(vars, TPLADD, "EMMICO", "image?i=ICEMM"); 1383 tpl_addVar(vars, TPLADD, "WRITEEMM", tpl_getTpl(vars, "READERWRITEEMMBIT")); 1384 } 1385 1374 tpl_addVar(vars, TPLADD, "ENTITLEMENT", ""); 1375 } 1376 } 1377 1378 if(rdr->enable == 0) 1379 { 1380 tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICENA"); 1381 tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Enable this reader"); 1382 tpl_addVar(vars, TPLADD, "SWITCH", "enable"); 1383 tpl_addVar(vars, TPLADD, "WRITEEMM", ""); 1384 } 1385 else 1386 { 1387 tpl_addVar(vars, TPLADD, "SWITCHICO", "image?i=ICDIS"); 1388 tpl_addVar(vars, TPLADD, "SWITCHTITLE", "Disable this reader"); 1389 tpl_addVar(vars, TPLADD, "SWITCH", "disable"); 1390 1391 tpl_addVar(vars, TPLADD, "EMMICO", "image?i=ICEMM"); 1392 tpl_addVar(vars, TPLADD, "WRITEEMM", tpl_getTpl(vars, "READERWRITEEMMBIT")); 1393 } 1394 1395 if(!apicall) 1396 { 1386 1397 // Add to WebIf Template 1387 1398 tpl_addVar(vars, TPLAPPEND, "READERLIST", tpl_getTpl(vars, "READERSBIT")); 1388 1389 1399 } 1390 1400 else … … 1394 1404 tpl_addVar(vars, TPLADD, "APIREADERENABLED", !rdr->enable ? "0" : "1"); 1395 1405 if(cl) 1396 { tpl_printf(vars, TPLADD, "APIREADERTYPE", "%c", cl->typ ? cl->typ : 'x'); } 1397 1398 // Add to API Template 1399 tpl_addVar(vars, TPLAPPEND, "APIREADERLIST", tpl_getTpl(vars, "APIREADERSBIT")); 1400 } 1406 { 1407 tpl_printf(vars, TPLADD, "APIREADERTYPE", "%c", cl->typ ? cl->typ : 'x'); 1408 } 1409 1410 if(apicall==1) 1411 { 1412 // Add to API Template 1413 tpl_addVar(vars, TPLAPPEND, "APIREADERLIST", tpl_getTpl(vars, "APIREADERSBIT")); 1414 } 1415 if(apicall==2) 1416 { 1417 tpl_printf(vars, TPLAPPEND, "APIREADERLIST","%s%s",jsondelimiter?",":"", tpl_getTpl(vars, "JSONREADERBIT")); 1418 jsondelimiter++; 1419 } 1420 } 1421 1401 1422 } 1402 1423 } … … 1436 1457 { 1437 1458 if(cardreaders[i].desc) 1438 { tpl_printf(vars, TPLAPPEND, "ADDPROTOCOL", "<option>%s</option>\n", xml_encode(vars, cardreaders[i].desc)); } 1459 { 1460 tpl_printf(vars, TPLAPPEND, "ADDPROTOCOL", "<option>%s</option>\n", xml_encode(vars, cardreaders[i].desc)); 1461 } 1439 1462 } 1440 1463 return tpl_getTpl(vars, "READERS"); … … 1442 1465 else 1443 1466 { 1444 return tpl_getTpl(vars, "APIREADERS"); 1467 if(apicall == 1) 1468 { 1469 return tpl_getTpl(vars, "APIREADERS"); 1470 } 1471 else 1472 { 1473 return tpl_getTpl(vars, "JSONREADER"); 1474 } 1445 1475 } 1446 1476 } … … 2710 2740 tpl_addVar(vars, TPLADDONCE, "CLIENTPROTO", ""); 2711 2741 tpl_addVar(vars, TPLADDONCE, "CLIENTPROTOTITLE", ""); 2742 tpl_addVar(vars, TPLADDONCE, "PROTOICON", ""); 2712 2743 if(!cl) { return; } 2713 2744 #ifdef MODULE_NEWCAMD 2714 2745 if(streq(proto, "newcamd") && cl->typ == 'c') 2715 2746 { 2716 if(cfg.http_showpicons && !apicall)2747 if(cfg.http_showpicons ) 2717 2748 { 2718 2749 char picon_name[32]; … … 2722 2753 tpl_addVar(vars, TPLADD, "NCMDA", (char *)proto); 2723 2754 tpl_addVar(vars, TPLADD, "NCMDB", (char *)newcamd_get_client_name(cl->ncd_client_id)); 2724 tpl_addVar(vars, TPLADD, "CLIENTPROTO", tpl_getTpl(vars, "PROTONEWCAMDPIC")); 2755 if (!apicall) { 2756 tpl_addVar(vars, TPLADD, "CLIENTPROTO", tpl_getTpl(vars, "PROTONEWCAMDPIC")); 2757 } else { 2758 tpl_printf(vars, TPLADD, "CLIENTPROTO", "%s (%s)", proto, newcamd_get_client_name(cl->ncd_client_id)); 2759 tpl_printf(vars, TPLADDONCE, "PROTOICON", "%s_%s",(char *)proto, (char *)newcamd_get_client_name(cl->ncd_client_id)); 2760 } 2725 2761 } 2726 2762 else … … 2743 2779 if(cc && cc->remote_version && cc->remote_build) 2744 2780 { 2745 if(cfg.http_showpicons && !apicall)2781 if(cfg.http_showpicons ) 2746 2782 { 2747 2783 char picon_name[32]; … … 2753 2789 tpl_addVar(vars, TPLADD, "CCC", cc->remote_build); 2754 2790 tpl_addVar(vars, TPLADD, "CCD", cc->extended_mode ? cc->remote_oscam : ""); 2755 tpl_addVar(vars, TPLADD, "CLIENTPROTO", tpl_getTpl(vars, "PROTOCCCAMPIC")); 2791 if (!apicall) { 2792 tpl_addVar(vars, TPLADD, "CLIENTPROTO", tpl_getTpl(vars, "PROTOCCCAMPIC")); 2793 } else { 2794 tpl_printf(vars, TPLADDONCE, "CLIENTPROTO", "%s (%s-%s)", proto, cc->remote_version, cc->remote_build); 2795 tpl_printf(vars, TPLADDONCE, "PROTOICON", "%s_%s_%s",(char *)proto, cc->remote_version, cc->remote_build); 2796 } 2756 2797 tpl_addVar(vars, TPLADD, "CLIENTPROTOTITLE", cc->extended_mode ? cc->remote_oscam : ""); 2757 2798 } … … 2772 2813 } 2773 2814 #endif 2774 if(cfg.http_showpicons && !apicall)2815 if(cfg.http_showpicons) 2775 2816 { 2776 2817 char picon_name[32]; … … 2779 2820 { 2780 2821 tpl_addVar(vars, TPLADD, "OTHER", (char *)proto); 2781 tpl_addVar(vars, TPLADD, "CLIENTPROTO", tpl_getTpl(vars, "PROTOOTHERPIC")); 2822 if (!apicall) { 2823 tpl_addVar(vars, TPLADD, "CLIENTPROTO", tpl_getTpl(vars, "PROTOOTHERPIC")); 2824 } else { 2825 tpl_addVar(vars, TPLADDONCE, "CLIENTPROTO", (char *)proto); 2826 tpl_printf(vars, TPLADDONCE, "PROTOICON", "%s",(char *)proto); 2827 } 2782 2828 tpl_addVar(vars, TPLADD, "CLIENTPROTOTITLE", ""); 2783 2829 } … … 2881 2927 char *user = getParam(params, "user"); 2882 2928 int32_t found = 0; 2929 unsigned char md5tmp[MD5_DIGEST_LENGTH]; 2883 2930 2884 2931 if(!apicall) … … 3034 3081 tpl_addVar(vars, TPLADD, "CLIENTSRVID", ""); 3035 3082 tpl_addVar(vars, TPLADD, "LASTCHANNEL", ""); 3083 tpl_addVar(vars, TPLADD, "USERMD5", ""); 3036 3084 3037 3085 if(account->expirationdate && account->expirationdate < now) … … 3119 3167 } 3120 3168 3121 if(cfg.http_showpicons && !apicall)3169 if(cfg.http_showpicons ) 3122 3170 { 3123 3171 char picon_name[32]; … … 3134 3182 tpl_addVar(vars, TPLADDONCE, "LCB", lastchan); 3135 3183 tpl_addVar(vars, TPLADDONCE, "LASTCHANNELTITLE", lastchan); 3136 tpl_addVar(vars, TPLADDONCE, "LASTCHANNEL", tpl_getTpl(vars, "USERCONFIGLASTCHANEL")); 3184 if(!apicall) 3185 { 3186 tpl_addVar(vars, TPLADDONCE, "LASTCHANNEL", tpl_getTpl(vars, "USERCONFIGLASTCHANEL")); 3187 } 3188 else 3189 { 3190 tpl_addVar(vars, TPLADDONCE, "LASTCHANNEL", lastchan); 3191 } 3137 3192 } 3138 3193 else … … 3264 3319 3265 3320 tpl_addVar(vars, TPLADD, "CLASSNAME", classname); 3321 MD5((unsigned char *)account->usr, strlen(account->usr), md5tmp); 3322 int z; 3323 for (z = 0; z < MD5_DIGEST_LENGTH; z++){ 3324 tpl_printf(vars, TPLAPPEND, "USERMD5", "%02x", md5tmp[z]); 3325 } 3266 3326 tpl_addVar(vars, TPLADD, "USERNAME", xml_encode(vars, account->usr)); 3267 3327 tpl_addVar(vars, TPLADD, "USERNAMEENC", urlencode(vars, account->usr)); … … 3298 3358 else if(!filter || strcmp(filter, account->usr) == 0 || strcmp(filter, "all") == 0 || strlen(filter) == 0) 3299 3359 { 3300 tpl_addVar(vars, TPLAPPEND, "APIUSERCONFIGS", tpl_getTpl(vars, "APIUSERCONFIGLISTBIT")); 3360 if(apicall == 1){ 3361 tpl_addVar(vars, TPLAPPEND, "APIUSERCONFIGS", tpl_getTpl(vars, "APIUSERCONFIGLISTBIT")); 3362 } else if (apicall == 2){ 3363 tpl_printf(vars, TPLADD, "JSONDELIMITER", "%s", (total_users > 1)?",":""); 3364 tpl_addVar(vars, TPLAPPEND, "APIUSERCONFIGS", tpl_getTpl(vars, "JSONUSERBIT")); 3365 } 3301 3366 ++clientcount; 3302 3367 } … … 3384 3449 if(!filter || clientcount > 0) 3385 3450 { 3386 return tpl_getTpl(vars, "APIUSERCONFIGLIST");3451 return tpl_getTpl(vars, (apicall==1)?"APIUSERCONFIGLIST":"JSONUSER"); 3387 3452 } 3388 3453 else … … 3831 3896 } 3832 3897 3898 static char *send_oscam_logpoll(struct templatevars * vars, struct uriparams * params) 3899 { 3900 if(strcmp(getParam(params, "lasttime"), "start") == 0){ 3901 setActiveMenu(vars, MNU_LIVELOG); 3902 return tpl_getTpl(vars, "LOGPAGE"); 3903 } 3904 3905 int dot = 0; //Delimiter 3906 3907 #ifndef WITH_DEBUG 3908 //cs_log("*** Warning: Debug Support not compiled in ***"); 3909 tpl_printf(vars, TPLAPPEND, "DATA","%s\"nodebug\":\"1\"",dot?",":""); 3910 dot++; 3911 #else 3912 char *debuglvl = getParam(params, "debug"); 3913 if(strlen(debuglvl) > 0) { 3914 int32_t dblvl = atoi(debuglvl); 3915 if(cs_dblevel != dblvl) { 3916 if(dblvl >= 0 && dblvl <= 65535) { cs_dblevel = dblvl; } 3917 cs_log("%s debug_level=%d", "all", cs_dblevel); 3918 } 3919 } 3920 tpl_printf(vars, TPLAPPEND, "DATA","%s\"debug\":\"%d\"", dot?",":"", cs_dblevel); 3921 dot++; 3922 tpl_printf(vars, TPLAPPEND, "DATA","%s\"maxdebug\":\"%d\"",dot?",":"", MAX_DEBUG_LEVELS); 3923 #endif 3924 3925 if(cfg.loghistorysize == 0){ 3926 tpl_printf(vars, TPLAPPEND, "DATA","%s\"logdisabled\":\"1\"",dot?",":""); 3927 return tpl_getTpl(vars, "POLL"); 3928 dot++; 3929 } 3930 3931 char *t_loghistptr = loghistptr, *ptr1 = NULL; 3932 if(loghistptr >= loghist + (cfg.loghistorysize) - 1) 3933 { t_loghistptr = loghist; } 3934 3935 int32_t d = 0, l1 = strlen(t_loghistptr + 1) + 2; 3936 char *lastpos = loghist + (cfg.loghistorysize) - 1; 3937 3938 tpl_printf(vars, TPLAPPEND, "DATA", "%s\"lines\":[", dot?",":""); 3939 3940 int i; 3941 dot=0; 3942 for(ptr1 = t_loghistptr + l1, i = 0; i < 200; i++, ptr1 = ptr1 + l1) 3943 { 3944 l1 = strlen(ptr1) + 1; 3945 if(!d && ((ptr1 >= lastpos) || (l1 < 2))) 3946 { 3947 ptr1 = loghist; 3948 l1 = strlen(ptr1) + 1; 3949 d++; 3950 } 3951 3952 if(d && ((ptr1 >= t_loghistptr) || (l1 < 2))) 3953 { break; } 3954 3955 3956 char p_usr[32]; 3957 size_t pos1 = strcspn(ptr1, "\t") + 1; 3958 cs_strncpy(p_usr, ptr1 , pos1 > sizeof(p_usr) ? sizeof(p_usr) : pos1); 3959 3960 char *p_txt = ptr1 + pos1; 3961 3962 int year; 3963 struct tm lt; 3964 sscanf(p_txt, "%04d/%02d/%02d %02d:%02d:%02d", &year, <.tm_mon, <.tm_mday, <.tm_hour, <.tm_min, <.tm_sec); 3965 lt.tm_year = year - 1900; 3966 time_t logtime = mktime(<); 3967 int lasttime = atoi(getParam(params, "lasttime")); 3968 3969 pos1 = strcspn(p_txt, "\n") + 1; 3970 char str_out[pos1]; 3971 cs_strncpy(str_out, p_txt , pos1); 3972 3973 if(p_txt[0] && (int)logtime > lasttime){ 3974 tpl_printf(vars, TPLAPPEND, "DATA","%s{\"ts\":\"%d\",\"usr\":\"%s\",\"line\":\"%s\"}", 3975 dot?",":"", 3976 (int)logtime, 3977 xml_encode(vars, p_usr), 3978 xml_encode(vars, str_out)); 3979 dot=1; // next in Array with leading delimiter 3980 } 3981 } 3982 tpl_addVar(vars, TPLAPPEND, "DATA", "]"); 3983 return tpl_getTpl(vars, "POLL"); 3984 } 3985 3833 3986 static char *send_oscam_status(struct templatevars * vars, struct uriparams * params, int32_t apicall) 3834 3987 { … … 3838 3991 time_t now = time((time_t *)0); 3839 3992 struct tm lt; 3993 int delimiter=0; 3840 3994 3841 3995 if(!apicall) … … 3998 4152 tpl_addVar(vars, TPLADD, "CLIENTLASTRESPONSETIME", ""); 3999 4153 tpl_addVar(vars, TPLADD, "CLIENTLASTRESPONSETIMEHIST", ""); 4000 tpl_addVar(vars, TPLADD, "JSONARRAYDELIMITER", cl->next ? "," : "");4001 4154 4002 4155 if(cl->typ == 'c') … … 4071 4224 else { cau = 1; } 4072 4225 4073 if( !apicall)4226 if(cau == 0) 4074 4227 { 4075 if(cau == 0) 4228 tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "OFF"); 4229 } 4230 else 4231 { 4232 if(cau == -1) 4233 { tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", !apicall?"<A HREF=\"#\" CLASS=\"tooltip\">ON":""); } 4234 else 4235 { tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", !apicall?"<A HREF=\"#\" CLASS=\"tooltip\">ACTIVE":""); } 4236 tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", !apicall?"<SPAN>":""); 4237 if(cl->typ == 'c') 4076 4238 { 4077 tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "OFF"); 4239 struct s_reader *rdr; 4240 LL_ITER itr = ll_iter_create(cl->aureader_list); 4241 while((rdr = ll_iter_next(&itr))) 4242 { 4243 if(rdr->audisabled) 4244 { tpl_printf(vars, TPLAPPEND, "CLIENTCAUHTTP", "(%s)<BR>", xml_encode(vars, rdr->label)); } 4245 else 4246 { tpl_printf(vars, TPLAPPEND, "CLIENTCAUHTTP", "%s<BR>", xml_encode(vars, rdr->label)); } 4247 } 4078 4248 } 4079 else 4080 { 4081 if(cau == -1) 4082 { tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "<A HREF=\"#\" CLASS=\"tooltip\">ON"); } 4083 else 4084 { tpl_addVar(vars, TPLADD, "CLIENTCAUHTTP", "<A HREF=\"#\" CLASS=\"tooltip\">ACTIVE"); } 4085 tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", "<SPAN>"); 4086 if(cl->typ == 'c') 4087 { 4088 struct s_reader *rdr; 4089 LL_ITER itr = ll_iter_create(cl->aureader_list); 4090 while((rdr = ll_iter_next(&itr))) 4091 { 4092 if(rdr->audisabled) 4093 { tpl_printf(vars, TPLAPPEND, "CLIENTCAUHTTP", "(%s)<BR>", xml_encode(vars, rdr->label)); } 4094 else 4095 { tpl_printf(vars, TPLAPPEND, "CLIENTCAUHTTP", "%s<BR>", xml_encode(vars, rdr->label)); } 4096 } 4097 } 4098 else { tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", xml_encode(vars, cl->reader->label)); } 4099 tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", "</SPAN></A>"); 4100 } 4249 else { tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", xml_encode(vars, cl->reader->label)); } 4250 tpl_addVar(vars, TPLAPPEND, "CLIENTCAUHTTP", !apicall?"</SPAN></A>":""); 4101 4251 } 4102 4252 } … … 4144 4294 tpl_printf(vars, TPLADD, "CSIDX", "%p", cl); 4145 4295 } 4296 tpl_printf(vars, TPLADD, "CSIDXPLAIN", "%p", cl); 4146 4297 } 4147 4298 else … … 4171 4322 } 4172 4323 4173 if(!apicall) 4324 bool picon_shown = false; 4325 const char *status_user_icon_tpl = NULL; 4326 4327 if(cfg.http_showpicons) 4174 4328 { 4175 bool picon_shown = false; 4176 const char *status_user_icon_tpl = NULL; 4177 4178 if(cfg.http_showpicons && !apicall) 4329 if(picon_exists(xml_encode(vars, usr))) 4179 4330 { 4180 if(picon_exists(xml_encode(vars, usr))) 4181 { 4182 switch (cl->typ) { 4183 case 'c': status_user_icon_tpl = "SUSERICON"; picon_shown = true; break; 4184 case 'p': // Fall through 4185 case 'r': status_user_icon_tpl = "SREADERICON"; picon_shown = true; break; 4186 } 4187 } 4188 else 4189 { 4190 tpl_printf(vars, TPLADD, "UPICMISSING", "missing icon: IC_%s.tpl", xml_encode(vars, usr)); 4331 switch (cl->typ) { 4332 case 'c': status_user_icon_tpl = "SUSERICON"; picon_shown = true; break; 4333 case 'p': // Fall through 4334 case 'r': status_user_icon_tpl = "SREADERICON"; picon_shown = true; break; 4191 4335 } 4192 4336 } 4193 4194 if (!picon_shown) { 4195 switch (cl->typ) { 4196 case 'c': status_user_icon_tpl = "SUSER"; break; 4197 case 'p': // Fall through 4198 case 'r': status_user_icon_tpl = "SREADER"; break; 4199 } 4337 else 4338 { 4339 tpl_printf(vars, TPLADD, "UPICMISSING", "missing icon: IC_%s.tpl", xml_encode(vars, usr)); 4340 tpl_addVar(vars, TPLADD, "USERENC", ""); 4200 4341 } 4201 4202 if (status_user_icon_tpl)4203 tpl_addVar(vars, TPLADD, "STATUSUSERICON", tpl_getTpl(vars, status_user_icon_tpl));4204 4342 } 4343 4344 if (!picon_shown) { 4345 switch (cl->typ) { 4346 case 'c': status_user_icon_tpl = "SUSER"; break; 4347 case 'p': // Fall through 4348 case 'r': status_user_icon_tpl = "SREADER"; break; 4349 } 4350 } 4351 4352 if (status_user_icon_tpl) 4353 tpl_addVar(vars, TPLADD, "STATUSUSERICON", tpl_getTpl(vars, status_user_icon_tpl)); 4205 4354 4206 4355 tpl_printf(vars, TPLADD, "CLIENTCAU", "%d", cau); … … 4235 4384 else 4236 4385 { 4386 tpl_printf(vars, TPLADD, "CLIENTLOGINDATEFMT", "%02d.%02d.%02d %02d:%02d:%02d", lt.tm_mday, lt.tm_mon + 1, lt.tm_year % 100, lt.tm_hour, lt.tm_min, lt.tm_sec); 4237 4387 char tbuffer [30]; 4238 4388 strftime(tbuffer, 30, "%Y-%m-%dT%H:%M:%S%z", <); … … 4253 4403 { 4254 4404 tpl_addVar(vars, TPLADD, "LASTREADER", cl->lastreader); 4405 tpl_printf(vars, TPLADD, "MSVALUE", "%d", cl->cwlastresptime); 4255 4406 } 4256 4407 else … … 4276 4427 tpl_addVar(vars, TPLADD, "CLIENTSRVDESCRIPTION", cl->last_srvidptr && cl->last_srvidptr->desc ? xml_encode(vars, cl->last_srvidptr->desc) : ""); 4277 4428 tpl_addVar(vars, TPLADD, "CLIENTTIMEONCHANNEL", sec2timeformat(vars, chsec)); 4278 if(cfg.http_showpicons && !apicall)4429 if(cfg.http_showpicons) 4279 4430 { 4280 4431 snprintf(picon_name, sizeof(picon_name) / sizeof(char) - 1, "%04X_%04X", cl->last_caid, cl->last_srvid); … … 4294 4445 { 4295 4446 tpl_addVar(vars, TPLADDONCE, "CURRENTPICON", tpl_getTpl(vars, "CLIENTCURRENTCHANNEL")); 4447 tpl_addVar(vars, TPLADD, "PICONNAME", ""); 4296 4448 } 4297 4449 } … … 4299 4451 { 4300 4452 tpl_addVar(vars, TPLADDONCE, "CURRENTPICON", tpl_getTpl(vars, "CLIENTCURRENTCHANNELBIT")); 4453 tpl_addVar(vars, TPLADD, "PICONNAME", "0000_0000"); 4301 4454 } 4302 4455 } … … 4543 4696 { 4544 4697 if(apicall == 1) 4545 4698 { tpl_addVar(vars, TPLAPPEND, "APISTATUSBITS", tpl_getTpl(vars, "APISTATUSBIT")); } 4546 4699 if(apicall == 2) 4547 { tpl_addVar(vars, TPLAPPEND, "JSONSTATUSBITS", tpl_getTpl(vars, "JSONSTATUSBIT")); } 4700 { 4701 tpl_addVar(vars, TPLADD, "JSONARRAYDELIMITER", delimiter?",":""); 4702 tpl_addVar(vars, TPLAPPEND, "JSONSTATUSBITS", tpl_getTpl(vars, "JSONSTATUSBIT")); 4703 delimiter++; 4704 } 4548 4705 } 4549 4706 } … … 4557 4714 cs_readunlock(&readerlist_lock); 4558 4715 4559 if(cfg.loghistorysize )4716 if(cfg.loghistorysize && 0 == 1) 4560 4717 { 4561 4718 char *t_loghistptr = loghistptr, *ptr1 = NULL; … … 4742 4899 { 4743 4900 if(apicall == 1) 4744 4901 { return tpl_getTpl(vars, "APISTATUS"); } 4745 4902 if(apicall == 2) 4746 { return tpl_getTpl(vars, "JSONSTATUS"); } 4903 { 4904 tpl_printf(vars, TPLADD, "UCS", "%d", user_count_shown); 4905 tpl_printf(vars, TPLADD, "UCA", "%d", user_count_all); 4906 tpl_printf(vars, TPLADD, "UCAC", "%d", user_count_active); 4907 tpl_printf(vars, TPLADD, "CFGH", "%d", cfg.hideclient_to); 4908 tpl_printf(vars, TPLADD, "PICONENABLED", "%d", cfg.http_showpicons?1:0); 4909 return tpl_getTpl(vars, "JSONSTATUS"); 4910 } 4747 4911 } 4748 4912 … … 6626 6790 "/robots.txt", 6627 6791 "/ghttp.html", 6792 "/logpoll.html", 6793 "/jquery.js", 6628 6794 }; 6629 6795 … … 6810 6976 send_file(f, "JS", subdir, modifiedheader, etagheader, extraheader); 6811 6977 } 6978 else if(pgidx == 30) 6979 { 6980 send_file(f, "JQ", subdir, modifiedheader, etagheader, extraheader); 6981 } 6812 6982 else 6813 6983 { … … 6865 7035 if(strcmp(getParam(¶ms, "callback"), "")) 6866 7036 { 6867 tpl_addVar(vars, TPLADD, "CALLBACK", getParam(¶ms, "callback")); 7037 tpl_printf(vars, TPLADD, "CALLBACK", "%s%s", getParam(¶ms, "callback"), "("); 7038 tpl_addVar(vars, TPLADD, "ENDBRACKET", ")"); 6868 7039 } 6869 7040 … … 6972 7143 result = send_oscam_ghttp(vars, ¶ms, 0); 6973 7144 break; 6974 #endif 7145 7146 #endif 7147 case 29: 7148 result = send_oscam_logpoll(vars, ¶ms); 7149 break; 7150 6975 7151 default: 6976 7152 result = send_oscam_status(vars, ¶ms, 0);
Note:
See TracChangeset
for help on using the changeset viewer.