json.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. //
  3. // vnStat PHP frontend (c)2006-2010 Bjorge Dijkstra (bjd@jooz.net)
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 2 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU General Public License
  16. // along with this program; if not, write to the Free Software
  17. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. //
  19. //
  20. // see file COPYING or at http://www.gnu.org/licenses/gpl.html
  21. // for more information.
  22. //
  23. require 'config.php';
  24. require 'localize.php';
  25. require 'vnstat.php';
  26. validate_input();
  27. require "./themes/$style/theme.php";
  28. function write_summary()
  29. {
  30. global $summary,$top,$day,$hour,$month;
  31. $trx = $summary['totalrx']*1024+$summary['totalrxk'];
  32. $ttx = $summary['totaltx']*1024+$summary['totaltxk'];
  33. //
  34. // build array for write_data_table
  35. //
  36. $sum['hour']['act'] = 1;
  37. $sum['hour']['rx'] = $hour[0]['rx'];
  38. $sum['hour']['tx'] = $hour[0]['tx'];
  39. $sum['day']['act'] = 1;
  40. $sum['day']['rx'] = $day[0]['rx'];
  41. $sum['day']['tx'] = $day[0]['tx'];
  42. $sum['month']['act'] = 1;
  43. $sum['month']['rx'] = $month[0]['rx'];
  44. $sum['month']['tx'] = $month[0]['tx'];
  45. $sum['total']['act'] = 1;
  46. $sum['total']['rx'] = $trx;
  47. $sum['total']['tx'] = $ttx;
  48. print json_encode($sum);
  49. }
  50. get_vnstat_data(false);
  51. header('Content-type: application/json; charset=utf-8');
  52. $graph_params = "if=$iface&amp;page=$page&amp;style=$style";
  53. if ($page == 's')
  54. {
  55. write_summary();
  56. }
  57. else if ($page == 'h')
  58. {
  59. print json_encode(array('hours' => $hour));
  60. }
  61. else if ($page == 'd')
  62. {
  63. print json_encode(array('days' => $day));
  64. }
  65. else if ($page == 'm')
  66. {
  67. print json_encode(array('months' => $month));
  68. }
  69. ?>