Skip to content

Instantly share code, notes, and snippets.

View PatrickKalkman's full-sized avatar

Patrick Kalkman PatrickKalkman

View GitHub Profile
:nextAppService Foreach ($appService in $allAppServices)
{
$appServiceName = $appService.Name
Foreach ($appServiceToExclude in $AppServicesToExclude)
{
if($appServiceToExclude.ToLower().Contains($appServiceName.ToLower()))
{
Write-Output "Skipped app service $appServiceName as it is in the exclude list"
continue nextAppService
function Add-AccessRestrictionsToAppServices([string] $ResourceGroupName,
[string] $JsonFilename,
[bool] $RemoveExistingRules,
[string[]] $AppServicesToExclude)
{
Write-Information "Retrieving all app services in $ResourceGroupName"
$allAppServices = Get-AzWebApp -ResourceGroupName $ResourceGroupName
$confirmAppServicesToExclude = Confirm-AppServicesToExclude -AllAppServices $allAppServices -AppServicesToExclude $AppServicesToExclude
if (!$confirmAppServicesToExclude)
@PatrickKalkman
PatrickKalkman / rules.json
Created January 21, 2022 09:25
A file with rules to set as access restrictions on app services
[
{ "rulename": "gateway", "ipaddress": "213.46.145.111", "priority": "200" },
{ "rulename": "vpn", "ipaddress": "210.46.145.111", "priority": "300" },
{ "rulename": "test", "ipaddress": "215.46.145.111", "priority": "400" }
]
<#
.SYNOPSIS
Remove all access restrictions from the app services in the given resource group
.DESCRIPTION
The Remove-AccessRestrictions.ps1 script removes all access restrictions from
the app services in the given resource group
.PARAMETER resourceGroupName
The resource group with the app services to remove the access restrictions
function Remove-AccessRestrictionsFromAppService([string] $ResourceGroupName, [string] $Name) {
$config = Get-AzWebAppAccessRestrictionConfig -ResourceGroupName $ResourceGroupName -Name $Name
Write-Information "Removing existing access restrictions on $Name"
Foreach ($accessRestriction in $config.MainSiteAccessRestrictions) {
$ruleName = $accessRestriction.RuleName
Write-Debug "Removing rule $ruleName"
Remove-AzWebAppAccessRestrictionRule -ResourceGroupName $ResourceGroupName -WebAppName $Name -Name $accessRestriction.RuleName
}
# Also remove all the access restriction from the staging slots
function Remove-AllAccessRestrictionsFromAppServices([string] $ResourceGroupName) {
Write-Information "Retrieving all app services in $ResourceGroupName"
$allAppServices = Get-AzWebApp -ResourceGroupName $ResourceGroupName
Foreach ($appService in $allAppServices) {
Remove-AccessRestrictionsFromAppService -ResourceGroupName $ResourceGroupName -Name $appService.Name
}
}
@PatrickKalkman
PatrickKalkman / two-factor-registration.js
Created January 16, 2022 15:25
Enable two factor authentication temple
<template>
<div>
<h3>Two Factor Registration</h3>
<img v-bind:src="qr" />
<form @submit.prevent="validateToken">
<label for="token">
Enter token to enable two factor authentication:
</label>
<input v-model="token" type="text" name="token" value />
<button type="submit" name="button">validate</button>
@PatrickKalkman
PatrickKalkman / store-validate-token.js
Created January 15, 2022 14:42
The validate token method in the Vuex store
validateToken({ commit }, credentials) {
return apiClient
.post('/user/validatetoken', credentials)
.then(({ data }) => {
commit('SET_TWOFACTOR_LOGIN', data.validated);
});
},
@PatrickKalkman
PatrickKalkman / validate-token.js
Created January 15, 2022 14:29
The validateToken method of the LoginUser.vue component
validateToken() {
this.$store
.dispatch('validateToken', {
token: this.token,
})
.then(() => {
if (this.$store.state.twofactorvalidated) {
this.$router.push({ name: 'dashboard' });
} else {
this.error = 'The provided token was not valid, please try again';
@PatrickKalkman
PatrickKalkman / login-template.js
Created January 15, 2022 14:18
template part of the login vue component
<template>
<div>
<h3>{{ title }}</h3>
<form v-if="!showTwoFactorPanel" @submit.prevent="login">
<label for="email"> Email: </label>
<input v-model="email" type="email" name="email" value />
<label for="password"> Password: </label>
<input v-model="password" type="password" name="password" value />
<button type="submit" name="button">Login</button>
<p>{{ error }}</p>