Files
editcaptcha/class/editcaptcha.php
2026-03-06 15:28:56 +05:00

96 lines
3.3 KiB
PHP

<?php
/**
* AVE.cms - Модуль Настройки captcha
* @author Repellent
* @package AVE.cms
*/
class ModuleEditcaptcha
{
public $tpl_dir;
private function checkAccess()
{
return (defined('ACP') && check_permission('modules'));
}
public function editCaptcha()
{
global $AVE_Template;
$config_file = BASE_DIR . '/lib/kcaptcha/kcaptcha_config.php';
// Дефолты
$allowed_symbols = "23456789abcdegikpqsvxyz";
$length = "4,6";
$fluctuation_amplitude = 8;
$white_noise_density = "1/30";
$black_noise_density = "1/30";
$no_spaces = true;
$background_color = array(255, 255, 255);
if (file_exists($config_file)) {
include($config_file);
}
// Преобразуем массив RGB в HEX для инпута в админке
$bg_hex = sprintf("#%02x%02x%02x", $background_color[0], $background_color[1], $background_color[2]);
$AVE_Template->assign([
'allow_symbols' => $allowed_symbols,
'count_symbols' => $length,
'fluct_amplit' => $fluctuation_amplitude,
'white_noise' => $white_noise_density,
'black_noise' => $black_noise_density,
'no_spaces' => ($no_spaces == true) ? 'true' : 'false',
'bg_color' => $bg_hex
]);
$AVE_Template->assign('content', $AVE_Template->fetch($this->tpl_dir . 'editcaptcha.tpl'));
}
public function saveCaptcha()
{
if (!$this->checkAccess()) exit("Access Denied");
$a = preg_replace('/[^a-z0-9]/i', '', $_POST['a'] ?? '');
$b = preg_replace('/[^0-9,]/', '', $_POST['b'] ?? '4,6');
$c = (int)($_POST['c'] ?? 8);
$d = strip_tags($_POST['d'] ?? '0');
$e = strip_tags($_POST['e'] ?? '0');
$f = ($_POST['f'] === 'true') ? 'true' : 'false';
// Обработка цвета фона (из #ffffff в array(255,255,255))
$hex = $_POST['g'] ?? '#ffffff';
list($r, $g, $b_rgb) = sscanf($hex, "#%02x%02x%02x");
$length_val = (strpos($b, ',') !== false) ? "mt_rand({$b})" : (int)$b;
$text = "<?php\n\n";
$text .= "# KCAPTCHA configuration file\n";
$text .= "\$alphabet = \"0123456789abcdefghijklmnopqrstuvwxyz\";\n";
$text .= "\$allowed_symbols = \"{$a}\";\n";
$text .= "\$fontsdir = 'fonts';\n";
$text .= "\$length = {$length_val};\n";
$text .= "\$width = 160;\n";
$text .= "\$height = 80;\n";
$text .= "\$fluctuation_amplitude = {$c};\n";
$text .= "\$white_noise_density = {$d};\n";
$text .= "\$black_noise_density = {$e};\n";
$text .= "\$no_spaces = {$f};\n";
$text .= "\$show_credits = false;\n";
$text .= "\$foreground_color = array(mt_rand(0,80), mt_rand(0,80), mt_rand(0,80));\n";
$text .= "\$background_color = array({$r}, {$g}, {$b_rgb});\n";
$text .= "\$jpeg_quality = 95;\n";
$text .= "?>";
$file_path = BASE_DIR . "/lib/kcaptcha/kcaptcha_config.php";
if (is_writable($file_path) || @chmod($file_path, 0666)) {
file_put_contents($file_path, $text);
echo "success";
} else {
echo "Ошибка прав доступа к файлу конфига!";
}
exit;
}
}