1111 */
1212define ( 'TaskTimeTerminate ' , 'API ' );
1313
14- die ("Coming soon! " );
15-
1614require_once ( __DIR__ . '/../core/load.php ' );
1715
18- $ login = new Login ();
16+ if (
17+ !empty ($ _GET ['group ' ]) && !empty ($ _GET ['token ' ])
18+ &&
19+ is_string ($ _GET ['group ' ]) && is_string ($ _GET ['token ' ])
20+ &&
21+ preg_match (API ::GROUP_NAME_PREG , $ _GET ['group ' ]) === 1 && strlen ($ _GET ['token ' ]) === 50
22+ ){
23+ $ login = new Login ($ _GET ['group ' ], $ _GET ['token ' ]);
24+
25+ if ($ login ->isLoggedIn ()){
26+ $ dataAccess = new DataAccess ($ login , new Share ($ login ));
27+
28+ // parse range
29+ $ rFrom = "" ;
30+ $ rTo = "" ;
31+ if (isset ($ _GET ['range ' ]) && is_string ($ _GET ['range ' ])){
32+ if (strpos ($ _GET ['range ' ], ', ' ) === false ){
33+ $ rFrom = $ _GET ['range ' ];
34+ }
35+ else {
36+ $ parts = explode (', ' , $ _GET ['range ' ]);
37+ $ rFrom = $ parts [0 ];
38+ $ rTo = $ parts [1 ];
39+ }
40+ }
1941
20- if ($ login ->isLoggedIn ()){
21- $ cal = new Calendar ($ login );
42+ // parse devices
43+ $ devices = array ();
44+ if (isset ($ _GET ['devices ' ]) && is_string ($ _GET ['devices ' ])){
45+ $ devices = explode (', ' , $ _GET ['devices ' ]);
46+ }
2247
48+ // set parsed filters
49+ $ dataAccess ->setParams (
50+ $ _GET ['time ' ], $ rFrom , $ rTo ,
51+ $ _GET ['cats ' ] ?? "" , $ _GET ['names ' ] ?? "" , $ devices
52+ );
53+
54+ // add shares
55+ if ( isset ($ _GET ['shares ' ]) && is_string ($ _GET ['shares ' ]) ){
56+ $ dataAccess ->requestShare (explode (', ' , $ _GET ['shares ' ]));
57+ }
58+
59+ if (!$ dataAccess ->hasError () ){
60+ // create calendar
61+ $ cal = new Calendar ($ login );
62+ $ ics = $ cal ->generateICS ($ dataAccess );
63+
64+ // output
65+ header ('Content-type: text/calendar; charset=utf-8 ' );
66+ header ('Content-Disposition: inline; filename=ttt.ics ' );
67+ die ($ ics );
68+ }
69+ else {
70+ // error message
71+ http_response_code (400 );
72+ header ('Content-Type: text/plain; charset=utf-8 ' );
73+ die ("Error – Invalid filter! " );
74+ }
75+ }
2376}
77+
78+ // error message
79+ http_response_code (403 );
80+ header ('Content-Type: text/plain; charset=utf-8 ' );
81+ die ("Error – Failed to authenticate! " );
2482?>
0 commit comments