Skip to content

Commit b76e4ae

Browse files
committed
Merge branch 'master' of github.com:serghey-rodin/vesta
2 parents 560d4e5 + 8082225 commit b76e4ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2383
-2102
lines changed

web/captcha.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta' . DIRECTORY_SEPARATOR . 'core' . DIRECTORY_SEPARATOR . 'VestaSession.class.php';
4+
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'Config.class.php';
5+
6+
define('V_ROOT_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR . 'vesta' . DIRECTORY_SEPARATOR);
7+
8+
class Captcha
9+
{
10+
protected $width = 200;
11+
protected $image = null;
12+
protected $color1 = null;
13+
protected $color2 = null;
14+
protected $color3 = null;
15+
protected $keyword = '';
16+
public $key_len = 7;
17+
protected $chars = 'qw1e2r3t4y5u67o8p9as9d38f6g4h3j2k1l3z5x7c8v3b5n781234567890';
18+
19+
public function __construct()
20+
{
21+
VestaSession::start();
22+
//var_dump(Config::get('session_dirname'));die();
23+
$this->image = imagecreatetruecolor($this->width, 50);
24+
$this->color1 = imagecolorallocate($this->image, 57, 58, 52);
25+
$this->color2 = imagecolorallocate($this->image, 45, 44, 40);
26+
$this->color3 = imagecolorallocate($this->image, 255, 255, 255);
27+
imagefilledrectangle($this->image, 0, 0, 249, 249, $this->color1);
28+
}
29+
30+
31+
public function generateImage($offset = 0)
32+
{
33+
$values = array(
34+
$offset, 15,
35+
$offset, 40,
36+
$offset + 14, 32,
37+
$offset + 14, 8,
38+
$offset, 15,
39+
$offset, 15
40+
);
41+
42+
imagefilledpolygon($this->image, $values, 6, $this->color2);
43+
}
44+
45+
public function draw()
46+
{
47+
$this->generateKeyword();
48+
for ($i = 0; $i < strlen($this->keyword) -1; $i++) {
49+
$this->generateImage($i * 15);
50+
}
51+
52+
$font_file = dirname(__FILE__).DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'arialbd.ttf';
53+
imagefttext($this->image, 17, 0, 2, 31, $this->color3, $font_file, $this->keyword);
54+
$this->slice();
55+
}
56+
57+
public function slice()
58+
{
59+
$width = 15;
60+
$height = 50;
61+
$dest = imagecreatetruecolor(15 * $this->key_len + 2 * $this->key_len + 8, $height);
62+
imagefilledrectangle($dest, 0, 0, 249, 249, $this->color1);
63+
64+
for ($i = 0; $i < $this->key_len; $i++) {
65+
$dest_x = $i == 0 ? $i * 15 : $i * 15 + $i * 4;
66+
imagecopy($dest, $this->image, $dest_x, 0, $i * 15, 0, $width, $height);
67+
}
68+
69+
header('Content-type: image/jpeg');
70+
imagepng($dest);
71+
}
72+
73+
/**
74+
*
75+
*/
76+
protected function generateKeyword()
77+
{
78+
$this->keyword = '';
79+
for ($i = 0; $i < $this->key_len; $i++) {
80+
$this->keyword .= $this->chars[rand(0, strlen($this->chars)-1)];
81+
}
82+
83+
$_SESSION['captcha_key'] = $this->keyword;
84+
return $this->keyword;
85+
}
86+
87+
}
88+
89+
$c = new Captcha();
90+
$c->draw();
91+
92+
93+
94+
?>

web/change_password.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
class ChangePassword
4+
{
5+
6+
public function dispatch()
7+
{
8+
//print_r($_SERVER);
9+
if (empty($_GET['v'])) {
10+
return $this->renderError('General error');
11+
}
12+
13+
$key = $_GET['v'];
14+
$real_key = sha1($_SERVER['HTTP_USER_AGENT'].$_SERVER['REMOTE_ADDR']);
15+
$key_sha1 = substr($key, 0, 10) . substr($key, 20, strlen($key));
16+
$stamp = substr($key, 10, 10);
17+
$allowed = time() - 60 * 5; // - 5 mins
18+
19+
if (strcmp($real_key, $key_sha1) != 0) {
20+
return $this->renderError('Invalid keys');
21+
}
22+
23+
/*if ($stamp < $allowed) {
24+
return $this->renderError('Key is expired');
25+
}*/
26+
27+
$this->showResetForm();
28+
print $key_sha1 . "<br />" . $real_key;
29+
}
30+
31+
public function showResetForm()
32+
{
33+
print <<<HTML
34+
<form action="" >
35+
<input type="hidden" name="action" value="change" />
36+
<label>Enter secret code:</label>
37+
<input type="text" name="secret_code" value="" />
38+
<label>Enter new password:</label>
39+
<input type="text" name="secret_code" value="" />
40+
</form>
41+
HTML;
42+
43+
}
44+
45+
public function renderError($message)
46+
{
47+
print <<<HTML
48+
{$message}
49+
HTML;
50+
51+
}
52+
53+
}
54+
55+
$changePassword = new ChangePassword();
56+
$changePassword->dispatch();
57+
58+
?>

web/css/arialbd.ttf

344 KB
Binary file not shown.

0 commit comments

Comments
 (0)