fet: init

This commit is contained in:
Aravinth Manivannan 2024-01-03 01:02:56 +05:30
commit 8ffc6cd45f
Signed by: realaravinth
GPG key ID: F8F50389936984FF
6 changed files with 334 additions and 0 deletions

3
.env_sample Normal file
View file

@ -0,0 +1,3 @@
export USERNAME=
export PASSWORD=
export INSTANCE_URL=

133
.gitignore vendored Normal file
View file

@ -0,0 +1,133 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*
.env
.env.local
tmp/

1
.nvmrc Normal file
View file

@ -0,0 +1 @@
20.10.0

47
.woodpecker.yml Normal file
View file

@ -0,0 +1,47 @@
steps:
postgres:
image: postgres
detach: true
environment:
- POSTGRES_PASSWORD=password
cache:
image: mcaptcha/cache:latest
detach: true
mcaptcha:
image: mcaptcha/mcaptcha:latest
detach: true
environment:
- DATABASE_URL=postgres://postgres:password@postgres:5432/postgres # set password at placeholder
- RUST_LOG=debug
- PORT=7000
- MCAPTCHA_server_IP=0.0.0.0
- MCAPTCHA_server_DOMAIN=mcaptcha
- MCAPTCHA_server_COOKIE_SECRET=4d08c163c0b9780e7462893fd8aed5102c2c509f
- MCAPTCHA_captcha_SALT=4d08c163c0b9780e7462893fd8aed5102c2c509f
- MCAPTCHA_redis_URL=redis://cache/
- MCAPTCHA_redis_POOL=4
- MCAPTCHA_allow_demo=true
test_setup:
image: python
environment:
- USERNAME=aaronsw
- PASSWORD=password
- INSTANCE_URL=http://mcaptcha:7000
commands:
- pip install virtualenv && virtualenv venv
- make env
- make test.env
- mv .env.local .env_sample
test:
image: node:20.10.0
environment:
- USERNAME=aaronsw
- PASSWORD=password
- INSTANCE_URL=http://mcaptcha:7000
commands:
- mv .env_sample .env.local
- make test

115
scripts/create_captcha.py Normal file
View file

@ -0,0 +1,115 @@
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
# SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT
import sys
from urllib.parse import urlparse, urlunparse, urlencode, parse_qsl
from requests import Session
def clean_url(url):
parsed = urlparse(url)
return urlunparse((parsed.scheme, parsed.netloc, "", "", "", ""))
def set_path(url: str, path: str) -> str:
parsed = urlparse(url)
return urlunparse((parsed.scheme, parsed.netloc, path, "", "", ""))
def help():
print("Usage: create_captcha.py <option>")
print("OPTIONS:\ncreate_captcha <mcaptcha_instance_url> <username> <password>")
print("get_secret <mcaptcha_instance_url> <username> <password>")
print("widget_url <mcaptcha_instance_url> <sitekey>")
c = Session()
if len(sys.argv) < 1:
help()
exit(1)
option = sys.argv[1]
def login():
if len(sys.argv) < 4:
help()
exit(1)
instance_url = clean_url(sys.argv[2])
username = sys.argv[3]
password = sys.argv[4]
url = set_path(instance_url, "/api/v1/signin")
payload = {"login": username, password: password}
resp = c.post(url, json=payload)
assert resp.status_code == 200
def create_captcha():
instance_url = clean_url(sys.argv[2])
username = sys.argv[3]
password = sys.argv[4]
levels = [
{"difficulty_factor": 50, "visitor_threshold": 50},
{"difficulty_factor": 500, "visitor_threshold": 500},
]
payload = {
"levels": levels,
"duration": 30,
"description": "create_captcha_test_script",
"publish_benchmarks": False,
}
url = set_path(instance_url, "/api/v1/mcaptcha/create")
resp = c.post(url, json=payload, cookies=c.cookies.get_dict())
assert resp.status_code == 200
return resp.json()["key"]
def get_secret():
if len(sys.argv) < 3:
help()
exit(1)
instance_url = clean_url(sys.argv[2])
username = sys.argv[3]
password = sys.argv[4]
instance_url = clean_url(sys.argv[2])
sitekey = sys.argv[3]
url = set_path(instance_url, "/api/v1/account/secret/get")
resp = c.get(url, cookies=c.cookies.get_dict())
assert resp.status_code == 200
return resp.json()["secret"]
def widget_url():
if len(sys.argv) < 4:
help()
exit(1)
instance_url = set_path(clean_url(sys.argv[2]), "/widget")
sitekey = sys.argv[3]
query = urlencode({"sitekey": sitekey})
url = f"{instance_url}?{query}"
return url
if __name__ == "__main__":
if option == "create_captcha":
login()
print(create_captcha())
elif option == "get_secret":
login()
print(get_secret())
elif option == "widget_url":
print(widget_url())
else:
help()

35
scripts/download-cli.sh Executable file
View file

@ -0,0 +1,35 @@
#!/bin/bash
# SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
# SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
#
# SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: MIT
readonly PROJECT_ROOT=$(pwd)
readonly SOURCE=https://dl.mcaptcha.org/mcaptcha/cli/0.3.0/x86_64-unknown-linux-gnu.tar.gz
readonly BIN_PATH=tmp/cli/mcaptcha-cli
readonly TARBALL=mcaptcha-cli.tar.gz
download() {
if [ ! -e $BIN_PATH ];
then
mkdir -p tmp/cli
cd tmp/cli/
wget $SOURCE --quiet --output-document=$TARBALL $SOURCE
tar -xvzf $TARBALL > /dev/null
rm $TARBALL
echo "[*] Downloaded mCaptcha CLI"
mv build/x86_64-unknown-linux-gnu/mcaptcha-cli .
rm -rf build/
cd $PROJECT_ROOT
fi
}
# 1: widget URI
gen_pow() {
$BIN_PATH widget-url $2 | cut -d ':' -f 2 | tr -d ' '
}
$1 $@