33require_once ('../other/config.php ' );
44
55start_session ($ cfg );
6+ $ lang = set_language (get_language ());
67
78error_reporting (E_ALL );
89ini_set ("log_errors " , 1 );
910set_error_handler ("php_error_handling " );
10- ini_set ("error_log " , $ cfg [ ' logs_path ' ]. ' ranksystem.log ' );
11+ ini_set ("error_log " , $ GLOBALS [ ' logfile ' ] );
1112
1213header ("Content-Type: application/json; charset=UTF-8 " );
1314
4849$ order = (isset ($ _GET ['order ' ]) && strtolower ($ _GET ['order ' ]) == 'desc ' ) ? 'DESC ' : 'ASC ' ;
4950$ part = (isset ($ _GET ['part ' ]) && is_numeric ($ _GET ['part ' ]) && $ _GET ['part ' ] > 0 ) ? (($ _GET ['part ' ] - 1 ) * $ limit ) : 0 ;
5051
51- if (isset ($ _GET ['groups ' ])) {
52+ if (isset ($ _GET ['bot ' ])) {
53+ if (!isset ($ _GET ['check ' ]) && !isset ($ _GET ['restart ' ]) && !isset ($ _GET ['start ' ]) && !isset ($ _GET ['stop ' ])) {
54+ $ json = array (
55+ "usage " => array (
56+ "_desc " => array (
57+ "0 " => "You are able to use bot commands with this function (start, stop, ..). " ,
58+ "1 " => "Use the Parameter, which are described below! " ,
59+ "2 " => "" ,
60+ "3 " => "Return values are: " ,
61+ "4 " => "- 'rc' " ,
62+ "5 " => "- 'msg' " ,
63+ "6 " => "- 'ranksystemlog' " ,
64+ "7 " => "" ,
65+ "8 " => "# RC " ,
66+ "9 " => "The return Code of the transaction (i.e. start process): " ,
67+ "10 " => "0 - EXIT_SUCCESS " ,
68+ "11 " => "1 - EXIT_FAILURE " ,
69+ "12 " => "" ,
70+ "13 " => "# MSG " ,
71+ "14 " => "An additional message of the process. In case of EXIT_FAILURE, you will receive here an error message. " ,
72+ "15 " => "" ,
73+ "16 " => "# RANKSYSTEMLOG " ,
74+ "17 " => "A short log extract of the last rows of the Ranksystem logfile to get more information about the Bot itself. " ,
75+ ),
76+ "check " => array (
77+ "desc " => "Check the Ranksystem Bot is running. If not, it will be started with this. " ,
78+ "usage " => "Use \$_GET parameter 'check' without any value " ,
79+ "example " => "/api/?bot&check "
80+ ),
81+ "restart " => array (
82+ "desc " => "Restarts the Ranksystem Bot. " ,
83+ "usage " => "Use \$_GET parameter 'restart' without any value " ,
84+ "example " => "/api/?bot&restart "
85+ ),
86+ "start " => array (
87+ "desc " => "Starts the Ranksystem Bot. " ,
88+ "usage " => "Use \$_GET parameter 'start' without any value " ,
89+ "example " => "/api/?bot&start "
90+ ),
91+ "stop " => array (
92+ "desc " => "Stops the Ranksystem Bot " ,
93+ "usage " => "Use \$_GET parameter 'stop' without any value " ,
94+ "example " => "/api/?bot&stop "
95+ )
96+ )
97+ );
98+ } else {
99+ $ check_permission = 0 ;
100+ foreach ($ cfg ['stats_api_keys ' ] as $ apikey => $ desc ) {
101+ if (hash_equals ($ apikey , $ _GET ['apikey ' ]) && $ desc ['perm_bot ' ] == 1 ) {
102+ $ check_permission = 1 ;
103+ break ;
104+ }
105+ }
106+ if ($ check_permission == 1 ) {
107+ if (isset ($ _GET ['check ' ])) {
108+ $ result = bot_check ();
109+ } elseif (isset ($ _GET ['restart ' ])) {
110+ $ result = bot_restart ();
111+ } elseif (isset ($ _GET ['start ' ])) {
112+ $ result = bot_start ();
113+ } elseif (isset ($ _GET ['stop ' ])) {
114+ $ result = bot_stop ();
115+ }
116+ if (isset ($ result ['log ' ]) && $ result ['log ' ] != NULL ) {
117+ $ ranksystemlog = $ result ['log ' ];
118+ } else {
119+ $ ranksystemlog = "NULL " ;
120+ }
121+ $ json = array (
122+ "rc " => $ result ['rc ' ],
123+ "msg " => $ result ['msg ' ],
124+ "ranksystemlog " => $ ranksystemlog
125+ );
126+ } else {
127+ $ json = array (
128+ "Error " => array (
129+ "invalid " => array (
130+ "permissions " => "API Key is not permitted to start/stop the Ranksystem Bot "
131+ )
132+ )
133+ );
134+ echo json_encode ($ json );
135+ exit ;
136+ }
137+ }
138+ } elseif (isset ($ _GET ['groups ' ])) {
52139 $ sgidname = $ all = '----------_none_selected_---------- ' ;
53140 $ sgid = -1 ;
54141 if (isset ($ _GET ['all ' ])) $ all = 1 ;
463550} else {
464551 $ json = array (
465552 "usage " => array (
553+ "bot " => array (
554+ "desc " => "Use this to trigger Bot commands as starting or stopping the Ranksystem Bot. " ,
555+ "usage " => "Use \$_GET parameter 'bot' " ,
556+ "example " => "/api/?bot "
557+ ),
466558 "groups " => array (
467559 "desc " => "Get details about the TeamSpeak servergroups " ,
468560 "usage " => "Use \$_GET parameter 'groups' " ,
493585}
494586
495587echo json_encode ($ json );
496- ?>
588+ ?>
0 commit comments