Example #1
0
 /**
  * @covers JCrypt::genRandomBytes
  */
 public function testGenRandomBytes()
 {
     // We're just testing wether the value has the expected length,
     // we obviously can't test the result since it's random.
     $randomBytes16 = JCrypt::genRandomBytes();
     $this->assertEquals(strlen($randomBytes16), 16);
     $randomBytes8 = JCrypt::genRandomBytes(8);
     $this->assertEquals(strlen($randomBytes8), 8);
     $randomBytes17 = JCrypt::genRandomBytes(17);
     $this->assertEquals(strlen($randomBytes17), 17);
 }
 protected static function generateKey()
 {
     jimport('joomla.crypt.crypt');
     $key = JCrypt::genRandomBytes(32);
     $salt = md5_file(JPATH_SITE . '/configuration.php');
     $key = base64_encode(self::pbkdf2($key, $salt, 32));
     $filecontents = "<?php defined('WF_EDITOR') or die(); define('WF_SERVERKEY', '{$key}'); ?>";
     $filename = JPATH_COMPONENT_ADMINISTRATOR . '/serverkey.php';
     $result = JFile::write($filename, $filecontents);
     if (!$result) {
         return '';
     } else {
         return base64_decode($key);
     }
 }
Example #3
0
 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     jimport('joomla.filesystem.file');
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = JPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = is_writable('/tmp') ? '/tmp' : false;
     $dir = !$dir && is_writable($ssp) ? $ssp : false;
     $dir = !$dir && is_writable($jtp) ? $jtp : false;
     if ($dir) {
         $fileObject = new JFilesystemWrapperFile();
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         $fileObject->write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         $fileObject->delete($test);
         return $return;
     }
     return false;
 }
Example #4
0
 /**
  * Method to generate a new encryption key object.
  *
  * @param   array  $options  Key generation options.
  *
  * @return  JCryptKey
  *
  * @since   12.1
  * @throws  InvalidArgumentException
  */
 public function generateKey(array $options = array())
 {
     // Create the new encryption key object.
     $key = new JCryptKey($this->keyType);
     // Generate an initialisation vector based on the algorithm.
     $key->public = mcrypt_create_iv(mcrypt_get_iv_size($this->type, $this->mode));
     // Get the salt and password setup.
     $salt = isset($options['salt']) ? $options['salt'] : substr(pack("h*", md5(JCrypt::genRandomBytes())), 0, 16);
     if (!isset($options['password'])) {
         throw new InvalidArgumentException('Password is not set.');
     }
     // Generate the derived key.
     $key->private = $this->pbkdf2($options['password'], $salt, mcrypt_get_key_size($this->type, $this->mode));
     return $key;
 }
 /**
  * Generates a salt of specified length. The salt consists of characters in the set [./0-9A-Za-z].
  *
  * @param   integer  $length  The number of characters to return.
  *
  * @return  string  The string of random characters.
  *
  * @since   12.2
  */
 protected function getSalt($length)
 {
     $bytes = ceil($length * 6 / 8);
     $randomData = str_replace('+', '.', base64_encode(JCrypt::genRandomBytes($bytes)));
     return substr($randomData, 0, $length);
 }
Example #6
0
 public function check()
 {
     if ($this->container->platform->isFrontend()) {
         $this->user_id = $this->container->platform->getUser()->id;
     }
     $db = $this->getDbo();
     // Should this be a primary or a secondary DLID?
     if (is_null($this->primary)) {
         // Do I have another primary?
         $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__ars_dlidlabels'))->where($db->qn('user_id') . ' = ' . $db->q($this->user_id))->where($db->qn('primary') . ' = ' . $db->q(1));
         if ($this->ars_dlidlabel_id) {
             $query->where('NOT(' . $db->qn('ars_dlidlabel_id') . ' = ' . $db->q($this->ars_dlidlabel_id) . ')');
         }
         $hasPrimary = $db->setQuery($query)->loadResult();
         $this->primary = $hasPrimary ? 0 : 1;
     }
     if ($this->primary) {
         // You can never disable a primary Download ID
         $this->enabled = 1;
         // The primary Download ID title is fixed
         $this->label = '_MAIN_';
     }
     // Do I need to generate a download ID?
     if (empty($this->dlid)) {
         while (empty($this->dlid)) {
             $this->dlid = md5(\JCrypt::genRandomBytes(64));
             // Do I have another primary?
             $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__ars_dlidlabels'))->where($db->qn('dlid') . ' = ' . $db->q($this->dlid))->where($db->qn('user_id') . ' = ' . $db->q($this->user_id))->where($db->qn('primary') . ' = ' . $db->q($this->primary));
             if ($this->ars_dlidlabel_id) {
                 $query->where('NOT(' . $db->qn('ars_dlidlabel_id') . ' = ' . $db->q($this->ars_dlidlabel_id) . ')');
             }
             $dlidColission = $db->setQuery($query)->loadResult();
             if ($dlidColission) {
                 $this->dlid = null;
             }
         }
     }
     return parent::check();
 }
Example #7
0
 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->pointsgen)) {
         return;
     }
     parent::pluginParams($pack->pointsgen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         $serialObj = new stdClass();
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
                 } else {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[($shift + ord($random[$rndCpt])) % $base];
                         $shift += ord($random[$rndCpt++]);
                         if ($rndCpt == $this->plugin_params->size) {
                             $rndCpt = 1;
                             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
                             $shift = ord($random[0]);
                         }
                     }
                 }
             }
         }
         if (!$this->test) {
             if (!isset($serialObj->extradata)) {
                 $serialObj->extradata = array();
             }
             $serialObj->extradata['points_value'] = (int) $this->plugin_params->value;
             if (!empty($this->plugin_params->currency_rate)) {
                 $v = hikaserial::toFloat(trim($this->plugin_params->currency_rate));
                 $product_price = 0;
                 if (!empty($order->cart->products)) {
                     foreach ($order->cart->products as $p) {
                         if ($p->product_id == $pack->product_id || isset($pack->order_product_id) && $p->order_product_id == $pack->order_product_id) {
                             $product_price = hikaserial::toFloat($p->order_product_price);
                             if (!empty($this->plugin_params->discount_percent_tax)) {
                                 $product_price += hikaserial::toFloat($p->order_product_tax);
                             }
                             break;
                         }
                     }
                 }
                 if (!empty($product_price)) {
                     $shopConfig = hikaserial::config(false);
                     $main_currency = $shopConfig->get('main_currency', 1);
                     $currencyClass = hikaserial::get('shop.class.currency');
                     $currency = $currencyClass->get($main_currency);
                     if (isset($order->order_currency_id)) {
                         $order_currency_id = $order->order_currency_id;
                     } else {
                         $order_currency_id = hikashop_getCurrency();
                     }
                     if ($main_currency != $order_currency_id) {
                         $product_price = $currencyClass->convertUniquePrice($product_price, $main_currency, $order_currency_id);
                     }
                     $serialObj->extradata['points_value'] += (int) ($product_price / $v);
                 }
             }
             if (!empty($order->hikaserial->formData['points_value'])) {
                 $serialObj->extradata['points_value'] += (int) $order->hikaserial->formData['points_value'];
             }
         }
         if (!empty($serialObj) && !empty($serialObj->extradata)) {
             $serialObj->data = $serial;
             $serials[] = $serialObj;
         } else {
             $serials[] = $serial;
         }
     }
 }
Example #8
0
File: client.php Project: 01J/topm
 /**
  * Method used to generate the current nonce.
  *
  * @return  string  The current nonce.
  *
  * @since   13.1
  */
 public static function generateNonce()
 {
     $mt = microtime();
     $rand = JCrypt::genRandomBytes();
     // The md5s look nicer than numbers.
     return md5($mt . $rand);
 }
Example #9
0
 /**
  * Generates a set of One Time Emergency Passwords (OTEPs) for a user. Technique taken from Joomla
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public static function generateOteps($otpConfig, $count = 10)
 {
     // Initialise
     $oteps = array();
     // If two factor authentication is not enabled, abort
     if (empty($otpConfig->method) || $otpConfig->method == 'none') {
         return $oteps;
     }
     $salt = "0123456789";
     $base = strlen($salt);
     $length = 16;
     for ($i = 0; $i < $count; $i++) {
         $makepass = '';
         $random = JCrypt::genRandomBytes($length + 1);
         $shift = ord($random[0]);
         for ($j = 1; $j <= $length; ++$j) {
             $makepass .= $salt[($shift + ord($random[$j])) % $base];
             $shift += ord($random[$j]);
         }
         $oteps[] = $makepass;
     }
     return $oteps;
 }
Example #10
0
 /**
  * Return a random 32 byte hash value.
  * @param string extra entropy data
  */
 static function hash($length = 32)
 {
     require_once MODPATH . "gallery/vendor/joomla/crypt.php";
     return md5(JCrypt::genRandomBytes($length));
 }
Example #11
0
 /**
  * Method to generate a new encryption key[/pair] object.
  *
  * @param   array  $options  Key generation options.
  *
  * @return  JCryptKey
  *
  * @since   12.1
  */
 public function generateKey(array $options = array())
 {
     // Create the new encryption key[/pair] object.
     $key = new JCryptKey('simple');
     // Just a random key of a given length.
     $key->private = JCrypt::genRandomBytes(256);
     $key->public = $key->private;
     return $key;
 }
Example #12
0
 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->randomgen)) {
         return;
     }
     parent::pluginParams($pack->randomgen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
                 } else {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[($shift + ord($random[$rndCpt])) % $base];
                         $shift += ord($random[$rndCpt++]);
                         if ($rndCpt == $this->plugin_params->size) {
                             $rndCpt = 1;
                             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
                             $shift = ord($random[0]);
                         }
                     }
                 }
             }
         }
         $serials[] = $serial;
     }
     return true;
 }
Example #13
0
 /**
  * Method to generate a random string from a certain range of characters
  *
  * @param   int     $length  Length of the required string
  * @param   string  $range   Characters containing the range
  *
  * @return array
  */
 protected function generateRandomStringFromRange($length, $range)
 {
     $base = strlen($range);
     $randomChars = array();
     $random = JCrypt::genRandomBytes($length + 1);
     $shift = ord($random[0]);
     for ($i = 1; $i <= $length; ++$i) {
         $randomChars[] = $range[($shift + ord($random[$i])) % $base];
         $shift += ord($random[$i]);
     }
     return $randomChars;
 }
Example #14
0
 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     jimport('joomla.filesystem.file');
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = JPATH_SITE . '/tmp';
     // Try to find a writable directory
     $dir = false;
     foreach (array($jtp, $ssp, '/tmp') as $currentDir) {
         if (is_writable($currentDir)) {
             $dir = $currentDir;
             break;
         }
     }
     if ($dir) {
         $fileObject = new JFilesystemWrapperFile();
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         $fileObject->write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         $fileObject->delete($test);
         return $return;
     }
     return false;
 }
Example #15
0
 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->coupongen)) {
         return;
     }
     parent::pluginParams($pack->coupongen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         $serialObj = new stdClass();
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
                 } else {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[($shift + ord($random[$rndCpt])) % $base];
                         $shift += ord($random[$rndCpt++]);
                         if ($rndCpt == $this->plugin_params->size) {
                             $rndCpt = 1;
                             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
                             $shift = ord($random[0]);
                         }
                     }
                 }
             }
         }
         $discount_id = (int) $this->plugin_params->discount_id;
         $result = true;
         if (!$this->test && !empty($discount_id)) {
             $discountClass = hikaserial::get('shop.class.discount');
             $data = $discountClass->get($discount_id);
             if ($data) {
                 unset($data->discount_id);
                 $data->discount_code = $serial;
                 $data->discount_published = 1;
                 $data->discount_used_times = 0;
                 if (!empty($this->plugin_params->validity_period) && !empty($this->plugin_params->validity_value) && (int) $this->plugin_params->validity_value > 0) {
                     $date_d = date("d");
                     $date_m = date("m");
                     $date_y = date("Y");
                     $v = (int) $this->plugin_params->validity_value;
                     switch ($this->plugin_params->validity_period) {
                         case 'year':
                             $data->discount_end = mktime(0, 0, 0, $date_m, $date_d, $date_y + $v);
                             break;
                         case 'month':
                             $data->discount_end = mktime(0, 0, 0, $date_m + $v, $date_d, $date_y);
                             break;
                         case 'day':
                             $data->discount_end = mktime(0, 0, 0, $date_m, $date_d + $v, $date_y);
                             break;
                     }
                     if (!isset($serialObj->extradata)) {
                         $serialObj->extradata = array();
                     }
                     $serialObj->extradata['discount_end'] = $data->discount_end;
                 }
                 if (!empty($this->plugin_params->discount_percent)) {
                     $v = hikaserial::toFloat(trim($this->plugin_params->discount_percent));
                     $product_price = 0;
                     if (!empty($order->cart->products)) {
                         foreach ($order->cart->products as $p) {
                             if ($p->product_id == $pack->product_id || isset($pack->order_product_id) && $p->order_product_id == $pack->order_product_id) {
                                 $product_price = hikaserial::toFloat($p->order_product_price);
                                 if (!empty($this->plugin_params->discount_percent_tax)) {
                                     $product_price += hikaserial::toFloat($p->order_product_tax);
                                 }
                                 break;
                             }
                         }
                     }
                     if (!empty($product_price)) {
                         if (!empty($order->order_currency_id)) {
                             $data->discount_currency_id = (int) $order->order_currency_id;
                         } else {
                             $data->discount_currency_id = (int) $order->old->order_currency_id;
                         }
                         $data->discount_flat_amount = $product_price * $v / 100;
                         $data->discount_percent_amount = 0.0;
                     }
                 }
                 if (!$discountClass->save($data)) {
                     $result = false;
                 }
             }
         }
         if (!$result) {
             $app = JFactory::getApplication();
             $app->enqueueMessage(JText::_('ERR_CREATING_DISCOUNT_COUPON'));
         }
         if (!empty($serialObj) && !empty($serialObj->extradata)) {
             $serialObj->data = $serial;
             $serials[] = $serialObj;
         } else {
             $serials[] = $serial;
         }
     }
 }
Example #16
0
 /**
  * Generates a new set of One Time Emergency Passwords (OTEPs) for a given user.
  *
  * @param   integer  $user_id  The user ID
  * @param   integer  $count    How many OTEPs to generate? Default: 10
  *
  * @return  array  The generated OTEPs
  *
  * @since   3.2
  */
 public function generateOteps($user_id, $count = 10)
 {
     $user_id = !empty($user_id) ? $user_id : (int) $this->getState('user.id');
     // Initialise
     $oteps = array();
     // Get the OTP configuration for the user
     $otpConfig = $this->getOtpConfig($user_id);
     // If two factor authentication is not enabled, abort
     if (empty($otpConfig->method) || $otpConfig->method == 'none') {
         return $oteps;
     }
     $salt = "0123456789";
     $base = strlen($salt);
     $length = 16;
     for ($i = 0; $i < $count; $i++) {
         $makepass = '';
         $random = JCrypt::genRandomBytes($length + 1);
         $shift = ord($random[0]);
         for ($j = 1; $j <= $length; ++$j) {
             $makepass .= $salt[($shift + ord($random[$j])) % $base];
             $shift += ord($random[$j]);
         }
         $oteps[] = $makepass;
     }
     $otpConfig->otep = $oteps;
     // Save the now modified OTP configuration
     $this->setOtpConfig($user_id, $otpConfig);
     return $oteps;
 }
Example #17
0
 /**
  * Method to determine if script owns the path.
  *
  * @param   string  $path  Path to check ownership.
  *
  * @return  boolean  True if the php script owns the path passed.
  *
  * @since   11.1
  */
 public static function isOwner($path)
 {
     $tmp = md5(JCrypt::genRandomBytes());
     $ssp = ini_get('session.save_path');
     $jtp = PATH_PROJECT . '/data/tmp';
     // Try to find a writable directory
     $dir = is_writable('/tmp') ? '/tmp' : false;
     $dir = !$dir && is_writable($ssp) ? $ssp : false;
     $dir = !$dir && is_writable($jtp) ? $jtp : false;
     if ($dir) {
         $test = $dir . '/' . $tmp;
         // Create the test file
         $blank = '';
         App_Filesystem_File::write($test, $blank, false);
         // Test ownership
         $return = fileowner($test) == fileowner($path);
         // Delete the test file
         App_Filesystem_File::delete($test);
         return $return;
     }
     return false;
 }
Example #18
0
 /**
  * Generate a random password
  *
  * @param   integer  $length  Length of the password to generate
  *
  * @return  string  Random Password
  *
  * @since   11.1
  */
 public static function genRandomPassword($length = 8)
 {
     $salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
     $base = strlen($salt);
     $makepass = '';
     /*
      * Start with a cryptographic strength random string, then convert it to
      * a string with the numeric base of the salt.
      * Shift the base conversion on each character so the character
      * distribution is even, and randomize the start shift so it's not
      * predictable.
      */
     $random = JCrypt::genRandomBytes($length + 1);
     $shift = ord($random[0]);
     for ($i = 1; $i <= $length; ++$i) {
         $makepass .= $salt[($shift + ord($random[$i])) % $base];
         $shift += ord($random[$i]);
     }
     return $makepass;
 }
Example #19
0
 public function generate(&$pack, &$order, $quantity, &$serials)
 {
     if (!isset($pack->timelimitedgen)) {
         return;
     }
     parent::pluginParams($pack->timelimitedgen);
     if (empty($this->plugin_params->format) || !preg_match_all('#\\\\[|\\\\]|\\[[^]]+\\]\\{.*\\}|\\[.*\\]|.#iU', $this->plugin_params->format, $matches)) {
         $matches = array(array('[a-zA-Z0-9]{size}'));
     }
     $config = hikaserial::config();
     $fastRandom = (int) $config->get('use_fast_random', 0);
     for ($q = 0; $q < $quantity; $q++) {
         $serial = '';
         $serialObj = new stdClass();
         if (!HIKASHOP_J16 || $fastRandom) {
             $stat = @stat(__FILE__);
             if (empty($stat) || !is_array($stat)) {
                 $stat = array(php_uname());
             }
             mt_srand(crc32(microtime() . implode('|', $stat)));
         } else {
             if (empty($this->plugin_params->size) || $this->plugin_params->size == 0) {
                 $this->plugin_params->size = 15;
             }
             $rndCpt = 1;
             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
             $shift = ord($random[0]);
         }
         foreach ($matches[0] as $m) {
             if (strlen($m) == 1) {
                 $serial .= $m;
             } else {
                 $repeat = 1;
                 $format = $m;
                 if (strpos($m, '{') !== false) {
                     list($format, $repeat) = explode('{', $m);
                     $repeat = trim(trim($repeat, '}'));
                     if (empty($repeat) || (int) $repeat == 0) {
                         $repeat = $this->plugin_params->size;
                     } else {
                         $repeat = (int) $repeat;
                     }
                 }
                 $format = substr($format, 1, -1);
                 $list = '';
                 $l = strlen($format);
                 for ($i = 0; $i < $l; $i++) {
                     if ($i + 2 < $l) {
                         if ($format[$i + 1] == '-') {
                             $s = $format[$i];
                             $e = $format[$i + 2];
                             $s1 = $s >= 'a' && $s <= 'z';
                             $s2 = $s >= 'A' && $s <= 'Z';
                             $s3 = $s >= '0' && $s <= '9';
                             $e1 = $e >= 'a' && $e <= 'z';
                             $e2 = $e >= 'A' && $e <= 'Z';
                             $e3 = $e >= '0' && $e <= '9';
                             if (!$s1 && !$s2 && !$s3) {
                                 $list .= $s . '-';
                                 $i++;
                                 // Skip '-'
                                 continue;
                             }
                             if ($s1 && $e1 || $s2 && $e2 || $s3 && $e3) {
                                 if ($s > $e) {
                                     $c = $s;
                                     $s = $e;
                                     $e = $c;
                                 }
                                 for ($c = $s; $c < $e; $c++) {
                                     $list .= $c;
                                 }
                                 $i += 2;
                             } else {
                                 if ($s1 && $e2) {
                                     for ($c = $s; $c < 'z'; $c++) {
                                         $list .= $c;
                                     }
                                     for ($c = 'A'; $c < $e; $c++) {
                                         $list .= $c;
                                     }
                                     $i += 2;
                                 } else {
                                     $list .= $s . '-';
                                     $i++;
                                     // Skip '-'
                                 }
                             }
                         } else {
                             $list .= $format[$i];
                         }
                     } else {
                         $list .= $format[$i];
                     }
                 }
                 $base = strlen($list);
                 if (!HIKASHOP_J16 || $fastRandom) {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[mt_rand(0, $base - 1)];
                     }
                 } else {
                     for ($i = 1; $i <= $repeat; $i++) {
                         $serial .= $list[($shift + ord($random[$rndCpt])) % $base];
                         $shift += ord($random[$rndCpt++]);
                         if ($rndCpt == $this->plugin_params->size) {
                             $rndCpt = 1;
                             $random = JCrypt::genRandomBytes($this->plugin_params->size + 1);
                             $shift = ord($random[0]);
                         }
                     }
                 }
             }
         }
         if (!empty($this->plugin_params->validity_period) && !empty($this->plugin_params->validity_value) && (int) $this->plugin_params->validity_value > 0) {
             $date_d = date("d");
             $date_m = date("m");
             $date_y = date("Y");
             $v = (int) $this->plugin_params->validity_value;
             $discount_end = -1;
             switch ($this->plugin_params->validity_period) {
                 case 'year':
                     $discount_end = mktime(0, 0, 0, $date_m, $date_d, $date_y + $v);
                     break;
                 case 'month':
                     $discount_end = mktime(0, 0, 0, $date_m + $v, $date_d, $date_y);
                     break;
                 case 'day':
                     $discount_end = mktime(0, 0, 0, $date_m, $date_d + $v, $date_y);
                     break;
             }
             if ($discount_end > 0) {
                 if (!isset($serialObj->extradata)) {
                     $serialObj->extradata = array();
                 }
                 $serialObj->extradata['validity_end'] = $discount_end;
             }
         }
         if (empty($this->test) && !empty($serialObj) && !empty($serialObj->extradata)) {
             $serialObj->data = $serial;
             $serials[] = $serialObj;
         } else {
             $serials[] = $serial;
         }
     }
     return true;
 }