Last active
December 18, 2023 14:57
-
-
Save giacomocerquone/59bb1a04a88c1fc3254218fd9cdf7673 to your computer and use it in GitHub Desktop.
Print all non-active dns from pwds stored in bitwarden through bw cli
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require("axios"); | |
const bitwardenApiUrl = "http://localhost:8087"; | |
const MASTER_PWD = "xxx"; | |
// Function to unlock the vault | |
async function unlock() { | |
try { | |
const { data: unlockRes } = await axios.post(`${bitwardenApiUrl}/unlock`, { | |
password: MASTER_PWD, | |
}); | |
console.log("unlock response", unlockRes.success); | |
return true; | |
} catch (error) { | |
console.error("Error unlocking the vault:", error.message); | |
throw error; | |
} | |
} | |
async function fetchPasswordItems() { | |
const { | |
data: { | |
data: { data }, | |
}, | |
} = await axios.get(`${bitwardenApiUrl}/list/object/items`); | |
return data.filter((item) => item.type === 1); | |
} | |
// Function to check if a URL is active | |
async function isUrlActive(url) { | |
try { | |
const response = await axios.head(url, { | |
timeout: 5000, | |
maxRedirects: 10, // Maximum number of redirects to follow | |
validateStatus: (status) => status >= 200 && status <= 500, // Validate successful status codes | |
}); | |
return response.status >= 200 && response.status < 400; | |
} catch (e) { | |
return false; | |
} | |
} | |
// Main function to retrieve URLs and check their status | |
async function checkUrls() { | |
try { | |
await unlock(); | |
const passwords = await fetchPasswordItems(); | |
for (const item of passwords) { | |
if (item.login && item.login.uris) { | |
for (const uri of item.login.uris) { | |
const url = uri.uri; | |
if (url.startsWith("android")) continue; | |
const isActive = await isUrlActive(url); | |
if (!isActive) { | |
console.log(`${url} is not active`); | |
} | |
} | |
} | |
} | |
process.exit(); | |
} catch (error) { | |
console.error("Error checking URLs:", error.message); | |
} | |
} | |
checkUrls(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just make sure to configure the bw cli, add the master password in the above script, and then run
bw serve
.After that, you can launch this script.
Be careful, there will be false positives.