-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodule-webif.c
7911 lines (7084 loc) · 237 KB
/
module-webif.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "globals.h"
#ifdef WEBIF
//
// OSCam HTTP server module
//
#include <locale.h>
#include "cscrypt/md5.h"
#include "module-anticasc.h"
#include "module-cacheex.h"
#include "module-cccam.h"
#include "module-cccam-data.h"
#include "module-dvbapi.h"
#include "module-newcamd.h"
#include "module-stat.h"
#include "module-webif.h"
#include "module-webif-lib.h"
#include "module-webif-tpl.h"
#include "oscam-conf-mk.h"
#include "oscam-config.h"
#include "oscam-files.h"
#include "oscam-garbage.h"
#include "oscam-cache.h"
#include "oscam-client.h"
#include "oscam-lock.h"
#include "oscam-net.h"
#include "oscam-reader.h"
#include "oscam-string.h"
#include "oscam-time.h"
#include "oscam-work.h"
extern struct s_cardreader cardreaders[CS_MAX_MOD];
extern char cs_confdir[];
extern uint32_t ecmcwcache_size;
extern uint8_t cs_http_use_utf8;
extern uint32_t cfg_sidtab_generation;
extern int32_t exit_oscam;
extern char *entitlement_type[];
extern char *RDR_CD_TXT[];
extern char *loghist;
extern char *loghistid;
extern char *loghistptr;
int32_t ssl_active = 0;
char noncekey[33];
pthread_key_t getkeepalive;
static pthread_key_t getip;
pthread_key_t getssl;
static CS_MUTEX_LOCK http_lock;
CS_MUTEX_LOCK *lock_cs;
static uint8_t useLocalD = 1;
#define PRINTF_LOCAL_D useLocalD ? "%'d" : "%d"
static pthread_t httpthread;
static int32_t sock;
enum refreshtypes { REFR_ACCOUNTS, REFR_READERS, REFR_CLIENTS, REFR_SERVER, REFR_ANTICASC, REFR_SERVICES };
//initialize structs for calculating cpu-usage depending on time between refresh of status_page
static struct pstat p_stat_cur;
static struct pstat p_stat_old;
/* constants for menuactivating */
#define MNU_STATUS 0
#define MNU_CONFIG 1
#define MNU_READERS 2
#define MNU_USERS 3
#define MNU_SERVICES 4
#define MNU_FILES 5
#define MNU_FAILBAN 6
#define MNU_CACHEEX 7
#define MNU_SCRIPT 8
#define MNU_SHUTDOWN 9
#define MNU_LIVELOG 10
#define MNU_TOTAL_ITEMS 11 // sum of items above
/* constants for submenuactivating */
#define MNU_CFG_GLOBAL 0
#define MNU_CFG_LOADBAL 1
#define MNU_CFG_CAMD33 2
#define MNU_CFG_CAMD35 3
#define MNU_CFG_CAMD35TCP 4
#define MNU_CFG_NEWCAMD 5
#define MNU_CFG_RADEGAST 6
#define MNU_CFG_CCCAM 7
#define MNU_CFG_ANTICASC 8
#define MNU_CFG_MONITOR 9
#define MNU_CFG_SERIAL 10
#define MNU_CFG_DVBAPI 11
#define MNU_CFG_WEBIF 12
#define MNU_CFG_LCD 13
#define MNU_CFG_GBOX 14
#define MNU_CFG_SCAM 15
#define MNU_CFG_FVERSION 12
#define MNU_CFG_FCONF 13
#define MNU_CFG_FUSER 14
#define MNU_CFG_FSERVER 15
#define MNU_CFG_FSERVICES 16
#define MNU_CFG_FSRVID 17
#define MNU_CFG_FPROVID 18
#define MNU_CFG_FTIERS 19
#define MNU_CFG_FLOGFILE 20
#define MNU_CFG_FUSERFILE 21
#define MNU_CFG_FACLOG 22
#define MNU_CFG_FDVBAPI 23
#define MNU_CFG_CACHE 24
#define MNU_CFG_WHITELIST 25
#define MNU_CFG_RATELIMIT 26
#define MNU_CFG_FCSS 27
#define MNU_CFG_TOTAL_ITEMS 28 // sum of items above. Use it for "All inactive" in function calls too.
static void set_status_info_var(struct templatevars *vars, char *varname, int no_data, char *fmt, double value) {
if (no_data)
tpl_addVar(vars, TPLADD, varname, "N/A");
else
tpl_printf(vars, TPLADD, varname, fmt, value);
}
/*
* Creates vars Memory/CPU/OSCAM info in for status_page
* if check_available == 0 N/A will be displayed
*/
static void set_status_info(struct templatevars *vars, struct pstat stats){
set_status_info_var(vars, "MEM_CUR_TOTAL", stats.check_available & (1 << 0), "%'.2f MB" , (double)stats.mem_total/(1024.0*1024.0));
set_status_info_var(vars, "MEM_CUR_FREE", stats.check_available & (1 << 1), "%'.2f MB" , (double)stats.mem_free/(1024.0*1024.0));
set_status_info_var(vars, "MEM_CUR_USED", stats.check_available & (1 << 2), "%'.2f MB" , (double)stats.mem_used/(1024.0*1024.0));
set_status_info_var(vars, "MEM_CUR_BUFF", stats.check_available & (1 << 3), "%'.2f MB" , (double)stats.mem_buff/(1024.0*1024.0));
set_status_info_var(vars, "CPU_LOAD_0", stats.check_available & (1 << 3), "%.2f" , stats.cpu_avg[0]);
set_status_info_var(vars, "CPU_LOAD_1", stats.check_available & (1 << 4), "%.2f" , stats.cpu_avg[1]);
set_status_info_var(vars, "CPU_LOAD_2", stats.check_available & (1 << 5), "%.2f" , stats.cpu_avg[2]);
set_status_info_var(vars, "OSCAM_VMSIZE", stats.check_available & (1 << 6), "%'.2f MB" , (double)stats.vsize/(1024.0*1024.0));
set_status_info_var(vars, "OSCAM_RSSSIZE", stats.check_available & (1 << 7), "%'.2f MB" , (double)stats.rss/(1024.0*1024.0));
set_status_info_var(vars, "OSCAM_CPU_USER", stats.check_available & (1 << 8), "%.2f %%" , stats.cpu_usage_user);
set_status_info_var(vars, "OSCAM_CPU_SYS", stats.check_available & (1 << 9), "%.2f %%" , stats.cpu_usage_sys);
double sum_cpu = stats.cpu_usage_sys + stats.cpu_usage_user;
set_status_info_var(vars, "OSCAM_CPU_SUM", stats.check_available & (1 << 10), "%.2f %%" , sum_cpu);
if (stats.check_available & (1 << 11)) {
tpl_addVar(vars, TPLADD, "OSCAM_REFRESH" , "N/A");
} else {
tpl_printf(vars, TPLADD, "OSCAM_REFRESH" , "%02"PRId64":%02"PRId64":%02"PRId64"h",
stats.gone_refresh / 3600,
(stats.gone_refresh / 60) % 60,
stats.gone_refresh % 60);
}
}
static void clear_account_stats(struct s_auth *account)
{
account->cwfound = 0;
account->cwcache = 0;
account->cwnot = 0;
account->cwtun = 0;
account->cwignored = 0;
account->cwtout = 0;
account->emmok = 0;
account->emmnok = 0;
#ifdef CW_CYCLE_CHECK
account->cwcycledchecked = 0;
account->cwcycledok = 0;
account->cwcyclednok = 0;
account->cwcycledign = 0;
#endif
cacheex_clear_account_stats(account);
}
static void clear_all_account_stats(void)
{
struct s_auth *account = cfg.account;
while(account)
{
clear_account_stats(account);
account = account->next;
}
}
#ifdef CS_CACHEEX
static void cacheex_clear_all_stats(void)
{
struct s_auth *account = cfg.account;
while(account)
{
cacheex_clear_account_stats(account);
account = account->next;
}
struct s_client *cl;
for(cl = first_client->next; cl ; cl = cl->next)
{
cacheex_clear_client_stats(cl);
ll_clear_data(cl->ll_cacheex_stats);
}
cacheex_clear_client_stats(first_client);
}
#endif
static void clear_system_stats(void)
{
first_client->cwfound = 0;
first_client->cwcache = 0;
first_client->cwnot = 0;
first_client->cwtun = 0;
first_client->cwignored = 0;
first_client->cwtout = 0;
first_client->emmok = 0;
first_client->emmnok = 0;
cacheex_clear_client_stats(first_client);
}
static void set_ecm_info(struct templatevars * vars)
{
//if one of the stats overloaded, reset all stats!
if(first_client->cwfound<0
|| first_client->cwnot<0
|| first_client->cwignored<0
|| first_client->cwtout<0
|| first_client->cwcache<0
|| first_client->cwtun<0
|| first_client->emmok<0
|| first_client->emmnok<0
#ifdef CS_CACHEEX
|| first_client->cwcacheexgot<0
|| first_client->cwcacheexpush<0
|| first_client->cwcacheexhit<0
#endif
){
clear_system_stats();
}
//end reset stats
int ecm = 0, emm = 0;
double ecmsum = first_client->cwfound + first_client->cwcache + first_client->cwnot + first_client->cwtout; //dont count TUN its included
if(ecmsum < 1) {ecmsum = 1; ecm = 1;}
double ecmpos = first_client->cwfound + first_client->cwcache; // dont count TUN its included
if(ecmpos < 1) {ecmpos = 1;}
double ecmneg = first_client->cwnot + first_client->cwtout; //dont count IGN its not part of neagtiv
if(ecmneg < 1) {ecmneg = 1;}
double emmsum = first_client->emmok + first_client->emmnok;
if(emmsum < 1) {emmsum = 1; emm = 1;}
tpl_printf(vars, TPLADD, "TOTAL_ECM_MIN", "%d", first_client->n_request[0]);
tpl_printf(vars, TPLADD, "TOTAL_CW", PRINTF_LOCAL_D, !ecm ? (int)ecmsum : 0);
tpl_printf(vars, TPLADD, "TOTAL_CWOK", PRINTF_LOCAL_D, first_client->cwfound);
tpl_printf(vars, TPLADD, "TOTAL_CWNOK", PRINTF_LOCAL_D, first_client->cwnot);
tpl_printf(vars, TPLADD, "TOTAL_CWIGN", PRINTF_LOCAL_D, first_client->cwignored);
tpl_printf(vars, TPLADD, "TOTAL_CWTOUT", PRINTF_LOCAL_D, first_client->cwtout);
tpl_printf(vars, TPLADD, "TOTAL_CWCACHE", PRINTF_LOCAL_D, first_client->cwcache);
tpl_printf(vars, TPLADD, "TOTAL_CWTUN", PRINTF_LOCAL_D, first_client->cwtun);
tpl_printf(vars, TPLADD, "TOTAL_CWPOS", PRINTF_LOCAL_D, first_client->cwfound + first_client->cwcache);
tpl_printf(vars, TPLADD, "TOTAL_CWNEG", PRINTF_LOCAL_D, first_client->cwnot + first_client->cwtout);
tpl_printf(vars, TPLADD, "TOTAL_EM", PRINTF_LOCAL_D, !emm ? (int)emmsum : 0);
tpl_printf(vars, TPLADD, "TOTAL_EMOK", PRINTF_LOCAL_D, first_client->emmok);
tpl_printf(vars, TPLADD, "TOTAL_EMNOK", PRINTF_LOCAL_D, first_client->emmnok);
tpl_printf(vars, TPLADD, "REL_CWOK", "%.2f", (double)first_client->cwfound * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_CWNOK", "%.2f", (double)first_client->cwnot * 100 / ecmsum);
//tpl_printf(vars, TPLADD, "REL_CWIGN", "%.2f", (double)first_client->cwignored * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_CWTOUT", "%.2f", (double)first_client->cwtout * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_CWCACHE", "%.2f", (double)first_client->cwcache * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_CWTUN", "%.2f", (double)first_client->cwtun * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_CWPOS", "%.2f", (double)(first_client->cwfound + first_client->cwcache) * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_CWNEG", "%.2f", (double)(first_client->cwnot + first_client->cwtout) * 100 / ecmsum);
tpl_printf(vars, TPLADD, "REL_EMOK", "%.2f", (double)first_client->emmok * 100 / emmsum);
tpl_printf(vars, TPLADD, "REL_EMNOK", "%.2f", (double)first_client->emmnok * 100 / emmsum);
tpl_printf(vars, TPLADD, "REL_CWPOSOK", "%.2f", (double)first_client->cwfound * 100 / ecmpos);
tpl_printf(vars, TPLADD, "REL_CWPOSCACHE", "%.2f", (double)first_client->cwcache * 100 / ecmpos);
tpl_printf(vars, TPLADD, "REL_CWNEGNOK", "%.2f", (double)first_client->cwnot * 100 / ecmneg);
//tpl_printf(vars, TPLADD, "REL_CWNEGIGN", "%.2f", (double)first_client->cwignored * 100 / ecmneg);
tpl_printf(vars, TPLADD, "REL_CWNEGTOUT", "%.2f", (double)first_client->cwtout * 100 / ecmneg);
}
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_log("Refresh Readers requested by WebIF from %s", cs_inet_ntoa(GET_IP()));
reload_readerdb();
break;
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:
cs_log("Refresh Server requested by WebIF from %s", cs_inet_ntoa(GET_IP()));
//kill(first_client->pid, SIGHUP);
//todo how I can refresh the server after global settings
break;
case REFR_SERVICES:
cs_log("Refresh Services requested by WebIF from %s", cs_inet_ntoa(GET_IP()));
//init_sidtab();
cs_accounts_chk();
break;
#ifdef CS_ANTICASC
case REFR_ANTICASC:
cs_log("Refresh Anticascading requested by WebIF from %s", cs_inet_ntoa(GET_IP()));
ac_init_stat();
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;
}
}
break;
#endif
default:
break;
}
}
/*
* load historical values from ringbuffer and return it in the right order
* as string. Value should be freed with free_mk_t()
*/
static char *get_ecm_historystring(struct s_client *cl)
{
if(cl)
{
int32_t k, i, pos = 0, needed = 1, v;
char *value, *dot = "";
int32_t ptr = cl->cwlastresptimes_last;
needed = CS_ECM_RINGBUFFER_MAX * 6; //5 digits + delimiter
if(!cs_malloc(&value, needed)) { return ""; }
k = ptr + 1;
for(i = 0; i < CS_ECM_RINGBUFFER_MAX; i++)
{
if(k >= CS_ECM_RINGBUFFER_MAX)
{ k = 0; }
v = cl->cwlastresptimes[k].duration;
if(v > 0 && v < (int32_t)cfg.ctimeout * 5)
{
pos += snprintf(value + pos, needed - pos, "%s%d", dot, v);
dot = ",";
}
k++;
}
if(strlen(value) == 0)
{
NULLFREE(value);
return "";
}
else { return value; }
}
else
{
return "";
}
}
static char *get_ecm_fullhistorystring(struct s_client *cl)
{
if(cl)
{
int32_t k, i, pos = 0, needed = 1, v;
char *value, *dot = "";
int32_t ptr = cl->cwlastresptimes_last;
needed = CS_ECM_RINGBUFFER_MAX * 20; //5 digits + : + returncode(2) + : + time(10) + delimiter
if(!cs_malloc(&value, needed)) { return ""; }
k = ptr + 1;
for(i = 0; i < CS_ECM_RINGBUFFER_MAX; i++)
{
if(k >= CS_ECM_RINGBUFFER_MAX)
{ k = 0; }
v = cl->cwlastresptimes[k].duration;
if(v > 0 && v < (int32_t)cfg.ctimeout * 5)
{
pos += snprintf(value + pos, needed - pos, "%s%d:%d:%ld", dot, cl->cwlastresptimes[k].duration, cl->cwlastresptimes[k].rc, cl->cwlastresptimes[k].timestamp);
dot = ",";
}
k++;
}
return (value);
}
else
{
return "";
}
}
/*
* Set the active menu to a different CSS class
*/
static void setActiveMenu(struct templatevars *vars, int8_t active)
{
int8_t i;
for(i = 0; i < MNU_TOTAL_ITEMS; i++)
{
tpl_printf(vars, TPLADD, "TMP", "MENUACTIVE%d", i);
if(i == active)
{ tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "menu_selected"); }
else
{ tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "menu"); }
}
#ifdef WEBIF_LIVELOG
tpl_addVar(vars, TPLADD, "LOGPAGEMENU", tpl_getTpl(vars, "LOGMENU"));
#endif
}
/*
* Set the active submenu to a different CSS class
*/
static void setActiveSubMenu(struct templatevars *vars, int8_t active)
{
int8_t i;
for(i = 0; i < MNU_CFG_TOTAL_ITEMS; i++)
{
tpl_printf(vars, TPLADD, "TMP", "CMENUACTIVE%d", i);
if(i == active)
{ tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "configmenu_selected"); }
else
{ tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "configmenu"); }
}
}
static void webif_save_config(char *section, struct templatevars *vars, struct uriparams *params)
{
if(!streq(getParam(params, "action"), "execute"))
{ return; }
if(cfg.http_readonly)
{
tpl_addMsg(vars, "WebIf is in readonly mode. No changes are possible!");
return;
}
int i;
int cnt = (*params).paramcount;
for(i = 0; i < cnt; i++)
{
char *token = (*params).params[i];
char *value = (*params).values[i];
if(!streq(token, "part") && !streq(token, "action"))
{ config_set(section, token, value); }
}
if(write_config() == 0)
{
tpl_addMsg(vars, "Configuration was saved.");
enum refreshtypes ref_type = REFR_SERVER;
if(streq(getParam(params, "part"), "anticasc"))
{ ref_type = REFR_ANTICASC; }
refresh_oscam(ref_type);
}
else
{
tpl_addMsg(vars, "ERROR: Failed to write config file!!!");
}
}
static char *send_oscam_config_global(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_GLOBAL);
webif_save_config("global", vars, params);
if(IP_ISSET(cfg.srvip))
{ tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.srvip)); }
tpl_printf(vars, TPLADD, "NICE", "%d", cfg.nice);
tpl_printf(vars, TPLADD, "BINDWAIT", "%d", cfg.bindwait);
tpl_printf(vars, TPLADD, "NETPRIO", "%d", cfg.netprio);
tpl_printf(vars, TPLADD, "PIDFILE", "%s", ESTR(cfg.pidfile));
if(cfg.usrfile != NULL) { tpl_addVar(vars, TPLADD, "USERFILE", cfg.usrfile); }
if(cfg.disableuserfile == 0) { tpl_addVar(vars, TPLADD, "DISABLEUSERFILECHECKED", "checked"); }
if(cfg.usrfileflag == 1) { tpl_addVar(vars, TPLADD, "USERFILEFLAGCHECKED", "selected"); }
if(cfg.mailfile != NULL) { tpl_addVar(vars, TPLADD, "MAILFILE", cfg.mailfile); }
if(cfg.disablemail == 0) { tpl_addVar(vars, TPLADD, "DISABLEMAILCHECKED", "checked"); }
char *value = mk_t_logfile();
tpl_addVar(vars, TPLADD, "LOGFILE", value);
free_mk_t(value);
if(cfg.disablelog == 0) { tpl_addVar(vars, TPLADD, "DISABLELOGCHECKED", "checked"); }
tpl_printf(vars, TPLADD, "MAXLOGSIZE", "%d", cfg.max_log_size);
tpl_addVar(vars, TPLADD, "LOGDUPSCHECKED", (cfg.logduplicatelines == 1) ? "checked" : "");
if(cfg.cwlogdir != NULL) { tpl_addVar(vars, TPLADD, "CWLOGDIR", cfg.cwlogdir); }
if(cfg.emmlogdir != NULL) { tpl_addVar(vars, TPLADD, "EMMLOGDIR", cfg.emmlogdir); }
tpl_addVar(vars, TPLADD, "ECMFMT", cfg.ecmfmt);
tpl_printf(vars, TPLADD, "LOGHISTORYSIZE", "%u", cfg.loghistorysize);
tpl_printf(vars, TPLADD, "CLIENTTIMEOUT", "%u", cfg.ctimeout);
tpl_printf(vars, TPLADD, "FALLBACKTIMEOUT", "%u", cfg.ftimeout);
tpl_printf(vars, TPLADD, "CLIENTMAXIDLE", "%u", cfg.cmaxidle);
value = mk_t_caidvaluetab(&cfg.ftimeouttab);
tpl_addVar(vars, TPLADD, "FALLBACKTIMEOUT_PERCAID", value);
free_mk_t(value);
tpl_printf(vars, TPLADD, "SLEEP", "%d", cfg.tosleep);
tpl_addVar(vars, TPLADD, "UNLOCKPARENTALCHECKED", (cfg.ulparent == 1) ? "checked" : "");
if(cfg.block_same_ip) { tpl_addVar(vars, TPLADD, "BLOCKSAMEIPCHECKED", "checked"); }
if(cfg.block_same_name) { tpl_addVar(vars, TPLADD, "BLOCKSAMENAMECHECKED", "checked"); }
if(cfg.waitforcards == 1) { tpl_addVar(vars, TPLADD, "WAITFORCARDSCHECKED", "checked"); }
tpl_printf(vars, TPLADD, "EXTRADELAY", "%d", cfg.waitforcards_extra_delay);
if(cfg.preferlocalcards == 1)
{
tpl_addVar(vars, TPLADD, "PREFERCACHEEX", "selected");
}
else if(cfg.preferlocalcards == 2)
{
tpl_addVar(vars, TPLADD, "PREFERLOCALCARDS", "selected");
}
if(cfg.c35_suppresscmd08)
{ tpl_addVar(vars, TPLADD, "SUPPRESSCMD08", "checked"); }
if(cfg.reader_restart_seconds)
{ tpl_printf(vars, TPLADD, "READERRESTARTSECONDS", "%d", cfg.reader_restart_seconds); }
tpl_addVar(vars, TPLADD, "DROPDUPSCHECKED", (cfg.dropdups == 1) ? "checked" : "");
if(cfg.resolve_gethostbyname == 1)
{ tpl_addVar(vars, TPLADD, "RESOLVER1", "selected"); }
else
{ tpl_addVar(vars, TPLADD, "RESOLVER0", "selected"); }
tpl_printf(vars, TPLADD, "FAILBANTIME", "%d", cfg.failbantime);
tpl_printf(vars, TPLADD, "FAILBANCOUNT", "%d", cfg.failbancount);
tpl_addVar(vars, TPLADD, "DCHECKCSELECTED", (cfg.double_check == 1) ? "checked" : "");
value = mk_t_caidtab(&cfg.double_check_caid);
tpl_addVar(vars, TPLADD, "DOUBLECHECKCAID", value);
free_mk_t(value);
#ifdef LEDSUPPORT
if(cfg.enableled == 1)
{ tpl_addVar(vars, TPLADD, "ENABLELEDSELECTED1", "selected"); }
else if(cfg.enableled == 2)
{ tpl_addVar(vars, TPLADD, "ENABLELEDSELECTED2", "selected"); }
#endif
return tpl_getTpl(vars, "CONFIGGLOBAL");
}
#ifdef WITH_LB
static char *send_oscam_config_loadbalancer(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_LOADBAL);
if(strlen(getParam(params, "button")) > 0)
{
if(cfg.http_readonly)
{
tpl_addMsg(vars, "WebIf is in readonly mode. No changes are possible!");
}
else
{
if(strcmp(getParam(params, "button"), "Load Stats") == 0)
{
clear_all_stat();
load_stat_from_file();
tpl_addMsg(vars, "Stats loaded from file");
}
if(strcmp(getParam(params, "button"), "Save Stats") == 0)
{
save_stat_to_file(1);
tpl_addMsg(vars, "Stats saved to file");
}
if(strcmp(getParam(params, "button"), "Clear Stats") == 0)
{
clear_all_stat();
tpl_addMsg(vars, "Stats cleared completly");
}
if(strcmp(getParam(params, "button"), "Clear Timeouts") == 0)
{
clean_all_stats_by_rc(E_TIMEOUT, 0);
tpl_addMsg(vars, "Timeout cleared from Stats");
}
if(strcmp(getParam(params, "button"), "Clear Not Founds") == 0)
{
clean_all_stats_by_rc(E_NOTFOUND, 0);
tpl_addMsg(vars, "Not Found cleared from Stats");
}
if(strcmp(getParam(params, "button"), "Clear Invalid") == 0)
{
clean_all_stats_by_rc(E_INVALID, 0);
tpl_addMsg(vars, "Invalid cleared from Stats");
}
}
}
webif_save_config("global", vars, params);
tpl_printf(vars, TPLADD, "TMP", "LBMODE%d", cfg.lb_mode);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
tpl_printf(vars, TPLADD, "LBSAVE", "%d", cfg.lb_save);
if(cfg.lb_savepath) { tpl_addVar(vars, TPLADD, "LBSAVEPATH", cfg.lb_savepath); }
tpl_printf(vars, TPLADD, "LBNBESTREADERS", "%d", cfg.lb_nbest_readers);
char *value = mk_t_caidvaluetab(&cfg.lb_nbest_readers_tab);
tpl_addVar(vars, TPLADD, "LBNBESTPERCAID", value);
free_mk_t(value);
tpl_printf(vars, TPLADD, "LBNFBREADERS", "%d", cfg.lb_nfb_readers);
tpl_printf(vars, TPLADD, "LBMAXREADERS", "%d", cfg.lb_max_readers);
tpl_printf(vars, TPLADD, "LBMINECMCOUNT", "%d", cfg.lb_min_ecmcount);
tpl_printf(vars, TPLADD, "LBMAXECEMCOUNT", "%d", cfg.lb_max_ecmcount);
tpl_printf(vars, TPLADD, "LBRETRYLIMIT", "%d", cfg.lb_retrylimit);
value = mk_t_caidvaluetab(&cfg.lb_retrylimittab);
tpl_addVar(vars, TPLADD, "LBRETRYLIMITS", value);
free_mk_t(value);
tpl_printf(vars, TPLADD, "LBREOPENSECONDS", "%d", cfg.lb_reopen_seconds);
tpl_printf(vars, TPLADD, "LBCLEANUP", "%d", cfg.lb_stat_cleanup);
tpl_addVar(vars, TPLADD, "LBREOPENINVALID", (cfg.lb_reopen_invalid == 1) ? "checked" : "");
tpl_addVar(vars, TPLADD, "LBFORCEALWAYS", (cfg.lb_force_reopen_always == 1) ? "checked" : "");
value = mk_t_caidtab(&cfg.lb_noproviderforcaid);
tpl_addVar(vars, TPLADD, "LBNOPROVIDERFORCAID", value);
free_mk_t(value);
tpl_addVar(vars, TPLADD, "LBAUTOBETATUNNEL", (cfg.lb_auto_betatunnel == 1) ? "checked" : "");
if(cfg.lb_auto_betatunnel_mode)
{
tpl_printf(vars, TPLADD, "TMP", "LBAUTOBETATUNNELMODE%d", cfg.lb_auto_betatunnel_mode);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
}
tpl_printf(vars, TPLADD, "LBPREFERBETA", "%d", cfg.lb_auto_betatunnel_prefer_beta);
tpl_addVar(vars, TPLADD, "LBAUTOTIMEOUT", (cfg.lb_auto_timeout == 1) ? "checked" : "");
tpl_printf(vars, TPLADD, "LBAUTOTIMEOUTP", "%d", cfg.lb_auto_timeout_p);
tpl_printf(vars, TPLADD, "LBAUTOTIMEOUTT", "%d", cfg.lb_auto_timeout_t);
tpl_addVar(vars, TPLADDONCE, "CONFIG_CONTROL", tpl_getTpl(vars, "CONFIGLOADBALANCERCTRL"));
return tpl_getTpl(vars, "CONFIGLOADBALANCER");
}
#endif
#ifdef MODULE_CAMD33
static char *send_oscam_config_camd33(struct templatevars *vars, struct uriparams *params)
{
int32_t i;
setActiveSubMenu(vars, MNU_CFG_CAMD33);
webif_save_config("camd33", vars, params);
if(cfg.c33_port)
{
tpl_printf(vars, TPLADD, "PORT", "%d", cfg.c33_port);
if(IP_ISSET(cfg.c33_srvip)) { tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.c33_srvip)); }
tpl_addVar(vars, TPLADD, "PASSIVECHECKED", (cfg.c33_passive == 1) ? "checked" : "");
for(i = 0; i < (int) sizeof(cfg.c33_key); ++i) { tpl_printf(vars, TPLAPPEND, "KEY", "%02X", cfg.c33_key[i]); }
char *value = mk_t_iprange(cfg.c33_plain);
tpl_addVar(vars, TPLADD, "NOCRYPT", value);
free_mk_t(value);
}
return tpl_getTpl(vars, "CONFIGCAMD33");
}
#endif
#ifdef MODULE_CAMD35
static char *send_oscam_config_camd35(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_CAMD35);
webif_save_config("cs357x", vars, params);
if(cfg.c35_port)
{
tpl_printf(vars, TPLADD, "PORT", "%d", cfg.c35_port);
if(IP_ISSET(cfg.c35_srvip))
{ tpl_addVar(vars, TPLAPPEND, "SERVERIP", cs_inet_ntoa(cfg.c35_srvip)); }
if(cfg.c35_udp_suppresscmd08)
{ tpl_addVar(vars, TPLADD, "SUPPRESSCMD08UDP", "checked"); }
}
return tpl_getTpl(vars, "CONFIGCAMD35");
}
#endif
#ifdef MODULE_CAMD35_TCP
static char *send_oscam_config_camd35tcp(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_CAMD35TCP);
webif_save_config("cs378x", vars, params);
if((cfg.c35_tcp_ptab.nports > 0) && (cfg.c35_tcp_ptab.ports[0].s_port > 0))
{
char *value = mk_t_camd35tcp_port();
tpl_addVar(vars, TPLADD, "PORT", value);
free_mk_t(value);
if(IP_ISSET(cfg.c35_tcp_srvip))
{ tpl_addVar(vars, TPLAPPEND, "SERVERIP", cs_inet_ntoa(cfg.c35_tcp_srvip)); }
if(cfg.c35_tcp_suppresscmd08)
{ tpl_addVar(vars, TPLADD, "SUPPRESSCMD08TCP", "checked"); }
}
return tpl_getTpl(vars, "CONFIGCAMD35TCP");
}
#endif
static char *send_oscam_config_cache(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_CACHE);
webif_save_config("cache", vars, params);
tpl_printf(vars, TPLADD, "CACHEDELAY", "%u", cfg.delay);
tpl_printf(vars, TPLADD, "MAXCACHETIME", "%d", cfg.max_cache_time);
#ifdef CS_CACHEEX
char *value = NULL;
value = mk_t_cacheex_valuetab(&cfg.cacheex_wait_timetab);
tpl_addVar(vars, TPLADD, "WAIT_TIME", value);
free_mk_t(value);
tpl_printf(vars, TPLADD, "MAX_HIT_TIME", "%d", cfg.max_hitcache_time);
tpl_addVar(vars, TPLADD, "CACHEEXSTATSSELECTED", (cfg.cacheex_enable_stats == 1) ? "checked" : "");
tpl_addVar(vars, TPLADD, "WTTCHECKED", (cfg.wait_until_ctimeout == 1) ? "checked" : "");
if(cfg.csp_port)
{ tpl_printf(vars, TPLADD, "PORT", "%d", cfg.csp_port); }
if(IP_ISSET(cfg.csp_srvip))
{ tpl_addVar(vars, TPLAPPEND, "SERVERIP", cs_inet_ntoa(cfg.csp_srvip)); }
value = mk_t_cacheex_hitvaluetab(&cfg.csp.filter_caidtab);
tpl_addVar(vars, TPLADD, "CSP_ECM_FILTER", value);
free_mk_t(value);
value = mk_t_cacheex_cwcheck_valuetab(&cfg.cacheex_cwcheck_tab);
tpl_addVar(vars, TPLADD, "CACHEEXCWCHECK", value);
free_mk_t(value);
tpl_addVar(vars, TPLADD, "ARCHECKED", (cfg.csp.allow_request == 1) ? "checked" : "");
tpl_addVar(vars, TPLADD, "ARFCHECKED", (cfg.csp.allow_reforward == 1) ? "checked" : "");
#endif
#ifdef CW_CYCLE_CHECK
#ifndef CS_CACHEEX
char *value = NULL;
#endif
tpl_addVar(vars, TPLADD, "CWCYCLECHECK", (cfg.cwcycle_check_enable == 1) ? "checked" : "");
value = mk_t_caidtab(&cfg.cwcycle_check_caidtab);
tpl_addVar(vars, TPLADD, "CWCYCLECHECKCAID", value);
free_mk_t(value);
tpl_printf(vars, TPLADD, "MAXCYCLELIST", "%d", cfg.maxcyclelist);
tpl_printf(vars, TPLADD, "KEEPCYCLETIME", "%d", cfg.keepcycletime);
if(cfg.onbadcycle)
{
tpl_printf(vars, TPLADD, "TMP", "ONBADCYCLE%d", cfg.onbadcycle);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
}
tpl_addVar(vars, TPLADD, "DROPOLD", (cfg.cwcycle_dropold == 1) ? "checked" : "");
if(cfg.cwcycle_sensitive)
{
tpl_printf(vars, TPLADD, "TMP", "CWCSEN%d", cfg.cwcycle_sensitive);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
}
tpl_addVar(vars, TPLADD, "ALLOWBADFROMFFB", (cfg.cwcycle_allowbadfromffb == 1) ? "checked" : "");
tpl_addVar(vars, TPLADD, "USECWCFROMCE", (cfg.cwcycle_usecwcfromce == 1) ? "checked" : "");
#endif
return tpl_getTpl(vars, "CONFIGCACHE");
}
#ifdef MODULE_NEWCAMD
static char *send_oscam_config_newcamd(struct templatevars *vars, struct uriparams *params)
{
int32_t i;
setActiveSubMenu(vars, MNU_CFG_NEWCAMD);
webif_save_config("newcamd", vars, params);
if((cfg.ncd_ptab.nports > 0) && (cfg.ncd_ptab.ports[0].s_port > 0))
{
char *value = mk_t_newcamd_port();
tpl_addVar(vars, TPLADD, "PORT", value);
free_mk_t(value);
if(IP_ISSET(cfg.ncd_srvip))
{ tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.ncd_srvip)); }
for(i = 0; i < (int32_t)sizeof(cfg.ncd_key); i++)
{ tpl_printf(vars, TPLAPPEND, "KEY", "%02X", cfg.ncd_key[i]); }
value = mk_t_iprange(cfg.ncd_allowed);
tpl_addVar(vars, TPLADD, "ALLOWED", value);
free_mk_t(value);
if(cfg.ncd_keepalive)
{ tpl_addVar(vars, TPLADD, "KEEPALIVE", "checked"); }
if(cfg.ncd_mgclient)
{ tpl_addVar(vars, TPLADD, "MGCLIENTCHK", "checked"); }
}
return tpl_getTpl(vars, "CONFIGNEWCAMD");
}
#endif
#ifdef MODULE_GBOX
static char *send_oscam_config_gbox(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_GBOX);
webif_save_config("gbox", vars, params);
tpl_addVar(vars, TPLADD, "HOSTNAME", xml_encode(vars, cfg.gbox_hostname));
char *value = mk_t_gbox_port();
tpl_addVar(vars, TPLAPPEND, "PORT", value);
free_mk_t(value);
tpl_addVar(vars, TPLADD, "MYPASSWORD", xml_encode(vars, cfg.gbox_my_password));
return tpl_getTpl(vars, "CONFIGGBOX");
}
#endif
#ifdef MODULE_RADEGAST
static char *send_oscam_config_radegast(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_RADEGAST);
webif_save_config("radegast", vars, params);
tpl_printf(vars, TPLADD, "PORT", "%d", cfg.rad_port);
if(IP_ISSET(cfg.rad_srvip))
{ tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.rad_srvip)); }
tpl_addVar(vars, TPLADD, "USERNAME", xml_encode(vars, cfg.rad_usr));
char *value = mk_t_iprange(cfg.rad_allowed);
tpl_addVar(vars, TPLADD, "ALLOWED", value);
free_mk_t(value);
return tpl_getTpl(vars, "CONFIGRADEGAST");
}
#endif
#ifdef MODULE_SCAM
static char *send_oscam_config_scam(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_SCAM);
webif_save_config("scam", vars, params);
tpl_printf(vars, TPLADD, "PORT", "%d", cfg.scam_port);
if(IP_ISSET(cfg.scam_srvip))
{ tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.scam_srvip)); }
char *value = mk_t_iprange(cfg.scam_allowed);
tpl_addVar(vars, TPLADD, "ALLOWED", value);
free_mk_t(value);
return tpl_getTpl(vars, "CONFIGSCAM");
}
#endif
#ifdef MODULE_CCCAM
static char *send_oscam_config_cccam(struct templatevars *vars, struct uriparams *params)
{
setActiveSubMenu(vars, MNU_CFG_CCCAM);
if(strcmp(getParam(params, "button"), "Refresh list") == 0)
{
cs_debug_mask(D_TRACE, "Entitlements: Refresh Shares start");
#ifdef MODULE_CCCSHARE
refresh_shares();
#endif
cs_debug_mask(D_TRACE, "Entitlements: Refresh Shares finished");
tpl_addMsg(vars, "Refresh Shares started");
}
webif_save_config("cccam", vars, params);
if(streq(getParam(params, "action"), "execute") && !cfg.http_readonly)
{ cc_update_nodeid(); }
char *value = mk_t_cccam_port();
tpl_addVar(vars, TPLAPPEND, "PORT", value);
free_mk_t(value);
if(IP_ISSET(cfg.cc_srvip))
{ tpl_addVar(vars, TPLADD, "SERVERIP", cs_inet_ntoa(cfg.cc_srvip)); }
tpl_printf(vars, TPLADD, "RESHARE", "%d", cfg.cc_reshare);
if(!strcmp((char *)cfg.cc_version, "2.0.11"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED0", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.1.1"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED1", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.1.2"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED2", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.1.3"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED3", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.1.4"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED4", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.2.0"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED5", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.2.1"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED6", "selected");
}
else if(!strcmp((char *)cfg.cc_version, "2.3.0"))
{
tpl_addVar(vars, TPLADD, "VERSIONSELECTED7", "selected");
}
tpl_printf(vars, TPLADD, "UPDATEINTERVAL", "%d", cfg.cc_update_interval);
tpl_printf(vars, TPLADD, "RECV_TIMEOUT", "%u", cfg.cc_recv_timeout);
tpl_addVar(vars, TPLADD, "STEALTH", (cfg.cc_stealth == 1) ? "checked" : "");
tpl_printf(vars, TPLADD, "NODEID", "%02X%02X%02X%02X%02X%02X%02X%02X",
cfg.cc_fixed_nodeid[0], cfg.cc_fixed_nodeid[1], cfg.cc_fixed_nodeid[2], cfg.cc_fixed_nodeid[3],
cfg.cc_fixed_nodeid[4], cfg.cc_fixed_nodeid[5], cfg.cc_fixed_nodeid[6], cfg.cc_fixed_nodeid[7]);
tpl_printf(vars, TPLADD, "TMP", "MINIMIZECARDSELECTED%d", cfg.cc_minimize_cards);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
tpl_printf(vars, TPLADD, "TMP", "RESHAREMODE%d", cfg.cc_reshare_services);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
tpl_printf(vars, TPLADD, "TMP", "IGNRSHRSELECTED%d", cfg.cc_ignore_reshare);
tpl_addVar(vars, TPLADD, tpl_getVar(vars, "TMP"), "selected");
tpl_addVar(vars, TPLADD, "FORWARDORIGINCARD", (cfg.cc_forward_origin_card == 1) ? "checked" : "");
tpl_addVar(vars, TPLADD, "KEEPCONNECTED", (cfg.cc_keep_connected == 1) ? "checked" : "");
tpl_addVar(vars, TPLADDONCE, "CONFIG_CONTROL", tpl_getTpl(vars, "CONFIGCCCAMCTRL"));
return tpl_getTpl(vars, "CONFIGCCCAM");
}
#endif
static bool is_ext(const char *path, const char *ext)
{
size_t lenpath = strlen(path);
size_t lenext = strlen(ext);