add_server.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. /*
  3. *
  4. * OGP - Open Game Panel
  5. * Copyright (C) Copyright (C) 2008 - 2013 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. if ( empty($rhost_ip) ){
  39. print_failure( enter_ip_host );
  40. $view->refresh("?m=server");
  41. return;
  42. }
  43. if ( !isPortValid($rhost_port) ){
  44. print_failure( enter_valid_ip );
  45. $view->refresh("?m=server");
  46. return;
  47. }
  48. require_once('includes/lib_remote.php');
  49. $remote = new OGPRemoteLibrary($rhost_ip,$rhost_port,$encryption_key,$timeout);
  50. $status = $remote->status_chk();
  51. if($status === 0)
  52. {
  53. print_failure( agent_offline . "<br>" . could_not_add_server . " " . $rhost_ip );
  54. echo create_back_button($_GET['m']);
  55. return;
  56. }
  57. elseif($status === -1)
  58. {
  59. print_failure( encryption_key_mismatch . "<br>" . could_not_add_server . " " . $rhost_ip );
  60. echo create_back_button($_GET['m']);
  61. return;
  62. }
  63. $rhost_user_name = trim($remote->exec('echo %USERNAME%'));
  64. if( $rhost_user_name == '%USERNAME%' ) $rhost_user_name = trim($remote->exec('whoami'));
  65. $rhost_id = $db->addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$timeout,$use_nat);
  66. if ( !$rhost_id )
  67. {
  68. print_failure( could_not_add_server ." ".$rhost_ip." ". to_db );
  69. $view->refresh("?m=server");
  70. return;
  71. }
  72. print_success( added_server ." $rhost_ip ". with_port ." $rhost_port ". to_db_succesfully );
  73. $iplist = $remote->discover_ips();
  74. if ( empty($iplist) )
  75. print_failure( unable_discover ." ".$rhost_ip.". ". set_ip_manually );
  76. else
  77. {
  78. print_success( found_ips ." (".implode(",",$iplist).") ". for_remote_server );
  79. foreach ( $iplist as $remote_ip )
  80. {
  81. $remote_ip = trim($remote_ip);
  82. if ( empty($remote_ip) )
  83. continue;
  84. if ( !$db->addRemoteServerIp($rhost_id,$remote_ip) )
  85. print_failure( failed_add_ip ." (".$remote_ip.") ". for_remote_server );
  86. }
  87. }
  88. $view->refresh("?m=server");
  89. return;
  90. }
  91. }
  92. ?>