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 |
|
---|
17 | int8_t running;
|
---|
18 |
|
---|
19 | void refresh_lcd_file() {
|
---|
20 |
|
---|
21 |
|
---|
22 | char targetfile[256];
|
---|
23 | snprintf(targetfile, sizeof(targetfile),"%s%s", get_tmp_dir(), "/oscam.lcd");
|
---|
24 |
|
---|
25 | int32_t seconds = 0, secs = 0, fullmins = 0, mins = 0, fullhours = 0, hours = 0, days = 0;
|
---|
26 | time_t now = time((time_t)0);
|
---|
27 |
|
---|
28 | while(running) {
|
---|
29 | now = time((time_t)0);
|
---|
30 | int16_t cnt = 0, idx = 0, count_r = 0, count_p = 0, count_u = 0;
|
---|
31 | FILE *fpsave;
|
---|
32 |
|
---|
33 | if((fpsave = fopen(targetfile,"w"))){
|
---|
34 |
|
---|
35 | idx = 0;
|
---|
36 | int16_t i;
|
---|
37 | char *type;
|
---|
38 | char *label;
|
---|
39 | char *status;
|
---|
40 |
|
---|
41 | struct s_client *cl;
|
---|
42 | for ( i=0, cl=first_client; cl ; cl=cl->next, i++) {
|
---|
43 | type = "---";
|
---|
44 | label = "+++";
|
---|
45 | status = "OFFLINE";
|
---|
46 | seconds = 0;
|
---|
47 | secs = 0;
|
---|
48 | fullmins = 0;
|
---|
49 | mins = 0;
|
---|
50 | fullhours = 0;
|
---|
51 | hours = 0;
|
---|
52 | days = 0;
|
---|
53 |
|
---|
54 |
|
---|
55 | if (cl->typ=='c' || cl->typ=='r' || cl->typ=='p'){
|
---|
56 |
|
---|
57 | seconds = now - cl->lastecm;
|
---|
58 |
|
---|
59 | if (cl->typ == 'c' && seconds < 10){
|
---|
60 | type = "user";
|
---|
61 | idx = count_u;
|
---|
62 | label = cl->account->usr;
|
---|
63 | status = "ONLINE";
|
---|
64 | count_u++;
|
---|
65 | }
|
---|
66 |
|
---|
67 | else if (cl->typ == 'r'){
|
---|
68 | type = "reader";
|
---|
69 | idx = count_r;
|
---|
70 | label = cl->reader->label;
|
---|
71 | if (cl->reader->card_status == CARD_INSERTED)
|
---|
72 | status = "CONNECTED";
|
---|
73 | count_r++;
|
---|
74 | }
|
---|
75 |
|
---|
76 | else if (cl->typ == 'p'){
|
---|
77 | type = "proxy";
|
---|
78 | idx = count_p;
|
---|
79 | label = cl->reader->label;
|
---|
80 | if (cl->reader->card_status == CARD_INSERTED)
|
---|
81 | status = "CARDOK";
|
---|
82 | count_p++;
|
---|
83 | }
|
---|
84 |
|
---|
85 | if (cl->typ == 'c'){
|
---|
86 | if(seconds < 10){
|
---|
87 | get_servicename(cl, cl->last_srvid, cl->last_caid);
|
---|
88 | fprintf(fpsave,"%s%d: %-10s %s:%s [%d]\n",
|
---|
89 | type,
|
---|
90 | idx,
|
---|
91 | label,
|
---|
92 | cl->last_srvidptr && cl->last_srvidptr->prov ? cl->last_srvidptr->prov : "",
|
---|
93 | cl->last_srvidptr && cl->last_srvidptr->name ? cl->last_srvidptr->name : "",
|
---|
94 | cl->cwlastresptime);
|
---|
95 | }
|
---|
96 | } else {
|
---|
97 |
|
---|
98 |
|
---|
99 | secs = seconds % 60;
|
---|
100 | if (seconds > 60) {
|
---|
101 | fullmins = seconds / 60;
|
---|
102 | mins = fullmins % 60;
|
---|
103 | if(fullmins > 60) {
|
---|
104 | fullhours = fullmins / 60;
|
---|
105 | hours = fullhours % 24;
|
---|
106 | days = fullhours / 24;
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | int16_t written = 0, skipped = 0, blocked = 0, error = 0;
|
---|
111 |
|
---|
112 | for (i=0; i<4; i++) {
|
---|
113 | error += cl->reader->emmerror[i];
|
---|
114 | blocked += cl->reader->emmblocked[i];
|
---|
115 | skipped += cl->reader->emmskipped[i];
|
---|
116 | written += cl->reader->emmwritten[i];
|
---|
117 | }
|
---|
118 |
|
---|
119 | fprintf(fpsave,"%s%d: %-10s %02d:%02d:%02d %d/%d/%d/%d %s\n",
|
---|
120 | type,
|
---|
121 | idx,
|
---|
122 | label,
|
---|
123 | hours,
|
---|
124 | mins,
|
---|
125 | secs,
|
---|
126 | written,
|
---|
127 | skipped,
|
---|
128 | blocked,
|
---|
129 | error,
|
---|
130 | status);
|
---|
131 |
|
---|
132 | }
|
---|
133 |
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | }
|
---|
138 |
|
---|
139 | seconds = 0;
|
---|
140 | secs = 0;
|
---|
141 | fullmins = 0;
|
---|
142 | mins = 0;
|
---|
143 | fullhours = 0;
|
---|
144 | hours = 0;
|
---|
145 | days = 0;
|
---|
146 |
|
---|
147 | if (now > first_client->login){
|
---|
148 | seconds = now - first_client->login;
|
---|
149 | secs = seconds % 60;
|
---|
150 | if (seconds > 60) {
|
---|
151 | fullmins = seconds / 60;
|
---|
152 | mins = fullmins % 60;
|
---|
153 | if(fullmins > 60) {
|
---|
154 | fullhours = fullmins / 60;
|
---|
155 | hours = fullhours % 24;
|
---|
156 | days = fullhours / 24;
|
---|
157 | }
|
---|
158 | }
|
---|
159 | }
|
---|
160 |
|
---|
161 | fprintf(fpsave,"status0: Version: %s\n", CS_VERSION);
|
---|
162 | fprintf(fpsave,"status1: Revision: %s\n", CS_SVN_VERSION);
|
---|
163 | if(days == 0)
|
---|
164 | fprintf(fpsave, "status2: up: %02d:%02d:%02d\n", hours, mins, secs);
|
---|
165 | else
|
---|
166 | fprintf(fpsave, "status2: up: %02dd %02d:%02d:%02d\n", days, hours, mins, secs);
|
---|
167 | fprintf(fpsave,"status3: proxies: %d\n", count_p);
|
---|
168 | fprintf(fpsave,"status4: reader: %d\n", count_r);
|
---|
169 | fprintf(fpsave,"status5: user: %d\n", count_u);
|
---|
170 | fprintf(fpsave,"status6: 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);
|
---|
171 | fprintf(fpsave,"status7: uptime: %d\n", seconds);
|
---|
172 |
|
---|
173 | fclose(fpsave);
|
---|
174 | }
|
---|
175 | idx = 0;
|
---|
176 | cs_sleepms(10000);
|
---|
177 | cnt++;
|
---|
178 | }
|
---|
179 |
|
---|
180 | }
|
---|
181 |
|
---|
182 | void start_lcd_thread() {
|
---|
183 | running = 1;
|
---|
184 | start_thread((void *) &refresh_lcd_file, "LCD");
|
---|
185 | }
|
---|
186 |
|
---|
187 | void end_lcd_thread() {
|
---|
188 | running = 0;
|
---|
189 | }
|
---|
190 |
|
---|
191 | #endif
|
---|