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