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

Diff of /contributions/modules/aes/aes.install

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

revision 1.1.2.1, Thu Dec 6 20:20:14 2007 UTC revision 1.1.2.2, Tue Apr 1 14:07:10 2008 UTC
# Line 3  Line 3 
3    
4  function aes_install() {  function aes_install() {
5    
6    if ($GLOBALS['db_type'] == "mysql" || $GLOBALS['db_type'] == "mysqli") {    drupal_install_schema("aes");
     db_query("CREATE TABLE `{aes_passwords}` (  
     `uid` INT NOT NULL ,  
     `pass` VARCHAR( 128 ) NOT NULL ,  
     PRIMARY KEY ( `uid` )  
     )");  
   }  
   else if ($GLOBALS['db_type'] == "pgsql") {  
     db_query("CREATE TABLE {aes_passwords} (  
     uid integer NOT NULL,  
     pass character varying(128)  
     )");  
   
     db_query("ALTER TABLE ONLY {aes_passwords} ADD CONSTRAINT {aes_passwords}_pkey PRIMARY KEY (uid)");  
   }  
7    
8    variable_set("aes_key_storage_method", "Database");    variable_set("aes_key_storage_method", "Database");
9    variable_set("aes_cipher", "rijndael-128");    variable_set("aes_cipher", "rijndael-128");
# Line 27  function aes_install() { Line 13  function aes_install() {
13    drupal_set_message(t("AES installed."));    drupal_set_message(t("AES installed."));
14  }  }
15    
16    function aes_schema() {
17    
18            $schema['aes_passwords'] = array(
19                    'fields' => array(
20                            'uid' => array('type' => 'int', 'unsigned' => true, 'not null' => true, 'default' => 0),
21                            'pass' => array('type' => 'varchar', 'length' => 128, 'not null' => true, 'default' => ''),
22                            ),
23                    'primary key' => array('uid'),
24            );
25    
26            return $schema;
27    }
28    
29  function aes_uninstall() {  function aes_uninstall() {
30    //delete keyfile    //delete keyfile
31    if (variable_get("aes_key_storage_method", "") == "File") {    if (variable_get("aes_key_storage_method", "") == "File") {
32      unlink(variable_get("aes_key_path", ""));      unlink(variable_get("aes_key_path", ""));
33    }    }
34    
35    db_query("DROP TABLE {aes_passwords}");    drupal_uninstall_schema("aes");
36    
37    //delete variables    //delete variables
38    variable_del("aes_key");    variable_del("aes_key");
# Line 47  function aes_uninstall() { Line 46  function aes_uninstall() {
46    
47    drupal_set_message(t("AES uninstalled."));    drupal_set_message(t("AES uninstalled."));
48  }  }
   
 function aes_update_1() {  
   if ($GLOBALS['db_type'] == "mysql" || $GLOBALS['db_type'] == "mysqli") {  
     $return[] = update_sql("CREATE TABLE `{aes_passwords}` (  
     `uid` INT NOT NULL ,  
     `pass` VARCHAR( 128 ) NOT NULL ,  
     PRIMARY KEY ( `uid` )  
     )");  
   }  
   else if ($GLOBALS['db_type'] == "pgsql") {  
     $return[] = update_sql("CREATE TABLE {aes_passwords} (  
     uid integer NOT NULL,  
     pass character varying(128)  
     )");  
   
     $return[] = update_sql("ALTER TABLE ONLY {aes_passwords} ADD CONSTRAINT {aes_passwords}_pkey PRIMARY KEY (uid)");  
   }  
   
   $result = db_query("SELECT uid, pass FROM {users} WHERE uid != 0");  
   
   while ($user = db_fetch_array($result)) {  
     if (strlen($user['pass']) != 32) {  
   
       $td = mcrypt_module_open("rijndael-128", "", MCRYPT_MODE_CBC, "");  
       $iv = base64_decode(variable_get("aes_encryption_iv", ""));  
       $ks = mcrypt_enc_get_key_size($td);  
   
       $storage_method = variable_get("aes_key_storage_method", "database");  
       if ($storage_method == "Database") {  
         $key = variable_get("aes_key", false);  
       }  
       if ($storage_method == "File") {  
         $key = file_get_contents(variable_get("aes_key_path", ""));  
       }  
   
       $key = substr(sha1($key), 0, $ks);  
   
       mcrypt_generic_init($td, $key, $iv);  
       $plain_pass = mdecrypt_generic($td, base64_decode($user['pass']));  
       mcrypt_generic_deinit($td);  
       mcrypt_module_close($td);  
   
       $md5_pass = md5(trim($plain_pass));  
       db_query("INSERT INTO {aes_passwords} (uid, pass) VALUES (%d, '%s')", $user['uid'], $user['pass']);  
       db_query("UPDATE {users} SET pass='%s' WHERE uid=%d", $md5_pass, $user['uid']);  
     }  
   }  
   
   variable_set("aes_viewing_method", "collapsible");  
   
   drupal_set_message(t('AES updated (1.0 -> 1.1).'));  
   
   return $return;  
 }  
   

Legend:
Removed from v.1.1.2.1  
changed lines
  Added in v.1.1.2.2

  ViewVC Help
Powered by ViewVC 1.1.2