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

Contents of /contributions/modules/aes/aes.install

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


Revision 1.2 - (show annotations) (download) (as text)
Tue Apr 10 17:41:40 2007 UTC (2 years, 7 months ago) by amc
Branch: MAIN
CVS Tags: DRUPAL-5--1-1, HEAD
Changes since 1.1: +80 -20 lines
File MIME type: text/x-php
Commit of 1.1-version.
1 <?php
2 // $Id $
3
4 function aes_install() {
5
6 if ($GLOBALS['db_type'] == "mysql" || $GLOBALS['db_type'] == "mysqli") {
7 db_query("CREATE TABLE `{aes_passwords}` (
8 `uid` INT NOT NULL ,
9 `pass` VARCHAR( 128 ) NOT NULL ,
10 PRIMARY KEY ( `uid` )
11 )");
12 }
13 else if ($GLOBALS['db_type'] == "pgsql") {
14 db_query("CREATE TABLE {aes_passwords} (
15 uid integer NOT NULL,
16 pass character varying(128)
17 )");
18
19 db_query("ALTER TABLE ONLY {aes_passwords} ADD CONSTRAINT {aes_passwords}_pkey PRIMARY KEY (uid)");
20 }
21
22 variable_set("aes_key_storage_method", "Database");
23 variable_set("aes_cipher", "rijndael-128");
24 variable_set("aes_convert", "true");
25 variable_set("aes_viewing_method", "collapsible");
26
27 drupal_set_message(t("AES installed."));
28 }
29
30 function aes_uninstall() {
31 //delete keyfile
32 if (variable_get("aes_key_storage_method", "") == "File") {
33 unlink(variable_get("aes_key_path", ""));
34 }
35
36 db_query("DROP TABLE {aes_passwords}");
37
38 //delete variables
39 variable_del("aes_key");
40 variable_del("aes_convert");
41 variable_del("aes_key_storage_method");
42 variable_del("aes_key_path");
43 variable_del("aes_key");
44 variable_del("aes_encryption_iv");
45 variable_del("aes_cipher");
46 variable_del("aes_viewing_method");
47
48 drupal_set_message(t("AES uninstalled."));
49 }
50
51 function aes_update_1() {
52 if ($GLOBALS['db_type'] == "mysql" || $GLOBALS['db_type'] == "mysqli") {
53 $return[] = update_sql("CREATE TABLE `{aes_passwords}` (
54 `uid` INT NOT NULL ,
55 `pass` VARCHAR( 128 ) NOT NULL ,
56 PRIMARY KEY ( `uid` )
57 )");
58 }
59 else if ($GLOBALS['db_type'] == "pgsql") {
60 $return[] = update_sql("CREATE TABLE {aes_passwords} (
61 uid integer NOT NULL,
62 pass character varying(128)
63 )");
64
65 $return[] = update_sql("ALTER TABLE ONLY {aes_passwords} ADD CONSTRAINT {aes_passwords}_pkey PRIMARY KEY (uid)");
66 }
67
68 $result = db_query("SELECT uid, pass FROM {users} WHERE uid != 0");
69
70 while ($user = db_fetch_array($result)) {
71 if (strlen($user['pass']) != 32) {
72
73 $td = mcrypt_module_open("rijndael-128", "", MCRYPT_MODE_CBC, "");
74 $iv = base64_decode(variable_get("aes_encryption_iv", ""));
75 $ks = mcrypt_enc_get_key_size($td);
76
77 $storage_method = variable_get("aes_key_storage_method", "database");
78 if ($storage_method == "Database") {
79 $key = variable_get("aes_key", false);
80 }
81 if ($storage_method == "File") {
82 $key = file_get_contents(variable_get("aes_key_path", ""));
83 }
84
85 $key = substr(sha1($key), 0, $ks);
86
87 mcrypt_generic_init($td, $key, $iv);
88 $plain_pass = mdecrypt_generic($td, base64_decode($user['pass']));
89 mcrypt_generic_deinit($td);
90 mcrypt_module_close($td);
91
92 $md5_pass = md5(trim($plain_pass));
93 db_query("INSERT INTO {aes_passwords} (uid, pass) VALUES (%d, '%s')", $user['uid'], $user['pass']);
94 db_query("UPDATE {users} SET pass='%s' WHERE uid=%d", $md5_pass, $user['uid']);
95 }
96 }
97
98 variable_set("aes_viewing_method", "collapsible");
99
100 drupal_set_message(t('AES updated (1.0 -> 1.1).'));
101
102 return $return;
103 }
104

  ViewVC Help
Powered by ViewVC 1.1.2