| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installation functions for Private Number.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function private_number_install() {
|
| 13 |
private_number_config(FALSE);
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implementation of hook_uninstall().
|
| 18 |
*/
|
| 19 |
function private_number_uninstall() {
|
| 20 |
db_query("DELETE FROM {variable} WHERE name LIKE 'private_number_%'");
|
| 21 |
cache_clear_all('variables', 'cache');
|
| 22 |
|
| 23 |
drupal_set_message(t('Private Number variables removed. Private Number config inserted into settings.php will need to be removed manually.'));
|
| 24 |
}
|
| 25 |
|
| 26 |
/**
|
| 27 |
* Convert legacy key to settings.php.
|
| 28 |
*/
|
| 29 |
function private_number_update_1() {
|
| 30 |
return private_number_config();
|
| 31 |
}
|
| 32 |
|
| 33 |
/**
|
| 34 |
* Insert Private Number config into settings.php.
|
| 35 |
*/
|
| 36 |
function private_number_config($update = TRUE) {
|
| 37 |
if ($update) $items = array();
|
| 38 |
|
| 39 |
$settings_file = './'. conf_path() .'/'. $prefix .'settings.php';
|
| 40 |
drupal_install_fix_file($settings_file, FILE_WRITABLE);
|
| 41 |
|
| 42 |
$config = "\r\n/**\r\n";
|
| 43 |
$config .= " * Private Number key:\r\n";
|
| 44 |
$config .= " * \r\n";
|
| 45 |
$config .= " * The key is set with the variable \$conf['private_number_key']. Note that\r\n";
|
| 46 |
$config .= " * changing the key will make previously stored Private Numbers unreadable!\r\n";
|
| 47 |
$config .= " * \r\n";
|
| 48 |
$config .= " * The key can alternatively be stored in the first line of a file located\r\n";
|
| 49 |
$config .= " * above the docroot with the variable \$conf['private_number_key_file'] \r\n";
|
| 50 |
$config .= " * where the path is relative to this settings.php file.\r\n";
|
| 51 |
$config .= " * \r\n";
|
| 52 |
$config .= " * More information on Private Number key management can be found in README.txt.\r\n";
|
| 53 |
$config .= " */\r\n";
|
| 54 |
$config .= "\$conf['private_number_key'] = '" . variable_get('private_number_cipher_key', variable_get('site_name', 'drupal')) . "';\r\n";
|
| 55 |
$config .= "#\$conf['private_number_key_file'] = '../../../private_number.key';\r\n";
|
| 56 |
|
| 57 |
if ($fp = @fopen($settings_file, 'a')) {
|
| 58 |
if ($fp && fwrite($fp, $config) === FALSE) {
|
| 59 |
drupal_set_message(t('Failed to modify %settings, please verify the file permissions.', array('%settings' => $settings_file)), 'error');
|
| 60 |
}
|
| 61 |
else {
|
| 62 |
// Delete legacy key.
|
| 63 |
variable_del('private_number_cipher_key');
|
| 64 |
cache_clear_all('variables', 'cache');
|
| 65 |
|
| 66 |
if ($update) {
|
| 67 |
$items[] = array('success' => TRUE, 'query' => 'Private Number legacy key from the database and config inserted into settings.php.');
|
| 68 |
}
|
| 69 |
else {
|
| 70 |
drupal_set_message(t('Private Number config inserted into settings.php. Please configure your key before using Private Number.'));
|
| 71 |
}
|
| 72 |
}
|
| 73 |
fclose($fp);
|
| 74 |
}
|
| 75 |
else {
|
| 76 |
drupal_set_message(t('Failed to open %settings, please verify the file permissions.', array('%settings' => $settings_file)), 'error');
|
| 77 |
}
|
| 78 |
|
| 79 |
// Cleanup settings.php file perm.
|
| 80 |
drupal_install_fix_file($settings_file, FILE_NOT_WRITABLE);
|
| 81 |
|
| 82 |
if ($update) return $items;
|
| 83 |
}
|