bdr.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /*
  3. FusionPBX
  4. Version: MPL 1.1
  5. The contents of this file are subject to the Mozilla Public License Version
  6. 1.1 (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  11. for the specific language governing rights and limitations under the
  12. License.
  13. The Original Code is FusionPBX
  14. The Initial Developer of the Original Code is
  15. Mark J Crane <[email protected]>
  16. Portions created by the Initial Developer are Copyright (C) 2008-2023
  17. the Initial Developer. All Rights Reserved.
  18. Contributor(s):
  19. Mark J Crane <[email protected]>
  20. */
  21. //includes files
  22. require_once dirname(__DIR__, 2) . "/resources/require.php";
  23. //check permissions
  24. require_once "resources/check_auth.php";
  25. if (permission_exists('bdr_view')) {
  26. //access granted
  27. }
  28. else {
  29. echo "access denied";
  30. exit;
  31. }
  32. //add multi-lingual support
  33. $language = new text;
  34. $text = $language->get();
  35. //additional includes
  36. require_once "resources/header.php";
  37. require_once "resources/paging.php";
  38. //show the header
  39. echo "<h2>FusionPBX BDR</h2>";
  40. //get the my node id
  41. $sql = "select bdr.bdr_get_local_nodeid()";
  42. $prep_statement = $db->prepare(check_sql($sql));
  43. $prep_statement->execute();
  44. $result = $prep_statement->fetchAll();
  45. $result_count = count($result);
  46. unset ($prep_statement, $sql);
  47. $replace[] = '(';
  48. $replace[] = ')';
  49. $my_node_id = explode(',',str_replace($replace,'',$result[0]['bdr_get_local_nodeid']));
  50. //get the node list
  51. $sql = "select * from bdr.bdr_nodes";
  52. $prep_statement = $db->prepare(check_sql($sql));
  53. $prep_statement->execute();
  54. $result = $prep_statement->fetchAll();
  55. $result_count = count($result);
  56. unset ($prep_statement, $sql);
  57. $sql = "SELECT bdr.bdr_version()";
  58. $prep_statement = $db->prepare(check_sql($sql));
  59. $prep_statement->execute();
  60. $resultversion = $prep_statement->fetchAll();
  61. unset ($prep_statement, $sql);
  62. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  63. echo "<tr>\n";
  64. echo "<th class='th' colspan='2' align='left'>BDR Information</th>\n";
  65. echo "</tr>\n";
  66. echo "<tr>\n";
  67. echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
  68. echo "BDR Version\n";
  69. echo "</td>\n";
  70. echo "<td class='row_style1'>\n";
  71. echo $resultversion[0]['bdr_version'] . "\n";
  72. echo "</td>\n";
  73. echo "</tr>\n";
  74. echo "<tr>\n";
  75. echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
  76. echo "Node Count\n";
  77. echo "</td>\n";
  78. echo "<td class='row_style1'>\n";
  79. echo " $result_count\n";
  80. echo "</td>\n";
  81. echo "</tr>\n";
  82. echo "</table>\n<br/><br/>";
  83. //table headers
  84. $c = 0;
  85. $row_style["0"] = "row_style0";
  86. $row_style["1"] = "row_style1";
  87. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  88. //echo "<tr>\n";
  89. //echo "<td class=\"th\" colspan=\"8\" align=\"left\">Nodes</td>\n";
  90. //echo "</tr>\n";
  91. echo "<tr>\n";
  92. echo "<th class=\"th\" align=\"left\">ID</th>\n";
  93. echo "<th class=\"th\" align=\"left\">Status</th>\n";
  94. echo "<th class=\"th\" align=\"left\">Name</th>\n";
  95. echo "<th class=\"th\" align=\"left\">Local</th>\n";
  96. echo "<th class=\"th\" align=\"left\">Database</th>\n";
  97. echo "<th class=\"th\" align=\"left\">Active</th>\n";
  98. echo "<th class=\"th\" align=\"left\">Retained Bytes</th>\n";
  99. echo "<th class=\"th\" align=\"left\">Lag Bytes</th>\n";
  100. echo "<th>&nbsp;</th>\n";
  101. echo "</tr>\n";
  102. $c = 0;
  103. $row_style["0"] = "row_style0";
  104. $row_style["1"] = "row_style1";
  105. foreach ($result as $row) {
  106. //get the status, bytes, database list
  107. $sql = "SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes";
  108. $sql .= " FROM pg_replication_slots WHERE plugin = 'bdr'";
  109. $sql .= " AND slot_name like '%" . $row['node_sysid'] . "%' ";
  110. $sql .= " AND database = 'fusionpbx' ";
  111. $prep_statement = $db->prepare(check_sql($sql));
  112. $prep_statement->execute();
  113. $result1 = $prep_statement->fetchAll();
  114. unset ($prep_statement, $sql);
  115. //get lag bytes
  116. $sql = "select pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_bytes";
  117. $sql .= " FROM pg_stat_replication WHERE ";
  118. $sql .= " application_name like '%" . $row['node_sysid'] . "%". $row['node_dboid'] ."%' ";
  119. $prep_statement = $db->prepare(check_sql($sql));
  120. $prep_statement->execute();
  121. $result2 = $prep_statement->fetchAll();
  122. unset ($prep_statement, $sql);
  123. echo "<tr>\n";
  124. echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_sysid'] . "_" . $row['node_dboid'] . "</td>\n";
  125. echo " <td valign='top' class='".$row_style[$c]."'>";
  126. if ($row['node_status'] == "r") {
  127. echo "Ready";
  128. } else if ($row['node_status'] == "k") {
  129. echo "Removed/Killed";
  130. } else if ($row['node_status'] == "i") {
  131. echo "Initializing";
  132. } else if ($row['node_status'] == "b") {
  133. echo "Bootstrapping";
  134. } else if ($row['node_status'] == "c") {
  135. echo "Catching Up";
  136. } else if ($row['node_status'] == "o") {
  137. echo "Caught Up/Waiting";
  138. } else {
  139. echo "Unknown";
  140. }
  141. echo "</td>\n";
  142. echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_name'] . "</td>\n";
  143. echo " <td valign='top' class='".$row_style[$c]."'>";
  144. if ($row['node_sysid'] == $my_node_id[0]) { echo "Yes"; $is_current = 1; } else { echo "No"; $is_current = 0; }
  145. echo "</td>\n";
  146. echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['database'] . "</td>\n";
  147. echo " <td valign='top' class='".$row_style[$c]."'>";
  148. if ($is_current != 1) {if ($result1[0]['active'] == 1) { echo "Yes"; } else { echo "No"; }};
  149. echo "</td>\n";
  150. echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['retained_bytes'] . "</td>\n";
  151. echo " <td valign='top' class='".$row_style[$c]."'>" . $result2[0]['lag_bytes'] . "</td>\n";
  152. echo " <td class='list_control_icons'>";
  153. //if (permission_exists('extension_edit')) {
  154. // echo "<a href='extension_edit.php?id=".$row['extension_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
  155. //}
  156. if (permission_exists('bdr_delete')) {
  157. 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>";
  158. }
  159. echo "</td>\n";
  160. echo "</tr>\n";
  161. if ($c==0) { $c=1; } else { $c=0; }
  162. }
  163. echo " </table>\n";
  164. //show the header
  165. echo "<h2>Freeswitch BDR</h2>";
  166. //connect to the switch database
  167. $db_fs = new PDO("pgsql:host=$db_host port=$db_port dbname=freeswitch user=$db_username password=$db_password");
  168. //get the my node id
  169. $sql = "select bdr.bdr_get_local_nodeid()";
  170. $prep_statement = $db_fs->prepare(check_sql($sql));
  171. $prep_statement->execute();
  172. $result = $prep_statement->fetchAll();
  173. $result_count = count($result);
  174. unset ($prep_statement, $sql);
  175. $replace[] = '(';
  176. $replace[] = ')';
  177. $my_node_id = explode(',',str_replace($replace,'',$result[0]['bdr_get_local_nodeid']));
  178. //get the node list
  179. $sql = "select * from bdr.bdr_nodes";
  180. $prep_statement = $db_fs->prepare(check_sql($sql));
  181. $prep_statement->execute();
  182. $result = $prep_statement->fetchAll();
  183. $result_count = count($result);
  184. unset ($prep_statement, $sql);
  185. $sql = "SELECT bdr.bdr_version()";
  186. $prep_statement = $db_fs->prepare(check_sql($sql));
  187. $prep_statement->execute();
  188. $resultversion = $prep_statement->fetchAll();
  189. unset ($prep_statement, $sql);
  190. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  191. echo "<tr>\n";
  192. echo "<th class='th' colspan='2' align='left'>BDR Information</th>\n";
  193. echo "</tr>\n";
  194. echo "<tr>\n";
  195. echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
  196. echo "BDR Version\n";
  197. echo "</td>\n";
  198. echo "<td class='row_style1'>\n";
  199. echo $resultversion[0]['bdr_version'] . "\n";
  200. echo "</td>\n";
  201. echo "</tr>\n";
  202. echo "<tr>\n";
  203. echo "<td width='20%' class='vncell' style='text-align: left;'>\n";
  204. echo "Node Count\n";
  205. echo "</td>\n";
  206. echo "<td class='row_style1'>\n";
  207. echo " $result_count\n";
  208. echo "</td>\n";
  209. echo "</tr>\n";
  210. echo "</table>\n<br/><br/>";
  211. //table headers
  212. $c = 0;
  213. $row_style["0"] = "row_style0";
  214. $row_style["1"] = "row_style1";
  215. echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
  216. echo "<tr>\n";
  217. echo "<th class=\"th\" align=\"left\">ID</th>\n";
  218. echo "<th class=\"th\" align=\"left\">Status</th>\n";
  219. echo "<th class=\"th\" align=\"left\">Name</th>\n";
  220. echo "<th class=\"th\" align=\"left\">Local</th>\n";
  221. echo "<th class=\"th\" align=\"left\">Database</th>\n";
  222. echo "<th class=\"th\" align=\"left\">Active</th>\n";
  223. echo "<th class=\"th\" align=\"left\">Retained Bytes</th>\n";
  224. echo "<th class=\"th\" align=\"left\">Lag Bytes</th>\n";
  225. echo "<th>&nbsp;</th>\n";
  226. echo "</tr>\n";
  227. $c = 0;
  228. $row_style["0"] = "row_style0";
  229. $row_style["1"] = "row_style1";
  230. foreach ($result as $row) {
  231. //get the status, bytes, database list
  232. $sql = "SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes";
  233. $sql .= " FROM pg_replication_slots WHERE plugin = 'bdr'";
  234. $sql .= " AND slot_name like '%" . $row['node_sysid'] . "%' ";
  235. $sql .= " AND database ='freeswitch' ";
  236. $prep_statement = $db_fs->prepare(check_sql($sql));
  237. $prep_statement->execute();
  238. $result1 = $prep_statement->fetchAll();
  239. unset ($prep_statement, $sql);
  240. //get lag bytes
  241. $sql = "select pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_bytes";
  242. $sql .= " FROM pg_stat_replication WHERE ";
  243. $sql .= " application_name like '%" . $row['node_sysid'] . "%". $row['node_dboid'] ."%' ";
  244. $prep_statement = $db_fs->prepare(check_sql($sql));
  245. $prep_statement->execute();
  246. $result2 = $prep_statement->fetchAll();
  247. unset ($prep_statement, $sql);
  248. echo "<tr>\n";
  249. echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_sysid'] . "_" . $row['node_dboid'] . "</td>\n";
  250. echo " <td valign='top' class='".$row_style[$c]."'>";
  251. if ($row['node_status'] == "r") {
  252. echo "Ready";
  253. } else if ($row['node_status'] == "k") {
  254. echo "Removed/Killed";
  255. } else if ($row['node_status'] == "i") {
  256. echo "Initializing";
  257. } else if ($row['node_status'] == "b") {
  258. echo "Bootstrapping";
  259. } else if ($row['node_status'] == "c") {
  260. echo "Catching Up";
  261. } else if ($row['node_status'] == "o") {
  262. echo "Caught Up/Waiting";
  263. } else {
  264. echo "Unknown";
  265. }
  266. echo "</td>\n";
  267. echo " <td valign='top' class='".$row_style[$c]."'>" . $row['node_name'] . "</td>\n";
  268. echo " <td valign='top' class='".$row_style[$c]."'>";
  269. if ($row['node_sysid'] == $my_node_id[0]) { echo "Yes"; $is_current = 1; } else { echo "No"; $is_current = 0; }
  270. echo "</td>\n";
  271. echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['database'] . "</td>\n";
  272. echo " <td valign='top' class='".$row_style[$c]."'>";
  273. if ($is_current != 1) {if ($result1[0]['active'] == 1) { echo "Yes"; } else { echo "No"; }};
  274. echo "</td>\n";
  275. echo " <td valign='top' class='".$row_style[$c]."'>" . $result1[0]['retained_bytes'] . "</td>\n";
  276. echo " <td valign='top' class='".$row_style[$c]."'>" . $result2[0]['lag_bytes'] . "</td>\n";
  277. echo " <td class='list_control_icons'>";
  278. //if (permission_exists('extension_edit')) {
  279. // echo "<a href='extension_edit.php?id=".$row['extension_uuid']."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
  280. //}
  281. if (permission_exists('bdr_delete')) {
  282. 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>";
  283. }
  284. echo "</td>\n";
  285. echo "</tr>\n";
  286. if ($c==0) { $c=1; } else { $c=0; }
  287. }
  288. echo " </table>\n";
  289. //include the footer
  290. require_once "resources/footer.php";
  291. ?>