Compare commits

...

6 Commits

Author SHA1 Message Date
beu
a42c12ace8 remove map from the playlist when erasing map file 2025-06-22 11:47:22 +02:00
beu
a769fec577 improve logging 2025-06-22 11:45:44 +02:00
beu
271395edfa improve logging 2025-06-22 11:45:37 +02:00
beu
aefff423f7 check permission to prevent CustomEvent injection 2025-06-22 11:45:02 +02:00
beu
827e59ff93 fix error if admin is null 2025-06-22 11:10:12 +02:00
beu
f15fc201d2 Add logging when an admin change a setting 2025-06-22 10:41:45 +02:00
7 changed files with 49 additions and 14 deletions

View File

@ -618,6 +618,7 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
// Trigger own callback // Trigger own callback
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTING_CHANGED, $settingName, $settingValue); $this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTING_CHANGED, $settingName, $settingValue);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the gamemode setting "'. $settingName .'" to "'. $settingValue .'"');
$settingIndex++; $settingIndex++;
} }
@ -627,7 +628,6 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
$chatMessage .= '!'; $chatMessage .= '!';
$this->maniaControl->getChat()->sendInformation($chatMessage); $this->maniaControl->getChat()->sendInformation($chatMessage);
Logger::logInfo($chatMessage, true);
return true; return true;
} }

View File

@ -15,6 +15,7 @@ use FML\Script\Script;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager; use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use ManiaControl\Settings\Setting; use ManiaControl\Settings\Setting;
@ -528,6 +529,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$setting->value = $settingData['Value']; $setting->value = $settingData['Value'];
} }
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the setting "'. $setting->class . '\\\\' . $setting->setting .'" to "'. $setting->value .'"');
} }
$this->maniaControl->getChat()->sendSuccess('Settings saved!', $player); $this->maniaControl->getChat()->sendSuccess('Settings saved!', $player);

View File

@ -15,6 +15,7 @@ use FML\Controls\Quads\Quad_UIConstruction_Buttons;
use FML\Controls\Quads\Quad_UIConstructionBullet_Buttons; use FML\Controls\Quads\Quad_UIConstructionBullet_Buttons;
use FML\ManiaLink; use FML\ManiaLink;
use FML\Script\Features\Paging; use FML\Script\Features\Paging;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Files\AsyncHttpRequest; use ManiaControl\Files\AsyncHttpRequest;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
use ManiaControl\Logger; use ManiaControl\Logger;
@ -483,6 +484,11 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function handleAddFile(array $actionCallback, Player $player) { public function handleAddFile(array $actionCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$actionName = $actionCallback[1][2]; $actionName = $actionCallback[1][2];
$fileName = base64_decode(substr($actionName, strlen(self::ACTION_ADD_FILE))); $fileName = base64_decode(substr($actionName, strlen(self::ACTION_ADD_FILE)));
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH); $folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
@ -529,7 +535,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$map $map
); );
$this->maniaControl->getChat()->sendSuccess($message); $this->maniaControl->getChat()->sendSuccess($message);
Logger::logInfo($message, true); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') added the map file "'. $filePath .'"');
// Queue requested Map // Queue requested Map
$this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($player, $map); $this->maniaControl->getMapManager()->getMapQueue()->addMapToMapQueue($player, $map);
@ -542,16 +548,33 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function handleEraseFile(array $actionCallback, Player $player) { public function handleEraseFile(array $actionCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$actionName = $actionCallback[1][2]; $actionName = $actionCallback[1][2];
$fileName = base64_decode(substr($actionName, strlen(self::ACTION_ERASE_FILE))); $fileName = base64_decode(substr($actionName, strlen(self::ACTION_ERASE_FILE)));
$folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH); $folderPath = $player->getCache($this, self::CACHE_FOLDER_PATH);
$filePath = $folderPath . $fileName; $filePath = $folderPath . $fileName;
$maps = $this->maniaControl->getMapManager()->getMaps();
$mapsFolder = $this->maniaControl->getServer()->getDirectory()->getMapsFolder();
$filteredMaps = array_filter($maps, function ($item) use ($mapsFolder, $filePath) {
return ($mapsFolder . $item->fileName === $filePath);
});
foreach ($filteredMaps as $map) {
Logger::log('Map "'. $filePath .'" loaded by the server, removing it from the playlist before erasing the file');
$this->maniaControl->getMapManager()->removeMap($player, $map->uid);
}
if (@unlink($filePath)) { if (@unlink($filePath)) {
$message = $this->maniaControl->getChat()->formatMessage( $message = $this->maniaControl->getChat()->formatMessage(
'Erased %s!', 'Erased %s!',
$fileName $fileName
); );
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') erased the map file "'. $filePath .'"');
$this->showManiaLink($player); $this->showManiaLink($player);
} else { } else {
$message = $this->maniaControl->getChat()->formatMessage( $message = $this->maniaControl->getChat()->formatMessage(
@ -569,6 +592,11 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
* @param Player $player * @param Player $player
*/ */
public function handleCreateFolder(array $actionCallback, Player $player) { public function handleCreateFolder(array $actionCallback, Player $player) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$name = trim($actionCallback[1][3][0]["Value"]); $name = trim($actionCallback[1][3][0]["Value"]);
var_dump($actionCallback); var_dump($actionCallback);
@ -578,13 +606,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (mkdir($folderPath . $name, 755, true)) { if (mkdir($folderPath . $name, 755, true)) {
$message = "Successfully created directory ". $name; $message = "Successfully created directory ". $name;
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log($message . " by " . $player->nickname); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') created the folder "'. $folderPath .'"');
$this->showManiaLink($player, $name); $this->showManiaLink($player, $name);
} else { } else {
$message = "Failed to create directory ". $name; $message = "Failed to create directory ". $name;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message . " by " . $player->nickname); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when creating the folder "'. $folderPath .'".');
$this->showManiaLink($player); $this->showManiaLink($player);
} }
@ -607,7 +635,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (!$file || $error) { if (!$file || $error) {
$message = "Impossible to download the file: " . $error; $message = "Impossible to download the file: " . $error;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error during the download of the zip file "'. $url .'": '. $error);
return; return;
} }
$filePath = ""; $filePath = "";
@ -625,13 +653,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if ($open === true) { if ($open === true) {
$zip->extractTo($folderPath); $zip->extractTo($folderPath);
$zip->close(); $zip->close();
$message = "Succesfully extracted zip archive from ". $url; $message = "Successfully extracted zip archive from ". $url;
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log($message . " by " . $player->nickname); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') downloaded the zip file "'. $url .'"');
} else { } else {
$message = "Cannot extract archive from ". $url; $message = "Cannot extract archive from ". $url;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message . " by " . $player->nickname); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloading the zip file "'. $url .'": Cannot extract the archive');
} }
// Clean up the temporary file // Clean up the temporary file
unlink($tempFile); unlink($tempFile);
@ -691,7 +719,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (!$this->isMapFileName($filePath)) { if (!$this->isMapFileName($filePath)) {
$message = "File is not a map: " . $fileName; $message = "File is not a map: " . $fileName;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloadeding the map file "'. $fileName .'": File is not a map');
return; return;
} }
} else { } else {
@ -718,13 +746,13 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Failed to write file " . $filePath; $message = "Failed to write file " . $filePath;
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
Logger::logError($message . " by " . $player->nickname); Logger::logError(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') encountered an error when downloadeding the map file "'. $fileName .'": Failed to write the file');
return; return;
} }
$message = "Succesfully downloaded the map ". $fileName; $message = "Successfully downloaded the map ". $fileName;
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
Logger::log($message . " by " . $player->nickname); Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') downloaded the map file "'. $filePath .'"');
} }
} }

View File

@ -195,7 +195,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
* @param string $uid * @param string $uid
*/ */
public function updateMap($admin, $uid) { public function updateMap($admin, $uid) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_ADD_MAP)) return; if ($admin !== null && !$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_ADD_MAP)) return;
$this->updateMapTimestamp($uid); $this->updateMapTimestamp($uid);
@ -274,7 +274,7 @@ class MapManager implements CallbackListener, CommunicationListener, UsageInform
* @return bool * @return bool
*/ */
public function removeMap($admin, $uid, $eraseFile = false, $message = true) { public function removeMap($admin, $uid, $eraseFile = false, $message = true) {
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_REMOVE_MAP)) return; if ($admin !== null && !$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_REMOVE_MAP)) return;
if (!isset($this->maps[$uid])) { if (!isset($this->maps[$uid])) {
if ($admin) { if ($admin) {

View File

@ -636,6 +636,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$setting->value = $settingData['Value']; $setting->value = $settingData['Value'];
} }
$this->maniaControl->getSettingManager()->saveSetting($setting); $this->maniaControl->getSettingManager()->saveSetting($setting);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the setting "'. $setting->class . '\\\\' . $setting->setting .'" to "'. $setting->value .'"');
} }
$this->maniaControl->getChat()->sendSuccess('Plugin Settings saved!', $player); $this->maniaControl->getChat()->sendSuccess('Plugin Settings saved!', $player);

View File

@ -418,6 +418,7 @@ class ServerOptionsMenu implements CallbackListener, ConfiguratorMenu, TimerList
$success = $this->applyNewServerOptions($newServerOptions, $player); $success = $this->applyNewServerOptions($newServerOptions, $player);
if ($success) { if ($success) {
$this->maniaControl->getChat()->sendSuccess('Server Options saved!', $player); $this->maniaControl->getChat()->sendSuccess('Server Options saved!', $player);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed Server Options');
} else { } else {
$this->maniaControl->getChat()->sendError('Server Options saving failed!', $player); $this->maniaControl->getChat()->sendError('Server Options saving failed!', $player);
} }

View File

@ -10,6 +10,7 @@ use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Configurator\ConfiguratorMenu; use ManiaControl\Configurator\ConfiguratorMenu;
use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Players\Player; use ManiaControl\Players\Player;
use Maniaplanet\DedicatedServer\Structures\VoteRatio; use Maniaplanet\DedicatedServer\Structures\VoteRatio;
@ -166,6 +167,7 @@ class VoteRatiosMenu implements CallbackListener, ConfiguratorMenu, TimerListene
$success = $this->maniaControl->getClient()->setCallVoteRatios($newVoteRatios); $success = $this->maniaControl->getClient()->setCallVoteRatios($newVoteRatios);
if ($success) { if ($success) {
$this->maniaControl->getChat()->sendSuccess('Vote Ratios saved!', $player); $this->maniaControl->getChat()->sendSuccess('Vote Ratios saved!', $player);
Logger::log(AuthenticationManager::getAuthLevelName($player->authLevel) .' "'. $player->nickname . '" ('. $player->login .') changed the Vote Ratios');
} else { } else {
$this->maniaControl->getChat()->sendError('Vote Ratios saving failed!', $player); $this->maniaControl->getChat()->sendError('Vote Ratios saving failed!', $player);
} }