Subversion Repositories cryptochat

Rev

Blame | Last modification | View Log | RSS feed

  1. <%     
  2.  
  3. function r(str)
  4. {
  5.         Response.write("<br>-"+str+"-<br>")
  6. }
  7.  
  8.         function Sajax(debug_mode)
  9.         {
  10.                 this.debug_mode = debug_mode||false;
  11.                 this.export_list = [];
  12.                 this.js_has_been_shown = false;
  13.        
  14.                 this.handle_client_request = function()
  15.                 {
  16.                         func_name = Request.QueryString("rs");
  17.                         if(!func_name||String(func_name)=="undefined") return false
  18.                        
  19.                         //bust cache
  20.                         Response.AddHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT")
  21.             //always modified
  22.                         Response.AddHeader("Last-Modified", new Date().toGMTString().replace(/UTC/,"GMT"))
  23.                         //HTTP/1.1
  24.             Response.AddHeader("Cache-Control", "no-cache, must-revalidate")
  25.                         //HTTP/1.0
  26.             Response.AddHeader("Pragma", "no-cache")
  27.            
  28.            
  29.            
  30.                         if(this.export_list[func_name]=="undefined")
  31.                         {
  32.                                 result = "-"+func_name+" is not callable";
  33.                 //if(this.debug_mode) Response.write("-"+func_name+" is not callable");
  34.                         }
  35.                         else
  36.                         {
  37.                                 rsargs_raw = Request.QueryString("rsargs[]")
  38.  
  39.                 rsargs = []
  40.                 for(rs_i=1;rs_i<=rsargs_raw.Count;rs_i++)
  41.                 {
  42.                     rsargs[rs_i-1]=rsargs_raw(rs_i)
  43.                 }
  44.  
  45.                // if(this.debug_mode) Response.write("calling " + func_name + "(" +
  46.                //                                    rsargs.join(",")+")")
  47.                                
  48.                 eval_str = this.export_list[func_name]+"("+rsargs+")"
  49.                
  50.                 try
  51.                 {
  52.                     result = "+"+eval(eval_str);
  53.                 }
  54.                 catch(e)
  55.                 {
  56.                     result = "-"+e.message+" (x_"+eval_str+")";
  57.                 }
  58.                         }
  59.                        
  60.             Response.write(result+"[sajax_result________end]]")
  61.                         //exit()
  62.                 }
  63.                
  64.                 this.show_common_js = function()
  65.                 {
  66.                         js_debug_mode = this.debug_mode
  67.                 js_string_out = "      // remote scripting library\n" +
  68.                                                         "      // (c) copyright 2005 modernmethod, inc\n" +
  69.                                                         "      var rs_debug_mode = "+js_debug_mode+";\n" +
  70.                                                         "      var rs_obj = false;\n" +
  71.                                                         "      var rs_callback = false;\n" +
  72.                                                         "      \n" +
  73.                                                         "      function rs_debug(text) {\n" +
  74.                                                         "         if (rs_debug_mode)\n" +
  75.                                                         "            alert('RSD: ' + text)\n" +
  76.                                                         "      }\n" +
  77.                                                         "      \n" +
  78.                                                         "       function rs_init_object() {\n" +
  79.                                                         "          rs_debug('rs_init_object() called..')\n" +
  80.                                                         "          \n" +
  81.                                                         "          var A;\n" +
  82.                                                         "         try {\n" +
  83.                                                         "            A=new ActiveXObject('Msxml2.XMLHTTP');\n" +
  84.                                                         "         } catch (e) {\n" +
  85.                                                         "            try {\n" +
  86.                                                         "               A=new ActiveXObject('Microsoft.XMLHTTP');\n" +
  87.                                                         "            } catch (oc) {\n" +
  88.                                                         "               A=null;\n" +
  89.                                                         "            }\n" +
  90.                                                         "         }\n" +
  91.                                                         "         if(!A && typeof XMLHttpRequest != 'undefined')\n" +
  92.                                                         "            A = new XMLHttpRequest();\n" +
  93.                                                         "         if (!A)\n" +
  94.                                                         "            rs_debug('Could not create connection object.');\n" +
  95.                                                         "         return A;\n" +
  96.                                                         "      }\n"
  97.  
  98.                         Response.write(js_string_out)
  99.                 }
  100.  
  101.                 this.rs_esc=function(val)
  102.                 {
  103.                        
  104.                 }
  105.                
  106.                 this.export_function = function()
  107.                 {
  108.                         for(var i=0;i<arguments.length;i++)
  109.                         {
  110.                                 this.export_list[arguments[i]] = arguments[i];
  111.                         }
  112.                 }
  113.                
  114.                 this.show_javascript = function()
  115.                 {
  116.                         if(!this.js_has_been_shown)
  117.                         {
  118.                                 this.show_common_js()
  119.                                 this.js_has_been_shown = true
  120.                         }
  121.                
  122.                         for(func_name in this.export_list)
  123.                         {
  124.                                 this.show_one(func_name);
  125.                         }
  126.                 }
  127.                
  128.                 this.rs_esc = function(val)
  129.                 {
  130.                         var dqex = /\"/g //"
  131.                         return val.replace(dqex, '\\\\"')
  132.                 }
  133.                
  134.                 this.show_one=function(func_name)
  135.                 {
  136.                         var svr, srl, qsr;
  137.                        
  138.                         svr = Request.ServerVariables("SERVER_NAME")
  139.                         srl = Request.ServerVariables("URL")
  140.                         qsr = Request.ServerVariables("QUERY_STRING");
  141.                         uri = svr + srl + qsr;
  142.  
  143.                         if(!(uri.indexOf('?')>-1))
  144.                         {
  145.                                 uri += "?rs=" +  escape(func_name)
  146.                         }
  147.                         else
  148.                         {
  149.                                 uri += "&rs=" + escape(func_name)
  150.                         }
  151.  
  152.                     escapeduri = this.rs_esc(uri)
  153.                         js_string_out = "   // wrapper for "+func_name+"\n" +
  154.                                                         "   function x_"+func_name+"(){\n" +
  155.                                                         "      // count args; build URL\n" +
  156.                                                         "         var i, x, n;\n" +
  157.                                                         "         //var url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" +
  158.                                                         "         url = 'http://"+escapeduri+"', a = x_"+func_name+".arguments;\n" +
  159.                                                         "         for (i = 0; i < a.length-1; i++)\n" +
  160.                                                         "            url = url + '&rsargs[]=' + escape(a[i]);\n" +
  161.                                                         "         x = rs_init_object();\n" +
  162.                                                         "         x.open('GET', url, true);\n" +
  163.                                                         "         x.onreadystatechange = function() {\n" +
  164.                                                         "            if (x.readyState != 4)\n" +
  165.                                                         "               return;\n" +
  166.                                                         "            rs_debug('received ' + x.responseText);\n" +
  167.                                                         "            \n" +
  168.                                                         "            var status;\n" +
  169.                                                         "            var data;\n" +
  170.                                                         "            status = x.responseText.charAt(0);\n" +
  171.                                                         "            data = x.responseText;\n" +
  172.                             "            var pos = data.indexOf('[sajax_result________end]]');\n " +
  173.                                                         "            if (status == '-'){\n" +
  174.                                                         "               if("+this.debug_mode+"){alert('Error: ' + data.substring(1,pos));}}\n" +
  175.                                                         "            else \n" +
  176.                                                         "               a[a.length-1](data.substring(1,pos));\n" +
  177.                                                         "         }\n" +
  178.                                                         "         x.send(null);\n" +
  179.                                                         "         rs_debug('x_"+func_name+" url = ' + url);\n" +
  180.                                                         "         rs_debug('x_"+func_name+" waiting..');\n" +
  181.                                                         "      }\n"
  182.                
  183.                         Response.write(js_string_out)
  184.                 }
  185.         }
  186. %>