123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <?php
- /*
- FusionPBX
- Version: MPL 1.1
- The contents of this file are subject to the Mozilla Public License Version
- 1.1 (the "License"); you may not use this file except in compliance with
- the License. You may obtain a copy of the License at
- http://www.mozilla.org/MPL/
- Software distributed under the License is distributed on an "AS IS" basis,
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- for the specific language governing rights and limitations under the
- License.
- The Original Code is FusionPBX
- The Initial Developer of the Original Code is
- Mark J Crane <[email protected]>
- Portions created by the Initial Developer are Copyright (C) 2008-2023
- the Initial Developer. All Rights Reserved.
- Contributor(s):
- Mark J Crane <[email protected]>
- */
- //includes files
- require_once dirname(__DIR__, 2) . "/resources/require.php";
- //check permissions
- require_once "resources/check_auth.php";
- if (permission_exists('bdr_view')) {
- //access granted
- }
- else {
- echo "access denied";
- exit;
- }
- //add multi-lingual support
- $language = new text;
- $text = $language->get();
- //additional includes
- require_once "resources/header.php";
- require_once "resources/paging.php";
- //show the header
- echo "<h2>FusionPBX BDR</h2>";
- //get the my node id
- $sql = "select bdr.bdr_get_local_nodeid()";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll();
- $result_count = count($result);
- unset ($prep_statement, $sql);
- $replace[] = '(';
- $replace[] = ')';
- $my_node_id = explode(',',str_replace($replace,'',$result[0]['bdr_get_local_nodeid']));
- //get the node list
- $sql = "select * from bdr.bdr_nodes";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll();
- $result_count = count($result);
- unset ($prep_statement, $sql);
- $sql = "SELECT bdr.bdr_version()";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $resultversion = $prep_statement->fetchAll();
- unset ($prep_statement, $sql);
- echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
- echo "<tr>\n";
- echo "<th class='th' colspan='2' align='left'>BDR Information</th>\n";
- echo "</tr>\n";
- echo "<tr>\n";
- echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
- echo "BDR Version\n";
- echo "</td>\n";
- echo "<td class='row_style1'>\n";
- echo $resultversion[0]['bdr_version'] . "\n";
- echo "</td>\n";
- echo "</tr>\n";
- echo "<tr>\n";
- echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
- echo "Node Count\n";
- echo "</td>\n";
- echo "<td class='row_style1'>\n";
- echo " $result_count\n";
- echo "</td>\n";
- echo "</tr>\n";
- echo "</table>\n<br/><br/>";
- //table headers
- $c = 0;
- $row_style["0"] = "row_style0";
- $row_style["1"] = "row_style1";
- echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
- //echo "<tr>\n";
- //echo "<td class=\"th\" colspan=\"8\" align=\"left\">Nodes</td>\n";
- //echo "</tr>\n";
- echo "<tr>\n";
- echo "<th class=\"th\" align=\"left\">ID</th>\n";
- echo "<th class=\"th\" align=\"left\">Status</th>\n";
- echo "<th class=\"th\" align=\"left\">Name</th>\n";
- echo "<th class=\"th\" align=\"left\">Local</th>\n";
- echo "<th class=\"th\" align=\"left\">Database</th>\n";
- echo "<th class=\"th\" align=\"left\">Active</th>\n";
- echo "<th class=\"th\" align=\"left\">Retained Bytes</th>\n";
- echo "<th class=\"th\" align=\"left\">Lag Bytes</th>\n";
- echo "<th> </th>\n";
- echo "</tr>\n";
- $c = 0;
- $row_style["0"] = "row_style0";
- $row_style["1"] = "row_style1";
- foreach ($result as $row) {
-
- //get the status, bytes, database list
- $sql = "SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes";
- $sql .= " FROM pg_replication_slots WHERE plugin = 'bdr'";
- $sql .= " AND slot_name like '%" . $row['node_sysid'] . "%' ";
- $sql .= " AND database = 'fusionpbx' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result1 = $prep_statement->fetchAll();
- unset ($prep_statement, $sql);
-
- //get lag bytes
- $sql = "select pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_bytes";
- $sql .= " FROM pg_stat_replication WHERE ";
- $sql .= " application_name like '%" . $row['node_sysid'] . "%". $row['node_dboid'] ."%' ";
- $prep_statement = $db->prepare(check_sql($sql));
- $prep_statement->execute();
- $result2 = $prep_statement->fetchAll();
- unset ($prep_statement, $sql);
-
- echo "<tr>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_sysid'] . "_" . $row['node_dboid'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>";
- if ($row['node_status'] == "r") {
- echo "Ready";
- } else if ($row['node_status'] == "k") {
- echo "Removed/Killed";
- } else if ($row['node_status'] == "i") {
- echo "Initializing";
- } else if ($row['node_status'] == "b") {
- echo "Bootstrapping";
- } else if ($row['node_status'] == "c") {
- echo "Catching Up";
- } else if ($row['node_status'] == "o") {
- echo "Caught Up/Waiting";
- } else {
- echo "Unknown";
- }
- echo "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_name'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>";
- if ($row['node_sysid'] == $my_node_id[0]) { echo "Yes"; $is_current = 1; } else { echo "No"; $is_current = 0; }
- echo "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['database'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>";
- if ($is_current != 1) {if ($result1[0]['active'] == 1) { echo "Yes"; } else { echo "No"; }};
- echo "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['retained_bytes'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $result2[0]['lag_bytes'] . "</td>\n";
- echo " <td class='list_control_icons'>";
- //if (permission_exists('extension_edit')) {
- // echo "<a href='extension_edit.php?id=".$row['extension_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
- //}
- if (permission_exists('bdr_delete')) {
- echo "<a href='bdr_delete.php?action=delete&id=".$row['node_name']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
- }
- echo "</td>\n";
- echo "</tr>\n";
- if ($c==0) { $c=1; } else { $c=0; }
- }
- echo " </table>\n";
- //show the header
- echo "<h2>Freeswitch BDR</h2>";
- //connect to the switch database
- $db_fs = new PDO("pgsql:host=$db_host port=$db_port dbname=freeswitch user=$db_username password=$db_password");
- //get the my node id
- $sql = "select bdr.bdr_get_local_nodeid()";
- $prep_statement = $db_fs->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll();
- $result_count = count($result);
- unset ($prep_statement, $sql);
- $replace[] = '(';
- $replace[] = ')';
- $my_node_id = explode(',',str_replace($replace,'',$result[0]['bdr_get_local_nodeid']));
- //get the node list
- $sql = "select * from bdr.bdr_nodes";
- $prep_statement = $db_fs->prepare(check_sql($sql));
- $prep_statement->execute();
- $result = $prep_statement->fetchAll();
- $result_count = count($result);
- unset ($prep_statement, $sql);
- $sql = "SELECT bdr.bdr_version()";
- $prep_statement = $db_fs->prepare(check_sql($sql));
- $prep_statement->execute();
- $resultversion = $prep_statement->fetchAll();
- unset ($prep_statement, $sql);
- echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
- echo "<tr>\n";
- echo "<th class='th' colspan='2' align='left'>BDR Information</th>\n";
- echo "</tr>\n";
- echo "<tr>\n";
- echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
- echo "BDR Version\n";
- echo "</td>\n";
- echo "<td class='row_style1'>\n";
- echo $resultversion[0]['bdr_version'] . "\n";
- echo "</td>\n";
- echo "</tr>\n";
- echo "<tr>\n";
- echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
- echo "Node Count\n";
- echo "</td>\n";
- echo "<td class='row_style1'>\n";
- echo " $result_count\n";
- echo "</td>\n";
- echo "</tr>\n";
- echo "</table>\n<br/><br/>";
- //table headers
- $c = 0;
- $row_style["0"] = "row_style0";
- $row_style["1"] = "row_style1";
- echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
- echo "<tr>\n";
- echo "<th class=\"th\" align=\"left\">ID</th>\n";
- echo "<th class=\"th\" align=\"left\">Status</th>\n";
- echo "<th class=\"th\" align=\"left\">Name</th>\n";
- echo "<th class=\"th\" align=\"left\">Local</th>\n";
- echo "<th class=\"th\" align=\"left\">Database</th>\n";
- echo "<th class=\"th\" align=\"left\">Active</th>\n";
- echo "<th class=\"th\" align=\"left\">Retained Bytes</th>\n";
- echo "<th class=\"th\" align=\"left\">Lag Bytes</th>\n";
- echo "<th> </th>\n";
- echo "</tr>\n";
- $c = 0;
- $row_style["0"] = "row_style0";
- $row_style["1"] = "row_style1";
- foreach ($result as $row) {
-
- //get the status, bytes, database list
- $sql = "SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes";
- $sql .= " FROM pg_replication_slots WHERE plugin = 'bdr'";
- $sql .= " AND slot_name like '%" . $row['node_sysid'] . "%' ";
- $sql .= " AND database ='freeswitch' ";
- $prep_statement = $db_fs->prepare(check_sql($sql));
- $prep_statement->execute();
- $result1 = $prep_statement->fetchAll();
- unset ($prep_statement, $sql);
-
- //get lag bytes
- $sql = "select pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_bytes";
- $sql .= " FROM pg_stat_replication WHERE ";
- $sql .= " application_name like '%" . $row['node_sysid'] . "%". $row['node_dboid'] ."%' ";
- $prep_statement = $db_fs->prepare(check_sql($sql));
- $prep_statement->execute();
- $result2 = $prep_statement->fetchAll();
- unset ($prep_statement, $sql);
-
- echo "<tr>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_sysid'] . "_" . $row['node_dboid'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>";
- if ($row['node_status'] == "r") {
- echo "Ready";
- } else if ($row['node_status'] == "k") {
- echo "Removed/Killed";
- } else if ($row['node_status'] == "i") {
- echo "Initializing";
- } else if ($row['node_status'] == "b") {
- echo "Bootstrapping";
- } else if ($row['node_status'] == "c") {
- echo "Catching Up";
- } else if ($row['node_status'] == "o") {
- echo "Caught Up/Waiting";
- } else {
- echo "Unknown";
- }
- echo "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_name'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>";
- if ($row['node_sysid'] == $my_node_id[0]) { echo "Yes"; $is_current = 1; } else { echo "No"; $is_current = 0; }
- echo "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['database'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>";
- if ($is_current != 1) {if ($result1[0]['active'] == 1) { echo "Yes"; } else { echo "No"; }};
- echo "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['retained_bytes'] . "</td>\n";
- echo " <td valign='top' class='".$row_style[$c]."'>" . $result2[0]['lag_bytes'] . "</td>\n";
- echo " <td class='list_control_icons'>";
- //if (permission_exists('extension_edit')) {
- // echo "<a href='extension_edit.php?id=".$row['extension_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
- //}
- if (permission_exists('bdr_delete')) {
- echo "<a href='bdr_delete.php?action=delete&id=".$row['node_name']."' alt='".$text['button-delete']."' onclick=\"return confirm('".$text['confirm-delete']."')\">$v_link_label_delete</a>";
- }
- echo "</td>\n";
- echo "</tr>\n";
- if ($c==0) { $c=1; } else { $c=0; }
- }
- echo " </table>\n";
- //include the footer
- require_once "resources/footer.php";
- ?>
|