コード例 #1
0
ファイル: Captcha.php プロジェクト: netconstructor/LampCMS
 /**
  * Extracts the config array and generate needed params.
  *
  **/
 public function __construct(\Lampcms\Ini $Ini, array $config = array(), $secure = true, $debug = false)
 {
     $this->Ini = $Ini;
     $aConfig = !empty($config) ? $config : $Ini->getSection('CAPTCHA');
     d('Captcha config: ' . print_r($aConfig, 1));
     d("Captcha-Debug: The available GD-Library has major version " . $this->gd_version);
     $this->tempfolder = LAMPCMS_DATA_DIR . 'img' . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR;
     $this->TTF_folder = LAMPCMS_PATH . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR;
     d('$this->tempfolder: ' . $this->tempfolder . ' $this->TTF_folder: ' . $this->TTF_folder);
     // Hack prevention
     if (isset($_GET['maxtry']) || isset($_POST['maxtry']) || isset($_COOKIE['maxtry']) || (isset($_GET['debug']) || isset($_POST['debug']) || isset($_COOKIE['debug'])) || (isset($_GET['captcharefresh']) || isset($_COOKIE['captcharefresh'])) || isset($_POST['captcharefresh']) && isset($_POST['private_key'])) {
         d("Captcha-Debug: bad guy detected!");
         if (isset($this->badguys_url) && !headers_sent()) {
             header('Location: ' . $this->badguys_url);
         } else {
             throw new \Lampcms\Exception('Sorry but something is not right with this captcha image');
         }
     }
     // extracts config array
     if (!empty($aConfig)) {
         d("Captcha-Debug: Extracts Config-Array in secure-mode!");
         $valid = get_object_vars($this);
         // d('valid vars: '.print_r($valid, 1));
         foreach ($aConfig as $k => $v) {
             if (array_key_exists($k, $valid)) {
                 $this->{$k} = $v;
                 // key/val from $config become instance variables here
             }
         }
     }
     // check vars for maxtry, secretposition and min-max-size
     $this->maxtry = $this->maxtry > 9 || $this->maxtry < 1 ? 3 : $this->maxtry;
     $this->secretposition = $this->secretposition > 32 || $this->secretposition < 1 ? $this->maxtry : $this->secretposition;
     if ($this->minsize > $this->maxsize) {
         $temp = $this->minsize;
         $this->minsize = $this->maxsize;
         $this->maxsize = $temp;
         e("What do you think I mean with min and max? Switch minsize with maxsize.");
     }
     // check TrueTypeFonts
     if (is_array($this->TTF_RANGE)) {
         d("Check given TrueType-Array! (" . count($this->TTF_RANGE) . ")");
         $temp = array();
         foreach ($this->TTF_RANGE as $k => $v) {
             if (is_readable($this->TTF_folder . $v)) {
                 $temp[] = $v;
             }
         }
         $this->TTF_RANGE = $temp;
         d("Valid TrueType-files: (" . count($this->TTF_RANGE) . ")");
         if (count($this->TTF_RANGE) < 1) {
             throw new \Lampcms\Exception('No Truetypefont available for the CaptchaClass.');
         }
     } else {
         d("Check given TrueType-File! (" . $this->TTF_RANGE . ")");
         if (!is_readable($this->TTF_folder . $this->TTF_RANGE)) {
             throw new DevException('No Truetypefont available or TTF folder not readable ');
         }
     }
     // select first TrueTypeFont
     $this->change_TTF();
     d("Set current TrueType-File: (" . $this->TTF_file . ")");
     // get number of noise-chars for background if is enabled
     $this->nb_noise = $this->noise ? $this->chars * $this->noisefactor : 0;
     d("Set number of noise characters to: (" . $this->nb_noise . ")");
     // set dimension of image
     $this->lx = ($this->chars + 1) * (int) (($this->maxsize + $this->minsize) / 1.5);
     $this->ly = (int) (2.4 * $this->maxsize);
     d("Set image dimension to: (" . $this->lx . " x " . $this->ly . ")");
     d("Set messages to language: (" . $this->lang . ")");
     // check Postvars
     if (isset($_POST['public_key'])) {
         $this->public_K = substr(strip_tags($_POST['public_key']), 0, $this->chars);
     }
     /**
      * Replace Z with 0 for submitted captcha text
      * because we replace 0 with Z when generated image
      * So now we must make sure to replace it back to 0
      * str_replace('Z', '0',
      */
     if (isset($_POST['private_key'])) {
         $this->private_K = substr(strip_tags($_POST['private_key']), 0, $this->chars);
     }
     $this->current_try = isset($_POST['hncaptcha']) ? $this->get_try() : 0;
     if (!isset($_POST['captcharefresh'])) {
         $this->current_try++;
     }
     d("Check POST-vars, current try is: (" . $this->current_try . ")");
     // generate Keys
     $this->key = md5($this->secretstring);
     $this->public_key = substr(md5(uniqid(rand(), true)), 0, $this->chars);
     d('public key is: ' . $this->public_key);
 }
コード例 #2
0
ファイル: DB.php プロジェクト: netconstructor/LampCMS
 public function __construct(\Lampcms\Ini $Ini)
 {
     if (!\extension_loaded('mongo')) {
         throw new \OutOfBoundsException('Unable to use this program because PHP mongo extension not loaded. Make sure your php has mongo extension enabled. Exiting');
     }
     $aOptions = array('connect' => true);
     $aConfig = $Ini->getSection('MONGO');
     //d('$aConfig: '.print_r($aConfig, 1));
     $server = $aConfig['server'];
     /**
      * For Unit testing we define
      * MONGO_DBNAME to be LAMPCMS_TEST
      * so that actual database not used during testing
      *
      */
     $this->dbname = defined('MONGO_DBNAME') ? constant('MONGO_DBNAME') : $aConfig['db'];
     try {
         $this->conn = new \Mongo($server, $aOptions);
     } catch (\MongoException $e) {
         $err = 'LampcmsError unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     }
     if (!empty($aConfig['prefix'])) {
         $this->prefix = (string) $aConfig['prefix'];
     }
 }