Index: /branches/rel_ag_9_4_5/webui/proxy/new/inc/class.anLib_cli.php
===================================================================
--- /branches/rel_ag_9_4_5/webui/proxy/new/inc/class.anLib_cli.php	(revision 20543)
+++ /branches/rel_ag_9_4_5/webui/proxy/new/inc/class.anLib_cli.php	(working copy)
@@ -324,9 +324,9 @@
 	 * @param mixed         printf like variable arguments
 	 *
 	 *************************************************************************/
-	function exec($cmd_format) /* more arguments are available */
+	static function exec($cmd_format) /* more arguments are available */
 	{
-			
+
 		$numargs = func_num_args();
 		$arg_list = func_get_args();
 		array_shift($arg_list);
@@ -425,8 +425,19 @@
 	 * @return object decode the last json string and return
 	 *
 	 *************************************************************************/
-	function check_multiple_json_format($cmd_str, $output)
+	static function check_multiple_json_format($cmd_str, $output)
 	{
+		// There may be special characters before or after json strings,
+		// so we need to clean the special characters first.
+		$output = preg_replace('/^\xEF\xBB\xBF/', '', $output); // remove BOM
+		$output = preg_replace('/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/', '', $output); // remove control characters(Such as \t, \r, \n)
+		$output = preg_replace('/[\xF0-\xFF]/', '', $output); // remove $f_eop and other non-utf8 characters
+		$output = trim($output);
+
+		if (empty($output)) {
+			return self::create_response();
+		}
+
 		$jsons = array();
 		$buffer = '';
 		$depth = 0;
@@ -444,14 +455,26 @@
 				}
 			}
 		}
+
+		if (empty($jsons)) {
+			return self::create_response(array($output), 0, -1);
+		}
+
+		// There is some reason cause the result of output is two json format,
+		// so we hope we can find the last valid json string from the output.
+		$last_valid_json = null;
 		foreach ($jsons as $json) {
-			if (!json_decode($json)) {
-				//error parsing json - this must be a bug
-				echo "Fatal error executing command: $cmd_str; The abnormal response is \"$output\"\n";
-				exit(1);
+			$decoded = json_decode($json);
+			if ($decoded === null && json_last_error() !== JSON_ERROR_NONE) {
+				continue;
 			}
+			$last_valid_json = $decoded;
+		}
+		if ($last_valid_json === null) {
+			echo "Fatal error executing command: $cmd_str; The abnormal response is \"$output\"\n";
+			exit(1);
 		}
-		return json_decode(end($jsons));
+		return $last_valid_json;
 	}
 	/*************************************************************************
 	 *
@@ -997,6 +1020,27 @@
 		}
 		return $temp;
 	}
+
+	/*************************************************************************
+	 *
+	 * Create a default response object
+	 *
+	 * @param array   $content  Response content array
+	 * @param int     $result   Result code (1 = success, 0 = fail)
+	 * @param int     $reason   Reason code
+	 *
+	 * @return object  stdClass response object
+	 *
+	 *************************************************************************/
+	static function create_response($content = array(), $result = 0, $reason = 0)
+	{
+		$response = new stdClass();
+		$response->content = $content;
+		$response->result = $result;
+		$response->reason = $reason;
+		return $response;
+	}
+
 }
 /*************************************************************************
  *
