Esempio n. 1
0
 /**
  * Extracts the config array and generate needed params.
  *
  * @param \Lampcms\Config\Ini $Ini
  * @param array               $config
  * @param bool                $secure
  * @param bool                $debug
  *
  * @throws \Lampcms\Exception
  * @throws \Lampcms\DevException
  */
 public function __construct(\Lampcms\Config\Ini $Ini, array $config = array(), $secure = true, $debug = false)
 {
     $this->Ini = $Ini;
     $aConfig = !empty($config) ? $config : $Ini->getSection('CAPTCHA');
     d('Captcha config: ' . \json_encode($aConfig));
     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_file = LAMPCMS_CONFIG_DIR . DIRECTORY_SEPARATOR . 'fonts' . DIRECTORY_SEPARATOR . 'font.ttf';
     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.");
     }
     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);
 }
Esempio n. 2
0
 /**
  * Constructor
  *
  * @param \Lampcms\Config\Ini $Ini
  */
 public function __construct(\Lampcms\Config\Ini $Ini)
 {
     $this->Ini = $Ini;
     $this->map = $Ini->getSection('URI_PARTS');
     $this->routes = $Ini->getSection('ROUTES');
     $this->init();
 }
Esempio n. 3
0
 public function __construct(\Lampcms\Config\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');
     }
     $this->Ini = $Ini;
     $aOptions = array('connect' => true);
     $aConfig = $Ini->getSection('MONGO');
     $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 {
         /**
          * Need to lower to error reporting level just for
          * this method because Mongo may raise notices
          * that we are not interested in.
          * We only care about actual exceptions
          */
         $ER = \error_reporting(0);
         /**
          * Prefered way it to use MongoClient
          * but some older versions on mongo php extension may still
          * not have this class and only have Mongo class available
          * Must use 'false' in class_exists so taht our autoloader will
          * not kick-in in case native MongoClient class is not loaded
          * because our own autoloader will end up throwing exception in this case becase
          * we don't have our own MongoClient.php file anywhere.
          */
         if (\class_exists('\\MongoClient', false)) {
             $this->conn = new \MongoClient($server, $aOptions);
         } else {
             $this->conn = new \Mongo($server, $aOptions);
         }
         /**
          * Return error reporting level to original value
          */
         \error_reporting($ER);
     } catch (\MongoConnectionException $e) {
         $err = 'MongoConnectionException caught. Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     } catch (\MongoException $e) {
         $err = 'MongoException caught. Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     } catch (DevException $e) {
         $err = 'Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
     } catch (\Exception $e) {
         /**
          * This will not be a MongoException
          * because mongo connection process will not throw exception,
          * it will raise php error or warning which is then
          * processed by out error handler and turned into DevException
          * So we are getting DevException here but may also
          * get MongoException
          */
         $err = 'Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     }
     if (null === $this->conn) {
         throw new DevException('No connection to MongoDB');
     }
     if (!empty($aConfig['prefix'])) {
         $this->prefix = (string) $aConfig['prefix'];
     }
 }
Esempio n. 4
0
 public function __construct(\Lampcms\Config\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');
     }
     $this->Ini = $Ini;
     $aOptions = array('connect' => true);
     $aConfig = $Ini->getSection('MONGO');
     $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 {
         /**
          * Need to lower to error reporting level just for
          * this method because Mongo may raise notices
          * that we are not interested in.
          * We only care about actual exceptions
          */
         $ER = \error_reporting(0);
         $this->conn = new \Mongo($server, $aOptions);
         \error_reporting($ER);
     } catch (\MongoConnectionException $e) {
         $err = 'MongoConnectionException caught. Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     } catch (\MongoException $e) {
         $err = 'MongoException caught. Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     } catch (DevException $e) {
         $err = 'Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
     } catch (\Exception $e) {
         /**
          * This will not be a MongoException
          * because mongo connection process will not throw exception,
          * it will raise php error or warning which is then
          * processed by out error handler and turned into DevException
          * So we are getting DevException here but may also
          * get MongoException
          */
         $err = 'Unable to connect to Mongo: ' . $e->getMessage();
         e($err);
         throw new DevException($err);
     }
     if (null === $this->conn) {
         throw new DevException('No connection to MongoDB');
     }
     if (!empty($aConfig['prefix'])) {
         $this->prefix = (string) $aConfig['prefix'];
     }
 }