/** * Supprime un fichier de cache * * @param string $key -> Clef du cache à supprimer * @return bool */ public function delete($key) { $out = false; $file = $this->folder . $key . '.json'; if (file_exists($file)) { if (($result = File::delete($file)) !== true) { AdminServ::error($result); } else { $out = true; } } return $out; }
$scoreTeamRed = intval($_POST['ScoreTeamRed']); $scores = array(array('PlayerId' => 0, 'Score' => $scoreTeamBlue), array('PlayerId' => 1, 'Score' => $scoreTeamRed)); if (!$client->query('ForceScores', $scores, true)) { AdminServ::error(); } else { $action = '[Admin] ' . Utils::t('The scores have been modified : $00fblue team $fffhas !scoreTeamBlue and $f00red team $fffhas !scoreTeamRed', array('!scoreTeamBlue' => $scoreTeamBlue, '!scoreTeamRed' => $scoreTeamRed)); if (!$client->query('ChatSendServerMessage', $action)) { AdminServ::error(); } else { AdminServLogs::add('action', $action); } } } else { if (isset($_POST['CancelVote'])) { if (!$client->query('CancelVote')) { AdminServ::error(); } else { Utils::redirection(); } } } } } } } } } } } // Info serveur $data['serverInfo'] = AdminServ::getCurrentServerInfo();
/** * Enregistre les infos sur les équipes * @param array $team1 -> (assoc) array(name, color (0 to 1), country) * @param array $team2 * @return bool */ public static function setTeamInfo($team1, $team2) { global $client; $out = false; if (!$client->query('SetTeamInfo', 'Unused', 0.0, 'World', $team1['name'], (double) $team1['color'], $team1['country'], $team2['name'], (double) $team2['color'], $team2['country'])) { AdminServ::error(); } else { $_SESSION['adminserv']['teaminfo'] = array('team1' => $team1, 'team2' => $team2); $out = true; } return $out; }
AdminServ::error(Utils::t('Connection error: invalid session.')); } } } } else { if (OnlineConfig::ACTIVATE === true) { Utils::redirection(false, './config/'); } else { AdminServ::info(Utils::t('No server available. To add one, configure "config/servers.cfg.php" file.')); } } } else { if (OnlineConfig::ACTIVATE === true && !isset($_GET['error'])) { Utils::redirection(false, './config/'); } else { AdminServ::error(Utils::t('The servers configuration file isn\'t recognized by AdminServ.')); } } } else { if (isset($_SESSION['adminserv']['get_password'])) { AdminServ::info(Utils::t('It\'s your first connection and no server configured. Choose a password to configure your servers.')); } } // HTML if (isset($_GET['error'])) { AdminServ::error($_GET['error']); } else { if (isset($_GET['info'])) { AdminServ::info($_GET['info']); } }
<?php // ENREGISTREMENT if (isset($_POST['savepassword'])) { $current = md5($_POST['changePasswordCurrent']); $new = md5($_POST['changePasswordNew']); if (isset($_SESSION['adminserv']['path'])) { $adminservPath = $_SESSION['adminserv']['path']; } else { $adminservPath = null; } $pathConfig = $adminservPath . 'config/'; if (OnlineConfig::PASSWORD !== $current) { AdminServ::error(Utils::t('The current password doesn\'t match.')); } else { if (($result = AdminServServerConfig::savePasswordConfig($pathConfig . 'adminserv.cfg.php', $new)) !== true) { AdminServ::error(Utils::t('Unable to save password.') . ' (' . $result . ')'); } else { $info = Utils::t('The password has been changed.'); AdminServ::info($info); AdminServLogs::add('action', $info); } } Utils::redirection(false, '?p=' . USER_PAGE); }
$newPath = addslashes($_POST['optionFolderHiddenFieldValue']); if ($newPath == '.') { $newPath = $data['mapsDirectoryPath']; } $newPath .= basename($args['directory']) . '/'; $newPathFromMapsPath = str_replace($data['mapsDirectoryPath'], '', $newPath); if ($newPathFromMapsPath) { $newPathFromMapsPath = '&d=' . $newPathFromMapsPath; } if (($result = Folder::rename($data['mapsDirectoryPath'] . $args['directory'], $newPath)) !== true) { AdminServ::error(Utils::t('Unable to move the folder') . ' : ' . $args['directory'] . ' (' . $result . ')'); } else { AdminServLogs::add('action', 'Move folder: ' . $args['directory'] . ' to ' . $newPathFromMapsPath); Utils::redirection(false, '?p=' . USER_PAGE . $newPathFromMapsPath); } } else { if (isset($_POST['optionFolderHiddenFieldAction']) && $_POST['optionFolderHiddenFieldAction'] == 'delete') { if (($result = Folder::delete($data['mapsDirectoryPath'] . $args['directory'])) !== true) { AdminServ::error(Utils::t('Unable to delete the folder') . ' : ' . $args['directory'] . ' (' . $result . ')'); } else { // Clean cache $cache = new AdminServCache(); $cacheKey = 'mapslist-' . Str::replaceChars($data['mapsDirectoryPath'] . $args['directory']); $cache->delete($cacheKey); AdminServLogs::add('action', 'Delete folder: ' . $args['directory']); Utils::redirection(false, '?p=' . USER_PAGE); } } } } }
<?php // SESSION if (!isset($_SESSION['adminserv']['allow_config_servers'])) { AdminServ::error(Utils::t('You are not allowed to configure the servers')); Utils::redirection(); } // VERIFICATION if (class_exists('ServerConfig')) { // Si on n'autorise pas la configuration en ligne if (OnlineConfig::ACTIVATE !== true) { AdminServ::info(Utils::t('No server available. To add one, configure "config/servers.cfg.php" file.')); Utils::redirection(); } elseif (USER_PAGE != 'config-addserver') { if (OnlineConfig::ADD_ONLY === true) { Utils::redirection(false, './?p=addserver'); } } } else { AdminServ::error(Utils::t('The servers configuration file isn\'t recognized by AdminServ.')); Utils::redirection(); }
/** * Inclue les fichiers pour le rendu d'un plugin * * @param string $pluginName -> Le nom du dossier plugin * @return html */ public static function renderPlugin($pluginName = null) { global $client, $translate, $args; if ($pluginName === null) { $pluginName = USER_PLUGIN; } // Tente de récupérer les plugins d'une autre config self::setPluginsList(); // Création du rendu du plugin $pluginPath = AdminServConfig::$PATH_PLUGINS . $pluginName . '/'; $scriptFile = $pluginPath . 'script.php'; $viewFile = $pluginPath . 'view.php'; if (file_exists($scriptFile) && file_exists($viewFile)) { // Process require_once $scriptFile; // Terminate client if (isset($client) && $client->socket != null) { $client->Terminate(); } // Header AdminServUI::getHeader(); // Content echo '<section class="plugins hasMenu">' . '<section class="cadre left menu">' . self::getMenuList() . '</section>' . '<section class="cadre right">' . '<h1>' . self::getConfig($pluginName, 'name') . '</h1>'; require_once $viewFile; echo '</section>' . '</section>'; // Footer AdminServUI::getFooter(); AdminServLogs::add('access', 'Plugin: ' . $pluginName); } else { AdminServ::error(Utils::t('Plugin error: script.php or view.php file is missing.')); AdminServUI::getHeader(); AdminServUI::getFooter(); } }
// SET $setServerData = array('name' => trim(htmlspecialchars(addslashes($_POST['server'][0] . ' - ' . Utils::t('copy')))), 'address' => trim($getServerData['address']), 'port' => intval($getServerData['port']), 'matchsettings' => trim($getServerData['matchsettings']), 'adminlevel' => array('SuperAdmin' => $getServerData['adminlevel']['SuperAdmin'], 'Admin' => $getServerData['adminlevel']['Admin'], 'User' => $getServerData['adminlevel']['User'])); if (AdminServServerConfig::saveServerConfig($setServerData)) { $action = Utils::t('This server has been duplicated.'); AdminServ::info($action); AdminServLogs::add('action', $action); Utils::redirection(false, '?p=' . USER_PAGE); } else { AdminServ::error(Utils::t('Unable to duplicate server.')); } } // SUPPRESSION if (isset($_POST['deleteserver'])) { $servers = ServerConfig::$SERVERS; unset($servers[$_POST['server'][0]]); if (($result = AdminServServerConfig::saveServerConfig(array(), -1, $servers)) !== true) { AdminServ::error(Utils::t('Unable to delete server.') . ' (' . $result . ')'); } else { $action = Utils::t('The "!serverName" server has been deleted.', array('!serverName' => $_POST['server'][0])); AdminServ::info($action); AdminServLogs::add('action', $action); Utils::redirection(false, '?p=' . USER_PAGE); } } // SERVERLIST $data['servers'] = array(); if (is_array(ServerConfig::$SERVERS) && !empty(ServerConfig::$SERVERS)) { $data['servers'] = ServerConfig::$SERVERS; } $data['count'] = count($data['servers']); $data['adminLevelsType'] = AdminServAdminLevel::getDefaultType();
foreach ($_POST['matchset'] as $matchset) { if (!$client->query('InsertPlaylistFromMatchSettings', $data['mapsDirectoryPath'] . $matchset)) { AdminServ::error(); } else { AdminServLogs::add('action', 'Insert playlist from matchsettings: ' . $matchset); } } Utils::redirection(false, '?p=' . USER_PAGE . $data['hasDirectory']); } else { if (isset($_POST['editMatchset']) && isset($_POST['matchset']) && count($_POST['matchset']) > 0) { AdminServLogs::add('action', 'Edit matchsettings: ' . $_POST['matchset'][0]); // Redirection sur la page de création d'un matchsettings Utils::redirection(false, '?p=maps-creatematchset' . $data['hasDirectory'] . '&f=' . $_POST['matchset'][0]); } else { if (isset($_POST['deleteMatchset']) && isset($_POST['matchset']) && count($_POST['matchset']) > 0) { foreach ($_POST['matchset'] as $matchset) { if (!File::delete($data['mapsDirectoryPath'] . $matchset)) { AdminServ::error(Utils::t('Unable to delete the playlist') . ' : ' . $matchset); } else { AdminServLogs::add('action', 'Delete matchsettings: ' . $matchset); } } Utils::redirection(false, '?p=' . USER_PAGE . $data['hasDirectory']); } } } } } } // MATCH SETTINGS LIST $data['matchsettingsList'] = AdminServ::getLocalMatchSettingList($data['currentDir'], $args['directory']);
/** * Récupère la liste des dossiers du répertoire "Maps" * * @require class "Folder" * * @param string $path -> Le chemin du dossier "Maps" * @param string $currentPath -> Le chemin à partir de "Maps" * @param bool $showOptions -> Afficher les options (nouveau, renommer, déplacer, supprimer) * @return template maps-directorylist */ public static function getMapsDirectoryList($directory, $currentPath = null, $showOptions = true) { global $data; if (class_exists('Folder')) { $data += array('folders' => array(), 'currentPath' => $currentPath, 'parentPath' => null, 'showOptions' => $showOptions); // Liste des dossiers if (is_array($directory)) { // Dossier parent if ($currentPath) { $params = null; $parentPathEx = explode('/', $currentPath); array_pop($parentPathEx); array_pop($parentPathEx); if (!empty($parentPathEx)) { $parentPath = null; foreach ($parentPathEx as $part) { $parentPath .= $part . '/'; } $data['parentPath'] = $parentPath; } } // Dossiers if (!empty($directory['folders'])) { $data['folders'] = $directory['folders']; } // Template self::getTemplate('maps-directorylist'); } else { AdminServ::error($directory); } } else { AdminServ::error('Class "Folder" not exists'); } }
// GAMEDATA if (AdminServAdminLevel::isType('Admin')) { if (!$client->query('GameDataDirectory')) { AdminServ::error(); } else { $gameDataDirectory = $client->getResponse(); define('IS_LOCAL', file_exists($gameDataDirectory)); if (IS_LOCAL) { $srvConfigDirectory = $gameDataDirectory . 'Config/'; $srvoptsConfigDirectory = $srvConfigDirectory . 'AdminServ/ServerOptions/'; if (!Utils::isWinServer()) { AdminServ::checkRights(array($srvConfigDirectory => 777)); } if (!file_exists($srvoptsConfigDirectory)) { if (($result = Folder::create($srvoptsConfigDirectory)) !== true) { AdminServ::error(Utils::t('Unable to create the folder') . ' : ' . $srvoptsConfigDirectory . ' (' . $result . ')'); } } $data['srvoptsConfigFiles'] = Folder::read($srvoptsConfigDirectory, array(), array(), intval(AdminServConfig::RECENT_STATUS_PERIOD * 3600)); } } } // ENREGISTREMENT if (isset($_POST['savesrvopts'])) { // Récupération des données $struct = AdminServ::getServerOptionsStruct(); $ChangeAuthPassword = null; if (isset($_POST['ChangeAuthPassword']) && $_POST['ChangeAuthPassword'] != null) { $ChangeAuthLevel = $_POST['ChangeAuthLevel']; $ChangeAuthPassword = trim($_POST['ChangeAuthPassword']); }
$struct['scriptsettings'][] = array('name' => $param['Name'], 'type' => $param['Type'], 'value' => $param['Default']); } } } // Maps $struct['startindex'] = 1; $maps = $_SESSION['adminserv']['matchset_maps_selected']['lst']; if (isset($maps) && is_array($maps) && !empty($maps)) { $mapsField = SERVER_VERSION_NAME == 'TmForever' ? 'challenge' : 'map'; foreach ($maps as $id => $values) { $struct[$mapsField][$values['UId']] = $values['FileName']; } } // Enregistrement if (($result = AdminServ::saveMatchSettings($filename, $struct)) !== true) { AdminServ::error(Utils::t('Unable to save the MatchSettings') . ' : ' . $matchSettingName . ' (' . $result . ')'); } else { $action = Utils::t('The MatchSettings "!matchSettingName" was successfully created in the folder', array('!matchSettingName' => $matchSettingName)) . ' : ' . $data['mapsDirectoryPath'] . $args['directory']; AdminServ::info($action); AdminServLogs::add('action', $action); Utils::redirection(false, '?p=' . USER_PAGE . $hasDirectory); } } else { if (!isset($_GET['f'])) { unset($_SESSION['adminserv']['matchset_maps_selected']); } } // LECTURE $data['directoryList'] = Folder::getArborescence($data['mapsDirectoryPath'], AdminServConfig::$MAPS_HIDDEN_FOLDERS, substr_count($data['mapsDirectoryPath'], '/')); $data['matchSettings'] = array(); // Édition
$setLevelData = array('name' => trim(htmlspecialchars(addslashes($_POST['level'][0] . ' - ' . Utils::t('copy')))), 'adminlevel' => $getLevelData['adminlevel'], 'access' => $getLevelData['access'], 'permission' => $getLevelData['permission']); if (AdminServAdminLevel::saveConfig($setLevelData)) { $action = Utils::t('This admin level has been duplicated.'); AdminServ::info($action); AdminServLogs::add('action', $action); Utils::redirection(false, '?p=' . USER_PAGE); } else { AdminServ::error(Utils::t('Unable to duplicate admin level.')); } } // SUPPRESSION if (isset($_POST['deletelevel'])) { $levels = AdminLevelConfig::$ADMINLEVELS; unset($levels[$_POST['level'][0]]); if (($result = AdminServAdminLevel::saveConfig(array(), -1, $levels)) !== true) { AdminServ::error(Utils::t('Unable to delete admin level.') . ' (' . $result . ')'); } else { $action = Utils::t('The "!levelName" admin level has been deleted.', array('!levelName' => $_POST['level'][0])); AdminServ::info($action); AdminServLogs::add('action', $action); Utils::redirection(false, '?p=' . USER_PAGE); } } // LEVELLIST $data['levels'] = array(); if (AdminServAdminLevel::hasLevel()) { foreach (AdminLevelConfig::$ADMINLEVELS as $levelName => $levelData) { $data['levels'][] = array('name' => $levelName, 'type' => $levelData['adminlevel']['type'], 'allowed_access' => count($levelData['access']) . ' ' . Utils::t('authorized access'), 'allowed_permissions' => count($levelData['permission']) . ' ' . Utils::t('authorized permissions')); } } $data['count'] = count($data['levels']);