|
3 | 3 | require_once('../other/config.php'); |
4 | 4 |
|
5 | 5 | start_session($cfg); |
| 6 | +$lang = set_language(get_language()); |
6 | 7 |
|
7 | 8 | error_reporting(E_ALL); |
8 | 9 | ini_set("log_errors", 1); |
9 | 10 | set_error_handler("php_error_handling"); |
10 | | -ini_set("error_log", $cfg['logs_path'].'ranksystem.log'); |
| 11 | +ini_set("error_log", $GLOBALS['logfile']); |
11 | 12 |
|
12 | 13 | header("Content-Type: application/json; charset=UTF-8"); |
13 | 14 |
|
|
48 | 49 | $order = (isset($_GET['order']) && strtolower($_GET['order']) == 'desc') ? 'DESC' : 'ASC'; |
49 | 50 | $part = (isset($_GET['part']) && is_numeric($_GET['part']) && $_GET['part'] > 0) ? (($_GET['part'] - 1) * $limit) : 0; |
50 | 51 |
|
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'])) { |
52 | 139 | $sgidname = $all = '----------_none_selected_----------'; |
53 | 140 | $sgid = -1; |
54 | 141 | if(isset($_GET['all'])) $all = 1; |
|
463 | 550 | } else { |
464 | 551 | $json = array( |
465 | 552 | "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 | + ), |
466 | 558 | "groups" => array( |
467 | 559 | "desc" => "Get details about the TeamSpeak servergroups", |
468 | 560 | "usage" => "Use \$_GET parameter 'groups'", |
|
0 commit comments