dolibarr 24.0.0-beta
BlockedLog Class Reference

Class to manage Blocked Log. More...

Public Member Functions

 __construct (DoliDB $db)
 Constructor.
 
 loadTrackedEvents ()
 Load list of tracked and controlled events into $this->controlled, $this->trackedevents and $this->trackedmodules.
 
 getObjectLink ()
 Try to retrieve source object (it it still exists).
 
 getUser ()
 Try to retrieve user author.
 
 setObjectData (&$object, $action, $amounts, $fuser=null, $amounts_taxexcl=null)
 Populate properties of an unalterable log entry from object data.
 
 fetch ($id)
 Get object from database.
 
 dolEncodeBlockedData ($data, $mode=1)
 Encode data.
 
 dolDecodeBlockedData ($data, $mode=0)
 Decode data.
 
 setCertified ()
 Set block certified by an external authority.
 
 create ($user, $forcesignature='')
 Create blocked log in database.
 
 getEndOfChainFlagFile ()
 Return path of end of chain flag file.
 
 checkSignature ($previoushash='', $returnarray=0)
 Check if calculated signature still correct compared to the value in the chain.
 
 buildKeyForSignature ($format='')
 Return the string for signature (clear data).
 
 saveHMACSecretKey ($hmac_secret_key, $obfuscationmode, $obfuscationkey='')
 Save the HMAC secret key into database.
 
 getObfuscationKey ()
 Return the remote obfuscation key from ping.dolibarr.org (used later to decode HMAC secret key).
 
 getEncodedHMACSecretKey ($nocache=0, $noentity=0)
 Get the encoded HMAC secret key.
 
 getClearHMACSecretKey ($hmac_encoded_secret_key)
 Get the HMAC secret key.
 
 getPreviousHash ($withlock=0, $beforeid=0)
 Get previous signature/hash in chain.
 
 getNextRecord ($rowidafter=0)
 Return the last record in blocked log.
 
 getLastRecord ()
 Return the last record in blocked log.
 
 getLog ($element, $fk_object, $limit=0, $sortfield='', $sortorder='', $search_fk_user=-1, $search_start=-1, $search_end=-1, $search_ref='', $search_amount='', $search_code='', $search_signature='', $search_module_source='', $search_pos_source='', $search_type_code='')
 Return array of unalterable log objects (filtered with criteria)
 
 getOrInitFirstSignature ()
 Return the signature (hash) of the "genesis-block" (Block 0).
 
 alreadyUsed ($ignoresystem=0)
 Check if module was already used or not for at least one recording.
 
 canBeEnabled ()
 Check if module can be enabled.
 
 canBeDisabled ()
 Check if module can be disabled.
 
 countRecord ()
 Return current number of records.
 

Private Member Functions

 buildFirstPartOfKeyForSignature ($format='')
 Return first part of string for signature (clear data) Note: rowid of line not included as it is not a business data and this allow to make backup of a year and restore it into another database with different ids without comprimising checksums.
 
 buildFinalSignatureHash ($clearstring, $format='')
 Return a hash that is the signature of a line data $clearstring (hash_hmac SHA256 of data + secret key)
 

Detailed Description

Class to manage Blocked Log.

Definition at line 31 of file blockedlog.class.php.

Constructor & Destructor Documentation

◆ __construct()

BlockedLog::__construct ( DoliDB $db)

Constructor.

Parameters
DoliDB$dbDatabase handler

Definition at line 212 of file blockedlog.class.php.

References $conf, and $db.

Member Function Documentation

◆ alreadyUsed()

BlockedLog::alreadyUsed ( $ignoresystem = 0)

Check if module was already used or not for at least one recording.

Parameters
int<0,1>$ignoresystem Ignore system events for the test
Returns
bool

Definition at line 2383 of file blockedlog.class.php.

References isBlockedLogUsed().

◆ buildFinalSignatureHash()

BlockedLog::buildFinalSignatureHash ( $clearstring,
$format = '' )
private

Return a hash that is the signature of a line data $clearstring (hash_hmac SHA256 of data + secret key)

Parameters
string$clearstringData string to sign
string$formatForce encryption format version to use ('V1', 'V2', ...)
Returns
string Signature string

Definition at line 1769 of file blockedlog.class.php.

References $mysoc, dol_hash(), getClearHMACSecretKey(), getEncodedHMACSecretKey(), getObfuscationKey(), isALNERunningVersion(), and saveHMACSecretKey().

Referenced by checkSignature(), and create().

◆ buildFirstPartOfKeyForSignature()

BlockedLog::buildFirstPartOfKeyForSignature ( $format = '')
private

Return first part of string for signature (clear data) Note: rowid of line not included as it is not a business data and this allow to make backup of a year and restore it into another database with different ids without comprimising checksums.

Parameters
string$formatForce format to use
Returns
string First part of key for signature

Definition at line 1709 of file blockedlog.class.php.

Referenced by buildKeyForSignature(), and create().

◆ buildKeyForSignature()

BlockedLog::buildKeyForSignature ( $format = '')

Return the string for signature (clear data).

Parameters
string$formatForce format to use
Returns
string Key for signature

Definition at line 1744 of file blockedlog.class.php.

References buildFirstPartOfKeyForSignature().

Referenced by checkSignature(), and create().

◆ canBeDisabled()

BlockedLog::canBeDisabled ( )

Check if module can be disabled.

Returns
int<0,1> 0=Can't be disabled, 1=Can be disabled

Definition at line 2415 of file blockedlog.class.php.

References $mysoc, and isALNEQualifiedVersion().

◆ canBeEnabled()

BlockedLog::canBeEnabled ( )

Check if module can be enabled.

Returns
string '' if ok, error message if not possible

Definition at line 2395 of file blockedlog.class.php.

References isALNEQualifiedVersion(), and isHTTPS().

◆ checkSignature()

BlockedLog::checkSignature ( $previoushash = '',
$returnarray = 0 )

Check if calculated signature still correct compared to the value in the chain.

Parameters
string$previoushashIf previous signature hash is known, we can provide it to avoid to make a search of it in database.
int<0,2>$returnarray 1=Return array of details, 2=Return array of details including keyforsignature, 0=Return a boolean
Returns
boolean|array{checkresult:bool,calculatedsignature:string,previoushash:string,keyforsignature?:string} Array or true if OK, false if KO

Definition at line 1651 of file blockedlog.class.php.

References buildFinalSignatureHash(), buildKeyForSignature(), dol_syslog(), and getPreviousHash().

◆ countRecord()

BlockedLog::countRecord ( )

Return current number of records.

Returns
int Number of recor for all instances

Definition at line 2438 of file blockedlog.class.php.

References dol_print_error().

◆ create()

BlockedLog::create ( $user,
$forcesignature = '' )

Create blocked log in database.

Parameters
User$userObject user that create
string$forcesignatureForce signature (for example '0000000000' when we disabled the module, to force a non valid record, for test purpose for example)
Returns
int<-3,-1>|int<1,1> Return integer <0 if KO, >0 if OK

Definition at line 1275 of file blockedlog.class.php.

References $conf, $mysoc, buildFinalSignatureHash(), buildFirstPartOfKeyForSignature(), buildKeyForSignature(), dol_mkdir(), dol_now(), dol_print_date(), dol_syslog(), dolChmod(), dolDecrypt(), dolEncodeBlockedData(), dolEncrypt(), getDolGlobalString(), getEndOfChainFlagFile(), getObfuscationKey(), getPreviousHash(), isALNERunningVersion(), and string.

◆ dolDecodeBlockedData()

BlockedLog::dolDecodeBlockedData ( $data,
$mode = 0 )

Decode data.

Parameters
string$dataData to unserialize
int$mode0=unserialize, 1=json_decode
Returns
Object Value unserialized, an object (stdClass)

Definition at line 1240 of file blockedlog.class.php.

Referenced by fetch().

◆ dolEncodeBlockedData()

BlockedLog::dolEncodeBlockedData ( $data,
$mode = 1 )

Encode data.

Parameters
?stdClass$dataData to serialize
int<0,1>$mode 0=serialize, 1=json_encode
Returns
string Value serialized, an object (stdClass).

Definition at line 1225 of file blockedlog.class.php.

Referenced by create().

◆ fetch()

BlockedLog::fetch ( $id)

Get object from database.

Parameters
int$idId of object to load
Returns
int<-1,1> >0 if OK, <0 if KO, 0 if not found

Definition at line 1138 of file blockedlog.class.php.

References dolDecodeBlockedData().

◆ getClearHMACSecretKey()

BlockedLog::getClearHMACSecretKey ( $hmac_encoded_secret_key)

Get the HMAC secret key.

Parameters
string$hmac_encoded_secret_keyHMAC encode string retrieved with getEncodedHMACSecretKey()
Returns
string Encoded HMAC secret key.

Definition at line 2026 of file blockedlog.class.php.

References dolDecrypt(), and getObfuscationKey().

Referenced by buildFinalSignatureHash().

◆ getEncodedHMACSecretKey()

BlockedLog::getEncodedHMACSecretKey ( $nocache = 0,
$noentity = 0 )

Get the encoded HMAC secret key.

Use a memory cache to avoid repeated db access.

Parameters
int$nocacheUse 1 to force to not use cache.
int$noentityUse 1 to search without entity.
Returns
string Encoded HMAC secret key.

Definition at line 1983 of file blockedlog.class.php.

References $conf.

Referenced by buildFinalSignatureHash(), and saveHMACSecretKey().

◆ getEndOfChainFlagFile()

BlockedLog::getEndOfChainFlagFile ( )

Return path of end of chain flag file.

Returns
string

Definition at line 1635 of file blockedlog.class.php.

References $conf.

Referenced by create().

◆ getLastRecord()

BlockedLog::getLastRecord ( )

Return the last record in blocked log.

Returns
array<string, int|string> Last record (id, date, signature)

Definition at line 2181 of file blockedlog.class.php.

References $conf.

◆ getLog()

BlockedLog::getLog ( $element,
$fk_object,
$limit = 0,
$sortfield = '',
$sortorder = '',
$search_fk_user = -1,
$search_start = -1,
$search_end = -1,
$search_ref = '',
$search_amount = '',
$search_code = '',
$search_signature = '',
$search_module_source = '',
$search_pos_source = '',
$search_type_code = '' )

Return array of unalterable log objects (filtered with criteria)

Parameters
string$elementElement to search
string | int$fk_objectId of object to search. Can be a UFS search criteria.
int<0,max>$limit Max number of element, 0 for all
string$sortfieldSort field
string$sortorderSort order
int$search_fk_userId of user(s)
int$search_startStart time limit
int$search_endEnd time limit
string$search_refSearch ref
string$search_amountSearch amount
string | string[]$search_codeSearch code
string$search_signatureSearch signature
string$search_module_sourceSearch on module source
string$search_pos_sourceSearch on terminal
string$search_type_codeSearch on type code
Returns
BlockedLog[]|int<-2,-1> Array of object log or <0 if error

Definition at line 2222 of file blockedlog.class.php.

References $conf, and natural_search().

◆ getNextRecord()

BlockedLog::getNextRecord ( $rowidafter = 0)

Return the last record in blocked log.

Parameters
int$rowidafterSearch record after this one
Returns
array<string, int|string> Last record (id, date, signature)

Definition at line 2153 of file blockedlog.class.php.

References $conf.

◆ getObfuscationKey()

BlockedLog::getObfuscationKey ( )

Return the remote obfuscation key from ping.dolibarr.org (used later to decode HMAC secret key).

Use a memory cache to avoid repeated db access. This function can also be called just to store the remote obfuscation key into the cache so all next call will not depends on the obfuscation key server availability. Note: Avoid to call this function if you are not in acontext that need remote obfuscation key.

Returns
string Obfuscation key or a coma-separated list of obfuscation keys, or "" if not found.

Definition at line 1931 of file blockedlog.class.php.

References $conf, $mysoc, callApiToGetObfuscationKey(), dol_syslog(), and getHashUniqueIdOfRegistration().

Referenced by buildFinalSignatureHash(), create(), and getClearHMACSecretKey().

◆ getObjectLink()

BlockedLog::getObjectLink ( )

Try to retrieve source object (it it still exists).

Returns
string URL string of source object

Definition at line 361 of file blockedlog.class.php.

References $object, and string.

◆ getOrInitFirstSignature()

BlockedLog::getOrInitFirstSignature ( )

Return the signature (hash) of the "genesis-block" (Block 0).

Returns
string Signature of genesis-block for current conf->entity

Definition at line 2357 of file blockedlog.class.php.

References $conf, $db, dolibarr_set_const(), and getDolGlobalString().

Referenced by getPreviousHash().

◆ getPreviousHash()

BlockedLog::getPreviousHash ( $withlock = 0,
$beforeid = 0 )

Get previous signature/hash in chain.

If there is no previous line, return the init hash.

Parameters
int<0,1>$withlock 1=With a lock (Used in the ->create() transaction)
int$beforeidID of a record
Returns
array<string, int|string> Hash of previous record (if beforeid is defined) or hash of last record (if beforeid is 0)

Definition at line 2071 of file blockedlog.class.php.

References $conf, dol_print_error(), dol_syslog(), and getOrInitFirstSignature().

Referenced by checkSignature(), and create().

◆ getUser()

BlockedLog::getUser ( )

Try to retrieve user author.

Returns
string

Definition at line 485 of file blockedlog.class.php.

◆ loadTrackedEvents()

BlockedLog::loadTrackedEvents ( )

Load list of tracked and controlled events into $this->controlled, $this->trackedevents and $this->trackedmodules.

Returns
int<1,1> Always 1

Definition at line 226 of file blockedlog.class.php.

References getDolGlobalString(), img_picto(), and isModEnabled().

◆ saveHMACSecretKey()

BlockedLog::saveHMACSecretKey ( $hmac_secret_key,
$obfuscationmode,
$obfuscationkey = '' )

Save the HMAC secret key into database.

Parameters
string$hmac_secret_keyHMAC secret key ('BLOCKEDLOG_HMAC_KEY...')
string$obfuscationmodeObfuscation mode ('dolcrypt', 'dolobfuscationv1-SIREN')
string$obfuscationkeyObfuscation key
Returns
int Return <0 if KO, >0 if OK

Definition at line 1856 of file blockedlog.class.php.

References $conf, dol_syslog(), dolEncrypt(), and getEncodedHMACSecretKey().

Referenced by buildFinalSignatureHash().

◆ setCertified()

BlockedLog::setCertified ( )

Set block certified by an external authority.

Returns
boolean

Definition at line 1258 of file blockedlog.class.php.

◆ setObjectData()

BlockedLog::setObjectData ( & $object,
$action,
$amounts,
$fuser = null,
$amounts_taxexcl = null )

Populate properties of an unalterable log entry from object data.

This populates ->object_data but also other fields like ->action, ->module_source, ->amounts_taxexcl, ->amounts and ->linktoref and ->linktype It also populates some debug info like ->element and ->fk_object

Parameters
CommonObject | stdClass$objectObject to store
string$actionAction code ('BILL_VALIDATE', 'BILL_SENTBYMAIL', ...)
float | int$amountsamounts (incl tax)
?User$fuserUser object (forced)
float | int | null$amounts_taxexclamounts (excl tax or null if not relevant)
Returns
int<-1,-1>|int<1,1> Return >0 if OK, <0 if KO

var CashControl $object

Definition at line 519 of file blockedlog.class.php.

References $mysoc, $object, dol_getIdFromCode(), dol_syslog(), dol_trunc(), dolGetFirstLineOfText(), getDolEntity(), string, Facture\TYPE_CREDIT_NOTE, and FactureFournisseur\TYPE_CREDIT_NOTE.


The documentation for this class was generated from the following file: