Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix admin permissions #611

Open
wants to merge 3 commits into
base: xgp-3.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ XG Proyect (XGP) is an OGame clone open-source web application framework designe
This is the simplest and easiest way if you're not a technical person. Download and install XG Proyect will be easy! ;)

1. Go to [releases](https://github.com/XGProyect/XG-Proyect-v3.x.x/releases)
2. Look for the last version and then **assets** and finally look for the `.zip` file.
2. Look for the last version and then **assets** and finally look for the `.zip` file
3. Unzip the file, you'll see 2 files and 1 folder.
4. Look for the contents of the `upload` folder, only what's inside this one is needed.
5. Copy the contents of the `upload` folder to the root on your host. There are hidden files in it, be sure that those are copied over also, specially the `.htaccess` file.
Expand Down
5 changes: 0 additions & 5 deletions app/Http/Controllers/Adm/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public function __construct()

public function index(): void
{
// check if the user is allowed to access
if (!Administration::authorization(__CLASS__, (int) $this->user['user_authlevel'])) {
die(Administration::noAccessMessage($this->langs->line('no_permissions')));
}

// build the page
$this->buildPage();
}
Expand Down
6 changes: 6 additions & 0 deletions app/Http/Controllers/Adm/MakerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ private function makeUser(): array
}
}

if ($auth >= $this->user['user_authlevel']) {
$error .= $this->langs->line('mk_user_invalid_auth_level');
$i++;
}

if ($i == 0) {
$this->makerModel->createNewUser($name, $email, $auth, $pass, $galaxy, $system, $planet);

Expand Down Expand Up @@ -355,6 +360,7 @@ private function buildLevelCombo(): array
];

foreach ($ranks as $rank_id) {
if($this->user['user_authlevel'] <= $rank_id) continue;
$user_levels[] = [
'id' => $rank_id,
'name' => $this->langs->language['user_level'][$rank_id],
Expand Down
13 changes: 13 additions & 0 deletions app/Http/Controllers/Adm/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ private function buildPage(): void
// initial data
$this->_user_query = $this->usersModel->getUserDataById($this->_id);

if($this->_user_query['user_authlevel'] > $this->user['user_authlevel']) {
die(Administration::noAccessMessage($this->langs->line('no_permissions')));
}

// save the data
if (isset($_POST['send_data']) && $_POST['send_data']) {
$this->saveData($type);
Expand Down Expand Up @@ -485,6 +489,14 @@ private function saveInfo()
$errors .= $this->langs->line('us_error_authlevel') . '<br />';
}

if ($authlevel != $this->user['user_authlevel'] && $this->user['user_id'] == $this->_user_query['user_id']) {
$errors .= $this->langs->line('us_error_authlevel_yourown') . '<br />';
}

if ($authlevel > $this->user['user_authlevel']) {
$errors .= $this->langs->line('us_error_invalid_auth_level') . '<br />';
}

if ($id_planet <= 0) {
$errors .= $this->langs->line('us_error_idplanet') . '<br />';
}
Expand Down Expand Up @@ -1263,6 +1275,7 @@ private function buildUsersRolesList()
];

foreach ($roles as $role) {
if($this->user['user_authlevel'] < $role) continue;
$roles_list[] = [
'role_id' => $role,
'role_sel' => ($role == $this->_user_query['user_authlevel'] ? 'selected' : ''),
Expand Down
2 changes: 1 addition & 1 deletion app/Libraries/Adm/AdministrationLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function installDirExists()
*/
public static function authorization(string $module, int $user_level)
{
$cleaned_module_name = strtolower(substr(strrchr($module, '\\'), 1));
$cleaned_module_name = substr(strtolower(substr(strrchr($module, '\\'), 1)), 0, -10);
$permissions = new Permissions(Functions::readConfig('admin_permissions'));

return $permissions->isAccessAllowed($cleaned_module_name, $user_level);
Expand Down
1 change: 1 addition & 0 deletions resources/lang/english/adm/maker_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
'mk_user_existing_email' => 'Email already exists<br>',
'mk_user_existing_planet' => 'Planet already exists<br>',
'mk_user_invalid_password' => 'Invalid password. It must contain more than 4 characters<br>',
'mk_user_invalid_auth_level' => 'Invalid level. The user level must be lower than yours<br>',
'mk_user_added' => 'User added with the password: %s',
];
2 changes: 2 additions & 0 deletions resources/lang/english/adm/users_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
'us_error_username' => 'Username empty on already taken',
'us_error_email' => 'Email empty or already taken',
'us_error_authlevel' => 'The user level can not be empty and must be between 0 and 3',
'us_error_authlevel_yourown' => 'You cannot change your user level on your own',
'us_error_invalid_auth_level' => 'Invalid level. The user level must be lower than or equal yours',
'us_error_idplanet' => 'The planet can not be empty',
'us_error_current_planet' => 'The current user planet can not be empty',
'us_error_ally_id' => 'The user alliance can not be empty',
Expand Down
1 change: 1 addition & 0 deletions resources/lang/spanish/adm/maker_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,6 @@
'mk_user_existing_email' => 'El email ingresado ya existe<br>',
'mk_user_existing_planet' => 'El planeta ingresado ya existe<br>',
'mk_user_invalid_password' => 'La clave ingresada no es válida. Debe tener 4 caracteres como mínimo.<br>',
'mk_user_invalid_auth_level' => 'Nivel no válido. El nivel de usuario debe ser inferior al tuyo.<br>',
'mk_user_added' => 'Usuario agregado con la clave: %s',
];
2 changes: 2 additions & 0 deletions resources/lang/spanish/adm/users_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@
'us_error_username' => 'Nombre de usuario vacío o ya existente',
'us_error_email' => 'Email vacío o existente',
'us_error_authlevel' => 'El nivel del usuario no puede estar vacío y debe estar entre 0 y 3',
'us_error_authlevel_yourown' => 'No puedes cambiar tu nivel de usuario por tu cuenta',
'us_error_invalid_auth_level' => 'Nivel no válido. El nivel de usuario debe ser inferior o igual al tuyo',
'us_error_idplanet' => 'El planeta del usuario no puede estar vacío',
'us_error_current_planet' => 'El planeta actual del usuario no puede estar vacío',
'us_error_ally_id' => 'La alianza del usuario no puede estar vacía',
Expand Down