Skip to content

Commit

Permalink
Fix checking of current IP address by trusted networks list
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Dec 27, 2022
1 parent 3dab349 commit d6ac0d9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
6 changes: 6 additions & 0 deletions controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,15 @@ public function actionIndex()
$this->view->saved();
}

$ip = Yii::$app->request->userIP;
if ($ip !== Yii::$app->request->remoteIP) {
$ip .= ', ' . Yii::$app->request->remoteIP;
}

return $this->render('module', [
'model' => $model,
'defaultDriverName' => TwofaHelper::getDriverByClassName($model->module->defaultDriver)->name,
'ip' => $ip,
]);
}
}
6 changes: 5 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.1.1 (Unreleased)
------------------------
- Fix: Fix checking of current IP address by trusted networks list

1.1.0 (November 9, 2022)
------------------------
- Enh #41: Added Option to use Google Authentication as Default
Expand All @@ -10,7 +14,7 @@ Changelog
---------------------
- Fix #45: Fix remember browser

1.0.6 (Februrary 2, 2022)
1.0.6 (February 2, 2022)
-------------------------
- Enh #36: Update logout url to POST method
- Enh: Added French translations
Expand Down
4 changes: 4 additions & 0 deletions helpers/TwofaHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ public static function isTrusted()
if (BaseIpHelper::inRange(Yii::$app->request->userIP, $trustedNet)) {
return true;
}
if (Yii::$app->request->userIP !== Yii::$app->request->remoteIP &&
BaseIpHelper::inRange(Yii::$app->request->remoteIP, $trustedNet)) {
return true;
}
}

return false;
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"resources/screen2.png",
"resources/screen3.png"
],
"version": "1.1.0",
"version": "1.1.1",
"humhub": {
"minVersion": "1.11"
}
Expand Down
3 changes: 2 additions & 1 deletion views/config/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/**
* @var $model Config
* @var $defaultDriverName string
* @var $ip string
*/

?>
Expand Down Expand Up @@ -47,7 +48,7 @@ class="alert alert-warning"<?= empty($model->enabledDrivers) ? '' : ' style="dis

<?= $form->field($model, 'trustedNetworks')->textarea() ?>
<div class="help-block">
<?= Yii::t('TwofaModule.config', 'List of IPs or subnets to whitelist, currently yours is {0}. Use coma separator to create a list, example: "{0}, {0}, {0}"', [Yii::$app->request->userIP]) ?>
<?= Yii::t('TwofaModule.config', 'List of IPs or subnets to whitelist, currently yours is {0}. Use coma separator to create a list, example: "{0}, {0}, {0}"', [$ip]) ?>
</div>

<?= Button::save()->submit() ?>
Expand Down

0 comments on commit d6ac0d9

Please sign in to comment.