Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

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 136 to 200

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($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)
                    {
                    
                    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 17th November 2024 15:05 Europe/London time based on the source file dated 1st October 2024 08:15 Europe/London time.