コード例 #1
0
 /**
  * @return string
  */
 public static function getFilePrefix()
 {
     if (!self::$filePrefix) {
         self::$filePrefix = "test_" . CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_';
     }
     return self::$filePrefix;
 }
コード例 #2
0
ファイル: Request.php プロジェクト: kcristiano/civicrm-core
 /**
  * Get a unique ID for the request.
  *
  * This unique ID is assigned to mysql when the connection is opened and is
  * available in PHP.
  *
  * The intent is that it is available for logging purposes and for triggers.
  *
  * The resulting string is 17 characters long. This consists of 13 characters of uniqid
  * and 4 more random characters.
  *
  * Uniqid is unique to the microsecond - to make it more unique we add 4 more characters
  * but stop short of the full 23 character string that a prefix would generate.
  *
  * It is intended that this string will be saved to log tables so striking a balance between
  * uniqueness and length is important. Note that I did check & lining up with byte values
  * (e.g 16 characters) does not confer any benefits. Using a CHAR field rather than VARCHAR
  * may improve speed, if indexed.
  *
  * @return string
  */
 public static function id()
 {
     if (!isset(\Civi::$statics[__CLASS__]['id'])) {
         \Civi::$statics[__CLASS__]['id'] = uniqid() . CRM_Utils_String::createRandom(CRM_Utils_String::ALPHANUMERIC, 4);
     }
     return \Civi::$statics[__CLASS__]['id'];
 }
コード例 #3
0
ファイル: Signer.php プロジェクト: hguru/224Civi
 /**
  * Instantiate a signature-processor
  *
  * @param $secret string, private
  * @param $paramNames array, fields which should be part of the signature
  */
 function __construct($secret, $paramNames)
 {
     sort($paramNames);
     // ensure consistent serialization of payloads
     $this->secret = $secret;
     $this->paramNames = $paramNames;
     $this->signDelim = "_";
     // chosen to be valid in URLs but not in salt or md5
     $this->defaultSalt = CRM_Utils_String::createRandom(self::SALT_LEN, CRM_Utils_String::ALPHANUMERIC);
 }
コード例 #4
0
ファイル: StringTest.php プロジェクト: hyebahi/civicrm-core
 public function testRandom()
 {
     for ($i = 0; $i < 4; $i++) {
         $actual = CRM_Utils_String::createRandom(4, 'abc');
         $this->assertEquals(4, strlen($actual));
         $this->assertRegExp('/^[abc]+$/', $actual);
         $actual = CRM_Utils_String::createRandom(6, '12345678');
         $this->assertEquals(6, strlen($actual));
         $this->assertRegExp('/^[12345678]+$/', $actual);
     }
 }
コード例 #5
0
ファイル: Resources.php プロジェクト: nganivet/civicrm-core
 /**
  * @return CRM_Core_Resources
  */
 public function resetCacheCode()
 {
     $this->setCacheCode(CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC));
     // Also flush cms resource cache if needed
     CRM_Core_Config::singleton()->userSystem->clearResourceCache();
     return $this;
 }
コード例 #6
0
ファイル: Security.php プロジェクト: nielosz/civicrm-core
 /**
  * Determine whether $url is a public version of $dir in which files
  * are remotely accessible.
  *
  * @param string $dir
  *   Local dir path.
  * @param string $url
  *   Public URL.
  * @return bool
  */
 public function isDirAccessible($dir, $url)
 {
     $dir = rtrim($dir, '/');
     $url = rtrim($url, '/');
     if (empty($dir) || empty($url) || !is_dir($dir)) {
         return FALSE;
     }
     $result = FALSE;
     $file = 'delete-this-' . CRM_Utils_String::createRandom(10, CRM_Utils_String::ALPHANUMERIC);
     // this could be a new system with no uploads (yet) -- so we'll make a file
     file_put_contents("{$dir}/{$file}", "delete me");
     $headers = @get_headers("{$url}/{$file}");
     if (stripos($headers[0], '200')) {
         $content = @file_get_contents("{$url}/{$file}");
         if (preg_match('/delete me/', $content)) {
             $result = TRUE;
         }
     }
     unlink("{$dir}/{$file}");
     return $result;
 }
コード例 #7
0
 /**
  * Test setting and getting a custom file field value.
  *
  * Uses the "attachment" api for setting value.
  */
 public function testCustomFileField()
 {
     $customGroup = $this->customGroupCreate(array('title' => 'attachment_test_group'));
     $params = array('custom_group_id' => $customGroup['id'], 'name' => 'test_file_attachment', 'label' => 'test_file_attachment', 'html_type' => 'File', 'data_type' => 'File', 'is_active' => 1);
     $customField = $this->callAPISuccess('custom_field', 'create', $params);
     $cfId = 'custom_' . $customField['id'];
     $cid = $this->individualCreate();
     $attachment = $this->callAPISuccess('attachment', 'create', array('name' => CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC) . '_testCustomFileField.txt', 'mime_type' => 'text/plain', 'content' => 'My test content', 'field_name' => $cfId, 'entity_id' => $cid));
     $this->assertAttachmentExistence(TRUE, $attachment);
     $result = $this->callAPISuccess('contact', 'getsingle', array('id' => $cid, 'return' => $cfId));
     $this->assertEquals($attachment['id'], $result[$cfId]);
 }
コード例 #8
0
 /**
  * Reset navigation for all contacts or a specified contact.
  *
  * @param int $contactID
  *   Reset only entries belonging to that contact ID.
  *
  * @return string
  */
 public static function resetNavigation($contactID = NULL)
 {
     $newKey = CRM_Utils_String::createRandom(self::CACHE_KEY_STRLEN, CRM_Utils_String::ALPHANUMERIC);
     if (!$contactID) {
         $query = "UPDATE civicrm_setting SET value = '{$newKey}' WHERE name='navigation' AND contact_id IS NOT NULL";
         CRM_Core_DAO::executeQuery($query);
         CRM_Core_BAO_Cache::deleteGroup('navigation');
     } else {
         // before inserting check if contact id exists in db
         // this is to handle weird case when contact id is in session but not in db
         $contact = new CRM_Contact_DAO_Contact();
         $contact->id = $contactID;
         if ($contact->find(TRUE)) {
             CRM_Core_BAO_Setting::setItem($newKey, CRM_Core_BAO_Setting::PERSONAL_PREFERENCES_NAME, 'navigation', NULL, $contactID, $contactID);
         }
     }
     // also reset the dashlet cache in case permissions have changed etc
     // FIXME: decouple this
     CRM_Core_BAO_Dashboard::resetDashletCache($contactID);
     return $newKey;
 }
コード例 #9
0
 public function resetCacheCode()
 {
     $this->setCacheCode(CRM_Utils_String::createRandom(5, CRM_Utils_String::ALPHANUMERIC));
 }
コード例 #10
0
 /**
  * Determine whether $url is a public, browsable listing for $dir
  *
  * @param string $dir local dir path
  * @param string $url public URL
  * @return bool
  */
 public function isBrowsable($dir, $url)
 {
     if (empty($dir) || empty($url) || !is_dir($dir)) {
         return FALSE;
     }
     $result = FALSE;
     $file = 'delete-this-' . CRM_Utils_String::createRandom(10, CRM_Utils_String::ALPHANUMERIC);
     // this could be a new system with no uploads (yet) -- so we'll make a file
     file_put_contents("{$dir}/{$file}", "delete me");
     $content = @file_get_contents("{$url}");
     if (stristr($content, $file)) {
         $result = TRUE;
     }
     unlink("{$dir}/{$file}");
     return $result;
 }