From 6e19805bcbb00c096df03fa97ad40bb395dd0043 Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Thu, 4 Mar 2021 07:55:41 -0600 Subject: [PATCH] remove legacy json format function (#12583) * remove legacy json format function * remove silly use --- LibreNMS/Util/ModuleTestHelper.php | 2 +- includes/functions.php | 122 ------------------ includes/html/forms/add-dashboard.inc.php | 4 +- includes/html/forms/alert-templates.inc.php | 2 +- .../html/forms/application-update.inc.php | 2 +- includes/html/forms/component.inc.php | 4 +- includes/html/forms/create-service.inc.php | 2 +- includes/html/forms/customoid.inc.php | 2 +- .../html/forms/delete-cluster-poller.inc.php | 2 +- includes/html/forms/delete-customoid.inc.php | 2 +- includes/html/forms/delete-dashboard.inc.php | 4 +- includes/html/forms/delete-poller.inc.php | 2 +- includes/html/forms/delete-service.inc.php | 2 +- includes/html/forms/edit-dashboard.inc.php | 2 +- .../html/forms/get-host-dependencies.inc.php | 2 +- includes/html/forms/mempool-update.inc.php | 4 +- includes/html/forms/override-config.inc.php | 4 +- .../html/forms/parse-alert-template.inc.php | 2 +- includes/html/forms/parse-customoid.inc.php | 2 +- .../html/forms/parse-poller-groups.inc.php | 2 +- includes/html/forms/parse-service.inc.php | 2 +- includes/html/forms/processor-update.inc.php | 4 +- includes/html/forms/rediscover-device.inc.php | 4 +- .../html/forms/refresh-oxidized-node.inc.php | 2 +- .../forms/reload-oxidized-nodes-list.inc.php | 2 +- includes/html/forms/reset-port-state.inc.php | 4 +- includes/html/forms/routing-update.inc.php | 4 +- .../html/forms/schedule-maintenance.inc.php | 2 +- .../html/forms/search-oxidized-config.inc.php | 12 +- .../html/forms/sensor-alert-reset.inc.php | 4 +- .../html/forms/sensor-alert-update.inc.php | 4 +- includes/html/forms/sensor-update.inc.php | 4 +- includes/html/forms/storage-update.inc.php | 4 +- .../forms/update-dashboard-config.inc.php | 4 +- includes/html/forms/update-ifalias.inc.php | 2 +- includes/html/forms/update-ifspeed.inc.php | 2 +- includes/html/forms/update-ports.inc.php | 4 +- includes/html/print-graph-alerts.inc.php | 2 +- includes/html/table/address-search.inc.php | 2 +- includes/html/table/alertlog-stats.inc.php | 2 +- includes/html/table/alertlog.inc.php | 2 +- includes/html/table/alerts.inc.php | 2 +- includes/html/table/app_ntp.inc.php | 2 +- includes/html/table/arp-search.inc.php | 2 +- includes/html/table/as-selection.inc.php | 2 +- includes/html/table/bills.inc.php | 2 +- includes/html/table/component.inc.php | 2 +- includes/html/table/edit-ports.inc.php | 2 +- includes/html/table/eventlog.inc.php | 2 +- includes/html/table/graylog.inc.php | 2 +- includes/html/table/inventory.inc.php | 2 +- includes/html/table/ix-list.inc.php | 2 +- includes/html/table/ix-peers.inc.php | 2 +- includes/html/table/mempool-edit.inc.php | 2 +- includes/html/table/ports.inc.php | 2 +- includes/html/table/processor-edit.inc.php | 2 +- includes/html/table/processor.inc.php | 2 +- includes/html/table/routing-edit.inc.php | 2 +- includes/html/table/sensors-common.php | 2 +- includes/html/table/storage-edit.inc.php | 2 +- includes/html/table/storage.inc.php | 2 +- includes/html/table/stp-ports.inc.php | 2 +- includes/html/table/tnmsneinfo.inc.php | 2 +- includes/html/table/toner.inc.php | 2 +- includes/services.inc.php | 2 +- 65 files changed, 84 insertions(+), 206 deletions(-) diff --git a/LibreNMS/Util/ModuleTestHelper.php b/LibreNMS/Util/ModuleTestHelper.php index 7c3458c6ca..e53e323df9 100644 --- a/LibreNMS/Util/ModuleTestHelper.php +++ b/LibreNMS/Util/ModuleTestHelper.php @@ -624,7 +624,7 @@ class ModuleTestHelper } } - file_put_contents($this->json_file, _json_encode($existing_data) . PHP_EOL); + file_put_contents($this->json_file, json_encode($existing_data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . PHP_EOL); $this->qPrint("Saved to $this->json_file\nReady for testing!\n"); } diff --git a/includes/functions.php b/includes/functions.php index 2b8fa1a75c..d75bf8271d 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -1107,128 +1107,6 @@ function validate_device_id($id) return $return; } -// The original source of this code is from Stackoverflow (www.stackoverflow.com). -// http://stackoverflow.com/questions/6054033/pretty-printing-json-with-php -// Answer provided by stewe (http://stackoverflow.com/users/3202187/ulk200 -if (! defined('JSON_UNESCAPED_SLASHES')) { - define('JSON_UNESCAPED_SLASHES', 64); -} -if (! defined('JSON_PRETTY_PRINT')) { - define('JSON_PRETTY_PRINT', 128); -} -if (! defined('JSON_UNESCAPED_UNICODE')) { - define('JSON_UNESCAPED_UNICODE', 256); -} - -function _json_encode($data, $options = 448) -{ - if (version_compare(PHP_VERSION, '5.4', '>=')) { - return json_encode($data, $options); - } else { - return _json_format(json_encode($data), $options); - } -} - -function _json_format($json, $options = 448) -{ - $prettyPrint = (bool) ($options & JSON_PRETTY_PRINT); - $unescapeUnicode = (bool) ($options & JSON_UNESCAPED_UNICODE); - $unescapeSlashes = (bool) ($options & JSON_UNESCAPED_SLASHES); - - if (! $prettyPrint && ! $unescapeUnicode && ! $unescapeSlashes) { - return $json; - } - - $result = ''; - $pos = 0; - $strLen = strlen($json); - $indentStr = ' '; - $newLine = "\n"; - $outOfQuotes = true; - $buffer = ''; - $noescape = true; - - for ($i = 0; $i < $strLen; $i++) { - // Grab the next character in the string - $char = substr($json, $i, 1); - - // Are we inside a quoted string? - if ('"' === $char && $noescape) { - $outOfQuotes = ! $outOfQuotes; - } - - if (! $outOfQuotes) { - $buffer .= $char; - $noescape = '\\' === $char ? ! $noescape : true; - continue; - } elseif ('' !== $buffer) { - if ($unescapeSlashes) { - $buffer = str_replace('\\/', '/', $buffer); - } - - if ($unescapeUnicode && function_exists('mb_convert_encoding')) { - // http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-cha - $buffer = preg_replace_callback( - '/\\\\u([0-9a-f]{4})/i', - function ($match) { - return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE'); - }, - $buffer - ); - } - - $result .= $buffer . $char; - $buffer = ''; - continue; - } elseif (false !== strpos(" \t\r\n", $char)) { - continue; - } - - if (':' === $char) { - // Add a space after the : character - $char .= ' '; - } elseif (('}' === $char || ']' === $char)) { - $pos--; - $prevChar = substr($json, $i - 1, 1); - - if ('{' !== $prevChar && '[' !== $prevChar) { - // If this character is the end of an element, - // output a new line and indent the next line - $result .= $newLine; - for ($j = 0; $j < $pos; $j++) { - $result .= $indentStr; - } - } else { - // Collapse empty {} and [] - $result = rtrim($result) . "\n\n" . $indentStr; - } - } - - $result .= $char; - - // If the last character was the beginning of an element, - // output a new line and indent the next line - if (',' === $char || '{' === $char || '[' === $char) { - $result .= $newLine; - - if ('{' === $char || '[' === $char) { - $pos++; - } - - for ($j = 0; $j < $pos; $j++) { - $result .= $indentStr; - } - } - } - // If buffer not empty after formating we have an unclosed quote - if (strlen($buffer) > 0) { - //json is incorrectly formatted - $result = false; - } - - return $result; -} - function convert_delay($delay) { $delay = preg_replace('/\s/', '', $delay); diff --git a/includes/html/forms/add-dashboard.inc.php b/includes/html/forms/add-dashboard.inc.php index 1806a0ceab..084fdf1009 100644 --- a/includes/html/forms/add-dashboard.inc.php +++ b/includes/html/forms/add-dashboard.inc.php @@ -26,7 +26,7 @@ if (! Auth::check()) { 'status' => 'error', 'message' => 'Unauthenticated', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -49,4 +49,4 @@ $response = [ 'dashboard_id' => $dash_id, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/alert-templates.inc.php b/includes/html/forms/alert-templates.inc.php index d4a4a99488..c264786faa 100644 --- a/includes/html/forms/alert-templates.inc.php +++ b/includes/html/forms/alert-templates.inc.php @@ -85,4 +85,4 @@ if (isset($vars['template']) && empty(view(['template' => $vars['template']], [] $response = ['status' => $status, 'message' => $message, 'newid' => $template_newid]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/application-update.inc.php b/includes/html/forms/application-update.inc.php index 9ff725ee8b..21d7f186de 100644 --- a/includes/html/forms/application-update.inc.php +++ b/includes/html/forms/application-update.inc.php @@ -51,4 +51,4 @@ if (! Auth::user()->hasGlobalAdmin()) { } } header('Content-Type: application/json'); -echo _json_encode($status); +echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/component.inc.php b/includes/html/forms/component.inc.php index 8b7bb6ced6..b052102fc9 100644 --- a/includes/html/forms/component.inc.php +++ b/includes/html/forms/component.inc.php @@ -7,7 +7,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -79,4 +79,4 @@ $response = [ 'status' => $status, 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/create-service.inc.php b/includes/html/forms/create-service.inc.php index 62b88b0d1c..745ce2fed1 100644 --- a/includes/html/forms/create-service.inc.php +++ b/includes/html/forms/create-service.inc.php @@ -45,4 +45,4 @@ if (is_numeric($service_id) && $service_id > 0) { } } header('Content-Type: application/json'); -echo _json_encode($status); +echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/customoid.inc.php b/includes/html/forms/customoid.inc.php index b1f4967a74..c64a2a1e4d 100644 --- a/includes/html/forms/customoid.inc.php +++ b/includes/html/forms/customoid.inc.php @@ -7,7 +7,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } diff --git a/includes/html/forms/delete-cluster-poller.inc.php b/includes/html/forms/delete-cluster-poller.inc.php index 0ba1e33b80..8b50b0f744 100644 --- a/includes/html/forms/delete-cluster-poller.inc.php +++ b/includes/html/forms/delete-cluster-poller.inc.php @@ -37,4 +37,4 @@ if (! Auth::user()->hasGlobalAdmin()) { } } header('Content-Type: application/json'); -echo _json_encode($status); +echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/delete-customoid.inc.php b/includes/html/forms/delete-customoid.inc.php index 00b1c35056..ff4faa474b 100644 --- a/includes/html/forms/delete-customoid.inc.php +++ b/includes/html/forms/delete-customoid.inc.php @@ -7,7 +7,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } diff --git a/includes/html/forms/delete-dashboard.inc.php b/includes/html/forms/delete-dashboard.inc.php index 827a35c1bc..12b94e672b 100644 --- a/includes/html/forms/delete-dashboard.inc.php +++ b/includes/html/forms/delete-dashboard.inc.php @@ -26,7 +26,7 @@ if (! Auth::check()) { 'status' => 'error', 'message' => 'Unauthenticated', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -52,4 +52,4 @@ $response = [ 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/delete-poller.inc.php b/includes/html/forms/delete-poller.inc.php index 6d7ef0ec03..b59eaeb29d 100644 --- a/includes/html/forms/delete-poller.inc.php +++ b/includes/html/forms/delete-poller.inc.php @@ -37,4 +37,4 @@ if (! Auth::user()->hasGlobalAdmin()) { } } header('Content-Type: application/json'); -echo _json_encode($status); +echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/delete-service.inc.php b/includes/html/forms/delete-service.inc.php index 4d679e0526..a28a570c37 100644 --- a/includes/html/forms/delete-service.inc.php +++ b/includes/html/forms/delete-service.inc.php @@ -25,4 +25,4 @@ if (! Auth::user()->hasGlobalAdmin()) { } } header('Content-Type: application/json'); -echo _json_encode($status); +echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/edit-dashboard.inc.php b/includes/html/forms/edit-dashboard.inc.php index dbcf1536f7..3cbd6f6e26 100644 --- a/includes/html/forms/edit-dashboard.inc.php +++ b/includes/html/forms/edit-dashboard.inc.php @@ -44,4 +44,4 @@ $response = [ 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/get-host-dependencies.inc.php b/includes/html/forms/get-host-dependencies.inc.php index 4c36780b2c..4c25faa464 100644 --- a/includes/html/forms/get-host-dependencies.inc.php +++ b/includes/html/forms/get-host-dependencies.inc.php @@ -108,4 +108,4 @@ if (! Auth::user()->hasGlobalAdmin()) { } header('Content-Type: application/json'); -echo _json_encode($status); +echo json_encode($status, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/mempool-update.inc.php b/includes/html/forms/mempool-update.inc.php index e2b4ec3e03..c3c2b25a8f 100644 --- a/includes/html/forms/mempool-update.inc.php +++ b/includes/html/forms/mempool-update.inc.php @@ -19,7 +19,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -50,4 +50,4 @@ $response = [ 'message' => $message, 'extra' => $extra, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/override-config.inc.php b/includes/html/forms/override-config.inc.php index 5229d06691..9da8f8b836 100644 --- a/includes/html/forms/override-config.inc.php +++ b/includes/html/forms/override-config.inc.php @@ -19,7 +19,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -45,4 +45,4 @@ $response = [ 'status' => $status, 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/parse-alert-template.inc.php b/includes/html/forms/parse-alert-template.inc.php index 5245ccb920..3b98f2c146 100644 --- a/includes/html/forms/parse-alert-template.inc.php +++ b/includes/html/forms/parse-alert-template.inc.php @@ -54,4 +54,4 @@ foreach (dbFetchRows('SELECT `id`,`rule`,`name` FROM `alert_rules` order by `nam $output['rules'] = $rules; header('Content-type: application/json'); -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/parse-customoid.inc.php b/includes/html/forms/parse-customoid.inc.php index e368c2fff7..486ad68c36 100644 --- a/includes/html/forms/parse-customoid.inc.php +++ b/includes/html/forms/parse-customoid.inc.php @@ -5,7 +5,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } $customoid_id = $_POST['customoid_id']; diff --git a/includes/html/forms/parse-poller-groups.inc.php b/includes/html/forms/parse-poller-groups.inc.php index 088d3d7543..105a84d20b 100644 --- a/includes/html/forms/parse-poller-groups.inc.php +++ b/includes/html/forms/parse-poller-groups.inc.php @@ -26,5 +26,5 @@ if (is_numeric($group_id) && $group_id > 0) { 'descr' => $group['descr'], ]; header('Content-type: application/json'); - echo _json_encode($output); + echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } diff --git a/includes/html/forms/parse-service.inc.php b/includes/html/forms/parse-service.inc.php index 544a654c9e..1d536ae257 100644 --- a/includes/html/forms/parse-service.inc.php +++ b/includes/html/forms/parse-service.inc.php @@ -33,5 +33,5 @@ if (is_numeric($service_id) && $service_id > 0) { ]; header('Content-Type: application/json'); - echo _json_encode($output); + echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } diff --git a/includes/html/forms/processor-update.inc.php b/includes/html/forms/processor-update.inc.php index 9ff0e9a467..8fa52c0935 100644 --- a/includes/html/forms/processor-update.inc.php +++ b/includes/html/forms/processor-update.inc.php @@ -19,7 +19,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -50,4 +50,4 @@ $response = [ 'message' => $message, 'extra' => $extra, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/rediscover-device.inc.php b/includes/html/forms/rediscover-device.inc.php index 7c8478dda1..14c766f36e 100644 --- a/includes/html/forms/rediscover-device.inc.php +++ b/includes/html/forms/rediscover-device.inc.php @@ -17,7 +17,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -65,4 +65,4 @@ $output = [ ]; header('Content-type: application/json'); -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/refresh-oxidized-node.inc.php b/includes/html/forms/refresh-oxidized-node.inc.php index 5f87a02975..06bee6fbf0 100644 --- a/includes/html/forms/refresh-oxidized-node.inc.php +++ b/includes/html/forms/refresh-oxidized-node.inc.php @@ -32,4 +32,4 @@ $output = [ ]; header('Content-type: application/json'); -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/reload-oxidized-nodes-list.inc.php b/includes/html/forms/reload-oxidized-nodes-list.inc.php index 8c30f04f58..571871b674 100644 --- a/includes/html/forms/reload-oxidized-nodes-list.inc.php +++ b/includes/html/forms/reload-oxidized-nodes-list.inc.php @@ -23,4 +23,4 @@ $output = [ 'message' => $message, ]; header('Content-type: application/json'); -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/reset-port-state.inc.php b/includes/html/forms/reset-port-state.inc.php index 1f3b9c6c4e..9ba49fdaa0 100644 --- a/includes/html/forms/reset-port-state.inc.php +++ b/includes/html/forms/reset-port-state.inc.php @@ -30,7 +30,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -70,4 +70,4 @@ $output = [ ]; header('Content-type: application/json'); -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/routing-update.inc.php b/includes/html/forms/routing-update.inc.php index 15520ba0cd..7324251374 100644 --- a/includes/html/forms/routing-update.inc.php +++ b/includes/html/forms/routing-update.inc.php @@ -19,7 +19,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -48,4 +48,4 @@ $response = [ 'message' => $message, 'extra' => $extra, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/schedule-maintenance.inc.php b/includes/html/forms/schedule-maintenance.inc.php index 456c72ab55..9939f24ff1 100644 --- a/includes/html/forms/schedule-maintenance.inc.php +++ b/includes/html/forms/schedule-maintenance.inc.php @@ -219,4 +219,4 @@ if ($sub_type == 'new-maintenance') { ]; }//end if header('Content-type: application/json'); -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/search-oxidized-config.inc.php b/includes/html/forms/search-oxidized-config.inc.php index 0548ae4f0c..f5b8349ccb 100644 --- a/includes/html/forms/search-oxidized-config.inc.php +++ b/includes/html/forms/search-oxidized-config.inc.php @@ -22,9 +22,9 @@ if (isset($parameters)) { } else { $message = 'ERROR: Could not query'; } -echo display(_json_encode([ - 'status' => $status, - 'message' => $message, - 'search_in_conf_textbox' => $parameters, - 'output' => $output, -])); +echo display(json_encode([ + 'status' => $status, + 'message' => $message, + 'search_in_conf_textbox' => $parameters, + 'output' => $output, +], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); diff --git a/includes/html/forms/sensor-alert-reset.inc.php b/includes/html/forms/sensor-alert-reset.inc.php index aa5c9e686f..ab58a847ad 100644 --- a/includes/html/forms/sensor-alert-reset.inc.php +++ b/includes/html/forms/sensor-alert-reset.inc.php @@ -20,7 +20,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -51,4 +51,4 @@ $response = [ 'status' => $status, 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/sensor-alert-update.inc.php b/includes/html/forms/sensor-alert-update.inc.php index 918e13729c..5939cc2cc0 100644 --- a/includes/html/forms/sensor-alert-update.inc.php +++ b/includes/html/forms/sensor-alert-update.inc.php @@ -20,7 +20,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -60,4 +60,4 @@ $response = [ 'status' => $status, 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/sensor-update.inc.php b/includes/html/forms/sensor-update.inc.php index 5c49f84a43..8b19f64d53 100644 --- a/includes/html/forms/sensor-update.inc.php +++ b/includes/html/forms/sensor-update.inc.php @@ -20,7 +20,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -50,4 +50,4 @@ $response = [ 'status' => $status, 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/storage-update.inc.php b/includes/html/forms/storage-update.inc.php index c2158fcd7a..9aa4b352d1 100644 --- a/includes/html/forms/storage-update.inc.php +++ b/includes/html/forms/storage-update.inc.php @@ -19,7 +19,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -50,4 +50,4 @@ $response = [ 'message' => $message, 'extra' => $extra, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/update-dashboard-config.inc.php b/includes/html/forms/update-dashboard-config.inc.php index de9ab7abc9..d2657aef6d 100644 --- a/includes/html/forms/update-dashboard-config.inc.php +++ b/includes/html/forms/update-dashboard-config.inc.php @@ -7,7 +7,7 @@ if (! Auth::check()) { 'status' => 'error', 'message' => 'Unauthenticated', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -76,4 +76,4 @@ $response = [ 'message' => $message, 'extra' => $extra, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/update-ifalias.inc.php b/includes/html/forms/update-ifalias.inc.php index eb93520518..5ddb5f9593 100644 --- a/includes/html/forms/update-ifalias.inc.php +++ b/includes/html/forms/update-ifalias.inc.php @@ -44,4 +44,4 @@ if (! empty($ifName) && is_numeric($port_id)) { $response = [ 'status' => $status, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/update-ifspeed.inc.php b/includes/html/forms/update-ifspeed.inc.php index 2e592c2565..5971e7a770 100644 --- a/includes/html/forms/update-ifspeed.inc.php +++ b/includes/html/forms/update-ifspeed.inc.php @@ -54,4 +54,4 @@ if (! empty($ifName) && is_numeric($port_id) && is_numeric($port_id)) { $response = [ 'status' => $status, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/forms/update-ports.inc.php b/includes/html/forms/update-ports.inc.php index aac8d150a2..8c3cad1fa9 100644 --- a/includes/html/forms/update-ports.inc.php +++ b/includes/html/forms/update-ports.inc.php @@ -7,7 +7,7 @@ if (! Auth::user()->hasGlobalAdmin()) { 'status' => 'error', 'message' => 'Need to be admin', ]; - echo _json_encode($response); + echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); exit; } @@ -78,4 +78,4 @@ $response = [ 'status' => $status, 'message' => $message, ]; -echo _json_encode($response); +echo json_encode($response, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/print-graph-alerts.inc.php b/includes/html/print-graph-alerts.inc.php index 7f649be7ab..dcb6bddfa2 100644 --- a/includes/html/print-graph-alerts.inc.php +++ b/includes/html/print-graph-alerts.inc.php @@ -71,7 +71,7 @@ $query = "SELECT DATE_FORMAT(time_logged, '" . \LibreNMS\Config::get('alert_grap } } - $graph_data = _json_encode($data); + $graph_data = json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); ?> var groups = new vis.DataSet(); $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/alertlog-stats.inc.php b/includes/html/table/alertlog-stats.inc.php index 1817410ac5..503f386218 100644 --- a/includes/html/table/alertlog-stats.inc.php +++ b/includes/html/table/alertlog-stats.inc.php @@ -83,4 +83,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/alertlog.inc.php b/includes/html/table/alertlog.inc.php index 92827d6f38..15c973ecff 100644 --- a/includes/html/table/alertlog.inc.php +++ b/includes/html/table/alertlog.inc.php @@ -118,4 +118,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/alerts.inc.php b/includes/html/table/alerts.inc.php index 04c9b67379..26e2562858 100644 --- a/includes/html/table/alerts.inc.php +++ b/includes/html/table/alerts.inc.php @@ -188,4 +188,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/app_ntp.inc.php b/includes/html/table/app_ntp.inc.php index c8416aefb2..5363a99d70 100644 --- a/includes/html/table/app_ntp.inc.php +++ b/includes/html/table/app_ntp.inc.php @@ -105,4 +105,4 @@ $output = [ 'rows' => $response, 'total' => $count, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/arp-search.inc.php b/includes/html/table/arp-search.inc.php index c885441bb2..d44f57e331 100644 --- a/includes/html/table/arp-search.inc.php +++ b/includes/html/table/arp-search.inc.php @@ -112,4 +112,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/as-selection.inc.php b/includes/html/table/as-selection.inc.php index e3d339a7dc..d5863861bb 100644 --- a/includes/html/table/as-selection.inc.php +++ b/includes/html/table/as-selection.inc.php @@ -50,4 +50,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/bills.inc.php b/includes/html/table/bills.inc.php index 2cbdae86af..8e924be6f4 100644 --- a/includes/html/table/bills.inc.php +++ b/includes/html/table/bills.inc.php @@ -173,4 +173,4 @@ foreach (dbFetchRows($sql, $param) as $bill) { } $output = ['current' => $current, 'rowCount' => $rowCount, 'rows' => $response, 'total' => $total]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/component.inc.php b/includes/html/table/component.inc.php index 3885fa90d5..7a34df0483 100644 --- a/includes/html/table/component.inc.php +++ b/includes/html/table/component.inc.php @@ -65,4 +65,4 @@ $output = [ 'rows' => $response, 'total' => count($COMPONENTS[$device_id]), ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/edit-ports.inc.php b/includes/html/table/edit-ports.inc.php index a06eceb3b9..f813dada28 100644 --- a/includes/html/table/edit-ports.inc.php +++ b/includes/html/table/edit-ports.inc.php @@ -83,4 +83,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/eventlog.inc.php b/includes/html/table/eventlog.inc.php index bb401197b5..d79b622356 100644 --- a/includes/html/table/eventlog.inc.php +++ b/includes/html/table/eventlog.inc.php @@ -99,4 +99,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/graylog.inc.php b/includes/html/table/graylog.inc.php index c32dce50d7..c02571d552 100644 --- a/includes/html/table/graylog.inc.php +++ b/includes/html/table/graylog.inc.php @@ -97,4 +97,4 @@ if (empty($messages['total_results'])) { } $output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/inventory.inc.php b/includes/html/table/inventory.inc.php index db3c3e5f02..8f364857b6 100644 --- a/includes/html/table/inventory.inc.php +++ b/includes/html/table/inventory.inc.php @@ -83,4 +83,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/ix-list.inc.php b/includes/html/table/ix-list.inc.php index 63d1899c9f..611b5e5089 100644 --- a/includes/html/table/ix-list.inc.php +++ b/includes/html/table/ix-list.inc.php @@ -68,4 +68,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/ix-peers.inc.php b/includes/html/table/ix-peers.inc.php index f789f163f4..111e9668bb 100644 --- a/includes/html/table/ix-peers.inc.php +++ b/includes/html/table/ix-peers.inc.php @@ -88,4 +88,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/mempool-edit.inc.php b/includes/html/table/mempool-edit.inc.php index 69951d63b6..80254b8d05 100644 --- a/includes/html/table/mempool-edit.inc.php +++ b/includes/html/table/mempool-edit.inc.php @@ -49,4 +49,4 @@ foreach (dbFetchRows($sql, $param) as $drive) { } $output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/ports.inc.php b/includes/html/table/ports.inc.php index 74fa15565f..55e193e9e8 100644 --- a/includes/html/table/ports.inc.php +++ b/includes/html/table/ports.inc.php @@ -205,4 +205,4 @@ $output = [ 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/processor-edit.inc.php b/includes/html/table/processor-edit.inc.php index 0cc0822118..e5dab22536 100644 --- a/includes/html/table/processor-edit.inc.php +++ b/includes/html/table/processor-edit.inc.php @@ -49,4 +49,4 @@ foreach (dbFetchRows($sql, $param) as $drive) { } $output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/processor.inc.php b/includes/html/table/processor.inc.php index ae489c441c..637ab4a04c 100644 --- a/includes/html/table/processor.inc.php +++ b/includes/html/table/processor.inc.php @@ -100,4 +100,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/routing-edit.inc.php b/includes/html/table/routing-edit.inc.php index 69e7527553..ee22e0cd86 100644 --- a/includes/html/table/routing-edit.inc.php +++ b/includes/html/table/routing-edit.inc.php @@ -58,4 +58,4 @@ foreach (dbFetchRows($sql, $param) as $routing) { } $output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/sensors-common.php b/includes/html/table/sensors-common.php index d7b49dca20..9c80482478 100644 --- a/includes/html/table/sensors-common.php +++ b/includes/html/table/sensors-common.php @@ -163,4 +163,4 @@ $output = [ 'rows' => $response, 'total' => $count, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/storage-edit.inc.php b/includes/html/table/storage-edit.inc.php index d15e5ca84c..0f73dcc8d1 100644 --- a/includes/html/table/storage-edit.inc.php +++ b/includes/html/table/storage-edit.inc.php @@ -53,4 +53,4 @@ foreach (dbFetchRows($sql, $param) as $drive) { } $output = ['current'=>$current, 'rowCount'=>$rowCount, 'rows'=>$response, 'total'=>$total]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/storage.inc.php b/includes/html/table/storage.inc.php index e29d4fbec9..ae0d55cd1a 100644 --- a/includes/html/table/storage.inc.php +++ b/includes/html/table/storage.inc.php @@ -113,4 +113,4 @@ $output = [ 'rows' => $response, 'total' => $count, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/stp-ports.inc.php b/includes/html/table/stp-ports.inc.php index 793f9797da..9d86730c56 100644 --- a/includes/html/table/stp-ports.inc.php +++ b/includes/html/table/stp-ports.inc.php @@ -54,4 +54,4 @@ $output = [ 'rows' => $response, 'total' => $total, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/html/table/tnmsneinfo.inc.php b/includes/html/table/tnmsneinfo.inc.php index 6e54cb4ef2..478af3ba18 100644 --- a/includes/html/table/tnmsneinfo.inc.php +++ b/includes/html/table/tnmsneinfo.inc.php @@ -106,5 +106,5 @@ if (isset($vars['device_id'])) { 'rows' => $response, 'total' => $total, ]; - echo _json_encode($output); + echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); } diff --git a/includes/html/table/toner.inc.php b/includes/html/table/toner.inc.php index 03287dbb5e..b78e22354c 100644 --- a/includes/html/table/toner.inc.php +++ b/includes/html/table/toner.inc.php @@ -108,4 +108,4 @@ $output = [ 'rows' => $response, 'total' => $count, ]; -echo _json_encode($output); +echo json_encode($output, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE); diff --git a/includes/services.inc.php b/includes/services.inc.php index 6bcdadefea..47aa4aee7a 100644 --- a/includes/services.inc.php +++ b/includes/services.inc.php @@ -150,7 +150,7 @@ function poll_service($service) foreach ($perf as $k => $v) { $DS[$k] = $v['uom']; } - d_echo('Service DS: ' . _json_encode($DS) . "\n"); + d_echo('Service DS: ' . json_encode($DS, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE) . "\n"); if (($service['service_ds'] == '{}') || ($service['service_ds'] == '')) { $update['service_ds'] = json_encode($DS); }