api_hosts.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) 2008 - 2018 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. function exec_ogp_module()
  25. {
  26. global $db;
  27. $api_hosts_file = 'api_authorized.hosts';
  28. echo "<h2>".get_lang('autohorized_hosts')."</h2>";
  29. if(isset($_POST['remove_hosts']))
  30. {
  31. if(file_exists($api_hosts_file))
  32. {
  33. $new_hosts = array();
  34. $hosts_list = file_get_contents($api_hosts_file);
  35. $hosts = preg_split("/[\r\n]+/", $hosts_list);
  36. foreach($hosts as $host)
  37. {
  38. $host = trim($host);
  39. if($host == '')
  40. continue;
  41. if(in_array($host, $_POST['hosts_to_remove']))
  42. continue;
  43. $new_hosts[] = $host;
  44. }
  45. file_put_contents($api_hosts_file, implode("\n", $new_hosts));
  46. }
  47. }
  48. if(isset($_POST['add_host']))
  49. {
  50. if(file_exists($api_hosts_file))
  51. {
  52. $new_hosts = array();
  53. $hosts_list = file_get_contents($api_hosts_file);
  54. $hosts = preg_split("/[\r\n]+/", $hosts_list);
  55. foreach($hosts as $host)
  56. {
  57. $host = trim($host);
  58. if($host == '')
  59. continue;
  60. $new_hosts[] = $host;
  61. }
  62. $new_hosts[] = trim($_POST['host_to_add']);
  63. file_put_contents($api_hosts_file, implode("\n", $new_hosts));
  64. }
  65. else
  66. {
  67. file_put_contents($api_hosts_file, trim($_POST['host_to_add']));
  68. }
  69. }
  70. $autorized_hosts = array($_SERVER['SERVER_NAME'], getHostByName(getHostName()), '127.0.0.1', 'localhost');
  71. $remote_servers = $db->getRemoteServers();
  72. foreach($remote_servers as $remote_server)
  73. {
  74. foreach(gethostbynamel($remote_server['agent_ip']) as $agent_ip)
  75. {
  76. if(!in_array($agent_ip, $autorized_hosts))
  77. $autorized_hosts[] = $agent_ip;
  78. }
  79. }
  80. echo "<h4>".get_lang('default_hosts')."</h4>\n<br>\n<div align='center'>\n";
  81. foreach($autorized_hosts as $autorized_host)
  82. {
  83. echo $autorized_host."<br>\n";
  84. }
  85. echo "</div>\n<br>\n<form method=POST action='?m=settings&p=api_hosts'>\n<div align='center'>\n";
  86. if(file_exists($api_hosts_file))
  87. {
  88. $hosts_list = file_get_contents($api_hosts_file);
  89. $hosts = preg_split("/[\r\n]+/", $hosts_list);
  90. if(!empty(array_filter($hosts)))
  91. {
  92. echo "<h4>".get_lang('custom_hosts')."</h4>\n<br>\n";
  93. foreach($hosts as $host)
  94. {
  95. $host = trim($host);
  96. if($host == '')
  97. continue;
  98. echo "<input type=checkbox id='$host' name='hosts_to_remove[]' value='$host' ><label for='host'>$host</label><br>\n";
  99. }
  100. echo "<br><input type=submit name=remove_hosts value='".get_lang('remove_hosts')."'>\n<br>\n<br>\n";
  101. }
  102. }
  103. echo "<input type=text name='host_to_add' >\n".
  104. "<input type=submit name=add_host value='".get_lang('add_host')."'>\n".
  105. "</div>\n".
  106. "</form>\n".
  107. "<br>\n".
  108. "<br>\n".
  109. "<a href='?m=settings'>".get_lang('back')."</a>";
  110. }