diff --git a/.gitignore b/.gitignore index 6157fc1..75313cb 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ /*.conf logs imgs +web-angular diff --git a/README.md b/README.md index 8da722b..969c36c 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,43 @@ # goCaptcha captcha server, with own datasets, to train own machine learning AI - ### How to use? +#### Frontend +Insert this lines in the html file: +```html + + +
+ + + +``` + +It will place the goCaptcha box in the div: + +![goCaptcha](https://raw.githubusercontent.com/arnaucode/goCaptcha/master/demo01.png "goCaptcha") + +#### Backend +- Put dataset images in the folder 'imgs'. +- Run MongoDB. +- Go to the folder /goCaptcha, and run: +``` +./goCaptcha +``` +It will show: +``` +user@laptop:~/goCaptcha$ ./goCaptcha + goCaptcha started + dataset read + num of dataset categories: 4 + server running + port: 3025 +``` + + +### How to make the petitions? 1. Get the captcha: ``` @@ -114,6 +149,19 @@ CaptchaSolution Model ``` Both models are stored in the MongoDB. +The Captcha Model 'imgs' parameter, are UUIDs generated to set 'random' names to images. The server stores into MongoDB the relation between the 'random' name of each image and the real path of the image: +```json +{ + "captchaid" : "881c6083-0643-4d1c-9987-f8cc5bb9d5b1", + "real" : "leopard/image_0092.jpg", + "fake" : "1b838c46-b784-471e-b143-48be058c39a7.png" +} +``` +When the server recieves a petition to get an image, recieves the petition with the fake image name, then, gets the real path of the image, gets it and serves the image content under the fake image name: +``` +127.0.0.1:3025/image/1b838c46-b784-471e-b143-48be058c39a7.png +``` + Captcha Model contains the captcha that server returns to the petition. And CaptchaSolution contains the solution of the captcha. Both have the same Id. diff --git a/demo01.png b/demo01.png new file mode 100644 index 0000000..51159d3 Binary files /dev/null and b/demo01.png differ diff --git a/goCaptcha b/goCaptcha new file mode 100755 index 0000000..6d436d8 Binary files /dev/null and b/goCaptcha differ diff --git a/web/goCaptcha.css b/web/goCaptcha.css new file mode 100644 index 0000000..067bdcc --- /dev/null +++ b/web/goCaptcha.css @@ -0,0 +1,34 @@ + +.c_blue300{ + background: #64B5F6!important; + color: #ffffff!important; +} +.g_button{ + border: none; + border-radius: 2px; + position: relative; + padding: 8px 30px; + margin: 10px 1px; + font-size: 14px; + font-weight: 500; + text-transform: uppercase; + letter-spacing: 0; + will-change: box-shadow, transform; + outline: 0; + cursor: pointer; + text-decoration: none; + background: transparent; + display: inline-block; + text-align: center; + white-space: nowrap; + vertical-align: middle; +} +.g_floatRight{ + float: right; +} +.g_selected{ + border: 4px solid yellow; +} +.g_unselected{ + border: 4px solid white; +} diff --git a/web/goCaptcha.js b/web/goCaptcha.js new file mode 100644 index 0000000..77d75ba --- /dev/null +++ b/web/goCaptcha.js @@ -0,0 +1,66 @@ + +var selection = [0, 0, 0, 0, 0, 0]; +var captchaid = ""; + +function httpGet(url) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open("GET", url, false); // false for synchronous request + xmlHttp.send(null); + return xmlHttp.responseText; +} + +function httpPost(url, data) { + var xmlHttp = new XMLHttpRequest(); + xmlHttp.open("POST", url, false); + xmlHttp.setRequestHeader("Access-Control-Allow-Origin", "*"); + xmlHttp.send(data); + return xmlHttp.responseText; +} + +function getCaptcha() { + data = httpGet(goCaptchaURL + "/captcha") + captcha = JSON.parse(data); + captchaid = captcha.id; + showCaptcha(captcha); +} + +function showCaptcha(captcha) { + var html; + html = ""; + html += "