b55022
b55022
b55022
#
b55022
# strip.php /path/to/file key_name
b55022
# 
b55022
# Takes a file as input and a string prefix; reads
b55022
# the file as a serialized data blob and removes a
b55022
# key with name key_name from the hash.
b55022
# Serializes again and writes output to stdout.
b55022
# 
b55022
b55022
$file = $_SERVER['argv'][1];
b55022
$key = $_SERVER['argv'][2];
b55022
b55022
function remove_key($array, $name) {
b55022
    if (array_key_exists($name, $array)) {
b55022
        unset($array[$name]);
b55022
    }
b55022
b55022
    return $array;
b55022
}
b55022
b55022
$input = file_get_contents($file);
b55022
b55022
# Special case for /etc/pear.conf.
b55022
if (strncmp($input, "#PEAR_Config 0.9\n", 17) == 0) {
b55022
    echo substr($input, 0, 17);
b55022
    $s = substr($input, 17);
b55022
} else {
b55022
    $s = $input;
b55022
}
b55022
b55022
echo serialize(remove_key(unserialize($s), $key));
b55022
b55022
?>