瀏覽代碼

Adding Dispaly Public IP override Option for Gameservers behind NAT

Andreas Reinhard 9 年之前
父節點
當前提交
0acedcff27

+ 2 - 2
includes/database.php

@@ -151,7 +151,7 @@ abstract class OGPDatabase {
 
     // Server module functions
     /// \brief Adds remote server to database.
-    abstract public function addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$rhost_timeout,$use_nat);
+    abstract public function addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$rhost_timeout,$use_nat,$display_public_ip);
 
     abstract public function getRemoteServer($id);
 
@@ -171,7 +171,7 @@ abstract class OGPDatabase {
 
     /// \brief Change encryption key for remote server.
     abstract public function changeRemoteServerSettings($server_id,
-        $agent_ip,$agent_port,$remote_server_name,$remote_server_user_name,$remote_host_ftp_ip,$remote_host_ftp_port,$encryption_key,$rhost_timeout,$use_nat);
+        $agent_ip,$agent_port,$remote_server_name,$remote_server_user_name,$remote_host_ftp_ip,$remote_host_ftp_port,$encryption_key,$rhost_timeout,$use_nat,$display_public_ip);
 
     // Gamemanager functions
     abstract public function getHomeIpPorts($home_id);

+ 10 - 6
includes/database_mysql.php

@@ -977,7 +977,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 
 	// Server module functions
 	/// \brief Adds remote server to database.
-	public function addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$rhost_timeout,$use_nat)
+	public function addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$rhost_timeout,$use_nat,$display_public_ip)
 	{
 		$rhost_ip = trim($rhost_ip);
 		$rhost_port = trim($rhost_port);
@@ -987,6 +987,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 		$encryption_key = trim($encryption_key);
 		$rhost_timeout = trim($rhost_timeout);
 		$use_nat = trim($use_nat);
+		$display_public_ip = trim($display_public_ip);
 
 		if ( empty($rhost_ip) )
 			return false;
@@ -996,8 +997,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 			return false;
 
 		$rhost_name = trim($rhost_name);
-		$query = sprintf("INSERT INTO `%sremote_servers` (`agent_ip`,remote_server_name,ogp_user,agent_port,ftp_ip,ftp_port,`encryption_key`,timeout,use_nat)
-			VALUES('%s','%s','%s','%d','%s','%s','%s','%s','%s');",
+		$query = sprintf("INSERT INTO `%sremote_servers` (`agent_ip`,remote_server_name,ogp_user,agent_port,ftp_ip,ftp_port,`encryption_key`,timeout,use_nat,display_public_ip)
+			VALUES('%s','%s','%s','%d','%s','%s','%s','%s','%s','%s');",
 				$this->table_prefix,
 				mysql_real_escape_string($rhost_ip,$this->link),
 				mysql_real_escape_string($rhost_name,$this->link),
@@ -1007,7 +1008,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 				mysql_real_escape_string($rhost_ftp_port,$this->link),
 				mysql_real_escape_string($encryption_key,$this->link),
 				mysql_real_escape_string($rhost_timeout,$this->link),
-				mysql_real_escape_string($use_nat,$this->link));
+				mysql_real_escape_string($use_nat,$this->link),
+				mysql_real_escape_string($display_public_ip,$this->link));
 		++$this->queries_;
 		mysql_query($query,$this->link);
 
@@ -1151,7 +1153,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 	}
 
 	public function changeRemoteServerSettings($server_id,
-		$agent_ip,$agent_port,$remote_server_name,$remote_server_user_name,$remote_host_ftp_ip,$remote_host_ftp_port,$encryption_key,$remote_timeout,$use_nat)
+		$agent_ip,$agent_port,$remote_server_name,$remote_server_user_name,$remote_host_ftp_ip,$remote_host_ftp_port,$encryption_key,$remote_timeout,$use_nat,$display_public_ip)
 	{
 		$query = sprintf("UPDATE %sremote_servers SET agent_ip='%s',
 			agent_port='%s', encryption_key='%s',
@@ -1160,7 +1162,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 			ftp_ip='%s',
 			ftp_port='%s',
 			timeout='%s',
-			use_nat='%s'
+			use_nat='%s',
+			display_public_ip='%s'
 			WHERE remote_server_id = %d;",
 			$this->table_prefix,
 			mysql_real_escape_string($agent_ip, $this->link),
@@ -1172,6 +1175,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 			mysql_real_escape_string($remote_host_ftp_port, $this->link),
 			mysql_real_escape_string($remote_timeout, $this->link),
 			mysql_real_escape_string($use_nat, $this->link),
+			mysql_real_escape_string($display_public_ip, $this->link),
 			mysql_real_escape_string($server_id, $this->link));
 		++$this->queries_;
 		if ( mysql_query($query, $this->link) === FALSE )

+ 10 - 6
includes/database_mysqli.php

@@ -974,7 +974,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 
 	// Server module functions
 	/// \brief Adds remote server to database.
-	public function addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$rhost_timeout,$use_nat)
+	public function addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$rhost_timeout,$use_nat,$display_public_ip)
 	{
 		$rhost_ip = trim($rhost_ip);
 		$rhost_port = trim($rhost_port);
@@ -984,6 +984,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 		$encryption_key = trim($encryption_key);
 		$rhost_timeout = trim($rhost_timeout);
 		$use_nat = trim($use_nat);
+		$display_public_up = trim($display_public_ip);
 
 		if ( empty($rhost_ip) )
 			return false;
@@ -993,8 +994,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 			return false;
 
 		$rhost_name = trim($rhost_name);
-		$query = sprintf("INSERT INTO `%sremote_servers` (`agent_ip`,remote_server_name,ogp_user,agent_port,ftp_ip,ftp_port,`encryption_key`,timeout,use_nat)
-			VALUES('%s','%s','%s','%d','%s','%s','%s','%s','%s');",
+		$query = sprintf("INSERT INTO `%sremote_servers` (`agent_ip`,remote_server_name,ogp_user,agent_port,ftp_ip,ftp_port,`encryption_key`,timeout,use_nat,display_public_ip)
+			VALUES('%s','%s','%s','%d','%s','%s','%s','%s','%s','%s');",
 				$this->table_prefix,
 				mysqli_real_escape_string($this->link,$rhost_ip),
 				mysqli_real_escape_string($this->link,$rhost_name),
@@ -1004,7 +1005,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 				mysqli_real_escape_string($this->link,$rhost_ftp_port),
 				mysqli_real_escape_string($this->link,$encryption_key),
 				mysqli_real_escape_string($this->link,$rhost_timeout),
-				mysqli_real_escape_string($this->link,$use_nat));
+				mysqli_real_escape_string($this->link,$use_nat),
+				mysqli_real_escape_string($this->link,$display_public_ip));
 		++$this->queries_;
 		mysqli_query($this->link,$query);
 
@@ -1148,7 +1150,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 	}
 
 	public function changeRemoteServerSettings($server_id,
-		$agent_ip,$agent_port,$remote_server_name,$remote_server_user_name,$remote_host_ftp_ip,$remote_host_ftp_port,$encryption_key,$remote_timeout,$use_nat)
+		$agent_ip,$agent_port,$remote_server_name,$remote_server_user_name,$remote_host_ftp_ip,$remote_host_ftp_port,$encryption_key,$remote_timeout,$use_nat,$display_public_ip)
 	{
 		$query = sprintf("UPDATE %sremote_servers SET agent_ip='%s',
 			agent_port='%s', encryption_key='%s',
@@ -1157,7 +1159,8 @@ class OGPDatabaseMySQL extends OGPDatabase
 			ftp_ip='%s',
 			ftp_port='%s',
 			timeout='%s',
-			use_nat='%s'
+			use_nat='%s',
+			display_public_ip='%s'
 			WHERE remote_server_id = %d;",
 			$this->table_prefix,
 			mysqli_real_escape_string($this->link,$agent_ip),
@@ -1169,6 +1172,7 @@ class OGPDatabaseMySQL extends OGPDatabase
 			mysqli_real_escape_string($this->link,$remote_host_ftp_port),
 			mysqli_real_escape_string($this->link,$remote_timeout),
 			mysqli_real_escape_string($this->link,$use_nat),
+			mysqli_real_escape_string($this->link,$display_public_ip),
 			mysqli_real_escape_string($this->link,$server_id));
 		++$this->queries_;
 		if ( mysqli_query($this->link,$query) === FALSE )

+ 6 - 4
modules/gamemanager/server_monitor.php

@@ -498,12 +498,14 @@ function exec_ogp_module() {
 
 			if( $host_stat === 1)
 			{
-				if ( $server_home['use_nat'] == 1 )
+				if ( $server_home['use_nat'] == 1 ){
 					$query_ip = $server_home['agent_ip'];
-				else
+				}else{
 					$query_ip = $server_home['ip'];
-
-				$address = $query_ip . ":" . $server_home['port'];
+				}
+				if(ip2long($server_home['display_public_ip'])){
+					$query_ip = $server_home['display_public_ip'];
+				}
 				$screen_running = $remote->is_screen_running(OGP_SCREEN_TYPE_HOME,$server_home['home_id']) === 1;
 				$update_in_progress = $remote->is_screen_running(OGP_SCREEN_TYPE_UPDATE,$server_home['home_id']) === 1;
 				if($screen_running)

+ 2 - 1
modules/server/add_server.php

@@ -38,6 +38,7 @@ function exec_ogp_module() {
 		$encryption_key = trim($_POST['remote_encryption_key']);
 		$timeout = trim($_POST['timeout']);
 		$use_nat = trim($_POST['use_nat']);
+		$display_public_ip = trim($_POST['display_public_ip']);
 		
 		if ( empty($rhost_ip) ){
 			print_failure( enter_ip_host );
@@ -71,7 +72,7 @@ function exec_ogp_module() {
 		$rhost_user_name = trim($remote->exec('echo %USERNAME%'));
 		if( $rhost_user_name == '%USERNAME%' ) $rhost_user_name = trim($remote->exec('whoami'));
 		
-		$rhost_id = $db->addRemoteServer($rhost_ip,$rhost_name,$rhost_user_name,$rhost_port,$rhost_ftp_ip,$rhost_ftp_port,$encryption_key,$timeout,$use_nat);
+		$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);
 		if ( !$rhost_id )
 		{
 			print_failure( could_not_add_server ." ".$rhost_ip." ". to_db );

+ 4 - 1
modules/server/edit_server.php

@@ -119,7 +119,8 @@ function exec_ogp_module() {
 			$_REQUEST['remote_host_ftp_port'],
             $_REQUEST['remote_encryption_key'],
 			$_REQUEST['timeout'],
-			$_REQUEST['use_nat']);
+			$_REQUEST['use_nat'],
+			$_REQUEST['display_public_ip']);
         print_success(get_lang_f('remote_server_settings_changed',$remote_server['remote_server_name']));
         $view->refresh("?m=server&p=edit&rhost_id=".$rhost_id."&edit");
     }
@@ -127,6 +128,7 @@ function exec_ogp_module() {
     {
 		$remote_server = $db->getRemoteServer($rhost_id);
 		$ftp_ip = empty($remote_server['ftp_ip']) ? $remote_server['agent_ip'] : $remote_server['ftp_ip'];
+		$dp_ip = empty($remote_server['display_public_ip']) ? $remote_server['agent_ip'] : $remote_server['display_public_ip'];
         require_once('includes/form_table_class.php');
         $ft = new FormTable();
         $ft->start_form('?m=server&p=edit&rhost_id='.$rhost_id.'&edit');
@@ -141,6 +143,7 @@ function exec_ogp_module() {
         $ft->add_field('string','remote_encryption_key',$remote_server['encryption_key']);
 		$ft->add_field('string','timeout',$remote_server['timeout']);
 		$ft->add_field('on_off','use_nat',$remote_server['use_nat']);
+		$ft->add_field('string','display_public_ip',$dp_ip);
         $ft->end_table();
         $ft->add_button('submit','save_settings', save_settings );
         $ft->end_form();

+ 7 - 2
modules/server/module.php

@@ -24,8 +24,8 @@
 
 // Module general information
 $module_title = "Server manager";
-$module_version = "1.5";
-$db_version = 5;
+$module_version = "1.6";
+$db_version = 6;
 $module_required = TRUE;
 $module_menus = array(
 	array( 'subpage' => '', 'name'=>'Servers', 'group'=>'admin' )
@@ -82,4 +82,9 @@ $install_queries[5] = array(
 	 DROP COLUMN `ufw_status`;",
 	"ALTER TABLE `OGP_DB_PREFIXremote_servers` 
 	 ADD `firewall_settings` LONGTEXT NULL;");
+
+$install_queries[6] = array(
+        "ALTER TABLE `OGP_DB_PREFIXremote_servers`
+	ADD `display_public_ip` varchar(15) NOT NULL;");
+
 ?>

+ 1 - 0
modules/server/servers.php

@@ -45,6 +45,7 @@ function exec_ogp_module() {
 	$ft->add_field('string','remote_encryption_key',"");
 	$ft->add_field('string','timeout',"5");
 	$ft->add_field('on_off','use_nat',"0");
+	$ft->add_field('string','default_public_ip',"");
 	$ft->end_table();
 	$ft->add_button('submit','add_remote_host', add_remote_host );
 	$ft->end_form();