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: permissions system #86

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix vulnerabilities on the discovery page
leonardolauryel authored and eduardoperetto committed Jan 31, 2023
commit 205a54dc6af3da46e7c5c1cf928d8cb5092e6791
2 changes: 1 addition & 1 deletion modules/base/views/layouts/sidebar-menu.php
Original file line number Diff line number Diff line change
@@ -56,7 +56,7 @@
['label'=>Yii::t('topology','Ports'), 'url'=>['/topology/port'], 'visible'=>RbacController::can('domainTopology/read')],
['label'=>Yii::t('topology','Locations'), 'url'=>['/topology/location'], 'visible'=>RbacController::can('domainTopology/read')],
['label'=>Yii::t('topology','Viewer'), 'url'=>['/topology/viewer'],],
['label'=>Yii::t('topology','Discovery'), 'url'=>['/topology/discovery'], 'visible'=>RbacController::can('domainTopology/read')],
['label'=>Yii::t('topology','Discovery'), 'url'=>['/topology/discovery'], 'visible'=>(RbacController::can('synchronizer/read') || RbacController::can('domainTopology/read'))],
],
],
[
44 changes: 26 additions & 18 deletions modules/topology/controllers/DiscoveryController.php
Original file line number Diff line number Diff line change
@@ -23,8 +23,8 @@
class DiscoveryController extends RbacController {

public function actionIndex() {
if(!self::can('domainTopology/read')){
Yii::$app->getSession()->addFlash('danger', Yii::t('aaa', 'You are not allowed to access Topology Discovery'));
if(!self::can('synchronizer/read') && !self::can('domainTopology/read')) {
Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to access Topology Discovery'));
return $this->goHome();
}

@@ -73,7 +73,12 @@ public function actionIndex() {
));
}

public function actionExecute($rule) {
public function actionExecute($rule) {
if(!self::can('synchronizer/read') && !self::can('domainTopology/read')) {
Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to perform Topology Discovery'));
return $this->goHome();
}

self::beginAsyncAction();

$ds = new DiscoveryService;
@@ -95,8 +100,8 @@ public function actionTask($id) {

public function actionCreateRule() {
if(!self::can('synchronizer/create')){
Yii::$app->getSession()->addFlash('danger', Yii::t('aaa', 'You are not allowed to create rules on Topology Discovery'));
return $this->goHome();
Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to create rules on Topology Discovery'));
return $this->redirect('index');
}
$form = new DiscoveryRuleForm;

@@ -114,6 +119,10 @@ public function actionCreateRule() {
}

public function actionUpdateRule($id) {
if(!self::can('synchronizer/update')) {
Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to update rules on Topology Discovery'));
return $this->redirect('index');
}
$form = DiscoveryRuleForm::loadFromDB($id);

if($form->load($_POST)) {
@@ -130,20 +139,19 @@ public function actionUpdateRule($id) {
}

public function actionDeleteRule() {
if(true){
if(isset($_POST['delete'])){
foreach ($_POST['delete'] as $id) {
$rule = DiscoveryRule::findOne($id);
if ($rule->delete()) {
Yii::$app->getSession()->addFlash('success', Yii::t('topology', 'Rule {name} deleted', ['name'=>$rule->name]));
} else {
Yii::$app->getSession()->setFlash('error', Yii::t('topology', 'Error deleting rule {name}', ['name'=>$rule->name]));
}
}
if(!self::can('synchronizer/delete')) {
Yii::$app->getSession()->addFlash('warning', Yii::t('topology', 'You are not allowed to delete discovery rules'));
return $this->redirect('index');
}

if(isset($_POST['delete'])){
foreach ($_POST['delete'] as $id) {
$rule = DiscoveryRule::findOne($id);
if ($rule->delete())
Yii::$app->getSession()->addFlash('success', Yii::t('topology', 'Rule {name} deleted', ['name'=>$rule->name]));
else
Yii::$app->getSession()->setFlash('error', Yii::t('topology', 'Error deleting rule {name}', ['name'=>$rule->name]));
}
}
else Yii::$app->getSession()->addFlash('warning', Yii::t('topology', 'You are not allowed to delete rules'));

return $this->redirect('index');
}
}
10 changes: 7 additions & 3 deletions modules/topology/messages/pt-BR/topology.php
Original file line number Diff line number Diff line change
@@ -103,9 +103,13 @@
'Network {net} not deleted. You are not allowed to delete on domain {domain}' => 'Rede {net} não foi removida. Você não tem permissão para remover no domínio {domain}',
'You are not allowed to delete on domain {domain}' => 'Você não tem permissão para remover no domínio {domain}',
'You are not allowed to update on domain {domain}' => 'Você não tem permissão para editar no domínio {domain}',
'You are not allowed to add synchronizers' => 'Você não tem permissão para adicionar sincronizadores',
'You are not allowed to update synchronizers' => 'Você não tem permissão para editar sincronizadores',
'You are not allowed to delete synchronizers' => 'Você não tem permissão para remover sincronizadores',

'You are not allowed to access Topology Discovery' => 'Você não tem permissão para acessar a Descoberta de Topologia',
'You are not allowed to create rules on Topology Discovery' => 'Você não tem permissão para criar regras de Descoberta de Topologia',
'You are not allowed to update rules on Topology Discovery' => 'Você não tem permissão para editar regras de Descoberta de Topologia',
'You are not allowed to delete rules on Topology Discovery' => 'Você não tem permissão para remover regras de Descoberta de Topologia',
'You are not allowed to perform Topology Discovery' => 'Você não tem permissão para executar a Descoberta de Topologia',

'Delete Ports' => 'Deletar Portas',
'Add Port' => 'Adicionar Porta',
'Add' => 'Adicionar',