Просмотр исходного кода

Merge pull request #153 from oNdsen/master

Adding Display Public IP override Option for Gameservers behind NAT
OwN-3m-All 9 лет назад
Родитель
Сommit
ffa94b30d6

+ 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 )

+ 7 - 3
modules/dashboard/dashboard.php

@@ -139,10 +139,14 @@ function exec_ogp_module()
 				{
 					require_once("modules/config_games/server_config_parser.php");
 					$server_xml = read_server_config(SERVER_CONFIG_LOCATION."/".$server_home['home_cfg_file']);
-					if ( $server_home['use_nat'] == 1 )
+					if ( $server_home['use_nat'] == 1 ){
 						$ip = $server_home['agent_ip'];
-					else
+					}else{
 						$ip = $server_home['ip'];
+					}
+					if(ip2long($server_home['display_public_ip'])){
+						$ip = $server_home['display_public_ip'];
+					}
 					$port = $server_home['port'];
 					
 					if($server_xml->protocol == "lgsl")
@@ -347,4 +351,4 @@ $(document).ready(function(){
 </script>
 <?php
 }
-?>
+?>

+ 9 - 9
modules/ftp/ftp_admin.php

@@ -63,19 +63,19 @@ function exec_ogp_module()
 			$remote->ftp_mgr("useradd", $post_ftp_login, $post_ftp_password, $post_full_path);
 		}
 	}
-	
+
 	if(isset($_POST['del_ftp_user_y']))
 	{
 		$ftp_login = strip_real_escape_string($_POST['ftp_login']);
 		$server_row = $db->getRemoteServer($_POST['remote_server_id']);
 		$remote = new OGPRemoteLibrary($server_row['agent_ip'],$server_row['agent_port'],$server_row['encryption_key'],$server_row['timeout']);
-				
+
 		$remote->ftp_mgr("userdel", $ftp_login);
-		
+
 		$home_info = $db->getHomeByFtpLogin($server_row['remote_server_id'], $ftp_login);
 		$db->changeFtpStatus('disabled',$home_info['home_id']);
 	}
-		
+
 	if(isset($_POST['edit_ftp_user']))
 	{
 		$server_row = $db->getRemoteServer($_POST['remote_server_id']);
@@ -98,17 +98,16 @@ function exec_ogp_module()
 	$servers = $db->getRemoteServers();
 
 	if ($servers !== false) {
-		
 		echo "<tr><td colspan='3' >
 			<form method=POST >
 			<table class='center' style='width:100%' ><tr>
 			<td>". remote_server ." <select style='width:250px' name='remote_server_id' >";
-			
+
 		foreach ( $servers as $server_row )
 		{
-			echo "<option value='" . $server_row['remote_server_id'] . "' >" . $server_row['remote_server_name'] . " (" . $server_row['agent_ip'] . ":" . $server_row['agent_port'] . ")</option>";
+			$display_ip = ip2long($server_row['display_public_ip']) && $server_row['display_public_ip']!=$server_row['agent_ip'] ? $server_row['display_public_ip'] : $server_row['agent_ip'];
+			echo "<option value='" . $server_row['remote_server_id'] . "' >" . $server_row['remote_server_name'] . " (" . $display_ip . ":" . $server_row['agent_port'] . ")</option>";
 		}
-		
 		echo "</select>
 				</td>
 				<td>". login ."<input type=text name='ftp_login' /></td>
@@ -132,6 +131,7 @@ function exec_ogp_module()
 	<?php		
 		foreach ( $servers as $server_row )
 		{
+			$display_ip = ip2long($server_row['display_public_ip']) && $server_row['display_public_ip']!=$server_row['agent_ip'] ? $server_row['display_public_ip'] : $server_row['agent_ip'];
 			$remote = new OGPRemoteLibrary($server_row['agent_ip'],$server_row['agent_port'],$server_row['encryption_key'],$server_row['timeout']);
 
 			$host_stat = $remote->status_chk();
@@ -151,7 +151,7 @@ function exec_ogp_module()
 						$home_info = $db->getHomeByFtpLogin($server_row['remote_server_id'], $ftp_login);
 						$expandme = ( ( isset($_POST['ftp_login']) and $ftp_login == strip_real_escape_string($_POST['ftp_login']) ) AND ( isset($_POST['remote_server_id']) and $home_info['remote_server_id'] == $_POST['remote_server_id'] ) ) ? "expandme" : "";
 						$home_name = isset( $home_info['home_name'] ) ? $home_info['home_name'] : $ftp_path;
-						echo "<tr class='maintr $expandme'><td class='collapsible' ></td><td>".$server_row['remote_server_name']." (".$server_row['agent_ip'].")</td><td><b class='failure' >$ftp_login</td><td>" . htmlentities($home_name) . "</td><td>$ftp_path</td></tr>
+						echo "<tr class='maintr $expandme'><td class='collapsible' ></td><td>".$server_row['remote_server_name']." (".$display_ip.")</td><td><b class='failure' >$ftp_login</td><td>" . htmlentities($home_name) . "</td><td>$ftp_path</td></tr>
 							  <tr class='expand-child' ><td colspan='4' >
 							  <form method=POST >
 							  <table>";

+ 3 - 1
modules/ftp/skins/blue/login.template.php

@@ -33,6 +33,8 @@ foreach($user_homes as $ftp_info)
 		$ftp_login = isset($ftp_info['ftp_login']) ? $ftp_info['ftp_login'] : $ftp_info['home_id'];
 		$isFtpEnabled = $ftp_info['ftp_status'] == 1 ? TRUE : FALSE;
 		$ftp_ip = empty($ftp_info['ftp_ip']) ? $ftp_info['agent_ip'] : $ftp_info['ftp_ip'];
+		$display_ip = ip2long($ftp_info['display_public_ip']) && $ftp_info['display_public_ip']!=$ftp_info['agent_ip'] ? $ftp_info['display_public_ip'] : $ftp_ip;
+
 		?><table style="text-align:center;width:100%;border:1px solid black;background-image:url(../../themes/Revolution/images/wrapper-bg.png);">
 			<tr>
 			  <td colspan="3">
@@ -48,7 +50,7 @@ foreach($user_homes as $ftp_info)
 			    <table>
 				  <tr  >
 			        <td style='width: 50%;'>
-				      <?php echo "".__("FTP server").":</td><td style='width: 50%;'><input type='text' readonly='readonly' size='26' onclick='select()' value='".$ftp_ip.":".$ftp_info['ftp_port']."'/></td></tr><tr><td>".__("Username").":</td><td><input type='text' readonly='readonly' size='26' onclick='select()' value=\"".str_replace('"', "&quot;", $ftp_login)."\"/></td></tr><tr><td>".__("Password").":</td><td><input type='text' readonly='readonly' size='26' onclick='select()' value=\"".str_replace('"', "&quot;", $ftp_info['ftp_password'])."\"/>"; ?>
+				      <?php echo "".__("FTP server").":</td><td style='width: 50%;'><input type='text' readonly='readonly' size='26' onclick='select()' value='".$display_ip.":".$ftp_info['ftp_port']."'/></td></tr><tr><td>".__("Username").":</td><td><input type='text' readonly='readonly' size='26' onclick='select()' value=\"".str_replace('"', "&quot;", $ftp_login)."\"/></td></tr><tr><td>".__("Password").":</td><td><input type='text' readonly='readonly' size='26' onclick='select()' value=\"".str_replace('"', "&quot;", $ftp_info['ftp_password'])."\"/>"; ?>
 			        </td>
 				  </tr>
 				</table>

+ 7 - 3
modules/gamemanager/server_monitor.php

@@ -498,12 +498,16 @@ 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'];
-
+				}
+				if(ip2long($server_home['display_public_ip'])){
+					$query_ip = $server_home['display_public_ip'];
+				}
 				$address = $query_ip . ":" . $server_home['port'];
+
 				$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&amp;p=edit&amp;rhost_id=".$rhost_id."&amp;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&amp;p=edit&amp;rhost_id='.$rhost_id.'&amp;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();

+ 3 - 2
modules/user_games/add_home.php

@@ -136,8 +136,9 @@ function exec_ogp_module()
 		echo "<option>".get_lang('select_remote_server')."</option>\n";
 		foreach ( $remote_servers as $server )
 		{
+			$ip = ip2long($server['display_public_ip']) && $server['display_public_ip']!=$server['agent_ip'] ? $server['display_public_ip'] : $server['agent_ip'];
 			echo "<option value='".$server['remote_server_id']."'>".
-				$server['remote_server_name']." (".$server['agent_ip'].")</option>\n";
+				$server['remote_server_name']." (".$ip.")</option>\n";
 		}
 		echo "</select>\n";
 		echo "</form>";
@@ -190,4 +191,4 @@ function exec_ogp_module()
 		echo "</form>";
 	}
 }
-?>
+?>

+ 26 - 15
modules/user_games/edit_home.php

@@ -43,7 +43,9 @@ function exec_ogp_module()
 	$home_info = $db->getGameHomeWithoutMods($home_id);
 	$home_id = $home_info['home_id'];
 	$enabled_mods = $db->getHomeMods($home_id);
-		
+
+	$display_ip = ip2long($home_info['display_public_ip']) && $home_info['display_public_ip']!=$home_info['agent_ip'] ? $home_info['display_public_ip'] : $home_info['agent_ip'];
+
 	if( $isAdmin and isset( $_POST['change_home_cfg_id'] ) )
 	{
 		if( !empty($enabled_mods) )
@@ -784,11 +786,11 @@ function exec_ogp_module()
 					{
 						if ( $db->addGameIpPort($home_id, $ip_id, $port) === FALSE )
 						{
-							print_failure(get_lang_f('ip_port_already_in_use', $ip, $port));
+							print_failure(get_lang_f('ip_port_already_in_use', $display_ip, $port));
 						}
 						else {
-							print_success(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
-							$db->logger(get_lang_f('successfully_assigned_ip_port_to_server_id', $ip, $port, $home_id));
+							print_success(get_lang_f('successfully_assigned_ip_port_to_server_id', $display_ip, $port, $home_id));
+							$db->logger(get_lang_f('successfully_assigned_ip_port_to_server_id', $display_ip, $port, $home_id));
 						}
 					}
 				}
@@ -806,22 +808,26 @@ function exec_ogp_module()
 					else
 						print_failure("Failed to unassign ip:port.");
 				}
-								
+
 				echo "<form action='?m=user_games&p=edit&home_id=".$home_id."' method='post'>\n";
 				echo "<input type='hidden' name='home_id' value=\"$home_id\" />\n";
 				echo  ip .":<select name='ip' onchange='this.form.submit();'>";
-				
-				foreach($avail_ips as $value)
-				{
-					$selected = ( isset($_POST['ip']) and $_POST['ip'] == $value['ip_id'] ) ? "selected='selected'" : "";
-					echo "<option value='".$value['ip_id']."' $selected >".$value['ip']."</option>\n";
+
+				if(ip2long($home_info['display_public_ip']) && $home_info['display_public_ip']!=$home_info['agent_ip']){
+					echo "<option value='".$avail_ips[0]['ip_id']."' $selected >".$display_ip."</option>\n";
+				}else{
+					foreach($avail_ips as $value)
+					{
+						$selected = ( isset($_POST['ip']) and $_POST['ip'] == $value['ip_id'] ) ? "selected='selected'" : "";
+						echo "<option value='".$value['ip_id']."' $selected >".$value['ip']."</option>\n";
+					}
 				}
-				
+
 				echo "</select>";
 
 				$ip_id = isset($_POST['ip']) ? $_POST['ip'] : $avail_ips[0]['ip_id'];
 				$port = $db->getNextAvailablePort($ip_id,$home_info['home_cfg_id']);
-					
+
 				echo " ". port .":<input type='text' name='port' value='".$port."' size='6' />";
 				echo "<input type='submit' name='set_ip' value='". set_ip ."' />";
 				echo "</form>";
@@ -852,9 +858,14 @@ function exec_ogp_module()
 							$force_mod .= "</select>\n</form>\n</td>\n";
 							$align = "right";
 						}
-						echo "<table class='center'><tr><td align='$align'>".$assigned_rows['ip'].":".$assigned_rows['port'].
-							 " <a href='?m=user_games&amp;p=edit&amp;home_id=$home_id&amp;delete_ip&amp;ip=".
-							 $assigned_rows['ip_id']."&amp;port=".$assigned_rows['port'].
+						if(ip2long($home_info['display_public_ip']) && $home_info['display_public_ip']!=$home_info['agent_ip']){
+							$assigned_ip = $home_info['display_public_ip'];
+						}else{
+							$assigned_ip = $assigned_rows['ip'];
+						}
+						echo "<table class='center'><tr><td align='$align'>".$assigned_ip.":".$assigned_rows['port'].
+							 " <a href='?m=user_games&p=edit&home_id=$home_id&delete_ip&ip=".
+							 $assigned_rows['ip_id']."&port=".$assigned_rows['port'].
 							 "'>[ ". delete ." ]</a></td>\n".
 							 $force_mod.
 							 "</tr>\n</table>\n";