示例#1
0
 public function __construct_5($code, $fontFolder, $minFontSize, $maxFontSize, $maxRotation)
 {
     if (!function_exists('imagettftext')) {
         throw new \System\Error\Exception\SystemException('Requires FreeType support. Please enable PHP FreeType');
     }
     $this->fontFolder = $fontFolder;
     $this->ttfFiles = \System\IO\Directory::walkDir($fontFolder, new \System\Collection\Vector('ttf'));
     $this->width = (strlen($code) + 1) * intval(($minFontSize + $maxFontSize) / self::CAPTCHA_WIDTH_FACTOR);
     $this->height = intval(self::CAPTCHA_HEIGHT_FACTOR * $maxFontSize);
     $this->minFontSize = $minFontSize;
     $this->maxFontSize = $maxFontSize;
     $this->maxRotation = $maxRotation;
     $this->image = imagecreatetruecolor($this->width, $this->height);
     $bgcolor = imagecolorallocate($this->image, mt_rand(224, 255), mt_rand(224, 255), mt_rand(224, 255));
     imagefill($this->image, 0, 0, $bgcolor);
     $this->createBackground();
     $chars = str_split($code);
     $xPos = mt_rand($minFontSize, $maxFontSize);
     foreach ($chars as $char) {
         $size = mt_rand($minFontSize, $maxFontSize);
         $rotation = mt_rand($maxRotation * -1, $maxRotation);
         $yPos = mt_rand(intval($size * self::CAPTCHA_WIDTH_FACTOR), intval($this->height - $size / 4));
         $r = mt_rand(0, 127);
         $g = mt_rand(0, 127);
         $b = mt_rand(0, 127);
         $color = imagecolorallocate($this->image, $r, $g, $b);
         $shadow = imagecolorallocate($this->image, $r + 127, $g + 127, $b + 127);
         $ttfFile = $this->getNextTTFFile();
         imagettftext($this->image, $size, $rotation, $xPos + mt_rand(1, 5), $yPos + mt_rand(0, 5), $shadow, $ttfFile, $char);
         imagettftext($this->image, $size, $rotation, $xPos, $yPos, $color, $ttfFile, $char);
         $xPos += intval($size + $minFontSize / 3);
     }
     $watermarkImage = imagecreatefromstring(base64_decode($this->refreshIcon));
     $origSX = imagesx($this->image);
     $origSY = imagesy($this->image);
     $waterSX = imagesx($watermarkImage);
     $waterSY = imagesy($watermarkImage);
     $destX = $origSX - $waterSX - 5;
     $destY = $origSY - $waterSY - 5;
     imagecopy($this->image, $watermarkImage, $destX, $destY, 0, 0, $waterSX, $waterSY);
     imagedestroy($watermarkImage);
 }
示例#2
0
 /**
  * Creates a fingerprint of the entire system and returns it as an encoded json string. This fingerprint only gives information about the system version.
  * By using this fingerprint, we can identify the versions used in the currently deployed build
  * Note that the used encryption is not a secure one.
  * @param string The key used to encode the resultset and generate the hashes. This key is required for decryption.
  * @return string The encoded fingerprint
  */
 public static final function getSystemFingerprint($encodeKey = \System\Version::FINGERPRINT_KEY)
 {
     $baseDir = PATH_SYSTEM;
     $files = \System\IO\Directory::walkDir($baseDir, new \System\Collection\Vector('php'));
     $map = new \System\Collection\Map();
     foreach ($files as $file) {
         $hash = new \System\Security\Hash(\System\Security\Hash::HASH_SHA512);
         $hash->addFile($file);
         $map[\System\Security\Base64Encoding::Base64Encode($file->stripBase(PATH_SYSTEM), $encodeKey)] = $hash->getHash();
     }
     $jsonObject = json_encode($map->getArrayCopy());
     $encoded = \System\Security\XOREncoding::XOREncrypt($jsonObject, $encodeKey);
     return $encoded;
 }
示例#3
0
 private static final function copyFiles(\System\IO\Directory $targetFolder, $sourceFolder, \System\Collection\Vector $fileMask, $baseSubfolder)
 {
     $files = \System\IO\Directory::walkDir($sourceFolder, $fileMask);
     $target = new \System\IO\Directory($targetFolder->getCurrentPath() . \System\IO\Directory::getSeparator() . $baseSubfolder);
     foreach ($files as $file) {
         $baseFile = $file->stripBase($sourceFolder);
         $folderParts = preg_split('/\\\\/', $baseFile);
         array_pop($folderParts);
         $newPath = $target->getCurrentPath();
         foreach ($folderParts as $part) {
             $newPath = \System\IO\Directory::getPath($newPath . \System\IO\Directory::getSeparator() . $part);
             if (!file_exists($newPath)) {
                 mkdir($newPath, 0777, true);
             }
         }
         $newPath .= \System\IO\Directory::getSeparator() . $file->getFilename();
         $file->copyFile($newPath);
     }
 }