resign_all_code()

Description

Returns a signature for a given block of code.

Parameters

ColumnTypeDefaultDescription
$confirm bool true Require user to approve code changes when resigning from the server side.
$output bool true Display output. $confirm will override this option to provide detail if approval needed.
$output_changes_only bool false Output changes only - do not sign code.

Return

void

Location

include/encryption_functions.php lines 145 to 214

Definition

 
function resign_all_code($confirm true$output true$output_changes_only false)
{
    if (
$confirm) {
        
$output 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 [$table$column]) {
        
$rows ps_query("select ref,`$column` from `$table`");
        foreach (
$rows as $row) {
            
$code $row[$column];
            
$ref $row["ref"];
            if (
trim((string)$code) == "") {
                
$code "";
            }
            if (
$output && !$output_changes_only) {
                echo 
$table " -> " $column " -> " $ref;
            }

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

            if (
trim(eval_check_signed($code)) !== trim($purecode)) {
                
// Code is not signed.

                // Needs signing. Confirm it's safe.
                
if ($confirm) {
                    if (!
$output_changes_only) {
                        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();
                        }
                    } else {
                        echo 
$table " -> " $column " -> " $ref "\n" $code "\n\n";
                    }
                }

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

This article was last updated 14th July 2025 14:35 Europe/London time based on the source file dated 21st January 2025 15:20 Europe/London time.