/[drupal]/contributions/modules/private_number/private_number.install
ViewVC logotype

Contents of /contributions/modules/private_number/private_number.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Apr 6 20:37:32 2009 UTC (7 months, 3 weeks ago) by gestaltware
Branch: MAIN
CVS Tags: DRUPAL-5--2-0, DRUPAL-5--2-1, HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
- fixed bug where superuser always had view private number permission
- fixed bug where edit privileges overrode view private number permission
- added view own private number permission
- added settings.php key config and removed legacy key from db
- added support for key in external file
- added status report hook on key status
- added field setting to disable human regex validation error message
- added hook_private_number_access to integrate with other modules
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 }

  ViewVC Help
Powered by ViewVC 1.1.2