add_server.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. global $view;
  26. global $db;
  27. #This will add a remote host to the list
  28. if ( isset($_REQUEST['add_remote_host']) )
  29. {
  30. $rhost_ip = trim($_POST['remote_host']);
  31. $rhost_name = trim($_POST['remote_host_name']);
  32. $rhost_port = trim($_POST['remote_host_port']);
  33. $rhost_ftp_ip = trim($_POST['remote_host_ftp_ip']);
  34. $rhost_ftp_port = trim($_POST['remote_host_ftp_port']);
  35. $encryption_key = trim($_POST['remote_encryption_key']);
  36. $timeout = trim($_POST['timeout']);
  37. $use_nat = trim($_POST['use_nat']);
  38. $display_public_ip = trim($_POST['display_public_ip']);
  39. if ( empty($rhost_ip) ){
  40. print_failure( get_lang("enter_ip_host") );
  41. $view->refresh("?m=server");
  42. return;
  43. }
  44. if ( !isPortValid($rhost_port) ){
  45. print_failure( get_lang("enter_valid_ip") );
  46. $view->refresh("?m=server");
  47. return;
  48. }
  49. require_once('includes/lib_remote.php');
  50. $remote = new OGPRemoteLibrary($rhost_ip,$rhost_port,$encryption_key,$timeout);
  51. $status = $remote->status_chk();
  52. if($status === 0)
  53. {
  54. print_failure( get_lang("agent_offline") . "<br>" . get_lang("could_not_add_server") . " " . $rhost_ip );
  55. echo create_back_button($_GET['m']);
  56. return;
  57. }
  58. elseif($status === -1)
  59. {
  60. print_failure( get_lang("encryption_key_mismatch") . "<br>" . get_lang("could_not_add_server") . " " . $rhost_ip );
  61. echo create_back_button($_GET['m']);
  62. return;
  63. }
  64. $rhost_user_name = trim($remote->exec('echo %USERNAME%'));
  65. if( $rhost_user_name == '%USERNAME%' ) $rhost_user_name = trim($remote->exec('whoami'));
  66. $rhost_id = $db->addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$timeout,$use_nat,$display_public_ip);
  67. if ( !$rhost_id )
  68. {
  69. print_failure( get_lang("could_not_add_server") ." ".$rhost_ip." ". get_lang("to_db") );
  70. $view->refresh("?m=server");
  71. return;
  72. }
  73. print_success( get_lang("added_server") ." $rhost_ip ". get_lang("with_port") ." $rhost_port ". get_lang("to_db_succesfully") );
  74. $iplist = $remote->discover_ips();
  75. if ( empty($iplist) )
  76. print_failure( get_lang("unable_discover") ." ".$rhost_ip.". ". get_lang("set_ip_manually") );
  77. else
  78. {
  79. print_success( get_lang("found_ips") ." (".implode(",",$iplist).") ". get_lang("for_remote_server") );
  80. foreach ( $iplist as $remote_ip )
  81. {
  82. $remote_ip = trim($remote_ip);
  83. if ( empty($remote_ip) )
  84. continue;
  85. if ( !$db->addRemoteServerIp($rhost_id,$remote_ip) )
  86. print_failure( get_lang("failed_add_ip") ." (".$remote_ip.") ". get_lang("for_remote_server") );
  87. }
  88. }
  89. $view->refresh("?m=server");
  90. return;
  91. }
  92. }
  93. ?>