1 | #ifndef SOFTCAM_H |
---|
2 | #define SOFTCAM_H |
---|
3 | |
---|
4 | //char* swhichcam = NULL; |
---|
5 | struct clist *emulist[LISTHASHSIZE] = {NULL}; |
---|
6 | |
---|
7 | char* whichcam() |
---|
8 | { |
---|
9 | return command("emu.sh active"); |
---|
10 | } |
---|
11 | |
---|
12 | int checkrunningcam(char* emu) |
---|
13 | { |
---|
14 | char* check = NULL; |
---|
15 | char* cmd = NULL; |
---|
16 | int running = 0; |
---|
17 | |
---|
18 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
19 | cmd = ostrcat("emu.sh check \"" , cmd, 0, 1); |
---|
20 | check = command(cmd); |
---|
21 | free(cmd); |
---|
22 | if(ostrstr(check, "checkemu running") != 0) running = 1; |
---|
23 | free(check); |
---|
24 | return running; |
---|
25 | } |
---|
26 | |
---|
27 | void readmenu() |
---|
28 | { |
---|
29 | char* emuname = NULL; |
---|
30 | char* emuline = NULL; |
---|
31 | char* emush = NULL; |
---|
32 | char* cmd = NULL; |
---|
33 | char* checkactive = NULL; |
---|
34 | char* checkstate = NULL; |
---|
35 | int count = 0; |
---|
36 | int active = 0; |
---|
37 | int check = 0; |
---|
38 | |
---|
39 | // clear the list |
---|
40 | if(emulist != NULL) |
---|
41 | freelist(emulist); |
---|
42 | |
---|
43 | // search active cam |
---|
44 | //free(swhichcam); swhichcam = NULL; |
---|
45 | //swhichcam = whichcam(); |
---|
46 | |
---|
47 | // get the emu list |
---|
48 | emuline = command("emu.sh list"); |
---|
49 | if(emuline != NULL) |
---|
50 | { |
---|
51 | // split emulist lines |
---|
52 | emush = strtok(emuline, "\n"); |
---|
53 | |
---|
54 | while(emush != NULL) |
---|
55 | { |
---|
56 | active = 0; |
---|
57 | check = 0; |
---|
58 | |
---|
59 | // read emu infoname |
---|
60 | cmd = string_quote(emush); |
---|
61 | cmd = ostrcat("emu.sh infoname ", cmd, 0, 1); |
---|
62 | emuname = string_newline(command(cmd)); |
---|
63 | free(cmd); cmd = NULL; |
---|
64 | |
---|
65 | // check if cam is active |
---|
66 | cmd = string_quote(emush); |
---|
67 | cmd = ostrcat("emu.sh active ", cmd, 0, 1); |
---|
68 | checkactive = string_newline(command(cmd)); |
---|
69 | free(cmd); cmd = NULL; |
---|
70 | if(ostrcmp(emush, checkactive) == 0) |
---|
71 | { |
---|
72 | debug(100, "active emu = %s", emush); |
---|
73 | active = 1; |
---|
74 | } |
---|
75 | |
---|
76 | // check if emu is running |
---|
77 | cmd = string_quote(emush); |
---|
78 | cmd = ostrcat("emu.sh check ", cmd, 0, 1); |
---|
79 | checkstate = command(cmd); |
---|
80 | free(cmd); cmd = NULL; |
---|
81 | if(ostrstr(checkstate, "checkemu running") != 0) |
---|
82 | { |
---|
83 | debug(100, "running emu = %s", emush); |
---|
84 | check = 1; |
---|
85 | } |
---|
86 | |
---|
87 | // update emuname with status |
---|
88 | if(active == 1 && check == 1) |
---|
89 | { |
---|
90 | emuname = ostrcat(emuname, " (", 1, 0); |
---|
91 | emuname = ostrcat(emuname, _("started"), 1, 0); |
---|
92 | emuname = ostrcat(emuname, ") (", 1, 0); |
---|
93 | emuname = ostrcat(emuname, _("active"), 1, 0); |
---|
94 | emuname = ostrcat(emuname, ")", 1, 0); |
---|
95 | } |
---|
96 | else if(check == 1) |
---|
97 | { |
---|
98 | emuname = ostrcat(emuname, " (", 1, 0); |
---|
99 | emuname = ostrcat(emuname, _("started"), 1, 0); |
---|
100 | emuname = ostrcat(emuname, ")", 1, 0); |
---|
101 | } |
---|
102 | else if(active == 1) |
---|
103 | { |
---|
104 | emuname = ostrcat(emuname, " (", 1, 0); |
---|
105 | emuname = ostrcat(emuname, _("active"), 1, 0); |
---|
106 | emuname = ostrcat(emuname, ")", 1, 0); |
---|
107 | } |
---|
108 | |
---|
109 | debug(100, "emuname = %s", emuname); |
---|
110 | addlist(emulist, emuname, emush); |
---|
111 | free(emuname); emuname = NULL; |
---|
112 | free(checkactive); checkactive = NULL; |
---|
113 | free(checkstate); checkstate = NULL; |
---|
114 | emush = strtok(NULL, "\n"); |
---|
115 | count++; |
---|
116 | } |
---|
117 | } |
---|
118 | else |
---|
119 | addlist(emulist, _("Emu not found"), "emu0"); |
---|
120 | |
---|
121 | free(emuname); |
---|
122 | free(emuline); |
---|
123 | free(emush); |
---|
124 | free(cmd); |
---|
125 | free(checkactive); |
---|
126 | free(checkstate); |
---|
127 | } |
---|
128 | |
---|
129 | void fillmenubox() |
---|
130 | { |
---|
131 | struct clist* elist = NULL; |
---|
132 | struct skin* screen = getscreen("softcam"); |
---|
133 | struct skin* listbox = getscreennode(screen, "listbox"); |
---|
134 | struct skin* node = NULL; |
---|
135 | char* aktemu = NULL; |
---|
136 | int setselection = 0, i; |
---|
137 | |
---|
138 | delmarkedscreennodes(screen, 1); |
---|
139 | |
---|
140 | int height = 22; |
---|
141 | height += status.fontsizeadjust; |
---|
142 | |
---|
143 | for(i = 0; i < LISTHASHSIZE; i++) |
---|
144 | { |
---|
145 | elist = emulist[i]; |
---|
146 | |
---|
147 | while(elist != NULL) |
---|
148 | { |
---|
149 | if(elist->value != NULL) |
---|
150 | { |
---|
151 | node = addlistbox(screen, listbox, node, 1); |
---|
152 | if(node != NULL) |
---|
153 | { |
---|
154 | changetext(node, _(elist->key)); |
---|
155 | changename(node, elist->value); |
---|
156 | node->height = height; |
---|
157 | |
---|
158 | // change font color, depending emu is running/active |
---|
159 | if(ostrstr(node->text, "active") != 0) |
---|
160 | { |
---|
161 | node->fontcol = convertcol("emuaktivecol"); |
---|
162 | if(setselection == 0) |
---|
163 | { |
---|
164 | aktemu = elist->value; |
---|
165 | setselection = 1; |
---|
166 | } |
---|
167 | } |
---|
168 | else if(ostrstr(node->text, "started") != 0) |
---|
169 | { |
---|
170 | node->fontcol = convertcol("emurunningcol"); |
---|
171 | if(setselection == 0 || setselection == 1) |
---|
172 | { |
---|
173 | aktemu = elist->value; |
---|
174 | setselection = 2; |
---|
175 | } |
---|
176 | } |
---|
177 | else |
---|
178 | node->fontcol = listbox->fontcol; |
---|
179 | } |
---|
180 | } |
---|
181 | elist = elist->next; |
---|
182 | } |
---|
183 | } |
---|
184 | setlistboxselection(listbox, aktemu); |
---|
185 | debug(100, "set selection to %s", aktemu); |
---|
186 | } |
---|
187 | |
---|
188 | void activate(char* emu) |
---|
189 | { |
---|
190 | char* cmd = NULL; |
---|
191 | |
---|
192 | debug(100, "active emu= %s", emu); |
---|
193 | if(emu == NULL) return; |
---|
194 | |
---|
195 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
196 | cmd = ostrcat("emu.sh activate \"" , cmd, 0, 1); |
---|
197 | osystem(cmd, 20); |
---|
198 | free(cmd); |
---|
199 | readmenu(); |
---|
200 | fillmenubox(); |
---|
201 | } |
---|
202 | |
---|
203 | void deactivate(char* emu) |
---|
204 | { |
---|
205 | char* cmd = NULL; |
---|
206 | |
---|
207 | debug(100, "deaktivate emu= %s", emu); |
---|
208 | if(emu == NULL) return; |
---|
209 | |
---|
210 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
211 | cmd = ostrcat("emu.sh deactivate \"" , cmd, 0, 1); |
---|
212 | osystem(cmd, 20); |
---|
213 | free(cmd); |
---|
214 | readmenu(); |
---|
215 | fillmenubox(); |
---|
216 | } |
---|
217 | |
---|
218 | void startcam(char* emu) |
---|
219 | { |
---|
220 | char* cmd = NULL; |
---|
221 | |
---|
222 | debug(100, "startcam emu= %s", emu); |
---|
223 | if(emu == NULL) return; |
---|
224 | |
---|
225 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
226 | cmd = ostrcat("emu.sh start \"" , cmd, 0, 1); |
---|
227 | osystem(cmd, 20); |
---|
228 | free(cmd); |
---|
229 | readmenu(); |
---|
230 | fillmenubox(); |
---|
231 | } |
---|
232 | |
---|
233 | void stopcam(char* emu) |
---|
234 | { |
---|
235 | char* cmd = NULL; |
---|
236 | |
---|
237 | debug(100, "stopcam emu= %s", emu); |
---|
238 | if(emu == NULL) return; |
---|
239 | |
---|
240 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
241 | cmd = ostrcat("emu.sh stop \"" , cmd, 0, 1); |
---|
242 | osystem(cmd, 20); |
---|
243 | free(cmd); |
---|
244 | readmenu(); |
---|
245 | fillmenubox(); |
---|
246 | } |
---|
247 | |
---|
248 | void restartcam(char* emu) |
---|
249 | { |
---|
250 | char* cmd = NULL; |
---|
251 | |
---|
252 | debug(100, "restart emu= %s", emu); |
---|
253 | if(emu == NULL) return; |
---|
254 | |
---|
255 | cmd = ostrcat(emu, "\"" , 0, 0); |
---|
256 | cmd = ostrcat("emu.sh restart \"" , cmd, 0, 1); |
---|
257 | osystem(cmd, 20); |
---|
258 | free(cmd); |
---|
259 | readmenu(); |
---|
260 | fillmenubox(); |
---|
261 | } |
---|
262 | |
---|
263 | void readecminfo(struct skin* labelecminfo) |
---|
264 | { |
---|
265 | char* tmpstr = NULL; |
---|
266 | |
---|
267 | tmpstr = command("emu.sh ecminfo"); |
---|
268 | changetext(labelecminfo, _(tmpstr)); |
---|
269 | free(tmpstr); |
---|
270 | } |
---|
271 | |
---|
272 | void screensoftcam() |
---|
273 | { |
---|
274 | int rcret = 0; |
---|
275 | char* tmpstr = NULL; |
---|
276 | struct skin* loading = getscreen("loading"); |
---|
277 | struct skin* softcam = getscreen("softcam"); |
---|
278 | struct skin* listbox = getscreennode(softcam, "listbox"); |
---|
279 | struct skin* labelecminfo = getscreennode(softcam, "ecminfo"); |
---|
280 | struct skin* menutitle = getscreennode(softcam, "menutitle"); |
---|
281 | struct skin* b_red = getscreennode(softcam, "b1"); |
---|
282 | struct skin* b_green = getscreennode(softcam, "b2"); |
---|
283 | struct skin* b_yellow = getscreennode(softcam, "b3"); |
---|
284 | struct skin* b_blue = getscreennode(softcam, "b4"); |
---|
285 | struct skin* b_menu = getscreennode(softcam, "b7"); |
---|
286 | |
---|
287 | struct skin* pluginnode = NULL; |
---|
288 | void (*startplugin)(char*); |
---|
289 | |
---|
290 | drawscreen(loading, 0, 0); |
---|
291 | |
---|
292 | // show labels |
---|
293 | changetext(menutitle, _("Softcam selection:")); |
---|
294 | changetext(b_red, _("Deactivate")); |
---|
295 | changetext(b_green, _("Restart")); |
---|
296 | changetext(b_yellow, _("Refresh")); |
---|
297 | changetext(b_blue, _("Activate")); |
---|
298 | |
---|
299 | // read ecm inf0 |
---|
300 | readecminfo(labelecminfo); |
---|
301 | |
---|
302 | // read emulist |
---|
303 | readmenu(); |
---|
304 | |
---|
305 | // add emu's to selectionbox |
---|
306 | fillmenubox(); |
---|
307 | |
---|
308 | drawscreen(softcam, 2, 0); |
---|
309 | addscreenrc(softcam, listbox); |
---|
310 | int found = 0; |
---|
311 | |
---|
312 | if(listbox->select != NULL) |
---|
313 | { |
---|
314 | free(tmpstr), tmpstr = NULL; |
---|
315 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
316 | string_tolower(tmpstr); |
---|
317 | |
---|
318 | if(ostrstr(tmpstr, "oscam") != NULL) |
---|
319 | { |
---|
320 | b_menu->hidden = NO; |
---|
321 | found = 1; |
---|
322 | } |
---|
323 | else |
---|
324 | { |
---|
325 | b_menu->hidden = YES; |
---|
326 | found = 0; |
---|
327 | } |
---|
328 | free(tmpstr), tmpstr = NULL; |
---|
329 | } |
---|
330 | |
---|
331 | drawscreen(softcam, 0, 0); |
---|
332 | |
---|
333 | while(1) |
---|
334 | { |
---|
335 | rcret = waitrc(softcam, 4000, 2); |
---|
336 | if(rcret == getrcconfigint("rcexit", NULL)) break; |
---|
337 | if(listbox->select != NULL) |
---|
338 | { |
---|
339 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
340 | string_tolower(tmpstr); |
---|
341 | if(ostrstr(tmpstr, "oscam") != NULL) |
---|
342 | { |
---|
343 | b_menu->hidden = NO; |
---|
344 | found = 1; |
---|
345 | } |
---|
346 | else |
---|
347 | { |
---|
348 | b_menu->hidden = YES; |
---|
349 | found = 0; |
---|
350 | } |
---|
351 | free(tmpstr), tmpstr = NULL; |
---|
352 | } |
---|
353 | if(listbox->select != NULL && rcret == getrcconfigint("rcred", NULL)) |
---|
354 | { |
---|
355 | // deactivate or stop emu |
---|
356 | drawscreen(loading, 0, 0); |
---|
357 | |
---|
358 | // check if cam is active |
---|
359 | char* cmd = string_quote(listbox->select->name); |
---|
360 | cmd = ostrcat("emu.sh active ", cmd, 0, 1); |
---|
361 | if(ostrcmp(listbox->select->name, string_newline(command(cmd))) == 0) |
---|
362 | deactivate(listbox->select->name); |
---|
363 | else |
---|
364 | stopcam(listbox->select->name); |
---|
365 | free(cmd); cmd = NULL; |
---|
366 | startinternreader(1); |
---|
367 | } |
---|
368 | if(listbox->select != NULL && rcret == getrcconfigint("rcgreen", NULL)) |
---|
369 | { |
---|
370 | startinternreader(0); |
---|
371 | // restart emu |
---|
372 | drawscreen(loading, 0, 0); |
---|
373 | restartcam(listbox->select->name); |
---|
374 | startinternreader(1); |
---|
375 | } |
---|
376 | if(rcret == getrcconfigint("rcyellow", NULL)) |
---|
377 | { |
---|
378 | // refrech screen |
---|
379 | drawscreen(loading, 0, 0); |
---|
380 | readecminfo(labelecminfo); |
---|
381 | readmenu(); |
---|
382 | fillmenubox(); |
---|
383 | } |
---|
384 | if(listbox->select != NULL && rcret == getrcconfigint("rcblue", NULL)) |
---|
385 | { |
---|
386 | startinternreader(0); |
---|
387 | // activate emu |
---|
388 | drawscreen(loading, 0, 0); |
---|
389 | activate(listbox->select->name); |
---|
390 | startinternreader(1); |
---|
391 | } |
---|
392 | if(listbox->select != NULL && rcret == getrcconfigint("rcok", NULL)) |
---|
393 | { |
---|
394 | startinternreader(0); |
---|
395 | // start/stop emu, depending if emu already runs |
---|
396 | drawscreen(loading, 0, 0); |
---|
397 | if(checkrunningcam(listbox->select->name) == 1) |
---|
398 | stopcam(listbox->select->name); |
---|
399 | else |
---|
400 | startcam(listbox->select->name); |
---|
401 | startinternreader(1); |
---|
402 | } |
---|
403 | if(rcret == getrcconfigint("rcmenu", NULL) && found == 1) |
---|
404 | { |
---|
405 | pluginnode = getplugin("Reader Config"); |
---|
406 | |
---|
407 | if(pluginnode != NULL) |
---|
408 | { |
---|
409 | startplugin = dlsym(pluginnode->pluginhandle, "screenoscam"); |
---|
410 | if(startplugin != NULL) |
---|
411 | startplugin(listbox->select->name); |
---|
412 | } |
---|
413 | else |
---|
414 | textbox(_("Message"), _("Reader Config Plugin not installed !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
415 | } |
---|
416 | if(rcret == getrcconfigint("rcinfo", NULL)) |
---|
417 | { |
---|
418 | int pinret = 0; |
---|
419 | pinret = screenpincheck(4, NULL); |
---|
420 | if(pinret == 1) continue; |
---|
421 | |
---|
422 | char* extract = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL, *cmd = NULL; |
---|
423 | |
---|
424 | tmpstr = ostrcat(listbox->select->name, NULL, 0, 0); |
---|
425 | |
---|
426 | string_tolower(tmpstr); |
---|
427 | tmpstr = stringreplacecharonce(tmpstr, '-', '\0'); |
---|
428 | tmpstr = stringreplacecharonce(tmpstr, '_', '\0'); |
---|
429 | tmpstr = stringreplacecharonce(tmpstr, '.', '\0'); |
---|
430 | |
---|
431 | if(listbox->select->name == NULL) |
---|
432 | { |
---|
433 | if(file_exist("/mnt/swapextensions/keys")) |
---|
434 | tmpstr1 = ostrcat("/mnt/swapextensions", NULL, 0, 0); |
---|
435 | else if(file_exist("/var/swap/keys")) |
---|
436 | tmpstr1 = ostrcat("/var/swap", NULL, 0, 0); |
---|
437 | else if(file_exist("/var/keys")) |
---|
438 | tmpstr1 = ostrcat("/var/keys", NULL, 0, 0); |
---|
439 | |
---|
440 | if(tmpstr1 == NULL) return; |
---|
441 | extract = ostrcat("tar -zxvf /tmp/.tmp.tar.gz -C ", tmpstr1, 0, 0); |
---|
442 | extract = ostrcat(extract, "/keys/", 1, 0); |
---|
443 | extract = ostrcat(extract, " > /dev/null 2>&1", 1, 0); |
---|
444 | free(tmpstr1), tmpstr1 = NULL; |
---|
445 | } |
---|
446 | else |
---|
447 | { |
---|
448 | cmd = ostrcat("/sbin/emu.sh keydir ", listbox->select->name, 0, 0); |
---|
449 | tmpstr1 = string_newline(command(cmd)); |
---|
450 | extract = ostrcat("tar -zxvf /tmp/.tmp.tar.gz -C ", tmpstr1, 0, 0); |
---|
451 | extract = ostrcat(extract, "/", 1, 0); |
---|
452 | extract = ostrcat(extract, " > /dev/null 2>&1", 1, 0); |
---|
453 | free(cmd), cmd = NULL; |
---|
454 | free(tmpstr1), tmpstr1 = NULL; |
---|
455 | } |
---|
456 | |
---|
457 | tmpstr1 = ostrcat("/svn/auth/", tmpstr, 0, 0); |
---|
458 | tmpstr1 = ostrcat(tmpstr1, ".tar.gz", 0, 0); |
---|
459 | |
---|
460 | tmpstr2 = ostrcat(tmpstr, " ", 0, 0); |
---|
461 | tmpstr2 = ostrcat(tmpstr2, _("Keys Updated !"), 1, 0); |
---|
462 | |
---|
463 | tmpstr3 = ostrcat(_("Restart"), " ", 0, 0); |
---|
464 | tmpstr3 = ostrcat(tmpstr3, tmpstr, 1, 0); |
---|
465 | tmpstr3 = ostrcat(tmpstr3, " ?", 1, 0); |
---|
466 | |
---|
467 | int ret = 1; |
---|
468 | |
---|
469 | debug(696, "tmpstr1: %s", tmpstr1); |
---|
470 | gethttp("atemio.dyndns.tv", tmpstr1, 80, "/tmp/.tmp.tar.gz", HTTPAUTH, 5000, NULL, 0); |
---|
471 | |
---|
472 | debug(696, "extract: %s", extract); |
---|
473 | ret = system(extract); |
---|
474 | |
---|
475 | if(ret == 0) |
---|
476 | { |
---|
477 | textbox(_("Message"), tmpstr2, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 10, 0); |
---|
478 | if(textbox(_("Message"), tmpstr3, _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0) == 1) |
---|
479 | { |
---|
480 | cmd = ostrcat("emu.sh restart" , NULL, 0, 0); |
---|
481 | ret = system(cmd); |
---|
482 | free(cmd); |
---|
483 | } |
---|
484 | } |
---|
485 | system("rm -rf /tmp/.tmp.tar.gz > /dev/null 2>&1"); |
---|
486 | |
---|
487 | free(tmpstr); tmpstr = NULL; |
---|
488 | free(tmpstr1); tmpstr1 = NULL; |
---|
489 | free(tmpstr2); tmpstr2 = NULL; |
---|
490 | free(tmpstr3); tmpstr3 = NULL; |
---|
491 | free(extract); extract = NULL; |
---|
492 | } |
---|
493 | if(rcret == RCTIMEOUT) |
---|
494 | { |
---|
495 | // update ecminfo |
---|
496 | readecminfo(labelecminfo); |
---|
497 | } |
---|
498 | drawscreen(softcam, 0, 0); |
---|
499 | } |
---|
500 | |
---|
501 | if(emulist != NULL) |
---|
502 | freelist(emulist); |
---|
503 | |
---|
504 | //free(swhichcam); swhichcam = NULL; |
---|
505 | delmarkedscreennodes(softcam, 1); |
---|
506 | delownerrc(softcam); |
---|
507 | clearscreen(softcam); |
---|
508 | } |
---|
509 | |
---|
510 | #endif |
---|