]> git.joonet.de Git - adminer.git/commitdiff
Allow permanent login without customization
authorJakub Vrana <jakub@vrana.cz>
Thu, 6 May 2010 13:45:34 +0000 (15:45 +0200)
committerJakub Vrana <jakub@vrana.cz>
Thu, 6 May 2010 13:45:34 +0000 (15:45 +0200)
adminer/include/adminer.inc.php
adminer/include/functions.inc.php
adminer/include/xxtea.inc.php
changes.txt
editor/include/adminer.inc.php

index 9bed3601e698f2f63d80c3f995494123caa9fb91..c8d23cc4a2fcdb8c935598aa9ff51d331072086d 100644 (file)
@@ -21,7 +21,7 @@ class Adminer {
        * @return string cryptic string which gets combined with password
        */
        function permanentLogin() {
-               return "";
+               return password_file();
        }
        
        /** Identifier of selected database
@@ -49,9 +49,7 @@ document.getElementById('username').focus();
 </script>
 <?php
                echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
-               if ($this->permanentLogin()) {
-                       echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
-               }
+               echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
        }
        
        /** Authorize the user
index 37a4d6beb4c03610361277806361ee5ea48ab771..818121a013f66627319326a621499c6809ab885a 100644 (file)
@@ -644,6 +644,37 @@ function apply_sql_function($function, $column) {
        return ($function ? ($function == "unixepoch" ? "DATETIME($column, '$function')" : ($function == "count distinct" ? "COUNT(DISTINCT " : strtoupper("$function(")) . "$column)") : $column);
 }
 
+/** Read password from file adminer.key in temporary directory or create one
+* @return string or false if the file can not be created
+*/
+function password_file() {
+       $dir = ini_get("upload_tmp_dir"); // session_save_path() may contain other storage path
+       if (!$dir) {
+               if (function_exists('sys_get_temp_dir')) {
+                       $dir = sys_get_temp_dir();
+               } else {
+                       $filename = @tempnam("", ""); // @ - temp directory can be disabled by open_basedir
+                       if (!$filename) {
+                               return false;
+                       }
+                       $dir = dirname($filename);
+                       unlink($filename);
+               }
+       }
+       $filename = "$dir/adminer.key";
+       $return = @file_get_contents($filename); // @ - can not exist
+       if ($return) {
+               return $return;
+       }
+       $fp = @fopen($filename, "w"); // @ - can have insufficient rights //! is not atomic
+       if ($fp) {
+               $return = md5(uniqid(mt_rand(), true));
+               fwrite($fp, $return);
+               fclose($fp);
+       }
+       return $return;
+}
+
 /** Check whether the string is e-mail address
 * @param string
 * @return bool
index 774c8198bbd594835ec538c1b2d6b236aa31a456..7467a0da852ef981b3762cce064028ae4bf59da6 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-/** PHP implementation of XXTEA encryption algorithm.
+/** PHP implementation of XXTEA encryption algorithm
 * @author Ma Bingyao <andot@ujn.edu.cn>
 * @link http://www.coolcode.cn/?action=show&id=128
 */
index 0df572fd082f1cad9ea4f713b8c4126187d3f47b..4cbd56652ab024575900312be440118da9262f88 100644 (file)
@@ -1,6 +1,7 @@
 Adminer 3.0.0-dev:
 Drivers for MS SQL, SQLite, PostgreSQL
 Allow concurrent logins on the same server
+Allow permanent login without customization
 In-place editation in select
 Show number of tables in server overview
 Operator LIKE %%
index 3c18971c5975723491d6c2fea5f9e4791d5b0d20..dc8a9324a309246af7c970373647e768e5f3e192 100644 (file)
@@ -7,14 +7,14 @@ class Adminer {
                return lang('Editor');
        }
        
-       //! driver
+       //! driver, ns
        
        function credentials() {
                return array(); // default INI settings
        }
        
        function permanentLogin() {
-               return "";
+               return password_file();
        }
        
        function database() {
@@ -37,9 +37,7 @@ document.getElementById('username').focus();
 </script>
 <?php
                echo "<p><input type='submit' value='" . lang('Login') . "'>\n";
-               if ($this->permanentLogin()) {
-                       echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
-               }
+               echo checkbox("permanent", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n";
        }
        
        function login($login, $password) {