Advertisement
Guest User

ntop display board

a guest
Dec 3rd, 2012
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.83 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <?php
  3. //gets the current traffic speed in kb/s
  4. $api_address = "http://127.0.0.1:3000/dumpTrafficData.html?language=xml&view=long";
  5. $ch = curl_init();
  6.     curl_setopt($ch, CURLOPT_URL, $api_address);
  7.     curl_setopt($ch, CURLOPT_PORT, "3000");
  8.     curl_setopt($ch, CURLOPT_HEADER, 0);
  9.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  10.     $curl = curl_exec($ch);
  11.     curl_close($ch);
  12.  
  13. $a = json_decode(json_encode((array) simplexml_load_string($curl)),1);
  14. $bps = $a['ntop-traffic-information']['device-information']['actualThpt'];
  15. $kbs = round($bps / 1024, 2);
  16. $percent = round(($kbs / 256) * 100);
  17.  
  18. //build graphs
  19. $now = time();
  20. $before_10min = $now - 600;
  21. $before_60min = $now - 3600;
  22.  
  23. $img_10 = "http://127.0.0.1:3000/plugins/rrdPlugin?action=arbreq&which=graph&arbfile=throughput&arbiface=eth0&arbip=&start=" . $before_10min . "&end=" . $now . "&counter=&title=Last+10+Minutes";
  24. $img_60 = "http://127.0.0.1:3000/plugins/rrdPlugin?action=arbreq&which=graph&arbfile=throughput&arbiface=eth0&arbip=&start=" . $before_60min . "&end=" . $now . "&counter=&title=Last+60+Minutes";
  25.  
  26. //pings googles DNS server, checks to see if line quality is up
  27. $ping =  shell_exec('ping -c 1 -w 1 8.8.8.8');
  28. $pre = explode("=", $ping);
  29. $ping_final = explode(" ms", $pre[3]);
  30.  
  31. ?>
  32.  
  33. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  34. <head>
  35.         <META HTTP-EQUIV=REFRESH CONTENT=60>
  36.         <META HTTP-EQUIV=Pragma CONTENT=no-cache>
  37.         <META HTTP-EQUIV=Cache-Control CONTENT=no-cache>
  38.         <title>CompanyName - Network</title>
  39.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  40.         <link rel="stylesheet" type="text/css" href="asubtlebeige.css" />
  41. <style type="text/css">
  42. </style></head>
  43. <body>
  44. <div id="page">
  45.     <div id="header">
  46.         <div class="title">CompanyName - Network</div>
  47.         <div class="subText">Status - Updated Every Minute</div>
  48.     </div>
  49.     <div id="bar">
  50.     </div>
  51.     <div id="pageContent">
  52.                 <div class="articleTitle">
  53.                         <?php
  54.                         if ($kbs == 0)
  55.                                 {
  56.                                         echo 'Currently the CompanyName network is using less than 10Kb/s</b>.<br \> That is under 2% of available bandwidth.';
  57.                                 }
  58.                                 else
  59.                                 {
  60.                                         echo 'Currently the CompanyName network is using <b>' . $kbs . 'Kb/s</b>.<br \> That is roughly <b>' . $percent . '</b>% of available bandwidth.';
  61.                                 }
  62.                         if ($ping_final[0] == "")
  63.                                 {
  64.                                         echo "<br />NOTICE: Internet currently unreachable via CompanyName network.";
  65.                                 }
  66.  
  67.  
  68.                         if ($kbs > 200 || $ping_final[0] > 100)
  69.                                 {
  70.                                         echo '<br />High outgoing network load is detected, expect slower speeds to the internet.';
  71.                                 }
  72.                         ?>
  73.                 </div>
  74.         </div>
  75.  
  76.       <div class="articleContent">
  77.                 <?php echo '<img class="displayed" src="' . $img_10 . '">'; ?><br \>
  78.                 <?php echo '<img class="displayed" src="' . $img_60 . '">'; ?><br \>
  79.  
  80.         </div>
  81.  
  82.  
  83.     </div>
  84.  
  85. </div>
  86.     <div id="footer"><b>This page was last updated <?php echo shell_exec(date); ?></b><br />
  87. <?php
  88.  
  89. echo "<br />";
  90. echo shell_exec(uptime);
  91. echo "<br />Full network stats available at http://127.0.0.1:3000/thptStats.html<br />";
  92. echo "Avg outgoing latency - " . $ping_final[0] . "ms";
  93.  
  94. ?>
  95. </div>
  96. </body>
  97. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement