Collections functions
General functions
Render functions
Theme permission functions
Resource functions

resign_all_code()

Description

Returns a signature for a given block of code.

Parameters

ColumnTypeDefaultDescription
$confirm true
$code string The code to sign

Return

string The signature

Location

include/encryption_functions.php lines 137 to 187

Definition

 
function resign_all_code($confirm=true)
    {
    
$todo=array
        (
        array(
"resource_type_field",    "value_filter"),
        array(
"resource_type_field",    "onchange_macro"),        
        array(
"resource_type_field",    "autocomplete_macro"),
        array(
"resource_type_field",    "exiftool_filter"),
        array(
"resource_type",          "config_options"),
        array(
"usergroup",              "config_options")
        );
    foreach (
$todo as $do)
        {
        
$table=$do[0];$column=$do[1];

        
// Iterate through all columns
        
$rows=ps_query("select ref,`$column` from `$table`");
        foreach (
$rows as $row)
            {
            
$code=$row[$column];$ref=$row["ref"];if (trim((string)$code)=="") {$code="";}
            echo 
$table " -> " $column " -> " $ref;

            
// Extract signature if already one present
            
$purecode=$code;
            if (
substr($code,0,5)=="//SIG") {$purecode=trim(substr($code,strpos($code,"\n")+1));}

            if (
trim(eval_check_signed($code))!==trim($purecode))
                {
                
// Code is not signed.
                    
                // Needs signing. Confirm it's safe.
                
if ($confirm)
                    {
                    echo 
" needs signing\n-----------------------------\n";echo $purecode;echo "\n-----------------------------\nIs this code safe? (y/n)";ob_flush();
                    
$line fgets(STDIN);if (trim($line)!="y") {exit();}
                    }

                
$code=trim($code);
                
$code="//SIG" sign_code($code) . "\n" $code;
                
ps_query("update `$table` set `$column`=? where ref=?",array("s",$code,"i",$ref));
                }
            else    
                {
                echo 
" is OK" $code "\n";
                }
            }
        }
    
// Clear the cache so the code uses the updated signed code.
    
clear_query_cache("schema");
    
set_sysvar("code_sign_required","");
    }

This article was last updated 26th June 2022 05:35 Europe/London time based on the source file dated 18th May 2022 15:00 Europe/London time.