function getBannedIps() { if ($this->request->is('ajax')) { $this->disableCache(); Configure::write('debug', 2); $this->autoRender = false; include APP . 'spacebukkitcall.php'; //Get IP bans $ips = array(); $bip = $api->call('getBannedIPs', array(), false); if (!is_null($bip)) { foreach ($bip as $ip) { $ips[] = array($ip, perm_action('users', 'ban', $this->Session->read("user_perm"), '<span class=\\"button-group"><a href="./tplayers/ipban_del/' . $ip . '" class="button icon danger arrowdown ajax_table4">' . __('Remove') . '</a>')); } } else { $ips = array(array('No Banned IP\'s found!', '')); } echo json_encode(array('aaData' => $ips)); } }
function getWorlds() { if ($this->request->is('ajax')) { $this->disableCache(); Configure::write('debug', 0); $this->autoRender = false; //call API require APP . 'spacebukkitcall.php'; //set clear arguments $args = array(); //get World Management Plugin $wmpl = $this->getWMPL($api->call("getPlugins", $args, false)); //get all worlds $worlds = $api->call("getAllWorlds", $args, true); //get the enabled worlds $loadedWorlds = $api->call("getWorlds", $args, false); //get main worlds $args = array("server.properties"); $config = $api->call("getFileContent", $args, true); //make an array for them $main = array(); $main['NL'] = $this->get_string_between($config, "level-name=", "\n"); $main['NR'] = $main['NL'] . "_nether"; $main['TE'] = $main['NL'] . "_the_end"; //Start the datatable write $num = count($worlds); $i = 1; echo '{ "aaData": ['; foreach ($worlds as $w) { //Call when the world is NOT loaded if (in_array($w, $loadedWorlds) == NULL) { //These variables are the "columns" of the table $online = '<img src=\\"img/disabled.png\\">'; $name = $w; $time = ""; $animals = ""; $hostiles = ""; $pvp = ""; $difficulty = ""; $environment = ""; //if the World Management Plugin is installed, put a load button if ($wmpl != 0) { $load = perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/loadWorld/' . $name . '\\" class=\\"button icon arrowup ajax_table1\\">' . __('Load') . '</a></span>'); } else { $load = ""; } //Call when world is LOADED } else { if (in_array($w, $loadedWorlds) != NULL) { //get world specific information $args = array($w); $worldInfo = $api->call("getWorldInformations", $args, false); $rTime = substr($worldInfo['FormattedTime'], 0, 5); //these variables aren't multiworld dependent so we don't check for that :) //set icon if (in_array($w, $main) == NULL) { $online = '<img src=\\"img/enabled.png\\">'; } else { $online = __('Default'); } //set name variable $name = $worldInfo['Name']; //set environment variable if ($worldInfo['Environment'] == "NORMAL") { $environment = '<img src=\\"img/world_normal.png\\"> Normal'; } else { if ($worldInfo['Environment'] == "NETHER") { $environment = '<img src=\\"img/world_nether.png\\"> Nether'; } else { if ($worldInfo['Environment'] == "THE_END") { $environment = '<img src=\\"img/world_end.png\\"> The End'; } } } //if you use a WMPL if ($wmpl != 0) { //set time column $time = '<span class=\\"button-group\\"><a href=\\"./tworlds/getTime/' . $name . '\\" class=\\"button icon clock fancy\\">' . $rTime . '</a></span>'; //set properties //per WMPL config if ($wmpl == 2) { //animals multiverse if ($worldInfo['AllowAnimals'] == 1) { $animals = '<img src=\\"img/circle_green.png\\"> '; $animals .= perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/worldAnimals/0/' . $name . '\\" class=\\"button icon arrowdown ajax_table1\\">' . __('Disable') . '</a></span>'); } else { $animals = '<img src=\\"img/circle_red.png\\"> '; $animals .= perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/worldAnimals/1/' . $name . '\\" class=\\"button icon arrowup ajax_table1\\">' . __('Enable') . '</a></span>'); } //monsters multiverse if ($worldInfo['AllowMonsters'] == 1) { $hostiles = '<img src=\\"img/circle_green.png\\"> '; $hostiles .= perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/worldHostiles/0/' . $name . '\\" class=\\"button icon arrowdown ajax_table1\\">' . __('Disable') . '</a></span>'); } else { $hostiles = '<img src=\\"img/circle_red.png\\"> '; $hostiles .= perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/worldHostiles/1/' . $name . '\\" class=\\"button icon arrowup ajax_table1\\">' . __('Enable') . '</a></span>'); } } else { if ($wmpl == 1) { //animals MyWorlds if ($worldInfo['AllowAnimals'] == 1) { $animals = '<img src=\\"img/circle_green.png\\">'; } else { $animals = '<img src=\\"img/circle_red.png\\">'; } //hostiles myWorlds if ($worldInfo['AllowMonsters'] == 1) { $hostiles = '<img src=\\"img/circle_green.png\\">'; } else { $hostiles = '<img src=\\"img/circle_red.png\\">'; } } } //set PVP if ($worldInfo['PVP'] == 1) { $pvp = '<img src=\\"img/circle_green.png\\"> '; $pvp .= perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/worldPVP/0/' . $name . '\\" class=\\"button icon arrowdown ajax_table1\\">' . __('Disable') . '</a></span>'); } else { $pvp = '<img src=\\"img/circle_red.png\\"> '; $pvp .= perm_action('worlds', 'changeWorldSettings', $this->Session->read("user_perm"), '<span class=\\"button-group\\"><a href=\\"./tworlds/worldPVP/1/' . $name . '\\" class=\\"button icon arrowup ajax_table1\\">' . __('Enable') . '</a></span>'); } //set difficulty if ($worldInfo['Difficulty'] == "PEACEFUL") { $difficulty = '<img src=\\"img/peaceful.png\\"> <span class=\\"button-group\\"><a href=\\"./tworlds/getWorldDiff/' . $name . '\\" class=\\"button icon edit fancy\\">' . __('Change') . '</a></span>'; } else { if ($worldInfo['Difficulty'] == "EASY") { $difficulty = '<img src=\\"img/easy.png\\"> <span class=\\"button-group\\"><a href=\\"./tworlds/getWorldDiff/' . $name . '\\" class=\\"button icon edit fancy\\">' . __('Change') . '</a></span>'; } else { if ($worldInfo['Difficulty'] == "NORMAL") { $difficulty = '<img src=\\"img/normal.png\\"> <span class=\\"button-group\\"><a href=\\"./tworlds/getWorldDiff/' . $name . '\\" class=\\"button icon edit fancy\\">' . __('Change') . '</a></span>'; } else { if ($worldInfo['Difficulty'] == "HARD") { $difficulty = '<img src=\\"img/hard.png\\"> <span class=\\"button-group\\"><a href=\\"./tworlds/getWorldDiff/' . $name . '\\" class=\\"button icon edit fancy\\">' . __('Change') . '</a></span>'; } } } } //set load button if it's not the main world if (in_array($name, $main) == NULL) { $load = '<a href=\\"./tworlds/unloadWorld/' . $name . '\\" class=\\"button icon arrowdown ajax_table1\\">' . __('Unload') . '</a>'; } else { $load = ""; } } //if you don't use a WMPL if ($wmpl == 0) { //set time column $time = $rTime; //set animals column if ($worldInfo['AllowAnimals'] == 1) { $animals = '<img src=\\"img/circle_green.png\\">'; } else { $animals = '<img src=\\"img/circle_red.png\\">'; } //set monsters column if ($worldInfo['AllowMonsters'] == 1) { $hostiles = '<img src=\\"img/circle_green.png\\">'; } else { $hostiles = '<img src=\\"img/circle_red.png\\">'; } //set pvp column if ($worldInfo['PVP'] == 1) { $pvp = '<img src=\\"img/circle_green.png\\">'; } else { $pvp = '<img src=\\"img/circle_red.png\\">'; } //set difficulty if ($worldInfo['Difficulty'] == "PEACEFUL") { $difficulty = '<img src=\\"img/peaceful.png\\">'; } else { if ($worldInfo['Difficulty'] == "EASY") { $difficulty = '<img src=\\"img/easy.png\\">'; } else { if ($worldInfo['Difficulty'] == "NORMAL") { $difficulty = '<img src=\\"img/normal.png\\">'; } else { if ($worldInfo['Difficulty'] == "HARD") { $difficulty = '<img src=\\"img/hard.png\\">'; } } } } //set load button if it's not the main world if (in_array($name, $main) == NULL) { $load = '<a href=\\"./tworlds/unloadWorld/' . $name . '\\" class=\\"button icon arrowdown ajax_table1\\">' . __('Unload') . '</a>'; } else { $load = ""; } } } } //UNCOMMENT THIS FOR BACKUPS, ETC //$actions = '<center> '.$load.' <span class=\"button-group\"><a href=\"#\" class=\"button icon like ajax_table1\">'.__('Backup').'</a><a href=\"#\" class=\"button icon remove danger ajax_table1\">'.__('Delete!').'</a></span></center>'; $actions = '<center><span class=\\"button-group\\"> ' . $load . '</span> <span class=\\"button-group\\"><a href=\\"./tworlds/deleteWorld/' . $name . '\\" class=\\"button icon remove danger remove\\">' . __('Delete!') . '</a></span></center>'; //send to table echo <<<END [ "{$online}", "{$name}", "{$time}", "{$animals}", "{$hostiles}", "{$pvp}", "{$difficulty}", "{$environment}", "{$actions}" ] END; if ($i < $num) { echo ","; } $i++; } echo '] }'; } }
function getTasks() { if ($this->request->is('ajax')) { $this->disableCache(); Configure::write('debug', 0); $this->autoRender = false; require APP . 'spacebukkitcall.php'; $args = array(); $tasks = $api->call("getTasks", $args, true); $i = 1; $num = count($tasks); echo '{ "aaData": ['; foreach ($tasks as $id => $task) { $argument = $task[1]; if ($task[0] == 1) { $type = __('Backup Worlds'); } elseif ($task[0] == 2) { $type = __('Disable Whitelisting'); } elseif ($task[0] == 3) { $type = __('Enable Whitelisting'); } elseif ($task[0] == 4) { $type = __('Restart Server'); } elseif ($task[0] == 5) { $type = __('Restart Server (if empty)'); } elseif ($task[0] == 6) { $type = __('Save Worlds'); } elseif ($task[0] == 7) { $type = __('Say something'); } elseif ($task[0] == 8) { $type = __('Execute command'); } elseif ($task[0] == 9) { $type = __('Start Server'); } elseif ($task[0] == 10) { $type = __('Stop Server'); } if ($task[2] == 1) { $timeType = __('Every X Hours'); } elseif ($task[2] == 2) { $timeType = __('Every X Minutes'); } elseif ($task[2] == 3) { $timeType = __('Once per day at X:Y'); } elseif ($task[2] == 4) { $timeType = __('At X minutes after every hour'); } $timeArg1 = $task[3]; $timeArg2 = $task[4]; $actions = perm_action('servers', 'Schedules', $this->Session->read("user_perm"), '<a href=\\"./tservers/runTask/' . $task[0] . '/' . $argument . '\\" class=\\"button icon approve ajax_table1\\">' . __('Run now') . '</a><a href=\\"./tservers/removeTask/' . $id . '\\" class=\\"button icon remove danger ajax_table1\\">' . __('Remove') . '</a>'); echo <<<END [ "{$id}", "{$type}", "{$argument}", "{$timeType}", "{$timeArg1} : {$timeArg2}", "{$actions}" ] END; if ($i < $num) { echo ","; } $i++; } echo '] }'; } }
function getBackups($prevAmount = '3,3,3,3') { // ajax function that return a json with the data for previous and scheduled backups ans well as the backup stats if ($this->request->is('ajax')) { $this->disableCache(); Configure::write('debug', 0); $this->autoRender = false; require APP . 'spacebukkitcall.php'; // -------------------------------------------------------------------------------------------------- // | Functions to aid in parsing previous backups! | // -------------------------------------------------------------------------------------------------- function backup_type_count($array) { $types = array('w' => array(), 'p' => array(), 's' => array()); foreach ($array as $key => $backup) { if (preg_match("/World-.*/", $backup[1])) { $types['w'][] = $key; } else { if ($backup[1] == 'Plugins') { $types['p'][] = $key; } else { if ($backup[1] == 'Server') { $types['s'][] = $key; } } } $types['a'] = $array; } return $types; } function time_sort_array($array) { $sorter = array(); $new = array(); foreach ($array as $int => $array2) { $k = intval($array2[3] / 10000); while (array_key_exists($k, $sorter)) { $k++; } $sorter[$k] = $int; } ksort($sorter); foreach ($sorter as $key) { $new[] = $array[$key]; } $new = array_reverse($new); return $new; } // -------------------------------------------------------------------------------------------------- // | Previous Backups | // -------------------------------------------------------------------------------------------------- $tyToWrite = explode(',', $prevAmount); $args = array(); $backups = $api->call('getBackups', $args, true); if (empty($backups)) { $e = 0; } else { $e = count($backups); $backups = array_reverse($backups); //reverse array, newest on top $types = backup_type_count($backups); //Count the backup types $prevOutput = array("a" => '', "w" => '', "p" => '', "s" => ''); $wrote = array("a" => 0, "w" => 0, "p" => 0, "s" => 0); $i = 0; foreach ($backups as $b) { if (preg_match("/World-.*/", $b[1])) { $text = ''; $text .= '<section>'; $wn = explode('-', $b[1]); $text .= '<div class="b-what">' . perm_action('backups', 'restore', $this->Session->read("user_perm"), '<a href="./tbackups/restore/' . $b[0] . '" class="button icon move restore">' . __('Restore') . '</a> ') . $wn[0] . ' "' . $wn[1] . '"</div>'; $text .= '<div class="b-in">' . round($b[3] / 1048576, 2) . __('MB') . '</div>'; $text .= '<div class="b-when">' . date('l, dS F Y \\a\\t H:i', $b[2] / 1000) . '</div>'; $text .= '</section>'; if ($wrote["w"] < $tyToWrite[1]) { $prevOutput["w"] .= $text; $wrote["w"]++; } if ($wrote["a"] < $tyToWrite[0]) { $prevOutput["a"] .= $text; $wrote["a"]++; } } else { if (preg_match("/Plugins/", $b[1])) { $text = ''; $text .= '<section>'; $text .= '<div class="b-what">' . perm_action('backups', 'restore', $this->Session->read("user_perm"), '<a href="./tbackups/restore/' . $b[0] . '" class="button icon move restore">' . __('Restore') . '</a> ') . __('All Plugins') . '</div>'; $text .= '<div class="b-in">' . round($b[3] / 1048576, 2) . __('MB') . '</div>'; $text .= '<div class="b-when">' . date('l, dS F Y \\a\\t H:i', $b[2] / 1000) . '</div>'; $text .= '</section>'; if ($wrote["p"] < $tyToWrite[2]) { $prevOutput["p"] .= $text; $wrote["p"]++; } if ($wrote["a"] < $tyToWrite[0]) { $prevOutput["a"] .= $text; $wrote["a"]++; } } else { if (preg_match("/Server/", $b[1])) { $text = ''; $text .= '<section>'; $text .= '<div class="b-what">' . perm_action('backups', 'restore', $this->Session->read("user_perm"), '<a href="./tbackups/restore/' . $b[0] . '" class="button icon move restore">' . __('Restore') . '</a> ') . __('Complete Server') . '</div>'; $text .= '<div class="b-in">' . round($b[3] / 1048576, 2) . 'MB</div>'; $text .= '<div class="b-when">' . date('l, dS F Y \\a\\t H:i', $b[2] / 1000) . '</div>'; $text .= '</section>'; if ($wrote["s"] < $tyToWrite[3]) { $prevOutput["s"] .= $text; $wrote["s"]++; } if ($wrote["a"] < $tyToWrite[0]) { $prevOutput["a"] .= $text; $wrote["a"]++; } } } } } } if ($e == 0) { $text = ''; $text .= '<section>'; $text .= '<h3>' . __('No backups found!') . '</h3>'; //Name $text .= '</section>'; $prevOutput["a"] = $text; $prevOutput["w"] = $text; $prevOutput["p"] = $text; $prevOutput["s"] = $text; } else { if (count($types["a"]) > $wrote["a"]) { $prevOutput["a"] .= '<section><div class="b-what"><a href="#" class="button icon add" id="updatepa">' . __('More...') . '</a></div><div class="b-in"></div><div class="b-when"></div></section>'; } if (count($types["w"]) > $wrote["w"]) { $prevOutput["w"] .= '<section><div class="b-what"><a href="#" class="button icon add" id="updatepw">' . __('More...') . '</a></div><div class="b-in"></div><div class="b-when"></div></section>'; } else { if ($wrote["w"] == 0) { $prevOutput["w"] .= '<section><h3>No world backups found!</h3></section>'; } } if (count($types["p"]) > $wrote["p"]) { $prevOutput["p"] .= '<section><div class="b-what"><a href="#" class="button icon add" id="updatepp">' . __('More...') . '</a></div><div class="b-in"></div><div class="b-when"></div></section>'; } else { if ($wrote["p"] == 0) { $prevOutput["p"] .= '<section><h3>No plugin backups found!</h3></section>'; } } if (count($types["s"]) > $wrote["s"]) { $prevOutput["s"] .= '<section><div class="b-what"><a href="#" class="button icon add" id="updateps">' . __('More...') . '</a></div><div class="b-in"></div><div class="b-when"></div></section>'; } else { if ($wrote["s"] == 0) { $prevOutput["s"] .= '<section><h3>No server backups found!</h3></section>'; } } } // -------------------------------------------------------------------------------------------------- // | Scheduled Backups | // -------------------------------------------------------------------------------------------------- $args = array(); //$jobs = $api->call('getJobs', $args, true); $schedOutput = ''; $nbackups = array(); foreach ($jobs as $name => $info) { if ($info[0] == 'backup') { $nbackups[$name] = array('type' => $info[1][0][0], 'fold' => $info[1][0][1], 'timeType' => $info[2], 'timeArg' => $info[3]); } } if (empty($nbackups)) { $schedOutput .= '<section>'; $schedOutput .= '<h3>' . __('No scheduled backups found!') . '</h3>'; //Name $schedOutput .= '</section>'; } else { $i = 0; foreach ($nbackups as $bname => $binfo) { if ($i >= 3) { echo ''; } else { if (preg_match("/EVERYXHOURS/", $binfo['timeType'])) { $when = __('Every') . ' ' . $binfo['timeArg'] . ' ' . __('hours'); } else { if (preg_match("/EVERYXMINUTES/", $binfo['timeType'])) { $when = __('Every') . ' ' . $binfo['timeArg'] . ' ' . __('minutes'); } else { if (preg_match("/ONCEPERDAYAT/", $binfo['timeType'])) { $when = __('Once per day at:') . ' ' . $binfo['timeArg']; } else { if (preg_match("/XMINUTESPASTEVERYHOUR/", $binfo['timeType'])) { $when = $binfo['timeArg'] . ' ' . __('minutes past every hour'); } } } } $schedOutput .= '<section>'; $schedOutput .= '<div class="b-what">' . $bname . '</a></div>'; //Name $schedOutput .= '<div class="b-in">' . __('contents') . ': ' . $binfo['type'] . ', ' . __('folder') . ': ' . $binfo['fold'] . '</div>'; //Size $schedOutput .= '<div class="b-when">' . $when . '</div>'; //date $schedOutput .= '</section>'; $i++; } } } $schedOutput .= '<section>'; $schedOutput .= '<div class="b-what"><a href="./tbackups/schedule" class="button icon add fancy" id="schedb">' . __('Schedule backup') . '</a></div>'; //Name $schedOutput .= '<div class="b-in"></div>'; //Size $schedOutput .= '<div class="b-when"></div>'; //date $schedOutput .= '</section>'; // -------------------------------------------------------------------------------------------------- // | Backup information | // -------------------------------------------------------------------------------------------------- $args = array(); $backupInfo = ''; $backups = $api->call('getBackups', $args, true); $bnum = count($backups); $bsize = 0; foreach ($backups as $b) { $bsize += round($b[3] / 1048576, 2); } $backupInfo .= '<section>'; $backupInfo .= '<h3>' . __('Backup count') . ': ' . $bnum . '</h3>'; //Name $backupInfo .= '</section>'; $backupInfo .= '<section>'; $backupInfo .= '<h3>' . __('Total size') . ': ' . round($bsize, 2) . __('MB') . '</h3>'; //Name $backupInfo .= '</section>'; // -------------------------------------------------------------------------------------------------- // | Combine call result | // -------------------------------------------------------------------------------------------------- $result = array("prev" => $prevOutput, "next" => $schedOutput, "info" => $backupInfo); echo json_encode($result); } }
function getPlugin($plugin) { if ($this->request->is('ajax')) { $this->disableCache(); Configure::write('debug', 0); $this->autoRender = false; require APP . 'spacebukkitcall.php'; $args = array($plugin); $plg = $api->call("getPluginInformations", $args, false); if ($plg['IsEnabled'] == 1) { $status = '<img src="img/circle_green.png" />'; } else { $status = '<img src="img/circle_red.png" />'; } if ($plg['Bukget'] == true) { $bukget = '<img src="img/bukget_enabled.png" />'; $pname = $plg["Bukget"]; } else { $bukget = ''; $pname = $plg["Name"]; } $pconf = str_replace(" ", "%20", $plg["Name"]); $authors = implode(', ', $plg['Authors']); if ($pname == "SpaceBukkit" || $pname == "RemoteToolkitPlugin") { $enplg = ''; $remplg = ''; } else { $remplg = perm_action('plugins', 'removeAddPlugin', $this->Session->read("user_perm"), '<a href="./tplugins/remove_plugin/' . $plg["Name"] . '" class="button icon trash dangera jax_table1">' . __('Remove') . '</a>'); if ($plg['IsEnabled'] == 1) { $enplg = perm_action('plugins', 'disablePlugin', $this->Session->read("user_perm"), '<a href="./tplugins/disable_plugin/' . $plg["Name"] . '" class="button icon remove danger ajax_table1">' . __('Disable') . '</a>'); } else { $enplg = perm_action('plugins', 'disablePlugin', $this->Session->read("user_perm"), '<a href="./tplugins/enable_plugin/' . $plg["Name"] . '" class="button icon reload ajax_table1">' . __('Enable') . '</a>'); } } $plgconf = perm_action('plugins', 'configurePlugin', $this->Session->read("user_perm"), '<a href="./tplugins/config/' . $pconf . '" class="button icon fancy edit ">' . __('Configure') . '</a>'); $plgactions = $enplg . $remplg . $plgconf; if ($plg['Website'] != "") { $plginfo = '<a href="' . $plg['Website'] . '" target="_blank" class="button icon home">' . __('Website') . '</a>'; } else { $plginfo = ''; } $description = trim(str_replace('"', '"', str_replace("n", ' ', $plg["Description"]))); $result = array($status . $bukget, $plg["Name"], $plg["Version"], $authors, $description, '<span class="button-group">' . $plgactions . '</span>', '<span class="button-group">' . $plginfo . '</span>'); echo json_encode($result); } }