uptime.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2017 The OGP Development Team
  6. *
  7. * http://www.opengamepanel.org/
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation; either version 2
  12. * of the License, or any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. *
  23. */
  24. include_once("modules/status/config.php");
  25. if ($os == "windows")
  26. {
  27. $upsince = filemtime($pagefilelocation);
  28. $uptime = (time() - $upsince);
  29. }
  30. elseif ($os == "linux" or $os == "cygwin")
  31. {
  32. if( isset($_GET['remote_server_id']) )
  33. {
  34. require_once('includes/lib_remote.php');
  35. $rhost_id = $_GET['remote_server_id'];
  36. $remote_server = $db->getRemoteServer($rhost_id);
  37. $remote = new OGPRemoteLibrary($remote_server['agent_ip'], $remote_server['agent_port'], $remote_server['encryption_key'], $remote_server['timeout']);
  38. list($uptime,$upsince) = $remote->shell_action('get_uptime', 'seconds');
  39. }
  40. else
  41. {
  42. $uptime = round(current(explode(" ", exec("cat /proc/uptime"))));
  43. $upsince = (time() - $uptime);
  44. }
  45. }
  46. $days = floor($uptime / (24 * 3600));
  47. $uptime = $uptime - ($days * (24 * 3600));
  48. $hours = floor($uptime / (3600));
  49. $uptime = $uptime - ($hours * (3600));
  50. $minutes = floor($uptime / (60));
  51. $uptime = $uptime - ($minutes * 60);
  52. $seconds = $uptime;
  53. $days = $days != 1 ? $days . ' Days' : $days . ' Day';
  54. $hours = $hours != 1 ? $hours . ' Hours' : $hours . ' Hour';
  55. $minutes = $minutes != 1 ? $minutes . ' Minutes' : $minutes . ' Minute';
  56. $seconds = $seconds != 1 ? $seconds . ' Seconds' : $seconds . ' Second';
  57. if ($days == 0) {
  58. $days = "";
  59. }
  60. if ($hours == 0) {
  61. $hours = "";
  62. }
  63. if ($minutes == 0) {
  64. $minutes = "";
  65. }
  66. if ($seconds == 0) {
  67. $seconds = "";
  68. }
  69. $indexuptime = $days . ' ' . $hours . ' ' . $minutes . ' ' . $seconds;
  70. $indexuptimesince = date('F jS, Y. h:i A', $upsince);
  71. ?>