Skip to content
Merged
Show file tree
Hide file tree
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
Next Next commit
feat: apply whitelist to ratelimit
Signed-off-by: Dorra Jaouad <[email protected]>
  • Loading branch information
DorraJaouad committed May 16, 2025
commit ae220f6ffafabc2520a8562a868c436104ce79db
3 changes: 3 additions & 0 deletions lib/Settings/IPWhitelist.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace OCA\BruteForceSettings\Settings;

use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IAppConfig;
use OCP\AppFramework\Services\IInitialState;
use OCP\IRequest;
use OCP\Security\Bruteforce\IThrottler;
Expand All @@ -24,13 +25,15 @@ public function __construct(
protected IRequest $request,
protected IInitialState $initialState,
protected IThrottler $throttler,
protected IAppConfig $appConfig,
) {
}

public function getForm(): TemplateResponse {
$this->initialState->provideInitialState('remote-address', $this->request->getRemoteAddress());
$this->initialState->provideInitialState('bypass-listed', $this->throttler->isBypassListed($this->request->getRemoteAddress()));
$this->initialState->provideInitialState('delay', $this->throttler->getDelay($this->request->getRemoteAddress()));
$this->initialState->provideInitialState('apply_allowlist_to_ratelimit', $this->appConfig->getAppValueBool('apply_allowlist_to_ratelimit'));

return new TemplateResponse('bruteforcesettings', 'ipwhitelist');
}
Expand Down
22 changes: 22 additions & 0 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
</tbody>
</table>

<NcCheckboxRadioSwitch :model-value="isApplyAllowListToRateLimitEnabled"
:disabled="loading"
type="switch"
@update:model-value="saveApplyAllowListToRateLimit">
{{ t('spreed', 'Apply whitelist to rate limit') }}
</NcCheckboxRadioSwitch>

<h3>{{ t('bruteforcesettings', 'Add a new whitelist') }}</h3>
<div class="whitelist__form">
<NcInputField id="ip"
Expand Down Expand Up @@ -71,6 +78,7 @@ import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import NcNoteCard from '@nextcloud/vue/dist/Components/NcNoteCard.js'
import NcSettingsSection from '@nextcloud/vue/dist/Components/NcSettingsSection.js'
import NcInputField from '@nextcloud/vue/dist/Components/NcInputField.js'
import NcCheckboxRadioSwitch from '@nextcloud/vue/dist/Components/NcCheckboxRadioSwitch.js'

import PlusIcon from 'vue-material-design-icons/Plus.vue'

Expand All @@ -84,6 +92,7 @@ export default {
NcButton,
NcNoteCard,
NcSettingsSection,
NcCheckboxRadioSwitch,
NcInputField,
PlusIcon,
},
Expand All @@ -97,6 +106,8 @@ export default {
remoteAddress: '',
delay: 0,
isBypassListed: false,
isApplyAllowListToRateLimitEnabled: false,
loading: false,
}
},

Expand Down Expand Up @@ -128,6 +139,7 @@ export default {
this.remoteAddress = loadState('bruteforcesettings', 'remote-address', '127.0.0.1')
this.isBypassListed = loadState('bruteforcesettings', 'bypass-listed', false)
this.delay = loadState('bruteforcesettings', 'delay', 0)
this.isApplyAllowListToRateLimitEnabled = loadState('bruteforcesettings', 'apply_allowlist_to_ratelimit', false)

axios.get(generateUrl('apps/bruteforcesettings/ipwhitelist'))
.then((response) => {
Expand Down Expand Up @@ -157,6 +169,16 @@ export default {
showError(t('bruteforcesettings', 'There was an error adding the IP to the whitelist.'))
}
},

saveApplyAllowListToRateLimit(value) {
this.loading = true
OCP.AppConfig.setValue('bruteforcesettings', 'apply_allowlist_to_ratelimit', value ? 1 : 0, {
success: () => {
this.loading = false
this.isApplyAllowListToRateLimitEnabled = value
},
})
},
},
}
</script>
Expand Down