2005-12-01 17:12:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
#
|
|
|
|
# relocate.php /path/to/file prefix
|
|
|
|
#
|
|
|
|
# Takes a file as input and a string prefix; reads
|
|
|
|
# the file as a serialized data blob and strips PREFIX
|
|
|
|
# from the beginning of each string value within the blob.
|
|
|
|
# Serializes again and writes output to stdout.
|
|
|
|
#
|
|
|
|
|
|
|
|
$file = $_SERVER['argv'][1];
|
|
|
|
$destdir = $_SERVER['argv'][2];
|
|
|
|
|
|
|
|
$destdir_len = strlen($destdir);
|
|
|
|
|
2007-02-05 12:33:03 +00:00
|
|
|
function relocate_string($value) {
|
2005-12-01 17:12:57 +00:00
|
|
|
global $destdir, $destdir_len;
|
|
|
|
|
2007-02-05 12:33:03 +00:00
|
|
|
if (strncmp($value, $destdir, $destdir_len) == 0) {
|
|
|
|
$value = substr($value, $destdir_len);
|
|
|
|
}
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function relocate_value($value) {
|
2005-12-01 17:12:57 +00:00
|
|
|
if (is_string($value)) {
|
2007-02-05 12:33:03 +00:00
|
|
|
$value = relocate_string($value);
|
2005-12-01 17:12:57 +00:00
|
|
|
} else if (is_array($value)) {
|
|
|
|
$value = relocate_array($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
function relocate_array($array) {
|
2007-02-05 12:33:03 +00:00
|
|
|
$result = array();
|
|
|
|
|
2005-12-01 17:12:57 +00:00
|
|
|
foreach ($array as $key => $value) {
|
2007-02-05 12:47:58 +00:00
|
|
|
if (is_string($key)) {
|
|
|
|
$key = relocate_string($key);
|
|
|
|
}
|
2007-02-05 12:33:03 +00:00
|
|
|
$result[$key] = relocate_value($value);
|
2005-12-01 17:12:57 +00:00
|
|
|
}
|
|
|
|
|
2007-02-05 12:33:03 +00:00
|
|
|
return $result;
|
2005-12-01 17:12:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$input = file_get_contents($file);
|
|
|
|
|
|
|
|
# Special case for /etc/pear.conf.
|
|
|
|
if (strncmp($input, "#PEAR_Config 0.9\n", 17) == 0) {
|
|
|
|
echo substr($input, 0, 17);
|
|
|
|
$s = substr($input, 17);
|
|
|
|
} else {
|
|
|
|
$s = $input;
|
|
|
|
}
|
|
|
|
|
|
|
|
echo serialize(relocate_value(unserialize($s)));
|
|
|
|
|
|
|
|
?>
|