initial version of fulcrm_uuid

master
Marek Isalski 8 years ago
commit ae97c26bfb

@ -0,0 +1,5 @@
name = fulcrm webhook
description = fulcrm webhooks
core = 7.x
package = fulcrm
configure = admin/config/services/fulcrm/webhook

@ -0,0 +1,32 @@
<?php /* -*- php -*- */
function _fulcrm_uuid_stir_entropy() {
$entropy = '';
$entropy .= mt_rand();
$entropy .= rand();
$entropy .= time();
if ( function_exists( 'microtime' ) )
$entropy .= microtime();
$entropy .= variable_get( 'cron_key', '' );
$entropy .= variable_get( 'cron_last', '' );
$entropy .= variable_get( 'drupal_private_key', '' );
$entropy .= variable_get( 'site_name', '' );
if ( function_exists( 'openssl_random_pseudo_bytes' ) )
$entropy .= openssl_random_pseudo_bytes( 32 );
$handle = fopen( '/dev/urandom', 'r' );
$entropy .= fread( $handle, 32 );
fclose( $handle );
$old_entropy = variable_get( 'fulcrm_uuid_entropy_1', '' ) . variable_get( 'fulcrm_uuid_entropy_2', '' );
variable_set( 'fulcrm_uuid_entropy_1', sha1( $entropy ) );
variable_set( 'fulcrm_uuid_entropy_2', md5( $old_entropy . $entropy ) );
}
function fulcrm_uuid_install() {
_fulcrm_uuid_stir_entropy();
}

@ -0,0 +1,52 @@
<?php /* -*- php -*- */
function fulcrm_uuid_stir_mt_srand() {
$e1 = variable_get( 'fulcrm_uuid_entropy_1', '' );
mt_srand( crc32( $e1 ) );
}
function fulcrm_uuid_stir_entropy() {
fulcrm_uuid_stir_mt_srand();
$entropy = '';
$entropy .= mt_rand();
$entropy .= rand();
$entropy .= time();
if ( function_exists( 'microtime' ) )
$entropy .= microtime();
$entropy .= variable_get( 'cron_key', '' );
$entropy .= variable_get( 'cron_last', '' );
$entropy .= variable_get( 'drupal_private_key', '' );
$entropy .= variable_get( 'site_name', '' );
if ( function_exists( 'openssl_random_pseudo_bytes' ) )
$entropy .= openssl_random_pseudo_bytes( 32 );
$handle = fopen( '/dev/urandom', 'r' );
$entropy .= fread( $handle, 32 );
fclose( $handle );
$old_entropy = ( variable_get( 'fulcrm_uuid_entropy_1', '' ) .
variable_get( 'fulcrm_uuid_entropy_2', '' ) );
variable_set( 'fulcrm_uuid_entropy_1', sha1( $entropy ) );
variable_set( 'fulcrm_uuid_entropy_2', md5( $old_entropy . $entropy ) );
fulcrm_uuid_stir_mt_srand();
}
function fulcrm_uuid_cron() {
fulcrm_uuid_stir_entropy();
}
function fulcrm_uuid_uuid4() {
$data = ( variable_get( 'fulcrm_uuid_entropy_2', '' ) .
uniqid( $more_entropy = true ) .
variable_get( 'fulcrm_uuid_entropy_2', '' ) );
$data = hex2bin( md5( $data ) );
$data[ 6 ] = chr( ord( $data[ 6 ] ) & 0x0f | 0x40 );
$data[ 8 ] = chr( ord( $data[ 8 ] ) & 0x3f | 0x80 );
return vsprintf( '%s%s-%s-%s-%s-%s%s%s', str_split( bin2hex( $data ), 4 ) );
}
Loading…
Cancel
Save