1 | #include "globals.h"
|
---|
2 | #ifdef LCDSUPPORT
|
---|
3 | /*
|
---|
4 | * module-lcd.c
|
---|
5 | *
|
---|
6 | * Created on: 24.05.2011
|
---|
7 | * Author: alno
|
---|
8 | */
|
---|
9 |
|
---|
10 | #include <stdio.h>
|
---|
11 | #include <string.h>
|
---|
12 | #include <time.h>
|
---|
13 | #include <sys/stat.h>
|
---|
14 | #include <dirent.h>
|
---|
15 | #include "module-stat.h"
|
---|
16 | #include "module-cccam.h"
|
---|
17 | #include "module-cccshare.h"
|
---|
18 |
|
---|
19 | int8_t running;
|
---|
20 |
|
---|
21 | void refresh_lcd_file() {
|
---|
22 |
|
---|
23 | char targetfile[256];
|
---|
24 | char tmpfile[256];
|
---|
25 | char channame[32];
|
---|
26 |
|
---|
27 | if(cfg.lcd_output_path == NULL){
|
---|
28 | snprintf(targetfile, sizeof(targetfile),"%s%s", get_tmp_dir(), "/oscam.lcd");
|
---|
29 | snprintf(tmpfile, sizeof(tmpfile), "%s%s.tmp", get_tmp_dir(), "/oscam.lcd");
|
---|
30 | } else {
|
---|
31 | snprintf(targetfile, sizeof(targetfile),"%s%s", cfg.lcd_output_path, "/oscam.lcd");
|
---|
32 | snprintf(tmpfile, sizeof(tmpfile), "%s%s.tmp", cfg.lcd_output_path, "/oscam.lcd");
|
---|
33 | }
|
---|
34 |
|
---|
35 | int8_t iscccam = 0;
|
---|
36 | int32_t seconds = 0, secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;
|
---|
37 | time_t now = time((time_t)0);
|
---|
38 |
|
---|
39 |
|
---|
40 | while(running) {
|
---|
41 | now = time((time_t)0);
|
---|
42 | int16_t cnt = 0, idx = 0, count_r = 0, count_p = 0, count_u = 0;
|
---|
43 | FILE *fpsave;
|
---|
44 |
|
---|
45 | if((fpsave = fopen(tmpfile, "w"))){
|
---|
46 |
|
---|
47 | idx = 0;
|
---|
48 | int16_t i;
|
---|
49 | char *type;
|
---|
50 | char *label;
|
---|
51 | char *status;
|
---|
52 |
|
---|
53 | // Statuslines start
|
---|
54 | secs = 0; fullmins = 0; mins = 0; fullhours = 0; hours = 0; days = 0;
|
---|
55 |
|
---|
56 | seconds = now - first_client->login;
|
---|
57 | secs = seconds % 60;
|
---|
58 | if (seconds > 60) {
|
---|
59 | fullmins = seconds / 60;
|
---|
60 | mins = fullmins % 60;
|
---|
61 | if(fullmins > 60) {
|
---|
62 | fullhours = fullmins / 60;
|
---|
63 | hours = fullhours % 24;
|
---|
64 | days = fullhours / 24;
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | fprintf(fpsave,"Version: %s\n", CS_VERSION);
|
---|
69 | fprintf(fpsave,"Revision: %s\n", CS_SVN_VERSION);
|
---|
70 | if(days == 0)
|
---|
71 | fprintf(fpsave, "up: %02d:%02d:%02d\n", hours, mins, secs);
|
---|
72 | else
|
---|
73 | fprintf(fpsave, "up: %02dd %02d:%02d:%02d\n", days, hours, mins, secs);
|
---|
74 | fprintf(fpsave,"totals: %d/%d/%d/%d/%d/%d\n", first_client->cwfound, first_client->cwnot, first_client->cwignored, first_client->cwtout, first_client->cwcache, first_client->cwtun);
|
---|
75 | fprintf(fpsave,"uptime: %d\n", seconds);
|
---|
76 | // Statuslines end
|
---|
77 |
|
---|
78 | // Readertable head
|
---|
79 | fprintf(fpsave,"Typ| Label | Idle | w | s | b | e | St\n");
|
---|
80 | fprintf(fpsave,"---+------------+--------------+---+---+---+---+----\n");
|
---|
81 |
|
---|
82 | struct s_client *cl;
|
---|
83 |
|
---|
84 | // Reader/Proxy table start
|
---|
85 | for ( i=0, cl=first_client; cl ; cl=cl->next, i++) {
|
---|
86 |
|
---|
87 | if ((cl->typ=='r' || cl->typ=='p') && ((now - cl->last) < 20 || !cfg.lcd_hide_idle)){
|
---|
88 | type = "";
|
---|
89 | label = "";
|
---|
90 | status = "OFF";
|
---|
91 | secs = 0; fullmins = 0; mins = 0; fullhours = 0; hours = 0; days = 0;
|
---|
92 |
|
---|
93 | seconds = now - cl->last;
|
---|
94 |
|
---|
95 | if (cl->typ == 'r'){
|
---|
96 | type = "R";
|
---|
97 | idx = count_r;
|
---|
98 | label = cl->reader->label;
|
---|
99 | if (cl->reader->card_status == CARD_INSERTED)
|
---|
100 | status = "OK";
|
---|
101 | count_r++;
|
---|
102 | }
|
---|
103 |
|
---|
104 | else if (cl->typ == 'p'){
|
---|
105 | type = "P";
|
---|
106 | iscccam = 0;
|
---|
107 | idx = count_p;
|
---|
108 | label = cl->reader->label;
|
---|
109 | if ((strncmp(monitor_get_proto(cl), "cccam", 5) == 0))
|
---|
110 | iscccam = 1;
|
---|
111 |
|
---|
112 | if (cl->reader->card_status == CARD_INSERTED)
|
---|
113 | status = "CON";
|
---|
114 |
|
---|
115 | count_p++;
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | secs = seconds % 60;
|
---|
120 | if (seconds > 60) {
|
---|
121 | fullmins = seconds / 60;
|
---|
122 | mins = fullmins % 60;
|
---|
123 | if(fullmins > 60) {
|
---|
124 | fullhours = fullmins / 60;
|
---|
125 | hours = fullhours % 24;
|
---|
126 | days = fullhours / 24;
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | int16_t written = 0, skipped = 0, blocked = 0, error = 0;
|
---|
131 |
|
---|
132 | char *emmtext;
|
---|
133 | if(cs_malloc(&emmtext, 16 * sizeof(char), -1)){
|
---|
134 | if(cl->typ == 'r' || !iscccam ){
|
---|
135 | for (i=0; i<4; i++) {
|
---|
136 | error += cl->reader->emmerror[i];
|
---|
137 | blocked += cl->reader->emmblocked[i];
|
---|
138 | skipped += cl->reader->emmskipped[i];
|
---|
139 | written += cl->reader->emmwritten[i];
|
---|
140 | }
|
---|
141 | snprintf(emmtext, 16, "%3d|%3d|%3d|%3d",
|
---|
142 | written > 999? 999 : written,
|
---|
143 | skipped > 999? 999 : skipped,
|
---|
144 | blocked > 999? 999 : blocked,
|
---|
145 | error > 999? 999 : error);
|
---|
146 |
|
---|
147 | } else if(cl->typ == 'p' && iscccam ){
|
---|
148 | struct cc_data *rcc = cl->cc;
|
---|
149 | if(rcc){
|
---|
150 | LLIST *cards = rcc->cards;
|
---|
151 | if (cards) {
|
---|
152 | int32_t cnt = ll_count(cards);
|
---|
153 | int32_t locals = rcc->num_hop1;
|
---|
154 | snprintf(emmtext, 16, " %3d/%3d card%s", locals, cnt, (cnt > 1)? "s ": " ");
|
---|
155 | }
|
---|
156 | } else {
|
---|
157 | snprintf(emmtext, 16, " No cards ");
|
---|
158 | }
|
---|
159 |
|
---|
160 | } else {
|
---|
161 | snprintf(emmtext, 16, " ");
|
---|
162 | }
|
---|
163 |
|
---|
164 | }
|
---|
165 |
|
---|
166 | if(days == 0) {
|
---|
167 | fprintf(fpsave,"%s%d | %-10.10s | %02d:%02d:%02d |%s| %s\n",
|
---|
168 | type, idx, label, hours, mins,
|
---|
169 | secs, emmtext, status);
|
---|
170 | } else {
|
---|
171 | fprintf(fpsave,"%s%d | %-10.10s |% 2dd %02d:%02d:%02d |%s| %s\n",
|
---|
172 | type, idx, label, days, hours, mins,
|
---|
173 | secs, emmtext, status);
|
---|
174 | }
|
---|
175 | free(emmtext);
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | fprintf(fpsave,"---+------------+--------------+---+---+---+--++----\n");
|
---|
180 | // Reader/Proxy table end
|
---|
181 |
|
---|
182 |
|
---|
183 | // Usertable start
|
---|
184 | fprintf(fpsave,"Typ| Label | Channel | Time\n");
|
---|
185 | fprintf(fpsave,"---+------------+-----------------------------+-----\n");
|
---|
186 |
|
---|
187 | /*
|
---|
188 | //Testclient
|
---|
189 | fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
|
---|
190 | "U",
|
---|
191 | 1,
|
---|
192 | "test",
|
---|
193 | "Sky De",
|
---|
194 | "Discovery Channel",
|
---|
195 | 568);
|
---|
196 |
|
---|
197 | */
|
---|
198 |
|
---|
199 | for ( i=0, cl=first_client; cl ; cl=cl->next, i++) {
|
---|
200 |
|
---|
201 | seconds = now - cl->lastecm;
|
---|
202 |
|
---|
203 | if (cl->typ == 'c' && seconds < 15){
|
---|
204 | type = "U";
|
---|
205 | idx = count_u;
|
---|
206 | label = cl->account->usr;
|
---|
207 | count_u++;
|
---|
208 |
|
---|
209 | get_servicename(cl, cl->last_srvid, cl->last_caid, channame);
|
---|
210 | fprintf(fpsave,"%s%d | %-10.10s | %-10.10s:%-17.17s| % 4d\n",
|
---|
211 | type,
|
---|
212 | idx,
|
---|
213 | label,
|
---|
214 | cl->last_srvidptr && cl->last_srvidptr->prov ? cl->last_srvidptr->prov : "",
|
---|
215 | cl->last_srvidptr && cl->last_srvidptr->name ? cl->last_srvidptr->name : "",
|
---|
216 | cl->cwlastresptime);
|
---|
217 |
|
---|
218 | }
|
---|
219 | }
|
---|
220 | fprintf(fpsave,"---+------------+-----------------------------+-----\n");
|
---|
221 | // Usertable end
|
---|
222 | fclose(fpsave);
|
---|
223 | }
|
---|
224 |
|
---|
225 | idx = 0;
|
---|
226 | cs_sleepms(cfg.lcd_write_intervall * 1000);
|
---|
227 | cnt++;
|
---|
228 |
|
---|
229 | if(file_copy(tmpfile, targetfile) < 0)
|
---|
230 | cs_log("An error occured while writing oscam.lcd file %s.", targetfile);
|
---|
231 |
|
---|
232 | if(remove(tmpfile) < 0)
|
---|
233 | cs_log("Error removing temp oscam.lcd file %s (errno=%d %s)!", tmpfile, errno, strerror(errno));
|
---|
234 | }
|
---|
235 |
|
---|
236 | }
|
---|
237 |
|
---|
238 | void start_lcd_thread() {
|
---|
239 | running = 1;
|
---|
240 | start_thread((void *) &refresh_lcd_file, "LCD");
|
---|
241 | }
|
---|
242 |
|
---|
243 | void end_lcd_thread() {
|
---|
244 | running = 0;
|
---|
245 | }
|
---|
246 |
|
---|
247 | #endif
|
---|