1
0

agents.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2012 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 'util_config.php';
  25. session_name($sessionName);
  26. session_start();
  27. if(!empty($_SESSION['user_id'])){
  28. // This entire section is nothing but a big, messy, workaround.
  29. // Make ogpLang happy.
  30. $_REQUEST['m'] = 'util';
  31. // We need to change directory to be able to include lib_remote and make a database connection without any errors
  32. // This is becasue the following files include other files via their relative path rather than absolute path... could be fixed by editing them... but until then, this is just a hacky workaround.
  33. $cwd = getcwd();
  34. if(chdir('../../') === true){
  35. require_once('includes/config.inc.php');
  36. require_once('includes/helpers.php');
  37. include_once("includes/lang.php");
  38. ogpLang();
  39. require_once('includes/lib_remote.php');
  40. $db = createDatabaseConnection($db_type, $db_host, $db_user, $db_pass, $db_name, $table_prefix);
  41. }else{
  42. die(get_lang('chdir_failed'));
  43. }
  44. if(chdir($cwd) === false){
  45. die(get_lang('chdir_failed'));
  46. }
  47. // Actual script functions now.
  48. $remoteServers = $db->getRemoteServers();
  49. $servers = array();
  50. if(is_array($remoteServers)){
  51. foreach($remoteServers as $server){
  52. $remote = new OGPRemoteLibrary($server['agent_ip'], $server['agent_port'], $server['encryption_key'], 1);
  53. $status = (int)$remote->status_chk();
  54. $servers[] = array(
  55. 'id' => $server['remote_server_id'],
  56. 'name' => $server['remote_server_name'] .' '. (($status) === 0 ? '('.get_lang('offline').')' : '('.get_lang('online').')'),
  57. 'status' => $status,
  58. );
  59. }
  60. }
  61. echo json_encode($servers);
  62. }else{
  63. header('HTTP/1.0 403 Forbidden');
  64. exit;
  65. }
  66. ?>