1
0
mirror of https://github.com/monstra-cms/monstra.git synced 2025-07-31 18:30:20 +02:00

Monstra Library: basic core improvments

This commit is contained in:
Awilum
2013-01-04 21:08:04 +02:00
parent 7437cc6abb
commit ef12b7492e
289 changed files with 16265 additions and 17155 deletions

View File

@@ -1,49 +1,48 @@
<?php
/**
* Captcha plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
*/
// Register plugin
Plugin::register( __FILE__,
__('Captcha', 'captcha'),
__('Captcha plugin for Monstra', 'captcha'),
'1.0.0',
'Awilum',
'http://monstra.org/');
// Set crypt captcha path to images
$cryptinstall = Option::get('siteurl').'plugins/captcha/crypt/images/';
// Include Crypt Captcha
include PLUGINS . DS . 'captcha/crypt/cryptographp.fct.php';
/**
* Crypt Captha class
*/
class CryptCaptcha
{
/**
* Captcha plugin
*
* @package Monstra
* @subpackage Plugins
* @author Romanenko Sergey / Awilum
* @copyright 2012 Romanenko Sergey / Awilum
* @version 1.0.0
*
* Draw
*/
// Register plugin
Plugin::register( __FILE__,
__('Captcha', 'captcha'),
__('Captcha plugin for Monstra', 'captcha'),
'1.0.0',
'Awilum',
'http://monstra.org/');
// Set crypt captcha path to images
$cryptinstall = Option::get('siteurl').'plugins/captcha/crypt/images/';
// Include Crypt Captcha
include PLUGINS . DS . 'captcha/crypt/cryptographp.fct.php';
public static function draw()
{
dsp_crypt();
}
/**
* Crypt Captha class
* Check
*/
class CryptCaptcha {
/**
* Draw
*/
public static function draw() {
dsp_crypt();
}
/**
* Check
*/
public static function check($answer) {
return chk_crypt($answer);
}
}
public static function check($answer)
{
return chk_crypt($answer);
}
}

View File

@@ -12,7 +12,7 @@ $bgG = 255; // Background color RGB: Green (0 - 255)
$bgB = 255; // Background color RGB: Blue (0 - 255)
$bgclear = true; // Background transparent (true/false)
$bgimg = ''; // Background image
$bgimg = ''; // Background image
$bgframe = true; // Image frame/border
// ----------------------------
@@ -33,12 +33,12 @@ $tfont[] = 'luggerbu.ttf';
$charel = 'ABCDEFGHKLMNPRTWXYZ234569'; // Characters to use
$crypteasy = true; // Crypt image easy to read (true) or not (false)
$crypteasy = true; // Crypt image easy to read (true) or not (false)
$charelc = 'BCDFGHKLMNPRTVWXZ'; // $crypteasy = true
$charelv = 'AEIOUY'; // $crypteasy = true
$difuplow = false;
$difuplow = false;
$charnbmin = 4; // Minimum characters in the ciphertext
$charnbmax = 4; // Maximum characters in the ciphertext
@@ -50,12 +50,10 @@ $charsizemax = 16; // The maximum size of the characters
$charanglemax = 25; // The maximum steering angle of characters (0 - 360)
$charup = true; // Vertical movement of random characters (yes / no)
// Additional effects
$cryptgaussianblur = false; // Gaussian Blur
$cryptgaussianblur = false; // Gaussian Blur
$cryptgrayscal = false; // Grayscal
// ----------------------
// Configuration du bruit
@@ -74,20 +72,18 @@ $noisecolorchar = 3; // Noise: pixel colors, lines, circles: (1 - 3)
// 1: Characters color
// 2: The background color
// 3: Random Color
$brushsize = 1; // Brush size (in pixels) (1 - 25)
$noiseup = false; // Noise is under entry (TRUE) or below (false)
// --------------------------------
// System configuration and security
// --------------------------------
$cryptformat = "png"; // Image format "GIF", "PNG" or "JPG"
$cryptsecure = "md5"; // Crypt method "md5", "sha1" or ""
$cryptsecure = "md5"; // Crypt method "md5", "sha1" or ""
$cryptusetimer = 0; // Time sleep
$cryptusertimererror = 3; // Min times
$cryptusemax = 1000; // Max times
$cryptoneuse = false; //
$cryptoneuse = false; //

View File

@@ -4,35 +4,36 @@ if (session_id() == "") session_start();
$_SESSION['cryptdir'] = dirname($cryptinstall);
/**
* Render Capthca
*/
function dsp_crypt($cfg = 0, $reload = 1) {
function dsp_crypt($cfg = 0, $reload = 1)
{
echo "<table><tr><td><img id='cryptogram' src='".$_SESSION['cryptdir']."/cryptographp.php?cfg=".$cfg."&".SID."'></td>";
if ($reload) echo "<td>&nbsp;&nbsp;<a title='".($reload==1?'':$reload)."' style=\"cursor:pointer\" onclick=\"javascript:document.images.cryptogram.src='".$_SESSION['cryptdir']."/cryptographp.php?cfg=".$cfg."&".SID."&'+Math.round(Math.random(0)*1000)+1\"><img src=\"".$_SESSION['cryptdir']."/images/reload.png\"></a></td>";
echo "</tr></table>";
}
/**
* Verify Code
*/
function chk_crypt($code) {
function chk_crypt($code)
{
include ($_SESSION['configfile']);
$code = addslashes ($code);
$code = str_replace(' ', '', $code);
$code = ($difuplow ? $code : strtoupper($code));
switch (strtoupper($cryptsecure)) {
switch (strtoupper($cryptsecure)) {
case "MD5" : $code = md5($code); break;
case "SHA1" : $code = sha1($code); break;
}
if ($_SESSION['cryptcode'] and ($_SESSION['cryptcode'] == $code)) {
unset($_SESSION['cryptreload']);
if ($cryptoneuse) unset($_SESSION['cryptcode']);
if ($cryptoneuse) unset($_SESSION['cryptcode']);
return true;
} else {
$_SESSION['cryptreload'] = true;
return false;
}
}
}

View File

@@ -4,15 +4,15 @@
* Cryptographp / v1.5
*
* @version 1.5 Romanenko Sergey / Awilum
* @version 1.4 by Sylvain BRISON
* @version 1.4 by Sylvain BRISON
*/
error_reporting(0);
srand((double)microtime()*1000000);
srand((double) microtime()*1000000);
if (( ! isset($_COOKIE['cryptcookietest'])) and ($_GET[$_GET['sn']] == "")) {
if (( ! isset($_COOKIE['cryptcookietest'])) and ($_GET[$_GET['sn']] == "")) {
header("Content-type: image/png");
readfile('images/erreur3.png');
readfile('images/erreur3.png');
exit;
}
@@ -20,27 +20,26 @@ if ($_GET[$_GET['sn']] == "") { unset ($_GET['sn']); }
session_start();
// Takes only the configuration files in the same directory
if (is_file($_GET['cfg']) and dirname($_GET['cfg']) == '.' ) { $_SESSION['configfile']=$_GET['cfg']; } else { $_SESSION['configfile'] = "cryptographp.cfg.php"; }
include($_SESSION['configfile']);
include($_SESSION['configfile']);
if ($_SESSION['cryptcptuse'] >= $cryptusemax) {
header("Content-type: image/png");
readfile('images/erreur1.png');
readfile('images/erreur1.png');
exit;
}
$delai = time()-$_SESSION['crypttime'];
if ($delai < $cryptusetimer) {
if ($delai < $cryptusetimer) {
switch ($cryptusertimererror) {
case 2 : header("Content-type: image/png");
readfile('images/erreur2.png');
readfile('images/erreur2.png');
exit;
case 3 : sleep ($cryptusetimer-$delai);
break; // Fait une pause
case 1 :
case 1 :
default : exit; // Quitte le script sans rien faire
}
}
@@ -51,15 +50,14 @@ $blank = imagecolorallocate($imgtmp,255,255,255);
$black = imagecolorallocate($imgtmp,0,0,0);
imagefill($imgtmp,0,0,$blank);
$word ='';
$x = 10;
$x = 10;
$pair = rand(0,1);
$charnb = rand($charnbmin,$charnbmax);
for ($i=1;$i<= $charnb;$i++) {
for ($i=1;$i<= $charnb;$i++) {
$tword[$i]['font'] = $tfont[array_rand($tfont,1)];
$tword[$i]['angle'] = (rand(1,2)==1)?rand(0,$charanglemax):rand(360-$charanglemax,360);
if ($crypteasy) $tword[$i]['element'] =(!$pair)?$charelc{rand(0,strlen($charelc)-1)}:$charelv{rand(0,strlen($charelv)-1)};
else $tword[$i]['element'] = $charel{rand(0,strlen($charel)-1)};
@@ -67,12 +65,12 @@ for ($i=1;$i<= $charnb;$i++) {
$tword[$i]['size'] = rand($charsizemin,$charsizemax);
$tword[$i]['y'] = ($charup?($cryptheight/2)+rand(0,($cryptheight/5)):($cryptheight/1.5));
$word .=$tword[$i]['element'];
$lafont="fonts/".$tword[$i]['font'];
imagettftext($imgtmp,$tword[$i]['size'],$tword[$i]['angle'],$x,$tword[$i]['y'],$black,$lafont,$tword[$i]['element']);
$x +=$charspace;
}
}
// Calculation of horizontal framing cryptograms temporary
$xbegin=0;
@@ -84,8 +82,8 @@ while (($x<$cryptwidth)and(!$xbegin)) {
$y++;
}
$x++;
}
}
$xend=0;
$x=$cryptwidth-1;
while (($x>0)and(!$xend)) {
@@ -95,18 +93,17 @@ while (($x>0)and(!$xend)) {
$y++;
}
$x--;
}
}
$xvariation = round(($cryptwidth/2)-(($xend-$xbegin)/2));
imagedestroy ($imgtmp);
// Creating the final cryptogram
$img = imagecreatetruecolor($cryptwidth, $cryptheight);
$img = imagecreatetruecolor($cryptwidth, $cryptheight);
if ($bgimg and is_dir($bgimg)) {
$dh = opendir($bgimg);
while (false !== ($filename = readdir($dh)))
while (false !== ($filename = readdir($dh)))
if (eregi(".[gif|jpg|png]$", $filename)) { $files[] = $filename; }
closedir($dh);
$bgimg = $bgimg.'/'.$files[array_rand($files,1)];
@@ -127,17 +124,16 @@ if ($bgimg) {
if ($bgclear) imagecolortransparent($img,$bg);
}
function ecriture() {
function ecriture()
{
global $img, $ink, $charR, $charG, $charB, $charclear, $xvariation, $charnb, $charcolorrnd, $charcolorrndlevel, $tword, $charspace;
if (function_exists ('imagecolorallocatealpha')) $ink = imagecolorallocatealpha($img,$charR,$charG,$charB,$charclear);
else $ink = imagecolorallocate ($img,$charR,$charG,$charB);
$x = $xvariation;
for ($i = 1; $i <= $charnb; $i++) {
if ($charcolorrnd) {
for ($i = 1; $i <= $charnb; $i++) {
if ($charcolorrnd) {
$ok = false;
do {
$rndR = rand(0,255); $rndG = rand(0,255); $rndB = rand(0,255);
@@ -147,29 +143,29 @@ function ecriture() {
case 2 : if ($rndcolor<400) $ok=true; break; // sombre
case 3 : if ($rndcolor>500) $ok=true; break; // claires
case 4 : if ($rndcolor>650) $ok=true; break; // tr?s claires
default : $ok=true;
default : $ok=true;
}
} while (!$ok);
if (function_exists ('imagecolorallocatealpha')) $rndink = imagecolorallocatealpha($img,$rndR,$rndG,$rndB,$charclear);
else $rndink = imagecolorallocate ($img,$rndR,$rndG,$rndB);
}
else $rndink = imagecolorallocate ($img,$rndR,$rndG,$rndB);
}
$lafont="fonts/".$tword[$i]['font'];
imagettftext($img,$tword[$i]['size'],$tword[$i]['angle'],$x,$tword[$i]['y'],$charcolorrnd?$rndink:$ink,$lafont,$tword[$i]['element']);
$x +=$charspace;
}
}
}
function noisecolor() {
function noisecolor()
{
global $img, $noisecolorchar, $ink, $bg, $brushsize;
switch ($noisecolorchar) {
case 1 : $noisecol = $ink; break;
case 2 : $noisecol = $bg; break;
case 3 :
default : $noisecol = imagecolorallocate ($img,rand(0,255),rand(0,255),rand(0,255)); break;
case 3 :
default : $noisecol = imagecolorallocate ($img,rand(0,255),rand(0,255),rand(0,255)); break;
}
if ($brushsize and $brushsize > 1 and function_exists('imagesetbrush')) {
$brush = imagecreatetruecolor($brushsize,$brushsize);
@@ -177,11 +173,12 @@ function noisecolor() {
imagesetbrush($img, $brush);
$noisecol = IMG_COLOR_BRUSHED;
}
return $noisecol;
return $noisecol;
}
function bruit() {
function bruit()
{
global $noisepxmin, $noisepxmax, $noiselinemin, $noiselinemax, $nbcirclemin, $nbcirclemax,$img, $cryptwidth, $cryptheight;
$nbpx = rand($noisepxmin,$noisepxmax);
$nbline = rand($noiselinemin,$noiselinemax);
@@ -189,8 +186,7 @@ function bruit() {
for ($i=1;$i<$nbpx;$i++) imagesetpixel ($img,rand(0,$cryptwidth-1),rand(0,$cryptheight-1),noisecolor());
for ($i=1;$i<=$nbline;$i++) imageline($img,rand(0,$cryptwidth-1),rand(0,$cryptheight-1),rand(0,$cryptwidth-1),rand(0,$cryptheight-1),noisecolor());
for ($i=1;$i<=$nbcircle;$i++) imagearc($img,rand(0,$cryptwidth-1),rand(0,$cryptheight-1),$rayon=rand(5,$cryptwidth/3),$rayon,0,360,noisecolor());
}
}
if ($noiseup) {
ecriture();
@@ -200,51 +196,46 @@ if ($noiseup) {
ecriture();
}
// Creating frame
if ($bgframe) {
$framecol = imagecolorallocate($img,($bgR*3+$charR)/4,($bgG*3+$charG)/4,($bgB*3+$charB)/4);
imagerectangle($img, 0, 0, $cryptwidth-1, $cryptheight-1, $framecol);
}
// Additional changes: grayscale and gaussian blur
if (function_exists('imagefilter')) {
if ($cryptgrayscal) imagefilter ( $img, IMG_FILTER_GRAYSCALE);
if ($cryptgaussianblur) imagefilter ( $img, IMG_FILTER_GAUSSIAN_BLUR);
}
// Shift conversion cryptograms
$word = ($difuplow?$word:strtoupper($word));
// Write cryptcode to the Session
switch (strtoupper($cryptsecure)) {
switch (strtoupper($cryptsecure)) {
case "MD5" : $_SESSION['cryptcode'] = md5($word); break;
case "SHA1" : $_SESSION['cryptcode'] = sha1($word); break;
default : $_SESSION['cryptcode'] = $word; break;
}
$_SESSION['crypttime'] = time();
$_SESSION['cryptcptuse']++;
$_SESSION['cryptcptuse']++;
// Render image
switch (strtoupper($cryptformat)) {
// Render image
switch (strtoupper($cryptformat)) {
case "JPG" :
case "JPEG" : if (imagetypes() & IMG_JPG) {
case "JPEG" : if (imagetypes() & IMG_JPG) {
header("Content-type: image/jpeg");
imagejpeg($img, "", 80);
}
break;
case "GIF" : if (imagetypes() & IMG_GIF) {
case "GIF" : if (imagetypes() & IMG_GIF) {
header("Content-type: image/gif");
imagegif($img);
}
break;
case "PNG" :
default : if (imagetypes() & IMG_PNG) {
case "PNG" :
default : if (imagetypes() & IMG_PNG) {
header("Content-type: image/png");
imagepng($img);
}
@@ -252,4 +243,4 @@ switch (strtoupper($cryptformat)) {
imagedestroy ($img);
unset ($word,$tword);
unset ($_SESSION['cryptreload']);
unset ($_SESSION['cryptreload']);

View File

@@ -2,4 +2,4 @@
session_start();
error_reporting(E_ALL ^ E_NOTICE);
SetCookie("cryptcookietest", "1");
Header("Location: cryptographp.inc.php?cfg=".$_GET['cfg']."&sn=".session_name()."&".SID);
Header("Location: cryptographp.inc.php?cfg=".$_GET['cfg']."&sn=".session_name()."&".SID);

View File

@@ -1,4 +1,4 @@
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
// Add New Options
Option::add('captcha_installed', 'true');
Option::add('captcha_installed', 'true');

View File

@@ -8,4 +8,4 @@
<plugin_version>1.0.0</plugin_version>
<plugin_author>Awilum</plugin_author>
<plugin_author_uri>http://monstra.org/</plugin_author_uri>
</root>
</root>

View File

@@ -1,4 +1,4 @@
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
// Delete Options
Option::delete('captcha_installed');
Option::delete('captcha_installed');

View File

@@ -1,9 +1,9 @@
<?php
return array(
'captcha' => array(
'Captcha' => 'Captcha',
'Captcha plugin for Monstra' => 'Captcha Plugin für Monstra',
'Captcha code is wrong' => 'Captcha Code ist falsch',
)
);
<?php
return array(
'captcha' => array(
'Captcha' => 'Captcha',
'Captcha plugin for Monstra' => 'Captcha Plugin für Monstra',
'Captcha code is wrong' => 'Captcha Code ist falsch',
)
);

View File

@@ -5,5 +5,5 @@
'Captcha' => 'Captcha',
'Captcha plugin for Monstra' => 'Captcha plugin for Monstra',
'Captcha code is wrong' => 'Captcha code is wrong',
)
);
)
);

View File

@@ -5,5 +5,5 @@
'Captcha' => 'Captcha',
'Captcha plugin for Monstra' => 'Captcha plugin per Monstra',
'Captcha code is wrong' => 'Codice captcha è errato',
)
);
)
);

View File

@@ -5,5 +5,5 @@
'Captcha' => 'Saugos kodas',
'Captcha plugin for Monstra' => 'Saugos kodo papildinys',
'Captcha code is wrong' => 'Saugos kodas yra neteisingas',
)
);
)
);

View File

@@ -5,5 +5,5 @@
'Captcha' => 'Captcha',
'Captcha plugin for Monstra' => 'Plugin de captcha para o Monstra CMS',
'Captcha code is wrong' => 'O Captcha está errado',
)
);
)
);

View File

@@ -5,5 +5,5 @@
'Captcha' => 'Captcha',
'Captcha plugin for Monstra' => 'Captcha плагин для Monstra',
'Captcha code is wrong' => 'Captcha код неправильный',
)
);
)
);

View File

@@ -5,5 +5,5 @@
'Captcha' => 'Каптча',
'Captcha plugin for Monstra' => 'Каптча плагін для Monstra',
'Captcha code is wrong' => 'Код каптчі невірний',
)
);
)
);