Subversion Repositories Sigmater

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
6 Andrea 1
<?php
2
 
3
//
4
// jsrsServer.php - javascript remote scripting server include
5
//
6
 
7
function jsrsDispatch($validFuncs ){
8
  $func = jsrsBuildFunc($validFuncs);
9
 
10
  if ($func != ""){
11
    $retval;
12
 
13
    eval("\$retval =  " . $func . ";");
14
 
15
    if (strlen($retval)>0){
16
      jsrsReturn($retval."");
17
    } else {
18
      jsrsReturn("");
19
    } 
20
  } else {
21
    jsrsReturnError("function builds as empty string");
22
  }
23
}
24
 
25
function jsrsReturn($payload) {
26
  global $C;
27
  if(!isset($C)) $C = (isset($_REQUEST['C']) ? $_REQUEST['C'] : "");
28
 
29
  Print (
30
      "<html><head></head><body onload=\"p=document.layers?parentLayer:window.parent;p.jsrsLoaded('" 
31
    . $C . "');\">jsrsPayload:<br>" 
32
    . "<form name=\"jsrs_Form\"><textarea name=\"jsrs_Payload\">"
33
    . jsrsEscape($payload) . "</textarea></form></body></html>");
34
    exit();
35
}
36
 
37
function jsrsEscape($str){
38
  // escape ampersands so special chars aren't interpreted
39
  $tmp = ereg_replace( "&", "&amp;", $str );
40
  // escape slashes  with whacks so end tags don't interfere with return html
41
  return ereg_replace( "\/" , "\\/",$tmp); 
42
}
43
 
44
/////////////////////////////
45
//
46
// user functions
47
 
48
 
49
function jsrsReturnError($str){
50
  global $C;
51
  if(!isset($C)) $C = (isset($_REQUEST['C']) ? $_REQUEST['C'] : "");
52
 
53
  // escape quotes
54
  $cleanStr = ereg_replace("\'","\\'",$str);
55
 
56
  // !!!! --- Warning -- !!!
57
  $cleanStr = "jsrsError: " . ereg_replace("\"", "\\\"", $cleanStr); 
58
  print ("<html><head></head><body " 
59
         . "onload=\"p=document.layers?parentLayer:window.parent;p.jsrsError('" . $C . "','" . urlencode($str) . "');\">"
60
         . $cleanStr . "</body></html>" );
61
  exit();
62
}
63
 
64
function jsrsArrayToString( $a, $delim ){
65
  // user function to flatten 1-dim array to string for return to client
66
  $d = "~";
67
  if (isset($delim)) $d = $delim;
68
  return implode($a,$d); 
69
}
70
 
71
 
72
function jsrsBuildFunc($validFuncs) {
73
 global $F;
74
 if(!isset($F)) $F = (isset($_REQUEST['F']) ? $_REQUEST['F'] : "");
75
 
76
 $func = ""; 
77
 
78
 if ($F != "") {
79
  $func = $F;
80
 
81
 
82
  // make sure it's in the dispatch list
83
  if (strpos(strtoupper($validFuncs),strtoupper($func))===false)
84
     jsrsReturnError($func . " is not a valid function" );
85
 
86
   $func .= "(";
87
   $i = 0;
88
 
89
   //--- To optimize ! --- 
90
   eval("global \$P$i;");
91
   eval("if(!isset(\$P$i)) \$P$i = (isset(\$_REQUEST['P$i']) ? \$_REQUEST['P$i']:'');");
92
   $Ptmp = "P". $i;
93
 
94
   while ($$Ptmp!="") {
95
    $parm = $$Ptmp;
96
    $parm = substr($parm,1,strlen($parm)-2);
97
    $func .= "\"" . $parm . "\",";
98
    $i++;
99
    eval("global \$P$i;");
100
    eval("if(!isset(\$P$i)) \$P$i = (isset(\$_REQUEST['P$i']) ? \$_REQUEST['P$i']:'');");
101
    $Ptmp = "P". $i;
102
   }
103
 
104
   if (substr($func,strlen($func)-1,1)==",")  
105
    $func = substr($func,0,strlen($func)-1);
106
 
107
    $func .= ")";
108
  } 
109
 
110
 return $func;
111
}
112
 
113
function jsrsEvalEscape($thing) {
114
 $tmp = ereg_replace($thing,"\r\n","\n");
115
 return $tmp;
116
}
117
 
118
function jsrsVBArrayToString($a,$delim) {
119
 // --- not use in PHP see jsrsArrayToString method
120
 return jsrsArrayToString($a,$delim);
121
}
122
 
123
 
124
?>