Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
authorDan
Thu, 26 Jun 2008 18:03:04 -0400
changeset 586 234ddd896555
parent 585 35e91d16ecf5
child 587 705ed7162315
Made encryption work in form-based logon again; modified load_component() to fetch compressed versions when possible
includes/clientside/jsres.php
includes/clientside/static/acl.js
includes/clientside/static/enano-lib-basic.js
includes/clientside/static/l10n.js
includes/clientside/static/pwstrength.js
includes/sessions.php
plugins/SpecialUserFuncs.php
plugins/SpecialUserPrefs.php
--- a/includes/clientside/jsres.php	Thu Jun 26 17:31:33 2008 -0400
+++ b/includes/clientside/jsres.php	Thu Jun 26 18:03:04 2008 -0400
@@ -13,6 +13,24 @@
  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
  */
 
+/**
+ * Returns a floating-point number with the current UNIX timestamp in microseconds. Defined very early because we gotta call it
+ * from very early on in the script to measure the starting time of Enano.
+ * @return float
+ */
+
+// First check to see if something already declared this function.... it happens often.
+if ( !function_exists('microtime_float') )
+{
+  function microtime_float()
+  {
+    list($usec, $sec) = explode(" ", microtime());
+    return ((float)$usec + (float)$sec);
+  }
+}
+
+$local_start = microtime_float();
+
 // Disable for IE, it causes problems.
 if ( ( strstr(@$_SERVER['HTTP_USER_AGENT'], 'MSIE') /*|| true*/ ) && !isset($_GET['early']) )
 {
@@ -101,7 +119,7 @@
 
 // Output format will always be JS
 header('Content-type: text/javascript');
-$everything = '';
+$everything = "/* The code represented in this file is compressed for optimization purposes. The full source code is available in " . scriptPath . "/includes/clientside/static. */\n\nvar ENANO_JSRES_COMPRESSED = true;\n\n";
 
 // if we only want the tiny version of the API (just enough to get by until the full one is loaded), send that
 // with a simple ETag and far future expires header
@@ -165,25 +183,43 @@
 $before_includes = substr($file, 0, $pos_start_includes);
 $after_includes = substr($file, $pos_end_includes);
 
-// compress enano-lib-basic
-$libbasic = "$before_includes\n$after_includes";
-$libbasic = jsres_cache_check('enano-lib-basic.js', $libbasic);
-$everything .= $libbasic;
-
-// $everything .= $before_includes;
-// $everything .= $after_includes;
-
-foreach ( $file_list as $js_file )
+if ( isset($_GET['f']) )
+{
+  // requested a single file
+  $js_file =& $_GET['f'];
+  if ( !preg_match('/^[a-z0-9_-]+\.js$/i', $js_file) )
+  {
+    header('HTTP/1.1 404 Not Found');
+    exit('Not found');
+  }
+  
+  $apex = filemtime("includes/clientside/static/$js_file");
+  
+  $file_contents = file_get_contents("includes/clientside/static/$js_file");
+  $everything = jsres_cache_check($js_file, $file_contents);
+}
+else
 {
-  $file_contents = file_get_contents("includes/clientside/static/$js_file");
-  $time = filemtime("includes/clientside/static/$js_file");
-  if ( $time > $apex )
-    $apex = $time;
+  // compress enano-lib-basic
+  $libbasic = "$before_includes\n$after_includes";
+  $libbasic = jsres_cache_check('enano-lib-basic.js', $libbasic);
+  $everything .= $libbasic;
+  
+  // $everything .= $before_includes;
+  // $everything .= $after_includes;
   
-  $file_contents = jsres_cache_check($js_file, $file_contents);
-  
-  $everything .= "\n\n// $js_file\n";
-  $everything .= "\n" . $file_contents;
+  foreach ( $file_list as $js_file )
+  {
+    $file_contents = file_get_contents("includes/clientside/static/$js_file");
+    $time = filemtime("includes/clientside/static/$js_file");
+    if ( $time > $apex )
+      $apex = $time;
+    
+    $file_contents = jsres_cache_check($js_file, $file_contents);
+    
+    $everything .= "\n\n// $js_file\n";
+    $everything .= "\n" . $file_contents;
+  }
 }
 
 // generate ETag
@@ -209,6 +245,11 @@
 header("ETag: \"$etag\"");
 header("Expires: $expires");
 
+$local_end = microtime_float();
+$local_gentime = $local_end - $local_start;
+$local_gentime = round($local_gentime, 5);
+header("X-Performance: generated in $local_gentime seconds");
+
 echo $everything;
 
 if ( $do_gzip )
--- a/includes/clientside/static/acl.js	Thu Jun 26 17:31:33 2008 -0400
+++ b/includes/clientside/static/acl.js	Thu Jun 26 18:03:04 2008 -0400
@@ -9,10 +9,10 @@
   if(IE)
     return true;
   
+  load_component('l10n');
   load_component('messagebox');
   load_component('fadefilter');
   load_component('template-compiler');
-  load_component('l10n');
   
   if(!page_id || !namespace)
   {
--- a/includes/clientside/static/enano-lib-basic.js	Thu Jun 26 17:31:33 2008 -0400
+++ b/includes/clientside/static/enano-lib-basic.js	Thu Jun 26 18:03:04 2008 -0400
@@ -15,11 +15,16 @@
  * this website for more information.
  */
 
-if(typeof title != 'string')
+if ( typeof(title) != 'string')
 {
   alert('There was a problem loading the PHP-generated Javascript variables that control parameters for AJAX applets. Most on-page functionality will be very badly broken.\n\nTheme developers, ensure that you are using {JS_DYNAMIC_VARS} *before* you include jsres.php.');
 }
 
+if ( typeof(ENANO_JSRES_COMPRESSED) == undefined )
+{
+  var ENANO_JSRES_COMPRESSED = false;
+}
+
 // Run-time variables
 
 var detect = navigator.userAgent.toLowerCase();
@@ -196,8 +201,10 @@
 }
 
 var loaded_components = {};
+var _load_component_running = false;
 function load_component(file)
 {
+  _load_component_running = true;
   file = file.replace(/\.js$/, '');
   
   console.info('Loading component %s via AJAX', file);
@@ -214,7 +221,7 @@
   var ajax = ajaxMakeXHR();
   
   file = file + '.js';
-  var uri = scriptPath + '/includes/clientside/static/' + file;
+  var uri = ( ENANO_JSRES_COMPRESSED ) ? scriptPath + '/includes/clientside/jsres.php?f=' + file : scriptPath + '/includes/clientside/static/' + file;
   ajax.open('GET', uri, false);
   ajax.send(null);
   if ( ajax.readyState == 4 && ajax.status == 200 )
@@ -226,6 +233,7 @@
   }
   
   loaded_components[file] = true;
+  _load_component_running = false;
   return true;
 }
 
@@ -351,22 +359,16 @@
   'dropdown.js',
   'json.js',
   'sliders.js',
-  'pwstrength.js',
   'loader.js'
 ];
 
-var problem_scripts = {
-  'json.js' : true,
-  'template-compiler.js' : true
-};
-
 for(var f in thefiles)
 {
   if ( typeof(thefiles[f]) != 'string' )
     continue;
   var script = document.createElement('script');
   script.type="text/javascript";
-  if ( problem_scripts[thefiles[f]] && KILL_SWITCH )
+  if ( thefiles[f] == 'json.js' && KILL_SWITCH )
   {
     // alert('kill switch and problem script');
     continue;
@@ -443,6 +445,7 @@
   ajaxInitLogout: 'login.js',
   ajaxStartLogin: 'login.js',
   ajaxStartAdminLogin: 'login.js',
+  ajaxLoginNavTo: 'login.js',
   ajaxAdminPage: 'login.js',
   mb_logout: 'login.js',
   selectButtonMajor: 'toolbar.js',
@@ -452,6 +455,8 @@
   darken: 'fadefilter.js',
   enlighten: 'fadefilter.js',
   autofill_onload: 'autofill.js',
+  password_score: 'pwstrength.js',
+  password_score_field: 'pwstrength.js',
 }
 
 var placeholder_instances = {};
--- a/includes/clientside/static/l10n.js	Thu Jun 26 17:31:33 2008 -0400
+++ b/includes/clientside/static/l10n.js	Thu Jun 26 18:03:04 2008 -0400
@@ -25,6 +25,7 @@
     {
       eval_global(ajax.responseText);
     }
+    load_hide_win();
   }
   
   if ( typeof(enano_lang) != 'object' )
--- a/includes/clientside/static/pwstrength.js	Thu Jun 26 17:31:33 2008 -0400
+++ b/includes/clientside/static/pwstrength.js	Thu Jun 26 18:03:04 2008 -0400
@@ -195,6 +195,7 @@
   {
     // $lang isn't initted yet, this happens sometimes on the usercp/emailpassword form.
     // Try to init it if we have ENANO_LANG_ID and enano_lang; if not, report an error.
+    load_component('l10n');
     if ( typeof(enano_lang) == 'object' && typeof(ENANO_LANG_ID) == 'number' )
     {
       language_onload();
--- a/includes/sessions.php	Thu Jun 26 17:31:33 2008 -0400
+++ b/includes/sessions.php	Thu Jun 26 18:03:04 2008 -0400
@@ -3417,6 +3417,7 @@
           
           function runEncryption()
           {
+            load_component(\'crypto\');
             var testpassed = ' . ( ( isset($_GET['use_crypt']) && $_GET['use_crypt']=='0') ? 'false; // CRYPTO-AUTH DISABLED ON USER REQUEST // ' : '' ) . '( aes_self_test() && md5_vm_test() );
             var frm = document.forms.'.$form_name.';
             var use_diffiehellman = false;' . "\n";
--- a/plugins/SpecialUserFuncs.php	Thu Jun 26 17:31:33 2008 -0400
+++ b/plugins/SpecialUserFuncs.php	Thu Jun 26 18:03:04 2008 -0400
@@ -227,7 +227,7 @@
         $errstring = $lang->get('user_err_key_not_found');
         break;
       case 'ERR_DH_KEY_NOT_FOUND':
-        $errstring = $lang->get('user_err_dh_key_not_found') . " -- {$__login_status['debug']}";
+        $errstring = $lang->get('user_err_dh_key_not_found'); // . " -- {$__login_status['debug']}";
         break;
       case 'ERR_DH_KEY_NOT_INTEGER':
         $errstring = $lang->get('user_err_dh_key_not_numeric');
--- a/plugins/SpecialUserPrefs.php	Thu Jun 26 17:31:33 2008 -0400
+++ b/plugins/SpecialUserPrefs.php	Thu Jun 26 18:03:04 2008 -0400
@@ -392,30 +392,17 @@
       ?>
       <script type="text/javascript">
       <?php if ( getConfig('pw_strength_enable') == '1' ): ?>
-      password_score_field(document.forms.empwform.newpass);
-      <?php endif; ?>
-        disableJSONExts();
-        str = '';
-        for(i=0;i<keySizeInBits/4;i++) str+='0';
-        var key = hexToByteArray(str);
-        var pt = hexToByteArray(str);
-        var ct = rijndaelEncrypt(pt, key, "ECB");
-        var ct = byteArrayToHex(ct);
-        switch(keySizeInBits)
+      addOnloadHook(function()
         {
-          case 128:
-            v = '66e94bd4ef8a2c3b884cfa59ca342b2e';
-            break;
-          case 192:
-            v = 'aae06992acbf52a3e8f4a96ec9300bd7aae06992acbf52a3e8f4a96ec9300bd7';
-            break;
-          case 256:
-            v = 'dc95c078a2408989ad48a21492842087dc95c078a2408989ad48a21492842087';
-            break;
-        }
-        var aes_testpassed = ( ct == v && md5_vm_test() );
+          password_score_field(document.forms.empwform.newpass);
+        });
+      <?php endif; ?>
+        
         function runEncryption()
         {
+          load_component('crypto');
+          var aes_testpassed = aes_self_test();
+          
           var frm = document.forms.empwform;
           if ( frm.newpass.value.length < 1 )
             return true;