rename header.inc.php to header-backup.inc.php before updating it and rename it back, if update fails

This commit is contained in:
ralf 2022-03-05 15:57:18 +02:00
parent 2d047e7273
commit 70d86a7e5a

View File

@ -526,9 +526,15 @@ function patch_header($filename,&$user,$password)
}
//error_log(__FUNCTION__."('$filename', '$user', '$password') header_admin_password was '$pmatches[1]'");
file_put_contents($filename,$header_new=preg_replace('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m",
// $ in password needs to be escaped as they otherwise address captures in the regualar expression
"\$GLOBALS['egw_info']['server']['header_admin_password'] = '".str_replace('$', '\\$', $password)."';",$header));
$header_new = preg_replace('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m",
// $ in password needs to be escaped as they otherwise address captures in the regular expression
"\$GLOBALS['egw_info']['server']['header_admin_password'] = '".str_replace('$', '\\$', $password)."';",$header);
rename($filename, $backup=substr($filename, 0, -8).'-backup.inc.php');
if (strlen($header_new) !== file_put_contents($filename, $header_new))
{
rename($backup, $filename);
bail_out(99, "Failed to update $filename, maybe disk full!");
}
/*$xmatches = null;
preg_match('/'.preg_quote("\$GLOBALS['egw_info']['server']['header_admin_password'] = '", '/')."([^']*)';/m",$header_new,$xmatches);
@ -923,4 +929,4 @@ function _size_with_unit($_size)
$size *= 1024;
}
return $size;
}
}