PageRenderTime 69ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/html/pages/front/default.php

https://bitbucket.org/MelFlynn/observium
PHP | 150 lines | 121 code | 25 blank | 4 comment | 36 complexity | 81862402fbc26bf6fa3f26e84b20beaa MD5 | raw file
Possible License(s): GPL-3.0, MIT
  1. <?php
  2. function generate_front_box ($background, $content)
  3. {
  4. echo("<div style='text-align: center; margin: 2px; border: solid 2px #D0D0D0; float: left; margin-right: 2px; padding: 3px; width: 117px; height: 85px; background: $background;'>
  5. $content
  6. </div>");
  7. }
  8. echo("<div style='padding: 3px 10px; background: #fff;'>");
  9. if ($_SESSION['userlevel'] == '10')
  10. {
  11. $sql = mysql_query("SELECT * FROM `devices` WHERE `status` = '0' AND `ignore` = '0'");
  12. } else {
  13. $sql = mysql_query("SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '0' AND D.ignore = '0'");
  14. }
  15. while ($device = mysql_fetch_assoc($sql)) {
  16. generate_front_box("#ffaaaa", "<center><strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
  17. <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Device Down</span> <br />
  18. <span class=body-date-1>".truncate($device['location'], 20)."</span>
  19. </center>");
  20. }
  21. if ($_SESSION['userlevel'] == '10')
  22. {
  23. $sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D WHERE I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
  24. } else {
  25. $sql = mysql_query("SELECT * FROM `ports` AS I, `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND I.device_id = D.device_id AND ifOperStatus = 'down' AND ifAdminStatus = 'up' AND D.ignore = '0' AND I.ignore = '0'");
  26. }
  27. ### These things need to become more generic, and more manageable across different frontpages... rewrite inc :>
  28. if ($config['warn']['ifdown'])
  29. {
  30. while ($interface = mysql_fetch_assoc($sql))
  31. {
  32. if (!$interface['deleted'])
  33. {
  34. $interface = ifNameDescr($interface);
  35. generate_front_box("#ffdd99", "<center><strong>".generate_device_link($interface, shorthost($interface['hostname']))."</strong><br />
  36. <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Port Down</span><br />
  37. <!-- <img src='graph.php?type=bits&amp;if=".$interface['interface_id']."&amp;from=$day&amp;to=$now&amp;width=100&amp;height=32' /> -->
  38. <strong>".generate_port_link($interface, truncate(makeshortif($interface['label']),13,''))."</strong> <br />
  39. " . ($interface['ifAlias'] ? '<span class="body-date-1">'.truncate($interface['ifAlias'], 20, '').'</span>' : '') . "
  40. </center>");
  41. }
  42. }
  43. }
  44. /* FIXME service permissions? seem nonexisting now.. */
  45. $sql = mysql_query("SELECT * FROM `services` AS S, `devices` AS D WHERE S.device_id = D.device_id AND service_status = 'down' AND D.ignore = '0' AND S.service_ignore = '0'");
  46. while ($service = mysql_fetch_assoc($sql))
  47. {
  48. generate_front_box("#ffaaaa", "<center><strong>".generate_device_link($service, shorthost($service['hostname']))."</strong><br />
  49. <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>Service Down</span>
  50. <strong>".$service['service_type']."</strong><br />
  51. <span class=body-date-1>".truncate($interface['ifAlias'], 20)."</span>
  52. </center>");
  53. }
  54. if (isset($config['enable_bgp']) && $config['enable_bgp'])
  55. {
  56. if ($_SESSION['userlevel'] == '10')
  57. {
  58. $sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B WHERE bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
  59. } else {
  60. $sql = mysql_query("SELECT * FROM `devices` AS D, bgpPeers AS B, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND bgpPeerAdminStatus != 'start' AND bgpPeerState != 'established' AND bgpPeerState != '' AND B.device_id = D.device_id AND D.ignore = 0");
  61. }
  62. while ($peer = mysql_fetch_assoc($sql))
  63. {
  64. generate_front_box("#ffaaaa", "<center><strong>".generate_device_link($peer, shorthost($peer['hostname']))."</strong><br />
  65. <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #c00;'>BGP Down</span>
  66. <span style='" . (strstr($peer['bgpPeerIdentifier'],':') ? 'font-size: 10px' : '') . "'><strong>".$peer['bgpPeerIdentifier']."</strong></span><br />
  67. <span class=body-date-1>AS".truncate($peer['bgpPeerRemoteAs']." ".$peer['astext'], 14, "")."</span>
  68. </center>");
  69. }
  70. }
  71. if (filter_var($config['uptime_warning'], FILTER_VALIDATE_FLOAT) !== FALSE && $config['uptime_warning'] > 0)
  72. {
  73. if ($_SESSION['userlevel'] == '10')
  74. {
  75. $sql = mysql_query("SELECT * FROM `devices` AS D WHERE D.status = '1' AND D.uptime > 0 AND D.uptime < '" . $config['uptime_warning'] . "' AND D.ignore = 0");
  76. } else {
  77. $sql = mysql_query("SELECT * FROM `devices` AS D, devices_perms AS P WHERE D.device_id = P.device_id AND P.user_id = '" . $_SESSION['user_id'] . "' AND D.status = '1' AND D.uptime > 0 AND D.uptime < '" .
  78. $config['uptime_warning'] . "' AND D.ignore = 0");
  79. }
  80. while ($device = mysql_fetch_assoc($sql))
  81. {
  82. generate_front_box("#aaffaa", "<center><strong>".generate_device_link($device, shorthost($device['hostname']))."</strong><br />
  83. <span style='font-size: 14px; font-weight: bold; margin: 5px; color: #009;'>Device<br />Rebooted</span><br />
  84. <span class=body-date-1>".formatUptime($device['uptime'], 'short')."</span>
  85. </center>");
  86. }
  87. }
  88. if ($config['enable_syslog'])
  89. {
  90. ## Open Syslog Div
  91. echo("<div style='margin: 4px; clear: both; padding: 5px;'>
  92. <h3>Recent Syslog Messages</h3>
  93. ");
  94. $sql = "SELECT *, DATE_FORMAT(timestamp, '%D %b %T') AS date from syslog ORDER BY timestamp DESC LIMIT 20";
  95. $query = mysql_query($sql);
  96. echo("<table cellspacing=0 cellpadding=2 width=100%>");
  97. while ($entry = mysql_fetch_assoc($query))
  98. {
  99. $entry = array_merge($entry, device_by_id_cache($entry['device_id']));
  100. include("includes/print-syslog.inc.php");
  101. }
  102. echo("</table>");
  103. echo("</div>"); ## Close Syslog Div
  104. } else {
  105. ## Open eventlog Div
  106. echo("<div style='margin: 4px; clear: both; padding: 5px;'>
  107. <h3>Recent Eventlog Entries</h3>
  108. ");
  109. if ($_SESSION['userlevel'] == '10')
  110. {
  111. $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15";
  112. } else {
  113. $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host =
  114. P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15";
  115. }
  116. $data = mysql_query($query);
  117. echo('<table cellspacing="0" cellpadding="1" width="100%">');
  118. while ($entry = mysql_fetch_assoc($data)) {
  119. include("includes/print-event.inc.php");
  120. }
  121. echo("</table>");
  122. echo("</div>"); ## Close Syslog Div
  123. }
  124. echo("</div>");
  125. ?>