Exemplo n.º 1
0
 /**
  * 处理业务逻辑 查询log 查询统计信息
  * @see PHPServerWorker::dealProcess()
  */
 public function dealProcess($recv_str)
 {
     $time_start = microtime(true);
     HTTP::decode($recv_str);
     $rsp_data = '';
     $services = json_encode($this->getService());
     if (!empty($_POST)) {
         $class = isset($_POST['class']) ? $_POST['class'] : '';
         $func = isset($_POST['func']) ? $_POST['func'] : '';
         $param = isset($_POST['value']) ? $_POST['value'] : array();
         if (get_magic_quotes_gpc() && !empty($_POST['value']) && is_array($_POST['value'])) {
             foreach ($_POST['value'] as $index => $value) {
                 $_POST['value'][$index] = stripslashes(trim($value));
             }
         }
         if ($param) {
             foreach ($param as $index => $value) {
                 if (stripos($value, 'array') === 0 || $value === 'true' || $value === 'false' || $value == 'null' || stripos($value, 'object') === 0) {
                     eval('$param[' . $index . ']=' . $value . ';');
                 }
             }
         }
         global $reqText, $rspText;
         try {
             $rsp_data = call_user_func_array(array(ClientForTest::instance($class), $func), $param);
         } catch (Exception $e) {
             $rsp_data = $e . '';
         }
         return $this->display($rsp_data, microtime(true) - $time_start, $services);
     } elseif (isset($_GET['ajax_get_service'])) {
         $this->sendToClient(HTTP::encode($services));
     }
     $this->display('', '', '', '', microtime(true) - $time_start);
 }
Exemplo n.º 2
0
 /**
  * 处理业务逻辑 查询log 查询统计信息
  * @see PHPServerWorker::dealProcess()
  */
 public function dealProcess($recv_str)
 {
     HTTP::decode($recv_str);
     $module = isset($_GET['module']) ? trim($_GET['module']) : '';
     $interface = isset($_GET['interface']) ? trim($_GET['interface']) : '';
     $start_time = isset($_GET['start_time']) ? trim($_GET['start_time']) : '';
     $end_time = isset($_GET['end_time']) ? trim($_GET['end_time']) : '';
     // 管理员
     if (0 === strpos($_SERVER['REQUEST_URI'], '/admin')) {
         return $this->admin();
     } elseif (0 === strpos($_SERVER['REQUEST_URI'], '/html')) {
         if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
             HTTP::header("HTTP/1.1 304 Not Modified");
             return $this->sendToClient(HTTP::encode(''));
         }
         $modified_time = date('D, d M Y H:i:s');
         $base_name = basename($_SERVER['REQUEST_URI']);
         switch ($base_name) {
             case 'highcharts.js':
                 HTTP::header("Content-Type: application/javascript");
                 HTTP::header("Last-Modified: {$modified_time}");
                 return $this->sendToClient(HTTP::encode(self::$hichart));
             case 'jquery.min.js':
                 HTTP::header("Content-Type: application/javascript");
                 HTTP::header("Last-Modified: {$modified_time}");
                 return $this->sendToClient(HTTP::encode(self::$jquery));
             default:
                 HTTP::header("HTTP/1.1 404 Not Found");
                 return $this->sendToClient(HTTP::encode(''));
         }
     } elseif (0 === strpos($_SERVER['REQUEST_URI'], '/log')) {
         $this->checkRedirect();
         $right_str = '';
         $code = isset($_GET['code']) ? $_GET['code'] : '';
         $msg = isset($_GET['msg']) ? $_GET['msg'] : '';
         $pointer = isset($_GET['pointer']) ? $_GET['pointer'] : '';
         $count = isset($_GET['count']) ? $_GET['count'] : 5;
         $log_data_arr = $this->getStasticLog($module, $interface, $start_time, $end_time, $code, $msg, $pointer, $count);
         $log_data_str = '';
         unset($_GET['ip']);
         unset($_GET['pointer']);
         foreach ($log_data_arr as $address => $log_data) {
             list($ip, $port) = explode(':', $address);
             $str = str_replace('source_ip:', 'client_ip:', $log_data['data']);
             $log_data_str .= preg_replace('/t?arget_ip:\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}/', 'server_ip:' . $ip . "<br/>", $str);
             $_GET['ip'][] = $ip;
             $_GET['pointer'][] = $log_data['pointer'];
         }
         // 过滤掉用户名密码
         $log_data_str = preg_replace(array('/([^#]*?Db[a-zA-Z]*Connection[^#]*?[construct|connect]\\()([^)]*?),([^)]*?),([^)]*?)(,[^)]*?\\))/i', '/(REQUEST_DATA:.*?)"password":"******"]*?)"/'), array('${1}${2}, ****, ****$5', '$1"password":"******"'), $log_data_str);
         unset($_GET['end_time']);
         $next_page_url = http_build_query($_GET);
         $log_data_str .= "</br><center><a href='/log/?{$next_page_url}'>下一页</a></center>";
         return $this->display(nl2br($log_data_str));
     } else {
         $this->checkRedirect();
         // 首页
         if (empty($module)) {
             return $this->home();
         } else {
             if ($interface) {
                 return $this->displayInterface($module, $interface, $start_time, $end_time);
             } else {
                 $this->multiRequestStAndModules($module);
                 return $this->display();
             }
         }
     }
     return $this->display();
 }
Exemplo n.º 3
0
 /**
  * 处理业务逻辑 查询log 查询统计信息
  * @see PHPServerWorker::dealProcess()
  */
 public function dealProcess($recv_str)
 {
     $time_start = microtime(true);
     HTTP::decode($recv_str);
     $rsp_data = '';
     if (!empty($_POST)) {
         // 传的是json文本
         if (!empty($_POST['req_data'])) {
             $req_text = trim($_POST['req_data']);
             // 文本前有非json字符
             if ($req_text[0] != "{" && $req_text[0] != "[") {
                 for ($i = 0, $j = strlen($req_text); $i < $j; $i++) {
                     if ($req_text[$i] == "{" || $req_text[$i] == "[") {
                         $req_text = substr($req_text, $i);
                         break;
                     }
                 }
             }
             $len = strlen($req_text);
             if ($req_text[$len - 1] != "}" && $req_text[$len - 1] != "]") {
                 for ($i = $len - 1; $i > 0; $i--) {
                     if ($req_text[$i] == "]" || $req_text[$i] == "}") {
                         $req_text = substr($req_text, 0, $i + 1);
                         break;
                     }
                 }
             }
             $req_data = json_decode($req_text, true);
             if (isset($req_data[0])) {
                 $req_data = $req_data[0];
             }
             if (isset($req_data['data'])) {
                 $req_data = json_decode($req_data['data'], true);
             }
             if (is_array($req_data)) {
                 if (isset($req_data['class'])) {
                     $_POST['class'] = str_replace('RpcClient_', '', $req_data['class']);
                 }
                 if (isset($req_data['method'])) {
                     $_POST['func'] = $req_data['method'];
                 }
                 if (isset($req_data['params'])) {
                     $_POST['value'] = $req_data['params'];
                     if (is_array($_POST['value'])) {
                         foreach ($_POST['value'] as $key => $value) {
                             if (!is_scalar($value)) {
                                 $_POST['value'][$key] = var_export($value, true);
                             } else {
                                 if ($value === true) {
                                     $_POST['value'][$key] = 'true';
                                 } elseif ($value === false) {
                                     $_POST['value'][$key] = 'false';
                                 } elseif ($value === null) {
                                     $_POST['value'][$key] = 'null';
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $class = isset($_POST['class']) ? $_POST['class'] : '';
         $func = isset($_POST['func']) ? $_POST['func'] : '';
         $param = isset($_POST['value']) ? $_POST['value'] : '';
         $post_address = isset($_POST['address']) ? $_POST['address'] : '127.0.0.1:2201';
         list($address_ip, $address_port) = explode(':', $post_address);
         if (get_magic_quotes_gpc() && !empty($_POST['value']) && is_array($_POST['value'])) {
             foreach ($_POST['value'] as $index => $value) {
                 $_POST['value'][$index] = stripslashes(trim($value));
             }
         }
         if ($param) {
             foreach ($param as $index => $value) {
                 if (stripos($value, 'array') === 0 || stripos($value, 'true') === 0 || stripos($value, 'false') === 0 || stripos($value, 'null') === 0 || stripos($value, 'object') === 0) {
                     eval('$param[' . $index . ']=' . $value . ';');
                 }
             }
         }
         global $reqText, $rspText;
         JMTextRpcClient::on('send', function ($data) {
             global $reqText;
             $reqText = $data;
         });
         JMTextRpcClient::on('recv', function ($data) {
             global $rspText;
             $rspText = $data;
         });
         try {
             if (!class_exists('RpcClient_' . $class)) {
                 eval('class RpcClient_' . $class . ' extends JMTextRpcClient {}');
             }
             $remote_class = 'RpcClient_' . $class;
             $config = array('rpc_secret_key' => '769af463a39f077a0340a189e9c1ec28', 'User' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Item' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Order' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'), 'Cart' => array('host' => $address_ip, 'port' => $address_port, 'user' => 'Optool', 'secret' => '{1BA09530-F9E6-478D-9965-7EB31A59537E}'));
             $test = $remote_class::instance($config);
             //call_user_func_array(array($test, 'asend_'.$func), $param);
             //$rsp_data = call_user_func_array(array($test, 'arecv_'.$func), $param);
             $rsp_data = call_user_func_array(array($test, $func), $param);
         } catch (Exception $e) {
             $rsp_data = $e . '';
         }
         if (isset($_POST['req_data'])) {
             $reqText = $_POST['req_data'];
         }
         return $this->display($reqText, $rspText, $rsp_data, '', microtime(true) - $time_start);
     }
     $this->display('', '', '', '', microtime(true) - $time_start);
 }