Skip to content

Commit 6a0282a

Browse files
authored
new snippets (#10)
* new snippets * new snippets * . * pull repos * tf * tf * . * . * . * . * . * . * . * . * . * . * python, rest and JS * '' * .
1 parent 032b96d commit 6a0282a

45 files changed

Lines changed: 3159 additions & 1142 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.gitignore‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
!.vscode/launch.json
1010
!.vscode/extensions.json
1111
*.code-workspace
12+
13+
#Python
14+
.env

‎JavaScript/hibq.html‎

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
<html>
2+
<head>
3+
<title>HIBQ</title>
4+
<style>
5+
body {
6+
font-family: Arial, sans-serif;
7+
max-width: 800px;
8+
margin: 0 auto;
9+
text-align: center;
10+
}
11+
form {
12+
margin: 20px 0;
13+
}
14+
input[type="password"] {
15+
font-size: 18px;
16+
padding: 10px;
17+
border: 1px solid #ccc;
18+
border-radius: 4px;
19+
box-sizing: border-box;
20+
}
21+
input[type="text"] {
22+
font-size: 18px;
23+
padding: 10px;
24+
border: 1px solid #ccc;
25+
border-radius: 4px;
26+
box-sizing: border-box;
27+
}
28+
button[type="button"] {
29+
font-size: 18px;
30+
padding: 10px 20px;
31+
background-color: #4CAF50;
32+
color: white;
33+
border: none;
34+
border-radius: 4px;
35+
cursor: pointer;
36+
}
37+
button[type="button"]:hover {
38+
background-color: #45a049;
39+
}
40+
.result {
41+
margin: 20px 0;
42+
font-size: 18px;
43+
}
44+
.result.safe {
45+
color: green;
46+
}
47+
.result.unsafe {
48+
color: red;
49+
}
50+
</style>
51+
</head>
52+
<body>
53+
<h1>HIBQ</h1>
54+
<form>
55+
API Key: <input type="password" id="key" value="xxx">
56+
</form>
57+
resultKey: <p id="resultKey"></p>
58+
59+
<p>Enter a password to check if it has been compromised in a data breach:</p>
60+
<form>
61+
<input type="password" id="password">
62+
<button type="button" onclick="checkPassword()">Check Password</button>
63+
</form>
64+
resultPassword: <p id="resultPassword"></p>
65+
66+
<form>
67+
<input type="text" id="account">
68+
<button type="button" onclick="checkAccount()">Check Account</button>
69+
</form>
70+
resultAccount: <p id="resultAccount"></p>
71+
72+
<form>
73+
<label for="email">Email:</label>
74+
<input type="email" id="email" name="email">
75+
<button type="button" onclick="checkEmail()">Check</button>
76+
</form>
77+
<p id="result"></p>
78+
79+
<script>
80+
function checkPassword() {
81+
// Get the API key
82+
var key = document.getElementById("key").value;
83+
84+
// Get the password from the input field
85+
var password = document.getElementById('password').value;
86+
87+
// Use the Have I Been Pwned API to check if the password has been compromised
88+
fetch('https://api.pwnedpasswords.com/range/' + password.substring(0, 5), {
89+
// "method": "GET",
90+
"headers": {
91+
"Access-Control-Allow-Origin": "*",
92+
"Access-Control-Allow-Headers": "mode",
93+
"Access-Control-Allow-Methods": "*",
94+
"mode": "no-cors",
95+
"hibp-api-key": key
96+
}
97+
})
98+
.then(response => response.text())
99+
.then(data => {
100+
// Split the response into lines
101+
var lines = data.split('\n');
102+
103+
// Search for the password hash in the response
104+
for (var i = 0; i < lines.length; i++) {
105+
var line = lines[i];
106+
var hash = line.substring(0, 35);
107+
var count = line.substring(36);
108+
if (password.toUpperCase() == hash) {
109+
// If the password hash is found, display the result
110+
document.getElementById('resultPassword').innerHTML = 'This password has been compromised ' + count + ' times. It is not safe to use.';
111+
return;
112+
}
113+
}
114+
115+
// If the password hash is not found, display a message saying the password is safe to use
116+
document.getElementById('resultPassword').innerHTML = 'This password has not been compromised. It is safe to use.';
117+
document.getElementById('resultKey').innerHTML = 'The API Key you entered:' + key;
118+
});
119+
}
120+
function checkAccount() {
121+
// Get the API key
122+
var key = document.getElementById("key").value;
123+
124+
// Get the account from the input field
125+
var account = document.getElementById('account').value;
126+
127+
fetch("https://haveibeenpwned.com/api/v3/breachedaccount/" + account + "?truncateResponse=false", {
128+
"method": "GET",
129+
"headers": {
130+
"Access-Control-Allow-Origin": "*",
131+
"Access-Control-Allow-Headers": "mode",
132+
"Access-Control-Allow-Methods": "*",
133+
"mode": "no-cors",
134+
"hibp-api-key": key
135+
}
136+
})
137+
.then(response => {
138+
console.log(response);
139+
})
140+
.catch(err => {
141+
console.error(err);
142+
});
143+
}
144+
145+
function checkEmail() {
146+
// Get the API key
147+
var key = document.getElementById("key").value;
148+
149+
var email = document.getElementById("email").value;
150+
var xhr = new XMLHttpRequest();
151+
xhr.open("GET", "https://haveibeenpwned.com/api/v3/breachedaccount/" + email + "?truncateResponse=false");
152+
xhr.setRequestHeader("hibp-api-key", key);
153+
xhr.onload = function() {
154+
var resultElement = document.getElementById("result");
155+
if (xhr.status === 200) {
156+
var breaches = JSON.parse(xhr.responseText);
157+
if (breaches.length > 0) {
158+
resultElement.innerHTML = "The email address " + email + " has been compromised in the following breaches: " + breaches.map(b => b.Name).join(", ");
159+
} else {
160+
resultElement.innerHTML = "The email address " + email + " has not been found in any breaches.";
161+
}
162+
} else {
163+
resultElement.innerHTML = "An error occurred: " + xhr.status + " " + xhr.statusText;
164+
}
165+
};
166+
xhr.send();
167+
}
168+
</script>
169+
</body>
170+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
$folder = Get-Location # '.'
2+
$localRepos = Get-ChildItem $folder.Path -Directory -recurse | select *
3+
4+
foreach($repo in $localRepos) {
5+
"$($repo.FullName)"
6+
Set-Location "$($repo.FullName)"
7+
git tag -d 1.0.0
8+
git checkout main; git pull; git remote update origin --prune; git branch -vv | Select-String -Pattern ": gone]" | % { $_.toString().Trim().Split(" ")[0]} | % { git branch -D $_ }
9+
}
10+
Set-Location $folder.Path
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Param(
2+
[string]$destinationFolder = ".",
3+
[string]$org = "x00",
4+
[string]$project = "Modules"
5+
)
6+
7+
az devops configure --defaults organization=https://dev.azure.com/$org project=$project
8+
$repos = az repos list | ConvertFrom-Json
9+
10+
foreach($repo in $repos) {
11+
git clone $($repo.remoteUrl) $destinationFolder/$($repo.Name)
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Param(
2+
[string]$destinationFolder = "."
3+
)
4+
5+
$repos = Get-ChildItem -Path $destinationFolder -Directory
6+
7+
foreach($repo in $repos) {
8+
$($repo.FullName)
9+
Set-Location "$($repo.FullName)";
10+
git checkout -b users/segraef/provider-upgrade;
11+
git push --set-upstream origin users/segraef/provider-upgrade;
12+
git add .;
13+
git commit -m "provider upgrade";
14+
git push;
15+
}
16+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Param(
2+
[string]$org = "x00",
3+
[string]$project = "ESLZ Modules",
4+
[string]$token = "token",
5+
[string]$branchName = "users/segraef/provider-upgrade"
6+
)
7+
8+
az extension add --name azure-devops
9+
10+
echo $token | az devops login --organization https://dev.azure.com/$org
11+
az devops configure --defaults organization=https://dev.azure.com/$org project=$project
12+
$repos = az repos list | ConvertFrom-Json
13+
14+
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
15+
16+
# Create Pull Request on all repos
17+
foreach($repo in $repos){
18+
Write-Host $repo.name
19+
# az repos pr create --repository $repo.name --source-branch $branchName --open --output table
20+
}
21+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
$names = Get-ChildItem
2+
foreach($name in $names) {
3+
$x = $name.BaseName -replace "(?-i)[A-Z]",'-$&'
4+
$x = $x.ToLower()
5+
Write-output """terraform-azurerm$x"","
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Param(
2+
[string]$org = "x00",
3+
[string]$project = "Modules",
4+
[string]$token = "token"
5+
)
6+
7+
az devops configure --defaults organization=https://dev.azure.com/$org project=$project
8+
# $repos = az repos list --query "[].[id]" -o table
9+
$repos = az repos list | ConvertFrom-Json
10+
11+
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
12+
# Disable Repository
13+
$json = '{ "isDisabled" : "false" }'
14+
foreach($repo in $repos){
15+
$uri = "https://dev.azure.com/$org/$project/_apis/git/repositories/$($repo.id)" + "?api-version=6.0"
16+
Write-Host $repo.name
17+
$result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
18+
$result
19+
}

‎PowerShell/Snippets/Pull-Repos.ps1‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Param(
2+
[string]$destinationFolder = "."
3+
)
4+
5+
$repos = Get-ChildItem -Path $destinationFolder -Directory
6+
7+
foreach($repo in $repos) {
8+
$($repo.FullName)
9+
Set-Location "$($repo.FullName)";
10+
git checkout main;
11+
git pull;
12+
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# With -Directory for folders and without for files
22
$WhatIfPreference = 'False'
33

4-
$searchprefix = '*eus*'
4+
$searchprefix = '.terraform'
55
$a = 'eus'
66
$b = 'ae'
77
Get-ChildItem -Path $searchprefix -Recurse | ForEach-Object -Process { Rename-item -Path $_.FullName -NewName ($_.name -replace $a, $b) -Verbose}
8+
9+
# Remove
10+
Get-ChildItem -Recurse -Hidden | Where-Object { $_.FullName -like '*.terraform*' } | ForEach-Object -Process { Remove-Item -Path $_.FullName -Verbose -Force -Recurse}

0 commit comments

Comments
 (0)