Update readme, add SQL code, remove unused function in required.php

This commit is contained in:
Skylar Ittner 2017-06-09 03:50:25 -06:00
parent 950650fd1f
commit cbbd8859c8
4 changed files with 125 additions and 32 deletions

Binary file not shown.

114
database.sql Normal file
View File

@ -0,0 +1,114 @@
-- MySQL Script generated by MySQL Workbench
-- Fri 09 Jun 2017 03:48:51 AM MDT
-- Model: New Model Version: 1.0
-- MySQL Workbench Forward Engineering
SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Schema captcheck
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema captcheck
-- -----------------------------------------------------
CREATE SCHEMA IF NOT EXISTS `captcheck` DEFAULT CHARACTER SET utf8 ;
USE `captcheck` ;
-- -----------------------------------------------------
-- Table `captcheck`.`answers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `captcheck`.`answers` (
`aid` INT NOT NULL AUTO_INCREMENT,
`aname` VARCHAR(45) NOT NULL,
`aimg` VARCHAR(45) NOT NULL,
PRIMARY KEY (`aid`),
UNIQUE INDEX `aid_UNIQUE` (`aid` ASC))
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `captcheck`.`sessions`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `captcheck`.`sessions` (
`sid` INT NOT NULL AUTO_INCREMENT,
`skey` VARCHAR(60) NOT NULL,
`aid` INT NOT NULL,
`expired` TINYINT(1) NOT NULL DEFAULT 0,
`timestamp` DATETIME NOT NULL,
PRIMARY KEY (`sid`),
UNIQUE INDEX `sid_UNIQUE` (`sid` ASC),
INDEX `fk_sessions_answers1_idx` (`aid` ASC),
CONSTRAINT `fk_sessions_answers1`
FOREIGN KEY (`aid`)
REFERENCES `captcheck`.`answers` (`aid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `captcheck`.`scrambled_answers`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `captcheck`.`scrambled_answers` (
`sid` INT NOT NULL,
`aid` INT NOT NULL,
`acode` VARCHAR(20) NOT NULL,
INDEX `fk_sessions_has_answers_answers1_idx` (`aid` ASC),
INDEX `fk_sessions_has_answers_sessions1_idx` (`sid` ASC),
CONSTRAINT `fk_sessions_has_answers_sessions1`
FOREIGN KEY (`sid`)
REFERENCES `captcheck`.`sessions` (`sid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_sessions_has_answers_answers1`
FOREIGN KEY (`aid`)
REFERENCES `captcheck`.`answers` (`aid`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
-- -----------------------------------------------------
-- Data for table `captcheck`.`answers`
-- -----------------------------------------------------
START TRANSACTION;
USE `captcheck`;
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (1, 'heart', 'heart');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (2, 'envelope', 'envelope');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (3, 'building', 'building');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (4, 'camera', 'camera');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (5, 'cloud', 'cloud');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (6, 'circle', 'circle');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (7, 'girl', 'female');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (8, 'boy', 'male');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (9, 'paper', 'file-o');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (10, 'smartphone', 'mobile');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (11, 'moon', 'moon-o');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (12, 'pencil', 'pencil');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (13, 'paint brush', 'paint-brush');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (14, 'airplane', 'plane');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (15, 'printer', 'print');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (16, 'puzzle piece', 'puzzle-piece');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (17, 'picture', 'picture-o');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (18, 'sun', 'sun-o');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (19, 'star', 'star');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (20, 'square', 'square');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (21, 'tree', 'tree');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (22, 'umbrella', 'umbrella');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (23, 'snowflake', 'snowflake-o');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (24, 'basket', 'shopping-basket');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (25, 'globe', 'globe');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (26, 'flag', 'flag');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (27, 'cube', 'cube');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (28, 'lightning', 'bolt');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (29, 'truck', 'truck');
INSERT INTO `captcheck`.`answers` (`aid`, `aname`, `aimg`) VALUES (30, 'gear', 'cog');
COMMIT;

View File

@ -4,6 +4,7 @@ Captcheck
Easy, light, self-hostable CAPTCHA service. Works on all modern browsers and
IE9+. Uses icons from Font-Awesome.
How to use
----------
@ -45,6 +46,16 @@ Example responses:
`{"session":"some_session_id","result":false,"msg":"Answer incorrect."}`
Installation
------------
1. Run composer install.
2. Copy settings.template.php to settings.php and plug in your settings.
3. Install the database.
4. Customize captcheck.js with the correct api_url.
5. Follow the How to Use section and the example setup in test.html and test.php.
Execution Flow
--------------

View File

@ -84,38 +84,6 @@ function is_empty($str) {
return (is_null($str) || !isset($str) || $str == '');
}
/*
* http://stackoverflow.com/a/20075147/2534036
*/
if (!function_exists('base_url')) {
function base_url($atRoot = FALSE, $atCore = FALSE, $parse = FALSE) {
if (isset($_SERVER['HTTP_HOST'])) {
$http = isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off' ? 'https' : 'http';
$hostname = $_SERVER['HTTP_HOST'];
$dir = str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']);
$core = preg_split('@/@', str_replace($_SERVER['DOCUMENT_ROOT'], '', realpath(dirname(__FILE__))), NULL, PREG_SPLIT_NO_EMPTY);
$core = $core[0];
$tmplt = $atRoot ? ($atCore ? "%s://%s/%s/" : "%s://%s/") : ($atCore ? "%s://%s/%s/" : "%s://%s%s");
$end = $atRoot ? ($atCore ? $core : $hostname) : ($atCore ? $core : $dir);
$base_url = sprintf($tmplt, $http, $hostname, $end);
} else
$base_url = 'http://localhost/';
if ($parse) {
$base_url = parse_url($base_url);
if (isset($base_url['path']))
if ($base_url['path'] == '/')
$base_url['path'] = '';
}
return $base_url;
}
}
/**
* Attempts to discover the user's IP address.