Example #1
0
function openCfg()
{
    global $cfg, $DIR, $PUBLIC;
    $cfg_fn = sprintf('%s/ec/epicollect.ini', rtrim($DIR, '/'));
    if (!file_exists($cfg_fn)) {
        makeCfg();
    }
    makedirs();
    try {
        $cfg = new ConfigManager($cfg_fn);
        if ($cfg->settings['security']['use_ldap'] && !function_exists('ldap_connect')) {
            $cfg->settings['security']['use_ldap'] = false;
            $cfg->writeConfig();
        }
        if (!array_key_exists('salt', $cfg->settings['security']) || trim($cfg->settings['security']['salt']) == '') {
            $str = genStr();
            $cfg->settings['security']['salt'] = $str;
            $cfg->writeConfig();
        }
        $PUBLIC = $cfg->settings['misc']['public_server'];
    } catch (Exception $err) {
        die('could not load configuration');
    }
}
Example #2
0
function getImg()
{
    $with = 160;
    $height = 80;
    $r = mt_rand(100, 255);
    $g = mt_rand(100, 255);
    $b = mt_rand(100, 255);
    $img = imagecreatetruecolor($with, $height);
    $bg = imagecolorallocate($img, $r, $g, $b);
    $color = imagecolorallocate($img, 7, 7, 7);
    imagefilledrectangle($img, 0, 0, $with, $height, $bg);
    for ($h = mt_rand(1, 10); $h < $height; $h = $h + mt_rand(1, 10)) {
        for ($w = mt_rand(1, 10); $w < $with; $w = $w + mt_rand(1, 20)) {
            imagesetpixel($img, $w, $h, $color);
        }
    }
    $str = genStr(1);
    $_SESSION['capcha'] = $str;
    $dir = opendir('fonts/');
    $fonts = array();
    while (FALSE != ($file = readdir($dir))) {
        if ($file == '.' or $file == '..') {
            continue;
        }
        $fonts[] = $file;
    }
    $x = 20;
    for ($i = 0; $i < strlen($str); $i++) {
        $font = 'fonts/' . $fonts[mt_rand(0, count($fonts) - 1)];
        $size = mt_rand(20, 35);
        $angle = mt_rand(-30, 30);
        $y = mt_rand(40, 45);
        imagettftext($img, $size, $angle, $x, $y, $color, $font, $str[$i]);
        $x += $size - 5;
    }
    for ($c = 0; $c < 5; $c++) {
        $x1 = mt_rand(0, intval($with * 0.1));
        $x2 = mt_rand(intval($with * 0.8), $with);
        $y1 = mt_rand(0, intval($height * 0.6));
        $y2 = mt_rand(intval($height * 0.3), $height);
        imageline($img, $x1, $y1, $x2, $y2, $color);
    }
    header('Content-Type: image/png');
    imagepng($img);
    imagedestroy($img);
}