Giter Site home page Giter Site logo

emgrav / kocaptcha Goto Github PK

View Code? Open in Web Editor NEW

This project forked from koto-bank/kocaptcha

0.0 1.0 0.0 170 KB

A simple captcha service

Home Page: https://captcha.kotobank.ch

License: BSD 2-Clause "Simplified" License

Rust 90.98% Dockerfile 9.02%

kocaptcha's Introduction

Docker Pulls

A simple CAPTCHA service with a single API endpoint at /new that will give you a JSON output of md5 (the md5 of the answer) and url (the captcha image). Captchas expire after five minutes and delete themselves.

The files are stored in the captchas directory, which is deleted on exit.

Installation

If you don't want to build kocaptcha, you can use the docker image.

Otherwise, the only external dependency besides rust itself seems to be fontconfig to find fonts. The font used for captchas can be set with the KOCAPTCHA_FONT_FAMILY environmental variable, or the first one provided by fontconfig will be used.

cd into the kocaptcha directory and run cargo build --release. This will produce a binary, which you'll want to copy wherever you want to run the service from. You can then run the service bu simply launching the binary (optionally adding the KOCAPTCHA_FONT_FAMILY environmental variable). For example: KOCAPTCHA_FONT_FAMILY=FontFamily ./kocaptcha. This will start the service at 0.0.0.0:9093.

Running with a supervisor

You can also use run the service with systemd, openrc, or any other supervising system you'd like, it's fairly straightforward to do.

OpenRC service example

#!/sbin/openrc-run

# Requires OpenRC >= 0.35
directory=~kocaptcha

command=~kocaptcha/kocaptcha
command_user=kocaptcha:kocaptcha
command_background=1

# Ask process to terminate within 30 seconds, otherwise kill it
retry="SIGTERM/30/SIGKILL/5"

pidfile="/var/run/kocaptcha.pid"

depend() {
    need net
}

Note that this configuration implies that you have a kocaptcha user in your system and that user has a home directory, which in turn has the kocaptcha binary. If you don't, change the appropriate lines in the script to match your system configuration.

Systemd service example

[Unit]
Description=Kocaptcha captcha service
After=network.target

[Service]
ExecStart=/home/kocaptcha/kocaptcha

[Install]
WantedBy = multi-user.target

This systemd service implies that the home directory for kocaptcha exists. You can also provide a custom user for it, if needed.

Nginx configuration

While you can run the service on the 9093 port, it's better to run it on an actual domain. It's easier to remeber and as an additional benefit, you can configure nginx to redirect users from the http to the https version.

server {
    listen 80;
    server_name <domain name>;

    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name <domain name>;
    ssl_certificate /etc/letsencrypt/live/<domain name>/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/<domain name>/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    location / {
        proxy_pass http://localhost:9093;
    }
}

This configuration uses Let's encrypt certbot generated certificates and routes all traffic from your domain to the service's port. Note that you'll have to install and configure certbot for your domain.

kocaptcha's People

Contributors

fami-com avatar vaartis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.