-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
187 additions
and
29 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as fs from "node:fs"; | ||
import { getLoggerDefault } from "@prosopo/common"; | ||
import { getIPAddress } from "@prosopo/provider"; | ||
import mongoose from "mongoose"; | ||
import { RulesMongooseStorage } from "./rules/mongoose/rulesMongooseStorage.js"; | ||
import { getRuleMongooseSchema } from "./rules/mongoose/schemas/getRuleMongooseSchema.js"; | ||
|
||
function randomIntFromInterval(min: number, max: number) { | ||
// min and max included | ||
return Math.floor(Math.random() * (max - min + 1) + min); | ||
} | ||
|
||
const main = async (ips: string[]) => { | ||
const mongoConnection = await mongoose.connect( | ||
"mongodb://root:root@localhost:27017/prosopo", | ||
{ | ||
authSource: "admin", | ||
}, | ||
); | ||
|
||
const model = mongoConnection.model( | ||
"UserAccessRules", | ||
getRuleMongooseSchema(), | ||
undefined, | ||
{ overwriteModels: true }, | ||
); | ||
|
||
const logger = getLoggerDefault(); | ||
|
||
await model.syncIndexes(); | ||
|
||
const rulesStorage = new RulesMongooseStorage(logger, model); | ||
|
||
while (true) { | ||
const random = randomIntFromInterval(0, ips.length); | ||
const ipStr = ips[random]; | ||
if (ipStr) { | ||
const ip = getIPAddress(ipStr); | ||
|
||
const rule = await rulesStorage.find({ | ||
clientId: "5E1bGh2NgRb8dD4NC5bQKRbgiCz8oBc2EhAuYJzy99q3iJ3s", | ||
userIpAddress: ip, | ||
}); | ||
|
||
console.log("rule", rule); | ||
} | ||
} | ||
}; | ||
|
||
const ips = fs | ||
.readFileSync( | ||
"/home/chris/Documents/prosopo/shared/Data/2captcha/blockedIps2025-02-12.csv", | ||
"utf8", | ||
) | ||
.split("\n") | ||
.slice(1); | ||
|
||
console.log("ips", ips); | ||
|
||
main(ips) | ||
.then(() => { | ||
console.log("done"); | ||
process.exit(); | ||
}) | ||
.catch((error) => { | ||
console.error("error", error); | ||
process.exit(1); | ||
}); |
This file contains 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